Search in sources :

Example 16 with TreePath

use of javax.swing.tree.TreePath in project antlrworks by antlr.

the class AWTreePanel method scrollNodeToVisible.

public void scrollNodeToVisible(TreeNode node) {
    if (node == null)
        return;
    tree.scrollPathToVisible(new TreePath(jTreeModel.getPathToRoot(node)));
    treeGraphView.scrollNodeToVisible(node);
}
Also used : TreePath(javax.swing.tree.TreePath)

Example 17 with TreePath

use of javax.swing.tree.TreePath in project antlrworks by antlr.

the class AWTreePanel method selectNode.

public void selectNode(TreeNode node) {
    TreePath path = new TreePath(jTreeModel.getPathToRoot(node));
    tree.scrollPathToVisible(path);
    tree.setSelectionPath(path);
    treeGraphView.highlightNode(node);
}
Also used : TreePath(javax.swing.tree.TreePath)

Example 18 with TreePath

use of javax.swing.tree.TreePath in project languagetool by languagetool-org.

the class ConfigurationDialog method getMouseAdapter.

@NotNull
private MouseAdapter getMouseAdapter() {
    return new MouseAdapter() {

        private void handlePopupEvent(MouseEvent e) {
            JTree tree = (JTree) e.getSource();
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            TreePath[] paths = tree.getSelectionPaths();
            boolean isSelected = false;
            if (paths != null) {
                for (TreePath selectionPath : paths) {
                    if (selectionPath.equals(path)) {
                        isSelected = true;
                    }
                }
            }
            if (!isSelected) {
                tree.setSelectionPath(path);
            }
            if (node.isLeaf()) {
                JPopupMenu popup = new JPopupMenu();
                JMenuItem aboutRuleMenuItem = new JMenuItem(messages.getString("guiAboutRuleMenu"));
                aboutRuleMenuItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        RuleNode node = (RuleNode) tree.getSelectionPath().getLastPathComponent();
                        Rule rule = node.getRule();
                        Language lang = config.getLanguage();
                        if (lang == null) {
                            lang = Languages.getLanguageForLocale(Locale.getDefault());
                        }
                        Tools.showRuleInfoDialog(tree, messages.getString("guiAboutRuleTitle"), rule.getDescription(), rule, messages, lang.getShortCodeWithCountryAndVariant());
                    }
                });
                popup.add(aboutRuleMenuItem);
                popup.show(tree, e.getX(), e.getY());
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopupEvent(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopupEvent(e);
            }
        }
    };
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) Language(org.languagetool.Language) Rule(org.languagetool.rules.Rule) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with TreePath

use of javax.swing.tree.TreePath in project CoreNLP by stanfordnlp.

the class FileTreeModel method treeNodeChanged.

public void treeNodeChanged(FileTreeNode n) {
    TreePath t = new TreePath(makeTreePathArray(n));
    //System.out.println("Tree path is: " + t);
    this.fireTreeStructureChanged(t);
}
Also used : TreePath(javax.swing.tree.TreePath)

Example 20 with TreePath

use of javax.swing.tree.TreePath in project binnavi by google.

the class CRootTagTreeNode method refreshTree.

/**
   * Rebuilds the entire tree from scratch by filtering over all elements in the graph. This is
   * pretty damn slow for any reasonably-sized graph, and should hence be done only rarely.
   * @deprecated
   */
@Deprecated
@Override
public void refreshTree(final ITreeNode<CTag> tag) {
    final List<DefaultMutableTreeNode> lastNodes = TreeHelpers.getLastExpandedNodes(m_tagsTree);
    final List<Integer> lastNodeIds = new ArrayList<Integer>();
    if ((tag != null) && (tag.getParent() != null)) {
        lastNodeIds.add(tag.getParent().getObject().getId());
    }
    for (final DefaultMutableTreeNode lastNode : lastNodes) {
        if (lastNode.getUserObject() instanceof Integer) {
            final int tagId = (Integer) lastNode.getUserObject();
            lastNodeIds.add(tagId);
        }
    }
    deleteChildren();
    createChildren();
    final Enumeration<?> bfn = breadthFirstEnumeration();
    while (bfn.hasMoreElements()) {
        final Object node = bfn.nextElement();
        int tagId = -1;
        TreePath path = null;
        if (node instanceof CRootTagTreeNode) {
            final CRootTagTreeNode rootNode = (CRootTagTreeNode) node;
            tagId = m_rootTag.getObject().getId();
            path = new TreePath(rootNode.getPath());
        } else if (node instanceof CTagTreeNode) {
            final CTagTreeNode treeNode = (CTagTreeNode) node;
            tagId = treeNode.getTag().getObject().getId();
            path = new TreePath(treeNode.getPath());
        } else if (node instanceof CTaggedGraphNodesContainerNode) {
            final CTaggedGraphNodesContainerNode containerNode = (CTaggedGraphNodesContainerNode) node;
            tagId = -containerNode.getTag().getObject().getId();
            path = new TreePath(containerNode.getPath());
        }
        if (lastNodeIds.contains(tagId)) {
            m_tagsTree.expandPath(path);
        }
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList) CTagTreeNode(com.google.security.zynamics.binnavi.Gui.GraphWindows.NodeTaggingTree.Nodes.CTagTreeNode) CTaggedGraphNodesContainerNode(com.google.security.zynamics.binnavi.Gui.GraphWindows.NodeTaggingTree.Nodes.CTaggedGraphNodesContainerNode)

Aggregations

TreePath (javax.swing.tree.TreePath)539 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)177 ArrayList (java.util.ArrayList)58 TreeNode (javax.swing.tree.TreeNode)56 Nullable (org.jetbrains.annotations.Nullable)49 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)46 JTree (javax.swing.JTree)34 NotNull (org.jetbrains.annotations.NotNull)32 Test (org.junit.Test)22 Tree (com.intellij.ui.treeStructure.Tree)21 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)21 TreeSelectionListener (javax.swing.event.TreeSelectionListener)21 MouseEvent (java.awt.event.MouseEvent)18 Point (java.awt.Point)17 ActionEvent (java.awt.event.ActionEvent)15 KeyEvent (java.awt.event.KeyEvent)12 EVTask (net.sourceforge.processdash.ev.EVTask)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 KeyAdapter (java.awt.event.KeyAdapter)11 List (java.util.List)11