// ====================================================== private void treeMouseClicked(java.awt.event.MouseEvent evt) { // Set selection at mouse position TreePath selectedPath = getPathForLocation(evt.getX(), evt.getY()); if (selectedPath == null) return; int mask = evt.getModifiers(); // Check button clicked if (evt.getClickCount() == 2 && (mask & MouseEvent.BUTTON1_MASK) != 0) { } else if ((mask & MouseEvent.BUTTON3_MASK) != 0) { } }
// ====================================================== // ====================================================== private void treeMousePressed(java.awt.event.MouseEvent evt) { int mask = evt.getModifiers(); if ((mask & MouseEvent.BUTTON1_MASK) != 0) { TreePath selectedPath = getPathForLocation(evt.getX(), evt.getY()); if (selectedPath == null) return; DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedPath.getPathComponent(selectedPath.getPathCount() - 1); Object o = node.getUserObject(); if (o instanceof String) { TransferHandler transfer = this.getTransferHandler(); transfer.exportAsDrag(this, evt, TransferHandler.COPY); dragged_node = node; parent.setCursor(renderer.getNodeCursor(node)); } } }
// ====================================================== // ====================================================== private void treeMouseReleased(java.awt.event.MouseEvent evt) { int mask = evt.getModifiers(); if ((mask & MouseEvent.BUTTON1_MASK) != 0) { if (dragged_node == null) return; TreePath selectedPath = getPathForLocation(evt.getX(), evt.getY()); if (selectedPath == null) if ((selectedPath = getUpperPath(evt.getX(), evt.getY())) == null) return; DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedPath.getPathComponent(selectedPath.getPathCount() - 1); Object o = node.getUserObject(); int pos = 0; if (o instanceof String) { DefaultMutableTreeNode p_node = (DefaultMutableTreeNode) node.getParent(); pos = p_node.getIndex(node); node = p_node; } moveLeaf(node, dragged_node, pos); dragged_node = null; Cursor cursor = new Cursor(Cursor.DEFAULT_CURSOR); parent.setCursor(cursor); } }