sdljava.event
Class SDLEventManager

java.lang.Object
  extended by sdljava.event.SDLEventManager
All Implemented Interfaces:
java.lang.Runnable

public class SDLEventManager
extends java.lang.Object
implements java.lang.Runnable

The SDLEventManager is a thread helping us to handling SDL events.

Version:
$Id: SDLEventManager.java,v 1.5 2005/02/11 07:00:09 doc_alton Exp $
Author:
Bart LEBOEUF

Field Summary
private static SDLEventManager instance
          Class Instance
private  boolean isStopped
          Stop thread flag
private  java.lang.Thread managerThread
          Internal daemon thread reference
private  java.util.HashMap repository
          Inner repository contains listener list by event type.
 
Constructor Summary
private SDLEventManager()
          Constructor
 
Method Summary
 int countEventListeners()
          Count how many event type is listened.
 java.util.Iterator getEventListeners()
          Get an Iterator of events type listen.
static SDLEventManager getInstance()
          Get instance of this class
 java.util.Iterator getRegisteredListeners(java.lang.Class eventType)
          Get an Iterator of registered listeners for a particular event type.
 void notifyEvent(SDLEvent event)
          Notify all listeners registered for the event type of the new SDLEvent.
 boolean register(SDLEventListener listener, java.lang.Class eventType)
          Register a listener for an event type
 boolean register(SDLEventListener listener, java.util.List events)
          Register a listener for a list of events
 void run()
          Run method for our thread.
 void startAndWait()
          Start listening and Wait a for events.
 void stop()
          Stop handling the events.
 boolean unregister(SDLEventListener listener)
          Unregister a SDLEventListener
 boolean unregisterAll()
          Unregistered all listeners.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static SDLEventManager instance
Class Instance


repository

private java.util.HashMap repository
Inner repository contains listener list by event type.


managerThread

private java.lang.Thread managerThread
Internal daemon thread reference


isStopped

private volatile boolean isStopped
Stop thread flag

Constructor Detail

SDLEventManager

private SDLEventManager()
Constructor

Method Detail

getInstance

public static SDLEventManager getInstance()
Get instance of this class

Returns:
SDLEventManager return this class instance

register

public boolean register(SDLEventListener listener,
                        java.util.List events)
Register a listener for a list of events

Parameters:
listener - The class implements SDLEventListener interface
events - A list of events or event types.
Returns:
boolean return true if registration is done.

register

public boolean register(SDLEventListener listener,
                        java.lang.Class eventType)
Register a listener for an event type

Parameters:
listener - The class implements SDLEventListener interface
eventType - An SDL event type.
Returns:
boolean return true if registration is done.

unregister

public boolean unregister(SDLEventListener listener)
Unregister a SDLEventListener

Parameters:
listener - The class implements SDLEventListener interface
Returns:
boolean return true if unregistration is done.

getRegisteredListeners

public java.util.Iterator getRegisteredListeners(java.lang.Class eventType)
Get an Iterator of registered listeners for a particular event type.

Parameters:
eventType - SDLEvent type.
Returns:
Iterator return an Iterator of listeners

getEventListeners

public java.util.Iterator getEventListeners()
Get an Iterator of events type listen.

Returns:
Iterator return an Iterator of Event type.

unregisterAll

public boolean unregisterAll()
Unregistered all listeners.

Returns:
boolean return true if all listeners are unregistered

countEventListeners

public int countEventListeners()
Count how many event type is listened.

Returns:
int number of event type registered.

startAndWait

public void startAndWait()
Start listening and Wait a for events.


stop

public void stop()
Stop handling the events.


run

public void run()
Run method for our thread. If an SDLException as occured in a listener, it will not stop manager.

Specified by:
run in interface java.lang.Runnable

notifyEvent

public void notifyEvent(SDLEvent event)
Notify all listeners registered for the event type of the new SDLEvent.

Parameters:
event - The new SDLEvent