/** * Highlight all matching cases in the target. * <p/> * In default implementation, it will just search all texts in the target to highlight all. If you have a really * huge text to search, you may want to override this method to have a lazy behavior on visible areas only. */ protected void highlightAll() { int firstIndex = -1; int index = getSelectedIndex(); String text = getSearchingText(); while (index != -1) { int newIndex = findNext(text); if (index == newIndex) { index = -1; } else { index = newIndex; } if (index != -1) { if (firstIndex == -1) { firstIndex = index; } select(index, text); } } // now select the first one if (firstIndex != -1) { select(firstIndex, text); } }
@Override public int findNext(String s) { if (_component instanceof JTextComponent) { String text = getDocumentText(); int selectedIndex = (getCursor() != -1 ? getCursor() : getSelectedIndex()); if (selectedIndex < 0) selectedIndex = 0; int count = getElementCount(); if (count == 0) return s.length() > 0 ? -1 : 0; // find from cursor int found = isCaseSensitive() ? text.indexOf(s, selectedIndex + 1) : indexOf(text, s, selectedIndex + 1); // if not found, start over from the beginning if (found == -1 && isRepeats()) { found = isCaseSensitive() ? text.indexOf(s, 0) : indexOf(text, s, 0); if (found > selectedIndex) { found = -1; } } return found; } else { return super.findNext(s); } }
found = findNext(text); select(found, e, text);
int newIndex = findNext(text); if (index == newIndex) { index = -1;
setSelectedIndex(newIndex, false); oldIndex = newIndex; newIndex = findNext(s); _matchCount++;
public void actionPerformed(ActionEvent e) { _highlightsButton.setSelected(false); String text = getSearchingText(); addSearchingTextToHistory(text); int cursor = _searchable.getSelectedIndex(); _searchable.setCursor(cursor); int found = _searchable.findNext(text); if (found == cursor) { select(found, text, false); clearStatus(); } else if (found != -1 && _searchable.isRepeats() && found <= cursor) { select(found, text, false); setStatus(getResourceString("SearchableBar.reachedBottomRepeat"), getImageIcon(SearchableBarIconsFactory.Buttons.REPEAT)); } else if (!_searchable.isRepeats() && found == -1) { setStatus(getResourceString("SearchableBar.reachedBottom"), getImageIcon(SearchableBarIconsFactory.Buttons.ERROR)); } else if (found != -1) { select(found, text, false); clearStatus(); if (_searchable.getSearchingDelay() < 0) { // never updated the count so we update here highlightAllOrNext(); } } } };