Class BaseTree

    • Constructor Detail

      • BaseTree

        public BaseTree()
        Initializes the tree.
      • BaseTree

        public BaseTree​(TreeModel model)
        Initializes the tree with the given model.
        Parameters:
        model - the tree model to use
      • BaseTree

        public BaseTree​(TreeNode root)
        Initializes the tree with the given root node.
        Parameters:
        root - the root node to use
    • Method Detail

      • initialize

        protected void initialize()
        Further initialization of the tree.
      • expand

        public void expand​(DefaultMutableTreeNode node)
        Expands the specified node.
        Parameters:
        node - the node to expand
      • expandRoot

        public void expandRoot()
        Expands only the root node.
      • expandAll

        public void expandAll()
        Expands all nodes in the tree.
      • expandAll

        public void expandAll​(DefaultMutableTreeNode node)
        Expands the sub-tree below the specified node.
        Parameters:
        node - the node to expand
      • expandAll

        public void expandAll​(TreePath path)
        Expands the sub-tree below the specified node.
        Parameters:
        path - the path to the sub-tree
      • expand

        public void expand​(int depth)
        Expands all nodes in the tree up to the specified depth.
        Parameters:
        depth - the maximum expansion depth (root = 0)
      • collapse

        public void collapse​(DefaultMutableTreeNode node)
        Collapses the specified node.
        Parameters:
        node - the node to collapse
      • collapseRoot

        public void collapseRoot()
        Collapses only the root node.
      • collapseAll

        public void collapseAll()
        Collapses all nodes in the tree.
      • collapseAll

        public void collapseAll​(DefaultMutableTreeNode node)
        Collapses the sub-tree below the specified node.
        Parameters:
        node - the node to collapse
      • collapseAll

        public void collapseAll​(TreePath path)
        Collapses the sub-tree below the specified node.
        Parameters:
        path - the path to the sub-tree
      • toggleAll

        protected void toggleAll​(TreePath parent,
                                 boolean expand)
        Performs the expand/collapse recursively.
        Parameters:
        parent - the parent path
        expand - whether to expand or collapse
      • toggleAll

        protected void toggleAll​(TreePath parent,
                                 boolean expand,
                                 int currDepth,
                                 int maxDepth)
        Performs the expand/collapse recursively.
        Parameters:
        parent - the parent path
        expand - whether to expand or collapse
        currDepth - the current depth
        maxDepth - the maximum depth, -1 for infinity
      • getExpandedTreePaths

        public List<TreePath> getExpandedTreePaths()
        Returns all currently expanded nodes.
        Returns:
        the expanded nodes
      • getExpandedTreePaths

        public List<TreePath> getExpandedTreePaths​(DefaultMutableTreeNode node)
        Returns all currently expanded nodes, starting from the specified node.
        Parameters:
        node - the node to start from, use null for root
        Returns:
        the expanded nodes
      • setExpandedTreePaths

        public void setExpandedTreePaths​(List<TreePath> nodes)
        Expands the specified nodes, all others get collapsed.
        Parameters:
        nodes - the nodes to have expanded
      • setExpandedTreePaths

        public void setExpandedTreePaths​(DefaultMutableTreeNode node,
                                         List<TreePath> nodes)
        Expands the specified nodes, all others get collapsed.
        Parameters:
        node - the starting node, use null for root
        nodes - the nodes to have expanded
      • isRootSelected

        public boolean isRootSelected()
        Returns whether the root node is selected.
        Returns:
        true if selected
      • redraw

        public void redraw()
        Redraws the complete tree. Model must be derived from DefaultTreeModel.
      • redraw

        public void redraw​(DefaultMutableTreeNode node)
        Redraws the node and its subtree. Model must be derived from DefaultTreeModel.
        Parameters:
        node - the node (and its subtree) to redraw
      • getParentFrame

        public Frame getParentFrame()
        Tries to determine the frame this panel is part of.
        Returns:
        the parent frame if one exists or null if not
      • getParentDialog

        public Dialog getParentDialog()
        Tries to determine the dialog this panel is part of.
        Returns:
        the parent dialog if one exists or null if not
      • getParentInternalFrame

        public JInternalFrame getParentInternalFrame()
        Tries to determine the internal frame this panel is part of.
        Returns:
        the parent internal frame if one exists or null if not
      • setExpandedState

        public void setExpandedState​(boolean[] value)
        Sets the expanded state of the rows currently being displayed.
        Parameters:
        value - the expanded state of the rows
      • getExpandedState

        public boolean[] getExpandedState()
        Returns the expanded (or not) state of all the rows currently being displayed.
        Returns:
        the expanded state for the rows
      • setExpandedStateList

        public void setExpandedStateList​(List<Boolean> value)
        Sets the expanded state of the rows currently being displayed.
        Parameters:
        value - the expanded state of the rows
      • getExpandedStateList

        public List<Boolean> getExpandedStateList()
        Returns the expanded (or not) state of all the rows currently being displayed.
        Returns:
        the expanded state for the rows
      • getCommonAncestor

        public BaseTreeNode getCommonAncestor​(BaseTreeNode node1,
                                              BaseTreeNode node2)
        Returns the closest common ancestor for the two nodes.
        Parameters:
        node1 - the first node
        node2 - the second node
        Returns:
        the ancestor or null if no common ancestor, no even the root node
      • getFirstVisibleRow

        public int getFirstVisibleRow()
        Returns the first visible row.
        Returns:
        the visible row, -1 if none found
      • getLastVisibleRow

        public int getLastVisibleRow()
        Returns the last visible row.
        Returns:
        the visible row, -1 if none found
      • toString

        protected void toString​(StringBuilder builder,
                                int level,
                                TreeNode node,
                                List<Boolean> more)
        Adds the node (and its potentional children) to the StringBuilder.
        Parameters:
        builder - for adding the tree structure to
        level - the current level (for indentation)
        node - the node to process
        more - for keeping track whether more siblings come after the node
      • toString

        public String toString()
        Generates a string representation of the tree.
        Overrides:
        toString in class Component
        Returns:
        the string representation
      • toPlainText

        public String toPlainText()
        Generates a string representation of the tree in plain text.
        Returns:
        the string representation
      • toPlainText

        protected void toPlainText​(StringBuilder builder,
                                   int level,
                                   BaseTreeNode node,
                                   List<Boolean> more)
        Adds the node (and its potentional children) to the StringBuilder.
        Parameters:
        builder - for adding the tree structure to
        level - the current level (for indentation)
        node - the node to process
        more - for keeping track whether more siblings come after the node