private static void setSearchableParams(Searchable searchable) { searchable.setCaseSensitive(false); searchable.setWildcardEnabled(true); searchable.setRepeats(true); }
if (isCountMatch()) { boolean reverse = isReverseOrder(); setReverseOrder(false); int selectedIndex = getCurrentIndex(); if (selectedIndex < 0) { selectedIndex = 0; _matchCount = -1; do { setSelectedIndex(newIndex, false); oldIndex = newIndex; newIndex = findNext(s); _matchCount++; setSelectedIndex(selectedIndex, false); setReverseOrder(reverse); if (isReverseOrder()) { return reverseFindFromCursor(s); String str = isCaseSensitive() ? s : s.toLowerCase(); int selectedIndex = getCurrentIndex(); if (selectedIndex < 0) selectedIndex = 0; int count = getElementCount(); if (count == 0) return -1; // no match Object element = getElementAt(i);
/** * 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)); } }
/** * Gets the element at the specified index as string using {@link #convertElementToString(Object)} method. * * @param index the index. * @return the element at the index converted to string. */ public String getElementAtAsString(int index) { return convertElementToString(getElementAt(index)); }
/** * Checks if the element matches the searching text. * * @param element the element to be checked * @param searchingText the searching text * @return true if matches. */ protected boolean compare(Object element, String searchingText) { String text = convertElementToString(element); return text != null && compare(isCaseSensitive() ? text : text.toLowerCase(), searchingText); }
private void selectAll(KeyEvent e, String text) { boolean oldReverseOrder = isReverseOrder(); // keep the old reverse order and we will set it back. if (oldReverseOrder) { setReverseOrder(false); int index = findFirst(text); 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. boolean oldRepeats = isRepeats(); // set repeats to false and set it back later. if (oldRepeats) { setRepeats(false); int newIndex = findNext(text); if (index == newIndex) { index = -1; setRepeats(oldRepeats); setReverseOrder(oldReverseOrder);
if (!isReverseOrder()) { return findFromCursor(s); String str = isCaseSensitive() ? s : s.toLowerCase(); int selectedIndex = getCurrentIndex(); if (selectedIndex < 0) selectedIndex = 0; int count = getElementCount(); if (count == 0) return -1; // no match Object element = getElementAt(i); if (compare(element, str)) return i; Object element = getElementAt(i); if (compare(element, str)) return i;
/** * Finds the last element that matches the searching text. * * @param s the searching text * @return the last element that matches the searching text. */ public int findLast(String s) { String str = isCaseSensitive() ? s : s.toLowerCase(); int count = getElementCount(); if (count == 0) return s.length() > 0 ? -1 : 0; for (int i = count - 1; i >= 0; i--) { Object element = getElementAt(i); if (compare(element, str)) return i; } return -1; }
/** * Finds the previous matching index from the cursor. * * @param s the searching text * @return the previous index that the element matches the searching text. */ public int findPrevious(String s) { String str = isCaseSensitive() ? s : s.toLowerCase(); int count = getElementCount(); if (count == 0) return s.length() > 0 ? -1 : 0; int selectedIndex = getCurrentIndex(); for (int i = selectedIndex - 1; i >= 0; i--) { Object element = getElementAt(i); if (compare(element, str)) return i; } if (isRepeats()) { for (int i = count - 1; i >= selectedIndex; i--) { Object element = getElementAt(i); if (compare(element, str)) return i; } } return selectedIndex == -1 ? -1 : (compare(getElementAt(selectedIndex), str) ? selectedIndex : -1); }
@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)); } }
int exactIndex = getSearchable().findFirstExactly(text); if (exactIndex != -1) { return; int index = getSearchable().findFromCursor(text); Object item; if (index != -1) { item = getSearchable().getElementAt(index); setSelectedItem(item); setText(getSearchable().convertElementToString(item)); // this is what auto complete is if (isStrict()) { if (offs == 0 && text.equals(str)) { getSearchable().textChanged(""); index = getSearchable().findFromCursor(text); if (index != -1) { item = getSearchable().getElementAt(index); setSelectedItem(item); setText(getSearchable().convertElementToString(item)); // this is what auto complete is index = getSearchable().getSelectedIndex(); if (index == -1) { if (getSearchable().getElementCount() > 0) { index = 0; getSearchable().setSelectedIndex(0, false); item = getSearchable().getElementAt(index); offs = offs - str.length();
return; boolean old = _searchable.isRepeats(); _searchable.setRepeats(false); int index = _searchable.findFirst(text); 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.highlightAll(); _searchable.setRepeats(old); _searchable.setCursor(0);
_componentListener = createComponentListener(); _keyListener = createKeyListener(); JideSwingUtilities.insertKeyListener(getComponent(), _keyListener, 0); _focusListener = createFocusListener(); getComponent().addFocusListener(_focusListener); if (_searchableListener == null) { _searchableListener = new SearchableListener() { addSearchableListener(_searchableListener);
/** * Finds the first element that matches the searching text exactly. * * @param s the searching text * @return the first element that matches with the searching text. * @since 3.6.1 */ public int findFirstExactly(String s) { String str = isCaseSensitive() ? s : s.toLowerCase(); int count = getElementCount(); if (count == 0) return s.length() > 0 ? -1 : 0; for (int i = 0; i < count; i++) { int index = getIndex(count, i); Object element = getElementAt(index); String text = convertElementToString(element); if (JideSwingUtilities.equals(text, str)) return index; } return -1; } }
protected void textChanged(String text) { if (text == null || text.length() == 0) { firePropertyChangeEvent(""); return; } int found = findFromCursor(text); if (found == -1) { firePropertyChangeEvent(text); fireSearchableEvent(new SearchableEvent(this, SearchableEvent.SEARCHABLE_NOMATCH, text)); } else { firePropertyChangeEvent(text); Object element = getElementAt(found); fireSearchableEvent(new SearchableEvent(this, SearchableEvent.SEARCHABLE_MATCH, text, element, convertElementToString(element))); } }
private void setInitValue() { int index = getSearchable().getSelectedIndex(); if (index != -1) { Object selected = getSearchable().getElementAt(index); if (selected != null) _document.setText(getSearchable().convertElementToString(selected)); highlightCompletedText(0); } else { _document.setText(""); } }
_deletePressed = false; String text = getTextComponent().getText(); int index = getSearchable().findFirst(text); if (index != -1) { if (text.length() == 0) { Object item = getSearchable().getElementAt(index); setSelectedItem(item); getTextComponent().setText(getSearchable().convertElementToString(item)); // this is what auto complete is
/** * Creates a searchable bar with initial searching text and in compact mode or full mode. * * @param searchable the searchable * @param initialText the initial text * @param compact the flag indicating compact mode or full mode */ public SearchableBar(Searchable searchable, String initialText, boolean compact) { setFloatable(false); setRollover(true); _searchable = searchable; _searchable.addSearchableListener(new SearchableListener() { public void searchableEventFired(SearchableEvent e) { if (e.getID() == SearchableEvent.SEARCHABLE_MODEL_CHANGE && _searchable.getSearchingText() != null && _searchable.getSearchingText().length() != 0) { highlightAllOrNext(); } } }); _searchable.setSearchableProvider(this); _compact = compact; initComponents(initialText); }
public AutoCompletion(final JTextComponent textComponent, final Searchable searchable) { _searchable = searchable; _searchable.setWildcardEnabled(false); _textComponent = textComponent; registerSelectionListener(getSearchable()); installListeners(); }
private void highlightNext() { _searchable.cancelHighlightAll(); String text = getSearchingText(); if (text == null || text.length() == 0) { _findNextButton.setEnabled(false); _findPrevButton.setEnabled(false); _highlightsButton.setEnabled(false); select(-1, "", false); clearStatus(); return; } int found = _searchable.findFromCursor(text); if (found == -1) { select(-1, "", false); _findNextButton.setEnabled(false); _findPrevButton.setEnabled(false); _highlightsButton.setEnabled(false); setStatus(getResourceString("SearchableBar.notFound"), getImageIcon(SearchableBarIconsFactory.Buttons.ERROR)); } else { select(found, text, false); _findNextButton.setEnabled(true); _findPrevButton.setEnabled(true); _highlightsButton.setEnabled(true); clearStatus(); } }