Package org.fife.rsta.ac
Class SourceTreeNode
java.lang.Object
javax.swing.tree.DefaultMutableTreeNode
org.fife.rsta.ac.SourceTreeNode
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<SourceTreeNode>,MutableTreeNode,TreeNode
- Direct Known Subclasses:
JavaScriptTreeNode,JavaTreeNode,XmlTreeNode
Base class for tree nodes in an
AbstractSourceTree. They can be
sorted and filtered based on user input.- Version:
- 1.0
- See Also:
-
Field Summary
FieldsFields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject -
Constructor Summary
ConstructorsConstructorDescriptionSourceTreeNode(Object userObject) Creates an unsorted tree node.SourceTreeNode(Object userObject, boolean sorted) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(MutableTreeNode child) Overridden to ensure the new child is only made visible if it is matched by the current filter.children()Overridden to operate over visible children only.clone()Returns a clone of this tree node.Returns a clone of this tree node and all of its children.intcompareTo(SourceTreeNode stn2) Overridden to provide proper sorting of source tree nodes when the parentAbstractSourceTreeis sorted.protected voidFilters the children of this tree node based on the specified prefix.getChildAfter(TreeNode child) Overridden to operate over visible children only.getChildAt(int index) Overridden to operate over visible children only.getChildBefore(TreeNode child) Overridden to operate over visible children only.intOverridden to operate over visible children only.intOverridden to operate over visible children only.intReturns the relative priority of this node against others when being sorted (lower is higher priority).booleanReturns whether this particular node's children can be sorted.booleanisSorted()Returns whether this node is sorted.voidrefresh()Refreshes this tree node and its children.private voidRefreshes what children are visible in the tree.voidsetSortable(boolean sortable) Sets whether this particular node's children are sortable.voidsetSorted(boolean sorted) Sets whether this tree node (and any child sortable tree nodes) are sorting their children.voidsetSortPriority(int priority) Sets the relative sort priority of this tree node when it is compared against others (lower is higher priority).Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
breadthFirstEnumeration, depthFirstEnumeration, getAllowsChildren, getDepth, getFirstChild, getFirstLeaf, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject, toString
-
Field Details
-
sortable
private boolean sortable -
sorted
private boolean sorted -
pattern
-
visibleChildren
-
sortPriority
private int sortPriority
-
-
Constructor Details
-
SourceTreeNode
Creates an unsorted tree node.- Parameters:
userObject- The user data for this tree node.
-
SourceTreeNode
Constructor.- Parameters:
userObject- The user data for this tree node.sorted- Whether any child nodes added to this one should be sorted.
-
-
Method Details
-
add
Overridden to ensure the new child is only made visible if it is matched by the current filter.- Overrides:
addin classDefaultMutableTreeNode- Parameters:
child- The child node to add.
-
children
Overridden to operate over visible children only.- Specified by:
childrenin interfaceTreeNode- Overrides:
childrenin classDefaultMutableTreeNode- Returns:
- The visible children.
-
clone
Returns a clone of this tree node. The clone will not contain any child nodes.- Overrides:
clonein classDefaultMutableTreeNode- Returns:
- The clone of this node.
- See Also:
-
cloneWithChildren
Returns a clone of this tree node and all of its children.- Returns:
- The clone of this node.
- See Also:
-
compareTo
Overridden to provide proper sorting of source tree nodes when the parentAbstractSourceTreeis sorted. Sorting is done first by priority, and nodes with equal priority are then sorted by their string representations, ignoring case. Subclasses can override this method if they wish to do more intricate sorting.- Specified by:
compareToin interfaceComparable<SourceTreeNode>- Parameters:
stn2- A tree node to compare to.- Returns:
- How these tree nodes compare relative to each other.
-
filter
Filters the children of this tree node based on the specified prefix.- Parameters:
pattern- The pattern that the child nodes must match. If this isnull, all possible children are shown.
-
getChildAfter
Overridden to operate over visible children only.- Overrides:
getChildAfterin classDefaultMutableTreeNode- Parameters:
child- The child node.- Returns:
- The visible child after the specified node, or
nullif none.
-
getChildAt
Overridden to operate over visible children only.- Specified by:
getChildAtin interfaceTreeNode- Overrides:
getChildAtin classDefaultMutableTreeNode- Parameters:
index- The index of the visible child to retrieve.- Returns:
- The visible child after the specified index.
-
getChildBefore
Overridden to operate over visible children only.- Overrides:
getChildBeforein classDefaultMutableTreeNode- Parameters:
child- The child node.- Returns:
- The visible child before the specified node, or
nullif none.
-
getChildCount
public int getChildCount()Overridden to operate over visible children only.- Specified by:
getChildCountin interfaceTreeNode- Overrides:
getChildCountin classDefaultMutableTreeNode- Returns:
- The number of visible child nodes.
-
getIndex
Overridden to operate over visible children only.- Specified by:
getIndexin interfaceTreeNode- Overrides:
getIndexin classDefaultMutableTreeNode- Parameters:
child- The child node.- Returns:
- The index of the child, if it is visible. If the child node is
not contained in this tree, or is simply not visible,
-1is returned.
-
getSortPriority
public int getSortPriority()Returns the relative priority of this node against others when being sorted (lower is higher priority).- Returns:
- The relative priority.
- See Also:
-
isSortable
public boolean isSortable()Returns whether this particular node's children can be sorted.- Returns:
- Whether this node's children can be sorted.
- See Also:
-
isSorted
public boolean isSorted()Returns whether this node is sorted.- Returns:
- Whether this node is sorted.
-
refresh
public void refresh()Refreshes this tree node and its children. -
refreshVisibleChildren
private void refreshVisibleChildren()Refreshes what children are visible in the tree. -
setSortable
public void setSortable(boolean sortable) Sets whether this particular node's children are sortable. Usually, only tree nodes containing only "leaves" should be sorted (for example, a "types" node).- Parameters:
sortable- Whether this node's children are sortable.- See Also:
-
setSorted
public void setSorted(boolean sorted) Sets whether this tree node (and any child sortable tree nodes) are sorting their children.- Parameters:
sorted- Whether sorting is enabled.- See Also:
-
setSortPriority
public void setSortPriority(int priority) Sets the relative sort priority of this tree node when it is compared against others (lower is higher priority).- Parameters:
priority- The relative priority.- See Also:
-