public void actionPerformed(ActionEvent event) { JTree tree = getTree(); TreePath path = tree.getSelectionPath(); if (path == null) { sheet.getLogger().warning("Warning: User must select a node to delete"); // XXX add message telling users to select a node } else { Node selected = (Node) path.getLastPathComponent(); try { Node parent = selected.getParent(); if (parent != null) { parent.removeChild(selected); select(parent); } } catch (UnsupportedOperationException uox) { sheet.getLogger().warning("Cannot delete node: " + selected); } } }
public void mouseReleased(MouseEvent e) { _mouse_pressed = false; _drag_target = null; // send target node event first Node node = window.findNode(new AminoPoint(e.getPoint().getX(), e.getPoint().getY())); // console.log(node); MEvent evt = new MEvent(); evt.node = node; evt.x = e.getX(); evt.y = e.getY(); if (node != null) { Node start = node; while (start != null) { fireEvent("MOUSE_RELEASE", start, evt); if (start.isMouseBlocked()) return; start = (Node) start.getParent(); } } // send general events next fireEvent("MOUSE_RELEASE", null, evt); }
public void mouseDragged(MouseEvent e) { if (_mouse_pressed) { Node node = window.findNode(new AminoPoint(e.getPoint().getX(), e.getPoint().getY())); MEvent evt = new MEvent(); // redirect events to current drag target, if applicable if (_drag_target != null) { node = _drag_target; } evt.node = node; evt.x = e.getX(); evt.y = e.getY(); if (node != null) { Node start = node; while (start != null) { fireEvent("MOUSE_DRAG", start, evt); if (start.isMouseBlocked()) return; start = (Node) start.getParent(); } } // send general events next fireEvent("MOUSE_DRAG", null, evt); } }
// IconFocusedMethods public static void merge( Node currentNode, JoeTree tree, OutlineLayoutManager layout, boolean withSpaces) { JoeNodeList nodeList = tree.getSelectedNodes(); // Get merged text StringBuffer buf = new StringBuffer(); boolean didMerge = false; if (withSpaces) { for (int i = 0, limit = nodeList.size(); i < limit; i++) { Node node = nodeList.get(i); // Skip if node is not editable if (!node.isEditable()) { continue; } didMerge = true; node.getMergedValueWithSpaces(buf, i); } } else { for (int i = 0, limit = nodeList.size(); i < limit; i++) { Node node = nodeList.get(i); // Skip if node is not editable if (!node.isEditable()) { continue; } didMerge = true; node.getMergedValue(buf); } } // It's possible all nodes were read-only. If so then abort. if (!didMerge) { return; } // Get youngest editable node Node youngestNode = null; for (int i = 0, limit = nodeList.size(); i < limit; i++) { Node node = nodeList.get(i); if (node.isEditable()) { youngestNode = node; break; } } // Abort if no editable nodes found. if (youngestNode == null) { return; } Node parent = youngestNode.getParent(); CompoundUndoableReplace undoable = new CompoundUndoableReplace(parent); Node newNode = new NodeImpl(tree, buf.toString()); newNode.setDepth(youngestNode.getDepth()); newNode.setCommentState(youngestNode.getCommentState()); undoable.addPrimitive(new PrimitiveUndoableReplace(parent, youngestNode, newNode)); // Iterate over the remaining selected nodes deleting each one int mergeCount = 1; for (int i = 0, limit = nodeList.size(); i < limit; i++) { Node node = nodeList.get(i); // Abort if node is not editable if (!node.isEditable() || node == youngestNode) { continue; } undoable.addPrimitive(new PrimitiveUndoableReplace(parent, node, null)); mergeCount++; } if (!undoable.isEmpty()) { if (withSpaces) { if (mergeCount == 1) { undoable.setName("Merge Node with Spaces"); } else { undoable.setName( new StringBuffer() .append("Merge ") .append(mergeCount) .append(" Nodes with Spaces") .toString()); } } else { if (mergeCount == 1) { undoable.setName("Merge Node"); } else { undoable.setName( new StringBuffer().append("Merge ").append(mergeCount).append(" Nodes").toString()); } } tree.getDocument().getUndoQueue().add(undoable); undoable.redo(); } return; }