Lines 488-494
Link Here
|
488 |
* matching for the typed characters. Defaults to prefix (false). |
488 |
* matching for the typed characters. Defaults to prefix (false). |
489 |
* @since 6.11 |
489 |
* @since 6.11 |
490 |
* @param useSubstring <code>true</code> if substring search is used in quick search |
490 |
* @param useSubstring <code>true</code> if substring search is used in quick search |
|
|
491 |
* @deprecated Deprecated as the quick search feature uses both substring and prefix |
492 |
* matching. All prefix matches for the typed characters will appear before substring |
493 |
* matches. |
491 |
*/ |
494 |
*/ |
|
|
495 |
@Deprecated |
492 |
public void setUseSubstringInQuickSearch(boolean useSubstring) { |
496 |
public void setUseSubstringInQuickSearch(boolean useSubstring) { |
493 |
quickSearchUsingSubstring = useSubstring; |
497 |
quickSearchUsingSubstring = useSubstring; |
494 |
} |
498 |
} |
Lines 2079-2084
Link Here
|
2079 |
private List<TreePath> doSearch(String prefix) { |
2083 |
private List<TreePath> doSearch(String prefix) { |
2080 |
List<TreePath> results = new ArrayList<TreePath>(); |
2084 |
List<TreePath> results = new ArrayList<TreePath>(); |
2081 |
Set<TreePath> resSet = new HashSet<TreePath>(); |
2085 |
Set<TreePath> resSet = new HashSet<TreePath>(); |
|
|
2086 |
|
2087 |
// starting index of substring matches within the results |
2088 |
int startOfSubstringMatches = 0; |
2082 |
|
2089 |
|
2083 |
int startIndex = origSelectionPaths != null ? Math.max(0, getRowForPath(origSelectionPaths[0])) : 0; |
2090 |
int startIndex = origSelectionPaths != null ? Math.max(0, getRowForPath(origSelectionPaths[0])) : 0; |
2084 |
int size = getRowCount(); |
2091 |
int size = getRowCount(); |
Lines 2091-2109
Link Here
|
2091 |
while (true) { |
2098 |
while (true) { |
2092 |
startIndex = startIndex % size; |
2099 |
startIndex = startIndex % size; |
2093 |
|
2100 |
|
2094 |
TreePath path = null; |
2101 |
SubstringSearchResult substringSearchResult = getNextSubstringMatch(prefix, startIndex, Position.Bias.Forward); |
2095 |
if (quickSearchUsingSubstring) { |
2102 |
TreePath path = substringSearchResult != null? substringSearchResult.treePath: null; |
2096 |
path = getNextSubstringMatch(prefix, startIndex, Position.Bias.Forward); |
|
|
2097 |
} else { |
2098 |
path = getNextMatch(prefix, startIndex, Position.Bias.Forward); |
2099 |
} |
2100 |
|
2103 |
|
2101 |
if ((path != null) && !resSet.contains(path)) { |
2104 |
if ((path != null) && !resSet.contains(path)) { |
2102 |
startIndex = tree.getRowForPath(path); |
2105 |
startIndex = tree.getRowForPath(path); |
2103 |
results.add(path); |
2106 |
boolean isPrefixMatch = true; |
|
|
2107 |
// put all prefix matches to the top of the list while |
2108 |
// substring matches remains in the end of the list |
2109 |
if (substringSearchResult.index == 0) { |
2110 |
results.add(startOfSubstringMatches++, path); |
2111 |
} else { |
2112 |
isPrefixMatch = false; |
2113 |
results.add(path); |
2114 |
} |
2104 |
resSet.add(path); |
2115 |
resSet.add(path); |
2105 |
|
2116 |
|
2106 |
if (!quickSearchUsingSubstring) { |
2117 |
// calculate max prefix only with prefix matches |
|
|
2118 |
if (isPrefixMatch) { |
2107 |
String elementName = ((VisualizerNode) path.getLastPathComponent()).getDisplayName(); |
2119 |
String elementName = ((VisualizerNode) path.getLastPathComponent()).getDisplayName(); |
2108 |
|
2120 |
|
2109 |
// initialize prefix |
2121 |
// initialize prefix |
Lines 2135-2142
Link Here
|
2135 |
|
2147 |
|
2136 |
/** |
2148 |
/** |
2137 |
* Copied and adapted from JTree.getNextMatch(...). |
2149 |
* Copied and adapted from JTree.getNextMatch(...). |
|
|
2150 |
* |
2151 |
* @return An instance of SubstringSearchResult containing the matching TreePath |
2152 |
* and the index of the first occurrence of the substring in TreePath. |
2138 |
*/ |
2153 |
*/ |
2139 |
private TreePath getNextSubstringMatch( |
2154 |
private SubstringSearchResult getNextSubstringMatch( |
2140 |
String substring, int startingRow, Position.Bias bias) { |
2155 |
String substring, int startingRow, Position.Bias bias) { |
2141 |
|
2156 |
|
2142 |
int max = getRowCount(); |
2157 |
int max = getRowCount(); |
Lines 2157-2165
Link Here
|
2157 |
String text = convertValueToText( |
2172 |
String text = convertValueToText( |
2158 |
path.getLastPathComponent(), isRowSelected(row), |
2173 |
path.getLastPathComponent(), isRowSelected(row), |
2159 |
isExpanded(row), true, row, false); |
2174 |
isExpanded(row), true, row, false); |
2160 |
|
2175 |
|
2161 |
if (text.toUpperCase().indexOf(substring) >= 0) { |
2176 |
int index = text.toUpperCase().indexOf(substring); |
2162 |
return path; |
2177 |
if (index >= 0) { |
|
|
2178 |
return new SubstringSearchResult(path, index); |
2163 |
} |
2179 |
} |
2164 |
row = (row + increment + max) % max; |
2180 |
row = (row + increment + max) % max; |
2165 |
} while (row != startingRow); |
2181 |
} while (row != startingRow); |
Lines 2456-2461
Link Here
|
2456 |
} |
2472 |
} |
2457 |
} |
2473 |
} |
2458 |
} |
2474 |
} |
|
|
2475 |
|
2476 |
private class SubstringSearchResult { |
2477 |
|
2478 |
TreePath treePath; // holds the matching TreePath |
2479 |
int index; // holds the index of the first occurrence of the substring in TreePath |
2480 |
|
2481 |
public SubstringSearchResult(TreePath treePath, int index) { |
2482 |
this.treePath = treePath; |
2483 |
this.index = index; |
2484 |
} |
2485 |
|
2486 |
} |
2459 |
} |
2487 |
} |
2460 |
|
2488 |
|
2461 |
private static class DummyTransferHandler extends TransferHandler /*implements UIResource*/ { |
2489 |
private static class DummyTransferHandler extends TransferHandler /*implements UIResource*/ { |