01: package jimm.datavision.gui.cmd;
02:
03: import jimm.datavision.Point;
04: import jimm.datavision.field.Field;
05: import jimm.datavision.field.Rectangle;
06: import jimm.datavision.gui.FieldWidget;
07: import jimm.datavision.gui.SectionWidget;
08: import jimm.util.I18N;
09:
10: /**
11: * Abstract superclass for inserting new fields.
12: *
13: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
14: */
15: abstract public class InsertFieldCommand extends CommandAdapter {
16:
17: protected FieldWidget fw;
18: protected SectionWidget sw;
19: protected Point insertLoc;
20: protected String fieldType;
21: protected SectionResizeCommand sectionResizeCommand;
22:
23: public InsertFieldCommand(SectionWidget sw, String fieldType,
24: Point insertLoc) {
25: super (I18N.get("InsertFieldCommand.name"));
26:
27: this .sw = sw;
28: this .fieldType = fieldType;
29: this .insertLoc = insertLoc;
30: sectionResizeCommand = new SectionResizeCommand(sw);
31: }
32:
33: public void perform() {
34: if (fw == null) {
35: Field f = createField();
36: fw = createFieldWidget(f);
37: }
38:
39: fw.getField().getBounds().setBounds(initialFieldBounds());
40:
41: fw.moveToSection(sw);
42: sectionResizeCommand.perform();
43: }
44:
45: public void undo() {
46: sw.removeField(fw);
47: sectionResizeCommand.undo();
48: sw.repaint();
49: }
50:
51: /**
52: * Creates the field. This default behavior calls <code>Field.create</code>,
53: * passing it a type string.
54: */
55: protected Field createField() {
56: // Create field. Specify null section so the call to
57: // FieldWidget.moveToSection() will do the correct thing.
58: return Field.create(null, sw.getReport(), null, fieldType,
59: initialFieldValue(), true);
60: }
61:
62: protected abstract Rectangle initialFieldBounds();
63:
64: protected abstract Object initialFieldValue();
65:
66: protected abstract FieldWidget createFieldWidget(Field f);
67:
68: }
|