Changeset 12367
- Timestamp:
- 2006-08-01T13:45:40+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/MacrosManager.java
r12298 r12367 32 32 import javax.swing.*; 33 33 import javax.swing.event.*; 34 import javax.swing.undo.*; 34 35 import java.io.File; 35 36 import java.io.FileInputStream; … … 43 44 import org.greenstone.gatherer.Configuration; 44 45 import org.greenstone.gatherer.Dictionary; 46 import org.greenstone.gatherer.Gatherer; 45 47 import org.greenstone.gatherer.gui.DesignPaneHeader; 46 48 import org.greenstone.gatherer.gui.GLIButton; 47 49 48 public class MacrosManager 49 extends JPanel { 50 public class MacrosManager { 50 51 51 52 /** The controls used to modify the general options. */ … … 91 92 private class MacrosControl 92 93 extends JPanel 93 implements Control {94 implements Control, WindowFocusListener { 94 95 95 96 JTextArea macros_textarea = null; 96 JButton save_button = null; 97 JButton revert_button = null; 98 97 JButton undo_button = null; 98 JButton redo_button = null; 99 private final UndoManager undo = new UndoManager(); 100 private boolean macros_changed = false; 99 101 public MacrosControl() { 100 102 super(); … … 110 112 macros_textarea.setWrapStyleWord(false); 111 113 macros_textarea.setToolTipText(Dictionary.get("CDM.MacrosManager.Editor_Tooltip")); 114 readMacroFile(); // load in the original contents 115 macros_textarea.getDocument().addDocumentListener(new EditorListener()); 116 117 // Listen for undo and redo events 118 macros_textarea.getDocument().addUndoableEditListener(new UndoableEditListener() { 119 public void undoableEditHappened(UndoableEditEvent evt) { 120 undo.addEdit(evt.getEdit()); 121 } 122 }); 112 123 113 124 JPanel macros_pane = new JPanel(); … … 115 126 macros_pane.setLayout(new BorderLayout()); 116 127 macros_pane.add(new JScrollPane(macros_textarea), BorderLayout.CENTER); 117 118 save_button = new GLIButton(Dictionary.get("CDM.MacrosManager.Save"), Dictionary.get("CDM.MacrosManager.Save_Tooltip")); 119 revert_button = new GLIButton(Dictionary.get("CDM.MacrosManager.Revert"), Dictionary.get("CDM.MacrosManager.Revert_Tooltip")); 120 121 save_button.addActionListener(new SaveListener()); 122 revert_button.addActionListener(new RevertListener()); 128 undo_button = new GLIButton(Dictionary.get("General.Undo"), Dictionary.get("General.Undo_Tooltip")); 129 undo_button.setEnabled(false); 130 undo_button.addActionListener(new UndoListener()); 131 132 redo_button = new GLIButton(Dictionary.get("General.Redo"), Dictionary.get("General.Redo_Tooltip")); 133 redo_button.setEnabled(false); 134 redo_button.addActionListener(new RedoListener()); 135 123 136 JPanel button_pane = new JPanel(); 124 137 button_pane.setLayout(new GridLayout(1,2)); 125 button_pane.add( save_button);126 button_pane.add(re vert_button);138 button_pane.add(undo_button); 139 button_pane.add(redo_button); 127 140 128 141 main_pane.add(macros_pane, BorderLayout.CENTER); … … 133 146 add(header_pane, BorderLayout.NORTH); 134 147 add(main_pane, BorderLayout.CENTER); 135 readMacroFile();148 Gatherer.g_man.addWindowFocusListener(this); 136 149 } 137 150 … … 140 153 141 154 public void loseFocus() { 155 if (macros_changed) { 156 writeMacroFile(); 157 macros_changed = false; 158 } 142 159 } 143 160 144 161 public void gainFocus() { 145 //readMacroFile(); 162 } 163 164 public void windowGainedFocus(WindowEvent e) { 165 } 166 167 public void windowLostFocus(WindowEvent e) { 168 if (macros_changed) { 169 writeMacroFile(); 170 macros_changed = false; 171 } 146 172 } 147 173 … … 161 187 br.close(); 162 188 } catch (Exception e) { 163 System.err.println(" Exception happened,"+e.getMessage());189 System.err.println("MacrosManager Exception: "+e.getMessage()); 164 190 } 165 191 } … … 182 208 out.close(); 183 209 } catch (Exception e) { 184 185 } 186 } 187 private class SaveListener 210 System.err.println("MacrosManager Exception: "+e.getMessage()); 211 } 212 } 213 214 private class EditorListener 215 implements DocumentListener { 216 public void changedUpdate(DocumentEvent e) { 217 macros_changed = true; 218 undo_button.setEnabled(true); 219 } 220 221 public void insertUpdate(DocumentEvent e) { 222 macros_changed = true; 223 undo_button.setEnabled(true); 224 } 225 226 public void removeUpdate(DocumentEvent e) { 227 macros_changed = true; 228 undo_button.setEnabled(true); 229 } 230 231 } 232 233 private class UndoListener 188 234 implements ActionListener { 189 235 190 236 public void actionPerformed(ActionEvent event) { 191 writeMacroFile(); 192 } 193 } 194 195 private class RevertListener 196 implements ActionListener { 197 198 public void actionPerformed(ActionEvent event) { 199 readMacroFile(); 200 } 201 } 202 } 237 try { 238 if (undo.canUndo()) { 239 int pos = macros_textarea.getCaretPosition(); 240 undo.undo(); 241 macros_textarea.setCaretPosition(pos-1); 242 macros_textarea.grabFocus(); 243 redo_button.setEnabled(true); 244 245 } 246 if (!undo.canUndo()){ 247 undo_button.setEnabled(false); 248 } 249 else{ 250 undo_button.setEnabled(true); 251 } 252 253 } catch (Exception e) { 254 System.err.println("MacrosManager Exception: "+e.getMessage()); 255 } 256 } 257 } 258 259 private class RedoListener 260 implements ActionListener { 261 262 public void actionPerformed(ActionEvent evt) { 263 try { 264 if (undo.canRedo()) { 265 int pos = macros_textarea.getCaretPosition(); 266 undo.redo(); 267 macros_textarea.setCaretPosition(pos+1); 268 macros_textarea.grabFocus(); 269 } 270 if (!undo.canRedo()){ 271 redo_button.setEnabled(false); 272 } 273 else{ 274 redo_button.setEnabled(true); 275 } 276 277 } catch (Exception e) { 278 System.err.println("MacrosManager Exception: "+e.getMessage()); 279 } 280 } 281 } 282 283 } 284 285 203 286 204 287 }
Note:
See TracChangeset
for help on using the changeset viewer.