1 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 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 ("Param parent (MultiLayerDrawComponent) must not be null!"); 34 } 35 36 this.parent = parent; 37 setLabel(EditorPlugin.getResourceString("command_create_layer")); 38 } 39 40 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 } 59 60 63 public void redo() 64 { 65 super.redo(); 66 getMultiLayerDrawComponent().setCurrentLayer(getLayer()); 67 } 68 69 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 |