src/share/classes/java/awt/EventDispatchThread.java

Print this page

        

*** 32,43 **** import java.lang.reflect.Method; import java.security.AccessController; import sun.security.action.GetPropertyAction; import sun.awt.AWTAutoShutdown; import sun.awt.SunToolkit; ! import java.util.Vector; import sun.util.logging.PlatformLogger; import sun.awt.dnd.SunDragSourceContextPeer; import sun.awt.EventQueueDelegate; --- 32,45 ---- import java.lang.reflect.Method; import java.security.AccessController; import sun.security.action.GetPropertyAction; import sun.awt.AWTAutoShutdown; import sun.awt.SunToolkit; + import sun.awt.AppContext; ! import java.util.ArrayList; ! import java.util.List; import sun.util.logging.PlatformLogger; import sun.awt.dnd.SunDragSourceContextPeer; import sun.awt.EventQueueDelegate;
*** 64,78 **** private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventDispatchThread"); private EventQueue theQueue; private boolean doDispatch = true; ! private boolean threadDeathCaught = false; private static final int ANY_EVENT = -1; ! private Vector<EventFilter> eventFilters = new Vector<EventFilter>(); EventDispatchThread(ThreadGroup group, String name, EventQueue queue) { super(group, name); setEventQueue(queue); } --- 66,80 ---- private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventDispatchThread"); private EventQueue theQueue; private boolean doDispatch = true; ! private volatile boolean shutdown = false; private static final int ANY_EVENT = -1; ! private ArrayList<EventFilter> eventFilters = new ArrayList<EventFilter>(); EventDispatchThread(ThreadGroup group, String name, EventQueue queue) { super(group, name); setEventQueue(queue); }
*** 82,102 **** */ public void stopDispatching() { doDispatch = false; } public void run() { while (true) { try { pumpEvents(new Conditional() { public boolean evaluate() { return true; } }); } finally { ! EventQueue eq = getEventQueue(); ! if (eq.detachDispatchThread(this) || threadDeathCaught) { break; } } } } --- 84,108 ---- */ public void stopDispatching() { doDispatch = false; } + public void interrupt() { + shutdown = true; + super.interrupt(); + } + public void run() { while (true) { try { pumpEvents(new Conditional() { public boolean evaluate() { return true; } }); } finally { ! if(getEventQueue().detachDispatchThread(this, shutdown)) { break; } } } }
*** 122,135 **** } void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) { addEventFilter(filter); doDispatch = true; ! while (doDispatch && cond.evaluate()) { ! if (isInterrupted() || !pumpOneEventForFilters(id)) { ! doDispatch = false; ! } } removeEventFilter(filter); } void addEventFilter(EventFilter filter) { --- 128,139 ---- } void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) { addEventFilter(filter); doDispatch = true; ! while (doDispatch && !shutdown && cond.evaluate()) { ! pumpOneEventForFilters(id); } removeEventFilter(filter); } void addEventFilter(EventFilter filter) {
*** 161,171 **** synchronized (eventFilters) { eventFilters.remove(filter); } } ! boolean pumpOneEventForFilters(int id) { AWTEvent event = null; boolean eventOK = false; try { EventQueue eq = null; EventQueueDelegate.Delegate delegate = null; --- 165,175 ---- synchronized (eventFilters) { eventFilters.remove(filter); } } ! void pumpOneEventForFilters(int id) { AWTEvent event = null; boolean eventOK = false; try { EventQueue eq = null; EventQueueDelegate.Delegate delegate = null;
*** 210,237 **** } eq.dispatchEvent(event); if (delegate != null) { delegate.afterDispatch(event, handle); } - - return true; } catch (ThreadDeath death) { ! threadDeathCaught = true; ! return false; ! } catch (InterruptedException interruptedException) { ! return false; // AppContext.dispose() interrupts all // Threads in the AppContext - } catch (Throwable e) { processException(e); } - - return true; } private void processException(Throwable e) { if (eventLog.isLoggable(PlatformLogger.FINE)) { eventLog.fine("Processing exception: " + e); --- 214,235 ---- } eq.dispatchEvent(event); if (delegate != null) { delegate.afterDispatch(event, handle); } } catch (ThreadDeath death) { ! shutdown = true; ! throw death; } catch (InterruptedException interruptedException) { ! shutdown = true; // AppContext.dispose() interrupts all // Threads in the AppContext } catch (Throwable e) { processException(e); } } private void processException(Throwable e) { if (eventLog.isLoggable(PlatformLogger.FINE)) { eventLog.fine("Processing exception: " + e);