Package de.sciss.app

Class EventManager

  • All Implemented Interfaces:
    java.lang.Runnable
    Direct Known Subclasses:
    LaterInvocationManager

    public class EventManager
    extends java.lang.Object
    implements java.lang.Runnable
    A 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 interface  EventManager.Processor
      Callers of the EventManager constructor must provide an object implementing this interface
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addListener​(java.lang.Object listener)
      Adds a new listener.
      int countListeners()
      Get the number of listeners synchronization: MUST BE CALLED FROM THE EVENT DISPATCH THREAD
      void debugDump()  
      void dispatchEvent​(BasicEvent e)
      Puts a new event in the queue.
      void dispose()  
      java.lang.Object getListener​(int index)
      Gets a listener from the list synchronization: MUST BE CALLED FROM THE EVENT DISPATCH THREAD
      void pause()
      Pauses event dispatching.
      void removeListener​(java.lang.Object listener)
      Removes a listener.
      void resume()
      Resumes event dispatching.
      void run()
      Called by add/removeListener and dispatchEvent.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • 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. null is 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:
        run in interface java.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.