KickJava   Java API By Example, From Geeks To Geeks.

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


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

14 abstract public class InsertFieldCommand extends CommandAdapter {
15
16 protected FieldWidget fw;
17 protected SectionWidget sw;
18 protected Point insertLoc;
19 protected String JavaDoc fieldType;
20 protected SectionResizeCommand sectionResizeCommand;
21
22 public InsertFieldCommand(SectionWidget sw, String JavaDoc fieldType, Point insertLoc)
23 {
24     super(I18N.get("InsertFieldCommand.name"));
25
26     this.sw = sw;
27     this.fieldType = fieldType;
28     this.insertLoc = insertLoc;
29     sectionResizeCommand = new SectionResizeCommand(sw);
30 }
31
32 public void perform() {
33     if (fw == null) {
34     Field f = createField();
35     fw = createFieldWidget(f);
36     }
37
38     fw.getField().getBounds().setBounds(initialFieldBounds());
39
40     fw.moveToSection(sw);
41     sectionResizeCommand.perform();
42 }
43
44 public void undo() {
45     sw.removeField(fw);
46     sectionResizeCommand.undo();
47     sw.repaint();
48 }
49
50 /**
51  * Creates the field. This default behavior calls <code>Field.create</code>,
52  * passing it a type string.
53  */

54 protected Field createField() {
55     // Create field. Specify null section so the call to
56
// FieldWidget.moveToSection() will do the correct thing.
57
return Field.create(null, sw.getReport(), null, fieldType,
58             initialFieldValue(), true);
59 }
60
61 protected abstract Rectangle initialFieldBounds();
62
63 protected abstract Object JavaDoc initialFieldValue();
64
65 protected abstract FieldWidget createFieldWidget(Field f);
66
67 }
68
Popular Tags