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