Example usage for javax.swing.tree TreeNode getChildCount

List of usage examples for javax.swing.tree TreeNode getChildCount

Introduction

In this page you can find the example usage for javax.swing.tree TreeNode getChildCount.

Prototype

int getChildCount();

Source Link

Document

Returns the number of children TreeNodes the receiver contains.

Usage

From source file:Main.java

public static void visitAllNodes(TreeNode node) {
    System.out.println(node);/*from   w w  w . j a  v  a2  s .  c  o m*/
    if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements();) {
            TreeNode n = (TreeNode) e.nextElement();
            visitAllNodes(n);
        }
    }
}

From source file:Main.java

public static void visitAllExpandedNodes(JTree tree, TreePath parent) {
    if (!tree.isVisible(parent)) {
        return;/*ww w.jav  a 2  s .  c  om*/
    }
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    System.out.println(node);

    if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements();) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            visitAllExpandedNodes(tree, path);
        }
    }
}

From source file:TreeUtil.java

public static void expandAll(JTree tree, TreePath parent, boolean expand) {
    // Traverse children
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements();) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            expandAll(tree, path, expand);
        }//from w  ww. j a  v  a 2 s  . c o m
    }
    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}

From source file:Main.java

static private void expandAll(JTree tree, TreePath parent, boolean expand) {
    // Traverse children
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements();) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            expandAll(tree, path, expand);
        }/*from  ww  w. ja va  2 s.com*/
    }
    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}

From source file:Main.java

private static void expandAll(JTree tree, TreePath parent, boolean expand) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration<?> e = node.children(); e.hasMoreElements();) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            expandAll(tree, path, expand);
        }/*  w w w  . j av  a 2s  .  c  om*/
    }

    if (expand)
        tree.expandPath(parent);
    else
        tree.collapsePath(parent);
}

From source file:TreeUtils.java

public static void expandAll(JTree tree, TreePath parent, boolean expand) {
    // Traverse children
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements();) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            expandAll(tree, path, expand);
        }//w  ww  .  j a  va2s  . c  o m
    }

    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}

From source file:Main.java

private static TreePath find(JTree tree, TreePath parent, Object[] nodes, int depth) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    Object o = node;/*  www  .  j  a va 2s  .  c  o m*/

    if (o.equals(nodes[depth])) {
        if (depth == nodes.length - 1) {
            return parent;
        }
        if (node.getChildCount() >= 0) {
            for (Enumeration e = node.children(); e.hasMoreElements();) {
                TreeNode n = (TreeNode) e.nextElement();
                TreePath path = parent.pathByAddingChild(n);
                TreePath result = find(tree, path, nodes, depth + 1);
                if (result != null) {
                    return result;
                }
            }
        }
    }
    return null;
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

private static void getAllUserObject(TreeNode node, Set userObjectSet) {
    for (int i = 0; i < node.getChildCount(); i++) {
        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node.getChildAt(i);
        userObjectSet.add(childNode.getUserObject());
        getAllUserObject(childNode, userObjectSet);
    }/*from www .j  ava2 s . c  om*/
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

private static void getChildCntAverage(TreeNode node, List<Integer> childNodeCntList) {
    if (0 < node.getChildCount()) {
        childNodeCntList.add(node.getChildCount());
    }//  w w  w  . j a va2  s  .co m
    for (int i = 0; i < node.getChildCount(); i++) {
        ConceptTreeNode childNode = (ConceptTreeNode) node.getChildAt(i);
        getChildCntAverage(childNode, childNodeCntList);
    }
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

private static void getAllConcept(TreeNode node, Set<Concept> conceptSet) {
    for (int i = 0; i < node.getChildCount(); i++) {
        ConceptTreeNode childNode = (ConceptTreeNode) node.getChildAt(i);
        conceptSet.add(childNode.getConcept());
        getAllConcept(childNode, conceptSet);
    }//from ww w . java2s .c  om
}