Package ej.microui.event
Class EventGenerator
- java.lang.Object
-
- ej.microui.event.EventGenerator
-
- Direct Known Subclasses:
Buttons,Command,DesktopEventGenerator,GenericEventGenerator,States
public abstract class EventGenerator extends Object
-
-
Constructor Summary
Constructors Constructor Description EventGenerator()Creates a new event generator.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intaddToSystemPool()Adds the generator in the system pool.static EventGeneratorget(int id)Gets a generator from its identifier.static <E extends EventGenerator>
EventGenerator[]get(Class<E> clazz)Gets all generators of the given type from the system pool in an array.static <E extends EventGenerator>
Eget(Class<E> clazz, int fromIndex)Gets a generator whose class isclazzfrom the system pool starting the search fromfromIndex.EventHandlergetEventHandler()Gets the generator's event handler.abstract intgetEventType()Gets the event type associated with the event generatorintgetId()Gets the generator's unique identifier.voidremoveFromSystemPool()Removes the generator from the system generators pool.protected voidsendEvent(int event)Sends the given event to the currentEventHandler.voidsetEventHandler(EventHandler eventHandler)Sets an event handler to this event generator.
-
-
-
Method Detail
-
addToSystemPool
public int addToSystemPool()
Adds the generator in the system pool. The generator can only be added once as a system generator. When added, its identifier is set.- Returns:
- the event generator's identifier in the system pool.
- Throws:
MicroUIException- if the maximum number of event generators added to the system pool has been reached.
-
removeFromSystemPool
public void removeFromSystemPool()
Removes the generator from the system generators pool. If the generator is not in the pool, nothing is done.
-
setEventHandler
public void setEventHandler(@Nullable EventHandler eventHandler)
Sets an event handler to this event generator. It will receive the generated events.It replaces the old one and can be
null.- Parameters:
eventHandler- the event handler to add.- Throws:
SecurityException- if a security manager exists and does not allow the caller to handle events from this event generator.- Since:
- 2.0
-
get
public static EventGenerator get(int id)
Gets a generator from its identifier.- Parameters:
id- the generator's identifier.- Returns:
- the associated event generator.
- Throws:
IndexOutOfBoundsException- if the generator does not exist.MicroUIException- if MicroUI is not started
-
get
@Nullable public static <E extends EventGenerator> E get(Class<E> clazz, int fromIndex)
Gets a generator whose class isclazzfrom the system pool starting the search fromfromIndex. If classclazzis not anEventGeneratoror if nothing is found, returnsnull.- Parameters:
clazz- theEventGenerator's class to returnfromIndex- index from which starting to search- Returns:
- the
EventGeneratorornull. - Throws:
MicroUIException- if MicroUI is not started
-
get
public static <E extends EventGenerator> EventGenerator[] get(Class<E> clazz)
Gets all generators of the given type from the system pool in an array.- Parameters:
clazz- the type of the event generators to return.- Returns:
- the arrays of event generators.
- Throws:
MicroUIException- if MicroUI is not started
-
getId
public final int getId()
Gets the generator's unique identifier. Up to 254EventGenerators can be installed as MicroUI system event generator.- Returns:
- the generator's identifier as an
int.
-
getEventHandler
@Nullable public EventHandler getEventHandler()
Gets the generator's event handler.- Returns:
- the generator's event handler.
- Since:
- 2.0
-
getEventType
public abstract int getEventType()
Gets the event type associated with the event generator- Returns:
- the event type
-
sendEvent
protected void sendEvent(int event)
Sends the given event to the currentEventHandler. Does nothing if there is no event handler set to this event generator.- Parameters:
event- the event to send
-
-