01: package jimm.datavision.gui.cmd;
02:
03: import jimm.datavision.field.Field;
04: import jimm.datavision.field.Rectangle;
05: import jimm.datavision.gui.FieldWidget;
06: import jimm.datavision.gui.SectionWidget;
07: import jimm.datavision.gui.PreMoveInfo;
08: import jimm.util.I18N;
09:
10: /**
11: * Moves a single field.
12: *
13: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
14: */
15: public class FieldMoveCommand extends CommandAdapter {
16:
17: protected FieldWidget fw;
18: protected Rectangle newBounds;
19: protected SectionWidget newSectionWidget;
20: protected SectionResizeCommand sectionResizeCommand;
21: protected PreMoveInfo preMoveInfo;
22:
23: public FieldMoveCommand(FieldWidget fw, SectionWidget sw) {
24: super (I18N.get("FieldMoveCommand.name"));
25:
26: this .fw = fw;
27: preMoveInfo = fw.getPreMoveInfo();
28: newBounds = new Rectangle(fw.getField().getBounds()); // Make a copy
29: newSectionWidget = sw;
30: sectionResizeCommand = new SectionResizeCommand(sw);
31: }
32:
33: public void perform() {
34: fw.getField().getBounds().setBounds(newBounds);
35: fw.putDown(newSectionWidget);
36: sectionResizeCommand.perform();
37: }
38:
39: public void undo() {
40: Field f = fw.getField();
41: SectionWidget sw = fw.getSectionWidget();
42: f.getBounds().setBounds(preMoveInfo.origBounds); // Move to original bounds
43: fw.moveToSection(preMoveInfo.sectionWidget); // Move to original section
44: sectionResizeCommand.undo();
45: if (sw != preMoveInfo.sectionWidget)
46: sw.repaint();
47: }
48:
49: }
|