KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > command > DeleteDrawComponentCommand


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 26.10.2004 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

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     /** The DrawComponent to delete */
20     private DrawComponent child;
21     
22     /** MultiLayerDrawComponent to removed from. */
23     private final DrawComponentContainer parent;
24   
25     /** the DrawComponentsIndex of the DrawComponentContainer */
26     private int index;
27     
28     /** True, if child was removed from its parent. */
29     private boolean wasRemoved;
30
31     /** the Deletion String */
32     public static final String JavaDoc DELETE_DRAWCOMPONENT = EditorPlugin.getResourceString("command_delete_drawcomponent");
33   
34     /**
35      * Create a command that will remove the shape from its parent.
36      * @param parent the ShapesDiagram containing the child
37      * @param child the Shape to remove
38      * @throws IllegalArgumentException if any parameter is null
39      */

40     public DeleteDrawComponentCommand(DrawComponentContainer parent, DrawComponent child)
41     {
42         if (parent == null || child == null) {
43             throw new IllegalArgumentException JavaDoc();
44         }
45         setLabel(DELETE_DRAWCOMPONENT);
46         this.parent = parent;
47         this.child = child;
48     }
49     
50     /* (non-Javadoc)
51      * @see org.eclipse.gef.commands.Command#canUndo()
52      */

53     public boolean canUndo() {
54         return wasRemoved;
55     }
56     
57     /* (non-Javadoc)
58      * @see org.eclipse.gef.commands.Command#execute()
59      */

60     public void execute()
61     {
62       // TODO: change DeleteDrawComponent to previous version,
63
// this may solve the layer selection
64
index = parent.getDrawComponents().indexOf(child);
65 // wasRemoved = parent.getDrawComponents().remove(child);
66
parent.removeDrawComponent(child);
67     wasRemoved = true;
68     }
69     
70     /* (non-Javadoc)
71      * @see org.eclipse.gef.commands.Command#redo()
72      */

73     public void redo()
74     {
75 // parent.getDrawComponents().remove(index);
76
parent.removeDrawComponent(index);
77     }
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.gef.commands.Command#undo()
81      */

82     public void undo()
83     {
84 // parent.getDrawComponents().add(index, child);
85
parent.addDrawComponent(child, index);
86     }
87     
88 }
Popular Tags