/** * 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); }
/** * <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; }
_pattern = Pattern.compile(isFromStart() ? "^" + s : s, isCaseSensitive() ? 0 : Pattern.CASE_INSENSITIVE); return _pattern.matcher(text).find();
/** * 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; } }
/** * Creates the match case button. By default it will return a JCheckBox. Subclass class can override it to return * your own button or customize the button created by default as long as it can set underlying Searchable's * caseSensitive property. * * @return the match case button. */ protected AbstractButton createMatchCaseButton() { JCheckBox checkBox = new JCheckBox(getResourceString("SearchableBar.matchCase")); checkBox.setMnemonic(getResourceString("SearchableBar.matchCase.mnemonic").charAt(0)); checkBox.setRequestFocusEnabled(false); checkBox.setFocusable(false); checkBox.setSelected(getSearchable().isCaseSensitive()); checkBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getSource() instanceof AbstractButton) { getSearchable().setCaseSensitive(((AbstractButton) e.getSource()).isSelected()); addSearchingTextToHistory(getSearchingText()); highlightAllOrNext(); } } }); checkBox.setOpaque(false); return checkBox; }
/** * 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); }
String str = isCaseSensitive() ? s : s.toLowerCase(); int selectedIndex = getCurrentIndex(); if (selectedIndex < 0)
String str = isCaseSensitive() ? s : s.toLowerCase(); int selectedIndex = getCurrentIndex(); if (selectedIndex < 0)