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.SectionWidget;
07: import jimm.datavision.gui.SectionFieldPanel;
08: import jimm.datavision.gui.FieldWidget;
09: import jimm.datavision.gui.TextFieldWidget;
10: import java.awt.event.MouseEvent;
11: import java.awt.Component;
12:
13: /**
14: * Inserts a new text field.
15: *
16: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
17: */
18: public class NewTextFieldCommand extends InsertFieldCommand {
19:
20: public NewTextFieldCommand(SectionWidget sw, MouseEvent e) {
21: super (sw, "text", new Point(e.getPoint()));
22:
23: // Translate insertLoc's mouse coordinates to SectionFieldPanel
24: // coordinates.
25: Component c = e.getComponent();
26: while (!(c instanceof SectionFieldPanel)) {
27: java.awt.Rectangle bounds = c.getBounds();
28: insertLoc.translate(bounds.x, bounds.y);
29: c = c.getParent();
30: if (c == null) // Should never happen
31: break;
32: }
33: }
34:
35: public void perform() {
36: super .perform();
37: ((TextFieldWidget) fw).startEditing(); // Selects the widget, too
38: }
39:
40: protected Rectangle initialFieldBounds() {
41: return new Rectangle(insertLoc.getX(), insertLoc.getY()
42: - (int) (Field.DEFAULT_HEIGHT / 2),
43: (double) Field.DEFAULT_WIDTH,
44: (double) Field.DEFAULT_HEIGHT);
45: }
46:
47: protected Object initialFieldValue() {
48: return "";
49: }
50:
51: protected FieldWidget createFieldWidget(Field f) {
52: return new TextFieldWidget(null, f);
53: }
54:
55: }
|