KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jimm.datavision.gui.cmd;
2 import jimm.datavision.field.Rectangle;
3 import jimm.datavision.gui.FieldWidget;
4 import jimm.util.I18N;
5
6 /**
7  * After stretching a field using the mouse, this command lets us undo and
8  * redo the size change.
9  *
10  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
11  */

12 public class FieldStretchCommand extends CommandAdapter {
13
14 protected FieldWidget fw;
15 protected Rectangle origBounds;
16 protected Rectangle newBounds;
17
18 public FieldStretchCommand(FieldWidget fw, Rectangle origBounds) {
19     super(I18N.get("FieldStretchCommand.name"));
20
21     this.fw = fw;
22     this.origBounds = origBounds;
23 }
24
25 public void perform() {
26     // Remember the field's new bounds.
27
newBounds = new Rectangle(fw.getField().getBounds()); // Make a copy
28
}
29
30 public void undo() {
31     fw.getField().getBounds().setBounds(origBounds);
32 }
33
34 public void redo() {
35     fw.getField().getBounds().setBounds(newBounds);
36 }
37
38 }
39
Popular Tags