< prev index next >

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

Print this page




 841     }
 842 
 843     /**
 844      * Returns the event currently being dispatched by the
 845      * {@code EventQueue} associated with the calling thread. This is
 846      * useful if a method needs access to the event, but was not designed to
 847      * receive a reference to it as an argument. Note that this method should
 848      * only be invoked from an application's event dispatching thread. If this
 849      * method is invoked from another thread, null will be returned.
 850      *
 851      * @return the event currently being dispatched, or null if this method is
 852      *         invoked on a thread other than an event dispatching thread
 853      * @since 1.4
 854      */
 855     public static AWTEvent getCurrentEvent() {
 856         return Toolkit.getEventQueue().getCurrentEventImpl();
 857     }
 858     private AWTEvent getCurrentEventImpl() {
 859         pushPopLock.lock();
 860         try {
 861             if (fxAppThreadIsDispatchThread) {

 862                 return (currentEvent != null)
 863                         ? currentEvent.get()
 864                         : null;
 865             } else {
 866                 return (Thread.currentThread() == dispatchThread)
 867                         ? currentEvent.get()
 868                         : null;
 869             }

 870         } finally {
 871             pushPopLock.unlock();
 872         }
 873     }
 874 
 875     /**
 876      * Replaces the existing {@code EventQueue} with the specified one.
 877      * Any pending events are transferred to the new {@code EventQueue}
 878      * for processing by it.
 879      *
 880      * @param newEventQueue an {@code EventQueue}
 881      *          (or subclass thereof) instance to be use
 882      * @see      java.awt.EventQueue#pop
 883      * @throws NullPointerException if {@code newEventQueue} is {@code null}
 884      * @since           1.2
 885      */
 886     public void push(EventQueue newEventQueue) {
 887         if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) {
 888             getEventLog().fine("EventQueue.push(" + newEventQueue + ")");
 889         }




 841     }
 842 
 843     /**
 844      * Returns the event currently being dispatched by the
 845      * {@code EventQueue} associated with the calling thread. This is
 846      * useful if a method needs access to the event, but was not designed to
 847      * receive a reference to it as an argument. Note that this method should
 848      * only be invoked from an application's event dispatching thread. If this
 849      * method is invoked from another thread, null will be returned.
 850      *
 851      * @return the event currently being dispatched, or null if this method is
 852      *         invoked on a thread other than an event dispatching thread
 853      * @since 1.4
 854      */
 855     public static AWTEvent getCurrentEvent() {
 856         return Toolkit.getEventQueue().getCurrentEventImpl();
 857     }
 858     private AWTEvent getCurrentEventImpl() {
 859         pushPopLock.lock();
 860         try {
 861             if (Thread.currentThread() == dispatchThread
 862                     || fxAppThreadIsDispatchThread) {
 863                 return (currentEvent != null)
 864                         ? currentEvent.get()
 865                         : null;




 866             }
 867             return null;
 868         } finally {
 869             pushPopLock.unlock();
 870         }
 871     }
 872 
 873     /**
 874      * Replaces the existing {@code EventQueue} with the specified one.
 875      * Any pending events are transferred to the new {@code EventQueue}
 876      * for processing by it.
 877      *
 878      * @param newEventQueue an {@code EventQueue}
 879      *          (or subclass thereof) instance to be use
 880      * @see      java.awt.EventQueue#pop
 881      * @throws NullPointerException if {@code newEventQueue} is {@code null}
 882      * @since           1.2
 883      */
 884     public void push(EventQueue newEventQueue) {
 885         if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) {
 886             getEventLog().fine("EventQueue.push(" + newEventQueue + ")");
 887         }


< prev index next >