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

Print this page




 369      */
 370     private static AppContext getAppContext(Object target) {
 371         if (target instanceof Component) {
 372             return AWTAccessor.getComponentAccessor().
 373                        getAppContext((Component)target);
 374         } else if (target instanceof MenuComponent) {
 375             return AWTAccessor.getMenuComponentAccessor().
 376                        getAppContext((MenuComponent)target);
 377         } else {
 378             return null;
 379         }
 380     }
 381 
 382     /*
 383      * Fetch the AppContext associated with the given target.
 384      * This can be used to determine things like which EventQueue
 385      * to use for posting events to a Component.  If the target is
 386      * null or the target can't be found, a null with be returned.
 387      */
 388     public static AppContext targetToAppContext(Object target) {
 389         if (target == null || GraphicsEnvironment.isHeadless()) {
 390             return null;
 391         }
 392         AppContext context = getAppContext(target);
 393         if (context == null) {
 394             // target is not a Component/MenuComponent, try the
 395             // appContextMap.
 396             context = appContextMap.get(target);
 397         }
 398         return context;
 399     }
 400 
 401      /**
 402       * Sets the synchronous status of focus requests on lightweight
 403       * components in the specified window to the specified value.
 404       * If the boolean parameter is <code>true</code> then the focus
 405       * requests on lightweight components will be performed
 406       * synchronously, if it is <code>false</code>, then asynchronously.
 407       * By default, all windows have their lightweight request status
 408       * set to asynchronous.
 409       * <p>


 443             policy = (FocusTraversalPolicy)layoutPolicyClass.newInstance();
 444         }
 445         catch (ClassNotFoundException e) {
 446             assert false;
 447         }
 448         catch (InstantiationException e) {
 449             assert false;
 450         }
 451         catch (IllegalAccessException e) {
 452             assert false;
 453         }
 454 
 455         return policy;
 456     }
 457 
 458     /*
 459      * Insert a mapping from target to AppContext, for later retrieval
 460      * via targetToAppContext() above.
 461      */
 462     public static void insertTargetMapping(Object target, AppContext appContext) {
 463         if (!GraphicsEnvironment.isHeadless()) {
 464             if (!setAppContext(target, appContext)) {
 465                 // Target is not a Component/MenuComponent, use the private Map
 466                 // instead.
 467                 appContextMap.put(target, appContext);
 468             }
 469         }
 470     }
 471 
 472     /*
 473      * Post an AWTEvent to the Java EventQueue, using the PostEventQueue
 474      * to avoid possibly calling client code (EventQueueSubclass.postEvent())
 475      * on the toolkit (AWT-Windows/AWT-Motif) thread.  This function should
 476      * not be called under another lock since it locks the EventQueue.
 477      * See bugids 4632918, 4526597.
 478      */
 479     public static void postEvent(AppContext appContext, AWTEvent event) {
 480         if (event == null) {
 481             throw new NullPointerException();
 482         }
 483 
 484         AWTAccessor.SequencedEventAccessor sea = AWTAccessor.getSequencedEventAccessor();
 485         if (sea != null && sea.isSequencedEvent(event)) {
 486             AWTEvent nested = sea.getNested(event);
 487             if (nested.getID() == WindowEvent.WINDOW_LOST_FOCUS &&
 488                 nested instanceof TimedWindowEvent)
 489             {
 490                 TimedWindowEvent twe = (TimedWindowEvent)nested;




 369      */
 370     private static AppContext getAppContext(Object target) {
 371         if (target instanceof Component) {
 372             return AWTAccessor.getComponentAccessor().
 373                        getAppContext((Component)target);
 374         } else if (target instanceof MenuComponent) {
 375             return AWTAccessor.getMenuComponentAccessor().
 376                        getAppContext((MenuComponent)target);
 377         } else {
 378             return null;
 379         }
 380     }
 381 
 382     /*
 383      * Fetch the AppContext associated with the given target.
 384      * This can be used to determine things like which EventQueue
 385      * to use for posting events to a Component.  If the target is
 386      * null or the target can't be found, a null with be returned.
 387      */
 388     public static AppContext targetToAppContext(Object target) {
 389         if (target == null) {
 390             return null;
 391         }
 392         AppContext context = getAppContext(target);
 393         if (context == null) {
 394             // target is not a Component/MenuComponent, try the
 395             // appContextMap.
 396             context = appContextMap.get(target);
 397         }
 398         return context;
 399     }
 400 
 401      /**
 402       * Sets the synchronous status of focus requests on lightweight
 403       * components in the specified window to the specified value.
 404       * If the boolean parameter is <code>true</code> then the focus
 405       * requests on lightweight components will be performed
 406       * synchronously, if it is <code>false</code>, then asynchronously.
 407       * By default, all windows have their lightweight request status
 408       * set to asynchronous.
 409       * <p>


 443             policy = (FocusTraversalPolicy)layoutPolicyClass.newInstance();
 444         }
 445         catch (ClassNotFoundException e) {
 446             assert false;
 447         }
 448         catch (InstantiationException e) {
 449             assert false;
 450         }
 451         catch (IllegalAccessException e) {
 452             assert false;
 453         }
 454 
 455         return policy;
 456     }
 457 
 458     /*
 459      * Insert a mapping from target to AppContext, for later retrieval
 460      * via targetToAppContext() above.
 461      */
 462     public static void insertTargetMapping(Object target, AppContext appContext) {

 463         if (!setAppContext(target, appContext)) {
 464             // Target is not a Component/MenuComponent, use the private Map
 465             // instead.
 466             appContextMap.put(target, appContext);
 467         }
 468     }

 469 
 470     /*
 471      * Post an AWTEvent to the Java EventQueue, using the PostEventQueue
 472      * to avoid possibly calling client code (EventQueueSubclass.postEvent())
 473      * on the toolkit (AWT-Windows/AWT-Motif) thread.  This function should
 474      * not be called under another lock since it locks the EventQueue.
 475      * See bugids 4632918, 4526597.
 476      */
 477     public static void postEvent(AppContext appContext, AWTEvent event) {
 478         if (event == null) {
 479             throw new NullPointerException();
 480         }
 481 
 482         AWTAccessor.SequencedEventAccessor sea = AWTAccessor.getSequencedEventAccessor();
 483         if (sea != null && sea.isSequencedEvent(event)) {
 484             AWTEvent nested = sea.getNested(event);
 485             if (nested.getID() == WindowEvent.WINDOW_LOST_FOCUS &&
 486                 nested instanceof TimedWindowEvent)
 487             {
 488                 TimedWindowEvent twe = (TimedWindowEvent)nested;