KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jimm.datavision.gui.cmd;
2 import jimm.datavision.Section;
3 import jimm.datavision.Point;
4 import jimm.datavision.field.Field;
5 import jimm.datavision.field.Rectangle;
6 import jimm.datavision.field.ColumnField;
7 import jimm.datavision.source.Column;
8 import jimm.datavision.gui.SectionWidget;
9 import jimm.datavision.gui.FieldWidget;
10 import java.awt.dnd.DropTargetDropEvent JavaDoc;
11
12 /**
13  * Inserts a new text field.
14  *
15  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
16  */

17 public class NewDraggedFieldCommand extends InsertFieldCommand {
18
19 protected FieldWidget titleField;
20 protected SectionResizeCommand titleSectionResizeCommand;
21
22 public NewDraggedFieldCommand(SectionWidget sw, String JavaDoc dropString,
23                   DropTargetDropEvent JavaDoc e)
24 {
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 JavaDoc 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 =
44         sw.getDesigner().findSectionWidgetFor(titleSection);
45     titleSectionResizeCommand =
46         new SectionResizeCommand(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 JavaDoc initialFieldValue() {
92     return null;
93 }
94
95 protected FieldWidget createFieldWidget(Field f) {
96     return f.makeWidget(null);
97 }
98
99 }
100
Popular Tags