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

Print this page


   1 /*
   2  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 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 (SequencedEvent)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,


 194                     getCurrentSequencedEvent() == this) {
 195                 KeyboardFocusManager.getCurrentKeyboardFocusManager().
 196                     setCurrentSequencedEvent(null);
 197             }
 198             disposed = true;
 199         }
 200         // Wake myself up
 201         if (appContext != null) {
 202             SunToolkit.postEvent(appContext, new SentEvent());
 203         }
 204 
 205         SequencedEvent next = null;
 206 
 207         synchronized (SequencedEvent.class) {
 208           SequencedEvent.class.notifyAll();
 209 
 210           if (list.getFirst() == this) {
 211               list.removeFirst();
 212 
 213               if (!list.isEmpty()) {
 214                     next = (SequencedEvent)list.getFirst();
 215               }
 216           } else {
 217               list.remove(this);
 218           }
 219       }
 220         // Wake up waiting threads
 221         if (next != null && next.appContext != null) {
 222             SunToolkit.postEvent(next.appContext, new SentEvent());
 223         }
 224     }
 225 }
   1 /*
   2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 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,


 194                     getCurrentSequencedEvent() == this) {
 195                 KeyboardFocusManager.getCurrentKeyboardFocusManager().
 196                     setCurrentSequencedEvent(null);
 197             }
 198             disposed = true;
 199         }
 200         // Wake myself up
 201         if (appContext != null) {
 202             SunToolkit.postEvent(appContext, new SentEvent());
 203         }
 204 
 205         SequencedEvent next = null;
 206 
 207         synchronized (SequencedEvent.class) {
 208           SequencedEvent.class.notifyAll();
 209 
 210           if (list.getFirst() == this) {
 211               list.removeFirst();
 212 
 213               if (!list.isEmpty()) {
 214                     next = list.getFirst();
 215               }
 216           } else {
 217               list.remove(this);
 218           }
 219       }
 220         // Wake up waiting threads
 221         if (next != null && next.appContext != null) {
 222             SunToolkit.postEvent(next.appContext, new SentEvent());
 223         }
 224     }
 225 }