org.jdesktop.wonderland.client.input
Class EventListenerBaseImpl

java.lang.Object
  extended by org.jdesktop.mtgame.EntityComponent
      extended by org.jdesktop.mtgame.ProcessorComponent
          extended by org.jdesktop.wonderland.client.input.EventListenerBaseImpl
All Implemented Interfaces:
EventListener
Direct Known Subclasses:
EventClassListener

public class EventListenerBaseImpl
extends org.jdesktop.mtgame.ProcessorComponent
implements EventListener

The base implementation of a Wonderland event listener. Almost all custom event listeners should extend this class.

Author:
deronj

Field Summary
protected  boolean enabled
          Whether the listener is enabled.
 
Constructor Summary
EventListenerBaseImpl()
           
 
Method Summary
 void addToEntity(org.jdesktop.mtgame.Entity entity)
          Add this event listener to the given entity.
 void commit(org.jdesktop.mtgame.ProcessorArmingCollection collection)
          INTERNAL ONLY
Called in the render loop to allow this collection to commit the compute() calculations to alter the scene graph.
 void commitEvent(Event event)
          Called after computeEvent has been called for this event listener.
 void compute(org.jdesktop.mtgame.ProcessorArmingCollection collection)
          INTERNAL ONLY.
 void computeEvent(Event event)
          The implementation of this method should determine how to change the world based on the given event.
 boolean consumesEvent(Event event)
          Returns whether this event listener currently wishes to receive the given event.
 void initialize()
          
 boolean isEnabled()
          Returns whether this event listener is currently enabled.
 boolean isListeningForEntity(org.jdesktop.mtgame.Entity entity)
          Returns true if this listener is currently attached to the given entity.
 void postEvent(Event event)
          INTERNAL ONLY.
 boolean propagatesToParent(Event event)
          Returns whether the event should also be propagated to the event entity's parent for possible delivery.
 void removeFromEntity(org.jdesktop.mtgame.Entity entity)
          Remove this event listener from the given entity.
 void setEnabled(boolean enable)
          Enable or disable this event listener.
 
Methods inherited from class org.jdesktop.mtgame.ProcessorComponent
addToChain, getArmingCondition, getCurrentTriggerCollection, getLocation, getLODLevel, getRunInRenderer, getSwingSafe, removeFromChain, setArmingCondition, setLocation, setRunInRenderer, setSwingSafe
 
Methods inherited from class org.jdesktop.mtgame.EntityComponent
getEntity, setEntity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enabled

protected boolean enabled
Whether the listener is enabled.

Constructor Detail

EventListenerBaseImpl

public EventListenerBaseImpl()
Method Detail

isEnabled

public boolean isEnabled()
Returns whether this event listener is currently enabled. Note: A listener is enabled by default.

Specified by:
isEnabled in interface EventListener
Overrides:
isEnabled in class org.jdesktop.mtgame.ProcessorComponent

setEnabled

public void setEnabled(boolean enable)
Enable or disable this event listener.

Note: Disabling the listener deletes any pending posted events which have not yet been delivered to the listeners.

Specified by:
setEnabled in interface EventListener
Overrides:
setEnabled in class org.jdesktop.mtgame.ProcessorComponent
Parameters:
enable - Whether the event listener should be enabled.

consumesEvent

public boolean consumesEvent(Event event)
Returns whether this event listener currently wishes to receive the given event. Here is where the decision to receive different types of events occurs. The input system calls this method only if the listener is enabled. Computations in this method should be kept reasonably short as they occur in AWT Event Dispatch thread.

Example Usage: User interface buttons with rounded edges can use a simple quad for its geometry and use a transparent texture to achieve the rounded appearance. In order to make sure that the portions of the quad which are transparent are not input sensitive we could define consumesEvent to lookup the hit texel in the texture and not consume the event if the hit texel is transparent.

Note on subclassing: unless a subclass overrides this method, true is always returned.

Specified by:
consumesEvent in interface EventListener
Parameters:
event - The event in question.

propagatesToParent

public boolean propagatesToParent(Event event)
Returns whether the event should also be propagated to the event entity's parent for possible delivery. If any listener on an entity prevents propagation to parents, the event will not be delivered to the entity's parents or to any global listeners. Note that other listeners on the same entity will receive the event.

This method is only called if consumesEvent() returns true for the given event

Computations in this method should be kept reasonably short as they occur in the AWT Event Dispatch thread. This method is only called for entity-attached event listeners.

Note on subclassing: unless a subclass overrides this method, true is always returned.

Specified by:
propagatesToParent in interface EventListener
Parameters:
event - The event in question.

computeEvent

public void computeEvent(Event event)
The implementation of this method should determine how to change the world based on the given event.

Note: It is guaranteed that when computeEvent is called for a particular event that commitEvent will be called sometime after.

Specified by:
computeEvent in interface EventListener
Parameters:
event - The event in question.

commitEvent

public void commitEvent(Event event)
Called after computeEvent has been called for this event listener. The implementation of this method should apply to the world those changes which were determined in computeEvent.

Note: It is guaranteed that a call to commitEvent for an event is always preceded by a call to commitEvent for that event.

Specified by:
commitEvent in interface EventListener
Parameters:
event - The event which was computed.

addToEntity

public void addToEntity(org.jdesktop.mtgame.Entity entity)
Add this event listener to the given entity. An given event listener instance may be only be added once to an entity. Once an event listener instance has been added to an entity, subsequent attempts to add the entity will be ignored. However, a given event listener instance may be added to multiple entities.

Note: It is not a good idea to call this from inside EventListener.computeEvent function. However, it is okay to call this from inside EventListener.commitEvent function if necessary.

Specified by:
addToEntity in interface EventListener
Parameters:
entity - The entity to which to attach this event listener.

removeFromEntity

public void removeFromEntity(org.jdesktop.mtgame.Entity entity)
Remove this event listener from the given entity.

Note: It is not a good idea to call this from inside EventListener.computeEvent function. However, it is okay to call this from inside EventListener.commitEvent function if necessary.

Specified by:
removeFromEntity in interface EventListener
Parameters:
entity - The entity to which to attach this event listener.

isListeningForEntity

public boolean isListeningForEntity(org.jdesktop.mtgame.Entity entity)
Returns true if this listener is currently attached to the given entity.

Specified by:
isListeningForEntity in interface EventListener
Parameters:
entity - The entity to which to attach this event listener.

postEvent

public void postEvent(Event event)
INTERNAL ONLY.
Deliver the given event to this collection. This is only ever called by the EventDeliverer.

Specified by:
postEvent in interface EventListener

initialize

public void initialize()

Specified by:
initialize in class org.jdesktop.mtgame.ProcessorComponent

compute

public void compute(org.jdesktop.mtgame.ProcessorArmingCollection collection)
INTERNAL ONLY.
Called when there is new event in the input queue.

Specified by:
compute in class org.jdesktop.mtgame.ProcessorComponent

commit

public void commit(org.jdesktop.mtgame.ProcessorArmingCollection collection)
INTERNAL ONLY
Called in the render loop to allow this collection to commit the compute() calculations to alter the scene graph.

Specified by:
commit in class org.jdesktop.mtgame.ProcessorComponent


Open Wonderland - http://openwonderland.org