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);
}
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);
}
}
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());
}
}
}
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);
}
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();
}
Aggregations