Search in sources :

Example 76 with TreeNode

use of javax.swing.tree.TreeNode in project selenium_java by sergueik.

the class JTreeZipFile method addTreeNode.

private DefaultMutableTreeNode addTreeNode(final DefaultMutableTreeNode parent, final String childText, final boolean isFolder, final ZipEntry ze) {
    if (parent == null) {
        throw new IllegalArgumentException("parent node cannot be null.");
    }
    if (childText == null || childText.isEmpty()) {
        throw new IllegalArgumentException("child node text cannot be null or empty.");
    }
    DefaultMutableTreeNode child = null;
    if (parent.isLeaf()) {
        child = new DefaultMutableTreeNode(new JTreeNodeZipFile(childText, ze));
        parent.add(child);
    } else {
        final int childCount = parent.getChildCount();
        TreeNode childTreeNode = null;
        for (int i = 0; i < childCount; i++) {
            childTreeNode = parent.getChildAt(i);
            if (childText.equals(childTreeNode.toString()) && childTreeNode instanceof DefaultMutableTreeNode) {
                child = (DefaultMutableTreeNode) childTreeNode;
            }
        }
        if (child == null) {
            // Change the tree node icon here accroding to 'isFolder'.
            child = new DefaultMutableTreeNode(new JTreeNodeZipFile(childText, ze));
            parent.add(child);
        }
    }
    return child;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 77 with TreeNode

use of javax.swing.tree.TreeNode in project keystore-explorer by kaikramer.

the class DProperties method expandTwoLevels.

private void expandTwoLevels(TreePath treePath) {
    if (treePath.getPathCount() > 2) {
        return;
    }
    TreeNode node = (TreeNode) treePath.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration<?> enumChildren = node.children(); enumChildren.hasMoreElements(); ) {
            TreeNode subNode = (TreeNode) enumChildren.nextElement();
            TreePath path = treePath.pathByAddingChild(subNode);
            expandTwoLevels(path);
        }
    }
    jtrProperties.expandPath(treePath);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode)

Example 78 with TreeNode

use of javax.swing.tree.TreeNode in project keystore-explorer by kaikramer.

the class DViewCertificate method expandTree.

private void expandTree(JTree tree, TreePath parent) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration<?> enumNodes = node.children(); enumNodes.hasMoreElements(); ) {
            TreeNode subNode = (TreeNode) enumNodes.nextElement();
            TreePath path = parent.pathByAddingChild(subNode);
            expandTree(tree, path);
        }
    }
    tree.expandPath(parent);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode)

Example 79 with TreeNode

use of javax.swing.tree.TreeNode in project Spark by igniterealtime.

the class Tree method find2.

private TreePath find2(Tree tree, TreePath parent, Object[] nodes, int depth, boolean byName) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    Object o = node;
    // If by name, convert node to a string
    if (byName) {
        o = o.toString();
    }
    // If equal, go down the branch
    if (o.equals(nodes[depth])) {
        // If at end, return match
        if (depth == nodes.length - 1) {
            return parent;
        }
        // Traverse children
        if (node.getChildCount() >= 0) {
            for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements(); ) {
                TreeNode n = e.nextElement();
                TreePath path = parent.pathByAddingChild(n);
                TreePath result = find2(tree, path, nodes, depth + 1, byName);
                // Found a match
                if (result != null) {
                    return result;
                }
            }
        }
    }
    // No match at this branch
    return null;
}
Also used : TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 80 with TreeNode

use of javax.swing.tree.TreeNode in project triplea by triplea-game.

the class HistoryPanel method previous.

private void previous() {
    if (tree.getSelectionCount() == 0) {
        tree.setSelectionInterval(0, 0);
        return;
    }
    final TreePath path = tree.getSelectionPath();
    final TreeNode selected = (TreeNode) path.getLastPathComponent();
    @SuppressWarnings("unchecked") final Enumeration<TreeNode> nodeEnum = ((DefaultMutableTreeNode) tree.getModel().getRoot()).depthFirstEnumeration();
    TreeNode previous = null;
    while (nodeEnum.hasMoreElements()) {
        final TreeNode current = nodeEnum.nextElement();
        if (current == selected) {
            break;
        } else if (current.getParent() instanceof Step) {
            previous = current;
        }
    }
    if (previous != null) {
        navigateTo(previous);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Step(games.strategy.engine.history.Step)

Aggregations

TreeNode (javax.swing.tree.TreeNode)313 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)146 TreePath (javax.swing.tree.TreePath)125 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)31 Enumeration (java.util.Enumeration)30 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)28 MPart (gov.sandia.n2a.eqset.MPart)27 ArrayList (java.util.ArrayList)27 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)25 JTree (javax.swing.JTree)23 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)23 Nullable (org.jetbrains.annotations.Nullable)23 MutableTreeNode (javax.swing.tree.MutableTreeNode)19 CannotRedoException (javax.swing.undo.CannotRedoException)18 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)16 CannotUndoException (javax.swing.undo.CannotUndoException)14 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)12 MouseEvent (java.awt.event.MouseEvent)11 NotNull (org.jetbrains.annotations.NotNull)11 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)10