KickJava   Java API By Example, From Geeks To Geeks.

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


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: 16.11.2004 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.command;
9
10 import org.apache.log4j.Logger;
11
12 import com.nightlabs.editor2d.Editor2DFactory;
13 import com.nightlabs.editor2d.EditorPlugin;
14 import com.nightlabs.editor2d.Layer;
15 import com.nightlabs.editor2d.MultiLayerDrawComponent;
16
17
18 public class CreateLayerCommand
19 extends CreateDrawComponentCommand
20 {
21   public static final Logger LOGGER = Logger.getLogger(CreateLayerCommand.class);
22   
23   private static final String JavaDoc LAYER_DEFAULT_NAME = EditorPlugin.getResourceString("layer_default_name");
24     
25     private int layerCount = 0;
26     protected int nextLayerCount() {
27       return layerCount++;
28     }
29      
30     public CreateLayerCommand(MultiLayerDrawComponent parent)
31     {
32         if (parent == null) {
33             throw new IllegalArgumentException JavaDoc("Param parent (MultiLayerDrawComponent) must not be null!");
34         }
35       
36       this.parent = parent;
37       setLabel(EditorPlugin.getResourceString("command_create_layer"));
38     }
39     
40     /* (non-Javadoc)
41      * @see org.eclipse.gef.commands.Command#execute()
42      */

43     public void execute()
44     {
45       drawComponent = Editor2DFactory.eINSTANCE.createLayer();
46       
47     getLayer().setParent(getMultiLayerDrawComponent());
48         drawOrderIndex = getMultiLayerDrawComponent().getDrawComponents().indexOf(
49         getMultiLayerDrawComponent().getCurrentLayer()) + 1;
50     getMultiLayerDrawComponent().addDrawComponent(getLayer(), drawOrderIndex);
51         shapeAdded = true;
52         if (layerCount == 0) {
53           layerCount = getMultiLayerDrawComponent().getDrawComponents().size();
54         }
55     getMultiLayerDrawComponent().setCurrentLayer(getLayer());
56     // TODO should come from somewhere else
57
// getLayer().setName(LAYER_DEFAULT_NAME + nextLayerCount());
58
}
59     
60     /* (non-Javadoc)
61      * @see org.eclipse.gef.commands.Command#redo()
62      */

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

72     public void undo()
73     {
74     super.undo();
75         layerCount--;
76     }
77         
78     protected MultiLayerDrawComponent getMultiLayerDrawComponent() {
79       return (MultiLayerDrawComponent) parent;
80     }
81   
82   protected Layer getLayer() {
83     return (Layer) drawComponent;
84   }
85 }
86
Popular Tags