src/share/classes/sun/awt/SunToolkit.java

Print this page




 527             (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
 528         if (postEventQueue != null) {
 529             postEventQueue.postEvent(event);
 530         }
 531     }
 532 
 533     /*
 534      * Post AWTEvent of high priority.
 535      */
 536     public static void postPriorityEvent(final AWTEvent e) {
 537         PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() {
 538                 public void run() {
 539                     AWTAccessor.getAWTEventAccessor().setPosted(e);
 540                     ((Component)e.getSource()).dispatchEvent(e);
 541                 }
 542             }, PeerEvent.ULTIMATE_PRIORITY_EVENT);
 543         postEvent(targetToAppContext(e.getSource()), pe);
 544     }
 545 
 546     protected static final Lock flushLock = new ReentrantLock();
 547     private static boolean isFlushingPendingEvents = false;
 548 
 549     /*
 550      * Flush any pending events which haven't been posted to the AWT
 551      * EventQueue yet.
 552      */
 553     public static void flushPendingEvents()  {
 554         flushLock.lock();
 555         try {
 556             // Don't call flushPendingEvents() recursively
 557             if (!isFlushingPendingEvents) {
 558                 isFlushingPendingEvents = true;
 559                 AppContext appContext = AppContext.getAppContext();
 560                 PostEventQueue postEventQueue =
 561                     (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
 562                 if (postEventQueue != null) {
 563                     postEventQueue.flush();
 564                 }
 565             }
 566         } finally {
 567             isFlushingPendingEvents = false;
 568             flushLock.unlock();
 569         }
 570     }
 571 
 572     public static boolean isPostEventQueueEmpty()  {
 573         AppContext appContext = AppContext.getAppContext();
 574         PostEventQueue postEventQueue =
 575             (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
 576         if (postEventQueue != null) {
 577             return postEventQueue.noEvents();
 578         } else {
 579             return true;
 580         }
 581     }
 582 
 583     /*
 584      * Execute a chunk of code on the Java event handler thread for the
 585      * given target.  Does not wait for the execution to occur before
 586      * returning to the caller.
 587      */




 527             (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
 528         if (postEventQueue != null) {
 529             postEventQueue.postEvent(event);
 530         }
 531     }
 532 
 533     /*
 534      * Post AWTEvent of high priority.
 535      */
 536     public static void postPriorityEvent(final AWTEvent e) {
 537         PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() {
 538                 public void run() {
 539                     AWTAccessor.getAWTEventAccessor().setPosted(e);
 540                     ((Component)e.getSource()).dispatchEvent(e);
 541                 }
 542             }, PeerEvent.ULTIMATE_PRIORITY_EVENT);
 543         postEvent(targetToAppContext(e.getSource()), pe);
 544     }
 545 
 546     protected static final Lock flushLock = new ReentrantLock();
 547     private static int flushNestingLevel = 0;
 548 
 549     /*
 550      * Flush any pending events which haven't been posted to the AWT
 551      * EventQueue yet.
 552      */
 553     public static void flushPendingEvents()  {
 554         flushLock.lock();
 555         try {
 556             // Don't call flushPendingEvents() recursively
 557             ++flushNestingLevel;
 558             if (flushNestingLevel == 1) {
 559                 AppContext appContext = AppContext.getAppContext();
 560                 PostEventQueue postEventQueue =
 561                     (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
 562                 if (postEventQueue != null) {
 563                     postEventQueue.flush();
 564                 }
 565             }
 566         } finally {
 567             --flushNestingLevel;
 568             flushLock.unlock();
 569         }
 570     }
 571 
 572     public static boolean isPostEventQueueEmpty()  {
 573         AppContext appContext = AppContext.getAppContext();
 574         PostEventQueue postEventQueue =
 575             (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
 576         if (postEventQueue != null) {
 577             return postEventQueue.noEvents();
 578         } else {
 579             return true;
 580         }
 581     }
 582 
 583     /*
 584      * Execute a chunk of code on the Java event handler thread for the
 585      * given target.  Does not wait for the execution to occur before
 586      * returning to the caller.
 587      */