syn3d.base
Class ActiveNode

java.lang.Object
  extended by syn3d.base.ActiveNode
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BuilderNode, GroupNode, LoaderNode, RootNode, ShapeNode, SynopticViewNode, ViewNode, XYZResultNode

public abstract class ActiveNode
extends java.lang.Object
implements java.io.Serializable

Active nodes are a the plugin interface to build the 3D scene graph, which is itself mapped to the swing tree. They can represent any object for the scene, be it a Shape3D, a Transform group or an ambiant light. As their name suggests, they also bring their own possible actions. For example, a rotation transform may declare an action to rotate 90° on X axis, and so on. A switch group may declare actions to set its children visible or not. Etc... Another reason why this interface is neither the swing nor the 3D node, is for serialization. See the save/restore methods for comments.

Author:
nicolas brodu
See Also:
Serialized Form

Field Summary
protected  java.util.ArrayList children
           
protected  java.lang.String name
          Name of this node.
protected  ActiveNode parent
           
 
Constructor Summary
protected ActiveNode()
           
  ActiveNode(ActiveNode parent)
           
 
Method Summary
protected  void addChild(ActiveNode child)
          Internal use function.
 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.ArrayList findDescendantOfType(java.lang.Class c)
          Utility method to recursively find all descendant of a given type
 java.util.ArrayList findDescendantOfType(java.lang.Class c, java.util.ArrayList array)
          Utility method to recursively find all descendant of a given type.
 java.lang.Object get3DObject()
          Returns the 3D object that this node refers to.
 java.util.List getActions()
          Returns a list of possible actions on this node.
 java.util.ArrayList getChildren()
           
 javax.swing.Icon getIcon()
          Utility method to specialize the swing tree renderer.
 java.lang.String getName()
           
 ActiveNode getParent()
           
 void highlight(boolean on, java.lang.Object parameter)
          Highlights this node some way.
 void notifyInternalChange()
          Notify the system that this node has changed and the scene needs to be re-built
 void notifyStructuralChange()
          Notify the system that this node structure has changed and the tree needs to be re-built in addition to the scene
protected  void propagateAddChildEvent(ActiveNode child)
           
protected  void propagateChangeNameEvent(ActiveNode node)
           
protected  void propagateHighlightEvent(ActiveNode node, boolean on)
           
protected  void propagateInternalChangeEvent(ActiveNode node)
           
protected  void propagateRemoveChildEvent(ActiveNode child)
           
protected  void propagateStructuralChangeEvent(ActiveNode node)
           
 void remove()
          Removes this node from the parent list.
protected  void removeChild(ActiveNode child)
          Internal use function.
 void removeNodeTree()
          Delete the node tree from the current ActiveNode
protected  void removeNodeTreeFrom(ActiveNode node)
          Delete the node tree from the node
 void restoreReferences(ActiveNode parent)
          Restore a serialized object to the scene graph.
 boolean saveChildren()
          The scene/swing tree is serialized from root to leaf, hierachically.
 void setName(java.lang.String name)
           
 void setParent(ActiveNode parent)
           
 java.lang.String toString()
          Returns the name of this node if it is not null, or Object.toString() otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

protected transient ActiveNode parent

children

protected transient java.util.ArrayList children

name

protected java.lang.String name
Name of this node. Default is null, in which case Object.toString() is returned in toString(). Otherwise, the name is returned by this method This field is serialized.

Constructor Detail

ActiveNode

protected ActiveNode()

ActiveNode

public ActiveNode(ActiveNode parent)
Method Detail

setParent

public void setParent(ActiveNode parent)

remove

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


addChild

protected void addChild(ActiveNode child)
Internal use function. Overload this to do some action when a new child is added to this node Don't forget to call super implementation Beware : this function is called in the child constructor, so don't rely on the child beeing fully set up yet


removeChild

protected void removeChild(ActiveNode child)
Internal use function. Overload this to do some action when a new child is removed from this node Don't forget to call super implementation


propagateAddChildEvent

protected void propagateAddChildEvent(ActiveNode child)

propagateRemoveChildEvent

protected void propagateRemoveChildEvent(ActiveNode child)

propagateChangeNameEvent

protected void propagateChangeNameEvent(ActiveNode node)

propagateHighlightEvent

protected void propagateHighlightEvent(ActiveNode node,
                                       boolean on)

propagateInternalChangeEvent

protected void propagateInternalChangeEvent(ActiveNode node)

propagateStructuralChangeEvent

protected void propagateStructuralChangeEvent(ActiveNode node)

notifyInternalChange

public void notifyInternalChange()
Notify the system that this node has changed and the scene needs to be re-built


notifyStructuralChange

public void notifyStructuralChange()
Notify the system that this node structure has changed and the tree needs to be re-built in addition to the scene


getName

public java.lang.String getName()
Returns:
Returns the name.

setName

public void setName(java.lang.String name)
Parameters:
name - The name to set.

toString

public java.lang.String toString()
Returns the name of this node if it is not null, or Object.toString() otherwise. Note: getName() is used to get the name, so subclasses only need to everload that method, if needed.

Overrides:
toString in class java.lang.Object

getChildren

public java.util.ArrayList getChildren()

get3DObject

public java.lang.Object get3DObject()
Returns the 3D object that this node refers to. The object may depend on the 3D model used (Xith3D, Java3D) This object was previously created in the plugin create method, or in the loadTo method during de-serialization.

Returns:
the Object used for the scene graph, which probably depends on the underlying 3D architecture. This can be used on a parent node in the plugin canCreate method to check for this architecture.

getIcon

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

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.

getActions

public java.util.List getActions()
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...

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)
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.

Parameters:
action - An action previously declared by the getActions method.

saveChildren

public boolean saveChildren()
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.

Returns:
true if this object handles its children, false if it does not. Default is false

restoreReferences

public void restoreReferences(ActiveNode parent)
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.

Parameters:
parent - The active node to attach this one to once it has been successfully de-serialized

getParent

public ActiveNode getParent()
Returns:
Returns the parent of this node, as specified at creation or de-serialization time.

highlight

public void highlight(boolean on,
                      java.lang.Object parameter)
Highlights this node some way. It's up to the underlying 3D model to decide what it means. This is an optional operation. Highlighting may occur when the user selects a node in the tree, for example, or when picking an object on a scene view. Note for subclasses : please call the super implementation for event propagation.

Parameters:
on - true indicates to highlight this node, false to revert it back to normal
parameter - A parameter set from the 3D underlying model in case of a picking operation, or the node's 3D object in case of a user selection in the Scene Tree

findDescendantOfType

public java.util.ArrayList findDescendantOfType(java.lang.Class c)
Utility method to recursively find all descendant of a given type

Parameters:
c - The class to look for
Returns:
An ArrayList of children, potentially empty but not null

findDescendantOfType

public java.util.ArrayList findDescendantOfType(java.lang.Class c,
                                                java.util.ArrayList array)
Utility method to recursively find all descendant of a given type. The node found will be added to the array

Parameters:
c - The class to look for
array - if not null, use this array to return the children into
Returns:
An ArrayList of children, potentially empty but not null

removeNodeTree

public void removeNodeTree()
Delete the node tree from the current ActiveNode


removeNodeTreeFrom

protected void removeNodeTreeFrom(ActiveNode node)
Delete the node tree from the node