Áö´Ï°¡ GEF¸¦ ¸¸³µÀ»¶§3(Pallete&EditPolicy)(2008/11/10)

JLab Çã¿øÁø

¡¡

ÆÈ·§Æ®¿Í ¿¡µðÆ® Á¤Ã¥¿¡ ´ëÇØ¼­ ¾Ë¾Æº¸ÀÚ. ºñ±³Àû ÀÌÀü ±â»çµé°ú ´Þ¸® GEF ½ºÆå¿¡ ´ëÇØ ¾Ë¾Æ¾ßµÉ ºÎºÐÀÌ ¸¹´Ù. ÀÌÇØº¸´Ù´Â ÀÏ·ÃÀÇ ÇÊ¿ä °úÁ¤À¸·Î ÀνÄÇØ Áֱ⸦ ¹Ù¶õ´Ù. µð¹ö±× Æ÷ÀÎÆ®¸¦ ÀÇ½É ³ª´Â °÷ ¸¶´Ù °É¾î¼­ È帧À» ²À Çѹø »ìÆì º¸µµ·Ï ÇÏÀÚ.

¡¡

ÇÁ·¹ÀÓ¿öÅ© °³¹ßÀÚÀÇ ½ÃÁ¡À¸·Î º¸¶ó

Microsoft Office

¿ÀÇǽº »ç¿ëÀÚ°¡ ¿ÀÇǽº ¹®¼­¿¡ ¹®ÀÚ¸¦ »ðÀÔ ÇÏ´Â °úÁ¤À» ÅëÇØ Graphical Editing System¿¡ ´ëÇØ¼­ ¾Ë¾Æº¸ÀÚ.

1. ÆÈ·§Æ®¿¡¼­ ¹®ÀÚ ¼±ÅÃ

2. ÆÈ·§Æ® ÇÁ·ÎÆÛƼ¿¡¼­ ¼¼ºÎ»çÇ×(Å©±â, ¹è¿­ µî) ¼±ÅÃ

3. Ä˹ö½º ¿µ¿ª¿¡ ¹®ÀÚ¸¦ »ðÀÔ ÇÒ À§Ä¡¿¡ Ŭ¸¯

4. »ðÀÔÇÒ ¹®ÀÚ ÀÔ·Â

5. µå·¹±×&µå·ÓÀ» ÅëÇØ ¹®ÀÚ À§Ä¡ Á¶Á¤°ú ¿µ¿ª Á¶Á¤

¿©±â ±îÁö´Â Graphical Editor¸¦ »ç¿ëÇÏ´Â »ç¿ëÀÚÀÇ °üÁ¡À̰í, ÀÌÁ¦ À̸¦ Áö¿øÇÒ ¿¡µðÅ͸¦ ¸¸µé ¼ö ÀÖ´Â GEF¸¦ ¸¸µç °³¹ßÀÚÀÇ ½ÃÁ¡À¸·Î °¢ °úÁ¤À» ¹Ù¶óº¸ÀÚ.

1. ÆÈ·§Æ®¿¡¼­ ¹®ÀÚ ¼±ÅÃ

¿¡µðÅÍ °³¹ßÀÚ°¡ ÆíÁý¿¡ »ç¿ëÇÏ´Â ¿ä¼ÒµéÀ» ³ª¿­Çϰí À̸¦ ¼±Åà ÇÒ ¼ö ÀÖ°Ô Áö¿øÇؾßÇÑ´Ù.

2. ÆÈ·§Æ® ÇÁ·ÎÆÛƼ¿¡¼­ ¼¼ºÎ»çÇ×(Å©±â, ¹è¿­ µî) ¼±ÅÃ

ÀϹÝÀûÀÎ ÆÈ·§Æ® ÇüŰ¡ ¾Æ´Ñ ÀÓÀÇÀÇ ÆÈ·§Æ®³ª ÇÁ·ÎÆÛƼ âÀ̳ª º°µµÀÇ À©µµ¿ì¸¦ ÅëÇÑ GUI¸¦ Áö¿øÇØ¾ß ÇÑ´Ù.

3. Ä˹ö½º ¿µ¿ª¿¡ ¹®ÀÚ¸¦ »ðÀÔ ÇÒ À§Ä¡¿¡ Ŭ¸¯

Ä˹ö½º¿¡¼­ ÀϾ´Â À¯Àú ÀÔ·Â À̺¥Æ®¸¦ ÀνÄÇØ¾ß ÇÑ´Ù.

4. »ðÀÔÇÒ ¹®ÀÚ ÀÔ·Â

canvas ¿µ¿ª¿¡ ¼¼ºÎ»çÇ×À» ÀÔ·Â ÇÒ ¼ö ÀÖµµ·Ï À¯¿¬ÇÑ È¯°æÀ» Á¦°øÇØ¾ß ÇÑ´Ù.

5. µå·¹±×&µå·ÓÀ» ÅëÇØ ¹®ÀÚ À§Ä¡ Á¶Á¤°ú ¿µ¿ª Á¶Á¤

À¯Àú ÀÔ·Â À̺¥Æ®¿¡ µû¸¥ ½Ã³ª¸®¿À°¡ Á¤ÀǵǾî ÀÖ°í À̸¦ ÅëÁ¦ ÇÒ ¼ö ÀÖ¾î¾ß ÇÑ´Ù.

GEF °³¹ßÀÚ º¸´Ù´Â GEF À¯Àú°¡ ½±°í, GEF À¯Àú º¸´Ù´Â ¿¡µðÅÍ »ç¿ëÀÚ°¡ ½±´Ù. ´ç¿¬ÇÑ À̾߱â´Ù. ÇÏÀÚ¸¸ ¿ª¼³ ÀûÀ¸·Î ¿¡µðÅ͸¦ Àß »ç¿ëÇϱâ À§Çؼ­´Â ¿¡µðÅÍ ½Ã½ºÅÛÀ» ÀÌÇØÇϰí GEF¸¦ ÀÌ¿ëÇØ ¿¡µðÅ͸¦ Àß ¸¸µé±â À§Çؼ­´Â GEF¸¦ Àß ÀÌÇØÇØ¾ßÇÒ Çʿ䰡 ÀÖ´Ù. ¿©·¯ºÐµéÀÌ ¸ÅÀÏ ±×¸®´Â ¹®¼­ ¼ÓÀÇ End User°¡ ¾Æ´Ñ ProviderÁßÀÇ Provider·Î »ý°¢ÇØ º¸´Â°ÍÀÌ´Ù. ¹°·Ð ÀÌ·¯ÇÑ ¿ª¹ß»óÀ̳ª ÀÌÇØ ¾øÀ̵µ GEF¸¦ ±â°èÀûÀ¸·Î ±¸ÇöÇÏ°í »ç¿ëÇϴ°Ϳ¡´Â ¹«¸®°¡ ¾ø´Ù. ÇÏÁö¸¸ ¿©·¯ºÐµéÀº ²÷ÀÓ¾ø´Â "¾î¶»°ÔÇØ"¿¡ ½Ã´Þ·Á¾ß ÇÑ´Ù. ºä¾î¸¦ Draw2D°¡ ¾Æ´Ñ SWT OpenGL·Î ¹Ù²Ü·Á¸é ¾î¶»°Ô ÇØ, ¸¶¿ì½º³ª Űº¸µå°¡ ¾Æ´Ñ »õ·Î¿î ÀåÄ¡ÀÇ ÀÔ·ÂÀ» ÅëÇÑ ÆíÁýÀº ¾î¶»°Ô ÇØ µîµî "¾î¶»°ÔÇØ" ¿¡ ½Ã´Þ¸®°Ô µÈ´Ù. GEF °³¹ßÀÚµµ »ç¶÷ÀÌ´Ù. GEF »ç¿ëÀÚÀÇ ÆíÀǼº°ú ±¸Çö ºñ¿ëÀ» ÀýÃæ ÇÏ¿© GEF¸¦ ¸¸µé¾ú´Ù. Áï ¿©·¯ºÐÀÌ "³»°¡ GEF ÀÌ ºÎºÐÀº ³ª ¶ó¸é ÀÌ·¸°Ô ¸¸µé¾úÀ» ²¨¾ß" ÇÑ´Ù¸é ±×·¸°Ô µÆÀ» È®·üÀÌ ³ô´Ù´Â °Í ÀÌ´Ù.

GEF¿¡¼­´Â ¾î¶»°Ô ±¸ÇöµÆÀ»±î? ÀÌÀü ±â»çÀÇ ViewerºÎºÐÀ» ¶°¿Ã·Á º¸ÀÚ. ±×¶§ ¿ì¸®´Â Viewer¿¡ ±×¸®±â À§ÇØ ¸ðµ¨À» Á¤ÀÇ Çϰí À̸¦ ViewerÀÇ ÄÁÅÙÆ®·Î ¼³Á¤ÇÏ´Â ÀÛ¾÷À» Çß´Ù. Çö´ë °³¹ß¿¡ À־ ÀÌó·³ ±âº»ÀÌ µÇ´Â ¸ðµ¨ Áß½ÉÀ¸·Î °³¹ß ÁøÇàÀÌ µÇ´Â°ÍÀº ÀϹÝÀûÀ¸·Î µÇ¾ú´Ù.

Natural World to System

Áö³­ ±â»ç¸¦ ¹ÙÅÁÀ¸·Î À­ ±×¸²¿¡ ÁÙ ±ß±â ³îÀ̸¦ ÇØº¸ÀÚ. GEF¸¦ ÀÌ¿ë Ÿ¿øÀ» ±×¸®±â À§Çؼ­´Â ÀϹÝÀûÀÎ Àϻ󿡼­ÀÇ Å¸¿ø¿¡ ´ëÇÑ °ü³äÀÌ ÇÊ¿äÇÏ´Ù. Âî±×·¯Áø °ø, ¿©¸§Ã¶ ºÓ°Ô ¹°µç ÇØ, ¼­¾ç ¼ö¹Ú... À̰͵éÀº ½Ã½ºÅÛ¿¡¼­ ´Ù·ç°ÔµÉ ±âº» ¸ðµ¨·Î ¹Ù²ï´Ù. ÀÌ ¸ðµ¨¿¡´Â Ÿ¿øÀÇ ÀϹÝÀûÀÎ Á¤º¸(Å©±â, À§Ä¡ µîµî)¸¦ ±â·ÏÇÒ ¼ö ÀÖ´Â Çʵå·Î ±¸¼º µÈ´Ù. ÇÏÁö¸¸ ÀÌ·¯ÇÑ ±âº» ¸ðµ¨¸¸À» ½Ã½ºÅÛ¿¡ Àû¿ëÇÏ¿© °á°ú¸¦ ¾ò±â¿¡´Â ºÎÁ·ÇÏ´Ù. ¸ðµ¨À» ÀÌ¿ëÇϰíÀÚ ÇÏ´Â ¸ñÀû¿¡ µû¶ó ±âº» ¸ðµ¨À» È®ÀåÇϰųª ºÎ°¡ Á¤º¸¸¦ ºÙÈ÷´Â ÀÛ¾÷ÀÌ ÇÊ¿äÇÏ´Ù. ºä¾î¿¡ ±×¸®´Â ÀÛ¾÷¸¸ ÇØµµ ¾îµð¿¡ ±×¸±°ÍÀΰ¡? ±×¸®´Âµ¥ Á¦¾à(Å©±â, »ö»ó ¹üÀ§)Àº ¹«¾ùÀΰ¡? ¹èÄ¡´Â ¾î¶»°Ô ÇØ¾ßÇϳª? µîµî ½Ã½ºÅÛ¸¸ÀÇ ºÎ°¡ Á¤º¸°¡ ÇÊ¿äÇÏ´Ù. µû¶ó¼­ ƯÁ¤ Ŭ·¡½º¸¦ ÀÌ¿ë ±âº» ¸ðµ¨À» ÀÎÀÚ·Î »ç¿ëÇϰųª ±âº» ¸ðµ¨À» È®ÀåÇÏ¿© ¿ªÇÒÀ» ¼öÇàÇÑ´Ù. Edit Part´Â ¾Æ·¡¿Í °°ÀÌ À̵éÀ» ¿¬°áÇØ ÁÖ´Â ¼±°ú °°Àº ¿ªÇÒÀ» ÇÑ´Ù. ¿©±â ±îÁö ¿ì¸®´Â GEF ¾ÆÅ°ÅØÆ®¿Í ½Ã½ºÅÛ, ÆäÅϵîÀ» ¾Ë¾Æ ¿Ô´Ù. ÀÌÁ¦ Specific Class »ç¿ë¹ý¸¸ ¾Ë¾ÆµÐ ´Ù¸é GEF¸¦ ¸¶À½´ë·Î »ç¿ë ÇÒ ¼ö ÀÖ´Ù. ÆíÁý°ú ÆÈ·§Æ®¸¦ À§ÇÑ Specific Class¸¦ ¾Ë¾Æº¸ÀÚ.

 

Pallete

¿¡µðÅÍ °³¹ßÀÚ°¡ ÆíÁý¿¡ »ç¿ëÇÏ´Â ¿ä¼ÒµéÀ» ³ª¿­Çϰí À̸¦ ¼±Åà ÇÒ ¼ö ÀÖ°Ô Áö¿øÇؾßÇÑ´Ù. ¿ì¼± ¿¡µðÅÍ Å¬·¡½º¿¡ ÆÈ·§Æ® µî·Ï ºÎºÐÀ» »ìÆì º¸ÀÚ. ÇÊÀÚ´Â ÆÈ·§Æ® ¶ÇÇÑ Edit Part¿¡ Àִ°ÍÀÌ ¸Â´Ù°í »ý°¢ÇÏÁö¸¸, Edit Part ClassÀÇ ºñ´ëÈ­¿Í ÆÈ·§Æ® À¯¹«¿¡ µû¸¥ ±âº» ¿¡µðÅÍ Å¬·¡½º ºÐ¸® ¶§¹®¿¡ º°µµÀÇ Å¬·¡½º¸¦ ¸¸µç°Í °°´Ù. ´Ù½Ã ¸» ÇÏÁö¸¸ GEF ¿¡µðÅÍ´Â ¿©·¯°³ÀÇ º¹ÀâÇÑ ÃʱâÈ­°¡ ÇÊ¿äÇÑ ÀνºÅϽº·Î ±¸¼º µÇ¾îÀÖ´Ù. GEF °³¹ßÀÚ´Â ÆÑÅ丮 ÆÐÅÏÀ» ÀÌ¿ëÇß´Ù. ÆÈ·§Æ® ÀÚü¿¡´Â ¾Æ¹«·± °¡º¯ Á¤º¸°¡ ¾ø±â ¶§¹®¿¡ static ÇüÀÌ¿©µµ ¹«°üÇÏ´Ù.

private static PaletteRoot PALETTE_MODEL;

@Override
protected PaletteRoot getPaletteRoot() {
System.err.println("** getPaletteRoot. **");
if (PALETTE_MODEL == null)
PALETTE_MODEL = SimplePaletteFactory.createPalette();
return PALETTE_MODEL;
}

¾Æ·¡ÀÇ Äڵ尡 ¾ø´Ù¸é ÆÈ·§Æ®¸¦ ¼±ÅÃÇϰí Ä˹ö½º¿¡ µå·ÓµÇ´Â °ÍÀ» ¾Ë ¼ö ¾ø°Ô µÈ´Ù. ÆÈ·§Æ®¿Í Ä˹ö½º´Â ¼­·Î ´Ù¸¥ widgetÀ̹ǷΠ´Ù¸¥ À§Á¬ ¿µ¿ªÀÇ À̺¥Æ®¸¦ ¸®½º´× Çϱâ À§ÇÑ ÄÚµå·Î º¸¸é µÈ´Ù. À§ ÄÚµå¿Í ¸¶Âù°¡Áö·Î ÆÈ·§Æ® Áغñ¿¡ ÇÊ¿äÇÑ ±âº» ÄÚµå·Î ÀÎ½Ä ÇÏÀÚ.

protected PaletteViewerProvider createPaletteViewerProvider() {
return new PaletteViewerProvider(getEditDomain()) {
protected void configurePaletteViewer(PaletteViewer viewer) {
super.configurePaletteViewer(viewer);
// create a drag source listener for this palette viewer
// together with an appropriate transfer drop target listener,
// this will enable
// model element creation by dragging a
// CombinatedTemplateCreationEntries
// from the palette into the editor
// @see ShapesEditor#createTransferDropTargetListener()
viewer
.addDragSourceListener(new TemplateTransferDragSourceListener(
viewer));
}
};
}

±×·³ ½ÇÁ¦ PalleteRoot Ŭ·¡½º´Â ¾î¶³±î.

package net.jlab.get.example.editor;

import net.jlab.get.example.editor.model.SimpleModel;

import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
import org.eclipse.gef.palette.MarqueeToolEntry;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteEntry;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.PaletteToolbar;
import org.eclipse.gef.palette.PanningSelectionToolEntry;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gef.requests.SimpleFactory;
import org.eclipse.jface.resource.ImageDescriptor;

final class SimplePaletteFactory {
  static PaletteRoot createPalette() {
    PaletteRoot palette = new PaletteRoot();
    palette.add(createToolsGroup(palette));
    palette.add(createShapesDrawer());
    return palette;
  }

  private static PaletteEntry createToolsGroup(PaletteRoot palette) {
    PaletteToolbar toolbar = new PaletteToolbar("Tools");

    // Add a selection tool to the group
    ToolEntry tool = new PanningSelectionToolEntry();
    toolbar.add(tool);
    palette.setDefaultEntry(tool);
    
    // Add a marquee tool to the group
    toolbar.add(new MarqueeToolEntry());
    return toolbar;
  }
  
  private static PaletteContainer createShapesDrawer() {
    PaletteDrawer componentsDrawer = new PaletteDrawer("Simple");

    CombinedTemplateCreationEntry component = new CombinedTemplateCreationEntry(
        "Ellipse"
        "Create an elliptical shape"
        SimpleModel.class,
        new SimpleFactory(SimpleModel.class)
        ImageDescriptor.createFromFile(SimpleEditor.class, "icons/ellipse16.gif")
        ImageDescriptor.createFromFile(SimpleEditor.class, "icons/ellipse24.gif"));
    componentsDrawer.add(component);

    return componentsDrawer;
  }
}

SimplePalleteFactory.java

ÆÈ·§Æ®´Â À§¿Í °°Àº ±¸Á¶·Î µÆ´Ù. ±âº»ÀûÀÎ ÆíÁý ¿ä¼Ò¸¦ ´ã°í ÀÖ´Â ToolBar¿Í À¯ÀúÇÑ Á¤ÀÇÇÑ ÆíÁý ¿ä¼ÒµéÀ» ±¸·ì º°·Î ºÐ¸®ÇÑ ContainerÀÌ´Ù. À§ÀÇ ±×¸²¿¡¼­´Â SimpleÀ̶ó´Â ±¸·ì¿¡ Ellipse ÆÈ·§Æ® ¿£Æ®¸® Çϳª ¸¸ ÀÖÁö¸¸ Ãß°¡ÀûÀÎ ±¸·ìÀ» ³ÖÀ» ¼ö ÀÖ´Ù.

Åø¹Ù¿¡ ±âº»ÀûÀÎ ÆíÁý ¿ä¼Ò ¼±ÅÃ Åø°ú ¹üÀ§ ¼±ÅÃ ÅøÀ» ³ÖÀº °ÍÀÌ´Ù. ÀÌ ¿Ü¿¡ ¿¬°á¼± Åøµµ ÀÖ´Ù. ÀÌ ÄÚµå´Â ÆÈ·§Æ® ±¸¼º¿¡ À־ ±âº»ÀûÀÎ ÄÚµå¶ó »ý°¢ÇÏÀÚ.

  // Add (solid-line) connection tool 
  tool = new ConnectionCreationToolEntry(
      "Solid connection",
      "Create a solid-line connection",
      new CreationFactory() {
        public Object getNewObject() { return null}
        // see ShapeEditPart#createEditPolicies() 
        // this is abused to transmit the desired line style 
        public Object getObjectType() { return Connection.SOLID_CONNECTION; }
      },
      ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_s16.gif"),
      ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_s24.gif"));
  toolbar.add(tool);
  
  // Add (dashed-line) connection tool
  tool = new ConnectionCreationToolEntry(
      "Dashed connection",
      "Create a dashed-line connection",
      new CreationFactory() {
        public Object getNewObject() { return null}
        // see ShapeEditPart#createEditPolicies()
        // this is abused to transmit the desired line style 
        public Object getObjectType() { return Connection.DASHED_CONNECTION; }
      },
      ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_d16.gif"),
      ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_d24.gif"));
  toolbar.add(tool);

ÆÈ·§Æ® ±¸·ì°ú ¿£Æ®¸®¸¦ µî·Ï ÇÏ´Â ºÎºÐÀÌ´Ù. CombinedTemplateCreationEntryÀÇ 3¹øÂ°ÀÇ ÀÎÀÚ¸¦ ÅëÇØ ÇØ´ç ÆÈ·§Æ®°¡ ¼±ÅõŠÄ˹ö½º ¿µ¿ª¿¡ µå·Ó µÈ´Ù¸é, ÀÌ ÀÎÀÚ¿Í ¿¬°áµÈ ¸í·É¾î¸¦ ã°Ô µÈ´Ù. Ç®¾î¼­ À̾߱â Çϸé Ÿ¿øÀ» ¼±ÅÃÇϰí À̰ÍÀ» ¼±Åà Ä˹ö½º¿¡ µå·Ó Çϸé Ÿ¿øÀ» »ý¼ºÇÏ´Â ¸í·ÉÀ» ã°Ô µÈ´Ù. ConnectionCreationToolEntryÀÇ ¸¶Áö¸· ÀÎÀÚÀÇ 24Çȼ¿ À̹ÌÁöÀÇ ¿ëµµ´Â ¾ÆÁ÷ ¾ø´Â°ÍÀ¸·Î º¸ÀδÙ.

¿©±â ±îÁöÀÇ Äڵ带 ÀÌÀü ¿¹Á¦¿¡ Ãß°¡ ÇÑ´Ù¸é ´ÙÀ½°ú °°Àº ÀÏÀ» ÇÒ ¼ö ÀÖ´Ù.

1. ÆÈ·§Æ® ¿µ¿ª¿¡ ¿£Æ®¸®°¡ º¸ÀδÙ.

2. ÆÈ·§Æ®¸¦ ¼±Åà Çϰí Ä˹ö½º¿¡ µå·ÓÇÑ À̺¥Æ®¸¦ ¾Ë ¼ö ÀÖ´Ù.

 

Edit Policy

GEF¿¡¼­ °¡Àå ÄÚµù·®ÀÌ ¸¹°í º¹ÀâÇÏ¸ç ¹ö±×¸¦ ¸¹ÀÌ ¸¸µå´Â ºÎºÐÀÌ´Ù. ÇÏÁö¸¸ ÇÁ·ÎÁ§Æ®´Â ´Þ¶óµµ Edit Policy¿Í Command´Â °ÅÀÌ ÀÏÁ¤ÇÏ°Ô ¾²ÀÌ´Â Äڵ常 »ç¿ëµÇ¹Ç·Î Çѹø¸¸ Àß¾Ë¾ÆµÎ¸é µÈ´Ù. Pallete SectionÀÇ Äڵ带 ½ÇÇà ÇÏ¸é ÆÈ·§Æ®´Â º¸ÀÌ°í µå·¡±×&µå·Óµµ µÇÁö¸¸ Ä˹ö½º¿¡ ±×·ÁÁö´Â ¸ðµ¨ÀÌ ¾ø´Ù. ¶ÇÇÑ Ä˹ö½º¿¡ ±×·ÁÁø ¸ðµ¨ÀÌ ¾øÀ¸¹Ç·Î ÆíÁý Á¶Â÷ ÇÒ ¼ö ¾ø´Ù. ¿ì¼± ÆÈ·§Æ® ¼±ÅÃÈÄ µå·¡±×&µå·ÓÀ» ÇÏ¸é ¸ðµ¨À» Ä˹ö½º¿¡ ±×¸®´Â(»ý¼ºÇÏ´Â) ÀÛ¾÷À» Ãß°¡·Î ÇØº¸ÀÚ. Àá±ñ Command¿¡ ´ëÇØ ¾ð±Þ ÇÏÀÚ¸é ¿¡µðÅÍ»óÀÇ À¯Àú ¿¢¼Ç(ŸÀÌÇÎ, µå·¡±ë, Ŭ¸¯Å· µî)Àº ¸ðµÎ Äĸǵå·Î °ü¸®µÈ´Ù. À̸¦ ÀÌ¿ë ÇÏ¿© ¸®µÎ&¾ðµÎ(Redo&Undo)¸¦ ±¸Çö ÇÑ´Ù. CommandÀÇ ÁýÇÕÀº ¿¡µðÅͰ¡ °¡Áö°í ÀÖ´Â ±Ùº»ÀûÀÎ ±â´ÉÀÇ ÁýÇÕÀ̶ó ÇÒ ¼ö ÀÖ´Ù. ¿¡µðÅÍ »óÀÇ ¹®ÀÚ¸¦ ÀÔ·ÂÇϰí Áö¿ì°í ¹Ù²Ù°í ÇÏ´Â ¸ðµç ±â´ÉÀº Command·Î Á¤ÀÇ µÈ´Ù. À¯Àú ¿¢¼Ç¿¡ µû¸¥ ¸®¿¢¼ÇÀ¸·Î ƯÁ¤ Äĸǵ尡 ½ÇÇàµÈ´Ù.

À§ ±×¸²Àº ¿ì¸®°¡ ÇϰíÀÚ ÇÏ´Â ÀÛ¾÷ÀÇ °á°ú È­¸éÀÌ´Ù. Ellipse ÆÈ·§Æ®·Î ¼±ÅÃÇÏ°í µå·¡±×&µå·ÓÀ» Çϸé Ÿ¿øÀÌ »ý¼º µÇ´Â°ÍÀÌ´Ù. ÀÌÀü ±îÁöÀÇ ÀÛ¾÷À» ÅëÇØ ÆÈ·§Æ®°¡ º¸ÀÌ°í µå·¡±×&µå·Ó À̺¥Æ®¸¦ ¿¬°áÇß´Ù. ¿©±â¿¡¼­ ¹®Á¦´Â 2°¡Áö ÀÌ´Ù.

1. ÆÈ·§Æ® ¼±Åà ÈÄ µå·¡±×&µå·Ó À̺¥Æ®´Â ´©°¡ ¹Þ´Â°ÍÀΰ¡?

2. ¼±ÅÃµÈ ÆÈ·§Æ®´Â ¾îµð¿¡ »ý¼º ÇÒ °ÍÀΰ¡?

1ÀÇ ´äÀº µå·¡±×&µå·Ó À§Ä¡¿¡ ÀÖ´Â ¸ðµ¨ÀÇ Figure°¡ ¹Þ´Â´Ù. ±×·¡ÇÈÀ» ó¸®ÇÏ´Â Figure°¡ ¹Þ¾Æ¼­ À̸¦ ÇØ´ç ¸ðµ¨ÀÇ EditPolicyÀÇ ÄÁ¸Çµå¿Í ¿¬°áÇÑ´Ù. Ç®¾î¼­ »ý°¢ÇÏÀÚ. À§ ±×¸²¿¡¼­ Ÿ¿øÀÌ ¾ø´Ù°í »ý°¢ÇÏÀÚ. ÆÈ·§Æ®¿¡¼­ Ÿ¿øÀ» ¼±Åà ÈÄ ÇϾá Ä˹ö½º ¿µ¿ª¿¡ µå·¡±×&µå·ÓÀ» Çϸé ÃÖ»óÀÇ ¸ðµ¨ÀÇ Figure°¡ ÅëÁö¸¦ ¹Þ´Â´Ù. ¿ì¸®°¡ º¸´Â µµÈ­Áö°°Àº ÇÏ¾á ¿µ¿ªµµ ¸ðµ¨°ú Edit Part, Figure¸¦ °¡Áö°í ÀÖ´Ù. 2ÀÇ ´äÀº ÀÚ¿¬ ½º·´°Ô ³ª¿Ô´Ù. µå·¡±×&µå·Ó À̺¥Æ®¸¦ ¹ÞÀº ¸ðµ¨¿¡ »ý¼º µÈ´Ù.

À§ ±×¸²Àº µå·¡±×&µå·Ó Á÷ ÈÄ ÃÖ»óÀ§ ¸ðµ¨ÀÎ SimpleDiagramÀÇ ¸Þ¸ð¸® ¸ð½À ÀÌ´Ù.

¿©±â¼­ Àǹ®ÀÌ »ý±ä´Ù ²À ¸ðµ¨ÀÇ µå·¡±×&µå·Ó À̺¥Æ®°¡ ¸ðµ¨ »ý¼º ¸í·É°ú ¿¬°áµÇ¾î¾ß ÇÒ±î. ¹°·Ð ¾Æ´Ï´Ù. Edit Policy°¡ ±×·¸°Ô Á¤ÀǵƱ⠶§¹®ÀÌ´Ù. Edit Policy°¡ Ãß°¡µÈ SimpleDaigramEditPart¸¦ »ìÆì º¸ÀÚ.

package net.jlab.get.example.editor.edit;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;

import net.jlab.get.example.editor.command.ShapeSetConstraintCommand;
import net.jlab.get.example.editor.command.SimpleModelCreateCommand;
import net.jlab.get.example.editor.model.SimpleDiagram;
import net.jlab.get.example.editor.model.SimpleModel;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.FreeformLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.editpolicies.RootComponentEditPolicy;
import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gef.requests.CreateRequest;

public class SimpleDiagramEditPart extends AbstractGraphicalEditPart implements
    PropertyChangeListener {

  /**
   * Upon activation, attach to the model element as a property change
   * listener.
   */
  public void activate() {
    if (!isActive()) {
      super.activate();
      ((SimpleModelgetModel()).addPropertyChangeListener(this);
    }
  }

  /**
   * Upon deactivation, detach from the model element as a property change
   * listener.
   */
  public void deactivate() {
    if (isActive()) {
      super.deactivate();
      ((SimpleModelgetModel()).removePropertyChangeListener(this);
    }
  }

  @Override
  public void propertyChange(PropertyChangeEvent evt) {
    String prop = evt.getPropertyName();
    if (SimpleDiagram.CHILD_ADDED_PROP.equals(prop)
        || SimpleDiagram.CHILD_REMOVED_PROP.equals(prop)) {
      refreshChildren();
    }

  }

  @Override
  protected IFigure createFigure() {
    Figure f = new FreeformLayer();
    f.setBorder(new MarginBorder(3));
    f.setLayoutManager(new FreeformLayout());

    return f;
  }

  @Override
  protected void createEditPolicies() {
    installEditPolicy(EditPolicy.COMPONENT_ROLE,
        new RootComponentEditPolicy());
    installEditPolicy(EditPolicy.LAYOUT_ROLE,
        new SimpleXYLayoutEditPolicy());
  }

  /**
   * EditPolicy for the Figure used by this edit part. Children of
   * XYLayoutEditPolicy can be used in Figures with XYLayout.
   
   @author Elias Volanakis
   */
  private static class SimpleXYLayoutEditPolicy extends XYLayoutEditPolicy {

    /*
     * (non-Javadoc)
     
     * @seeConstrainedLayoutEditPolicy#createChangeConstraintCommand(
     * ChangeBoundsRequest, EditPart, Object)
     */
    protected Command createChangeConstraintCommand(
        ChangeBoundsRequest request, EditPart child, Object constraint) {
      if (child instanceof SimpleModelEditPart
          && constraint instanceof Rectangle) {
        return new SimpleSetConstraintCommand((SimpleModel) child
            .getModel(), request, (Rectangleconstraint);
      }
      return super.createChangeConstraintCommand(request, child,
          constraint);
    }

    /*
     * (non-Javadoc)
     
     * @see
     * ConstrainedLayoutEditPolicy#createChangeConstraintCommand(EditPart,
     * Object)
     */
    protected Command createChangeConstraintCommand(EditPart child,
        Object constraint) {
      // not used in this example
      return null;
    }

    /*
     * (non-Javadoc)
     
     * @see LayoutEditPolicy#getCreateCommand(CreateRequest)
     */
    protected Command getCreateCommand(CreateRequest request) {
      Object childClass = request.getNewObjectType();
      if (childClass == SimpleModel.class) {
        return new SimpleModelCreateCommand((SimpleModelrequest
            .getNewObject()(SimpleDiagramgetHost().getModel(),
            (RectanglegetConstraintFor(request));
      }
      return null;
    }

  }

  /*
   * (non-Javadoc)
   
   * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren()
   */
  protected List getModelChildren() {
    return ((SimpleDiagramgetModel()).getChildren();
  }

}

SimpleDiagramEditPart.java

EditPolicy´Â ÇÁ·ÎÆÛƼ¿Í °°Àº Key/Value¸¦ °®´Â Å×ÀÌºí ±¸Á¶·Î µÇ¾î ÀÖ´Ù.

installEditPolicy(EditPolicy.COMPONENT_ROLE,
new RootComponentEditPolicy());

SimpleDiagramÀº ÃÖ»óÀÇ ¸ðµ¨ ÀÓÀ¸·Î »èÁ¦ µÇ°Å³ª Å©±â°¡ ¹Ù²î¾î¼­´Â ¾ÈµÈ´Ù. ÀÌ ¶§¹®¿¡ COMPONENT_ROLEÀ» À§¿Í °°ÀÌ ÁöÁ¤ Çß´Ù.

installEditPolicy(EditPolicy.LAYOUT_ROLE,
new SimpleXYLayoutEditPolicy());

SimpleDaigram ¿µ¿ª¿¡ ¹èÄ¡ µÉ ¸ðµ¨¿¡ ´ëÇÑ Á¦ÇÑÀ» ¼±¾ðÇß´Ù. Á¦ÇÑÀÇ ±¸Ã¼ÀûÀÎ ³»¿ëÀº SimpleXYLayoutEditPolicy¿¡ µé¾î ÀÖ´Ù.

SimpleXYLayoutEditPolicyÀÇ ³»¿ëÀº SimpleDiagram ³»¿¡ ÀÖ´Â ¸ðµ¨ÀÇ »ý¼º°ú Å©±â º¯°æ¿¡ ´ëÇÑ ³»¿ë ÀÌ´Ù. À̰͵µ ÀϹÝÀûÀÎ ÄÚµåÀÌ´Ù °ÅÀÌ ±×´ë·Î ¾²ÀδÙ. CommandÀÇ ±¸Ã¼ÀûÀÎ ³»¿ëÀº ÇÁ·ÎÁ§Æ® ¼Ò½º¸¦ º¸±â ¹Ù¶õ´Ù. Ưº°È÷ ¾÷±ÞÇÒ ³»¿ëÀÌ ¾ø´Ù. ¿©±â ±îÁö °úÁ¤À¸·Î ¿ì¸®°¡ ¸¸µç ¿¡µðÅÍ´Â ´ÙÀ½°ú °°Àº ÀÏÀ» ÇÒ ¼ö ÀÖ´Ù.

1.ÃÖ»óÀÇ ¸ðµ¨(SimpleDiagram)Àº ¸ðµ¨À» »ðÀÔ ÇÒ Áغñ°¡ µÇ¾î ÀÖ´Ù.

2.ÃÖ»óÀÇ ¸ðµ¨ÀÇ ÀÓÀÇÀÇ ¿µ¿ª¿¡ ¸ðµ¨À» ¹èÄ¡ ÇÒ ¼ö ÀÖ´Â ·¹À̾ƿôÀÌ Áغñ µÇ¾î ÀÖ´Ù.

 

Detecting & Firing

ÀÌ ºÎºÐÀº ÇÊÀÚ°¡ GEF¸¦ óÀ½ Á¢ÇÒ¶§ ÀÌÀ¯¸¦ ¸ô¶ó ¾Ö¸ÔÀº ºÎºÐÀÌ´Ù. GEF¸¦ ÅëÇÑ ¸ðµ¨ÀÇ º¯È­(¸ðµ¨ ±¸Á¶ÀÇ º¯È­°¡ ¾Æ´Ñ °ªÀÇ º¯È­)¿Í À̸¦ ÅëÁö ÇÏ´Â ¹æ¹ýÀÌ´Ù.

À§ ±×¸²¿¡¼­ È­»ìÇ¥¸¦ ¿ªÀ¸·Î µû¶ó°¡ÀÚ. Ÿ¿øÀÇ Å©±â¸¦ ¹Ù²Ù¸é Figure¸¦ ÅëÇØ À̺¥Æ®°¡ ¹ß»ý ÇÏ°í °á°úÀûÀ¸·Î´Â Ellipse ¸ðµ¨ÀÇ »çÀÌÁî °ªÀÌ ¹Ù²î°Ô µÈ´Ù. ´ç¿¬ ÇÏ´Ù°í ¸» ÇÒ ¼ö ÀÖÁö¸¸ ¸ðµ¨ÀÇ º¯È­¸¦ °¨ÁöÇϰí À̸¦ ó¸®ÇÏ´Â Äڵ尡 ¾ø´Ù¸é GEF ¿¡µðÅÍ »ó¿¡¼­ ¾Æ¹«·± º¯È­°¡ ÀϾÁö ¾Ê´Â´Ù. ÇÊÀÚ´Â ÀÌ °úÁ¤µµ ÀÚµ¿À¸·Î GEF°¡ ó¸® ÇÒ °ÍÀ̶ó »ý°¢ Çß´Ù.

À§ÀÇ ½ÃÄö½º ´ÙÀ̾Ʊ׷¥ ó·³ ¸ðµ¨ÀÇ º¯È­´Â GEF°¡ ó¸® ÇÏÁö¸¸ Çǵå¹éÀº GEF°¡ ó¸®ÇØ ÁÖÁö ¾Ê´Â´Ù. ÄÚµå »óÀº ´ÙÀ½°ú °°´Ù.

package net.jlab.get.example.editor.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;

public class SimpleModel {
  /** Property ID to use when the location of this shape is modified. */
  public static final String LOCATION_PROP = "Shape.Location";
  /** Property ID to use then the size of this shape is modified. */
  public static final String SIZE_PROP = "Shape.Size";
  
  private int type;
  public void setType(int type) {
    this.type = type;
  }
  public int getType() {
    return type;
  }
  
  private String content;
  public String getContent() {
    return content;
  }
  public void setContent(String content) {
    this.content = content;
  }
  
  /** Location of this shape. */
  private Point location = new Point(00);
  /** Size of this shape. */
  private Dimension size = new Dimension(5050);
  
  public Dimension getSize() {
    return size;
  }
  public void setSize(Dimension size) {
    this.size=size;
    firePropertyChange(SIZE_PROP, null, size);
    
  }
  public Point getLocation() {
    return location;
  }
  public void setLocation(Point location) {
    this.location=location;
    firePropertyChange(LOCATION_PROP, null, location);
    
  }
  
  private transient PropertyChangeSupport pcsDelegate = new PropertyChangeSupport(this);

  /** 
   * Attach a non-null PropertyChangeListener to this object.
   @param l a non-null PropertyChangeListener instance
   @throws IllegalArgumentException if the parameter is null
   */
  public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
    if (l == null) {
      throw new IllegalArgumentException();
    }
    pcsDelegate.addPropertyChangeListener(l);
  }
  
  /** 
   * Remove a PropertyChangeListener from this component.
   @param l a PropertyChangeListener instance
   */
  public synchronized void removePropertyChangeListener(PropertyChangeListener l) {
    if (l != null) {
      pcsDelegate.removePropertyChangeListener(l);
    }
  }

  /** 
   * Report a property change to registered listeners (for example edit parts).
   @param property the programmatic name of the property that changed
   @param oldValue the old value of this property
   @param newValue the new value of this property
   */
  protected void firePropertyChange(String property, Object oldValue, Object newValue) {
    if (pcsDelegate.hasListeners(property)) {
      pcsDelegate.firePropertyChange(property, oldValue, newValue);
    }
  }
}

SimpleModel.java

package net.jlab.get.example.editor.edit;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import net.jlab.get.example.editor.model.SimpleModel;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.NodeEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;


public class SimpleModelEditPart extends AbstractGraphicalEditPart implements
    NodeEditPart, PropertyChangeListener {


  /*
   * (non-Javadoc)
   
   * @seejava.beans.PropertyChangeListener#propertyChange(java.beans.
   * PropertyChangeEvent)
   */
  public void propertyChange(PropertyChangeEvent evt) {
    String prop = evt.getPropertyName();
    if (SimpleModel.SIZE_PROP.equals(prop)
        || SimpleModel.LOCATION_PROP.equals(prop)) {
      refreshVisuals();
    }
  }

  /**
   * Upon activation, attach to the model element as a property change
   * listener.
   */
  public void activate() {
    if (!isActive()) {
      super.activate();
      ((SimpleModelgetModel()).addPropertyChangeListener(this);
    }
  }

  /**
   * Upon deactivation, detach from the model element as a property change
   * listener.
   */
  public void deactivate() {
    if (isActive()) {
      super.deactivate();
      ((SimpleModelgetModel()).removePropertyChangeListener(this);
    }
  }

  private SimpleModel getCastedModel() {
    return (SimpleModelgetModel();
  }

  protected void refreshVisuals() {
    // notify parent container of changed position & location
    // if this line is removed, the XYLayoutManager used by the parent
    // container
    // (the Figure of the ShapesDiagramEditPart), will not know the bounds
    // of this figure
    // and will not draw it correctly.
    Rectangle bounds = new Rectangle(getCastedModel().getLocation(),
        getCastedModel().getSize());
    ((GraphicalEditPartgetParent()).setLayoutConstraint(this,
        getFigure(), bounds);
  }


}

SimpleModelEditPart.java

 

´ÙÀ½ ±â»ç¿¡¼­´Â Connection°ú Component Layout¿¡ ´ëÇØ ¾Ë¾Æº»´Ù.

°ü·Ã Á¦ÀÌ·¦ ±â»ç
Áö´Ï°¡ GEF¸¦ ¸¸³µÀ» ¶§ 1 http://www.jlab.net/news/20051107/news.htm
Áö´Ï°¡ GEF¸¦ ¸¸³µÀ» ¶§ 2 http://www.jlab.net/news/20051206/news.htm
Áö´Ï°¡ GEF¸¦ ¸¸³µÀ» ¶§ 1 (Renewer) http://www.jlab.net/news/20081023/news.htm
Áö´Ï°¡ GEF¸¦ ¸¸³µÀ» ¶§ 2 (Renewer) http://www.jlab.net/news/20081028/news.htm

 

Á¤º¸
ÀÌ ±â»ç´Â 2005³âµµÀÇ ±â»ç¸¦ ÀçÆíÁý ÇÏ¿© ¿¬ÀçÇÏ´Â ±â»çÀÔ´Ï´Ù.
¿¹Á¦ ÇÁ·ÎÁ§Æ® ´Ù¿î·Îµå

 


About Author

Çã¿øÁø

Á¦ÀÌ·¦ ´ëÇ¥ ¿î¿µÀÚ, Total Eclipse ´ëÇ¥ ÀúÀÚ, Eclipse Consultant, Juliet Scandal Project Leader. ÀÌŬ¸³½º ÇÁ·ÎÁ§Æ®µéÀ» Àû±Ø ÀÌ¿ëÇØ¼­ Àúºñ¿ëÀ¸·Î Äè¼Ó°³¹ßÀ» Çϴµ¥ °ü½ÉÀÌ ¸¹´Ù. Contact


www.jlab.net

ÀÌ ÄÁÅÙÃ÷´Â JPL¿¡ ÀÇÇØ¼­ º¸È£ ¹Þ½À´Ï´Ù. ¿ÀÅ» ÀÚ³ª °ÇÀÇ´Â À̰÷¿¡ ÇØÁֽʽÿÀ