static Object[] computeChildren(VisualizerEvent ev) { int[] childIndices = ev.getArray(); Object[] arr = new Object[childIndices.length]; List<Node> nodes = ev.getSnapshot(); for (int i = 0; i < arr.length; i++) { arr[i] = Visualizer.findVisualizer(nodes.get(childIndices[i])); } return arr; }
/** * Updates the set of highlighted nodes. */ final void updateHighlight() { synchronized (highlightedTreeNodes) { highlightedTreeNodes.clear(); for (Node node : pageModel.getHighlightedNodes()) { TreeNode visualizer = Visualizer.findVisualizer(node); highlightedTreeNodes.add(visualizer); } } treeView.repaint(); }
private int rowForNode(Node n) { TreeNode tn = Visualizer.findVisualizer(n); if (tn != null) { ArrayList<TreeNode> al = new ArrayList<TreeNode> (); while (tn != null) { al.add(tn); tn = tn.getParent(); } Collections.reverse(al); TreePath tp = new TreePath(al.toArray()); int row = outline.getLayoutCache().getRowForPath(tp); return row; } return -1; }
public List<String[]> getExpandedPaths() { List<String[]> result = new ArrayList<String[]>(); TreeNode rtn = Visualizer.findVisualizer(getRootContext()); TreePath tp = new TreePath(rtn); // Get the root Enumeration<TreePath> paths = tree.getExpandedDescendants(tp); if (null != paths) { while (paths.hasMoreElements()) { TreePath ep = paths.nextElement(); Node en = Visualizer.findNode(ep.getLastPathComponent()); String[] path = NodeOp.createPath(en, getRootContext()); result.add(path); } } return result; }
public void scrollToNode(Node n) { TreeNode tn = Visualizer.findVisualizer(n); if (tn == null) { return; } TreeModel model = tree.getModel(); if (!(model instanceof DefaultTreeModel)) { return; } TreePath path = new TreePath(((DefaultTreeModel) model).getPathToRoot(tn)); Rectangle r = tree.getPathBounds(path); if (r != null) { tree.scrollRectToVisible(r); } }
private TreePath getTreePathForNode(Node node) { TreeNode tn = Visualizer.findVisualizer(node); if (tn == null) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new NullPointerException("TreeNode not found for node=" + node)); // NOI18N return null; } TreeModel model = tree.getModel(); if (!(model instanceof DefaultTreeModel)) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new NullPointerException("DefaultTreeModel not found, model=" + model)); // NOI18N return null; } return new TreePath(((DefaultTreeModel)model).getPathToRoot(tn)); } } // End of OutlineTreeView.
/** Converts path of strings to TreePath if exists null otherwise */ private TreePath stringPath2TreePath(String[] sp) { try { Node n = NodeOp.findPath(getRootContext(), sp); // Create the tree path TreeNode tns[] = new TreeNode[sp.length + 1]; for (int i = sp.length; i >= 0; i--) { tns[i] = Visualizer.findVisualizer(n); n = n.getParentNode(); } return new TreePath(tns); } catch (NodeNotFoundException e) { return null; } } }
/** * Tries to expand nodes selected in the explorer manager. */ private void expandSelection() { Node[] arr = manager.getSelectedNodes (); for (int i = 0; i < arr.length; i++) { if ( (arr[i].getParentNode() == null) && (! outline.isRootVisible())) { // don't try to show root if it is invisible continue; } TreeNode tn = Visualizer.findVisualizer(arr[i]); if (tn != null) { ArrayList<TreeNode> al = new ArrayList<TreeNode> (); while (tn != null) { al.add(tn); tn = tn.getParent(); } Collections.reverse(al); TreePath tp = new TreePath(al.toArray()); while ((tp != null) && (tp.getPathCount() > 0)) { tp = tp.getParentPath(); if (tp != null) { outline.expandPath(tp); } } } } }