jdk/test/java/awt/Focus/6981400/Test3.java
author serb
Tue, 12 Nov 2013 20:24:25 +0400
changeset 21596 0e3a39f29dbc
parent 14856 92a1bcf46888
child 23010 6dadb192ad81
permissions -rw-r--r--
8027696: Incorrect copyright header in the tests Reviewed-by: alanb, malenkov, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13652
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
     1
/*
14856
92a1bcf46888 8004982: JDK8 source with GPL header errors
katleman
parents: 13652
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
13652
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
     4
 *
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 14856
diff changeset
     7
 * published by the Free Software Foundation.
13652
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
     8
 *
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    13
 * accompanied this code).
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    14
 *
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    18
 *
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    21
 * questions.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    22
 */
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    23
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    24
/*
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    25
 * @test
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    26
 * @bug     6981400
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    27
 * @summary Tabbing between textfiled do not work properly when ALT+TAB
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    28
 * @author  anton.tarasov
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    29
 * @library ../../regtesthelpers
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    30
 * @build   Util
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    31
 * @run     main Test3
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    32
 */
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    33
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    34
// A menu item in a frame should not be auto-selected when switching by Alt+TAB back and forth.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    35
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    36
import java.awt.*;
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    37
import javax.swing.*;
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    38
import java.awt.event.*;
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    39
import test.java.awt.regtesthelpers.Util;
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    40
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    41
public class Test3 {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    42
    static JFrame f = new JFrame("Frame");
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    43
    static JMenuBar bar = new JMenuBar();
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    44
    static JMenu menu = new JMenu("File");
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    45
    static JMenuItem item = new JMenuItem("Save");
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    46
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    47
    static JButton b0 = new JButton("b0");
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    48
    static JButton b1 = new JButton("b1");
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    49
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    50
    static Robot robot;
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    51
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    52
    public static void main(String[] args) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    53
        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    54
            public void eventDispatched(AWTEvent e) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    55
                System.err.println(e);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    56
            }
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    57
        }, KeyEvent.KEY_EVENT_MASK);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    58
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    59
        try {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    60
            robot = new Robot();
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    61
        } catch (AWTException ex) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    62
            throw new RuntimeException("Error: can't create Robot");
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    63
        }
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    64
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    65
        try {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    66
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    67
        } catch (Exception e) {}
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    68
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    69
        b0.addFocusListener(new FocusAdapter() {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    70
            public void focusLost(FocusEvent f) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    71
                try {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    72
                    Thread.sleep(2000);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    73
                } catch (Exception e) {}
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    74
            }
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    75
        });
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    76
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    77
        menu.add(item);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    78
        bar.add(menu);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    79
        f.setJMenuBar(bar);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    80
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    81
        f.add(b0);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    82
        f.add(b1);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    83
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    84
        f.setLayout(new FlowLayout());
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    85
        f.setSize(400, 100);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    86
        f.setVisible(true);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    87
        Util.waitForIdle(robot);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    88
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    89
        if (!b0.hasFocus()) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    90
            Util.clickOnComp(b0, robot);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    91
            Util.waitForIdle(robot);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    92
            if (!b0.hasFocus()) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    93
                throw new RuntimeException("Error: can't focus " + b0);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    94
            }
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    95
        }
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    96
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    97
        test();
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    98
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
    99
        System.out.println("Test passed.");
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   100
    }
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   101
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   102
    public static void test() {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   103
        robot.keyPress(KeyEvent.VK_TAB);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   104
        robot.delay(50);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   105
        robot.keyRelease(KeyEvent.VK_TAB);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   106
        robot.delay(50);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   107
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   108
        robot.keyPress(KeyEvent.VK_ALT);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   109
        robot.delay(50);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   110
        robot.keyPress(KeyEvent.VK_TAB);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   111
        robot.delay(50);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   112
        robot.keyRelease(KeyEvent.VK_ALT);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   113
        robot.delay(50);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   114
        robot.keyRelease(KeyEvent.VK_TAB);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   115
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   116
        robot.delay(500);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   117
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   118
        robot.keyPress(KeyEvent.VK_ALT);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   119
        robot.delay(50);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   120
        robot.keyPress(KeyEvent.VK_TAB);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   121
        robot.delay(50);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   122
        robot.keyRelease(KeyEvent.VK_ALT);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   123
        robot.delay(50);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   124
        robot.keyRelease(KeyEvent.VK_TAB);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   125
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   126
        // Control shot.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   127
        Util.clickOnTitle(f, robot);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   128
        Util.waitForIdle(robot);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   129
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   130
        if (menu.isSelected()) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   131
            throw new RuntimeException("Test failed: the menu gets selected");
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   132
        }
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   133
        if (!b1.hasFocus()) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   134
            throw new RuntimeException("Test failed: the button is not a focus owner " + b1);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   135
        }
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   136
    }
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   137
}
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   138
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
diff changeset
   139