01: package net.refractions.udig.printing.ui.internal.editor.commands;
02:
03: import net.refractions.udig.printing.model.Box;
04: import net.refractions.udig.printing.model.Page;
05:
06: import org.eclipse.draw2d.geometry.Dimension;
07: import org.eclipse.draw2d.geometry.Rectangle;
08: import org.eclipse.gef.commands.Command;
09:
10: public class BoxCreateCommand extends Command {
11: private Box newBox;
12: private Page parent; //page to add box to
13: private Rectangle bounds;
14:
15: public BoxCreateCommand(Box box, Page parent, Rectangle bounds) {
16: super ();
17: this .bounds = bounds;
18: newBox = box;
19: this .parent = parent;
20: setLabel("box creation");
21: }
22:
23: public boolean canExecute() {
24: return newBox != null && parent != null && bounds != null;
25: }
26:
27: public void execute() {
28: newBox.setLocation(bounds.getLocation());
29: Dimension size = bounds.getSize();
30: if (size.width > 0 && size.height > 0)
31: newBox.setSize(size);
32: redo();
33: }
34:
35: public void redo() {
36: parent.getBoxes().add(newBox);
37: }
38:
39: public void undo() {
40: parent.getBoxes().remove(newBox);
41: }
42: }
|