1 8 package com.nightlabs.editor2d.command; 9 10 import java.awt.Font ; 11 12 import org.eclipse.draw2d.geometry.Rectangle; 13 import org.eclipse.gef.commands.Command; 14 15 import com.nightlabs.editor2d.DrawComponentContainer; 16 import com.nightlabs.editor2d.EditorPlugin; 17 import com.nightlabs.editor2d.TextDrawComponent; 18 import com.nightlabs.editor2d.impl.TextDrawComponentImpl; 19 import com.nightlabs.editor2d.request.TextCreateRequest; 20 21 public class CreateTextCommand 22 extends Command 23 { 24 25 protected DrawComponentContainer parent; 26 public void setParent(DrawComponentContainer parent) { 27 this.parent = parent; 28 } 29 30 protected Rectangle rect; 31 public void setLocation(Rectangle rect) { 32 this.rect = rect; 33 } 34 protected Rectangle getLocation() { 35 return rect; 36 } 37 38 protected boolean shapeAdded; 39 protected int drawOrderIndex; 40 protected TextCreateRequest request; 41 42 public CreateTextCommand(TextCreateRequest request) 43 { 44 super(); 45 setLabel(EditorPlugin.getResourceString("command.create.text")); 46 this.request = request; 47 this.textDrawComponent = (TextDrawComponent) request.getNewObject(); 48 } 49 50 protected TextDrawComponent textDrawComponent; 51 public void execute() 52 { 53 int x = getLocation().x; 54 int y = getLocation().y; 55 Font newFont = new Font (request.getFontName(), request.getFontStyle(), request.getFontSize()); 56 textDrawComponent = new TextDrawComponentImpl(request.getText(), newFont, x, y); 57 58 parent.addDrawComponent(textDrawComponent); 59 textDrawComponent.setName(request.getText()); 60 shapeAdded = true; 61 drawOrderIndex = parent.getDrawComponents().indexOf(textDrawComponent); 62 } 63 64 public void redo() 65 { 66 parent.addDrawComponent(textDrawComponent, drawOrderIndex); 67 } 68 69 72 public void undo() 73 { 74 parent.removeDrawComponent(textDrawComponent); 75 } 76 77 } 78 | Popular Tags |