Java JTree Expand searchUnexpandedPath(JTree tree, TreePath path, int index, TreeNode node, TreePath[] result, boolean compareOnlyLabels)

Here you can find the source of searchUnexpandedPath(JTree tree, TreePath path, int index, TreeNode node, TreePath[] result, boolean compareOnlyLabels)

Description

search Unexpanded Path

License

BSD License

Declaration

public static boolean searchUnexpandedPath(JTree tree, TreePath path, int index, TreeNode node,
            TreePath[] result, boolean compareOnlyLabels) 

Method Source Code

//package com.java2s;
/*   TouchStone design platform is a software to design protocols for lab        *
 *   experiments. It is published under the terms of a BSD license               *
 *   (see details below)                                                         *
 *   Author: Caroline Appert (appert@lri.fr)                                     *
 *   Copyright (c) 2010 Caroline Appert and INRIA, France.                       *
 *   TouchStone design platform reuses parts of an early version which were      *
 *   programmed by Matthis Gilbert.                                              *
 *********************************************************************************/

import java.util.Enumeration;

import javax.swing.JTree;

import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

public class Main {
    public static boolean searchUnexpandedPath(JTree tree, TreePath path, int index, TreeNode node,
            TreePath[] result, boolean compareOnlyLabels) {
        Object[] pathElements = path.getPath();
        if (index >= pathElements.length) {
            return !tree.isExpanded(result[0]);
        }/*w  ww .jav  a  2 s  . c o m*/
        Object elementToSearch = pathElements[index];
        Enumeration<?> enumeration = node.children();
        while (enumeration.hasMoreElements()) {
            TreeNode next = (TreeNode) enumeration.nextElement();
            if ((compareOnlyLabels && next.toString().compareTo(elementToSearch.toString()) == 0)
                    || (!compareOnlyLabels && next.equals(elementToSearch))) {
                TreePath[] potentialResult = new TreePath[1];
                potentialResult[0] = result[0].pathByAddingChild(next);
                if (searchUnexpandedPath(tree, path, index + 1, next, potentialResult, compareOnlyLabels)) {
                    result[0] = potentialResult[0];
                    return true;
                }
            }
        }
        return false;
    }
}

Related

  1. getLastExpandedNodes(final JTree tree)
  2. getPaths(JTree tree, boolean expanded)
  3. getTreeSelectedExpandedIcon()
  4. isTreePathExpandable(TreeModel treeModel, TreePath treePath)
  5. makeTreeAutoExpandable(JTree tree)
  6. setExpandedIcon(JTree tree, Icon icon)
  7. setExpandedOnEdt(JTree tree, TreePath path, boolean expanded)
  8. setExpandedPaths(JTree tree, TreePath[] expandedPaths)
  9. setFullyExpandedPath(JTree Target, TreeModel TheModel, Object Node, Vector Path)