List of usage examples for javax.swing JTree isRowSelected
public boolean isRowSelected(int row)
From source file:org.executequery.gui.browser.TreeFindAction.java
protected boolean changed(JComponent comp, String searchString, Position.Bias bias) { if (StringUtils.isBlank(searchString)) { return false; }/*www. ja v a 2 s. co m*/ JTree tree = (JTree) comp; String prefix = searchString; if (ignoreCase()) { prefix = prefix.toUpperCase(); } boolean wildcardStart = prefix.startsWith("*"); if (wildcardStart) { prefix = prefix.substring(1); } else { prefix = "^" + prefix; } prefix = prefix.replaceAll("\\*", ".*"); Matcher matcher = Pattern.compile(prefix).matcher(""); List<TreePath> matchedPaths = new ArrayList<TreePath>(); for (int i = 1; i < tree.getRowCount(); i++) { TreePath path = tree.getPathForRow(i); String text = tree.convertValueToText(path.getLastPathComponent(), tree.isRowSelected(i), tree.isExpanded(i), true, i, false); if (ignoreCase()) { text = text.toUpperCase(); } // if ((wildcardStart && text.contains(prefix)) || text.startsWith(prefix, 0)) { // // matchedPaths.add(path); // } matcher.reset(text); if (matcher.find()) { matchedPaths.add(path); } } foundValues(matchedPaths); return !(matchedPaths.isEmpty()); }
From source file:org.executequery.gui.browser.TreeFindAction.java
public TreePath getNextMatch(JTree tree, String prefix, int startingRow, Position.Bias bias) { int max = tree.getRowCount(); if (prefix == null) { throw new IllegalArgumentException(); }//from w ww . ja v a2s . c om if (startingRow < 0 || startingRow >= max) { throw new IllegalArgumentException(); } if (ignoreCase()) { prefix = prefix.toUpperCase(); } // start search from the next/previous element froom the // selected element int increment = (bias == null || bias == Position.Bias.Forward) ? 1 : -1; int row = startingRow; do { TreePath path = tree.getPathForRow(row); String text = tree.convertValueToText(path.getLastPathComponent(), tree.isRowSelected(row), tree.isExpanded(row), true, row, false); if (ignoreCase()) { text = text.toUpperCase(); } if (text.startsWith(prefix)) { return path; } row = (row + increment + max) % max; } while (row != startingRow); return null; }