Example usage for javax.swing.tree TreePath pathByAddingChild

List of usage examples for javax.swing.tree TreePath pathByAddingChild

Introduction

In this page you can find the example usage for javax.swing.tree TreePath pathByAddingChild.

Prototype

public TreePath pathByAddingChild(Object child) 

Source Link

Document

Returns a new path containing all the elements of this path plus child.

Usage

From source file:com.pironet.tda.TDA.java

/**
 * expand or collapse all nodes of the specified tree
 *
 * @param catTree the tree to expand all/collapse all
 * @param parent  the parent to start with
 * @param expand  expand=true, collapse=false
 *//*from   w w  w  .  ja  va2 s.c o m*/
private void expandAll(JTree catTree, 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(catTree, path, expand);
        }
    }

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

From source file:com.pironet.tda.TDA.java

/**
 * navigate to monitor/*from  w  w  w.  ja  va2  s. c  om*/
 *
 * @param monitorLink the monitor link to navigate to
 */
private void navigateToMonitor(String monitorLink) {
    String monitor = monitorLink.substring(monitorLink.lastIndexOf('/') + 1);

    // find monitor node for this thread info
    DefaultMutableTreeNode dumpNode;
    if (monitorLink.indexOf("Dump No.") > 0) {
        dumpNode = getDumpRootNode(
                monitorLink.substring(monitorLink.indexOf('/') + 1, monitorLink.lastIndexOf('/')),
                (DefaultMutableTreeNode) tree.getLastSelectedPathComponent());
    } else {
        dumpNode = getDumpRootNode((DefaultMutableTreeNode) tree.getLastSelectedPathComponent());
    }
    final Enumeration children = dumpNode.children();
    DefaultMutableTreeNode monitorNode = null;
    DefaultMutableTreeNode monitorWithoutLocksNode = null;
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        if (child.getUserObject() instanceof TreeCategory) {
            if (((TreeCategory) child.getUserObject()).getName().startsWith("Monitors (")) {
                monitorNode = child;
            } else if (((TreeCategory) child.getUserObject()).getName().startsWith("Monitors without")) {
                monitorWithoutLocksNode = child;
            }
        }
    }

    // highlight chosen monitor
    JTree searchTree = (JTree) ((TreeCategory) monitorNode.getUserObject()).getCatComponent(this);
    TreePath searchPath = searchTree.getNextMatch(monitor, 0, Position.Bias.Forward);
    if ((searchPath == null) && (monitorWithoutLocksNode != null)) {
        searchTree = (JTree) ((TreeCategory) monitorWithoutLocksNode.getUserObject()).getCatComponent(this);
        searchPath = searchTree.getNextMatch(monitor, 0, Position.Bias.Forward);
        monitorNode = monitorWithoutLocksNode;
    }

    if (searchPath != null) {
        TreePath monitorPath = new TreePath(monitorNode.getPath());
        tree.setSelectionPath(monitorPath);
        tree.scrollPathToVisible(monitorPath);

        displayCategory(monitorNode.getUserObject());

        TreePath threadInMonitor = searchPath
                .pathByAddingChild(((DefaultMutableTreeNode) searchPath.getLastPathComponent()).getLastChild());
        searchTree.setSelectionPath(threadInMonitor);
        searchTree.scrollPathToVisible(searchPath);
        searchTree.setSelectionPath(searchPath);
    }
}

From source file:com.android.tools.idea.uibuilder.structure.NlComponentTreeTest.java

private void describe(StringBuilder sb, TreePath path, int depth) {
    for (int i = 0; i < depth; i++) {
        sb.append("    ");
    }// w w  w . j av a2  s .c o m

    NlComponent component = (NlComponent) path.getLastPathComponent();
    sb.append("<").append(component.getTagName()).append(">");
    if (myTree.isExpanded(path)) {
        sb.append("  [expanded]");
    }
    if (myTree.isPathSelected(path)) {
        sb.append("  [selected]");
    }
    sb.append("\n");
    for (Object subNodeAsObject : component.getChildren()) {
        TreePath subPath = path.pathByAddingChild(subNodeAsObject);
        describe(sb, subPath, depth + 1);
    }
}

From source file:org.geopublishing.atlasViewer.GpCoreUtil.java

private final static void expandAll(final JTree tree, final TreePath parent, final boolean expand) {
    // Traverse children
    final TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (final Enumeration<TreeNode> e = node.children(); e.hasMoreElements();) {
            final TreeNode n = e.nextElement();
            final TreePath path = parent.pathByAddingChild(n);
            expandAll(tree, path, expand);
        }//from   w  ww  .  ja v  a2  s.  co  m
    }

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

From source file:org.languagetool.gui.ConfigurationDialog.java

@NotNull
private JPanel getTreeButtonPanel(int num) {
    GridBagConstraints cons;//from  w ww.  ja  va2 s .c o m
    JPanel treeButtonPanel = new JPanel();
    cons = new GridBagConstraints();
    cons.gridx = 0;
    cons.gridy = 0;
    JButton expandAllButton = new JButton(messages.getString("guiExpandAll"));
    treeButtonPanel.add(expandAllButton, cons);
    expandAllButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            TreeNode root = (TreeNode) configTree[num].getModel().getRoot();
            TreePath parent = new TreePath(root);
            for (Enumeration cat = root.children(); cat.hasMoreElements();) {
                TreeNode n = (TreeNode) cat.nextElement();
                TreePath child = parent.pathByAddingChild(n);
                configTree[num].expandPath(child);
            }
        }
    });

    cons.gridx = 1;
    cons.gridy = 0;
    JButton collapseAllButton = new JButton(messages.getString("guiCollapseAll"));
    treeButtonPanel.add(collapseAllButton, cons);
    collapseAllButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            TreeNode root = (TreeNode) configTree[num].getModel().getRoot();
            TreePath parent = new TreePath(root);
            for (Enumeration categ = root.children(); categ.hasMoreElements();) {
                TreeNode n = (TreeNode) categ.nextElement();
                TreePath child = parent.pathByAddingChild(n);
                configTree[num].collapsePath(child);
            }
        }
    });
    return treeButtonPanel;
}

From source file:org.nuclos.client.explorer.ExplorerNode.java

static void createExpandendPathsForTree(TreePath path, JTree tree, List<String> lstExpandedPathsResult) {
    final ExplorerNode<?> explorernode = (ExplorerNode<?>) path.getLastPathComponent();
    boolean isExpanded = tree.isExpanded(path);
    if (isExpanded) {
        lstExpandedPathsResult.add(explorernode.getIdentifierPath());

        for (int i = 0; i < explorernode.getChildCount(); i++) {
            final ExplorerNode<?> explorernodeChild = (ExplorerNode<?>) explorernode.getChildAt(i);
            createExpandendPathsForTree(path.pathByAddingChild(explorernodeChild), tree,
                    lstExpandedPathsResult);
        }//from w  w w.j ava 2s. co  m
    }
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private ArrayList<DefaultMutableTreeNode> getLocalLeafs(DefaultMutableTreeNode node, TreePath path) {
    ArrayList<DefaultMutableTreeNode> list = new ArrayList<DefaultMutableTreeNode>();
    TreePath temp;//w  w  w  . j  a v  a  2s  . c om

    if (node.isLeaf()) {
        list.add(node);
    } else {
        Enumeration<DefaultMutableTreeNode> en = node.children();

        while (en.hasMoreElements()) {
            DefaultMutableTreeNode elem = en.nextElement();

            temp = path.pathByAddingChild(elem);
            jTreeResults.expandPath(temp);

            list.addAll(getLocalLeafs(elem, temp));
        }
    }

    return list;
}

From source file:view.CertificatePropertiesDialog.java

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