Class SourceTreeNode

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.regex.Pattern pattern  
      private boolean sortable  
      private boolean sorted  
      private int sortPriority  
      private java.util.List<javax.swing.tree.TreeNode> visibleChildren  
      • Fields inherited from class javax.swing.tree.DefaultMutableTreeNode

        allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
    • 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
      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.
      java.util.Enumeration<javax.swing.tree.TreeNode> children()
      Overridden to operate over visible children only.
      java.lang.Object clone()
      Returns a clone of this tree node.
      SourceTreeNode cloneWithChildren()
      Returns a clone of this tree node and all of its children.
      int compareTo​(SourceTreeNode stn2)
      Overridden to provide proper sorting of source tree nodes when the parent AbstractSourceTree is sorted.
      protected void filter​(java.util.regex.Pattern pattern)
      Filters the children of this tree node based on the specified prefix.
      javax.swing.tree.TreeNode getChildAfter​(javax.swing.tree.TreeNode child)
      Overridden to operate over visible children only.
      javax.swing.tree.TreeNode getChildAt​(int index)
      Overridden to operate over visible children only.
      javax.swing.tree.TreeNode getChildBefore​(javax.swing.tree.TreeNode child)
      Overridden to operate over visible children only.
      int getChildCount()
      Overridden to operate over visible children only.
      int getIndex​(javax.swing.tree.TreeNode child)
      Overridden to operate over visible children only.
      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.
      void refresh()
      Refreshes this tree node and its children.
      private void refreshVisibleChildren()
      Refreshes what children are visible in the tree.
      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, 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
    • Field Detail

      • sortable

        private boolean sortable
      • sorted

        private boolean sorted
      • pattern

        private java.util.regex.Pattern pattern
      • visibleChildren

        private java.util.List<javax.swing.tree.TreeNode> visibleChildren
      • sortPriority

        private int sortPriority
    • 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:
        add in class javax.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:
        children in interface javax.swing.tree.TreeNode
        Overrides:
        children in class javax.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:
        clone in class javax.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 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 java.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 is null, 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:
        getChildAfter in class javax.swing.tree.DefaultMutableTreeNode
        Parameters:
        child - The child node.
        Returns:
        The visible child after the specified node, or null if none.
      • getChildAt

        public javax.swing.tree.TreeNode getChildAt​(int index)
        Overridden to operate over visible children only.
        Specified by:
        getChildAt in interface javax.swing.tree.TreeNode
        Overrides:
        getChildAt in class javax.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:
        getChildBefore in class javax.swing.tree.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 javax.swing.tree.TreeNode
        Overrides:
        getChildCount in class javax.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:
        getIndex in interface javax.swing.tree.TreeNode
        Overrides:
        getIndex in class javax.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, -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:
        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()