JIDE 3.5.15

com.jidesoft.tree
Class TreeUtils

java.lang.Object
  extended by com.jidesoft.tree.TreeUtils

public class TreeUtils
extends Object


Constructor Summary
TreeUtils()
           
 
Method Summary
static void expandAll(JTree tree)
          Expands the visible rows in a JTree.
static void expandAll(JTree tree, boolean expand)
          Expands the tree completely.
static void expandAll(JTree tree, TreePath parent, boolean expand)
          Expands the tree completely.
static Object findTreeNode(JTree tree, Object userObject)
          Finds the TreeNode that has the user object as passed in.
static Object findTreeNode(JTree tree, TreePath parent, Object userObject)
          Finds the TreeNode that has the user object as passed in starting from a tree path.
static int getLeafCount(TreeModel treeModel)
          Gets the leaf node count.
static int getLeafCount(TreeModel treeModel, Object node)
          Gets the leaf node count.
static boolean isDescendant(TreePath path1, TreePath path2)
           
static void loadExpansionState(JTree tree, int row, String expansionState)
           
static void loadExpansionStateByTreePath(JTree tree, Enumeration<TreePath> enumeration)
          Restore the expansion state of a JTree.
static void loadSelection(JTree tree, TreePath[] selected)
          Restore the selection in JTree.
static String saveExpansionState(JTree tree, int row)
           
static Enumeration<TreePath> saveExpansionStateByTreePath(JTree tree)
          Save the expansion state of a tree.
static TreePath[] saveSelection(JTree tree)
          Save the selection of the JTree as an array of integer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeUtils

public TreeUtils()
Method Detail

saveSelection

public static TreePath[] saveSelection(JTree tree)
Save the selection of the JTree as an array of integer.

Parameters:
tree - the JTree
Returns:
selection as an array

loadSelection

public static void loadSelection(JTree tree,
                                 TreePath[] selected)
Restore the selection in JTree. It must used the array that created by saveSelection.

Parameters:
tree - the JTree
selected - an int array created by saveSelection(javax.swing.JTree).

saveExpansionStateByTreePath

public static Enumeration<TreePath> saveExpansionStateByTreePath(JTree tree)
Save the expansion state of a tree.

Parameters:
tree - the JTree
Returns:
expanded tree path as Enumeration

loadExpansionStateByTreePath

public static void loadExpansionStateByTreePath(JTree tree,
                                                Enumeration<TreePath> enumeration)
Restore the expansion state of a JTree.

Parameters:
tree - the JTree
enumeration - an Enumeration of expansion state. You can get it using saveExpansionStateByTreePath(javax.swing.JTree).

isDescendant

public static boolean isDescendant(TreePath path1,
                                   TreePath path2)

saveExpansionState

public static String saveExpansionState(JTree tree,
                                        int row)

loadExpansionState

public static void loadExpansionState(JTree tree,
                                      int row,
                                      String expansionState)
Parameters:
tree - the JTree
row - the row index
expansionState - the expansion state

expandAll

public static void expandAll(JTree tree)
Expands the visible rows in a JTree. It will only expand one level from the current expansion level. If you want to expand all nodes recursively in a tree, use expandAll(javax.swing.JTree, boolean) with a true parameter.

Parameters:
tree - the JTree

expandAll

public static void expandAll(JTree tree,
                             boolean expand)
Expands the tree completely.

Parameters:
tree - the tree
expand - expand or collapse

expandAll

public static void expandAll(JTree tree,
                             TreePath parent,
                             boolean expand)
Expands the tree completely.

Parameters:
tree - the tree
parent - the parent tree path. Only tree paths under this parent tree path will be expanded or collapsed.
expand - expand or collapse

findTreeNode

public static Object findTreeNode(JTree tree,
                                  Object userObject)
Finds the TreeNode that has the user object as passed in. Please note, since only DefaultMutableTreeNode has userObject, this method will only find the tree node that is the DefaultMutableTreeNode.

Parameters:
tree - the tree
userObject - the user object to match with the tree node's user object.
Returns:
the tree node.

findTreeNode

public static Object findTreeNode(JTree tree,
                                  TreePath parent,
                                  Object userObject)
Finds the TreeNode that has the user object as passed in starting from a tree path. Please note, since only DefaultMutableTreeNode has userObject, this method will only find the tree node that is the DefaultMutableTreeNode.

Parameters:
tree - the tree
parent - the parent tree path. Only tree paths under this parent tree path will be searched.
userObject - the user object to match with the tree node's user object.
Returns:
the tree node that matches with the user object.

getLeafCount

public static int getLeafCount(TreeModel treeModel)
Gets the leaf node count. It will recursively go into each children node starting from root and count how many leaf nodes in the tree model.

Please use it carefully. If your tree model has unlimited number of tree nodes and a huge number of tree nodes, this method will never or take a long time to return.

Parameters:
treeModel - the TreeModel.
Returns:
the number of leaf nodes.

getLeafCount

public static int getLeafCount(TreeModel treeModel,
                               Object node)
Gets the leaf node count. It will recursively go into each children node starting from the specified node and count how many leaf nodes in the tree model.

Please use it carefully. If your tree model has unlimited number of tree nodes and a huge number of tree nodes, this method will never or take a long time to return.

Parameters:
treeModel - the TreeModel
node - the tree node
Returns:
the number of leaf nodes.

JIDE 3.5.15