/** * Delete this node by removing it from its parent's list of children. */ public void removeFromParent() { if (parent != null) { parent.removeChild(this); } }
/** * Remove all the children in the given collection from this node's list of * children. All removed nodes will have their parent set to null. * * @param childrenNodes the collection of children to remove */ public void removeChildren(final Collection childrenNodes) { final Iterator i = childrenNodes.iterator(); while (i.hasNext()) { final PNode each = (PNode) i.next(); removeChild(each); } }
/** * Raise this node within the Z-order of its parent to the top. * * @since 3.0 */ public void raiseToTop() { final PNode p = parent; if (p != null) { p.removeChild(this); p.addChild(this); } }
/** * Lower this node within the Z-order of its parent to the bottom. * * @since 3.0 */ public void lowerToBottom() { final PNode p = parent; if (p != null) { p.removeChild(this); p.addChild(0, this); } }
/** * Remove the given child from this node's children list. Any subsequent * children are shifted to the left (one is subtracted from their indices). * The removed child's parent is set to null. * * @param child the child to remove * @return the removed child */ public PNode removeChild(final PNode child) { final int index = indexOfChild(child); if (index == -1) { return null; } return removeChild(index); }
/** * Swaps this node out of the scene graph tree, and replaces it with the * specified replacement node. This node is left dangling, and it is up to * the caller to manage it. The replacement node will be added to this * node's parent in the same position as this was. That is, if this was the * 3rd child of its parent, then after calling replaceWith(), the * replacement node will also be the 3rd child of its parent. If this node * has no parent when replace is called, then nothing will be done at all. * * @param replacementNode the new node that replaces the current node in the * scene graph tree. */ public void replaceWith(final PNode replacementNode) { if (parent != null) { final PNode p = parent; final int index = p.getChildrenReference().indexOf(this); p.removeChild(this); p.addChild(index, replacementNode); } }
/** * Raise this node within the Z-order of its parent above the specified sibling node. * * @since 3.0 * @param sibling sibling node to raise this node above */ public void raiseAbove(final PNode sibling) { final PNode p = parent; if (p != null && p == sibling.getParent()) { p.removeChild(this); final int index = p.indexOfChild(sibling); p.addChild(index + 1, this); } }
/** * Lower this node within the Z-order of its parent below the specified sibling node. * * @since 3.0 * @param sibling sibling node to lower this node below */ public void lowerBelow(final PNode sibling) { final PNode p = parent; if (p != null && p == sibling.getParent()) { p.removeChild(this); final int index = p.indexOfChild(sibling); p.addChild(index, this); } }
/** * Add a node to be a new child of this node at the specified index. If * child was previously a child of another node, it is removed from that * node first. * * @param index where in the children list to insert the child * @param child the new child to add to this node */ public void addChild(final int index, final PNode child) { final PNode oldParent = child.getParent(); if (oldParent != null) { oldParent.removeChild(child); } child.setParent(this); getChildrenReference().add(index, child); child.invalidatePaint(); invalidateFullBounds(); firePropertyChange(PROPERTY_CODE_CHILDREN, PROPERTY_CHILDREN, null, children); }