Class EventEmitter

java.lang.Object
com.j3d.engine.react.events.EventEmitter
All Implemented Interfaces:
EventEmitterInterface
Direct Known Subclasses:
Camera, Commands, GObject, GuideFlow, GuideInfo

public abstract class EventEmitter extends Object implements EventEmitterInterface
EventEmitter is a class that allows for other classes to attach events that they can broadcast to at any time. Any class that can extend EventEmitter should, otherwise they can implement EventEmitterInterface if they cannot extend EventEmitter.
  • Field Details

  • Constructor Details

    • EventEmitter

      public EventEmitter()
      Creates a new EventEmitter with no registered listeners.
  • Method Details

    • attachListener

      public void attachListener(EventListener event)
      Attaches a listener to the event emitter.
      Specified by:
      attachListener in interface EventEmitterInterface
      Parameters:
      event - The listener to attach
    • detachListener

      public void detachListener(EventListener event)
      Detaches a listener from the event emitter.
      Specified by:
      detachListener in interface EventEmitterInterface
      Parameters:
      event - The listener to detach.
    • detachAll

      public void detachAll()
      Detaches all listeners from the event emitter.
      Specified by:
      detachAll in interface EventEmitterInterface
    • broadcast

      public <K> void broadcast(EventType eventType, EventPayload<K> properties)
      Broadcasts an event to all registered listeners.
      Specified by:
      broadcast in interface EventEmitterInterface
      Type Parameters:
      K - The object held by the EventPayload.
      Parameters:
      eventType - The event type.
      properties - Properties to pass onto the listener.
    • genericAttach

      public static void genericAttach(ArrayList<EventListener> events, EventListener event)
      Attaches a listener to the event emitter. Useful for implementors of EventEmitterInterface.
      Parameters:
      events - The list of current listeners
      event - The listener to attach
    • genericDetach

      public static void genericDetach(ArrayList<EventListener> events, EventListener event)
      Detaches a listener from the event emitter. Useful for implementors of EventEmitterInterface.
      Parameters:
      events - The list of current listeners
      event - The listener to detach
    • genericDetachAll

      public static void genericDetachAll(ArrayList<EventListener> events)
      Detaches all listeners from the event emitter. Useful for implementors of EventEmitterInterface.
      Parameters:
      events - The list of current listeners
    • genericBroadcast

      public static <K> void genericBroadcast(ArrayList<EventListener> events, EventType eventType, EventPayload<K> properties)
      Broadcasts an event to all registered listeners. Useful for implementors of EventEmitterInterface.
      Type Parameters:
      K - The object held by the EventPayload.
      Parameters:
      events - The list of current listeners
      eventType - The event type.
      properties - Properties to pass onto the listener.
    • isAttached

      public boolean isAttached(EventListener e)
      Description copied from interface: EventEmitterInterface
      Checks if the given event listener is attached to this event emitter.
      Specified by:
      isAttached in interface EventEmitterInterface
      Parameters:
      e - The event listener to check.
      Returns:
      True if the event listener is attached, false otherwise.