@Override public void actionPerformed(ActionEvent event) { if (textField.getText().length() == 0) return; RSyntaxTextArea pane = mainWindow.getModel().getCurrentTextArea(); if (pane == null) return; SearchContext context = new SearchContext(); context.setSearchFor(textField.getText()); context.setMatchCase(mcase.isSelected()); context.setRegularExpression(regex.isSelected()); context.setSearchForward(!reverse.isSelected()); context.setWholeWord(wholew.isSelected()); if (!SearchEngine.find(pane, context).wasFound()) { if (wrap.isSelected()) { pane.setSelectionStart(0); pane.setSelectionEnd(0); } else { mainWindow.getLabel().setText("Search Complete"); } } }
@Test public void testSearchEngineReplaceAll_zeroLengthMatches_emptyText() { textArea.setText(""); SearchContext context = new SearchContext(); context.setSearchFor(".*"); context.setReplaceWith(""); context.setRegularExpression(true); int count = replaceAllImpl(context); // The goal here is simply to not go into an infinite loop assertEquals(1, count); }
@Override public void actionPerformed(ActionEvent e) { if (textField.getText().length() == 0) return; RSyntaxTextArea pane = mainWindow.getModel().getCurrentTextArea(); if (pane == null) return; SearchContext context = new SearchContext(); context.setSearchFor(textField.getText()); context.setMatchCase(mcase.isSelected()); context.setRegularExpression(regex.isSelected()); context.setSearchForward(direction); context.setWholeWord(wholew.isSelected()); if (!SearchEngine.find(pane, context).wasFound()) { if (wrap.isSelected()) { pane.setSelectionStart(0); pane.setSelectionEnd(0); } else { mainWindow.getLabel().setText("Search Complete"); } } }
@Test public void testSearchEngineReplaceAll_zeroLengthMatches() { textArea.setText("one two three"); SearchContext context = new SearchContext(); context.setSearchFor(".*"); context.setReplaceWith(""); context.setRegularExpression(true); int count = replaceAllImpl(context); // The goal here is simply to not go into an infinite loop assertEquals(1, count); }
context.setSearchFor(searchText); context.setMatchCase(matchCase); context.setRegularExpression(regex);
@Test public void testSearchEngineReplaceAll_zeroLengthMatches_multiMatch() { textArea.setText("a\nba\n\na"); SearchContext context = new SearchContext(); context.setSearchFor("(?=a)"); context.setReplaceWith("CCC"); context.setRegularExpression(true); int count = replaceAllImpl(context); assertEquals(3, count); assertEquals("CCCa\nbCCCa\n\nCCCa", textArea.getText()); }
@Override public void actionPerformed(ActionEvent e) { // "FindNext" => search forward, "FindPrev" => search backward String command = e.getActionCommand(); boolean forward = "FindNext".equals(command); // Create an object defining our search parameters. SearchContext context = new SearchContext(); String text = searchField.getText(); if (text.length() == 0) { return; } context.setSearchFor(text); context.setMatchCase(matchCaseCB.isSelected()); context.setRegularExpression(regexCB.isSelected()); context.setSearchForward(forward); context.setWholeWord(false); boolean found = SearchEngine.find(textArea, context).wasFound(); if (!found) { JOptionPane.showMessageDialog(this, "Text not found"); } }
context.setSearchFor("chuck"); textArea.setText(text); String expected = textArea.getText().replaceAll("(?i:" + context.getSearchFor() + ")", context.getReplaceWith()); context.setSearchFor("wood"); textArea.setText(text); expected = textArea.getText().replaceAll(context.getSearchFor(), context.getReplaceWith()); context.setSearchFor("wood"); textArea.setText(text); expected = "How much FOOBAR wOuld a woodChuck chUck, if a woodchuck could chuck FOOBAR?"; context.setSearchFor("chUck"); textArea.setText(text); expected = "How much wood wOuld a woodChuck FOOBAR, if a woodchuck could chuck wOod?"; context.setSearchFor("wo(?:o|ul)d"); textArea.setText(text); expected = textArea.getText().replaceAll("(?i:" + context.getSearchFor() + ")", context.getReplaceWith()); context.setSearchFor("wo(?:o|ul)d"); textArea.setText(text); expected = textArea.getText().replaceAll(context.getSearchFor(), context.getReplaceWith()); context.setSearchFor("wo(?:o|ul)d"); textArea.setText(text); expected = "How much FOOBAR FOOBAR a woodChuck chUck, if a woodchuck could chuck FOOBAR?"; context.setSearchFor("wO(?:o|ul)d");
context.setSearchFor(toMark.toLowerCase()); findIn = findIn.toLowerCase();
context.setSearchFor("r(o+)t"); textArea.setText("root roOt root"); String expected = "oo oO oo"; context.setSearchFor("r(o+)t"); textArea.setText("root roOt root"); textArea.setCaretPosition(textArea.getText().length()-4); context.setSearchFor("(\\d)(\\d+)[kM]"); textArea.setText("152k 5271143M 3985k"); expected = "1.52 5.271143 3.985"; context.setSearchFor("(\\d)(\\d+)ABC"); expected = "152k 5271143M 3985k"; textArea.setText(expected);
private SearchContext createSearchContext(String text, boolean forward, boolean matchCase, boolean isRegex) { SearchContext context = new SearchContext(); context.setSearchFor(text); context.setMatchCase(matchCase); context.setRegularExpression(isRegex); context.setSearchForward(forward); context.setMarkAll(false); context.setSearchSelectionOnly(false); context.setWholeWord(false); return context; } }
/** * Click on the replace all button */ public void onReplaceAll() { String text = findTF.getText(); if (text.length() == 0) { return; } String textReplace = replaceTF.getText(); if (!textReplace.equals(text)) { 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.replaceAll(rSyntaxTextArea, c); } }
/** * Click on the find next button */ public void onFindNext() { 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(); SearchContext c = new SearchContext(); c.setMarkAll(markAll); c.setMatchCase(matchCase); c.setSearchFor(text); c.setWholeWord(wholeWord); c.setRegularExpression(regex); c.setSearchForward(forward); boolean found = SearchEngine.find(rSyntaxTextArea, c).wasFound(); if (!found) { LOGGER.info(I18N.tr("Text not found !")); } }
/** * Click on the replace all button */ public void onReplaceAll() { String text = findTF.getText(); if (text.length() == 0) { return; } String textReplace = replaceTF.getText(); if (!textReplace.equals(text)) { 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.replaceAll(rSyntaxTextArea, c); } }
/** * Click on the find next button */ public void onFindNext() { 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) { LOGGER.info(I18N.tr("Text not found !")); } }
context.setSearchFor("chuck"); context.setMatchCase(false); textArea.setCaretPosition(end); context.setSearchFor("Chuck"); context.setMatchCase(true); textArea.setCaretPosition(end); context.setSearchFor("Chuck"); context.setMatchCase(false); context.setWholeWord(true); context.setSearchFor("wood"); context.setMatchCase(true); context.setWholeWord(true); context.setSearchFor(".ould"); context.setMatchCase(false); context.setWholeWord(false); context.setSearchFor(".ould"); context.setMatchCase(true); context.setWholeWord(false); context.setSearchFor("[cd]hUCk"); context.setMatchCase(false); context.setWholeWord(true); context.setSearchFor("[cd]huck");
context.setSearchFor("chuck"); textArea.setText(text); String expected = textArea.getText().replaceAll("(?i:" + context.getSearchFor() + ")", context.getReplaceWith()); context.setSearchFor("chuck"); textArea.setText(text); expected = textArea.getText().replaceAll(context.getSearchFor(), context.getReplaceWith()); context.setSearchFor("chuck"); textArea.setText(text); expected = "How much wood wOuld a woodChuck FOOBAR, if a woodchuck could FOOBAR wOod?"; context.setSearchFor("chuck"); textArea.setText(text); expected = "How much wood wOuld a woodChuck chUck, if a woodchuck could FOOBAR wOod?"; context.setSearchFor(".huck"); textArea.setText(text); expected = textArea.getText().replaceAll("(?i:" + context.getSearchFor() + ")", context.getReplaceWith()); context.setSearchFor(".huck"); textArea.setText(text); expected = textArea.getText().replaceAll(context.getSearchFor(), context.getReplaceWith()); context.setSearchFor("[cd]huck"); textArea.setText(text); expected = "How much wood wOuld a woodChuck FOOBAR, if a woodchuck could FOOBAR wOod?"; context.setSearchFor("[cd]hUck");
context.setSearchFor("chuck"); int markedCount = markAll ? 4 : 0; boolean found = findImpl(context); context.setSearchFor("Chuck"); markedCount = markAll ? 1 : 0; context.setMatchCase(true); context.setSearchFor("chuck"); markedCount = markAll ? 2 : 0; context.setMatchCase(false); context.setSearchFor("wood"); markedCount = markAll ? 1 : 0; context.setMatchCase(true); context.setSearchFor(".ould"); markedCount = markAll ? 2 : 0; context.setMatchCase(false); context.setSearchFor(".ould"); markedCount = markAll ? 1 : 0; context.setMatchCase(true); context.setSearchFor("[cd]hUCk"); markedCount = markAll ? 2 : 0; context.setMatchCase(false); context.setSearchFor("[cd]huck");
context.setSearchFor("chuck"); int markedCount = markAll ? 4 : 0; context.setMatchCase(false); context.setSearchFor("Chuck"); markedCount = markAll ? 1 : 0; context.setMatchCase(true); context.setSearchFor("Chuck"); markedCount = markAll ? 2 : 0; context.setMatchCase(false); context.setSearchFor("wood"); markedCount = markAll ? 1 : 0; context.setMatchCase(true); context.setSearchFor(".ould"); markedCount = markAll ? 2 : 0; context.setMatchCase(false); context.setSearchFor(".ould"); markedCount = markAll ? 1 : 0; context.setMatchCase(true); context.setSearchFor("[cd]hUCk"); markedCount = markAll ? 2 : 0; context.setMatchCase(false); context.setSearchFor("[cd]huck");
public void searchInTextarea() { String text = samlGUI.getActionPanel().getSearchText(); SearchContext context = new SearchContext(); context.setMatchCase(false); context.setMarkAll(true); context.setSearchFor(text); context.setWholeWord(false); SearchResult result = SearchEngine.find(textArea, context); if (!result.wasFound()) { textArea.setCaretPosition(0); SearchEngine.find(textArea, context); } }