/** * Sets the cursor which is the index of current location when searching. The value will be used in findNext and * findPrevious. * * @param cursor the new position of the cursor. */ public void setCursor(int cursor) { setCursor(cursor, false); }
private void highlightAllOrNext() { if (_highlightsButton.isSelected()) { _previousCursor = _searchable.getCurrentIndex(); highlightAll(); } else { if (_previousCursor >= 0) { _searchable.setCursor(_previousCursor); _searchable.setSelectedIndex(_previousCursor, false); } highlightNext(); } }
/** * Select the index for the searching text. * * @param index the start offset * @param searchingText the searching text presented in the searchable event to be fired here. */ protected void select(int index, String searchingText) { if (index != -1) { setSelectedIndex(index, true); setCursor(index, true); Object element = getElementAt(index); fireSearchableEvent(new SearchableEvent(this, SearchableEvent.SEARCHABLE_MATCH, searchingText, element, convertElementToString(element))); } else { setSelectedIndex(-1, false); fireSearchableEvent(new SearchableEvent(this, SearchableEvent.SEARCHABLE_NOMATCH, searchingText)); } }
@Override protected void select(int index, KeyEvent e, String searchingText) { if (index != -1) { boolean incremental = e != null && isIncrementalSelectKey(e); setSelectedIndex(index, incremental); Searchable.this.setCursor(index, incremental); _textField.setForeground(Searchable.this.getForeground()); _noMatch.setText(""); } else { _textField.setForeground(getMismatchForeground()); _noMatch.setText(getResourceString("Searchable.noMatch")); } updatePopupBounds(); if (index != -1) { Object element = getElementAt(index); fireSearchableEvent(new SearchableEvent(Searchable.this, SearchableEvent.SEARCHABLE_MATCH, searchingText, element, convertElementToString(element))); } else { fireSearchableEvent(new SearchableEvent(Searchable.this, SearchableEvent.SEARCHABLE_NOMATCH, searchingText)); } }
/** * Hides the popup. */ public void hidePopup() { if (_popup != null) { if (isHeavyweightComponentEnabled()) { _popup.hidePopupImmediately(); } else { if (_layeredPane != null) { _layeredPane.remove(_popup); _layeredPane.validate(); _layeredPane.repaint(); _layeredPane = null; } } _popup = null; _searchableProvider = null; _previousSearchText = null; fireSearchableEvent(new SearchableEvent(Searchable.this, SearchableEvent.SEARCHABLE_END, "", getCurrentIndex(), _previousSearchText)); } setCursor(-1); }
protected void select(int index, String searchingText, boolean incremental) { if (index != -1) { _searchable.setSelectedIndex(index, incremental); _searchable.setCursor(index, incremental); _textField.setBackground(UIDefaultsLookup.getColor("TextField.background")); _comboBox.getEditor().getEditorComponent().setBackground(UIDefaultsLookup.getColor("TextField.background")); } else { _searchable.setSelectedIndex(-1, false); _textField.setBackground(getMismatchBackground()); _comboBox.getEditor().getEditorComponent().setBackground(UIDefaultsLookup.getColor("TextField.background")); } _searchable.firePropertyChangeEvent(searchingText); if (index != -1) { Object element = _searchable.getElementAt(index); _searchable.fireSearchableEvent(new SearchableEvent(_searchable, SearchableEvent.SEARCHABLE_MATCH, searchingText, element, _searchable.convertElementToString(element))); } else { _searchable.fireSearchableEvent(new SearchableEvent(_searchable, SearchableEvent.SEARCHABLE_NOMATCH, searchingText)); } }
if (index != -1) { _searchable.setSelectedIndex(index, false); // clear side effect of ctrl-a will select all items _searchable.setCursor(index); // as setSelectedIndex is used directly, we have to manually set the cursor value. _findNextButton.setEnabled(true); _findPrevButton.setEnabled(true); _searchable.setCursor(0);
if (index != -1) { setSelectedIndex(index, false); // clear side effect of ctrl-a will select all items Searchable.this.setCursor(index); // as setSelectedIndex is used directly, we have to manually set the cursor value.
public void actionPerformed(ActionEvent e) { _highlightsButton.setSelected(false); String text = getSearchingText(); addSearchingTextToHistory(text); int cursor = _searchable.getSelectedIndex(); _searchable.setCursor(cursor); int found = _searchable.findPrevious(text); if (found == cursor) { select(found, text, false); clearStatus(); } else if (found != -1 && _searchable.isRepeats() && found >= cursor) { select(found, text, false); setStatus(getResourceString("SearchableBar.reachedTopRepeat"), getImageIcon(SearchableBarIconsFactory.Buttons.REPEAT)); } else if (!_searchable.isRepeats() && found == -1) { setStatus(getResourceString("SearchableBar.reachedTop"), getImageIcon(SearchableBarIconsFactory.Buttons.ERROR)); } else if (found != -1) { select(found, text, false); clearStatus(); } } };
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(); } } } };