public void run() { if (getTree().isExpanded(t)) { expandedNodes.add(t.getLastPathComponent()); } else { expandedNodes.remove(t.getLastPathComponent()); } }
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 attach a new config to"); // XXX add a message telling users to select a node } else { createAttrConfigForNode((Node) path.getLastPathComponent()); } }
public void editSelected() { TreePath selected = tree.getSelectionPath(); if (selected != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) selected.getLastPathComponent(); Object obj = node.getUserObject(); if (obj instanceof CavityDBObject) { CavityDBObject dbObj = (CavityDBObject) obj; new ObjectEditingFrame(new ObjectEditingPanel(dbObj)); } } }
public DefaultMutableTreeNode addObject(MenuItem child) { DefaultMutableTreeNode parentNode = null; TreePath parentPath = tree.getSelectionPath(); if (parentPath == null) { parentNode = rootNode; } else { parentNode = (DefaultMutableTreeNode) (parentPath.getLastPathComponent()); } return addObject(parentNode, child, true); }
/** Remove the currently selected node. */ public void removeCurrentNode() { TreePath currentSelection = tree.getSelectionPath(); if (currentSelection != null) { DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) (currentSelection.getLastPathComponent()); MutableTreeNode parent = (MutableTreeNode) (currentNode.getParent()); if (parent != null) { treeModel.removeNodeFromParent(currentNode); return; } } // Either there was no selection, or the root was selected. toolkit.beep(); }
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); } } }
/** * Called whenever the value of the selection changes. * * @param e the event that characterizes the change. */ public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if (node.isLeaf()) { if (getInformation(path) != null) { // When selecting an image information. XmlInformation info = getInformation(path); for (int i = 0; i < listener_list.size(); i++) { InformationTreeSelectionListener listener = (InformationTreeSelectionListener) listener_list.elementAt(i); listener.select(info); } } else { // When expanding a folder. expandNode(node); } } } }
/** Removes the current selected group. */ final void removeSelectedGroup() { TreePath[] selectionPaths = this.tree.getSelectionPaths(); if (selectionPaths == null) { return; } DefaultTreeModel model = (DefaultTreeModel) this.tree.getModel(); ElementTreeNode rootNode = (ElementTreeNode) model.getRoot(); for (TreePath selectionPath : selectionPaths) { ElementTreeNode treeNode = (ElementTreeNode) selectionPath.getLastPathComponent(); if (treeNode.getUserObject() instanceof ElementGroup) { ElementGroup elementGroup = (ElementGroup) treeNode.getUserObject(); this.model.removeGroup(elementGroup); model.nodesWereRemoved( rootNode, new int[] {rootNode.getIndex(treeNode)}, new Object[] {treeNode}); } } }
private void myDoubleClick(int row, TreePath path) { if (path != null) { JFrame infoFrame = new JFrame("Object Info for: " + path); JLabel objectLabel; JLabel parentPathLabel; // Display Selected Object Name; objectLabel = new JLabel("Object: " + path.getLastPathComponent().toString()); objectLabel.setHorizontalAlignment(SwingConstants.CENTER); // Display specific object information parentPathLabel = new JLabel("Parent Path: " + path.getParentPath()); parentPathLabel.setHorizontalAlignment(SwingConstants.CENTER); // Construct infoFrame infoFrame.getContentPane().add(objectLabel, BorderLayout.CENTER); infoFrame.getContentPane().add(parentPathLabel, BorderLayout.SOUTH); infoFrame.pack(); infoFrame.setVisible(true); } }
/** * Processes an idChanged event. Search is different from all other navigators in that you while * search tree is synchronized the highlighting doesn't occur unless selected from the search * navigator. */ public void idChanged(HelpModelEvent e) { ID id = e.getID(); URL url = e.getURL(); HelpModel helpModel = searchnav.getModel(); debug("idChanged(" + e + ")"); if (e.getSource() != helpModel) { debug("Internal inconsistency!"); debug(" " + e.getSource() + " != " + helpModel); throw new Error("Internal error"); } TreePath s = tree.getSelectionPath(); if (s != null) { Object o = s.getLastPathComponent(); // should require only a TreeNode if (o instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode tn = (DefaultMutableTreeNode) o; SearchTOCItem item = (SearchTOCItem) tn.getUserObject(); if (item != null) { ID nId = item.getID(); if (nId != null && nId.equals(id)) { return; } } } } DefaultMutableTreeNode node = findIDorURL(topNode, id, url); if (node == null) { // node doesn't exist. Need to clear the selection. debug("node didn't exist"); tree.clearSelection(); return; } TreePath path = new TreePath(node.getPath()); tree.expandPath(path); tree.setSelectionPath(path); tree.scrollPathToVisible(path); }
/** * Creates a new check for the Config in the path. * * @param t The path to the descriptor config to check. */ public CheckIfExpanded(TreePath t) { assert t.getLastPathComponent() instanceof Config; this.t = t; }