Search in sources :

Example 21 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode 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 22 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project smile by haifengl.

the class SmileDemo method valueChanged.

/** Required by TreeSelectionListener interface. */
@Override
public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    if (node != null && node.isLeaf()) {
        int pos = workspace.getDividerLocation();
        workspace.setTopComponent((JPanel) node.getUserObject());
        workspace.setDividerLocation(pos);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 23 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode 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)

Example 24 with DefaultMutableTreeNode

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

the class AbstractTreeTransferHandler method drop.

@Override
public final void drop(final DropTargetDropEvent dtde) {
    if (drawImage) {
        clearImage();
    }
    final int action = dtde.getDropAction();
    final Transferable transferable = dtde.getTransferable();
    final Point pt = dtde.getLocation();
    if (transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR) && canPerformAction(tree, draggedNode, action, pt)) {
        boolean gotData = false;
        DefaultMutableTreeNode node = null;
        try {
            node = (DefaultMutableTreeNode) transferable.getTransferData(TransferableNode.NODE_FLAVOR);
            gotData = true;
        } catch (final IOException e) {
            // TODO: This should be properly logged
            System.out.println(e);
        } catch (final UnsupportedFlavorException e) {
            // TODO: This should be properly logged
            System.out.println(e);
        }
        if (gotData) {
            final TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
            final DefaultMutableTreeNode newParentNode = (DefaultMutableTreeNode) pathTarget.getLastPathComponent();
            if (executeDrop(tree, node, newParentNode, action)) {
                dtde.acceptDrop(action);
                dtde.dropComplete(true);
                return;
            }
        }
    } else if (canPerformAction(tree, dtde.getCurrentDataFlavors()[0], dtde.getTransferable(), action, pt)) {
        final TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
        final DefaultMutableTreeNode newParentNode = (DefaultMutableTreeNode) pathTarget.getLastPathComponent();
        if (executeDrop(tree, dtde.getTransferable(), newParentNode, action)) {
            dtde.acceptDrop(action);
            dtde.dropComplete(true);
            return;
        }
    }
    dtde.rejectDrop();
    dtde.dropComplete(false);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) Transferable(java.awt.datatransfer.Transferable) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point)

Example 25 with DefaultMutableTreeNode

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

the class CProjectTree method showPopupMenu.

/**
   * Shows a popup menu that depends on the node that was clicked.
   * 
   * @param event The event to handle.
   */
private void showPopupMenu(final MouseEvent event) {
    final IProjectTreeNode selectedNode = (IProjectTreeNode) TreeHelpers.getNodeAt(this, event.getX(), event.getY());
    if (selectedNode == null) {
        // Show the default menu
        m_popup.show(this, event.getX(), event.getY());
    } else {
        setSelectionPath(new TreePath(((DefaultMutableTreeNode) selectedNode).getPath()));
        final JPopupMenu menu = selectedNode.getPopupMenu();
        if (menu != null) {
            menu.show(this, event.getX(), event.getY());
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IProjectTreeNode(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.IProjectTreeNode) JPopupMenu(javax.swing.JPopupMenu)

Aggregations

DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)605 TreePath (javax.swing.tree.TreePath)162 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)85 Nullable (org.jetbrains.annotations.Nullable)50 ArrayList (java.util.ArrayList)44 TreeNode (javax.swing.tree.TreeNode)42 Test (org.junit.Test)39 JTree (javax.swing.JTree)34 NotNull (org.jetbrains.annotations.NotNull)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 JScrollPane (javax.swing.JScrollPane)25 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)21 TreeSelectionListener (javax.swing.event.TreeSelectionListener)21 Module (com.intellij.openapi.module.Module)20 Tree (com.intellij.ui.treeStructure.Tree)19 Enumeration (java.util.Enumeration)18 MProduct (org.compiere.model.MProduct)17 MouseEvent (java.awt.event.MouseEvent)15 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)14 List (java.util.List)13