1 26 package org.nightlabs.editor2d.actions; 27 28 import java.awt.Rectangle ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 32 import org.eclipse.gef.commands.Command; 33 import org.eclipse.gef.commands.CompoundCommand; 34 import org.nightlabs.config.Config; 35 import org.nightlabs.config.ConfigException; 36 import org.nightlabs.editor2d.AbstractEditor; 37 import org.nightlabs.editor2d.DrawComponent; 38 import org.nightlabs.editor2d.EditorPlugin; 39 import org.nightlabs.editor2d.command.CloneDrawComponentCommand; 40 import org.nightlabs.editor2d.command.CreateDrawComponentCommand; 41 import org.nightlabs.editor2d.config.QuickOptionsConfigModule; 42 43 46 public class CloneAction 47 extends AbstractEditorSelectionAction 48 { 49 public static final String ID = CloneAction.class.getName(); 50 51 55 public CloneAction(AbstractEditor part, int style) { 56 super(part, style); 57 } 58 59 62 public CloneAction(AbstractEditor part) { 63 super(part); 64 } 65 66 protected void init() 67 { 68 super.init(); 69 setText(EditorPlugin.getResourceString("action.clone.text")); 70 setToolTipText(EditorPlugin.getResourceString("action.clone.tooltip")); 71 setId(ID); 72 initConfigModule(); 74 } 75 76 protected QuickOptionsConfigModule confMod = null; 77 protected QuickOptionsConfigModule getConfigModule() 78 { 79 if (confMod == null) 80 initConfigModule(); 81 82 return confMod; 83 } 84 85 protected void initConfigModule() 86 { 87 try { 88 confMod = (QuickOptionsConfigModule) Config.sharedInstance().createConfigModule(QuickOptionsConfigModule.class); 89 } catch (ConfigException e) { 90 throw new RuntimeException (e); 91 } 92 } 93 94 97 protected boolean calculateEnabled() { 98 return !getDefaultSelection(false).isEmpty(); 99 } 100 101 124 128 public void run() 129 { 130 List dcs = getSelection(DrawComponent.class, true); 131 CompoundCommand cmd = new CompoundCommand(); 132 for (Iterator it = dcs.iterator(); it.hasNext(); ) 133 { 134 DrawComponent dc = (DrawComponent) it.next(); 135 CloneDrawComponentCommand cloneCmd = new CloneDrawComponentCommand(dc, dc.getParent()); 136 int distX = getConfigModule().getCloneDistanceX(); 137 int distY = getConfigModule().getCloneDistanceY(); 138 if (distX != 0 || distY != 0) { 139 Rectangle dcBounds = new Rectangle (dc.getBounds()); 140 dcBounds.setLocation(dcBounds.x + distX, dcBounds.y + distY); 141 cloneCmd.setCloneBounds(dcBounds); 142 } 143 cmd.add(cloneCmd); 144 } 145 execute(cmd); 146 } 147 148 } 149 | Popular Tags |