1 26 package org.nightlabs.editor2d.actions; 27 28 import java.awt.geom.AffineTransform ; 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.editor2d.AbstractEditor; 35 import org.nightlabs.editor2d.DrawComponent; 36 import org.nightlabs.editor2d.EditorPlugin; 37 import org.nightlabs.editor2d.command.CreateDrawComponentCommand; 38 39 42 public class MirrorAction 43 extends AbstractEditorSelectionAction 44 { 45 public static final String ID = MirrorAction.class.getName(); 46 47 51 public MirrorAction(AbstractEditor editor, int style) { 52 super(editor, style); 53 } 54 55 58 public MirrorAction(AbstractEditor editor) { 59 super(editor); 60 } 61 62 protected void init() 63 { 64 super.init(); 65 setText(EditorPlugin.getResourceString("action.mirror.text")); 66 setToolTipText(EditorPlugin.getResourceString("action.mirror.tooltip")); 67 setId(ID); 68 } 69 70 77 80 protected boolean calculateEnabled() { 81 return !getDefaultSelection(false).isEmpty(); 82 } 83 84 public void run() 85 { 86 List dcs = getSelection(DrawComponent.class, true); 87 Command cmd = new CompoundCommand(); 88 for (Iterator it = dcs.iterator(); it.hasNext(); ) { 89 DrawComponent dc = (DrawComponent) it.next(); 90 CreateDrawComponentCommand createCmd = new CreateDrawComponentCommand(); 91 DrawComponent clone = (DrawComponent) dc.clone(); 92 AffineTransform at = new AffineTransform (); 93 clone.setName(clone.getName() + getCopyString()); 95 createCmd.setChild(clone); 96 createCmd.setParent(dc.getParent()); 97 98 cmd.chain(createCmd); 99 } 100 execute(cmd); 101 } 102 103 protected String getCopyString() 104 { 105 return " ("+EditorPlugin.getResourceString("action.copy.text")+")"; 106 } 107 } 108 | Popular Tags |