net.jinx.action
Class Scene

java.lang.Object
  extended by net.jinx.action.Actor
      extended by net.jinx.action.Scene

public class Scene
extends Actor

Scene is an Actor that contains other Actors. SceneListener objects can be added, allowing other objects to be notified when Actors are added or removed.

API Stability: Beta.


Constructor Summary
Scene()
           
Scene(java.lang.String name)
          Constructs a Scene.
 
Method Summary
 void addActor(Actor actor)
          Adds an Actor to this Scene.
 void addSceneListener(SceneListener listener)
          Adds a SceneListener to the Scene.
protected  void deliverEvent(java.lang.String target, ActorEvent event)
          Delivers an ActorEvent to one or all of the Actors in this Scene.
protected  void eventDeliveryException(java.lang.Exception e)
          Called when an Exception is thrown in the deliverEvent(String, ActorEvent) method during the delivery of of an ActorEvent.
 Actor getActor(java.lang.String name)
          Provides the Actor with the given name.
 java.util.Iterator iterator()
          Provides an Iterator that allows you to iterate over all the Actors in the Scene.
protected  void processEvent(ActorEvent event)
          Processes Clock related events and sends them to this Scene's children.
 void removeActor(Actor actor)
          Removes an Actor from this Scene.
 void removeActor(java.lang.String name)
          Removes an Actor from this Scene, using it's name.
 void removeSceneListener(SceneListener listener)
          Removes a SceneListener from the Scene.
 void replace(Scene scene)
          Replaces this Scene with scene, moving Actor and SceneListener Objects over from one to the other.
 
Methods inherited from class net.jinx.action.Actor
checkAllowAdd, getName, getOwner, hashCode, ownerChanged, sendEvent, sendEvent, sendEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scene

public Scene()

Scene

public Scene(java.lang.String name)
Constructs a Scene.

Parameters:
name - the name that this Scene will be known by. This cannot be null.
Method Detail

addSceneListener

public void addSceneListener(SceneListener listener)
Adds a SceneListener to the Scene.

Parameters:
listener - the SceneListener to add.

removeSceneListener

public void removeSceneListener(SceneListener listener)
Removes a SceneListener from the Scene.

Parameters:
listener - the SceneListener to remove.

iterator

public java.util.Iterator iterator()
Provides an Iterator that allows you to iterate over all the Actors in the Scene. The Collection backing the Iterator is an immutable clone of the Collection backing this Scene, allowing you to freely add and remove Actors from the Scene without causing throwing ConcurrentModificationException.

Returns:
the Iterator.

addActor

public void addActor(Actor actor)
Adds an Actor to this Scene. This will remove the Actor from it's current owner, if it has one.

Parameters:
actor - the Actor to add.
Throws:
java.lang.IllegalArgumentException - if an attempt is made to add a Scene to itself or actor itself has rejected being placed in this Scene.

removeActor

public void removeActor(Actor actor)
Removes an Actor from this Scene. This does nothing if the Actor isn't part of the Scene already.

Parameters:
actor - the Actor to remove.

removeActor

public void removeActor(java.lang.String name)
Removes an Actor from this Scene, using it's name. This does nothing if the Actor isn't part of the Scene already.

Parameters:
name - the name of the Actor to remove.

getActor

public Actor getActor(java.lang.String name)
Provides the Actor with the given name.

Parameters:
name - the name of the Actor.
Returns:
the Actor; this will be null if there is no Actor with that name.

deliverEvent

protected void deliverEvent(java.lang.String target,
                            ActorEvent event)
Delivers an ActorEvent to one or all of the Actors in this Scene.

Parameters:
target - the name of the Actor to send the event to. If this is "*", then event will be delivered to all of the Actors in the scene.
event - the ActorEvent to deliver.

eventDeliveryException

protected void eventDeliveryException(java.lang.Exception e)
Called when an Exception is thrown in the deliverEvent(String, ActorEvent) method during the delivery of of an ActorEvent. The default action is to print a stack trace to System.err.

Parameters:
e - the Exception that was thrown.

processEvent

protected void processEvent(ActorEvent event)
Processes Clock related events and sends them to this Scene's children. This is done so that there is only one Clock for an entire Scene and all it's sub-Scenes.

Specified by:
processEvent in class Actor
Parameters:
event - the ActorEvent to process.

replace

public void replace(Scene scene)
Replaces this Scene with scene, moving Actor and SceneListener Objects over from one to the other. This even takes care of removing this Scene from it's owner and puts scene in it's place.

Parameters:
scene - the Scene object to replace this one with.