1 package jimm.datavision.gui; 2 import jimm.datavision.gui.cmd.CompoundCommand; 3 import jimm.util.I18N; 4 import java.awt.event.*; 5 import javax.swing.*; 6 7 13 public abstract class EditWin extends JDialog implements ActionListener 14 { 15 16 protected Designer designer; 17 protected JButton revertButton; 18 protected CompoundCommand commands; 19 20 28 public EditWin(Designer designer, String title, String commandNameKey) { 29 this(designer, title, commandNameKey, false); 30 } 31 32 41 public EditWin(Designer designer, String title, String commandNameKey, 42 boolean modal) 43 { 44 super(designer.getFrame(), title, modal); 45 this.designer = designer; 46 commands = new CompoundCommand(I18N.get(commandNameKey)); 47 } 48 49 54 protected JPanel closeButtonPanel() { 55 JPanel buttonPanel = new JPanel(); 56 JButton button; 57 58 buttonPanel.add(button = new JButton(I18N.get("GUI.ok"))); 59 button.addActionListener(this); 60 button.setDefaultCapable(true); 61 62 buttonPanel.add(button = new JButton(I18N.get("GUI.apply"))); 63 button.addActionListener(this); 64 65 buttonPanel.add(revertButton = new JButton(I18N.get("GUI.revert"))); 66 revertButton.addActionListener(this); 67 revertButton.setEnabled(false); 68 69 buttonPanel.add(button = new JButton(I18N.get("GUI.cancel"))); 70 button.addActionListener(this); 71 72 return buttonPanel; 73 } 74 75 80 public void actionPerformed(ActionEvent e) { 81 String cmd = e.getActionCommand(); 82 if (I18N.get("GUI.ok").equals(cmd)) { 83 save(true); dispose(); 85 } 86 else if (I18N.get("GUI.apply").equals(cmd)) { 87 save(false); } 89 else if (I18N.get("GUI.revert").equals(cmd)) { 90 revert(); 91 } 92 else if (I18N.get("GUI.cancel").equals(cmd)) { 93 revert(); 94 dispose(); 95 } 96 } 97 98 108 protected void save(boolean closing) { 109 doSave(); 110 revertButton.setEnabled(true); 111 112 if (closing && commands.numCommands() > 0) 113 designer.addCommand(commands); 114 } 115 116 120 protected abstract void doSave(); 121 122 128 protected void revert() { 129 commands.undo(); 130 commands = new CompoundCommand(commands.getName()); 131 doRevert(); 132 } 133 134 137 protected abstract void doRevert(); 138 139 } 140 | Popular Tags |