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

Print this page




 441       * The application can only set the status of lightweight focus
 442       * requests to synchronous for any of its windows if it doesn't
 443       * perform focus transfers between different heavyweight containers.
 444       * In this case the observable focus behaviour is the same as with
 445       * asynchronous status.
 446       * <p>
 447       * If the application performs focus transfer between different
 448       * heavyweight containers and sets the lightweight focus request
 449       * status to synchronous for any of its windows, then further focus
 450       * behaviour is unspecified.
 451       * <p>
 452       * @param    w window for which the lightweight focus request status
 453       *             should be set
 454       * @param    status the value of lightweight focus request status
 455       */
 456 
 457     public static void setLWRequestStatus(Window changed,boolean status){
 458         AWTAccessor.getWindowAccessor().setLWRequestStatus(changed, status);
 459     };
 460 
 461     public static void checkAndSetPolicy(Container cont, boolean isSwingCont)
 462     {
 463         FocusTraversalPolicy defaultPolicy = KeyboardFocusManager
 464             .getCurrentKeyboardFocusManager().getDefaultFocusTraversalPolicy();
 465 
 466         String toolkitName = Toolkit.getDefaultToolkit().getClass().getName();
 467         // if this is not XAWT then use default policy
 468         // because Swing change it
 469         if (!"sun.awt.X11.XToolkit".equals(toolkitName)) {
 470             cont.setFocusTraversalPolicy(defaultPolicy);
 471             return;
 472         }
 473 
 474         String policyName = defaultPolicy.getClass().getName();
 475 
 476         if (DefaultFocusTraversalPolicy.class != defaultPolicy.getClass()) {
 477             // Policy was changed
 478             // Check if it is awt policy or swing policy
 479             // If it is Swing policy we shouldn't use it in AWT frames
 480             // If it is AWT policy  we shouldn't use it in Swing frames
 481             // Otherwise we should use this policy
 482             if (policyName.startsWith("java.awt.")) {
 483                 // AWT
 484                 if (isSwingCont) {
 485                     // Can't use AWT policy in Swing windows - should use Swing's one.
 486                     defaultPolicy = createLayoutPolicy();
 487                 } else {
 488                     // New awt policy.
 489                 }
 490             } else if (policyName.startsWith("javax.swing.")) {
 491                 if (isSwingCont) {
 492                     // New Swing's policy
 493                 } else {
 494                     defaultPolicy = new DefaultFocusTraversalPolicy();
 495                 }
 496             }
 497         } else {
 498             // Policy is default, use different default policy for swing
 499             if (isSwingCont) {
 500                 defaultPolicy = createLayoutPolicy();
 501             }
 502         }
 503         cont.setFocusTraversalPolicy(defaultPolicy);
 504     }
 505 
 506     private static FocusTraversalPolicy createLayoutPolicy() {
 507         FocusTraversalPolicy policy = null;
 508         try {
 509             Class layoutPolicyClass =
 510                 Class.forName("javax.swing.LayoutFocusTraversalPolicy");
 511             policy = (FocusTraversalPolicy) layoutPolicyClass.newInstance();
 512         }
 513         catch (ClassNotFoundException e) {
 514             assert false;
 515         }
 516         catch (InstantiationException e) {
 517             assert false;
 518         }
 519         catch (IllegalAccessException e) {
 520             assert false;
 521         }
 522 




 441       * The application can only set the status of lightweight focus
 442       * requests to synchronous for any of its windows if it doesn't
 443       * perform focus transfers between different heavyweight containers.
 444       * In this case the observable focus behaviour is the same as with
 445       * asynchronous status.
 446       * <p>
 447       * If the application performs focus transfer between different
 448       * heavyweight containers and sets the lightweight focus request
 449       * status to synchronous for any of its windows, then further focus
 450       * behaviour is unspecified.
 451       * <p>
 452       * @param    w window for which the lightweight focus request status
 453       *             should be set
 454       * @param    status the value of lightweight focus request status
 455       */
 456 
 457     public static void setLWRequestStatus(Window changed,boolean status){
 458         AWTAccessor.getWindowAccessor().setLWRequestStatus(changed, status);
 459     };
 460 
 461     public static void checkAndSetPolicy(Container cont) {        
 462         FocusTraversalPolicy defaultPolicy = KeyboardFocusManager.
 463             getCurrentKeyboardFocusManager().
 464                 getDefaultFocusTraversalPolicy();








 465 





























 466         cont.setFocusTraversalPolicy(defaultPolicy);
 467     }
 468 
 469     private static FocusTraversalPolicy createLayoutPolicy() {
 470         FocusTraversalPolicy policy = null;
 471         try {
 472             Class layoutPolicyClass =
 473                 Class.forName("javax.swing.LayoutFocusTraversalPolicy");
 474             policy = (FocusTraversalPolicy) layoutPolicyClass.newInstance();
 475         }
 476         catch (ClassNotFoundException e) {
 477             assert false;
 478         }
 479         catch (InstantiationException e) {
 480             assert false;
 481         }
 482         catch (IllegalAccessException e) {
 483             assert false;
 484         }
 485