1 8 package com.nightlabs.editor2d.command; 9 10 import org.eclipse.gef.commands.Command; 11 12 import com.nightlabs.editor2d.DrawComponent; 13 import com.nightlabs.editor2d.DrawComponentContainer; 14 import com.nightlabs.editor2d.EditorPlugin; 15 16 public class DeleteDrawComponentCommand 17 extends Command 18 { 19 20 private DrawComponent child; 21 22 23 private final DrawComponentContainer parent; 24 25 26 private int index; 27 28 29 private boolean wasRemoved; 30 31 32 public static final String DELETE_DRAWCOMPONENT = EditorPlugin.getResourceString("command_delete_drawcomponent"); 33 34 40 public DeleteDrawComponentCommand(DrawComponentContainer parent, DrawComponent child) 41 { 42 if (parent == null || child == null) { 43 throw new IllegalArgumentException (); 44 } 45 setLabel(DELETE_DRAWCOMPONENT); 46 this.parent = parent; 47 this.child = child; 48 } 49 50 53 public boolean canUndo() { 54 return wasRemoved; 55 } 56 57 60 public void execute() 61 { 62 index = parent.getDrawComponents().indexOf(child); 65 parent.removeDrawComponent(child); 67 wasRemoved = true; 68 } 69 70 73 public void redo() 74 { 75 parent.removeDrawComponent(index); 77 } 78 79 82 public void undo() 83 { 84 parent.addDrawComponent(child, index); 86 } 87 88 } | Popular Tags |