/** * Sets the selected state for this node. Only nodes that implement the * marker interface {@link Selectable} can be selected. This method does * nothing if this node is not selectable. * <p> * Classes that extend this abstract base class may override the method * {@link #selectedChanged()}, typically to alter the appearance of a * node that has been selected or deselected. * @param selected true, for selected; false, otherwise. */ public final void setSelected(boolean selected) { if (this instanceof Selectable && _selected!=selected) { // Change the selected state of this node. _selected = selected; selectedChanged(); // If this node is in a world, update its selected set. World world = getWorld(); if (world!=null) world.updateSelectedSet(this); } }
/** * Updates the selected set of this world for the specified node. * This method must be called when (1) the specified node is added/removed * to/from this world or (2) the specified node is selected or deselected. * @param node the node for which to update the selected set of this world. */ void updateSelectedSet(Node node) { // Update our selected set for the specified node. If the node is now // (1) selected and (2) part of this world, then add it to our selected // set. (Ok if already there.) Otherwise, remove it from our selected // set. (Ok if not there.) if (node instanceof Selectable) { if (node.isSelected() && this==node.getWorld()) { _selectedSet.add(node); } else { _selectedSet.remove(node); } } // If the specified node is a group, then update our selected set // for each of its children. if (node instanceof Group) { Group group = (Group)node; Iterator<Node> children = group.getChildren(); while (children.hasNext()) { Node child = children.next(); updateSelectedSet(child); } } }
/** * Removes the specified child node from this group's list of children. If * the node is not a child of this group, then this method does nothing. * @param child the child node. */ public void removeChild(Node child) { if (child.removeParent(this)) { _childList.remove(child); dirtyBoundingSphere(); dirtyDraw(); World worldGroup = getWorld(); if (worldGroup!=null) worldGroup.updateSelectedSet(child); } }
/** * Adds the specified child node to this group's list of children. If the * node is already a child of this group, then this method does nothing. * <p> * The child must not be a world (root) node, because a world has no * parents. Also, if this group is in a world, the child must not already * be in a different world. A node cannot be in more than one world at a * time; it must be removed from one world before it can be added to another. * @param child the child node. */ public void addChild(Node child) { Check.argument(!(child instanceof World),"child is not a world"); World worldChild = child.getWorld(); World worldGroup = getWorld(); Check.argument( worldChild==null || worldGroup==null || worldChild==worldGroup, "child is not already in a different world"); if (child.addParent(this)) { _childList.add(child); dirtyBoundingSphere(); dirtyDraw(); if (worldGroup!=null) worldGroup.updateSelectedSet(child); } }