EventBus
final class EventBus
Package: dev.joid.lib.ui.event · Module: core · Source: EventBus.java
Holds the listeners of an object, one ordered list per event type, and runs them when an event fires.
Description
Section titled “Description”Every node and every UI holds its listeners in an EventBus; their onX, beforeX and handleX methods add to it.
The listeners of one type run in the order of their EventPriority, then in the order they were added.
A listener that throws does not stop the others: JOID prints a warning once for each new failure of that listener and runs the next one.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
EventBus | create(Supplier | Creates an empty bus. |
Methods
Section titled “Methods”| Returns | Signature | Summary |
|---|---|---|
this | listen(EventType type, EventListener listener) fluent | Adds a listener for a type of event, after the listeners of the same priority. |
this | addAll(EventBus bus) fluent | Adds every listener of another bus to this one, type by type, in their order; a copy of a node gets the listeners of the original this way. |
this | keep() fluent | Marks every listener added so far as permanent: reset() keeps them. |
this | reset() fluent | Removes every listener that keep() did not mark. |
this | clear() fluent | Removes every listener, the permanent ones included. |
void | fire(EventType<?> type, Event event) | Runs the listeners of a type: first fireListeners, then fireMonitor. |
void | fireListeners(EventType<?> type, Event event) | Runs the listeners of a type that are not MONITOR, in their order, and stops as soon as one of them cancels or consumes the event. |
void | fireMonitor(EventType<?> type, Event event) | Runs the MONITOR listeners of a type, even when the event is cancelled or consumed. |
boolean | has(EventType<?> type) | If true, at least one listener listens to the type. |
boolean | isEmpty() | If true, the bus holds no listener. |
int | count(EventType<?> type) | Returns the number of listeners of a type. |
Set<EventType<?>> | getTypes() | Returns the types that have at least one listener, as a read-only view. |
Creation details
Section titled “Creation details”create
Section titled “create”EventBus create(Supplier<String> owner) factory
Creates an empty bus.
owner gives the name of the object that holds it, printed in the warning of a listener that fails.
Method details
Section titled “Method details”listen
Section titled “listen”this listen(EventType<?> type, EventListener<?> listener) fluent
Adds a listener for a type of event, after the listeners of the same priority.
addAll
Section titled “addAll”this addAll(EventBus bus) fluent
Adds every listener of another bus to this one, type by type, in their order; a copy of a node gets the listeners of the original this way.
this keep() fluent
Marks every listener added so far as permanent: reset() keeps them.
A UI calls it when it opens for the first time, so that the listeners of its constructor survive every closing.
this reset() fluent
Removes every listener that keep() did not mark.
A UI calls it when it opens and when it closes, so that the listeners added in init() last one opening.
this clear() fluent
Removes every listener, the permanent ones included.
void fire(EventType<?> type, Event event)
Runs the listeners of a type: first fireListeners, then fireMonitor.
fireListeners
Section titled “fireListeners”void fireListeners(EventType<?> type, Event event)
Runs the listeners of a type that are not MONITOR, in their order, and stops as soon as one of them cancels or consumes the event.
fireMonitor
Section titled “fireMonitor”void fireMonitor(EventType<?> type, Event event)
Runs the MONITOR listeners of a type, even when the event is cancelled or consumed.
The event is read-only for them: cancel() or consume() throws an IllegalStateException.
boolean has(EventType<?> type)
If true, at least one listener listens to the type.
isEmpty
Section titled “isEmpty”boolean isEmpty()
If true, the bus holds no listener.
int count(EventType<?> type)
Returns the number of listeners of a type.
getTypes
Section titled “getTypes”Set<EventType<?>> getTypes()
Returns the types that have at least one listener, as a read-only view.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
