1 27 28 package org.nightlabs.editor2d.command; 29 30 import java.awt.Font ; 31 32 import org.eclipse.draw2d.geometry.Rectangle; 33 import org.eclipse.gef.commands.Command; 34 35 import org.nightlabs.editor2d.DrawComponentContainer; 36 import org.nightlabs.editor2d.EditorPlugin; 37 import org.nightlabs.editor2d.TextDrawComponent; 38 import org.nightlabs.editor2d.impl.TextDrawComponentImpl; 39 import org.nightlabs.editor2d.request.TextCreateRequest; 40 41 public class CreateTextCommand 42 extends Command 43 { 44 45 protected DrawComponentContainer parent; 46 public void setParent(DrawComponentContainer parent) { 47 this.parent = parent; 48 } 49 50 protected Rectangle rect; 51 public void setLocation(Rectangle rect) { 52 this.rect = rect; 53 } 54 protected Rectangle getLocation() { 55 return rect; 56 } 57 58 protected boolean shapeAdded; 59 protected int drawOrderIndex; 60 protected TextCreateRequest request; 61 62 public CreateTextCommand(TextCreateRequest request) 63 { 64 super(); 65 setLabel(EditorPlugin.getResourceString("command.create.text")); 66 this.request = request; 67 this.textDrawComponent = (TextDrawComponent) request.getNewObject(); 68 } 69 70 protected TextDrawComponent textDrawComponent; 71 public void execute() 72 { 73 int x = getLocation().x; 74 int y = getLocation().y; 75 Font newFont = new Font (request.getFontName(), request.getFontStyle(), request.getFontSize()); 76 textDrawComponent = new TextDrawComponentImpl(request.getText(), newFont, x, y); 77 78 parent.addDrawComponent(textDrawComponent); 79 textDrawComponent.setName(request.getText()); 80 shapeAdded = true; 81 drawOrderIndex = parent.getDrawComponents().indexOf(textDrawComponent); 82 } 83 84 public void redo() 85 { 86 parent.addDrawComponent(textDrawComponent, drawOrderIndex); 87 } 88 89 92 public void undo() 93 { 94 parent.removeDrawComponent(textDrawComponent); 95 } 96 97 } 98 | Popular Tags |