< prev index next >

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

Print this page




 247      * posted to the other AppContext's EventQueue, and this method blocks
 248      * until the event is handled or target AppContext is disposed.
 249      * Returns true if successfully dispatched event, false if failed
 250      * to dispatch.
 251      */
 252     static boolean sendMessage(Component target, AWTEvent e) {
 253         e.isPosted = true;
 254         AppContext myAppContext = AppContext.getAppContext();
 255         final AppContext targetAppContext = target.appContext;
 256         final SentEvent se =
 257             new DefaultKeyboardFocusManagerSentEvent(e, myAppContext);
 258 
 259         if (myAppContext == targetAppContext) {
 260             se.dispatch();
 261         } else {
 262             if (targetAppContext.isDisposed()) {
 263                 return false;
 264             }
 265             SunToolkit.postEvent(targetAppContext, se);
 266             if (EventQueue.isDispatchThread()) {

 267                 EventDispatchThread edt = (EventDispatchThread)
 268                     Thread.currentThread();
 269                 edt.pumpEvents(SentEvent.ID, new Conditional() {
 270                         public boolean evaluate() {
 271                             return !se.dispatched && !targetAppContext.isDisposed();
 272                         }
 273                     });

 274             } else {
 275                 synchronized (se) {
 276                     while (!se.dispatched && !targetAppContext.isDisposed()) {
 277                         try {
 278                             se.wait(1000);
 279                         } catch (InterruptedException ie) {
 280                             break;
 281                         }
 282                     }
 283                 }
 284             }
 285         }
 286         return se.dispatched;
 287     }
 288 
 289     /*
 290      * Checks if the focus window event follows key events waiting in the type-ahead
 291      * queue (if any). This may happen when a user types ahead in the window, the client
 292      * listeners hang EDT for a while, and the user switches b/w toplevels. In that
 293      * case the focus window events may be dispatched before the type-ahead events




 247      * posted to the other AppContext's EventQueue, and this method blocks
 248      * until the event is handled or target AppContext is disposed.
 249      * Returns true if successfully dispatched event, false if failed
 250      * to dispatch.
 251      */
 252     static boolean sendMessage(Component target, AWTEvent e) {
 253         e.isPosted = true;
 254         AppContext myAppContext = AppContext.getAppContext();
 255         final AppContext targetAppContext = target.appContext;
 256         final SentEvent se =
 257             new DefaultKeyboardFocusManagerSentEvent(e, myAppContext);
 258 
 259         if (myAppContext == targetAppContext) {
 260             se.dispatch();
 261         } else {
 262             if (targetAppContext.isDisposed()) {
 263                 return false;
 264             }
 265             SunToolkit.postEvent(targetAppContext, se);
 266             if (EventQueue.isDispatchThread()) {
 267                 if (Thread.currentThread() instanceof EventDispatchThread) {
 268                     EventDispatchThread edt = (EventDispatchThread)
 269                             Thread.currentThread();
 270                     edt.pumpEvents(SentEvent.ID, new Conditional() {
 271                         public boolean evaluate() {
 272                             return !se.dispatched && !targetAppContext.isDisposed();
 273                         }
 274                     });
 275                 }
 276             } else {
 277                 synchronized (se) {
 278                     while (!se.dispatched && !targetAppContext.isDisposed()) {
 279                         try {
 280                             se.wait(1000);
 281                         } catch (InterruptedException ie) {
 282                             break;
 283                         }
 284                     }
 285                 }
 286             }
 287         }
 288         return se.dispatched;
 289     }
 290 
 291     /*
 292      * Checks if the focus window event follows key events waiting in the type-ahead
 293      * queue (if any). This may happen when a user types ahead in the window, the client
 294      * listeners hang EDT for a while, and the user switches b/w toplevels. In that
 295      * case the focus window events may be dispatched before the type-ahead events


< prev index next >