Search in sources :

Example 46 with TreeNode

use of javax.swing.tree.TreeNode in project jabref by JabRef.

the class FindUnlinkedFilesDialog method expandTree.

/**
     * Expands or collapses the specified tree according to the
     * <code>expand</code>-parameter.
     */
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);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode)

Example 47 with TreeNode

use of javax.swing.tree.TreeNode in project JMRI by JMRI.

the class MultiPaneWindow method makeNavTreePane.

protected JScrollPane makeNavTreePane(String treeFile) {
    final JTree tree;
    TreeNode topNode;
    rightTopWI = new PanedInterface(this);
    topNode = makeNavTreeTopNode(treeFile, rightTopWI);
    tree = new JTree(topNode);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    // allow multiple roots
    tree.setRootVisible(false);
    // install listener
    tree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

        @Override
        public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (node == null) {
                //Nothing is selected.	
                return;
            }
            if (node.getUserObject() == null) {
                // Not an interesting node
                return;
            }
            if (node.getUserObject() instanceof AbstractAction) {
                AbstractAction action = (AbstractAction) node.getUserObject();
                action.actionPerformed(null);
            }
        }
    });
    // install in scroll area
    JScrollPane treeView = new JScrollPane(tree);
    treeView.setMinimumSize(new Dimension(0, 0));
    treeView.setPreferredSize(new Dimension(150, 600));
    return treeView;
}
Also used : JScrollPane(javax.swing.JScrollPane) JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Dimension(java.awt.Dimension) AbstractAction(javax.swing.AbstractAction)

Example 48 with TreeNode

use of javax.swing.tree.TreeNode in project JMRI by JMRI.

the class CatalogPanel method getCorrespondingNode.

/**
     * The tree held in the CatalogTreeManager must be kept in sync with the
     * tree displayed as the Image Index. Required in order to save the Index to
     * disc.
     */
private CatalogTreeNode getCorrespondingNode(CatalogTreeNode node) {
    TreeNode[] nodes = node.getPath();
    CatalogTreeNode cNode = null;
    for (int i = 0; i < _branchModel.size(); i++) {
        CatalogTreeNode cRoot = _branchModel.get(i).getRoot();
        cNode = match(cRoot, nodes, 1);
        if (cNode != null) {
            break;
        }
    }
    return cNode;
}
Also used : TreeNode(javax.swing.tree.TreeNode) Point(java.awt.Point)

Example 49 with TreeNode

use of javax.swing.tree.TreeNode in project intellij-plugins by JetBrains.

the class TreeTableRowSorter method sortOnKey.

private void sortOnKey(SortKey key) {
    if (key.getSortOrder() == SortOrder.UNSORTED) {
        return;
    }
    final int columnModelIndex = key.getColumn();
    TableColumnModel colModel = table.getColumnModel();
    int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
    if (modelIndex < 0 || getComparator(modelIndex) == null) {
        return;
    }
    final Comparator<TreeNode> comparator = new ComparatorWrapper<>(getComparator(modelIndex), key.getSortOrder() == SortOrder.ASCENDING);
    final List<TreePath> paths = TreeUtil.collectExpandedPaths(table.getTree());
    if (JTreeUtil.isSorted(paths, comparator, table.getTableModel())) {
        return;
    }
    for (TreePath path : paths) {
        Object node = path.getLastPathComponent();
        if (!(node instanceof DefaultMutableTreeNode)) {
            continue;
        }
        JTreeUtil.sortChildren((DefaultMutableTreeNode) node, comparator, table.getTableModel().getChildCount(node));
    }
    table.reload();
    TreeUtil.restoreExpandedPaths(table.getTree(), paths);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TableColumnModel(javax.swing.table.TableColumnModel)

Example 50 with TreeNode

use of javax.swing.tree.TreeNode in project intellij-plugins by JetBrains.

the class FoundUsersModelTest method testUserIn2Groups.

public void testUserIn2Groups() throws Exception {
    MockUser bob = new MockUser("BobName", null);
    bob.setProjects(new String[] { "bobProject", "anotherBobProject" });
    FoundUsersModel model = createModel(Arrays.asList(new User[] { bob }));
    assertEquals("2 projects expected", 2, getRoot(model).getChildCount());
    TreeNode projectNode1 = getRoot(model).getChildAt(0);
    assertEquals("Invalid project node", "anotherBobProject", projectNode1.toString());
    TreeNode projectNode2 = getRoot(model).getChildAt(1);
    assertEquals("Invalid project node", "bobProject", projectNode2.toString());
    assertEquals("One user in group expected", 1, projectNode1.getChildCount());
    assertEquals("One user in group expected", 1, projectNode2.getChildCount());
}
Also used : User(jetbrains.communicator.core.users.User) MockUser(jetbrains.communicator.mock.MockUser) TreeNode(javax.swing.tree.TreeNode) MockUser(jetbrains.communicator.mock.MockUser)

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