Package com.j3d.engine.react.events
Class EventEmitter
java.lang.Object
com.j3d.engine.react.events.EventEmitter
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprotected ArrayList<EventListener> All registered EventListeners -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidattachListener(EventListener event) Attaches a listener to the event emitter.<K> voidbroadcast(EventType eventType, EventPayload<K> properties) Broadcasts an event to all registered listeners.voidDetaches all listeners from the event emitter.voiddetachListener(EventListener event) Detaches a listener from the event emitter.static voidgenericAttach(ArrayList<EventListener> events, EventListener event) Attaches a listener to the event emitter.static <K> voidgenericBroadcast(ArrayList<EventListener> events, EventType eventType, EventPayload<K> properties) Broadcasts an event to all registered listeners.static voidgenericDetach(ArrayList<EventListener> events, EventListener event) Detaches a listener from the event emitter.static voidgenericDetachAll(ArrayList<EventListener> events) Detaches all listeners from the event emitter.booleanChecks if the given event listener is attached to this event emitter.
-
Field Details
-
registered
All registered EventListeners
-
-
Constructor Details
-
EventEmitter
public EventEmitter()Creates a new EventEmitter with no registered listeners.
-
-
Method Details
-
attachListener
Attaches a listener to the event emitter.- Specified by:
attachListenerin interfaceEventEmitterInterface- Parameters:
event- The listener to attach
-
detachListener
Detaches a listener from the event emitter.- Specified by:
detachListenerin interfaceEventEmitterInterface- Parameters:
event- The listener to detach.
-
detachAll
public void detachAll()Detaches all listeners from the event emitter.- Specified by:
detachAllin interfaceEventEmitterInterface
-
broadcast
Broadcasts an event to all registered listeners.- Specified by:
broadcastin interfaceEventEmitterInterface- Type Parameters:
K- The object held by theEventPayload.- Parameters:
eventType- The event type.properties- Properties to pass onto the listener.
-
genericAttach
Attaches a listener to the event emitter. Useful for implementors ofEventEmitterInterface.- Parameters:
events- The list of current listenersevent- The listener to attach
-
genericDetach
Detaches a listener from the event emitter. Useful for implementors ofEventEmitterInterface.- Parameters:
events- The list of current listenersevent- The listener to detach
-
genericDetachAll
Detaches all listeners from the event emitter. Useful for implementors ofEventEmitterInterface.- 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 ofEventEmitterInterface.- Type Parameters:
K- The object held by theEventPayload.- Parameters:
events- The list of current listenerseventType- The event type.properties- Properties to pass onto the listener.
-
isAttached
Description copied from interface:EventEmitterInterfaceChecks if the given event listener is attached to this event emitter.- Specified by:
isAttachedin interfaceEventEmitterInterface- Parameters:
e- The event listener to check.- Returns:
- True if the event listener is attached, false otherwise.
-