1 26 package org.nightlabs.editor2d.command; 27 28 import java.awt.Rectangle ; 29 30 import org.eclipse.gef.commands.Command; 31 import org.nightlabs.editor2d.DrawComponent; 32 import org.nightlabs.editor2d.DrawComponentContainer; 33 import org.nightlabs.editor2d.EditorPlugin; 34 35 38 public class CloneDrawComponentCommand 39 extends Command 40 { 41 42 47 public CloneDrawComponentCommand(DrawComponent source, DrawComponentContainer parent) 48 { 49 super(); 50 setLabel(EditorPlugin.getResourceString("command.clone.text")); 51 this.drawComponent = source; 52 this.parent = parent; 53 } 54 55 protected DrawComponent drawComponent = null; 56 public void setDrawComponent(DrawComponent dc) { 57 this.drawComponent = dc; 58 } 59 public DrawComponent getDrawComponent() { 60 return drawComponent; 61 } 62 63 protected DrawComponentContainer parent = null; 64 public DrawComponentContainer getParent() { 65 return parent; 66 } 67 public void setParent(DrawComponentContainer parent) { 68 this.parent = parent; 69 } 70 71 protected String cloneName = null; 72 76 public String getCloneName() 77 { 78 if (cloneName == null) { 79 if (drawComponent != null) { 80 cloneName = drawComponent.getName() + " " + getCopyString(); 81 } else { 82 cloneName = getCopyString(); 83 } 84 } 85 return cloneName; 86 } 87 91 public void setCloneName(String cloneName) { 92 this.cloneName = cloneName; 93 } 94 95 protected static final Rectangle DEFAULT_CLONE_BOUNDS = new Rectangle (0, 0, 10, 10); 96 97 protected Rectangle cloneBounds = null; 98 public Rectangle getCloneBounds() 99 { 100 if (cloneBounds == null) 101 { 102 if (drawComponent != null) { 103 cloneBounds = new Rectangle (drawComponent.getBounds()); 104 } 105 else { 106 cloneBounds = DEFAULT_CLONE_BOUNDS; 107 } 108 } 109 return cloneBounds; 110 } 111 public void setCloneBounds(Rectangle cloneBounds) { 112 this.cloneBounds = cloneBounds; 113 } 114 115 protected DrawComponent clone = null; 116 117 128 public void execute() 129 { 130 clone = (DrawComponent) drawComponent.clone(getParent()); 131 clone.setName(getCloneName()); 132 clone.setBounds(getCloneBounds()); 133 } 134 135 public void redo() 136 { 137 parent.addDrawComponent(clone); 138 } 139 140 public void undo() 141 { 142 parent.removeDrawComponent(clone); 143 } 144 145 protected String getCopyString() 146 { 147 return "("+EditorPlugin.getResourceString("action.clone.text")+")"; 148 } 149 150 } 151 | Popular Tags |