public class EventDispatcher extends Object
Handles event dispatching while guaranteeing that all events would be fired properly on the EDT regardless of their source. This class handles listener registration/removal in a safe and uniform way.
To integrate this into your code you can use something like:
Constructor and Description |
---|
EventDispatcher() |
Modifier and Type | Method and Description |
---|---|
void |
addListener(Object listener)
Add a listener to the dispatcher that would receive the events when they occurs
|
void |
fireActionEvent(ActionEvent ev)
Fires the event safely on the EDT without risk of concurrency errors
|
void |
fireBindTargetChange(Component source,
String propertyName,
Object oldValue,
Object newValue)
Fired when a property of the component changes to a new value
|
void |
fireDataChangeEvent(int index,
int type)
Fires the event safely on the EDT without risk of concurrency errors
|
void |
fireFocus(Component c)
Fires the event safely on the EDT without risk of concurrency errors
|
void |
fireScrollEvent(int scrollX,
int scrollY,
int oldscrollX,
int oldscrollY)
Fires the event safely on the EDT without risk of concurrency errors
|
void |
fireSelectionEvent(int oldSelection,
int newSelection)
Fires the event safely on the EDT without risk of concurrency errors
|
void |
fireStyleChangeEvent(String property,
Style source)
Fires the style change even to the listeners
|
Collection |
getListenerCollection()
Returns the collection of the listeners
|
Vector |
getListenerVector()
Deprecated.
use getListenerCollection instead, this method will now be VERY SLOW
|
boolean |
hasListeners()
Returns true if the event dispatcher has registered listeners
|
boolean |
isBlocking()
Indicates whether this dispatcher blocks when firing events or not, normally
a dispatcher uses callSeriallyAndWait() to be 100% synchronous with event delivery
however this method is very slow.
|
void |
removeListener(Object listener)
Remove the listener from the dispatcher
|
void |
setBlocking(boolean blocking)
Indicates whether this dispatcher blocks when firing events or not, normally
a dispatcher uses callSeriallyAndWait() to be 100% synchronous with event delivery
however this method is very slow.
|
static void |
setFireStyleEventsOnNonEDT(boolean fire)
When set to true, style events will be dispatched even from non-EDT threads.
|
public static void setFireStyleEventsOnNonEDT(boolean fire)
fire
- true to fire on non-EDT, false otherwisepublic void addListener(Object listener)
listener
- a dispatcher listener to addpublic Vector getListenerVector()
public Collection getListenerCollection()
public void removeListener(Object listener)
listener
- a dispatcher listener to removepublic void fireDataChangeEvent(int index, int type)
index
- the index of the eventtype
- the type of the eventpublic void fireBindTargetChange(Component source, String propertyName, Object oldValue, Object newValue)
source
- the source componentpropertyName
- the name of the propertyoldValue
- the old value of the propertynewValue
- the new value for the propertypublic void fireStyleChangeEvent(String property, Style source)
property
- the property name for the eventsource
- the style firing the eventpublic void fireActionEvent(ActionEvent ev)
ev
- the ActionEvent to fire to the listenerspublic void fireSelectionEvent(int oldSelection, int newSelection)
oldSelection
- old selectionnewSelection
- new selectionpublic void fireScrollEvent(int scrollX, int scrollY, int oldscrollX, int oldscrollY)
public void fireFocus(Component c)
c
- the Component that gets the focus eventpublic boolean hasListeners()
public boolean isBlocking()
public void setBlocking(boolean blocking)
blocking
- the blocking value