< prev index next >

src/share/classes/java/awt/SequencedEvent.java

Print this page




  87     /**
  88      * Dispatches the nested event after all previous nested events have been
  89      * dispatched or disposed. If this method is invoked before all previous nested events
  90      * have been dispatched, then this method blocks until such a point is
  91      * reached.
  92      * While waiting disposes nested events to disposed AppContext
  93      *
  94      * NOTE: Locking protocol.  Since dispose() can get EventQueue lock,
  95      * dispatch() shall never call dispose() while holding the lock on the list,
  96      * as EventQueue lock is held during dispatching.  The locks should be acquired
  97      * in the same order.
  98      */
  99     public final void dispatch() {
 100         try {
 101             appContext = AppContext.getAppContext();
 102 
 103             if (getFirst() != this) {
 104                 if (EventQueue.isDispatchThread()) {
 105                     EventDispatchThread edt = (EventDispatchThread)
 106                         Thread.currentThread();
 107                     edt.pumpEvents(ID, () -> !SequencedEvent.this.isFirstOrDisposed());




 108                 } else {
 109                     while(!isFirstOrDisposed()) {
 110                         synchronized (SequencedEvent.class) {
 111                             try {
 112                                 SequencedEvent.class.wait(1000);
 113                             } catch (InterruptedException e) {
 114                                 break;
 115                             }
 116                         }
 117                     }
 118                 }
 119             }
 120 
 121             if (!disposed) {
 122                 KeyboardFocusManager.getCurrentKeyboardFocusManager().
 123                     setCurrentSequencedEvent(this);
 124                 Toolkit.getEventQueue().dispatchEvent(nested);
 125             }
 126         } finally {
 127             dispose();




  87     /**
  88      * Dispatches the nested event after all previous nested events have been
  89      * dispatched or disposed. If this method is invoked before all previous nested events
  90      * have been dispatched, then this method blocks until such a point is
  91      * reached.
  92      * While waiting disposes nested events to disposed AppContext
  93      *
  94      * NOTE: Locking protocol.  Since dispose() can get EventQueue lock,
  95      * dispatch() shall never call dispose() while holding the lock on the list,
  96      * as EventQueue lock is held during dispatching.  The locks should be acquired
  97      * in the same order.
  98      */
  99     public final void dispatch() {
 100         try {
 101             appContext = AppContext.getAppContext();
 102 
 103             if (getFirst() != this) {
 104                 if (EventQueue.isDispatchThread()) {
 105                     EventDispatchThread edt = (EventDispatchThread)
 106                         Thread.currentThread();
 107                     edt.pumpEvents(SentEvent.ID, new Conditional() {
 108                         public boolean evaluate() {
 109                             return !SequencedEvent.this.isFirstOrDisposed();
 110                         }
 111                     });
 112                 } else {
 113                     while(!isFirstOrDisposed()) {
 114                         synchronized (SequencedEvent.class) {
 115                             try {
 116                                 SequencedEvent.class.wait(1000);
 117                             } catch (InterruptedException e) {
 118                                 break;
 119                             }
 120                         }
 121                     }
 122                 }
 123             }
 124 
 125             if (!disposed) {
 126                 KeyboardFocusManager.getCurrentKeyboardFocusManager().
 127                     setCurrentSequencedEvent(this);
 128                 Toolkit.getEventQueue().dispatchEvent(nested);
 129             }
 130         } finally {
 131             dispose();


< prev index next >