< prev index next >

test/jdk/java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusSetVisibleTest.java

Print this page


   1 /*
   2  * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  52     static Button ownWinButton;
  53     static Dialog ownedDialog;
  54     static Button ownDlgButton;
  55     static Dialog dialog;
  56     static Button dlgButton;
  57 
  58     static String toolkitClassName;
  59     static Robot robot = Util.createRobot();
  60 
  61     public static void main(String[] args) {
  62         AutoRequestFocusSetVisibleTest app = new AutoRequestFocusSetVisibleTest();
  63         app.init();
  64         app.start();
  65     }
  66 
  67     public void init() {
  68         // Create instructions for the user here, as well as set up
  69         // the environment -- set the layout manager, add buttons,
  70         // etc.
  71         this.setLayout (new BorderLayout ());
  72         Sysout.createDialogWithInstructions(new String[]
  73             {"This is an automatic test. Simply wait until it is done."
  74             });
  75         toolkitClassName = Toolkit.getDefaultToolkit().getClass().getName();
  76     }
  77 
  78     void recreateGUI() {
  79         if (focusedFrame != null) {
  80             focusedFrame.dispose();
  81             frame.dispose();
  82             frame2.dispose();
  83             window.dispose();
  84             ownedWindow.dispose();
  85             ownedDialog.dispose();
  86             dialog.dispose();
  87         }
  88 
  89         focusedFrame = new Frame("Base Frame");
  90         focusOwner = new Button("button");
  91 
  92         frame = new Frame("Test Frame");
  93         frameButton = new Button("button");
  94 


 134 
 135         ownedWindow.setBounds(180, 180, 140, 140);
 136         ownedWindow.add(ownWinButton);
 137 
 138         ownedDialog.setBounds(180, 180, 140, 140);
 139         ownedDialog.add(ownDlgButton);
 140 
 141         dialog.setBounds(140, 140, 220, 220);
 142         dialog.add(dlgButton);
 143     }
 144 
 145     public void start() {
 146 
 147         ///////////////////////////////////////////////////////
 148         // 1. Show Frame with owned modal Dialog without delay.
 149         //    Check that the Dialog takes focus.
 150         ///////////////////////////////////////////////////////
 151 
 152         recreateGUI();
 153 
 154         Sysout.println("Stage 1 in progress...");
 155 
 156         dialog.setModal(true);
 157         dialog.setAutoRequestFocus(false);
 158         setVisible(focusedFrame, true);
 159 
 160         TestHelper.invokeLaterAndWait(new Runnable() {
 161                 public void run() {
 162                     dialog.setVisible(true);
 163                 }
 164             }, robot);
 165 
 166         if (focusOwner.hasFocus()) {
 167             throw new TestFailedException("the modal dialog must gain focus but it didn't!");
 168         }
 169         setVisible(dialog, false);
 170 
 171         //////////////////////////////////////////////////
 172         // 2. Show Frame, activate, auto hide, auto show.
 173         //    Check that the Frame takes focus.
 174         //////////////////////////////////////////////////
 175 
 176         recreateGUI();
 177 
 178         Sysout.println("Stage 2 in progress...");
 179 
 180         setVisible(focusedFrame, false);
 181 
 182         focusedFrame.setAutoRequestFocus(false);
 183         setVisible(focusedFrame, true);
 184 
 185         Util.clickOnTitle(focusedFrame, robot);
 186         Util.waitForIdle(robot);
 187 
 188         if (!focusedFrame.isFocused()) {
 189             throw new Error("Test error: the frame couldn't be focused.");
 190         }
 191 
 192         focusedFrame.setExtendedState(Frame.ICONIFIED);
 193         Util.waitForIdle(robot);
 194         focusedFrame.setExtendedState(Frame.NORMAL);
 195         Util.waitForIdle(robot);
 196 
 197         if (!focusedFrame.isFocused()) {
 198             throw new TestFailedException("the restored frame must gain focus but it didn't!");


 266         // 4.2 Show Dialog.
 267         //////////////////
 268 
 269         test("Stage 4.2 in progress...", dialog, dlgButton);
 270 
 271 
 272         // 4.3. Show modal Dialog.
 273         /////////////////////////
 274 
 275         dialog.setModal(true);
 276         test("Stage 4.3 in progress...", dialog, dlgButton, true);
 277 
 278 
 279         ///////////////////////////////////
 280         // 5.1 Show Frame with owned Window.
 281         ///////////////////////////////////
 282 
 283         // On Windows, an owned Window will not be focused on its showing
 284         // if the owner is not currently active.
 285         if ("sun.awt.windows.WToolkit".equals(toolkitClassName)) {
 286             Sysout.println("Stage 5.1 - Skiping.");
 287         } else {
 288             setVisible(ownedWindow, true);
 289             setVisible(frame, false); // 'ownedWindow' will be shown along with the owner.
 290 
 291             test("Stage 5.1 in progress...", frame, ownedWindow, ownWinButton, true);
 292         }
 293 
 294 
 295         // 5.2 Show Frame with owned Dialog.
 296         ///////////////////////////////////
 297 
 298         setVisible(ownedDialog, true);
 299         setVisible(frame2, false); // 'ownedDialog' will be shown along with the owner.
 300 
 301         test("Stage 5.2 in progress...", frame2, ownedDialog, ownDlgButton, true);
 302 
 303 
 304         ///////////////////////////////////
 305         // 6. Show unblocking modal Dialog.
 306         ///////////////////////////////////
 307 
 308         if ("sun.awt.motif.MToolkit".equals(toolkitClassName)) {
 309             Sysout.println("Stage 6 - Skiping.");
 310         } else {
 311             Sysout.println("Stage 6 in progress...");
 312 
 313             // ---
 314             // Testing the bug of activating invisible modal Dialog (awt_Window::SetAndActivateModalBlocker).
 315             // Having some window not excluded from modality, so that it would be blocked.
 316             Frame f = new Frame("Aux. Frame");
 317             f.setSize(100, 100);
 318             setVisible(f, true);
 319             // ---
 320 
 321             setVisible(focusedFrame, true);
 322             if (!focusOwner.hasFocus()) {
 323                 Util.clickOnComp(focusOwner, robot);
 324                 Util.waitForIdle(robot);
 325                 if (!focusOwner.hasFocus()) {
 326                     throw new Error("Test error: the frame couldn't be focused.");
 327                 }
 328             }
 329 
 330             dialog.setModal(true);
 331             dialog.setAutoRequestFocus(false);
 332             focusedFrame.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
 333 
 334             TestHelper.invokeLaterAndWait(new Runnable() {
 335                     public void run() {
 336                         dialog.setVisible(true);
 337                     }
 338                 }, robot);
 339 
 340             if (dialog.isFocused()) {
 341                 throw new TestFailedException("the unblocking dialog shouldn't gain focus but it did!");
 342             }
 343             setVisible(dialog, false);
 344         }
 345 
 346         Sysout.println("Test passed.");
 347     }
 348 
 349     /*
 350      * @param msg notifies test stage number
 351      * @param showWindow a window to show/test (if ownedWindow == null)
 352      * @param ownedWindow an owned window to show/test, or null if showWindow should be tested
 353      * @param clickButton a button of the window (owner or owned) expected to be on the top of stack order
 354      * @param shouldFocusChange true the test window should gain focus
 355      */
 356     void test(String msg, final Window showWindow, Window ownedWindow, final Button clickButton, boolean shouldFocusChange) {
 357         Window testWindow = (ownedWindow == null ? showWindow : ownedWindow);
 358 
 359         Sysout.println(msg);
 360 
 361         if (showWindow.isVisible()) {
 362             showWindow.dispose();
 363             Util.waitForIdle(robot);
 364         }
 365         if (!focusedFrame.isVisible()) {
 366             setVisible(focusedFrame, true);
 367         }
 368         if (!focusOwner.hasFocus()) {
 369             Util.clickOnComp(focusOwner, robot);
 370             Util.waitForIdle(robot);
 371             if (!focusOwner.hasFocus()) {
 372                 throw new Error("Test error: the frame couldn't be focused.");
 373             }
 374         }
 375 
 376         //////////////////////////////////////////
 377         // Test focus change on showing the window
 378         //////////////////////////////////////////
 379 


 411         // Test that the window was shown on the top.
 412         // Test that it can be focused.
 413         ////////////////////////////////////////////
 414 
 415         if (!(testWindow instanceof Frame) ||
 416             ((Frame)testWindow).getExtendedState() != Frame.ICONIFIED)
 417         {
 418             boolean performed = Util.trackActionPerformed(clickButton, new Runnable() {
 419                     public void run() {
 420                         /*
 421                          * If 'showWindow' is not on the top then
 422                          * 'focusOwner' button completely overlaps 'clickButton'
 423                          * and we won't catch the action.
 424                          */
 425                         Util.clickOnComp(clickButton, robot);
 426                     }
 427                 }, 1000, false);
 428 
 429             if (!performed) {
 430                 // In case of loosing ACTION_PERFORMED, try once more.
 431                 Sysout.println("(ACTION_EVENT was not generated. One more attemp.)");
 432                 performed = Util.trackActionPerformed(clickButton, new Runnable() {
 433                         public void run() {
 434                             Util.clickOnComp(clickButton, robot);
 435                         }
 436                     }, 1000, false);
 437 
 438                 if (!performed) {
 439                     throw new TestFailedException("the window shown is not on the top!");
 440                 }
 441             }
 442         }
 443 
 444         recreateGUI();
 445     }
 446 
 447     void test(String msg, final Window showWindow, Button clickButton) {
 448         test(msg, showWindow, null, clickButton, false);
 449     }
 450     void test(String msg, final Window showWindow, Button clickButton, boolean shouldFocusChange) {
 451         test(msg, showWindow, null, clickButton, shouldFocusChange);


 453     void test(String msg, final Window showWindow, Window ownedWindow, Button clickButton) {
 454         test(msg, showWindow, ownedWindow, clickButton, false);
 455     }
 456 
 457     private static void setVisible(Window w, boolean b) {
 458         w.setVisible(b);
 459         try {
 460             Util.waitForIdle(robot);
 461         } catch (RuntimeException rte) { // InfiniteLoop
 462             rte.printStackTrace();
 463         }
 464         robot.delay(200);
 465     }
 466 }
 467 
 468 class TestFailedException extends RuntimeException {
 469     TestFailedException(String msg) {
 470         super("Test failed: " + msg);
 471     }
 472 }
 473 
 474 /****************************************************
 475  Standard Test Machinery
 476  DO NOT modify anything below -- it's a standard
 477   chunk of code whose purpose is to make user
 478   interaction uniform, and thereby make it simpler
 479   to read and understand someone else's test.
 480  ****************************************************/
 481 
 482 /**
 483  This is part of the standard test machinery.
 484  It creates a dialog (with the instructions), and is the interface
 485   for sending text messages to the user.
 486  To print the instructions, send an array of strings to Sysout.createDialog
 487   WithInstructions method.  Put one line of instructions per array entry.
 488  To display a message for the tester to see, simply call Sysout.println
 489   with the string to be displayed.
 490  This mimics System.out.println but works within the test harness as well
 491   as standalone.
 492  */
 493 
 494 class Sysout
 495 {
 496     static TestDialog dialog;
 497 
 498     public static void createDialogWithInstructions( String[] instructions )
 499     {
 500         dialog = new TestDialog( new Frame(), "Instructions" );
 501         dialog.printInstructions( instructions );
 502 //        dialog.setVisible(true);
 503         println( "Any messages for the tester will display here." );
 504     }
 505 
 506     public static void createDialog( )
 507     {
 508         dialog = new TestDialog( new Frame(), "Instructions" );
 509         String[] defInstr = { "Instructions will appear here. ", "" } ;
 510         dialog.printInstructions( defInstr );
 511 //        dialog.setVisible(true);
 512         println( "Any messages for the tester will display here." );
 513     }
 514 
 515 
 516     public static void printInstructions( String[] instructions )
 517     {
 518         dialog.printInstructions( instructions );
 519     }
 520 
 521 
 522     public static void println( String messageIn )
 523     {
 524         dialog.displayMessage( messageIn );
 525     }
 526 
 527 }// Sysout  class
 528 
 529 /**
 530   This is part of the standard test machinery.  It provides a place for the
 531    test instructions to be displayed, and a place for interactive messages
 532    to the user to be displayed.
 533   To have the test instructions displayed, see Sysout.
 534   To have a message to the user be displayed, see Sysout.
 535   Do not call anything in this dialog directly.
 536   */
 537 class TestDialog extends Dialog
 538 {
 539 
 540     TextArea instructionsText;
 541     TextArea messageText;
 542     int maxStringLength = 80;
 543 
 544     //DO NOT call this directly, go through Sysout
 545     public TestDialog( Frame frame, String name )
 546     {
 547         super( frame, name );
 548         int scrollBoth = TextArea.SCROLLBARS_BOTH;
 549         instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
 550         add( "North", instructionsText );
 551 
 552         messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
 553         add("Center", messageText);
 554 
 555         pack();
 556 
 557 //        setVisible(true);
 558     }// TestDialog()
 559 
 560     //DO NOT call this directly, go through Sysout
 561     public void printInstructions( String[] instructions )
 562     {
 563         //Clear out any current instructions
 564         instructionsText.setText( "" );
 565 
 566         //Go down array of instruction strings
 567 
 568         String printStr, remainingStr;
 569         for( int i=0; i < instructions.length; i++ )
 570         {
 571             //chop up each into pieces maxSringLength long
 572             remainingStr = instructions[ i ];
 573             while( remainingStr.length() > 0 )
 574             {
 575                 //if longer than max then chop off first max chars to print
 576                 if( remainingStr.length() >= maxStringLength )
 577                 {
 578                     //Try to chop on a word boundary
 579                     int posOfSpace = remainingStr.
 580                         lastIndexOf( ' ', maxStringLength - 1 );
 581 
 582                     if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
 583 
 584                     printStr = remainingStr.substring( 0, posOfSpace + 1 );
 585                     remainingStr = remainingStr.substring( posOfSpace + 1 );
 586                 }
 587                 //else just print
 588                 else
 589                 {
 590                     printStr = remainingStr;
 591                     remainingStr = "";
 592                 }
 593 
 594                 instructionsText.append( printStr + "\n" );
 595 
 596             }// while
 597 
 598         }// for
 599 
 600     }//printInstructions()
 601 
 602     //DO NOT call this directly, go through Sysout
 603     public void displayMessage( String messageIn )
 604     {
 605         messageText.append( messageIn + "\n" );
 606         System.out.println(messageIn);
 607     }
 608 
 609 }// TestDialog  class
   1 /*
   2  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  52     static Button ownWinButton;
  53     static Dialog ownedDialog;
  54     static Button ownDlgButton;
  55     static Dialog dialog;
  56     static Button dlgButton;
  57 
  58     static String toolkitClassName;
  59     static Robot robot = Util.createRobot();
  60 
  61     public static void main(String[] args) {
  62         AutoRequestFocusSetVisibleTest app = new AutoRequestFocusSetVisibleTest();
  63         app.init();
  64         app.start();
  65     }
  66 
  67     public void init() {
  68         // Create instructions for the user here, as well as set up
  69         // the environment -- set the layout manager, add buttons,
  70         // etc.
  71         this.setLayout (new BorderLayout ());



  72         toolkitClassName = Toolkit.getDefaultToolkit().getClass().getName();
  73     }
  74 
  75     void recreateGUI() {
  76         if (focusedFrame != null) {
  77             focusedFrame.dispose();
  78             frame.dispose();
  79             frame2.dispose();
  80             window.dispose();
  81             ownedWindow.dispose();
  82             ownedDialog.dispose();
  83             dialog.dispose();
  84         }
  85 
  86         focusedFrame = new Frame("Base Frame");
  87         focusOwner = new Button("button");
  88 
  89         frame = new Frame("Test Frame");
  90         frameButton = new Button("button");
  91 


 131 
 132         ownedWindow.setBounds(180, 180, 140, 140);
 133         ownedWindow.add(ownWinButton);
 134 
 135         ownedDialog.setBounds(180, 180, 140, 140);
 136         ownedDialog.add(ownDlgButton);
 137 
 138         dialog.setBounds(140, 140, 220, 220);
 139         dialog.add(dlgButton);
 140     }
 141 
 142     public void start() {
 143 
 144         ///////////////////////////////////////////////////////
 145         // 1. Show Frame with owned modal Dialog without delay.
 146         //    Check that the Dialog takes focus.
 147         ///////////////////////////////////////////////////////
 148 
 149         recreateGUI();
 150 
 151         System.out.println("Stage 1 in progress...");
 152 
 153         dialog.setModal(true);
 154         dialog.setAutoRequestFocus(false);
 155         setVisible(focusedFrame, true);
 156 
 157         TestHelper.invokeLaterAndWait(new Runnable() {
 158                 public void run() {
 159                     dialog.setVisible(true);
 160                 }
 161             }, robot);
 162 
 163         if (focusOwner.hasFocus()) {
 164             throw new TestFailedException("the modal dialog must gain focus but it didn't!");
 165         }
 166         setVisible(dialog, false);
 167 
 168         //////////////////////////////////////////////////
 169         // 2. Show Frame, activate, auto hide, auto show.
 170         //    Check that the Frame takes focus.
 171         //////////////////////////////////////////////////
 172 
 173         recreateGUI();
 174 
 175         System.out.println("Stage 2 in progress...");
 176 
 177         setVisible(focusedFrame, false);
 178 
 179         focusedFrame.setAutoRequestFocus(false);
 180         setVisible(focusedFrame, true);
 181 
 182         Util.clickOnTitle(focusedFrame, robot);
 183         Util.waitForIdle(robot);
 184 
 185         if (!focusedFrame.isFocused()) {
 186             throw new Error("Test error: the frame couldn't be focused.");
 187         }
 188 
 189         focusedFrame.setExtendedState(Frame.ICONIFIED);
 190         Util.waitForIdle(robot);
 191         focusedFrame.setExtendedState(Frame.NORMAL);
 192         Util.waitForIdle(robot);
 193 
 194         if (!focusedFrame.isFocused()) {
 195             throw new TestFailedException("the restored frame must gain focus but it didn't!");


 263         // 4.2 Show Dialog.
 264         //////////////////
 265 
 266         test("Stage 4.2 in progress...", dialog, dlgButton);
 267 
 268 
 269         // 4.3. Show modal Dialog.
 270         /////////////////////////
 271 
 272         dialog.setModal(true);
 273         test("Stage 4.3 in progress...", dialog, dlgButton, true);
 274 
 275 
 276         ///////////////////////////////////
 277         // 5.1 Show Frame with owned Window.
 278         ///////////////////////////////////
 279 
 280         // On Windows, an owned Window will not be focused on its showing
 281         // if the owner is not currently active.
 282         if ("sun.awt.windows.WToolkit".equals(toolkitClassName)) {
 283             System.out.println("Stage 5.1 - Skiping.");
 284         } else {
 285             setVisible(ownedWindow, true);
 286             setVisible(frame, false); // 'ownedWindow' will be shown along with the owner.
 287 
 288             test("Stage 5.1 in progress...", frame, ownedWindow, ownWinButton, true);
 289         }
 290 
 291 
 292         // 5.2 Show Frame with owned Dialog.
 293         ///////////////////////////////////
 294 
 295         setVisible(ownedDialog, true);
 296         setVisible(frame2, false); // 'ownedDialog' will be shown along with the owner.
 297 
 298         test("Stage 5.2 in progress...", frame2, ownedDialog, ownDlgButton, true);
 299 
 300 
 301         ///////////////////////////////////
 302         // 6. Show unblocking modal Dialog.
 303         ///////////////////////////////////
 304 
 305         if ("sun.awt.motif.MToolkit".equals(toolkitClassName)) {
 306             System.out.println("Stage 6 - Skiping.");
 307         } else {
 308             System.out.println("Stage 6 in progress...");
 309 
 310             // ---
 311             // Testing the bug of activating invisible modal Dialog (awt_Window::SetAndActivateModalBlocker).
 312             // Having some window not excluded from modality, so that it would be blocked.
 313             Frame f = new Frame("Aux. Frame");
 314             f.setSize(100, 100);
 315             setVisible(f, true);
 316             // ---
 317 
 318             setVisible(focusedFrame, true);
 319             if (!focusOwner.hasFocus()) {
 320                 Util.clickOnComp(focusOwner, robot);
 321                 Util.waitForIdle(robot);
 322                 if (!focusOwner.hasFocus()) {
 323                     throw new Error("Test error: the frame couldn't be focused.");
 324                 }
 325             }
 326 
 327             dialog.setModal(true);
 328             dialog.setAutoRequestFocus(false);
 329             focusedFrame.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
 330 
 331             TestHelper.invokeLaterAndWait(new Runnable() {
 332                     public void run() {
 333                         dialog.setVisible(true);
 334                     }
 335                 }, robot);
 336 
 337             if (dialog.isFocused()) {
 338                 throw new TestFailedException("the unblocking dialog shouldn't gain focus but it did!");
 339             }
 340             setVisible(dialog, false);
 341         }
 342 
 343         System.out.println("Test passed.");
 344     }
 345 
 346     /*
 347      * @param msg notifies test stage number
 348      * @param showWindow a window to show/test (if ownedWindow == null)
 349      * @param ownedWindow an owned window to show/test, or null if showWindow should be tested
 350      * @param clickButton a button of the window (owner or owned) expected to be on the top of stack order
 351      * @param shouldFocusChange true the test window should gain focus
 352      */
 353     void test(String msg, final Window showWindow, Window ownedWindow, final Button clickButton, boolean shouldFocusChange) {
 354         Window testWindow = (ownedWindow == null ? showWindow : ownedWindow);
 355 
 356         System.out.println(msg);
 357 
 358         if (showWindow.isVisible()) {
 359             showWindow.dispose();
 360             Util.waitForIdle(robot);
 361         }
 362         if (!focusedFrame.isVisible()) {
 363             setVisible(focusedFrame, true);
 364         }
 365         if (!focusOwner.hasFocus()) {
 366             Util.clickOnComp(focusOwner, robot);
 367             Util.waitForIdle(robot);
 368             if (!focusOwner.hasFocus()) {
 369                 throw new Error("Test error: the frame couldn't be focused.");
 370             }
 371         }
 372 
 373         //////////////////////////////////////////
 374         // Test focus change on showing the window
 375         //////////////////////////////////////////
 376 


 408         // Test that the window was shown on the top.
 409         // Test that it can be focused.
 410         ////////////////////////////////////////////
 411 
 412         if (!(testWindow instanceof Frame) ||
 413             ((Frame)testWindow).getExtendedState() != Frame.ICONIFIED)
 414         {
 415             boolean performed = Util.trackActionPerformed(clickButton, new Runnable() {
 416                     public void run() {
 417                         /*
 418                          * If 'showWindow' is not on the top then
 419                          * 'focusOwner' button completely overlaps 'clickButton'
 420                          * and we won't catch the action.
 421                          */
 422                         Util.clickOnComp(clickButton, robot);
 423                     }
 424                 }, 1000, false);
 425 
 426             if (!performed) {
 427                 // In case of loosing ACTION_PERFORMED, try once more.
 428                 System.out.println("(ACTION_EVENT was not generated. One more attemp.)");
 429                 performed = Util.trackActionPerformed(clickButton, new Runnable() {
 430                         public void run() {
 431                             Util.clickOnComp(clickButton, robot);
 432                         }
 433                     }, 1000, false);
 434 
 435                 if (!performed) {
 436                     throw new TestFailedException("the window shown is not on the top!");
 437                 }
 438             }
 439         }
 440 
 441         recreateGUI();
 442     }
 443 
 444     void test(String msg, final Window showWindow, Button clickButton) {
 445         test(msg, showWindow, null, clickButton, false);
 446     }
 447     void test(String msg, final Window showWindow, Button clickButton, boolean shouldFocusChange) {
 448         test(msg, showWindow, null, clickButton, shouldFocusChange);


 450     void test(String msg, final Window showWindow, Window ownedWindow, Button clickButton) {
 451         test(msg, showWindow, ownedWindow, clickButton, false);
 452     }
 453 
 454     private static void setVisible(Window w, boolean b) {
 455         w.setVisible(b);
 456         try {
 457             Util.waitForIdle(robot);
 458         } catch (RuntimeException rte) { // InfiniteLoop
 459             rte.printStackTrace();
 460         }
 461         robot.delay(200);
 462     }
 463 }
 464 
 465 class TestFailedException extends RuntimeException {
 466     TestFailedException(String msg) {
 467         super("Test failed: " + msg);
 468     }
 469 }









































































































































< prev index next >