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

Print this page




 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();
 132         }
 133     }
 134 
 135     /**
 136      * true only if event exists and nested source appContext is disposed.
 137      */
 138     private final static boolean isOwnerAppContextDisposed(SequencedEvent se) {
 139         if (se != null) {
 140             Object target = se.nested.getSource();
 141             if (target instanceof Component) {
 142                 return ((Component)target).appContext.isDisposed();
 143             }
 144         }
 145         return false;
 146     }
 147 
 148     /**
 149      * Sequenced events are dispatched in order, so we cannot dispatch
 150      * until we are the first sequenced event in the queue (i.e. it's our
 151      * turn).  But while we wait for our turn to dispatch, the event
 152      * could have been disposed for a number of reasons.
 153      */
 154     public final boolean isFirstOrDisposed() {
 155         if (disposed) {
 156             return true;
 157         }
 158         // getFirstWithContext can dispose this
 159         return this == getFirstWithContext() || disposed;
 160     }
 161 
 162     private final synchronized static SequencedEvent getFirst() {
 163         return list.getFirst();
 164     }
 165 
 166     /* Disposes all events from disposed AppContext
 167      * return first valid event
 168      */
 169     private final static SequencedEvent getFirstWithContext() {
 170         SequencedEvent first = getFirst();
 171         while(isOwnerAppContextDisposed(first)) {
 172             first.dispose();
 173             first = getFirst();
 174         }
 175         return first;
 176     }
 177 
 178     /**
 179      * Disposes of this instance. This method is invoked once the nested event
 180      * has been dispatched and handled, or when the peer of the target of the
 181      * nested event has been disposed with a call to Component.removeNotify.
 182      *
 183      * NOTE: Locking protocol.  Since SunToolkit.postEvent can get EventQueue lock,
 184      * it shall never be called while holding the lock on the list,
 185      * as EventQueue lock is held during dispatching and dispatch() will get
 186      * lock on the list. The locks should be acquired in the same order.
 187      */
 188     final void dispose() {
 189       synchronized (SequencedEvent.class) {




 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();
 132         }
 133     }
 134 
 135     /**
 136      * true only if event exists and nested source appContext is disposed.
 137      */
 138     private static final boolean isOwnerAppContextDisposed(SequencedEvent se) {
 139         if (se != null) {
 140             Object target = se.nested.getSource();
 141             if (target instanceof Component) {
 142                 return ((Component)target).appContext.isDisposed();
 143             }
 144         }
 145         return false;
 146     }
 147 
 148     /**
 149      * Sequenced events are dispatched in order, so we cannot dispatch
 150      * until we are the first sequenced event in the queue (i.e. it's our
 151      * turn).  But while we wait for our turn to dispatch, the event
 152      * could have been disposed for a number of reasons.
 153      */
 154     public final boolean isFirstOrDisposed() {
 155         if (disposed) {
 156             return true;
 157         }
 158         // getFirstWithContext can dispose this
 159         return this == getFirstWithContext() || disposed;
 160     }
 161 
 162     private static final synchronized SequencedEvent getFirst() {
 163         return list.getFirst();
 164     }
 165 
 166     /* Disposes all events from disposed AppContext
 167      * return first valid event
 168      */
 169     private static final SequencedEvent getFirstWithContext() {
 170         SequencedEvent first = getFirst();
 171         while(isOwnerAppContextDisposed(first)) {
 172             first.dispose();
 173             first = getFirst();
 174         }
 175         return first;
 176     }
 177 
 178     /**
 179      * Disposes of this instance. This method is invoked once the nested event
 180      * has been dispatched and handled, or when the peer of the target of the
 181      * nested event has been disposed with a call to Component.removeNotify.
 182      *
 183      * NOTE: Locking protocol.  Since SunToolkit.postEvent can get EventQueue lock,
 184      * it shall never be called while holding the lock on the list,
 185      * as EventQueue lock is held during dispatching and dispatch() will get
 186      * lock on the list. The locks should be acquired in the same order.
 187      */
 188     final void dispose() {
 189       synchronized (SequencedEvent.class) {