Package org.bushe.swing.event

The EventBus provides publish/subscribe event services for a single JVM.

See:
          Description

Interface Summary
ContainerEventServiceSupplier A interface implemented by a Swing Container to supply an EventService local to it's child components.
EventService The core interface.
EventServiceEvent Convenience interface for events that get processed by the EventService, its usage is not required in any way.
EventSubscriber<T> Callback interface for class-based subscribers of an EventService.
EventTopicSubscriber Callback interface for topic-based subscribers of an EventService.
ProxySubscriber An interface that can be implemented when proxies are used for subscription.
VetoEventListener Interface for classes that can veto class-based event publication from the EventService.
VetoTopicEventListener Interface for classes that can veto publication on topic names from the EventService.
 

Class Summary
AbstractEventServiceEvent Convenience base class for EventServiceEvents in the application.
CleanupEvent Published when the ThreadSafeEventService cleans up stale subscribers.
ContainerEventServiceAction When fired, this action poublishes an ActionEvent on a Container EventService.
ContainerEventServiceFinder This class finds a component's container event service, and creates one if necessary and possible.
ContainerEventServiceRegistrar Registers a component with it's Container's EventService while keeping track of the component's container.
EventBus The EventBus provides Swing event publication and subscription services.
EventBusAction When fired, this action publishes events on the EventBus.
EventServiceAction Abstract class that publishes a Swing ActionEvent (or another object) to an EventService.
EventServiceLocator A ServiceLocator pattern class for getting an instance of an EventService.
ObjectEvent A simple event that delivers an untyped object with a source object.
SubscriberTimingEvent This event is published internally to report timing for subscribe on an EventService.
SwingEventService An EventService implementation for Swing.
ThreadSafeEventService A thread-safe EventService implementation.
 

Enum Summary
CleanupEvent.Status  
 

Exception Summary
EventServiceExistsException Exception thrown by the EventServiceLocator when an exception exists.
 

Package org.bushe.swing.event Description

The EventBus provides publish/subscribe event services for a single JVM.

The EventBus is especially suitable for Swing Applications, though it is usable in any context, even server-side. See the package description below for a complete description. The EventBus allows two components to communicate with each other without either of them knowing about the other (i.e., having a reference to the other).  It is an alternative to the tight coupling introduced by the typical Swing addXXXListener event mechanism.  When using the EventBus, the listener is subscribed to the EventBus instead of being added to a component.   The component that normally sends events to its listener list instead publishes events to the EventBus..  The EventBus takes care of routing events from publishers to subscribers.

This simple example prints "Hello World" using class-based publication.


class HelloThingy { //the same for all the examples public String getWorld() { return "World"; } }
class MySubscriber implements EventSubscriber { //EventSubscriber implementation public void onEvent(Object event) { HelloThingy helloEvent = (HelloThingy)event; System.out.println("Hello"+helloEvent.getWorld()); } }
class HelloEventBus { public static void main(String args[]) { MySubscriber subscriber = new MySubscriber(); EventBus.subscribe(HelloThingy.class, subscriber); EventBus.publish(new HelloThingy()); } }

Alternatively, this example can be coded using EventBus annotations and the AnnotationProcessor:

class MySubscriber {