/** * Adds a node to the visualization tree as a child of this node. The <code>child</code>'s parent * is set to be this node. If <code> * child</code> is currently a child to another node <code>n</code>, then <code>child</code> is * first {@link #removeChildDisplay(TreeBrowserDisplay) removed} from <code>n</code> and then * added to this node. * * @param child The node to add. Mustn't be <code>null</code>. * @see DefaultMutableTreeNode */ public void addChildDisplay(TreeBrowserDisplay child) { if (child == null) throw new NullPointerException("No child."); if (childrenDisplay.contains(child)) return; if (child.parentDisplay != null) // Was the child of another node. child.parentDisplay.removeChildDisplay(child); child.parentDisplay = this; childrenDisplay.add(child); }
/** * Removes the specified <code>child</code> node. If <code>child</code> is not among the children * of this node, no action is taken. Otherwise, it is removed from the children set and orphaned. * That is, its parent (which is this node) is set to <code>null</code>. * * @param child The node to remove. Mustn't be <code>null</code>. */ public void removeChildDisplay(TreeBrowserDisplay child) { if (child == null) throw new NullPointerException("No child."); if (childrenDisplay.contains(child)) { // NOTE: parentDisplay != null b/c child has been added through // the add method. child.parentDisplay.childrenDisplay.remove(child); child.parentDisplay = null; } }