1 27 28 package org.nightlabs.editor2d.command; 29 30 import org.apache.log4j.Logger; 31 import org.eclipse.draw2d.geometry.Rectangle; 32 import org.eclipse.gef.commands.Command; 33 34 import org.nightlabs.editor2d.DrawComponent; 35 import org.nightlabs.editor2d.DrawComponentContainer; 36 import org.nightlabs.editor2d.EditorPlugin; 37 import org.nightlabs.editor2d.util.J2DUtil; 38 39 public class CreateDrawComponentCommand 40 extends Command 41 { 42 public static final Logger LOGGER = Logger.getLogger(CreateDrawComponentCommand.class); 43 44 45 protected DrawComponent drawComponent; 46 47 protected DrawComponentContainer parent; 48 49 protected boolean shapeAdded; 50 51 protected int drawOrderIndex; 52 53 protected Rectangle rect; 54 55 62 public CreateDrawComponentCommand() 63 { 64 super(EditorPlugin.getResourceString("command.create.drawcomponent")); 65 } 66 67 public CreateDrawComponentCommand(String name) 68 { 69 super(name); 70 } 71 72 75 public boolean canUndo() { 76 return shapeAdded; 77 } 78 79 82 public void execute() 83 { 84 drawComponent.setBounds(J2DUtil.toAWTRectangle(rect)); 85 86 parent.addDrawComponent(drawComponent); 87 shapeAdded = true; 88 drawOrderIndex = parent.getDrawComponents().indexOf(drawComponent); 89 90 if (drawComponent instanceof DrawComponentContainer) { 91 ((DrawComponentContainer)drawComponent).setParent(parent); 92 } 93 } 94 95 98 public void redo() { 99 parent.addDrawComponent(drawComponent, drawOrderIndex); 100 } 101 102 105 public void undo() { 106 parent.removeDrawComponent(drawComponent); 107 } 108 109 public void setParent(DrawComponentContainer newParent) { 110 parent = newParent; 111 } 112 113 public void setLocation(Rectangle r) { 114 rect = r; 115 } 116 117 public void setChild(DrawComponent dc) { 118 drawComponent = dc; 119 } 120 121 public DrawComponent getChild() { 122 return drawComponent; 123 } 124 125 public void setIndex(int index) { 126 this.drawOrderIndex = index; 127 } 128 } 129 | Popular Tags |