org.fife.rtext.plugins.sourcebrowser
Class SourceTreeNode

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by org.fife.rtext.plugins.sourcebrowser.SourceTreeNode
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode

public class SourceTreeNode
extends javax.swing.tree.DefaultMutableTreeNode

Base class for tree nodes in an DefaultSourceTree. They can be sorted and filtered based on user input.

This class is a clone of the identical class in RSTALanguageSupport, but unfortunately exists to prevent a dependency on that library in this plugin.

Version:
1.0
Author:
Robert Futrell
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
SourceTreeNode(java.lang.Object userObject)
           
SourceTreeNode(java.lang.Object userObject, boolean sorted)
           
 
Method Summary
 void add(javax.swing.tree.MutableTreeNode child)
           
 java.util.Enumeration<?> children()
           
 int compareTo(java.lang.Object obj)
           
 java.util.Comparator<java.lang.Object> createComparator()
          Returns a comparator used to sort the child nodes of this node.
protected  void filter(java.lang.String prefix)
          Filters the children of this tree node based on the specified prefix.
 javax.swing.tree.TreeNode getChildAfter(javax.swing.tree.TreeNode child)
           
 javax.swing.tree.TreeNode getChildAt(int index)
           
 javax.swing.tree.TreeNode getChildBefore(javax.swing.tree.TreeNode child)
           
 int getChildCount()
           
 int getIndex(javax.swing.tree.TreeNode child)
           
 int getSortPriority()
          Returns the relative priority of this node against others when being sorted (lower is higher priority).
 boolean isSortable()
          Returns whether this particular node's children can be sorted.
 boolean isSorted()
          Returns whether this node is sorted.
protected  void refresh()
           
 void setSortable(boolean sortable)
          Sets whether this particular node's children are sortable.
 void setSorted(boolean sorted)
          Sets whether this tree node (and any child sortable tree nodes) are sorting their children.
 void setSortPriority(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, clone, 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
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SourceTreeNode

public SourceTreeNode(java.lang.Object userObject)

SourceTreeNode

public SourceTreeNode(java.lang.Object userObject,
                      boolean sorted)
Method Detail

add

public void add(javax.swing.tree.MutableTreeNode child)
Overrides:
add in class javax.swing.tree.DefaultMutableTreeNode

children

public java.util.Enumeration<?> children()
Specified by:
children in interface javax.swing.tree.TreeNode
Overrides:
children in class javax.swing.tree.DefaultMutableTreeNode

compareTo

public int compareTo(java.lang.Object obj)

createComparator

public java.util.Comparator<java.lang.Object> createComparator()
Returns a comparator used to sort the child nodes of this node. The default implementation sorts alphabetically. Subclasses may want to override to return a comparator that groups by type of node and sorts by group, etc.

Returns:
A comparator.

filter

protected void filter(java.lang.String prefix)
Filters the children of this tree node based on the specified prefix.

Parameters:
prefix - The prefix. If this is null, all possible children are shown. This should be all lower case.

getChildAfter

public javax.swing.tree.TreeNode getChildAfter(javax.swing.tree.TreeNode child)
Overrides:
getChildAfter in class javax.swing.tree.DefaultMutableTreeNode

getChildAt

public javax.swing.tree.TreeNode getChildAt(int index)
Specified by:
getChildAt in interface javax.swing.tree.TreeNode
Overrides:
getChildAt in class javax.swing.tree.DefaultMutableTreeNode

getChildBefore

public javax.swing.tree.TreeNode getChildBefore(javax.swing.tree.TreeNode child)
Overrides:
getChildBefore in class javax.swing.tree.DefaultMutableTreeNode

getChildCount

public int getChildCount()
Specified by:
getChildCount in interface javax.swing.tree.TreeNode
Overrides:
getChildCount in class javax.swing.tree.DefaultMutableTreeNode

getIndex

public int getIndex(javax.swing.tree.TreeNode child)
Specified by:
getIndex in interface javax.swing.tree.TreeNode
Overrides:
getIndex in class javax.swing.tree.DefaultMutableTreeNode

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

protected void refresh()

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()