org.xith3d.scenegraph
Class Switch

java.lang.Object
  extended by org.xith3d.scenegraph.SceneGraphObject
      extended by org.xith3d.scenegraph.Node
          extended by org.xith3d.scenegraph.GroupNode
              extended by org.xith3d.scenegraph.Group
                  extended by org.xith3d.scenegraph.Switch
All Implemented Interfaces:
org.jagatoo.datatypes.NamableObject, org.jagatoo.datatypes.NamedObject, org.openmali.spatial.SpatialNode
Direct Known Subclasses:
BSPTreeGroup, LODSwitch

public class Switch
extends Group

Switch group nodes allow an application to choose dynamically amoung a number of subgraphs. The Switch node contains an ordered list of children and a switch value. The switch value determines which child or children will be rendered. The index order of children is only used for selecting the appropriate child or children, it does not specify rendering order.


Field Summary
static int CHILD_ALL
          indicates that all children are rendered, switch node acts as an oridinary Group node.
static int CHILD_MASK
          indicates that the childMask BitSet is used to select the children that are rendered
static int CHILD_NONE
          indicates that no children are rendered
 
Fields inherited from class org.xith3d.scenegraph.GroupNode
children, hostGroup, numChildren, totalNumChildren, totalNumShapes
 
Fields inherited from class org.xith3d.scenegraph.Node
bounds, boundsAutoCompute, boundsDirty, globalIgnoreBounds, instanceBoundsTypeHint, transformGroup, untransformedBounds
 
Fields inherited from class org.xith3d.scenegraph.SceneGraphObject
XITH3D_USERDATAKEY_OLDUSERDATA
 
Constructor Summary
Switch()
          Constructs a new Switch object with an empty childMask and whichChild set to CHILD_NONE.
Switch(int whichChild)
          Constructs a new Switch object with an empty childMask and the specified value for whichChild.
Switch(int whichChild, java.util.BitSet childMask)
          Constructs a new Switch object with the specified childMask and the specified value for whichChild.
 
Method Summary
 java.util.BitSet getChildMask()
          Gets the child mask for this object
 Node getCurrentChild()
          Gets the curently selected child.
static boolean getIgnoreMaskForTraversal()
          If this is true, all children will be traversed by the traverse() method.
 int getWhichChild()
          Gets the index of the child to render for this object.
 boolean isVisible(Node child)
          Tests if specified child is visible according current switch settings.
protected  Switch newInstance()
          
 Node removeChild(int index)
          Remove the child at the specified index.
 void setChildMask(java.util.BitSet childMask)
          Sets the child mask for this object.
static boolean setIgnoreMaskForTraversal(boolean ignore)
          If this is true, all children will be traversed by the traverse() method.
 void setWhichChild(int whichChild)
          Sets the index of the child to render for this object.
 boolean traverse(DetailedTraversalCallback callback)
          Traverses the scenegraph from this node on.
 boolean traverse(TraversalCallback listener)
          Traverses the scenegraph from this node on.
 
Methods inherited from class org.xith3d.scenegraph.Group
moveTo
 
Methods inherited from class org.xith3d.scenegraph.GroupNode
absorbDetails, addChild, addChild, checkChild, dump, dump, ensureCapacity, expandBounds, findAll, findAll, findFirst, findFirst, freeOpenGLResources, getChild, getChildren, getChildren, getClipper, getPickHost, getScissorRect, getTotalNumChildren, getTotalNumShapes, indexOf, isPickHost, mergeInheritedClipper, mergeInheritedNodes, mergeInheritedScissorRect, numChildren, removeAllChildren, removeChild, setBoundsDirty, setBoundsDirtyUpward, setChild, setClipper, setLive, setPickHost, setPickHost, setScissorRect, setShowBounds, sharedCopy, sharedCopy, unmergeInheritedFog, unmergeInheritedLight, unmergeInheritedNodes, updateBounds, updateBoundsCheap
 
Methods inherited from class org.xith3d.scenegraph.Node
cloneNode, detach, duplicateNode, freeOpenGLResources, getBounds, getBoundsAutoCompute, getBoundsType, getBoundsTypeHint, getDefaultPickable, getIndentString, getInheritedNodeAttributes, getModListener, getOrderedChild, getOrderedState, getParent, getRoot, getShadowAttachment, getShowBounds, getTransformGroup, getTreeCell, getWorldBounds, getWorldTransform, getWorldTransform, isBillboard, isIgnoreBounds, isOccluder, isPickable, isRenderable, isUpdatableNode, popGlobalIgnoreBounds, printBounds, pushGlobalIgnoreBounds, setBounds, setBoundsAutoCompute, setBoundsTypeHint, setDefaultPickable, setGlobalIgnoreBounds, setIgnoreBounds, setIsOccluder, setModListener, setOrderedChild, setParent, setPickable, setPickableRecursive, setPickableRecursive, setRenderable, setShadowAttachment, setShowBounds, setTransformGroup, setTreeCell, updateOrderedChild, updateTransformGroup, updateWorldTransform
 
Methods inherited from class org.xith3d.scenegraph.SceneGraphObject
getName, getUserData, getUserData, getUserDataMap, isLive, setName, setUserData, setUserData, setUserDataRecursive, setUserDataRecursive, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CHILD_NONE

public static final int CHILD_NONE
indicates that no children are rendered

See Also:
Constant Field Values

CHILD_ALL

public static final int CHILD_ALL
indicates that all children are rendered, switch node acts as an oridinary Group node.

See Also:
Constant Field Values

CHILD_MASK

public static final int CHILD_MASK
indicates that the childMask BitSet is used to select the children that are rendered

See Also:
Constant Field Values
Constructor Detail

Switch

public Switch(int whichChild,
              java.util.BitSet childMask)
Constructs a new Switch object with the specified childMask and the specified value for whichChild.


Switch

public Switch(int whichChild)
Constructs a new Switch object with an empty childMask and the specified value for whichChild.


Switch

public Switch()
Constructs a new Switch object with an empty childMask and whichChild set to CHILD_NONE.

Method Detail

setWhichChild

public void setWhichChild(int whichChild)
Sets the index of the child to render for this object. The value may be a non-negative integer, indicating a specific child, or it may be one of the following constants: CHILD_NONE, CHILD_ALL or CHILD_MASK.


getWhichChild

public final int getWhichChild()
Gets the index of the child to render for this object.


setChildMask

public final void setChildMask(java.util.BitSet childMask)
Sets the child mask for this object.


getChildMask

public final java.util.BitSet getChildMask()
Gets the child mask for this object


getCurrentChild

public Node getCurrentChild()
Gets the curently selected child. If whichChild is out of range or is set to CHILD_MASK, CHILD_ALL or CHILD_NONE then null is returned.


removeChild

public Node removeChild(int index)
Remove the child at the specified index. The parent of the child is set to null. The child is made not live.

Overrides:
removeChild in class GroupNode

isVisible

public final boolean isVisible(Node child)
Tests if specified child is visible according current switch settings.

Returns:
true if child visible, false if not visible or child is not a member of this switch

setIgnoreMaskForTraversal

public static boolean setIgnoreMaskForTraversal(boolean ignore)
If this is true, all children will be traversed by the traverse() method.
If this is false, only the unmasked children will be traversed by the traverse() method.

Parameters:
ignore -
Returns:
the previous value

getIgnoreMaskForTraversal

public static boolean getIgnoreMaskForTraversal()
If this is true, all children will be traversed by the traverse() method.
If this is false, only the unmasked children will be traversed by the traverse() method.


newInstance

protected Switch newInstance()

Overrides:
newInstance in class Group
Returns:
a new instance of this class. This is invoked by the sharedCopy() method.
See Also:
GroupNode.sharedCopy(CopyListener)

traverse

public boolean traverse(TraversalCallback listener)
Traverses the scenegraph from this node on. If this Node is a Group it will recusively run through each child.

Overrides:
traverse in class GroupNode
Parameters:
listener - the listener is notified of any traversed Node on the way
Returns:
if false, the whole traversal will stop
See Also:
getIgnoreMaskForTraversal()

traverse

public boolean traverse(DetailedTraversalCallback callback)
Traverses the scenegraph from this node on. If this Node is a Group it will recusively run through every child.

Overrides:
traverse in class Group
Parameters:
callback - the listener is notified of any traversed Node on the way
Returns:
if false, the whole traversal will stop