KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > gui > cmd > FieldMoveCommand


1 package jimm.datavision.gui.cmd;
2 import jimm.datavision.field.Field;
3 import jimm.datavision.field.Rectangle;
4 import jimm.datavision.gui.FieldWidget;
5 import jimm.datavision.gui.SectionWidget;
6 import jimm.datavision.gui.PreMoveInfo;
7 import jimm.util.I18N;
8
9 /**
10  * Moves a single field.
11  *
12  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
13  */

14 public class FieldMoveCommand extends CommandAdapter {
15
16 protected FieldWidget fw;
17 protected Rectangle newBounds;
18 protected SectionWidget newSectionWidget;
19 protected SectionResizeCommand sectionResizeCommand;
20 protected PreMoveInfo preMoveInfo;
21
22 public FieldMoveCommand(FieldWidget fw, SectionWidget sw) {
23     super(I18N.get("FieldMoveCommand.name"));
24
25     this.fw = fw;
26     preMoveInfo = fw.getPreMoveInfo();
27     newBounds = new Rectangle(fw.getField().getBounds()); // Make a copy
28
newSectionWidget = sw;
29     sectionResizeCommand = new SectionResizeCommand(sw);
30 }
31
32 public void perform() {
33     fw.getField().getBounds().setBounds(newBounds);
34     fw.putDown(newSectionWidget);
35     sectionResizeCommand.perform();
36 }
37
38 public void undo() {
39     Field f = fw.getField();
40     SectionWidget sw = fw.getSectionWidget();
41     f.getBounds().setBounds(preMoveInfo.origBounds); // Move to original bounds
42
fw.moveToSection(preMoveInfo.sectionWidget); // Move to original section
43
sectionResizeCommand.undo();
44     if (sw != preMoveInfo.sectionWidget)
45     sw.repaint();
46 }
47
48 }
49
Popular Tags