/** * Add a new root node to an empty Tree. * @return the newly added root Node */ public Node addRoot() { return getNode(addRootRow()); }
/** * Get the previous sibling of the given node. * @param node a node * @return the previous sibling, or null if there is no previous sibling */ public Node getPreviousSibling(Node node) { int n = getPreviousSiblingRow(node.getRow()); return ( n<0 ? null : getNode(n) ); }
/** * Get the child node at the given index. * @param node the parent Node * @param idx the child index * @return the child Node */ public Node getChild(Node node, int idx) { int c = getChildRow(node.getRow(), idx); return ( c<0 ? null : getNode(c) ); }
/** * Get the next sibling of the given node. * @param node a node * @return the next sibling, or null if there is no next sibling */ public Node getNextSibling(Node node) { int n = getNextSiblingRow(node.getRow()); return ( n<0 ? null : getNode(n) ); }
/** * Get a node's parent node * @param n the child node * @return the parent node, or null if there is no parent */ public Node getParent(Node n) { int p = getParent(n.getRow()); return ( p < 0 ? null : getNode(p) ); }
/** * Add a child node to the given parent node. An edge between the two * will also be created. * @param parent the parent node * @return the added child node */ public Node addChild(Node parent) { nodeCheck(parent, true); return getNode(addChild(parent.getRow())); }
/** * Get the root node. * @return the root Node */ public Node getRoot() { try { prefuse.data.Node n = ((prefuse.data.Tree) getPrefuseGraph()).getRoot(); return new PrefuseObviousNode(n); } catch (IllegalArgumentException e) { for (Node node : this.getNodes()) { int nodeRow = node.getRow(); if (((prefuse.data.Tree) getPrefuseGraph()).getParent(nodeRow) < 0) { return new PrefuseObviousNode( ((prefuse.data.Tree) getPrefuseGraph()).getNode(nodeRow)); } } return null; } }