public abstract class EventGenerator extends 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 identifier between 0 and 254,
otherwise identifier 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(Class<E> clazz)
Gets all generators of the given type from the system pool in an array.
|
static <E extends EventGenerator> |
get(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 identifier.
|
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 identifier.
|
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()
MicroUIException
- if the maximum number of event generators added to the system pool has been reached.public static <E extends EventGenerator> EventGenerator[] get(Class<E> clazz)
clazz
- the type of the event generators to return.MicroUIException
- if MicroUI is not started@Nullable public static <E extends EventGenerator> E get(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
.MicroUIException
- if MicroUI is not startedpublic static EventGenerator get(int id)
id
- the generator's identifier.IndexOutOfBoundsException
- if the generator does not exist.MicroUIException
- if MicroUI is not started@Nullable public EventHandler getEventHandler()
public abstract int getEventType()
public final int getId()
EventGenerator
s can be installed as MicroUI system
event generator.int
.public void removeFromSystemPool()
protected void sendEvent(int event)
EventHandler
. Does nothing if there is no event handler set to this
event generator.event
- the event to sendpublic void setEventHandler(@Nullable EventHandler eventHandler)
It replaces the old one and can be null
.
eventHandler
- the event handler to add.SecurityException
- if a security manager exists and does not allow the caller to handle events from this event
generator.