/** * @param str - if null -> reset current highlights */ private void highlightAllMatches(@Nullable String str) { SearchContext context = new SearchContext(str); context.setMarkAll(true); context.setMatchCase(true); context.setWholeWord(true); SearchEngine.markAll(this, context); }
private Component makeCell(JNode node, int column) { if (column == 0) { JLabel label = new JLabel(node.makeLongString() + " ", node.getIcon(), SwingConstants.LEFT); label.setFont(font); label.setOpaque(true); label.setToolTipText(label.getText()); return label; } if (!node.hasDescString()) { return emptyLabel; } RSyntaxTextArea textArea = CodeArea.getDefaultArea(mainWindow); textArea.setLayout(new GridLayout(1, 1)); textArea.setEditable(false); textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); textArea.setText(" " + node.makeDescString()); textArea.setRows(1); textArea.setColumns(textArea.getText().length() + 1); if (highlightText != null) { SearchContext searchContext = new SearchContext(highlightText); searchContext.setMatchCase(!highlightTextCaseInsensitive); searchContext.setMarkAll(true); SearchEngine.markAll(textArea, searchContext); } return textArea; }
context.setMatchCase(false); textArea.setCaretPosition(end); SearchResult res = SearchEngine.markAll(textArea, context); assertEquals(end, textArea.getCaretPosition()); assertEquals(new SearchResult(null, 0, 4), res); textArea.setCaretPosition(3); res = SearchEngine.markAll(textArea, context); assertEquals(3, textArea.getCaretPosition()); assertEquals(new SearchResult(null, 0, 4), res); context.setMatchCase(true); textArea.setCaretPosition(end); res = SearchEngine.markAll(textArea, context); assertEquals(end, textArea.getCaretPosition()); assertEquals(new SearchResult(null, 0, 1), res); textArea.setCaretPosition(1); res = SearchEngine.markAll(textArea, context); assertEquals(1, textArea.getCaretPosition()); assertEquals(new SearchResult(null, 0, 1), res); context.setWholeWord(true); textArea.setCaretPosition(end); res = SearchEngine.markAll(textArea, context); assertEquals(end, textArea.getCaretPosition()); assertEquals(new SearchResult(null, 0, 2), res); textArea.setCaretPosition(5); res = SearchEngine.markAll(textArea, context); assertEquals(5, textArea.getCaretPosition()); assertEquals(new SearchResult(null, 0, 2), res);
@Override public void searchEvent(SearchEvent e) { SearchEvent.Type type = e.getType(); SearchContext context = e.getSearchContext(); SearchResult result = null; switch (type) { default: // Prevent FindBugs warning later case MARK_ALL: result = SearchEngine.markAll(m_scriptEditor, context); break; case FIND: result = SearchEngine.find(m_scriptEditor, context); if (!result.wasFound()) { UIManager.getLookAndFeel().provideErrorFeedback(m_scriptEditor); } break; case REPLACE: result = SearchEngine.replace(m_scriptEditor, context); if (!result.wasFound()) { UIManager.getLookAndFeel().provideErrorFeedback(m_scriptEditor); } break; case REPLACE_ALL: result = SearchEngine.replaceAll(m_scriptEditor, context); JOptionPane.showMessageDialog(null, result.getCount() + " occurrences replaced."); break; } }