01: package jimm.datavision.gui.cmd;
02:
03: import jimm.datavision.Section;
04: import jimm.datavision.Point;
05: import jimm.datavision.field.Field;
06: import jimm.datavision.field.Rectangle;
07: import jimm.datavision.field.ColumnField;
08: import jimm.datavision.source.Column;
09: import jimm.datavision.gui.SectionWidget;
10: import jimm.datavision.gui.FieldWidget;
11: import java.awt.dnd.DropTargetDropEvent;
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 NewDraggedFieldCommand extends InsertFieldCommand {
19:
20: protected FieldWidget titleField;
21: protected SectionResizeCommand titleSectionResizeCommand;
22:
23: public NewDraggedFieldCommand(SectionWidget sw, String dropString,
24: DropTargetDropEvent e) {
25: super (sw, dropString, new Point(e.getLocation()));
26: }
27:
28: public void perform() {
29: super .perform();
30:
31: // If this is a detail section and the field represents a database
32: // column, add a title field whose name is the name of the column.
33: SectionWidget sw = fw.getSectionWidget();
34: Field f = fw.getField();
35: if (sw.getSection().isDetail() && (f instanceof ColumnField)) {
36: Column col = (Column) ((ColumnField) f).getColumn();
37: String name = col.getName();
38: name = name.substring(0, 1).toUpperCase()
39: + name.substring(1).toLowerCase();
40:
41: // The title section resize command may not be used.
42: Section titleSection = f.getReport().pageHeaders().first();
43: SectionWidget titleSectionWidget = sw.getDesigner()
44: .findSectionWidgetFor(titleSection);
45: titleSectionResizeCommand = new SectionResizeCommand(
46: titleSectionWidget);
47:
48: // Possible the title field. If no title field added, titleField
49: // will be null.
50: titleField = sw.addTitleField((int) insertLoc.getX(),
51: (int) Field.DEFAULT_WIDTH, name);
52:
53: if (titleField != null)
54: titleSectionResizeCommand.perform();
55: else
56: titleSectionResizeCommand = null;
57: }
58: }
59:
60: public void undo() {
61: super .undo();
62: if (titleField != null) {
63: titleField.doDelete();
64: titleSectionResizeCommand.undo();
65: titleField.getSectionWidget().repaint();
66: }
67: }
68:
69: public void redo() {
70: super .redo();
71: if (titleField != null)
72: titleField.moveToSection(titleField.getSectionWidget());
73: }
74:
75: /**
76: * Creates the field. This override creates a dragged field.
77: */
78: protected Field createField() {
79: // Create field. Specify null section so the call to
80: // FieldWidget.moveToSection() will do the correct thing.
81: //
82: // field type string is drop string
83: return Field.createFromDragString(sw.getReport(), fieldType);
84: }
85:
86: protected Rectangle initialFieldBounds() {
87: return new Rectangle(insertLoc.getX(), insertLoc.getY(),
88: Field.DEFAULT_WIDTH, Field.DEFAULT_HEIGHT);
89: }
90:
91: protected Object initialFieldValue() {
92: return null;
93: }
94:
95: protected FieldWidget createFieldWidget(Field f) {
96: return f.makeWidget(null);
97: }
98:
99: }
|