1 package jimm.datavision.gui; 2 import jimm.datavision.field.Field; 3 import jimm.datavision.gui.cmd.WidgetRenameCommand; 4 import java.awt.event.MouseEvent ; 5 import java.awt.event.ActionEvent ; 6 import javax.swing.JDialog ; 7 8 15 public abstract class EditWinWidget extends FieldWidget { 16 17 protected JDialog editor; 18 19 25 EditWinWidget(SectionWidget sw, Field field) { 26 super(sw, field); 27 } 28 29 protected void addCustomPopupItems() { 30 MenuUtils.addToMenu(this, popup, "EditWinWidget.popup_edit", POPUP_FONT); 31 MenuUtils.addToMenu(this, popup, "EditWinWidget.popup_rename", POPUP_FONT); 32 popup.addSeparator(); 33 } 34 35 39 public void actionPerformed(ActionEvent e) { 40 String command = e.getActionCommand(); 41 if (command == null) return; 42 43 if ("edit".equals(command)) 44 openEditor(); 45 else if ("rename".equals(command)) 46 rename(); 47 else 48 super.actionPerformed(e); 49 } 50 51 57 public void mouseClicked(MouseEvent e) { 58 if (sectionWidget.designer.isPlacingNewTextField()) 59 sectionWidget.createNewTextField(e); 60 if (e.getClickCount() == 2) 61 openEditor(); 62 else 63 super.mouseClicked(e); 64 } 65 66 69 public void openEditor() { 70 if (editor == null) 71 editor = createEditor(); 72 else 73 updateEditor(); 74 editor.setVisible(true); 75 editor.toFront(); 76 } 77 78 83 protected abstract JDialog createEditor(); 84 85 88 protected void updateEditor() {} 89 90 93 protected void rename() { 94 Designer designer = sectionWidget.designer; 95 String name = new AskStringDialog(designer.getFrame(), getEditorTitle(), 96 getEditorLabel(), getWidgetName()) 97 .getString(); 98 if (name != null) 99 designer.performCommand(new WidgetRenameCommand(this, getWidgetName(), 100 name)); 101 } 102 103 108 protected abstract String getWidgetName(); 109 110 113 protected abstract String getEditorTitle(); 114 115 119 protected abstract String getEditorLabel(); 120 121 127 public abstract void setWidgetName(String newName); 128 129 } 130 | Popular Tags |