org.jdesktop.wonderland.client.input
Class EventDistributor

java.lang.Object
  extended by org.jdesktop.wonderland.client.input.EventDistributor
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
EventDistributor3D

public abstract class EventDistributor
extends java.lang.Object
implements java.lang.Runnable

The abstract base class for an Event Distributor singleton. The Entity Distributor is part of the input subsystem which distributes events throughout the scene graph according to the information provided by the entity event listeners. It also supports a set of global event listeners. This are independent of any events. Events are always tried to be delivered to the global event listeners. In general, the user cannot make any assumptions about the order in which individual event listeners methods are called.

Author:
deronj

Field Summary
protected  java.util.HashMap<java.lang.Class,java.util.HashSet<org.jdesktop.mtgame.Entity>> focusSets
          The focus sets for the various event classes.
 
Constructor Summary
EventDistributor()
           
 
Method Summary
 void addGlobalEventListener(EventListener listener)
          Add an event listener to be tried once per event.
protected abstract  void processEvent(Event event, org.jdesktop.mtgame.PickInfo destPickInfo, org.jdesktop.mtgame.PickInfo hitPickInfo)
          The responsibility for determining how to process individual event types is delegated to the subclass.
protected  void processFocusChangeEvent(InputManager.FocusChange[] changes)
          Update the focus sets based on a change event which comes through the event queue.
protected abstract  void processPostEventToEntity(Event event, org.jdesktop.mtgame.Entity entity)
          The responsibility for determining how to process an event posted to a specific entity is delegated to the subclass.
 void removeGlobalEventListener(EventListener listener)
          Remove this global event listener.
 void run()
          The run loop of the thread.
protected  void start()
           
protected  void tryGlobalListeners(Event event)
          Traverse the list of global listeners to see whether the event should be delivered to any of them.
protected  boolean tryListenersForEntity(org.jdesktop.mtgame.Entity entity, Event event)
          See if any of the enabled event listeners for the given entity are willing to consume the given event.
protected  boolean tryListenersForEntityAndParents(org.jdesktop.mtgame.Entity entity, Event event)
          Traverse the entity parent chain (starting with the given entity) to see if the event should be delivered to any of their listeners.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

focusSets

protected java.util.HashMap<java.lang.Class,java.util.HashSet<org.jdesktop.mtgame.Entity>> focusSets
The focus sets for the various event classes.

Constructor Detail

EventDistributor

public EventDistributor()
Method Detail

start

protected void start()

run

public void run()
The run loop of the thread.

Specified by:
run in interface java.lang.Runnable

processEvent

protected abstract void processEvent(Event event,
                                     org.jdesktop.mtgame.PickInfo destPickInfo,
                                     org.jdesktop.mtgame.PickInfo hitPickInfo)
The responsibility for determining how to process individual event types is delegated to the subclass.

Parameters:
event - The event to try to deliver to event listeners.
destPickInfo - The destination pick info associated with the event.
hitPickInfo - The hit pick info associated with the event.

processPostEventToEntity

protected abstract void processPostEventToEntity(Event event,
                                                 org.jdesktop.mtgame.Entity entity)
The responsibility for determining how to process an event posted to a specific entity is delegated to the subclass.

Parameters:
event - The event to try to deliver to event listeners.
entity - The entity associated with the event.

tryGlobalListeners

protected void tryGlobalListeners(Event event)
Traverse the list of global listeners to see whether the event should be delivered to any of them. Post the event to all willing consumers.


tryListenersForEntity

protected boolean tryListenersForEntity(org.jdesktop.mtgame.Entity entity,
                                        Event event)
See if any of the enabled event listeners for the given entity are willing to consume the given event. Post the event to the first willing consumer. Returns true if the event was consumed, and false if not.

Parameters:
param - entity the entity to try listeners for
event - the event to try

tryListenersForEntityAndParents

protected boolean tryListenersForEntityAndParents(org.jdesktop.mtgame.Entity entity,
                                                  Event event)
Traverse the entity parent chain (starting with the given entity) to see if the event should be delivered to any of their listeners. Continue the search until the event is consumed or no more parents are found. Post the event to willing consumers.

Parameters:
entity - the entity to start with
event - the event to post
Returns:
true if the event should go to global listeners, or false if not

addGlobalEventListener

public void addGlobalEventListener(EventListener listener)
Add an event listener to be tried once per event. This global listener can be added only once. Subsequent attempts to add it will be ignored.

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.

Parameters:
listener - The global event listener to be added.

removeGlobalEventListener

public void removeGlobalEventListener(EventListener listener)
Remove this global event listener.

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.

Parameters:
listener - The global event listener to be removed.

processFocusChangeEvent

protected void processFocusChangeEvent(InputManager.FocusChange[] changes)
Update the focus sets based on a change event which comes through the event queue. Called at FocusChangeEvent time.

Parameters:
changes - An array of the changes to apply to the focus sets.


Open Wonderland - http://openwonderland.org