public void replaceAll(boolean back) { SearchContext context = new SearchContext(); String findText = this.findTextField.getText(); String text = this.replaceTextField.getText(); if (text.length() == 0) { return; } context.setSearchFor(findText); context.setReplaceWith(text); context.setMatchCase(this.matchCaseCheckBox.isSelected()); context.setRegularExpression(this.regExCheckBox.isSelected()); context.setSearchForward(back); context.setWholeWord(this.wholeWordsOnlyCheckBox.isSelected()); SearchResult found = SearchEngine.replaceAll(selectedArea, context); if (found.wasFound()) { JOptionPane.showMessageDialog( this, "Unable to replace the text", "DomainMath IDE", JOptionPane.INFORMATION_MESSAGE); } }
@Override public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if ("FindNext".equals(command)) { String text = findTF.getText(); if (text.length() == 0) { return; } boolean markAll = markAllCB.isSelected(); boolean forward = downCB.isSelected(); boolean matchCase = matchCaseCB.isSelected(); boolean wholeWord = wholeWrdsCB.isSelected(); boolean regex = regexCB.isSelected(); if (markAll) { rSyntaxTextArea.clearMarkAllHighlights(); rSyntaxTextArea.markAll(text, matchCase, wholeWord, regex); } SearchContext c = new SearchContext(); c.setMatchCase(matchCase); c.setSearchFor(text); c.setWholeWord(wholeWord); c.setRegularExpression(regex); c.setSearchForward(forward); boolean found = SearchEngine.find(rSyntaxTextArea, c); if (!found) { JOptionPane.showMessageDialog( this, I18N.getString("orbisgis.org.orbisgis.ui.findReplace.textNotFound")); } } else if ("Close".equals(command)) { setVisible(false); } else if ("Replace".equals(command)) { String text = findTF.getText(); if (text.length() == 0) { return; } String textReplace = replaceTF.getText(); if (textReplace.equals(text)) { return; } else { boolean forward = downCB.isSelected(); boolean matchCase = matchCaseCB.isSelected(); boolean wholeWord = wholeWrdsCB.isSelected(); boolean regex = regexCB.isSelected(); SearchContext c = new SearchContext(); c.setMatchCase(matchCase); c.setSearchFor(text); c.setReplaceWith(textReplace); c.setWholeWord(wholeWord); c.setRegularExpression(regex); c.setSearchForward(forward); boolean found = SearchEngine.find(rSyntaxTextArea, c); if (!found) { JOptionPane.showMessageDialog( this, I18N.getString("orbisgis.org.orbisgis.ui.findReplace.textNotFound")); } } } else if ("ReplaceAll".equals(command)) { String text = findTF.getText(); if (text.length() == 0) { return; } String textReplace = replaceTF.getText(); if (textReplace.equals(text)) { return; } else { boolean matchCase = matchCaseCB.isSelected(); boolean wholeWord = wholeWrdsCB.isSelected(); boolean regex = regexCB.isSelected(); SearchContext c = new SearchContext(); c.setMatchCase(matchCase); c.setSearchFor(text); c.setWholeWord(wholeWord); c.setRegularExpression(regex); c.setReplaceWith(textReplace); SearchEngine.find(rSyntaxTextArea, c); } } }