com.electrotank.electroserver5.client.events
Class EventDispatcher<I extends Enum,E extends Event>

java.lang.Object
  extended by com.electrotank.electroserver5.client.events.EventDispatcher<I,E>
Type Parameters:
I - The enumeration that will identify specific events.
E - The type of event that this dispatcher will handle.
Direct Known Subclasses:
Connection, EsEngine

public class EventDispatcher<I extends Enum,E extends Event>
extends Object

Provides a developer friendly method of handling event dispatching, similar to the way it is done in ActionScript 3. Using this class and it's semantics for event dispatching instead of traditional Java EventHandlers allows the developer to avoid casting events, allows multiple identifiers for a single event type to be handled by one dispatcher and adds support for event priority. This type of event dispatching also uses methods as targets for events instead of interfaces, so no anonymous inner classes or adapters are needed.


Constructor Summary
EventDispatcher()
           
 
Method Summary
protected  void addEventListener(I eventIdentifier, Object target, Method method)
           
protected  void addEventListener(I eventIdentifier, Object target, Method method, int priority)
           
 void addEventListener(I eventIdentifier, Object target, String method)
           
 void addEventListener(I eventIdentifier, Object target, String method, Class methodArgType)
           
 void addEventListener(I eventIdentifier, Object target, String method, Class methodArgType, int priority)
          Adds an event listener that will be notified on event dispatches.
 void addEventListener(I eventIdentifier, Object target, String method, int priority)
           
 void dispatchEvent(E event)
           
static Class<?> getClass(Type type)
          Get the underlying class for a type, or null if the type is a variable type.
static
<T> List<Class<?>>
getTypeArguments(Class<T> baseClass, Class<? extends T> childClass)
          Get the actual type arguments a child class has used to extend a generic base class.
 void removeEventListener(I eventIdentifier, Object target, String method)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventDispatcher

public EventDispatcher()
Method Detail

addEventListener

public void addEventListener(I eventIdentifier,
                             Object target,
                             String method,
                             Class methodArgType,
                             int priority)
Adds an event listener that will be notified on event dispatches.

Parameters:
eventIdentifier - Events with this type will be dispatched to this listener.
target - The Object that will receive the event.
method - The name of a method on target that will receive the event.
methodArgType - The type of event that is expected to be received. Supplying this allows the developer to avoid a cast on the listener.
priority - Notification priority. Higher priorities are notified before lower.

addEventListener

public void addEventListener(I eventIdentifier,
                             Object target,
                             String method,
                             Class methodArgType)

addEventListener

public void addEventListener(I eventIdentifier,
                             Object target,
                             String method,
                             int priority)

addEventListener

public void addEventListener(I eventIdentifier,
                             Object target,
                             String method)

addEventListener

protected void addEventListener(I eventIdentifier,
                                Object target,
                                Method method)

addEventListener

protected void addEventListener(I eventIdentifier,
                                Object target,
                                Method method,
                                int priority)

removeEventListener

public void removeEventListener(I eventIdentifier,
                                Object target,
                                String method)

dispatchEvent

public void dispatchEvent(E event)

getClass

public static Class<?> getClass(Type type)
Get the underlying class for a type, or null if the type is a variable type.

Parameters:
type - the type
Returns:
the underlying class

getTypeArguments

public static <T> List<Class<?>> getTypeArguments(Class<T> baseClass,
                                                  Class<? extends T> childClass)
Get the actual type arguments a child class has used to extend a generic base class.

Parameters:
baseClass - the base class
childClass - the child class
Returns:
a list of the raw classes for the actual type arguments.


Copyright © 2007-2010 Electrotank, Inc. All Rights Reserved.