long lastPaintTime = System.currentTimeMillis();
while (!shutdownPending && (context == null || context.isModalLoopRunning())) {
try {
EventQueue eventQueue = toolkit.getSystemEventQueueImpl();
NativeEvent ne = nativeQueue.getNextEvent();
if (ne != null) {
dispatcher.onEvent(ne);
MarkerEvent marker = new MarkerEvent(this, 0);
eventQueue.postEvent(marker);
for (AWTEvent ae = eventQueue.getNextEventNoWait();
(ae != null) && (ae != marker);
ae = eventQueue.getNextEventNoWait()) {
eventQueue.dispatchEvent(ae);
}
} else {
toolkit.shutdownWatchdog.setNativeQueueEmpty(true);
AWTEvent ae = eventQueue.getNextEventNoWait();
if (ae != null) {
eventQueue.dispatchEvent(ae);
long curTime = System.currentTimeMillis();
if (curTime - lastPaintTime > 10) {
toolkit.onQueueEmpty();
lastPaintTime = System.currentTimeMillis();
}
} else {
toolkit.shutdownWatchdog.setAwtQueueEmpty(true);
toolkit.onQueueEmpty();
lastPaintTime = System.currentTimeMillis();
waitForAnyEvent();
}
}
} catch (Throwable t) {
// TODO: Exception handler should be implemented
// t.printStackTrace();
}
}