/** * <code>findAll</code> uses the Searchable to find all the element indices that match the searching string. * * @param s the searching string. * @return the list of indices. */ public java.util.List<Integer> findAll(String s) { String str = isCaseSensitive() ? s : s.toLowerCase(); java.util.List<Integer> list = new ArrayList<Integer>(); for (int i = 0, count = getElementCount(); i < count; i++) { Object elementAt = getElementAt(i); if (compare(elementAt, str)) { list.add(i); } } return list; }
/** * 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 first element that matches the searching text. * * @param s the searching text * @return the first element that matches with the searching text. */ public int findFirst(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); if (compare(element, str)) return index; } return -1; }
/** * 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; } }
private void setSelectedItem(Object item) { _selecting = true; for (int i = 0, n = getSearchable().getElementCount(); i < n; i++) { Object currentItem = getSearchable().getElementAt(i); // current item starts with the pattern? if (JideSwingUtilities.equals(item, currentItem)) { getSearchable().setSelectedIndex(i, false); } } _selecting = false; }
/** * Finds the next matching index from the cursor. * * @param s the searching text * @return the next index that the element matches the searching text. */ public int findNext(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 < count; i++) { Object element = getElementAt(i); if (compare(element, str)) return i; } if (isRepeats()) { for (int i = 0; i < selectedIndex; i++) { Object element = getElementAt(i); if (compare(element, str)) return i; } } return selectedIndex == -1 ? -1 : (compare(getElementAt(selectedIndex), str) ? selectedIndex : -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); }
if (selectedIndex < 0) selectedIndex = 0; int count = getElementCount(); if (count == 0) return -1; // no match
index = getSearchable().getSelectedIndex(); if (index == -1) { if (getSearchable().getElementCount() > 0) { index = 0; getSearchable().setSelectedIndex(0, false); if (getSearchable().getElementCount() > 0) { index = 0; getSearchable().setSelectedIndex(0, false);
if (selectedIndex < 0) selectedIndex = 0; int count = getElementCount(); if (count == 0) return -1; // no match