Example usage for javax.swing.tree TreeNode children

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

Introduction

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

Prototype

Enumeration<? extends TreeNode> children();

Source Link

Document

Returns the children of the receiver as an Enumeration.

Usage

From source file:com.mirth.connect.client.ui.components.MirthTree.java

/**
 * Get the index of a node in relation to other nodes with the same name. Returns -1 if there
 * isn't an index./*from  ww  w  .  j  a v  a 2  s  .  c o  m*/
 * 
 * @param node
 * @return
 */
public static int getIndexOfNode(TreeNode node) {
    String nodeName = node.toString().replaceAll(" \\(.*\\)", ""); // Get the node name without the vocab
    TreeNode parent = node.getParent();

    // The parent will be null for the root node
    if (parent != null) {
        Enumeration children = parent.children();
        int indexCounter = 0;
        int foundIndex = -1;

        // Look through all of the children of the parent to see if there
        // are multiple children with the same name.
        while (children.hasMoreElements()) {
            TreeNode child = (TreeNode) children.nextElement();

            // Ignore the draggable nodes that have no children
            if (child.getChildCount() > 0) {
                if (nodeName.equals(child.toString().replaceAll(" \\(.*\\)", ""))) {
                    if (child != node) {
                        indexCounter++;
                    } else {
                        foundIndex = indexCounter;
                        indexCounter++;
                    }
                }
            }
        }

        // If there were multiple children, add the index to the nodeQ.
        if (indexCounter > 1) {
            return foundIndex;
        }
    }

    return -1;
}

From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java

private static void expandAll(JTree tree, TreePath treePath, boolean expand, int maxLevel, int currentLevel) {
    if (maxLevel != -1 && currentLevel >= maxLevel - 1) {
        return;// w w w. ja va 2 s. co m
    }

    TreeNode node = (TreeNode) treePath.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements();) {
            TreeNode n = e.nextElement();

            TreePath path = treePath.pathByAddingChild(n);
            expandAll(tree, path, expand, maxLevel, currentLevel + 1);
        }
    }

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

From source file:Main.java

private void expandAll(JTree tree, TreePath parent) {
    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);//from  ww w  .  j a  v a  2 s. c o  m
        }
    }
    tree.expandPath(parent);
    // tree.collapsePath(parent);
}

From source file:Main.java

public void getPaths(JTree tree, TreePath parent, boolean expanded, List<TreePath> list) {
    if (expanded && !tree.isVisible(parent)) {
        return;/*from www .  ja v  a 2  s . co  m*/
    }
    list.add(parent);
    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);
            getPaths(tree, path, expanded, list);
        }
    }
}

From source file:gdt.jgui.entity.JEntityStructurePanel.java

private void expandAll(JTree tree, TreePath path, boolean expand) {
    TreeNode node = (TreeNode) path.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        Enumeration enumeration = node.children();
        while (enumeration.hasMoreElements()) {
            TreeNode n = (TreeNode) enumeration.nextElement();
            TreePath p = path.pathByAddingChild(n);
            expandAll(tree, p, expand);/*from  www  .  j  a  va 2 s  . co  m*/
        }
    }
    if (expand) {
        tree.expandPath(path);
    } else {
        tree.collapsePath(path);
    }
}

From source file:dotaSoundEditor.Controls.EditorPanel.java

protected ArrayList<String> getWavePathsAsList(TreeNode selectedFile) {
    ArrayList<String> wavePathsList = new ArrayList<>();
    Enumeration e = selectedFile.children();
    while (e.hasMoreElements()) {
        Object currentElement = e.nextElement();

        //If a soundfile has multiple possible wavefiles
        if (currentElement.toString().contains("\"rndwave\"")) {
            Enumeration innerE = ((TreeNode) currentElement).children();
            while (innerE.hasMoreElements()) {
                Object currentInnerElement = innerE.nextElement();
                if ((currentInnerElement.toString().contains("\"wave\"")
                        || currentInnerElement.toString().contains(".wav")
                        || currentInnerElement.toString().contains(".mp3"))
                        && !currentInnerElement.toString().trim().startsWith("//")) {
                    //Maybe do some string massaging here before we just hand it back
                    wavePathsList.add(((TreeNode) currentInnerElement).toString());
                }/*w ww .ja v a  2  s .co m*/
            }
        }
        //If it only has one
        else if (currentElement.toString().contains("\"wave\"")) {
            if (!currentElement.toString().trim().startsWith("//")) {
                wavePathsList.add(((TreeNode) currentElement).toString());
            }
        }
    }
    return wavePathsList;
}

From source file:gdt.jgui.entity.JEntityDigestDisplay.java

private void expandAll(JTree tree, TreePath path, boolean expand) {
    TreeNode node = (TreeNode) path.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        Enumeration enumeration = node.children();
        while (enumeration.hasMoreElements()) {
            DefaultMutableTreeNode n = (DefaultMutableTreeNode) enumeration.nextElement();
            TreePath p = path.pathByAddingChild(n);
            expandAll(tree, p, expand);/*from   ww  w. j a va  2s.c o m*/
        }
    }
    if (expand) {
        tree.expandPath(path);
    } else {
        tree.collapsePath(path);
    }
}

From source file:de.erdesignerng.visual.common.OutlineComponent.java

private void expandOrCollapseAllChildrenOfNode(TreePath aParentPath, boolean aExpand) {
    TreeNode node = (TreeNode) aParentPath.getLastPathComponent();
    if (node.getChildCount() > 0) {
        for (Enumeration<TreeNode> en = node.children(); en.hasMoreElements();) {
            TreeNode n = en.nextElement();
            TreePath path = aParentPath.pathByAddingChild(n);
            expandOrCollapseAllChildrenOfNode(path, aExpand);
        }/*from w w w. j av a2  s .c om*/
    }
    if (aExpand) {
        tree.expandPath(aParentPath);
    } else {
        tree.collapsePath(aParentPath);
    }
}

From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java

/**
 * Expands or collapses the specified tree according to the
 * <code>expand</code>-parameter.
 *//* w  w  w .j  a v  a  2  s.  co m*/
private void expandTree(JTree currentTree, TreePath parent, boolean expand) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements();) {
            TreePath path = parent.pathByAddingChild(e.nextElement());
            expandTree(currentTree, path, expand);
        }
    }
    if (expand) {
        currentTree.expandPath(parent);
    } else {
        currentTree.collapsePath(parent);
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchSelectionFrame.java

private TreePath find2(JTree tree, TreePath parent, Village pNode, int depth) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    DefaultMutableTreeNode o = (DefaultMutableTreeNode) node;

    // If equal, go down the branch
    if (o.getUserObject().equals(pNode)) {
        // If at end, return match
        return parent;
    } else {/*  ww  w. ja  va2  s. c  om*/
        // Traverse children
        if (node.getChildCount() >= 0) {
            for (Enumeration e = node.children(); e.hasMoreElements();) {
                TreeNode n = (TreeNode) e.nextElement();
                TreePath path = parent.pathByAddingChild(n);
                TreePath result = find2(tree, path, pNode, depth + 1);
                // Found a match
                if (result != null) {
                    return result;
                }
            }
        }
    }
    // No match at this branch
    return null;
}