Changeset 32091
- Timestamp:
- 2017-12-11T17:28:04+13:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/gui/ConfigFileEditor.java
r31582 r32091 25 25 26 26 package org.greenstone.gatherer.gui; 27 28 // for RSyntaxTextArea editor's search functionality: 29 import org.fife.ui.rtextarea.SearchEngine; 30 import org.fife.ui.rtextarea.SearchContext; 27 31 28 32 import org.greenstone.gatherer.Configuration; … … 35 39 import org.w3c.dom.*; 36 40 37 38 41 import java.io.File; 39 42 import java.io.IOException; … … 57 60 private JTextArea editor_msgarea; 58 61 62 63 // https://github.com/bobbylight/RSyntaxTextArea/wiki/Example:-Using-Find-and-Replace 64 private JTextField searchField; 65 private JCheckBox regexCB; 66 private JCheckBox matchCaseCB; 67 private JButton nextButton; 68 private JButton prevButton; 69 59 70 //private final String DEFAULT_PROCESSING_INSTRUCTION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; 60 71 … … 62 73 63 74 public ConfigFileEditor() { 64 65 66 67 68 75 76 super(Gatherer.g_man, true); 77 setModal(true); 78 setSize(SIZE); 79 69 80 String collection_folder_path = Gatherer.getCollectDirectoryPath(); 70 81 String collectionName = Gatherer.c_man.getCollection().getName(); // we won't be in this constructor if collection is null. … … 88 99 validation_msg_panel.add(validation_label, BorderLayout.WEST); 89 100 validation_msg_panel.add(new JScrollPane(editor_msgarea), BorderLayout.CENTER); 101 102 // Find functionality - can extend for Find and Replace 103 // taken from https://github.com/bobbylight/RSyntaxTextArea/wiki/Example:-Using-Find-and-Replace 104 // Create a toolbar with searching options. 105 JToolBar toolBar = new JToolBar(); 106 searchField = new JTextField(30); 107 toolBar.add(searchField); 108 nextButton = new JButton("Find Next"); 109 nextButton.setActionCommand("FindNext"); 110 nextButton.addActionListener(this); 111 toolBar.add(nextButton); 112 searchField.addActionListener(this); 113 prevButton = new JButton("Find Previous"); 114 prevButton.setActionCommand("FindPrev"); 115 prevButton.addActionListener(this); 116 toolBar.add(prevButton); 117 regexCB = new JCheckBox("Regex"); 118 toolBar.add(regexCB); 119 matchCaseCB = new JCheckBox("Match Case"); 120 toolBar.add(matchCaseCB); 90 121 91 122 // the all important XML editor … … 106 137 button_panel.add(save_button); 107 138 139 // toolbars_panel to contain find-and-replace toolbar and undo/redo/cancel/save button panel 140 JPanel toolbars_panel = new JPanel(new BorderLayout()); 141 toolbars_panel.add(toolBar, BorderLayout.NORTH); 142 toolbars_panel.add(button_panel, BorderLayout.CENTER); 143 108 144 JPanel content_pane = (JPanel) getContentPane(); 109 145 content_pane.setComponentOrientation(Dictionary.getOrientation()); … … 111 147 content_pane.add(validation_msg_panel, BorderLayout.NORTH); 112 148 content_pane.add(new JScrollPane(editor), BorderLayout.CENTER); // make editor scrollable 113 content_pane.add(button_panel, BorderLayout.SOUTH);114 149 //content_pane.add(button_panel, BorderLayout.SOUTH); 150 content_pane.add(toolbars_panel, BorderLayout.SOUTH); 115 151 116 152 // NOW WE CAN PREPARE THE ACTUAL CONTENT TO GO INTO THE XML EDITOR TEXTAREA … … 166 202 Dimension screen_size = Configuration.screen_size; 167 203 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2); 204 editor.setCaretPosition(0); // start at top of config XML 168 205 } 169 206 … … 190 227 Gatherer.c_man.loadCollection(current_collection_filepath); 191 228 } 192 } 193 229 230 // Find functionality, can extend for Find and Replace 231 // taken from https://github.com/bobbylight/RSyntaxTextArea/wiki/Example:-Using-Find-and-Replace 232 else if(e.getSource() == searchField) { 233 nextButton.doClick(0); 234 } 235 else if(e.getSource() == nextButton || e.getSource() == prevButton) { 236 // "FindNext" => search forward, "FindPrev" => search backward 237 String command = e.getActionCommand(); 238 boolean forward = "FindNext".equals(command); 239 240 // Create an object defining our search parameters. 241 SearchContext context = new SearchContext(); 242 String text = searchField.getText(); 243 if (text.length() == 0) { 244 return; 245 } 246 context.setSearchFor(text); 247 context.setMatchCase(matchCaseCB.isSelected()); 248 context.setRegularExpression(regexCB.isSelected()); 249 context.setSearchForward(forward); 250 context.setWholeWord(false); 251 252 //boolean found = SearchEngine.find(this.editor, context).wasFound(); 253 boolean found = false; 254 try { 255 found = SearchEngine.find(this.editor, context); 256 // if the current search string is a correction to a previous invalid regex, 257 // then return background colour back to normal 258 searchField.setBackground(Color.white); 259 if (!found) { 260 JOptionPane.showMessageDialog(this, "Text not found"); 261 } 262 } catch(java.util.regex.PatternSyntaxException regex_exception) { 263 searchField.setBackground(Color.red); 264 JOptionPane.showMessageDialog(this, "Invalid regex"); 265 } 266 267 } 268 } 194 269 195 270
Note:
See TracChangeset
for help on using the changeset viewer.