Java Events Framework Wiki
Brought to you by:
heitorprojects
Welcome to your wiki!
This is the default page, edit it as you see fit. To add a page simply reference it within brackets, e.g.: [SamplePage].
The wiki uses Markdown syntax.
Introduction
This document describes the key elements to using the Java Events Framework (JEF). The sample code snippets are extracted from the source code of the Sample application which is available for download from the Downloads page of this project.
Any instantiatable class can use the Java Events Framework to become and Event-Handler or Event-Dispatcher object. A class can also be both; providing a two way communication pipe with other objects from the same or other classes. In any of these cases, the classes must import the JEF package with this statement:
Event Listeners
To 'handle' event notifications a class must declare that it implements the IEventHandler interface provided in the JEF package.
It must then supply the logic implementation for one single method:
But before it can receive notifications, it must 'register' itself with the object that is generating the events. This is simply accomplished by calling the following method on the event dispatching object:
If at any stage of execution it no longer needs to receive one or more of the events that this object dispatches, it can call the following method to de-register itself from receiving notifications for the specific event(s):
Event Dispatchers
To 'dispatch' event notifications a class must declare that it implements the IEventSource interface provided in the JEF package.
It must then supply the logic implementation for two methods that have been discussed above which are called from objects that wish to receive event notifications (event handlers):
The above method is called by 'listeners' who wish to be notified of one or more events that this dispatcher class generates and the method below is called by the same objects to 'de-register' themselves from receiving further notifications of one or more events from this object:
An additional method which must also be implemented by the class dispatching events is the following method, which provides a quick and easy way for 'listener' objects that receive event notifications to obtain a unique name to identify the source object that dispatched the event. It is up to the developer that creates objects of the event-dispatching class, to provide a unique
String
name for each of the objects that he instantiates, at object creation time.In addition to implementing the above methods from the IEventSource interface, a class that generates events must instantiate a single object of the EventsManager class.
This is the class that exposes the necessary methods required to dispatch events. It encapsulates all the 'plumbing' that manages the registration, de-registration and dispatching of events to registered 'listeners'.
At initialization, an array of Event objects is passed to its constructor, each of which encloses the various settings that define the name and threading model / priority (see the included Javadoc documentation for specific details of the available settings) for each type of event that this event-dispatching class generates.
When an event needs to be dispatched, the object calls the following method on its
EventsManager
object to manage the dispatching of the event to all registered 'listener' objects.Optionally it can deliver one or more parameters to the event listeners through its optional
params
method parameter. If multiple objects need to be passed, they can be encapsulated in an Array, Collection or a custom class, as theparams
parameter is conveniently defined as typeObject
.See the Javadoc documentation supplied with the framework's source to obtain specific details of method declarations and variable types.
Last edit: Jose Heitor 2011-04-21