Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class EventDispatcher
- Object
- EventDispatcher
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:
private final EventDispatcher listeners = new EventDispatcher();
public void addActionListener(ActionListener a) {
listeners.addListener(a);
}
public void removeActionListener(ActionListener a) {
listeners.removeListener(a);
}
private void fireEvent(ActionEvent ev) {
listeners.fireActionEvent(ev);
}
Constructors
public EventDispatcher() |
Methods
public static void setFireStyleEventsOnNonEDT(boolean fire) | When set to true, style events will be dispatched even from non-EDT threads. |
public synchronized void addListener(Object listener) | Add a listener to the dispatcher that would receive the events when they occurs |
public Vector getListenerVector() | Deprecated Returns the vector of the listeners |
public Collection getListenerCollection() | Returns the collection of the listeners |
public synchronized void removeListener(Object listener) | Remove the listener from the dispatcher |
public void fireDataChangeEvent(int index, int type) | Fires the event safely on the EDT without risk of concurrency errors |
public void fireBindTargetChange(Component source, String propertyName, Object oldValue, Object newValue) | Fired when a property of the component changes to a new value |
public void fireStyleChangeEvent(String property, Style source) | Fires the style change even to the listeners |
public void fireActionEvent(ActionEvent ev) | Fires the event safely on the EDT without risk of concurrency errors |
public void fireSelectionEvent(int oldSelection, int newSelection) | Fires the event safely on the EDT without risk of concurrency errors |
public void fireScrollEvent(int scrollX, int scrollY, int oldscrollX, int oldscrollY) | Fires the event safely on the EDT without risk of concurrency errors |
public void fireFocus(Component c) | Fires the event safely on the EDT without risk of concurrency errors |
public boolean hasListeners() | Returns true if the event dispatcher has registered listeners |
public 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. |
public 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. |
Inherited methods
Constructor details
EventDispatcher
public EventDispatcher()Method details
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
fireboolean- true to fire on non-EDT, false otherwise
addListener
public synchronized void addListener(Object listener)Parameters
listenerObject- a dispatcher listener to add
getListenerVector
public Vector getListenerVector()Returns
getListenerCollection
public Collection getListenerCollection()Returns
removeListener
public synchronized void removeListener(Object listener)Parameters
listenerObject- a dispatcher listener to remove
fireDataChangeEvent
public void fireDataChangeEvent(int index, int type)Parameters
indexint- the index of the event
typeint- the type of the event
fireBindTargetChange
public void fireBindTargetChange(Component source, String propertyName, Object oldValue, Object newValue)Parameters
sourceComponent- the source component
propertyNameString- the name of the property
oldValueObject- the old value of the property
newValueObject- the new value for the property
fireStyleChangeEvent
public void fireStyleChangeEvent(String property, Style source)Parameters
propertyString- the property name for the event
sourceStyle- the style firing the event
fireActionEvent
public void fireActionEvent(ActionEvent ev)Parameters
evActionEvent- the ActionEvent to fire to the listeners
fireSelectionEvent
public void fireSelectionEvent(int oldSelection, int newSelection)Parameters
oldSelectionint- old selection
newSelectionint- new selection
fireScrollEvent
public void fireScrollEvent(int scrollX, int scrollY, int oldscrollX, int oldscrollY)fireFocus
public void fireFocus(Component c)Parameters
cComponent- the Component that gets the focus event
hasListeners
public boolean hasListeners()Returns
isBlocking
public boolean isBlocking()Returns
setBlocking
public void setBlocking(boolean blocking)Parameters
blockingboolean- the blocking value