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
    --- | --- | ---
    `int` | `addToSystemPool()` | Adds the generator in the system pool.
    `static EventGenerator` | `get​(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> E` | `get​(Class<E> clazz, int fromIndex)` | Gets a generator whose class is `clazz` from the system pool starting the search from `fromIndex`.
    `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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### EventGenerator

          public EventGenerator()

      Creates a new event generator. As soon as a new event generator is added to the system pool it has a valid identifier.

  - ### 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 is `clazz` from the system pool starting the search from `fromIndex`. If class `clazz` is not an `EventGenerator` or if nothing is found, returns `null`.
      Parameters:
        `clazz` - the `EventGenerator`'s class to return
        `fromIndex` - index from which starting to search
      Returns:
        the `EventGenerator` or `null`.
      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 254 `EventGenerator`s 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 current `EventHandler`. Does nothing if there is no event handler set to this event generator.
      Parameters:
        `event` - the event to send