de.enough.polish.event
Class EventManager

java.lang.Object
  extended by de.enough.polish.event.EventManager

public class EventManager
extends Object

Manages events and forwards them to appropriate listeners

Copyright Enough Software 2007 - 2010

 history
        Sep 15, 2007 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
static String EVENT_DEFOCUS
          name of the unfocussed state event
static String EVENT_FOCUS
          name of the focussed state event
static String EVENT_HIDE
          name of the hide notify event
static String EVENT_KEY_HANDLED
          event when a key press or release event was handled
static String EVENT_MENU_CLOSE
          event when a commands menu is clpsed
static String EVENT_MENU_OPEN
          event when a commands menu is opened
static String EVENT_POINTER_HANDLED
          event when a pointer press or release event was handled
static String EVENT_PRESS
          name of the pressed state event
static String EVENT_SHOW
          name of the show notify event
static String EVENT_SHOW_FIRST_TIME
          name of the show notify event when a UI element is shown for the first time
static String EVENT_UNPRESS
          name of the pressed state event
static String EVENT_UNVISIT
          event when the visited stated of an item is rolled back
static String EVENT_VALUE_CHANGE
          name of the event when a value of an item is changed
static String EVENT_VISIT
          event when an item has been visited
 
Method Summary
 void addEventListener(String eventName, EventListener listener)
          Adds a event listener.
static EventManager createNewInstance()
          Allows users to create a new EventManager instance.
static void fireEvent(String name, Object source, Object data)
          Forwards the specified event to any listeners.
static EventManager getInstance()
          Retrieves the instance of the event manager (singleton pattern).
 void remapEvent(String eventName, Object alternativeSource)
          Remaps the named event to the specified alternative source.
 void removeAllRemappings()
          Removes all remappings
 void removeRemapEvent(String eventName)
          Removes all remappings for the specified event
 void removeRemapEvent(String eventName, Object alternativeSource)
          Removes a single remapping for the specified event
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EVENT_PRESS

public static final String EVENT_PRESS
name of the pressed state event

See Also:
Constant Field Values

EVENT_UNPRESS

public static final String EVENT_UNPRESS
name of the pressed state event

See Also:
Constant Field Values

EVENT_FOCUS

public static final String EVENT_FOCUS
name of the focussed state event

See Also:
Constant Field Values

EVENT_DEFOCUS

public static final String EVENT_DEFOCUS
name of the unfocussed state event

See Also:
Constant Field Values

EVENT_SHOW

public static final String EVENT_SHOW
name of the show notify event

See Also:
Constant Field Values

EVENT_SHOW_FIRST_TIME

public static final String EVENT_SHOW_FIRST_TIME
name of the show notify event when a UI element is shown for the first time

See Also:
Constant Field Values

EVENT_HIDE

public static final String EVENT_HIDE
name of the hide notify event

See Also:
Constant Field Values

EVENT_VALUE_CHANGE

public static final String EVENT_VALUE_CHANGE
name of the event when a value of an item is changed

See Also:
Constant Field Values

EVENT_MENU_CLOSE

public static final String EVENT_MENU_CLOSE
event when a commands menu is clpsed

See Also:
Constant Field Values

EVENT_MENU_OPEN

public static final String EVENT_MENU_OPEN
event when a commands menu is opened

See Also:
Constant Field Values

EVENT_VISIT

public static final String EVENT_VISIT
event when an item has been visited

See Also:
Constant Field Values

EVENT_UNVISIT

public static final String EVENT_UNVISIT
event when the visited stated of an item is rolled back

See Also:
Constant Field Values

EVENT_POINTER_HANDLED

public static final String EVENT_POINTER_HANDLED
event when a pointer press or release event was handled

See Also:
Constant Field Values

EVENT_KEY_HANDLED

public static final String EVENT_KEY_HANDLED
event when a key press or release event was handled

See Also:
Constant Field Values
Method Detail

getInstance

public static EventManager getInstance()
Retrieves the instance of the event manager (singleton pattern).

Returns:
the instance of the event manager (singleton pattern).

createNewInstance

public static EventManager createNewInstance()
Allows users to create a new EventManager instance. This might be used to process a completely set of different events and listeners in a separate manner.

Returns:
a new EventManager

fireEvent

public static void fireEvent(String name,
                             Object source,
                             Object data)
Forwards the specified event to any listeners.

Parameters:
name - the name of the event, e.g. EVENT_PRESS
source - the source of the event, for example an item
data - additional optional data, depends on the event - might be null!

addEventListener

public void addEventListener(String eventName,
                             EventListener listener)
Adds a event listener.

Parameters:
eventName - the name of events that the listener is interested in, or null when all events should be passed to the listener
listener - the listener
Throws:
NullPointerException - when the listener is null

remapEvent

public void remapEvent(String eventName,
                       Object alternativeSource)
Remaps the named event to the specified alternative source. This can be used for triggering animations in UI elements that did not trigger the named event themselves. Note that the events should be of a unique nature.

Parameters:
eventName - the name of the event, usually this is a custom event name
alternativeSource - the source that should also seem to fire this event
See Also:
removeAllRemappings(), removeRemapEvent(String)

removeRemapEvent

public void removeRemapEvent(String eventName)
Removes all remappings for the specified event

Parameters:
eventName - the name of the event that was remapped
See Also:
remapEvent(String, Object)

removeRemapEvent

public void removeRemapEvent(String eventName,
                             Object alternativeSource)
Removes a single remapping for the specified event

Parameters:
eventName - the name of the event that was remapped
alternativeSource - the source that should also seem to fire this event
See Also:
remapEvent(String, Object)

removeAllRemappings

public void removeAllRemappings()
Removes all remappings