syn3d.nodes
Class SceneNode

java.lang.Object
  extended by syn3d.base.ActiveNode
      extended by syn3d.nodes.GroupNode
          extended by syn3d.nodes.SceneNode
All Implemented Interfaces:
java.io.Serializable, EndNotificationListener
Direct Known Subclasses:
SceneNodeJava3D, SceneNodeXith3D

public class SceneNode
extends GroupNode
implements EndNotificationListener, java.io.Serializable

See Also:
Serialized Form

Nested Class Summary
protected  class SceneNode.SceneTimerTask
          Notify listeners that this scene has changed.
 
Field Summary
protected static int anonymousSceneNumber
           
protected  ListenerManager dirtyNodes
          An array of Dirty nodes to update before calling listeners The dirty nodes are then automatically removed from this array, as they're supposed to be cleaned up
protected  java.lang.String fileName
          Current file name used for saving the scene
static int FLY_BY_MODE
          In fly-by mode, the user can freely move in the scene.
protected static javax.swing.Icon icon
           
protected  ListenerManager listeners
          An array of UniverseChangeListener objects
static int REFRESH_PERIOD
           
protected  long refreshPeriod
           
protected  boolean refreshPeriodChanged
          True when the user has changed the period for refreshing the scene>
static int ROTATION_MODE
          In rotation mode, the user rotates the whole scene and can zoom in or out.
protected  java.util.Timer timer
          This timer is used to gather notify events and send them at a reasonable rate to 3D motors.
protected  int viewingMode
           
 
Fields inherited from class syn3d.base.ActiveNode
children, name, parent
 
Constructor Summary
SceneNode(ActiveNode parent)
           
 
Method Summary
 void addDirtyNode(DirtyNode node)
           
 void addListener(SceneChangeListener dsl)
           
 void autoZoom()
          Auto zooms the scene out of all objects
 void changeProjection()
          Turns perspective on an off
 void doAction(java.lang.Object action)
          When the user has selected an action in the list return by getActions(), this method is called.
 java.util.List getActions()
          Returns a list of possible actions on this node.
 javax.swing.Icon getIcon()
          Utility method to specialize the swing tree renderer.
 long getRefreshPeriod()
           
static SceneNode getScene(ActiveNode node)
          Use this function to get the scene containing this node
 int getViewingMode()
           
 void init2DPosition(int posX, int posY)
          Initialize 2D rotation algorithm with the current position as origin.
 boolean isVisible()
           
 void notificationEnd(java.lang.Object referer)
          Register the scene as the unique listener for data events in the whole scene graph.
protected  void notifyChange()
           
 void notifyListeners()
          Call this when the scene changed, to notify all registered listeners
 ActiveNode pick(int posX, int posY)
          Selects a single pick at the given position.
protected  void propagateHighlightEvent(ActiveNode node, boolean on)
          Catch highlight events as this can cause repaint.
protected  void propagateInternalChangeEvent(ActiveNode node)
          Receive change notification events for objects in this scene and propagate them to this scene listeners.
 void remove()
          Removes this node from the parent list.
 void removeDirtyNode(DirtyNode node)
           
 void removeListener(SceneChangeListener dsl)
           
 void reset()
          Reset all values to default
 void restoreReferences(ActiveNode parent)
          Restore a serialized object to the scene graph.
 void restoreScene(PluginManager pm)
          Restore scene : subclasses can restore the scene once all ActiveNOde have been initialised
 void rotate2D(int newX, int newY)
          Does a rotation of the scene according to moves in a 2D coordinate system.
 boolean saveChildren()
          The scene/swing tree is serialized from root to leaf, hierachically.
 void setRefreshPeriod(long period)
           
 void setViewingMode(int viewingMode)
           
 void setVisible(boolean status)
           
 java.util.ArrayList toggleAllPicks(int posX, int posY)
          Adds or removes all picks between the given position and the last position, to the selected objects.
 java.util.ArrayList toggleSinglePick(int posX, int posY)
          Adds or removes a single pick at the given position to the selected objects.
 void translate2D(int newX, int newY)
          Does a translation of the scene according to moves in a 2D coordinate system.
 void zoom(int zoomIncrement)
          Zooms in or out of the scene according to the increment.
 void zoom2D(int newX, int newY)
          Uses the 2D increments in position to compute a zoom factor, then zooms the scene accordingly.
 
Methods inherited from class syn3d.nodes.GroupNode
getScene
 
Methods inherited from class syn3d.base.ActiveNode
addChild, findDescendantOfType, findDescendantOfType, get3DObject, getChildren, getName, getParent, highlight, notifyInternalChange, notifyStructuralChange, propagateAddChildEvent, propagateChangeNameEvent, propagateRemoveChildEvent, propagateStructuralChangeEvent, removeChild, removeNodeTree, removeNodeTreeFrom, setName, setParent, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ROTATION_MODE

public static final int ROTATION_MODE
In rotation mode, the user rotates the whole scene and can zoom in or out. Rotation mode is adapted to study one object. This is the default

See Also:
Constant Field Values

FLY_BY_MODE

public static final int FLY_BY_MODE
In fly-by mode, the user can freely move in the scene. This is more adapted for scenes with multiple objects or for objects with a complex internal geometry to study.

See Also:
Constant Field Values

viewingMode

protected int viewingMode

fileName

protected java.lang.String fileName
Current file name used for saving the scene


listeners

protected transient ListenerManager listeners
An array of UniverseChangeListener objects


dirtyNodes

protected transient ListenerManager dirtyNodes
An array of Dirty nodes to update before calling listeners The dirty nodes are then automatically removed from this array, as they're supposed to be cleaned up


anonymousSceneNumber

protected static int anonymousSceneNumber

timer

protected transient java.util.Timer timer
This timer is used to gather notify events and send them at a reasonable rate to 3D motors.


refreshPeriodChanged

protected boolean refreshPeriodChanged
True when the user has changed the period for refreshing the scene>


REFRESH_PERIOD

public static int REFRESH_PERIOD

refreshPeriod

protected long refreshPeriod

icon

protected static javax.swing.Icon icon
Constructor Detail

SceneNode

public SceneNode(ActiveNode parent)
Method Detail

getViewingMode

public int getViewingMode()
Returns:
Returns the viewingMode.

setViewingMode

public void setViewingMode(int viewingMode)
Parameters:
viewingMode - The viewingMode to set.

restoreScene

public void restoreScene(PluginManager pm)
Restore scene : subclasses can restore the scene once all ActiveNOde have been initialised


getScene

public static SceneNode getScene(ActiveNode node)
Use this function to get the scene containing this node

Parameters:
node - A node whose scene is unknown
Returns:
the scene in which this node resides, or null if this node is not attached to a scene

getActions

public java.util.List getActions()
Description copied from class: ActiveNode
Returns a list of possible actions on this node. Actions may be classified by categories using the "|" separator. Ex: a transform node may have the following actions: "Rotate|90° on X", "Rotate|180° on X", etc...

Overrides:
getActions in class ActiveNode
Returns:
an array of possible actions, or a null or empty array if this node doesn't handle any action

doAction

public void doAction(java.lang.Object action)
Description copied from class: ActiveNode
When the user has selected an action in the list return by getActions(), this method is called. The node should then do what it claims.

Overrides:
doAction in class ActiveNode
Parameters:
action - An action previously declared by the getActions method.

isVisible

public boolean isVisible()

setVisible

public void setVisible(boolean status)

setRefreshPeriod

public void setRefreshPeriod(long period)

getRefreshPeriod

public long getRefreshPeriod()

getIcon

public javax.swing.Icon getIcon()
Description copied from class: ActiveNode
Utility method to specialize the swing tree renderer. Give a look to your node, don't let it anonymous!

Overrides:
getIcon in class ActiveNode
Returns:
an Icon to display in the swing tree. May be shared along a node type class, or may even change according the the state of this node.

restoreReferences

public void restoreReferences(ActiveNode parent)
Description copied from class: ActiveNode
Restore a serialized object to the scene graph. The scene is restored from root to leaf, hierachically. A node can count on its parent beeing successfully deserialized, and its precisely the added value of this method to indicate to this object the parent it should attach to. This node is responsible for re-creating its children if it returned true in the save operation. See description of the saveChildren method. This method is called after this node was successfully de-serialized, to give it an occasion to restore anything it may have to with its parent (listeners, etc...). As with the plugin interface methode create, this method should ensure that the 3D object this nodes refers to is added to its parent children list in the underlying 3D model (Java3D, Xith3D). Default behavior is to set this node's parent field to the given value, but an implementor SHALL do what's necessary for the underlying 3D scene graph.

Overrides:
restoreReferences in class ActiveNode
Parameters:
parent - The active node to attach this one to once it has been successfully de-serialized

saveChildren

public boolean saveChildren()
Description copied from class: ActiveNode
The scene/swing tree is serialized from root to leaf, hierachically. A node can count on its parent beeing successfully serialized, and should not try to save its parent. On the other hand, if it is able to re-create the children upon reload it should return true and this branch is considered done. This is especially useful for nodes loaded from external scene object files. This method is called after the object was successfully serialized, to determine wheter or not continue in this tree branch.

Overrides:
saveChildren in class ActiveNode
Returns:
true if this object handles its children, false if it does not. Default is false

notificationEnd

public void notificationEnd(java.lang.Object referer)
Register the scene as the unique listener for data events in the whole scene graph. This way, all events coming from the same source are fusionned into a single event for the scene

Specified by:
notificationEnd in interface EndNotificationListener

notifyChange

protected void notifyChange()

remove

public void remove()
Removes this node from the parent list. Notifies the parents for structural change.

Overrides:
remove in class ActiveNode

addListener

public void addListener(SceneChangeListener dsl)

removeListener

public void removeListener(SceneChangeListener dsl)

addDirtyNode

public void addDirtyNode(DirtyNode node)

removeDirtyNode

public void removeDirtyNode(DirtyNode node)

notifyListeners

public void notifyListeners()
Call this when the scene changed, to notify all registered listeners


propagateInternalChangeEvent

protected void propagateInternalChangeEvent(ActiveNode node)
Receive change notification events for objects in this scene and propagate them to this scene listeners. Don't propagate the event to the root node, as it doesn't care for it.

Overrides:
propagateInternalChangeEvent in class ActiveNode

propagateHighlightEvent

protected void propagateHighlightEvent(ActiveNode node,
                                       boolean on)
Catch highlight events as this can cause repaint. This is just a hook so the Root can notify its own listeners

Overrides:
propagateHighlightEvent in class ActiveNode

init2DPosition

public void init2DPosition(int posX,
                           int posY)
Initialize 2D rotation algorithm with the current position as origin. Typically, this is related to mouse positions in X and Y.


rotate2D

public void rotate2D(int newX,
                     int newY)
Does a rotation of the scene according to moves in a 2D coordinate system. Use init2DPosition to position an origin, then do as many rotate2D as required.

Parameters:
newX - The new X position in 2D, typically a mouse position
newY - The new Y position in 2D, typically a mouse position

translate2D

public void translate2D(int newX,
                        int newY)
Does a translation of the scene according to moves in a 2D coordinate system. Use init2DPosition to position an origin, then do as many translate2D as required.

Parameters:
newX - The new X position in 2D, typically a mouse position
newY - The new Y position in 2D, typically a mouse position

zoom2D

public void zoom2D(int newX,
                   int newY)
Uses the 2D increments in position to compute a zoom factor, then zooms the scene accordingly.

Parameters:
newX - The new X position in 2D, typically a mouse position
newY - The new Y position in 2D, typically a mouse position

zoom

public void zoom(int zoomIncrement)
Zooms in or out of the scene according to the increment. This is an arbitrary algorithm to help create correct zoom factors. You could use setZoomFactor and then update the zoom matrix directly, with the same effect.
The added value of this function is to provide a relative and easy to manipulate way to zoom in or out, with increments like +1 or -1 for small zooms, and +10 and -10 for greater zooms, etc...

Parameters:
zoomIncrement - A value typically 1 or -1, but which can be greater for fast zooms. Positive values zoom in, negative values zoom out.

changeProjection

public void changeProjection()
Turns perspective on an off


reset

public void reset()
Reset all values to default


autoZoom

public void autoZoom()
Auto zooms the scene out of all objects


toggleSinglePick

public java.util.ArrayList toggleSinglePick(int posX,
                                            int posY)
Adds or removes a single pick at the given position to the selected objects.

Parameters:
posX - the 2D X position where to do the picking
posY - the 2D Y position where to do the picking
Returns:
Returns the current selection, possibly an empy array
See Also:
ActiveNode.higlight(boolean,Object)

toggleAllPicks

public java.util.ArrayList toggleAllPicks(int posX,
                                          int posY)
Adds or removes all picks between the given position and the last position, to the selected objects.

Parameters:
posX - the 2D X position defining a region with the last position. All objects in this region should be picked.
posX - the 2D Y position defining a region with the last position. All objects in this region should be picked.
Returns:
Returns the current selection, possibly an empy array
See Also:
ActiveNode.higlight(boolean,Object)

pick

public ActiveNode pick(int posX,
                       int posY)
Selects a single pick at the given position.

Parameters:
posX - the 2D X position where to do the picking
posY - the 2D Y position where to do the picking
Returns:
Returns the picked node or possibly a null object if there was nothing to pick at this position
See Also:
ActiveNode.higlight(boolean,Object)