net.jinx.action
Class Actor

java.lang.Object
  extended by net.jinx.action.Actor
Direct Known Subclasses:
ActorView, AudioRenderer, Clock, Scene, VideoRenderer, VisibleActor

public abstract class Actor
extends java.lang.Object

Actor serves as the abstract base class of anything that has a presence of any kind in a Scene. An actor may be visible, audible, or even something non-sensory that has influence on the Scene or other Actors in it.

The primary funcionality of this class is to send and receive events. All Actors must have an owner to do this. The owner is a Scene object and is used to pass events between Actors.

API Stability: Beta.


Constructor Summary
Actor(java.lang.String name)
          Constructs an Actor.
 
Method Summary
protected  void checkAllowAdd(Scene scene)
          Provides a way for an Actor to determine if it can be added to a particular Scene.
 java.lang.String getName()
          Provides the name of this Actor.
 Scene getOwner()
          Provides the Scene that owns this Actor.
 int hashCode()
           
protected  void ownerChanged(Scene owner)
          This method does nothing, but is called when this Actor is added to a Scene.
protected abstract  void processEvent(ActorEvent event)
          Processes an ActorEvent.
protected  void sendEvent(Actor target, ActorEvent event)
          Sends an ActorEvent directly to the target Actor.
protected  void sendEvent(java.util.Collection targets, ActorEvent event)
          Sends an ActorEvent to as many of the targets in the Collection as possible.
protected  void sendEvent(java.lang.String target, ActorEvent event)
          Sends an ActorEvent to the target in this Actor's Scene.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Actor

public Actor(java.lang.String name)
Constructs an Actor.

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

getName

public final java.lang.String getName()
Provides the name of this Actor.

Returns:
the name as a String.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

checkAllowAdd

protected void checkAllowAdd(Scene scene)
Provides a way for an Actor to determine if it can be added to a particular Scene. This method does nothing. Sub-classes may override this to reject certain Scene placements by throwing an IllegalArgumentException.

Throws:
java.lang.IllegalArgumentException - if adding this Actor to scene is not acceptable.

ownerChanged

protected void ownerChanged(Scene owner)
This method does nothing, but is called when this Actor is added to a Scene. Essentially, this method is a place holder that can be overriden by sub-classes that need to be aware of their movements from one Scene to another.


getOwner

public final Scene getOwner()
Provides the Scene that owns this Actor. If this is null, then this Actor is not part of a Scene.

Returns:
the Scene that owns this Actor.

sendEvent

protected void sendEvent(java.lang.String target,
                         ActorEvent event)
Sends an ActorEvent to the target in this Actor's Scene.

Parameters:
target - the name of the Actor to send the event to. If this is "*" it means the message sgould be delivered to all Actors in the Scene.
event - the ActorEvent to send. This will be source stamped before it is sent.
Throws:
java.lang.NullPointerException - if this Actor has no owner.

sendEvent

protected void sendEvent(Actor target,
                         ActorEvent event)
Sends an ActorEvent directly to the target Actor.

Parameters:
target - the Actor to send the event to.
event - the ActorEvent to send. This will be source stamped before it is sent.

sendEvent

protected void sendEvent(java.util.Collection targets,
                         ActorEvent event)
Sends an ActorEvent to as many of the targets in the Collection as possible.

Parameters:
targets - a java.util.Collection containing String and Actor objects. Anything in it that isn't one of those is ignored.
event - the ActorEvent to send. This will be source stamped before it is sent.

processEvent

protected abstract void processEvent(ActorEvent event)
Processes an ActorEvent. This is what most Actor objects exist for.

Parameters:
event - the ActorEvent to process.