< prev index next >

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

Print this page




 322      * This can be used to determine things like which EventQueue
 323      * to use for posting events to a Component.  If the target is
 324      * null or the target can't be found, a null with be returned.
 325      */
 326     public static AppContext targetToAppContext(Object target) {
 327         if (target == null) {
 328             return null;
 329         }
 330         AppContext context = getAppContext(target);
 331         if (context == null) {
 332             // target is not a Component/MenuComponent, try the
 333             // appContextMap.
 334             context = appContextMap.get(target);
 335         }
 336         return context;
 337     }
 338 
 339      /**
 340       * Sets the synchronous status of focus requests on lightweight
 341       * components in the specified window to the specified value.
 342       * If the boolean parameter is <code>true</code> then the focus
 343       * requests on lightweight components will be performed
 344       * synchronously, if it is <code>false</code>, then asynchronously.
 345       * By default, all windows have their lightweight request status
 346       * set to asynchronous.
 347       * <p>
 348       * The application can only set the status of lightweight focus
 349       * requests to synchronous for any of its windows if it doesn't
 350       * perform focus transfers between different heavyweight containers.
 351       * In this case the observable focus behaviour is the same as with
 352       * asynchronous status.
 353       * <p>
 354       * If the application performs focus transfer between different
 355       * heavyweight containers and sets the lightweight focus request
 356       * status to synchronous for any of its windows, then further focus
 357       * behaviour is unspecified.
 358       * <p>
 359       * @param    changed the window for which the lightweight focus request
 360       *           status should be set
 361       * @param    status the value of lightweight focus request status
 362       */
 363 
 364     public static void setLWRequestStatus(Window changed,boolean status){


 504             new PeerEvent(target, runnable, PeerEvent.PRIORITY_EVENT) {
 505                 @Override
 506                 public long getWhen() {
 507                     return when;
 508                 }
 509             });
 510     }
 511 
 512     /*
 513      * Execute a chunk of code on the Java event handler thread for the
 514      * given target.  Does not wait for the execution to occur before
 515      * returning to the caller.
 516      */
 517     public static void executeOnEventHandlerThread(PeerEvent peerEvent) {
 518         postEvent(targetToAppContext(peerEvent.getSource()), peerEvent);
 519     }
 520 
 521     /*
 522      * Execute a chunk of code on the Java event handler thread. The
 523      * method takes into account provided AppContext and sets
 524      * <code>SunToolkit.getDefaultToolkit()</code> as a target of the
 525      * event. See 6451487 for detailes.
 526      * Does not wait for the execution to occur before returning to
 527      * the caller.
 528      */
 529      public static void invokeLaterOnAppContext(
 530         AppContext appContext, Runnable dispatcher)
 531      {
 532         postEvent(appContext,
 533             new PeerEvent(Toolkit.getDefaultToolkit(), dispatcher,
 534                 PeerEvent.PRIORITY_EVENT));
 535      }
 536 
 537     /*
 538      * Execute a chunk of code on the Java event handler thread for the
 539      * given target.  Waits for the execution to occur before returning
 540      * to the caller.
 541      */
 542     public static void executeOnEDTAndWait(Object target, Runnable runnable)
 543         throws InterruptedException, InvocationTargetException
 544     {


1146      */
1147     @Override
1148     public Locale getDefaultKeyboardLocale() {
1149         return getStartupLocale();
1150     }
1151 
1152     private static DefaultMouseInfoPeer mPeer = null;
1153 
1154     @Override
1155     public synchronized MouseInfoPeer getMouseInfoPeer() {
1156         if (mPeer == null) {
1157             mPeer = new DefaultMouseInfoPeer();
1158         }
1159         return mPeer;
1160     }
1161 
1162 
1163     /**
1164      * Returns whether default toolkit needs the support of the xembed
1165      * from embedding host(if any).
1166      * @return <code>true</code>, if XEmbed is needed, <code>false</code> otherwise
1167      */
1168     public static boolean needsXEmbed() {
1169         String noxembed = AccessController.
1170             doPrivileged(new GetPropertyAction("sun.awt.noxembed", "false"));
1171         if ("true".equals(noxembed)) {
1172             return false;
1173         }
1174 
1175         Toolkit tk = Toolkit.getDefaultToolkit();
1176         if (tk instanceof SunToolkit) {
1177             // SunToolkit descendants should override this method to specify
1178             // concrete behavior
1179             return ((SunToolkit)tk).needsXEmbedImpl();
1180         } else {
1181             // Non-SunToolkit doubtly might support XEmbed
1182             return false;
1183         }
1184     }
1185 
1186     /**
1187      * Returns whether this toolkit needs the support of the xembed
1188      * from embedding host(if any).
1189      * @return <code>true</code>, if XEmbed is needed, <code>false</code> otherwise
1190      */
1191     protected boolean needsXEmbedImpl() {
1192         return false;
1193     }
1194 
1195     private static Dialog.ModalExclusionType DEFAULT_MODAL_EXCLUSION_TYPE = null;
1196 
1197     /**
1198      * Returns whether the XEmbed server feature is requested by
1199      * developer.  If true, Toolkit should return an
1200      * XEmbed-server-enabled CanvasPeer instead of the ordinary CanvasPeer.
1201      */
1202     protected final boolean isXEmbedServerRequested() {
1203         return AccessController.doPrivileged(new GetBooleanAction("sun.awt.xembedserver"));
1204     }
1205 
1206     /**
1207      * Returns whether the modal exclusion API is supported by the current toolkit.
1208      * When it isn't supported, calling <code>setModalExcluded</code> has no
1209      * effect, and <code>isModalExcluded</code> returns false for all windows.
1210      *
1211      * @return true if modal exclusion is supported by the toolkit, false otherwise
1212      *
1213      * @see sun.awt.SunToolkit#setModalExcluded(java.awt.Window)
1214      * @see sun.awt.SunToolkit#isModalExcluded(java.awt.Window)
1215      *
1216      * @since 1.5
1217      */
1218     public static boolean isModalExcludedSupported()
1219     {
1220         Toolkit tk = Toolkit.getDefaultToolkit();
1221         return tk.isModalExclusionTypeSupported(DEFAULT_MODAL_EXCLUSION_TYPE);
1222     }
1223     /*
1224      * Default implementation for isModalExcludedSupportedImpl(), returns false.
1225      *
1226      * @see sun.awt.windows.WToolkit#isModalExcludeSupportedImpl
1227      * @see sun.awt.X11.XToolkit#isModalExcludeSupportedImpl
1228      *
1229      * @since 1.5
1230      */
1231     protected boolean isModalExcludedSupportedImpl()
1232     {
1233         return false;
1234     }
1235 
1236     /*
1237      * Sets this window to be excluded from being modally blocked. When the
1238      * toolkit supports modal exclusion and this method is called, input
1239      * events, focus transfer and z-order will continue to work for the
1240      * window, it's owned windows and child components, even in the
1241      * presence of a modal dialog.
1242      * For details on which <code>Window</code>s are normally blocked
1243      * by modal dialog, see {@link java.awt.Dialog}.
1244      * Invoking this method when the modal exclusion API is not supported by
1245      * the current toolkit has no effect.
1246      * @param window Window to be marked as not modally blocked
1247      * @see java.awt.Dialog
1248      * @see java.awt.Dialog#setModal(boolean)
1249      * @see sun.awt.SunToolkit#isModalExcludedSupported
1250      * @see sun.awt.SunToolkit#isModalExcluded(java.awt.Window)
1251      */
1252     public static void setModalExcluded(Window window)
1253     {
1254         if (DEFAULT_MODAL_EXCLUSION_TYPE == null) {
1255             DEFAULT_MODAL_EXCLUSION_TYPE = Dialog.ModalExclusionType.APPLICATION_EXCLUDE;
1256         }
1257         window.setModalExclusionType(DEFAULT_MODAL_EXCLUSION_TYPE);
1258     }
1259 
1260     /*
1261      * Returns whether the specified window is blocked by modal dialogs.
1262      * If the modal exclusion API isn't supported by the current toolkit,


1411 
1412     /**
1413      * Parameterless version of realsync which uses default timout (see DEFAUL_WAIT_TIME).
1414      */
1415     public void realSync() throws OperationTimedOut, InfiniteLoop {
1416         realSync(DEFAULT_WAIT_TIME);
1417     }
1418 
1419     /**
1420      * Forces toolkit to synchronize with the native windowing
1421      * sub-system, flushing all pending work and waiting for all the
1422      * events to be processed.  This method guarantees that after
1423      * return no additional Java events will be generated, unless
1424      * cause by user. Obviously, the method cannot be used on the
1425      * event dispatch thread (EDT). In case it nevertheless gets
1426      * invoked on this thread, the method throws the
1427      * IllegalThreadException runtime exception.
1428      *
1429      * <p> This method allows to write tests without explicit timeouts
1430      * or wait for some event.  Example:
1431      * <code>
1432      * Frame f = ...;
1433      * f.setVisible(true);
1434      * ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
1435      * </code>
1436      *
1437      * <p> After realSync, <code>f</code> will be completely visible
1438      * on the screen, its getLocationOnScreen will be returning the
1439      * right result and it will be the focus owner.
1440      *
1441      * <p> Another example:
1442      * <code>
1443      * b.requestFocus();
1444      * ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
1445      * </code>
1446      *
1447      * <p> After realSync, <code>b</code> will be focus owner.
1448      *
1449      * <p> Notice that realSync isn't guaranteed to work if recurring
1450      * actions occur, such as if during processing of some event
1451      * another request which may generate some events occurs.  By
1452      * default, sync tries to perform as much as {@value #MAX_ITERS}
1453      * cycles of event processing, allowing for roughly {@value
1454      * #MAX_ITERS} additional requests.
1455      *
1456      * <p> For example, requestFocus() generates native request, which
1457      * generates one or two Java focus events, which then generate a
1458      * serie of paint events, a serie of Java focus events, which then
1459      * generate a serie of paint events which then are processed -
1460      * three cycles, minimum.
1461      *
1462      * @param timeout the maximum time to wait in milliseconds, negative means "forever".
1463      */
1464     public void realSync(final long timeout) throws OperationTimedOut, InfiniteLoop
1465     {
1466         if (EventQueue.isDispatchThread()) {
1467             throw new IllegalThreadException("The SunToolkit.realSync() method cannot be used on the event dispatch thread (EDT).");


1502             }
1503             while (waitForIdle(timeout) && iters < MAX_ITERS) {
1504                 iters++;
1505             }
1506             if (iters >= MAX_ITERS) {
1507                 throw new InfiniteLoop();
1508             }
1509 
1510             bigLoop++;
1511             // Again, for Java events, it was simple to check for new Java
1512             // events by checking event queue, but what if Java events
1513             // resulted in native requests?  Therefor, check native events again.
1514         } while ((syncNativeQueue(timeout) || waitForIdle(timeout)) && bigLoop < MAX_ITERS);
1515     }
1516 
1517     /**
1518      * Platform toolkits need to implement this method to perform the
1519      * sync of the native queue.  The method should wait until native
1520      * requests are processed, all native events are processed and
1521      * corresponding Java events are generated.  Should return
1522      * <code>true</code> if some events were processed,
1523      * <code>false</code> otherwise.
1524      */
1525     protected abstract boolean syncNativeQueue(final long timeout);
1526 
1527     private boolean eventDispatched = false;
1528     private boolean queueEmpty = false;
1529     private final Object waitLock = "Wait Lock";
1530 
1531     private boolean isEQEmpty() {
1532         EventQueue queue = getSystemEventQueueImpl();
1533         return AWTAccessor.getEventQueueAccessor().noEvents(queue);
1534     }
1535 
1536     /**
1537      * Waits for the Java event queue to empty.  Ensures that all
1538      * events are processed (including paint events), and that if
1539      * recursive events were generated, they are also processed.
1540      * Should return <code>true</code> if more processing is
1541      * necessary, <code>false</code> otherwise.
1542      */
1543     @SuppressWarnings("serial")
1544     protected final boolean waitForIdle(final long timeout) {
1545         flushPendingEvents();
1546         boolean queueWasEmpty = isEQEmpty();
1547         queueEmpty = false;
1548         eventDispatched = false;
1549         synchronized(waitLock) {
1550             postEvent(AppContext.getAppContext(),
1551                       new PeerEvent(getSystemEventQueueImpl(), null, PeerEvent.LOW_PRIORITY_EVENT) {
1552                           @Override
1553                           public void dispatch() {
1554                               // Here we block EDT.  It could have some
1555                               // events, it should have dispatched them by
1556                               // now.  So native requests could have been
1557                               // generated.  First, dispatch them.  Then,
1558                               // flush Java events again.
1559                               int iters = 0;
1560                               while (iters < MIN_ITERS) {
1561                                   syncNativeQueue(timeout);


1786     /*
1787      * consumeNextKeyTyped() method is not currently used,
1788      * however Swing could use it in the future.
1789      */
1790     public static synchronized void consumeNextKeyTyped(KeyEvent keyEvent) {
1791         try {
1792             AWTAccessor.getDefaultKeyboardFocusManagerAccessor().consumeNextKeyTyped(
1793                 (DefaultKeyboardFocusManager)KeyboardFocusManager.
1794                     getCurrentKeyboardFocusManager(),
1795                 keyEvent);
1796         } catch (ClassCastException cce) {
1797              cce.printStackTrace();
1798         }
1799     }
1800 
1801     protected static void dumpPeers(final PlatformLogger aLog) {
1802         AWTAutoShutdown.getInstance().dumpPeers(aLog);
1803     }
1804 
1805     /**
1806      * Returns the <code>Window</code> ancestor of the component <code>comp</code>.
1807      * @return Window ancestor of the component or component by itself if it is Window;
1808      *         null, if component is not a part of window hierarchy
1809      */
1810     public static Window getContainingWindow(Component comp) {
1811         while (comp != null && !(comp instanceof Window)) {
1812             comp = comp.getParent();
1813         }
1814         return (Window)comp;
1815     }
1816 
1817     private static Boolean sunAwtDisableMixing = null;
1818 
1819     /**
1820      * Returns the value of "sun.awt.disableMixing" property. Default
1821      * value is {@code false}.
1822      */
1823     public static synchronized boolean getSunAwtDisableMixing() {
1824         if (sunAwtDisableMixing == null) {
1825             sunAwtDisableMixing = AccessController.doPrivileged(
1826                                       new GetBooleanAction("sun.awt.disableMixing"));




 322      * This can be used to determine things like which EventQueue
 323      * to use for posting events to a Component.  If the target is
 324      * null or the target can't be found, a null with be returned.
 325      */
 326     public static AppContext targetToAppContext(Object target) {
 327         if (target == null) {
 328             return null;
 329         }
 330         AppContext context = getAppContext(target);
 331         if (context == null) {
 332             // target is not a Component/MenuComponent, try the
 333             // appContextMap.
 334             context = appContextMap.get(target);
 335         }
 336         return context;
 337     }
 338 
 339      /**
 340       * Sets the synchronous status of focus requests on lightweight
 341       * components in the specified window to the specified value.
 342       * If the boolean parameter is {@code true} then the focus
 343       * requests on lightweight components will be performed
 344       * synchronously, if it is {@code false}, then asynchronously.
 345       * By default, all windows have their lightweight request status
 346       * set to asynchronous.
 347       * <p>
 348       * The application can only set the status of lightweight focus
 349       * requests to synchronous for any of its windows if it doesn't
 350       * perform focus transfers between different heavyweight containers.
 351       * In this case the observable focus behaviour is the same as with
 352       * asynchronous status.
 353       * <p>
 354       * If the application performs focus transfer between different
 355       * heavyweight containers and sets the lightweight focus request
 356       * status to synchronous for any of its windows, then further focus
 357       * behaviour is unspecified.
 358       * <p>
 359       * @param    changed the window for which the lightweight focus request
 360       *           status should be set
 361       * @param    status the value of lightweight focus request status
 362       */
 363 
 364     public static void setLWRequestStatus(Window changed,boolean status){


 504             new PeerEvent(target, runnable, PeerEvent.PRIORITY_EVENT) {
 505                 @Override
 506                 public long getWhen() {
 507                     return when;
 508                 }
 509             });
 510     }
 511 
 512     /*
 513      * Execute a chunk of code on the Java event handler thread for the
 514      * given target.  Does not wait for the execution to occur before
 515      * returning to the caller.
 516      */
 517     public static void executeOnEventHandlerThread(PeerEvent peerEvent) {
 518         postEvent(targetToAppContext(peerEvent.getSource()), peerEvent);
 519     }
 520 
 521     /*
 522      * Execute a chunk of code on the Java event handler thread. The
 523      * method takes into account provided AppContext and sets
 524      * {@code SunToolkit.getDefaultToolkit()} as a target of the
 525      * event. See 6451487 for detailes.
 526      * Does not wait for the execution to occur before returning to
 527      * the caller.
 528      */
 529      public static void invokeLaterOnAppContext(
 530         AppContext appContext, Runnable dispatcher)
 531      {
 532         postEvent(appContext,
 533             new PeerEvent(Toolkit.getDefaultToolkit(), dispatcher,
 534                 PeerEvent.PRIORITY_EVENT));
 535      }
 536 
 537     /*
 538      * Execute a chunk of code on the Java event handler thread for the
 539      * given target.  Waits for the execution to occur before returning
 540      * to the caller.
 541      */
 542     public static void executeOnEDTAndWait(Object target, Runnable runnable)
 543         throws InterruptedException, InvocationTargetException
 544     {


1146      */
1147     @Override
1148     public Locale getDefaultKeyboardLocale() {
1149         return getStartupLocale();
1150     }
1151 
1152     private static DefaultMouseInfoPeer mPeer = null;
1153 
1154     @Override
1155     public synchronized MouseInfoPeer getMouseInfoPeer() {
1156         if (mPeer == null) {
1157             mPeer = new DefaultMouseInfoPeer();
1158         }
1159         return mPeer;
1160     }
1161 
1162 
1163     /**
1164      * Returns whether default toolkit needs the support of the xembed
1165      * from embedding host(if any).
1166      * @return {@code true}, if XEmbed is needed, {@code false} otherwise
1167      */
1168     public static boolean needsXEmbed() {
1169         String noxembed = AccessController.
1170             doPrivileged(new GetPropertyAction("sun.awt.noxembed", "false"));
1171         if ("true".equals(noxembed)) {
1172             return false;
1173         }
1174 
1175         Toolkit tk = Toolkit.getDefaultToolkit();
1176         if (tk instanceof SunToolkit) {
1177             // SunToolkit descendants should override this method to specify
1178             // concrete behavior
1179             return ((SunToolkit)tk).needsXEmbedImpl();
1180         } else {
1181             // Non-SunToolkit doubtly might support XEmbed
1182             return false;
1183         }
1184     }
1185 
1186     /**
1187      * Returns whether this toolkit needs the support of the xembed
1188      * from embedding host(if any).
1189      * @return {@code true}, if XEmbed is needed, {@code false} otherwise
1190      */
1191     protected boolean needsXEmbedImpl() {
1192         return false;
1193     }
1194 
1195     private static Dialog.ModalExclusionType DEFAULT_MODAL_EXCLUSION_TYPE = null;
1196 
1197     /**
1198      * Returns whether the XEmbed server feature is requested by
1199      * developer.  If true, Toolkit should return an
1200      * XEmbed-server-enabled CanvasPeer instead of the ordinary CanvasPeer.
1201      */
1202     protected final boolean isXEmbedServerRequested() {
1203         return AccessController.doPrivileged(new GetBooleanAction("sun.awt.xembedserver"));
1204     }
1205 
1206     /**
1207      * Returns whether the modal exclusion API is supported by the current toolkit.
1208      * When it isn't supported, calling {@code setModalExcluded} has no
1209      * effect, and {@code isModalExcluded} returns false for all windows.
1210      *
1211      * @return true if modal exclusion is supported by the toolkit, false otherwise
1212      *
1213      * @see sun.awt.SunToolkit#setModalExcluded(java.awt.Window)
1214      * @see sun.awt.SunToolkit#isModalExcluded(java.awt.Window)
1215      *
1216      * @since 1.5
1217      */
1218     public static boolean isModalExcludedSupported()
1219     {
1220         Toolkit tk = Toolkit.getDefaultToolkit();
1221         return tk.isModalExclusionTypeSupported(DEFAULT_MODAL_EXCLUSION_TYPE);
1222     }
1223     /*
1224      * Default implementation for isModalExcludedSupportedImpl(), returns false.
1225      *
1226      * @see sun.awt.windows.WToolkit#isModalExcludeSupportedImpl
1227      * @see sun.awt.X11.XToolkit#isModalExcludeSupportedImpl
1228      *
1229      * @since 1.5
1230      */
1231     protected boolean isModalExcludedSupportedImpl()
1232     {
1233         return false;
1234     }
1235 
1236     /*
1237      * Sets this window to be excluded from being modally blocked. When the
1238      * toolkit supports modal exclusion and this method is called, input
1239      * events, focus transfer and z-order will continue to work for the
1240      * window, it's owned windows and child components, even in the
1241      * presence of a modal dialog.
1242      * For details on which {@code Window}s are normally blocked
1243      * by modal dialog, see {@link java.awt.Dialog}.
1244      * Invoking this method when the modal exclusion API is not supported by
1245      * the current toolkit has no effect.
1246      * @param window Window to be marked as not modally blocked
1247      * @see java.awt.Dialog
1248      * @see java.awt.Dialog#setModal(boolean)
1249      * @see sun.awt.SunToolkit#isModalExcludedSupported
1250      * @see sun.awt.SunToolkit#isModalExcluded(java.awt.Window)
1251      */
1252     public static void setModalExcluded(Window window)
1253     {
1254         if (DEFAULT_MODAL_EXCLUSION_TYPE == null) {
1255             DEFAULT_MODAL_EXCLUSION_TYPE = Dialog.ModalExclusionType.APPLICATION_EXCLUDE;
1256         }
1257         window.setModalExclusionType(DEFAULT_MODAL_EXCLUSION_TYPE);
1258     }
1259 
1260     /*
1261      * Returns whether the specified window is blocked by modal dialogs.
1262      * If the modal exclusion API isn't supported by the current toolkit,


1411 
1412     /**
1413      * Parameterless version of realsync which uses default timout (see DEFAUL_WAIT_TIME).
1414      */
1415     public void realSync() throws OperationTimedOut, InfiniteLoop {
1416         realSync(DEFAULT_WAIT_TIME);
1417     }
1418 
1419     /**
1420      * Forces toolkit to synchronize with the native windowing
1421      * sub-system, flushing all pending work and waiting for all the
1422      * events to be processed.  This method guarantees that after
1423      * return no additional Java events will be generated, unless
1424      * cause by user. Obviously, the method cannot be used on the
1425      * event dispatch thread (EDT). In case it nevertheless gets
1426      * invoked on this thread, the method throws the
1427      * IllegalThreadException runtime exception.
1428      *
1429      * <p> This method allows to write tests without explicit timeouts
1430      * or wait for some event.  Example:
1431      * <pre>{@code
1432      * Frame f = ...;
1433      * f.setVisible(true);
1434      * ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
1435      * }</pre>
1436      *
1437      * <p> After realSync, {@code f} will be completely visible
1438      * on the screen, its getLocationOnScreen will be returning the
1439      * right result and it will be the focus owner.
1440      *
1441      * <p> Another example:
1442      * <pre>{@code
1443      * b.requestFocus();
1444      * ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
1445      * }</pre>
1446      *
1447      * <p> After realSync, {@code b} will be focus owner.
1448      *
1449      * <p> Notice that realSync isn't guaranteed to work if recurring
1450      * actions occur, such as if during processing of some event
1451      * another request which may generate some events occurs.  By
1452      * default, sync tries to perform as much as {@value #MAX_ITERS}
1453      * cycles of event processing, allowing for roughly {@value
1454      * #MAX_ITERS} additional requests.
1455      *
1456      * <p> For example, requestFocus() generates native request, which
1457      * generates one or two Java focus events, which then generate a
1458      * serie of paint events, a serie of Java focus events, which then
1459      * generate a serie of paint events which then are processed -
1460      * three cycles, minimum.
1461      *
1462      * @param timeout the maximum time to wait in milliseconds, negative means "forever".
1463      */
1464     public void realSync(final long timeout) throws OperationTimedOut, InfiniteLoop
1465     {
1466         if (EventQueue.isDispatchThread()) {
1467             throw new IllegalThreadException("The SunToolkit.realSync() method cannot be used on the event dispatch thread (EDT).");


1502             }
1503             while (waitForIdle(timeout) && iters < MAX_ITERS) {
1504                 iters++;
1505             }
1506             if (iters >= MAX_ITERS) {
1507                 throw new InfiniteLoop();
1508             }
1509 
1510             bigLoop++;
1511             // Again, for Java events, it was simple to check for new Java
1512             // events by checking event queue, but what if Java events
1513             // resulted in native requests?  Therefor, check native events again.
1514         } while ((syncNativeQueue(timeout) || waitForIdle(timeout)) && bigLoop < MAX_ITERS);
1515     }
1516 
1517     /**
1518      * Platform toolkits need to implement this method to perform the
1519      * sync of the native queue.  The method should wait until native
1520      * requests are processed, all native events are processed and
1521      * corresponding Java events are generated.  Should return
1522      * {@code true} if some events were processed,
1523      * {@code false} otherwise.
1524      */
1525     protected abstract boolean syncNativeQueue(final long timeout);
1526 
1527     private boolean eventDispatched = false;
1528     private boolean queueEmpty = false;
1529     private final Object waitLock = "Wait Lock";
1530 
1531     private boolean isEQEmpty() {
1532         EventQueue queue = getSystemEventQueueImpl();
1533         return AWTAccessor.getEventQueueAccessor().noEvents(queue);
1534     }
1535 
1536     /**
1537      * Waits for the Java event queue to empty.  Ensures that all
1538      * events are processed (including paint events), and that if
1539      * recursive events were generated, they are also processed.
1540      * Should return {@code true} if more processing is
1541      * necessary, {@code false} otherwise.
1542      */
1543     @SuppressWarnings("serial")
1544     protected final boolean waitForIdle(final long timeout) {
1545         flushPendingEvents();
1546         boolean queueWasEmpty = isEQEmpty();
1547         queueEmpty = false;
1548         eventDispatched = false;
1549         synchronized(waitLock) {
1550             postEvent(AppContext.getAppContext(),
1551                       new PeerEvent(getSystemEventQueueImpl(), null, PeerEvent.LOW_PRIORITY_EVENT) {
1552                           @Override
1553                           public void dispatch() {
1554                               // Here we block EDT.  It could have some
1555                               // events, it should have dispatched them by
1556                               // now.  So native requests could have been
1557                               // generated.  First, dispatch them.  Then,
1558                               // flush Java events again.
1559                               int iters = 0;
1560                               while (iters < MIN_ITERS) {
1561                                   syncNativeQueue(timeout);


1786     /*
1787      * consumeNextKeyTyped() method is not currently used,
1788      * however Swing could use it in the future.
1789      */
1790     public static synchronized void consumeNextKeyTyped(KeyEvent keyEvent) {
1791         try {
1792             AWTAccessor.getDefaultKeyboardFocusManagerAccessor().consumeNextKeyTyped(
1793                 (DefaultKeyboardFocusManager)KeyboardFocusManager.
1794                     getCurrentKeyboardFocusManager(),
1795                 keyEvent);
1796         } catch (ClassCastException cce) {
1797              cce.printStackTrace();
1798         }
1799     }
1800 
1801     protected static void dumpPeers(final PlatformLogger aLog) {
1802         AWTAutoShutdown.getInstance().dumpPeers(aLog);
1803     }
1804 
1805     /**
1806      * Returns the {@code Window} ancestor of the component {@code comp}.
1807      * @return Window ancestor of the component or component by itself if it is Window;
1808      *         null, if component is not a part of window hierarchy
1809      */
1810     public static Window getContainingWindow(Component comp) {
1811         while (comp != null && !(comp instanceof Window)) {
1812             comp = comp.getParent();
1813         }
1814         return (Window)comp;
1815     }
1816 
1817     private static Boolean sunAwtDisableMixing = null;
1818 
1819     /**
1820      * Returns the value of "sun.awt.disableMixing" property. Default
1821      * value is {@code false}.
1822      */
1823     public static synchronized boolean getSunAwtDisableMixing() {
1824         if (sunAwtDisableMixing == null) {
1825             sunAwtDisableMixing = AccessController.doPrivileged(
1826                                       new GetBooleanAction("sun.awt.disableMixing"));


< prev index next >