1 package jimm.datavision.gui.cmd; 2 import jimm.datavision.Point; 3 import jimm.datavision.field.Field; 4 import jimm.datavision.field.Rectangle; 5 import jimm.datavision.gui.FieldWidget; 6 import jimm.datavision.gui.SectionWidget; 7 import jimm.util.I18N; 8 9 14 abstract public class InsertFieldCommand extends CommandAdapter { 15 16 protected FieldWidget fw; 17 protected SectionWidget sw; 18 protected Point insertLoc; 19 protected String fieldType; 20 protected SectionResizeCommand sectionResizeCommand; 21 22 public InsertFieldCommand(SectionWidget sw, String fieldType, Point insertLoc) 23 { 24 super(I18N.get("InsertFieldCommand.name")); 25 26 this.sw = sw; 27 this.fieldType = fieldType; 28 this.insertLoc = insertLoc; 29 sectionResizeCommand = new SectionResizeCommand(sw); 30 } 31 32 public void perform() { 33 if (fw == null) { 34 Field f = createField(); 35 fw = createFieldWidget(f); 36 } 37 38 fw.getField().getBounds().setBounds(initialFieldBounds()); 39 40 fw.moveToSection(sw); 41 sectionResizeCommand.perform(); 42 } 43 44 public void undo() { 45 sw.removeField(fw); 46 sectionResizeCommand.undo(); 47 sw.repaint(); 48 } 49 50 54 protected Field createField() { 55 return Field.create(null, sw.getReport(), null, fieldType, 58 initialFieldValue(), true); 59 } 60 61 protected abstract Rectangle initialFieldBounds(); 62 63 protected abstract Object initialFieldValue(); 64 65 protected abstract FieldWidget createFieldWidget(Field f); 66 67 } 68 | Popular Tags |