public abstract class EventGenerator
extends java.lang.Object
Event
). They are responsible for holding data that cannot be
sent within the event. Event generators are state machines that convert serialized (mostly external) integers to
MicroUI events.
There is a system pool that holds generators. A generator in the system pool has an ID between 0 and 254, otherwise
ID is 0xFF. The advantage of putting a generator in the system pool is that it can then be looked-up using
get(int)
and get(Class, int)
.
Event
Constructor and Description |
---|
EventGenerator()
Creates a new event generator.
|
Modifier and Type | Method and Description |
---|---|
int |
addToSystemPool()
Adds the generator in the system pool.
|
static <E extends EventGenerator> |
get(java.lang.Class<E> clazz)
Gets all generators of the given type from the system pool in an array.
|
static <E extends EventGenerator> |
get(java.lang.Class<E> clazz,
int fromIndex)
Gets a generator whose class is
clazz from the system pool starting the search from fromIndex . |
static EventGenerator |
get(int id)
Gets a generator from its id.
|
EventHandler |
getEventHandler()
Gets the generator's event handler.
|
abstract int |
getEventType()
Gets the event type associated with the event generator
|
int |
getID()
Gets the generator's unique id.
|
static <E extends EventGenerator> |
getList(java.lang.Class<E> clazz)
Gets all generators of the given type from the system pool in a list.
|
void |
removeFromSystemPool()
Removes the generator from the system generators pool.
|
protected void |
sendEvent(int event)
Sends the given event to the current
EventHandler . |
void |
setEventHandler(EventHandler eventHandler)
Sets an event handler to this event generator.
|
public EventGenerator()
public int addToSystemPool()
java.lang.RuntimeException
- if the maximum number of event generators added to the system pool has been reachedpublic void removeFromSystemPool()
public void setEventHandler(EventHandler eventHandler) throws java.lang.SecurityException
It replaces the old one and can be null
.
eventHandler
- the event handler to add.java.lang.SecurityException
- if a security manager exists and does not allow the caller to handle events from this event
generator.public static EventGenerator get(int id)
id
- the generator's id.java.lang.IndexOutOfBoundsException
- if the generator does not exist.public static <E extends EventGenerator> E get(java.lang.Class<E> clazz, int fromIndex)
clazz
from the system pool starting the search from fromIndex
. If
class clazz
is not an EventGenerator
or if nothing is found, returns null
.clazz
- the EventGenerator
's class to returnfromIndex
- index from which starting to searchEventGenerator
or null
.java.lang.NullPointerException
- if the given class is null
.public static <E extends EventGenerator> EventGenerator[] get(java.lang.Class<E> clazz)
clazz
- the type of the event generators to return.public static <E extends EventGenerator> java.util.List<E> getList(java.lang.Class<E> clazz)
clazz
- the type of the event generators to return.public int getID()
EventGenerator
s can be installed as MicroUI system event
generator.int
.public EventHandler getEventHandler()
public abstract int getEventType()
protected void sendEvent(int event)
EventHandler
. Does nothing if there is no event handler set to this
event generator.event
- the event to send