com.sun.lwuit.util
Class EventDispatcher

java.lang.Object
  extended by com.sun.lwuit.util.EventDispatcher

public class EventDispatcher
extends java.lang.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.


Constructor Summary
EventDispatcher()
           
 
Method Summary
 void addListener(java.lang.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 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 fireSelectionEvent(int oldSelection, int newSelection)
          Fires the event safely on the EDT without risk of concurrency errors
 void fireStyleChangeEvent(java.lang.String property, Style source)
          Fires the style change even to the listeners
 java.util.Vector getListenerVector()
          Returns the vector of the listeners
 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% synchronos with event delivery however this method is very slow.
 void removeListener(java.lang.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% synchronos 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventDispatcher

public EventDispatcher()
Method Detail

setFireStyleEventsOnNonEDT

public static void setFireStyleEventsOnNonEDT(boolean fire)
When set to true, style events will be dispatched even from non-EDT threads. When set to false, when in non-EDT threads, style events will not be dispatched at all (And developer has to make sure changes will be reflected by calling revalidate after all the changes) Default is false. Setting this to true results in a performance penalty, and it is better instead to simply aggregate events performed on non-EDT threads and when all are over - call revalidate on the relevant container.

Parameters:
fire - true to fire on non-EDT, false otherwise

addListener

public void addListener(java.lang.Object listener)
Add a listener to the dispatcher that would receive the events when they occurs

Parameters:
listener - a dispatcher listener to add

getListenerVector

public java.util.Vector getListenerVector()
Returns the vector of the listeners

Returns:
the vector of listeners attached to the event dispatcher

removeListener

public void removeListener(java.lang.Object listener)
Remove the listener from the dispatcher

Parameters:
listener - a dispatcher listener to remove

fireDataChangeEvent

public void fireDataChangeEvent(int index,
                                int type)
Fires the event safely on the EDT without risk of concurrency errors

Parameters:
index - the index of the event
type - the type of the event

fireStyleChangeEvent

public void fireStyleChangeEvent(java.lang.String property,
                                 Style source)
Fires the style change even to the listeners

Parameters:
property - the property name for the event
source - the style firing the event

fireActionEvent

public void fireActionEvent(ActionEvent ev)
Fires the event safely on the EDT without risk of concurrency errors

Parameters:
ev - the ActionEvent to fire to the listeners

fireSelectionEvent

public void fireSelectionEvent(int oldSelection,
                               int newSelection)
Fires the event safely on the EDT without risk of concurrency errors

Parameters:
oldSelection - old selection
newSelection - new selection

fireFocus

public void fireFocus(Component c)
Fires the event safely on the EDT without risk of concurrency errors

Parameters:
c - the Component that gets the focus event

hasListeners

public boolean hasListeners()
Returns true if the event dispatcher has registered listeners

Returns:
true if the event dispatcher has registered listeners

isBlocking

public boolean isBlocking()
Indicates whether this dispatcher blocks when firing events or not, normally a dispatcher uses callSeriallyAndWait() to be 100% synchronos with event delivery however this method is very slow. By setting blocking to false the callSerially method is used which allows much faster execution for IO heavy operations.

Returns:
the blocking state

setBlocking

public void setBlocking(boolean blocking)
Indicates whether this dispatcher blocks when firing events or not, normally a dispatcher uses callSeriallyAndWait() to be 100% synchronos with event delivery however this method is very slow. By setting blocking to false the callSerially method is used which allows much faster execution for IO heavy operations.

Parameters:
blocking - the blocking value