Search in sources :

Example 21 with TreePath

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

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

the class TreeHelpers method expandAll.

private static void expandAll(final JTree tree, final TreePath parent, final boolean expand) {
    // Traverse children
    final TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (final Enumeration<?> e = node.children(); e.hasMoreElements(); ) {
            final TreeNode n = (TreeNode) e.nextElement();
            final TreePath path = parent.pathByAddingChild(n);
            expandAll(tree, path, expand);
        }
    }
    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 23 with TreePath

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

Example 24 with TreePath

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

the class CAbstractDropHandler method canHandle.

@Override
public boolean canHandle(final DNDTree target, final Transferable transferable, final DataFlavor flavor, final int x, final int y) {
    if (!transferable.isDataFlavorSupported(m_flavor)) {
        return false;
    }
    final Object data = getData(transferable);
    if (data == null) {
        return false;
    }
    final TreePath pathTarget = target.getPathForLocation(x, y);
    if (pathTarget == null) {
        target.setSelectionPath(null);
        return false;
    }
    return canHandle((DefaultMutableTreeNode) pathTarget.getLastPathComponent(), data);
}
Also used : TreePath(javax.swing.tree.TreePath)

Example 25 with TreePath

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

the class CNodeExpander method setSelectionPath.

/**
   * Selects the project tree node that represents the given object.
   * 
   * @param tree The project tree.
   * @param object Object whose node is selected.
   */
public static void setSelectionPath(final JTree tree, final Object object) {
    tree.setSelectionPath(new TreePath(new Object[] { tree.getModel().getRoot(), findNode(tree, object) }));
    tree.validate();
}
Also used : TreePath(javax.swing.tree.TreePath)

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