Package org.bushe.swing.event.generics

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

See:
          Description

Class Summary
TypeReference<T> Courtesy of Neil Gafter's blog.
 

Package org.bushe.swing.event.generics 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 {