Example usage for javax.swing.tree DefaultMutableTreeNode getNextNode

List of usage examples for javax.swing.tree DefaultMutableTreeNode getNextNode

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode getNextNode.

Prototype

public DefaultMutableTreeNode getNextNode() 

Source Link

Document

Returns the node that follows this node in a preorder traversal of this node's tree.

Usage

From source file:Main.java

public static void expand(JTree tree, int level) {
    DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) tree.getModel().getRoot();
    while (currentNode != null) {
        if (currentNode.getLevel() <= level) {
            tree.expandPath(new TreePath(currentNode.getPath()));
        }/* w  w w  .  j  a v a2s .com*/
        currentNode = currentNode.getNextNode();
    }
}

From source file:org.apache.cayenne.modeler.ProjectTreeView.java

/**
 * Removes current node from the tree. Selects a new node adjacent to the currently
 * selected node instead./* w  w w  .j  a  v a2 s .c o  m*/
 */
protected void removeNode(DefaultMutableTreeNode toBeRemoved) {

    // lookup for the new selected node
    Object selectedNode = null;

    TreePath selectionPath = getSelectionPath();
    if (selectionPath != null) {
        selectedNode = selectionPath.getLastPathComponent();
    }

    if (toBeRemoved == selectedNode) {

        // first search siblings
        DefaultMutableTreeNode newSelection = toBeRemoved.getNextSibling();
        if (newSelection == null) {
            newSelection = toBeRemoved.getPreviousSibling();

            // try parent
            if (newSelection == null) {
                newSelection = (DefaultMutableTreeNode) toBeRemoved.getParent();

                // search the whole tree
                if (newSelection == null) {

                    newSelection = toBeRemoved.getNextNode();
                    if (newSelection == null) {

                        newSelection = toBeRemoved.getPreviousNode();
                    }
                }
            }
        }

        showNode(newSelection);
    }

    // remove this node
    getProjectModel().removeNodeFromParent(toBeRemoved);
}

From source file:org.openconcerto.erp.model.RubriquePayeTree.java

public RubriquePayeTree() {
    super();//ww  w .  j  a v a 2 s .  c o m
    this.setModel(model);
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    renderer.setLeafIcon(null);
    this.setCellRenderer(renderer);
    DefaultMutableTreeNode currentNode = ((DefaultMutableTreeNode) this.getModel().getRoot()).getNextNode();
    do {
        if (currentNode.getLevel() == 1)
            this.expandPath(new TreePath(currentNode.getPath()));
        currentNode = currentNode.getNextNode();
    } while (currentNode != null);
}

From source file:streamme.visuals.Main.java

public void askTree() {
    if (client == null) {
        this.setMessage("Connect first...");
        return;/*ww w.  j  a v a 2  s  . c  o  m*/
    }
    this.setMessage("Asking path...");
    askedFiles = true;

    new Thread() {
        @Override
        public void run() {
            JSONArray json = client.askJSON();
            tree_model = (DefaultTreeModel) tree_files.getModel();
            //DefaultMutableTreeNode allNode = (DefaultMutableTreeNode) new DefaultMutableTreeNode("Folders");
            //tree_model.setRoot(allNode);
            DefaultMutableTreeNode allNode = (DefaultMutableTreeNode) tree_model.getRoot();
            allNode.removeAllChildren();
            tree_model.reload();

            for (Object obj : json) {
                JSONObject jsonObj = (JSONObject) obj;
                fillTree(jsonObj, allNode);
            }

            DefaultMutableTreeNode currentNode = allNode;
            while (currentNode != null) {
                if (currentNode.getLevel() == 0)
                    tree_files.expandPath(new javax.swing.tree.TreePath(currentNode.getPath()));
                currentNode = currentNode.getNextNode();
            }
            setMessage("Path loaded");
        }
    }.start();
}