1 package jimm.datavision.gui; 2 import jimm.datavision.Report; 3 import jimm.datavision.ErrorHandler; 4 import jimm.datavision.gui.cmd.Command; 5 import jimm.util.I18N; 6 import java.awt.Dimension ; 7 import java.awt.BorderLayout ; 8 import java.awt.event.ActionListener ; 9 import java.awt.event.ActionEvent ; 10 import javax.swing.*; 11 12 19 public abstract class CodeEditorWin extends JDialog implements ActionListener { 20 21 protected static final Dimension EDIT_SIZE = new Dimension (400, 225); 22 23 protected Designer designer; 24 protected JTextArea codeField; 25 protected Command command; 26 protected String errorSuffix; 27 protected String errorTitle; 28 29 41 public CodeEditorWin(Designer designer, Report report, String initialText, 42 String title, String errorSuffixKey, String errorTitleKey) 43 { 44 super(designer.getFrame(), title); 45 this.designer = designer; 46 errorSuffix = errorSuffixKey == null ? null : I18N.get(errorSuffixKey); 47 errorTitle = errorTitleKey == null ? null : I18N.get(errorTitleKey); 48 buildWindow(report, initialText); 49 pack(); 50 setVisible(true); 51 } 52 53 59 protected void buildWindow(Report report, String initialText) { 60 codeField = 61 new DropListenerTextArea(report, 62 initialText == null ? "" : initialText); 63 JScrollPane scroller = new JScrollPane(codeField); 64 scroller.setPreferredSize(EDIT_SIZE); 66 getContentPane().add(scroller, BorderLayout.CENTER); 68 getContentPane().add(buildButtonPanel(), BorderLayout.SOUTH); 69 70 new FocusSetter(codeField); 71 } 72 73 78 protected JPanel buildButtonPanel() { 79 JPanel buttonPanel = new JPanel(); 80 JButton button; 81 82 buttonPanel.add(button = new JButton(I18N.get("GUI.ok"))); 83 button.addActionListener(this); 84 button.setDefaultCapable(true); 85 86 buttonPanel.add(button = new JButton(I18N.get("GUI.cancel"))); 87 button.addActionListener(this); 88 89 return buttonPanel; 90 } 91 92 98 public void actionPerformed(ActionEvent e) { 99 String cmd = e.getActionCommand(); 100 try { 101 if (I18N.get("GUI.ok").equals(cmd)) { 102 save(codeField.getText()); 103 if (command != null) 104 designer.performCommand(command); 105 dispose(); 106 } 107 else if (I18N.get("GUI.cancel").equals(cmd)) { 108 dispose(); 109 } 110 } 111 catch (Exception ex) { 112 String str = ex.toString(); 113 if (errorSuffix != null) str += "\n" + errorSuffix; 114 ErrorHandler.error(str, errorTitle); 115 116 command = null; 117 } 118 } 119 120 127 public abstract void save(String text); 128 129 } 130 | Popular Tags |