Lines 191-196
Link Here
|
191 |
transient private int allowedDragActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE; |
191 |
transient private int allowedDragActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE; |
192 |
transient private int allowedDropActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE; |
192 |
transient private int allowedDropActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE; |
193 |
|
193 |
|
|
|
194 |
/** |
195 |
* Whether the quick search uses prefix or substring. |
196 |
* Defaults to false meaning prefix is used. |
197 |
*/ |
198 |
transient private boolean quickSearchUsingSubstring = false; |
199 |
|
194 |
/** Constructor. |
200 |
/** Constructor. |
195 |
*/ |
201 |
*/ |
196 |
public TreeView() { |
202 |
public TreeView() { |
Lines 383-388
Link Here
|
383 |
tree.setShowsRootHandles(!visible); |
389 |
tree.setShowsRootHandles(!visible); |
384 |
} |
390 |
} |
385 |
|
391 |
|
|
|
392 |
/** |
393 |
* Set whether the quick search feature uses substring or prefix |
394 |
* matching for the typed characters. Defaults to prefix (false). |
395 |
* @since 6.11 |
396 |
* @param useSubstring <code>true</code> if substring search is used in quick search |
397 |
*/ |
398 |
public void setUseSubstringInQuickSearch(boolean useSubstring) { |
399 |
quickSearchUsingSubstring = useSubstring; |
400 |
} |
401 |
|
386 |
/********** Support for the Drag & Drop operations *********/ |
402 |
/********** Support for the Drag & Drop operations *********/ |
387 |
/** Drag support is enabled by default. |
403 |
/** Drag support is enabled by default. |
388 |
* @return true if dragging from the view is enabled, false |
404 |
* @return true if dragging from the view is enabled, false |
Lines 1705-1716
Link Here
|
1705 |
while (true) { |
1721 |
while (true) { |
1706 |
startIndex = startIndex % size; |
1722 |
startIndex = startIndex % size; |
1707 |
|
1723 |
|
1708 |
TreePath path = getNextMatch(prefix, startIndex, Position.Bias.Forward); |
1724 |
TreePath path = null; |
|
|
1725 |
if (quickSearchUsingSubstring) { |
1726 |
path = getNextSubstringMatch(prefix, startIndex, Position.Bias.Forward); |
1727 |
} else { |
1728 |
path = getNextMatch(prefix, startIndex, Position.Bias.Forward); |
1729 |
} |
1709 |
|
1730 |
|
1710 |
if ((path != null) && !results.contains(path)) { |
1731 |
if ((path != null) && !results.contains(path)) { |
1711 |
startIndex = tree.getRowForPath(path); |
1732 |
startIndex = tree.getRowForPath(path); |
1712 |
results.add(path); |
1733 |
results.add(path); |
1713 |
|
1734 |
|
|
|
1735 |
if (!quickSearchUsingSubstring) { |
1714 |
String elementName = ((VisualizerNode) path.getLastPathComponent()).getDisplayName(); |
1736 |
String elementName = ((VisualizerNode) path.getLastPathComponent()).getDisplayName(); |
1715 |
|
1737 |
|
1716 |
// initialize prefix |
1738 |
// initialize prefix |
Lines 1719-1725
Link Here
|
1719 |
} |
1741 |
} |
1720 |
|
1742 |
|
1721 |
maxPrefix = findMaxPrefix(maxPrefix, elementName); |
1743 |
maxPrefix = findMaxPrefix(maxPrefix, elementName); |
1722 |
|
1744 |
} |
1723 |
// try next element |
1745 |
// try next element |
1724 |
startIndex++; |
1746 |
startIndex++; |
1725 |
} else { |
1747 |
} else { |
Lines 1741-1746
Link Here
|
1741 |
} |
1763 |
} |
1742 |
|
1764 |
|
1743 |
/** |
1765 |
/** |
|
|
1766 |
* Copied and adapted from JTree.getNextMatch(...). |
1767 |
*/ |
1768 |
private TreePath getNextSubstringMatch( |
1769 |
String substring, int startingRow, Position.Bias bias) { |
1770 |
|
1771 |
int max = getRowCount(); |
1772 |
if (substring == null) { |
1773 |
throw new IllegalArgumentException(); |
1774 |
} |
1775 |
if (startingRow < 0 || startingRow >= max) { |
1776 |
throw new IllegalArgumentException(); |
1777 |
} |
1778 |
substring = substring.toUpperCase(); |
1779 |
|
1780 |
// start search from the next/previous element froom the |
1781 |
// selected element |
1782 |
int increment = (bias == Position.Bias.Forward) ? 1 : -1; |
1783 |
int row = startingRow; |
1784 |
do { |
1785 |
TreePath path = getPathForRow(row); |
1786 |
String text = convertValueToText( |
1787 |
path.getLastPathComponent(), isRowSelected(row), |
1788 |
isExpanded(row), true, row, false); |
1789 |
|
1790 |
if (text.toUpperCase().indexOf(substring) >= 0) { |
1791 |
return path; |
1792 |
} |
1793 |
row = (row + increment + max) % max; |
1794 |
} while (row != startingRow); |
1795 |
return null; |
1796 |
} |
1797 |
|
1798 |
/** |
1744 |
* Adds the search field to the tree. |
1799 |
* Adds the search field to the tree. |
1745 |
*/ |
1800 |
*/ |
1746 |
private void displaySearchField() { |
1801 |
private void displaySearchField() { |