Changeset 29030 for main/trunk/gli
- Timestamp:
- 2014-05-02T18:59:15+12:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/gui/FormatConversionDialog.java
r29017 r29030 80 80 private GLIButton next_button = null; 81 81 private GLIButton accept_all_button = null; 82 private GLIButton undo_button = null; 83 private GLIButton redo_button = null; 82 private GLIButton gs2_undo_button = null; 83 private GLIButton gs2_redo_button = null; 84 private GLIButton gs3_undo_button = null; 85 private GLIButton gs3_redo_button = null; 84 86 private GLIButton htmltidy_button = null; 85 87 private GLIButton xmltidy_button = null; … … 88 90 private JLabel count_label = null; 89 91 private JLabel statusbar = null; 90 private UndoManager undoManager;91 92 92 93 public FormatConversionDialog (File collect_cfg_file, Document xml_file_doc, NodeList gsf_format_gs2_list) { … … 104 105 105 106 107 gs2_textarea = new NumberedJTextArea(); 108 gs3_textarea = new NumberedJTextArea(); 109 110 106 111 JPanel midbutton_panel = new JPanel(); // FlowLayout by default in a JPanel 107 112 midbutton_panel.setComponentOrientation(Dictionary.getOrientation()); 113 114 gs2_undo_button = new GLIButton(Dictionary.get("General.Undo"), Dictionary.get("General.Undo_Tooltip")); 115 gs2_undo_button.setEnabled(false); 116 117 gs2_redo_button = new GLIButton(Dictionary.get("General.Redo"), Dictionary.get("General.Redo_Tooltip")); 118 gs2_redo_button.setEnabled(false); 119 120 gs2_undo_button.addActionListener(new UndoListener(gs2_textarea, gs2_undo_button, gs2_redo_button)); 121 gs2_redo_button.addActionListener(new RedoListener(gs2_textarea, gs2_undo_button, gs2_redo_button)); 122 108 123 JButton reconvert_button = new GLIButton(Dictionary.get("FormatConversionDialog.Reconvert"), Dictionary.get("FormatConversionDialog.Reconvert_Tooltip")); 124 125 midbutton_panel.add(gs2_undo_button); 126 midbutton_panel.add(gs2_redo_button); 109 127 midbutton_panel.add(reconvert_button); 110 128 reconvert_button.addActionListener(new ReconvertListener()); … … 117 135 JPanel button1_panel = new JPanel(); 118 136 button1_panel.setComponentOrientation(Dictionary.getOrientation()); 119 undo_button = new GLIButton(Dictionary.get("General.Undo"), Dictionary.get("General.Undo_Tooltip")); 120 undo_button.addActionListener(new UndoListener()); 121 undo_button.setEnabled(false); 122 123 redo_button = new GLIButton(Dictionary.get("General.Redo"), Dictionary.get("General.Redo_Tooltip")); 124 redo_button.addActionListener(new RedoListener()); 125 redo_button.setEnabled(false); 137 gs3_undo_button = new GLIButton(Dictionary.get("General.Undo"), Dictionary.get("General.Undo_Tooltip")); 138 gs3_undo_button.setEnabled(false); 139 140 gs3_redo_button = new GLIButton(Dictionary.get("General.Redo"), Dictionary.get("General.Redo_Tooltip")); 141 gs3_redo_button.setEnabled(false); 142 143 gs3_undo_button.addActionListener(new UndoListener(gs3_textarea, gs3_undo_button, gs3_redo_button)); 144 gs3_redo_button.addActionListener(new RedoListener(gs3_textarea, gs3_undo_button, gs3_redo_button)); 145 126 146 127 147 xmltidy_button = new GLIButton(Dictionary.get("FormatConversionDialog.XHTML_Tidy"), Dictionary.get("FormatConversionDialog.XHTML_Tidy_Tooltip")); 128 148 xmltidy_button.addActionListener(new XMLTidyButtonListener()); 129 149 130 button1_panel.add( undo_button);131 button1_panel.add( redo_button);150 button1_panel.add(gs3_undo_button); 151 button1_panel.add(gs3_redo_button); 132 152 button1_panel.add(xmltidy_button); 133 153 … … 149 169 // The undoable text areas. Adding the UndoableEditListener has to come after instantiation 150 170 // of the undo and redo buttons, since the listener expects these buttons to already exist 151 undoManager = new UndoManager(); 152 153 gs2_textarea = new NumberedJTextArea(); 154 gs3_textarea = new NumberedJTextArea(); 155 156 CustomUndoableEditListener customUndoableEditListener = new CustomUndoableEditListener(); 157 gs2_textarea.getDocument().addUndoableEditListener(customUndoableEditListener); 158 gs3_textarea.getDocument().addUndoableEditListener(customUndoableEditListener); 171 172 gs2_textarea.getDocument().addUndoableEditListener(new CustomUndoableEditListener(gs2_undo_button, gs2_redo_button)); 173 gs3_textarea.getDocument().addUndoableEditListener(new CustomUndoableEditListener(gs3_undo_button, gs3_redo_button)); 159 174 160 175 initTextArea(gs2_textarea); … … 639 654 640 655 // as we're on a new screen of dialog, need to clear all undo/redo history 641 undoManager.discardAllEdits(); 642 undo_button.setEnabled(false); 643 redo_button.setEnabled(false); 656 gs2_undo_button.setEnabled(false); 657 gs2_redo_button.setEnabled(false); 658 gs3_undo_button.setEnabled(false); 659 gs3_redo_button.setEnabled(false); 660 gs2_textarea.discardAllEdits(); 661 gs3_textarea.discardAllEdits(); 644 662 645 663 int len = gsf_format_gs2_list.getLength(); … … 935 953 private class UndoListener implements ActionListener 936 954 { 955 NumberedJTextArea textarea = null; 956 GLIButton undobutton, redobutton; 957 958 public UndoListener(NumberedJTextArea textarea, GLIButton undobutton, GLIButton redobutton) { 959 960 this.textarea = textarea; 961 this.undobutton = undobutton; 962 this.redobutton = redobutton; 963 964 } 965 937 966 public void actionPerformed(ActionEvent event) 938 967 { 939 968 try { 940 if ( undoManager.canUndo()) {941 redo _button.setEnabled(true);942 undoManager.undo();943 } 944 945 if (! undoManager.canUndo()) {946 undo _button.setEnabled(false);969 if (textarea.canUndo()) { 970 redobutton.setEnabled(true); 971 textarea.undoLastAction(); 972 } 973 974 if (!textarea.canUndo()) { 975 undobutton.setEnabled(false); 947 976 } else { 948 undo _button.setEnabled(true);977 undobutton.setEnabled(true); 949 978 } 950 979 951 980 } catch (Exception e) { 952 981 System.err.println("Exception trying to undo: " + e.getMessage()); 982 e.printStackTrace(); 953 983 } 954 984 } … … 957 987 private class RedoListener implements ActionListener 958 988 { 989 NumberedJTextArea textarea = null; 990 GLIButton undobutton, redobutton; 991 992 public RedoListener(NumberedJTextArea textarea, GLIButton undobutton, GLIButton redobutton) { 993 994 this.textarea = textarea; 995 this.undobutton = undobutton; 996 this.redobutton = redobutton; 997 } 998 959 999 public void actionPerformed(ActionEvent evt) 960 1000 { 961 1001 try { 962 if ( undoManager.canRedo()) {963 undo _button.setEnabled(true); // the difference with Format4gs3Manager, and no DocumentListener964 undoManager.redo();965 } 966 967 if (! undoManager.canRedo()) {968 redo _button.setEnabled(false);1002 if (textarea.canRedo()) { 1003 undobutton.setEnabled(true); // the difference with Format4gs3Manager, and no DocumentListener 1004 textarea.redoLastAction(); 1005 } 1006 1007 if (!textarea.canRedo()) { 1008 redobutton.setEnabled(false); 969 1009 } else { 970 redo _button.setEnabled(true);1010 redobutton.setEnabled(true); 971 1011 } 972 1012 973 1013 } catch (Exception e) { 974 1014 System.err.println("Exception trying to redo: " + e.getMessage()); 1015 e.printStackTrace(); 975 1016 } 976 1017 } … … 978 1019 979 1020 private class CustomUndoableEditListener implements UndoableEditListener { 1021 GLIButton undobutton = null; 1022 GLIButton redobutton = null; 1023 1024 public CustomUndoableEditListener(GLIButton undo_button, GLIButton redo_button) { 1025 undobutton = undo_button; 1026 redobutton = redo_button; 1027 } 1028 980 1029 public void undoableEditHappened(UndoableEditEvent evt) 981 { 982 983 undoManager.addEdit(evt.getEdit()); 984 redo_button.setEnabled(false); 985 undo_button.setEnabled(true); 986 } 987 } 988 1030 { 1031 undobutton.setEnabled(true); 1032 redobutton.setEnabled(false); 1033 } 1034 } 989 1035 }
Note:
See TracChangeset
for help on using the changeset viewer.