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 ; 11 12 17 public class NewDraggedFieldCommand extends InsertFieldCommand { 18 19 protected FieldWidget titleField; 20 protected SectionResizeCommand titleSectionResizeCommand; 21 22 public NewDraggedFieldCommand(SectionWidget sw, String dropString, 23 DropTargetDropEvent e) 24 { 25 super(sw, dropString, new Point(e.getLocation())); 26 } 27 28 public void perform() { 29 super.perform(); 30 31 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 Section titleSection = f.getReport().pageHeaders().first(); 43 SectionWidget titleSectionWidget = 44 sw.getDesigner().findSectionWidgetFor(titleSection); 45 titleSectionResizeCommand = 46 new SectionResizeCommand(titleSectionWidget); 47 48 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 78 protected Field createField() { 79 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 } 100 | Popular Tags |