S - The type of the ListenerStore this provider uses.public class AWTEventProvider<S extends ListenerStore> extends AbstractEventProvider<S>
EventProvider implementation that dispatches all events in the AWT
event thread.defaultHandler, exceptionHandler| Constructor and Description |
|---|
AWTEventProvider(S store,
boolean invokeNow)
Creates a new AwtEventProvider.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canDispatch()
Gets whether this EventProvider is ready for dispatching.
|
<L extends Listener,E extends Event<?,L>> |
dispatch(E event,
BiConsumer<L,E> bc,
ExceptionCallback ec)
Notifies all listeners of a certain kind about an occurred event with
explicit error handling.
|
protected boolean |
isImplementationSequential()
Whether this EventProvider implementation is sequential.
|
boolean |
isInvokeNow()
Whether this provider will block the current thread until dispatch is
done.
|
checkDispatchArgs, close, createInvocation, dispatch, dispatch, isSequential, listeners, notifyListeners, notifySingle, setExceptionCallback, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitconfigure, createDefault, dispatch, dispatch, dispatchpublic AWTEventProvider(S store, boolean invokeNow)
SwingUtilities.invokeLater(Runnable) or your current thread
should wait until all listeners are notified (uses
SwingUtilities.invokeAndWait(Runnable) to run notify the
listeners).store - Responsible for storing and retrieving listeners of this
provider.invokeNow - If true,
dispatch uses invokeAndWait, otherwise
invokeLater.public boolean isInvokeNow()
false, the notification of
Events is queued in the AWT event queue and dispatch returns
immediately.public <L extends Listener,E extends Event<?,L>> void dispatch(E event, BiConsumer<L,E> bc, ExceptionCallback ec)
EventProviderEventProvider.canDispatch(), this method returns immediately
without doing anything. This method will stop notifying further listeners
if the passed event has been marked 'handled' using
Event.setHandled(boolean).
Consider an UserListener interface:
public interface UserListener extends Listener {
public void userAdded(UserEvent e);
public void userDeleted(UserEvent e);
}
Notifying all registered UserListeners about an added user is as easy as
calling
final ExceptionCallback callBack = new EceptionCallback() { ... };
eventProvider.dispatchEvent(event, UserListener::userAdded, callBack);
The ExceptionCallback gets notified when any of the listeners
throws an unexpected exception. If the exception handler itself throws an
exception, it will be ignored. The callback provided to this method takes
precedence over the global callback provided by
EventProvider.setExceptionCallback(ExceptionCallback).
Note on concurrency: This method operates on a copy of the list of targeted listeners. This allows you to add/remove listeners from within a listening method.
Please note that neither parameter to this method must be null.
dispatch in interface EventProvider<S extends ListenerStore>dispatch in class AbstractEventProvider<S extends ListenerStore>L - Type of the listeners which will be notified.E - Type of the event which will be passed to a listener.event - The occurred event which shall be passed to each listener.bc - Function to delegate the event to the specific callback method
of the listener.ec - Callback to be notified when any of the listeners throws an
exception.public boolean canDispatch()
EventProviderdispatchprotected boolean isImplementationSequential()
AbstractEventProviderAbstractEventProvider.isSequential() method considers the result of this method and
the result of the current ListenerStore's
isSequential method for determining
whether dispatch events of this provider are sequential.isImplementationSequential in class AbstractEventProvider<S extends ListenerStore>Copyright © 2014–2015. All rights reserved.