Package de.sciss.app
Class EventManager
- java.lang.Object
-
- de.sciss.app.EventManager
-
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
LaterInvocationManager
public class EventManager extends java.lang.Object implements java.lang.RunnableA custom event dispatcher which carefully deals with synchronization issues. Assuming, the synchronization requests specified for some methods are fulfilled, this class is completely thread safe.It is constructed using a second object, the manager's processor which will be invoked whenever new events are available in the event FIFO queue. the processor is then responsible for querying all registered listeners and calling their appropriate event listening methods.
Event dispatching is deferred to the Swing thread execution time since this makes the whole application much more predictable and easily synchronizable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceEventManager.ProcessorCallers of the EventManager constructor must provide an object implementing this interface
-
Field Summary
Fields Modifier and Type Field Description static booleanDEBUG_EVENTSprotected EventManager.ProcessoreventProcessor
-
Constructor Summary
Constructors Modifier Constructor Description protectedEventManager()EventManager(EventManager.Processor eventProcessor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(java.lang.Object listener)Adds a new listener.intcountListeners()Get the number of listeners synchronization: MUST BE CALLED FROM THE EVENT DISPATCH THREADvoiddebugDump()voiddispatchEvent(BasicEvent e)Puts a new event in the queue.voiddispose()java.lang.ObjectgetListener(int index)Gets a listener from the list synchronization: MUST BE CALLED FROM THE EVENT DISPATCH THREADvoidpause()Pauses event dispatching.voidremoveListener(java.lang.Object listener)Removes a listener.voidresume()Resumes event dispatching.voidrun()Called by add/removeListener and dispatchEvent.
-
-
-
Field Detail
-
DEBUG_EVENTS
public static final boolean DEBUG_EVENTS
- See Also:
- Constant Field Values
-
eventProcessor
protected EventManager.Processor eventProcessor
-
-
Constructor Detail
-
EventManager
public EventManager(EventManager.Processor eventProcessor)
-
EventManager
protected EventManager()
-
-
Method Detail
-
dispose
public void dispose()
-
addListener
public void addListener(java.lang.Object listener)
Adds a new listener. The listener will receive all events queued after this method is called. Events already in queue at the moment this method is called are not passed to the listener.- Parameters:
listener- the listener to add
-
removeListener
public void removeListener(java.lang.Object listener)
Removes a listener. Similar to the adding process, the listener won't receive any events queued after this method is called. However, when there are events in the queue at the moment when this method is called, they will still be past to the old listener.- Parameters:
listener- the listener to remove.nullis allowed (no op).
-
run
public void run()
Called by add/removeListener and dispatchEvent. This method makes the postponed collection modifications permanent. It calls the eventProcessor as long as there are events in the queue.- Specified by:
runin interfacejava.lang.Runnable
-
getListener
public java.lang.Object getListener(int index)
Gets a listener from the list synchronization: MUST BE CALLED FROM THE EVENT DISPATCH THREAD
-
countListeners
public int countListeners()
Get the number of listeners synchronization: MUST BE CALLED FROM THE EVENT DISPATCH THREAD
-
debugDump
public void debugDump()
-
dispatchEvent
public void dispatchEvent(BasicEvent e)
Puts a new event in the queue. If the most recent event can be incorporated by the new event, it will be replaced, otherwise the new one is appended to the end. The eventProcessor is invoked asynchronously in the Swing event thread- Parameters:
e- the event to add to the queue. before it's added, the event's incorporate method will be checked against the most recent event in the queue.
-
pause
public void pause()
Pauses event dispatching. Events will still be queued, but the dispatcher will wait to call any processors until resume() is called.
-
resume
public void resume()
Resumes event dispatching. Any events in the queue will be distributed as normal.
-
-