Class SourceTreeNode

All Implemented Interfaces:
Serializable, Cloneable, Comparable<SourceTreeNode>, MutableTreeNode, TreeNode
Direct Known Subclasses:
JavaScriptTreeNode, JavaTreeNode, XmlTreeNode

public class SourceTreeNode extends DefaultMutableTreeNode implements Comparable<SourceTreeNode>
Base class for tree nodes in an AbstractSourceTree. They can be sorted and filtered based on user input.
Version:
1.0
See Also:
  • Field Details

    • sortable

      private boolean sortable
    • sorted

      private boolean sorted
    • pattern

      private Pattern pattern
    • visibleChildren

      private List<TreeNode> visibleChildren
    • sortPriority

      private int sortPriority
  • Constructor Details

    • SourceTreeNode

      public SourceTreeNode(Object userObject)
      Creates an unsorted tree node.
      Parameters:
      userObject - The user data for this tree node.
    • SourceTreeNode

      public SourceTreeNode(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 Details

    • add

      public void add(MutableTreeNode child)
      Overridden to ensure the new child is only made visible if it is matched by the current filter.
      Overrides:
      add in class DefaultMutableTreeNode
      Parameters:
      child - The child node to add.
    • children

      public Enumeration<TreeNode> children()
      Overridden to operate over visible children only.
      Specified by:
      children in interface TreeNode
      Overrides:
      children in class DefaultMutableTreeNode
      Returns:
      The visible children.
    • clone

      public Object clone()
      Returns a clone of this tree node. The clone will not contain any child nodes.
      Overrides:
      clone in class DefaultMutableTreeNode
      Returns:
      The clone of this node.
      See Also:
    • cloneWithChildren

      public SourceTreeNode cloneWithChildren()
      Returns a clone of this tree node and all of its children.
      Returns:
      The clone of this node.
      See Also:
    • compareTo

      public int compareTo(SourceTreeNode stn2)
      Overridden to provide proper sorting of source tree nodes when the parent AbstractSourceTree is 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:
      compareTo in interface Comparable<SourceTreeNode>
      Parameters:
      stn2 - A tree node to compare to.
      Returns:
      How these tree nodes compare relative to each other.
    • filter

      protected void filter(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 is null, all possible children are shown.
    • getChildAfter

      public TreeNode getChildAfter(TreeNode child)
      Overridden to operate over visible children only.
      Overrides:
      getChildAfter in class DefaultMutableTreeNode
      Parameters:
      child - The child node.
      Returns:
      The visible child after the specified node, or null if none.
    • getChildAt

      public TreeNode getChildAt(int index)
      Overridden to operate over visible children only.
      Specified by:
      getChildAt in interface TreeNode
      Overrides:
      getChildAt in class DefaultMutableTreeNode
      Parameters:
      index - The index of the visible child to retrieve.
      Returns:
      The visible child after the specified index.
    • getChildBefore

      public TreeNode getChildBefore(TreeNode child)
      Overridden to operate over visible children only.
      Overrides:
      getChildBefore in class DefaultMutableTreeNode
      Parameters:
      child - The child node.
      Returns:
      The visible child before the specified node, or null if none.
    • getChildCount

      public int getChildCount()
      Overridden to operate over visible children only.
      Specified by:
      getChildCount in interface TreeNode
      Overrides:
      getChildCount in class DefaultMutableTreeNode
      Returns:
      The number of visible child nodes.
    • getIndex

      public int getIndex(TreeNode child)
      Overridden to operate over visible children only.
      Specified by:
      getIndex in interface TreeNode
      Overrides:
      getIndex in class 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, -1 is 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: