Skip to content

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.

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.

ReturnsSignatureSummary
EventBuscreate(Supplier owner) factoryCreates an empty bus.

ReturnsSignatureSummary
thislisten(EventType type, EventListener listener) fluentAdds a listener for a type of event, after the listeners of the same priority.
thisaddAll(EventBus bus) fluentAdds 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.
thiskeep() fluentMarks every listener added so far as permanent: reset() keeps them.
thisreset() fluentRemoves every listener that keep() did not mark.
thisclear() fluentRemoves every listener, the permanent ones included.
voidfire(EventType<?> type, Event event)Runs the listeners of a type: first fireListeners, then fireMonitor.
voidfireListeners(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.
voidfireMonitor(EventType<?> type, Event event)Runs the MONITOR listeners of a type, even when the event is cancelled or consumed.
booleanhas(EventType<?> type)If true, at least one listener listens to the type.
booleanisEmpty()If true, the bus holds no listener.
intcount(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.

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.

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. 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.

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. 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.

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.


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

Report a problem with this page