KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > command > DeleteLayerCommand


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * Project author: Daniel Mazurek <Daniel.Mazurek [at] nightlabs [dot] org> *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin St, Fifth Floor, *
20  * Boston, MA 02110-1301 USA *
21  * *
22  * Or get it online : *
23  * http://www.gnu.org/copyleft/lesser.html *
24  * *
25  * *
26  ******************************************************************************/

27
28 package org.nightlabs.editor2d.command;
29
30 import org.nightlabs.editor2d.EditorPlugin;
31 import org.nightlabs.editor2d.Layer;
32 import org.nightlabs.editor2d.MultiLayerDrawComponent;
33
34
35 public class DeleteLayerCommand
36 //extends Command
37
extends DeleteDrawComponentCommand
38 {
39     /** the Deletion String */
40     public static final String JavaDoc DELETE_LAYER = EditorPlugin.getResourceString("command.delete.layer");
41     /**
42      * Create a command that will remove the shape from its parent.
43      * @param parent the ShapesDiagram containing the child
44      * @param child the Shape to remove
45      * @throws IllegalArgumentException if any parameter is null
46      */

47     public DeleteLayerCommand(MultiLayerDrawComponent mldc, Layer layer)
48     {
49         super(mldc, layer);
50         setLabel(DELETE_LAYER);
51     }
52         
53     /* (non-Javadoc)
54      * @see org.eclipse.gef.commands.Command#execute()
55      */

56     public void execute()
57     {
58         super.execute();
59         setCurrentLayer();
60     }
61     
62     /* (non-Javadoc)
63      * @see org.eclipse.gef.commands.Command#redo()
64      */

65     public void redo()
66     {
67         super.redo();
68       setCurrentLayer();
69     }
70     
71     /* (non-Javadoc)
72      * @see org.eclipse.gef.commands.Command#undo()
73      */

74     public void undo()
75     {
76         super.undo();
77       getMultiLayerDrawComponent().setCurrentLayer(getLayer());
78     }
79     
80     protected void setCurrentLayer()
81     {
82     if (index != 0) {
83         getMultiLayerDrawComponent().setCurrentLayer((Layer) parent.getDrawComponents().get(index-1));
84     } else if ( index==0 && parent.getDrawComponents().size() > 2) {
85         getMultiLayerDrawComponent().setCurrentLayer((Layer) parent.getDrawComponents().get(index+1));
86     }
87     }
88     
89     public MultiLayerDrawComponent getMultiLayerDrawComponent() {
90       return (MultiLayerDrawComponent) parent;
91     }
92     
93     public Layer getLayer() {
94         return (Layer) child;
95     }
96 }
97
Popular Tags