Package org.fife.rsta.ac
Class SourceTreeNode
- java.lang.Object
-
- javax.swing.tree.DefaultMutableTreeNode
-
- org.fife.rsta.ac.SourceTreeNode
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Comparable<SourceTreeNode>,javax.swing.tree.MutableTreeNode,javax.swing.tree.TreeNode
- Direct Known Subclasses:
JavaScriptTreeNode,JavaTreeNode,XmlTreeNode
public class SourceTreeNode extends javax.swing.tree.DefaultMutableTreeNode implements java.lang.Comparable<SourceTreeNode>
Base class for tree nodes in anAbstractSourceTree. They can be sorted and filtered based on user input.- Version:
- 1.0
- See Also:
AbstractSourceTree, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.regex.Patternpatternprivate booleansortableprivate booleansortedprivate intsortPriorityprivate java.util.List<javax.swing.tree.TreeNode>visibleChildren
-
Constructor Summary
Constructors Constructor Description SourceTreeNode(java.lang.Object userObject)Creates an unsorted tree node.SourceTreeNode(java.lang.Object userObject, boolean sorted)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(javax.swing.tree.MutableTreeNode child)Overridden to ensure the new child is only made visible if it is matched by the current filter.java.util.Enumeration<javax.swing.tree.TreeNode>children()Overridden to operate over visible children only.java.lang.Objectclone()Returns a clone of this tree node.SourceTreeNodecloneWithChildren()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 voidfilter(java.util.regex.Pattern pattern)Filters the children of this tree node based on the specified prefix.javax.swing.tree.TreeNodegetChildAfter(javax.swing.tree.TreeNode child)Overridden to operate over visible children only.javax.swing.tree.TreeNodegetChildAt(int index)Overridden to operate over visible children only.javax.swing.tree.TreeNodegetChildBefore(javax.swing.tree.TreeNode child)Overridden to operate over visible children only.intgetChildCount()Overridden to operate over visible children only.intgetIndex(javax.swing.tree.TreeNode child)Overridden to operate over visible children only.intgetSortPriority()Returns the relative priority of this node against others when being sorted (lower is higher priority).booleanisSortable()Returns 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 voidrefreshVisibleChildren()Refreshes 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
-
-
-
-
Constructor Detail
-
SourceTreeNode
public SourceTreeNode(java.lang.Object userObject)
Creates an unsorted tree node.- Parameters:
userObject- The user data for this tree node.
-
SourceTreeNode
public SourceTreeNode(java.lang.Object userObject, boolean sorted)Constructor.- Parameters:
userObject- The user data for this tree node.sorted- Whether any child nodes added to this one should be sorted.
-
-
Method Detail
-
add
public void add(javax.swing.tree.MutableTreeNode child)
Overridden to ensure the new child is only made visible if it is matched by the current filter.- Overrides:
addin classjavax.swing.tree.DefaultMutableTreeNode- Parameters:
child- The child node to add.
-
children
public java.util.Enumeration<javax.swing.tree.TreeNode> children()
Overridden to operate over visible children only.- Specified by:
childrenin interfacejavax.swing.tree.TreeNode- Overrides:
childrenin classjavax.swing.tree.DefaultMutableTreeNode- Returns:
- The visible children.
-
clone
public java.lang.Object clone()
Returns a clone of this tree node. The clone will not contain any child nodes.- Overrides:
clonein classjavax.swing.tree.DefaultMutableTreeNode- Returns:
- The clone of this node.
- See Also:
cloneWithChildren()
-
cloneWithChildren
public SourceTreeNode cloneWithChildren()
Returns a clone of this tree node and all of its children.- Returns:
- The clone of this node.
- See Also:
clone()
-
compareTo
public int compareTo(SourceTreeNode stn2)
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 interfacejava.lang.Comparable<SourceTreeNode>- Parameters:
stn2- A tree node to compare to.- Returns:
- How these tree nodes compare relative to each other.
-
filter
protected void filter(java.util.regex.Pattern pattern)
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
public javax.swing.tree.TreeNode getChildAfter(javax.swing.tree.TreeNode child)
Overridden to operate over visible children only.- Overrides:
getChildAfterin classjavax.swing.tree.DefaultMutableTreeNode- Parameters:
child- The child node.- Returns:
- The visible child after the specified node, or
nullif none.
-
getChildAt
public javax.swing.tree.TreeNode getChildAt(int index)
Overridden to operate over visible children only.- Specified by:
getChildAtin interfacejavax.swing.tree.TreeNode- Overrides:
getChildAtin classjavax.swing.tree.DefaultMutableTreeNode- Parameters:
index- The index of the visible child to retrieve.- Returns:
- The visible child after the specified index.
-
getChildBefore
public javax.swing.tree.TreeNode getChildBefore(javax.swing.tree.TreeNode child)
Overridden to operate over visible children only.- Overrides:
getChildBeforein classjavax.swing.tree.DefaultMutableTreeNode- 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 interfacejavax.swing.tree.TreeNode- Overrides:
getChildCountin classjavax.swing.tree.DefaultMutableTreeNode- Returns:
- The number of visible child nodes.
-
getIndex
public int getIndex(javax.swing.tree.TreeNode child)
Overridden to operate over visible children only.- Specified by:
getIndexin interfacejavax.swing.tree.TreeNode- Overrides:
getIndexin classjavax.swing.tree.DefaultMutableTreeNode- 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:
setSortPriority(int)
-
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:
setSortable(boolean)
-
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:
isSortable()
-
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:
isSorted()
-
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:
getSortPriority()
-
-