test/jdk/java/awt/Focus/ContainerFocusAutoTransferTest/ContainerFocusAutoTransferTest.java
author serb
Wed, 27 Feb 2019 18:46:55 -0800
changeset 54231 e4813eded7cb
parent 47216 71c04702a3d5
permissions -rw-r--r--
8213110: Remove the use of applets in automatic tests Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
     1
/*
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
     4
 *
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
     8
 *
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    13
 * accompanied this code).
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    14
 *
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 441
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 441
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 441
diff changeset
    21
 * questions.
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    22
 */
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    23
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    24
/*
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
    26
  @key headful
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    27
  @bug       6607170
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    28
  @summary   Tests for focus-auto-transfer.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    29
  @library   ../../regtesthelpers
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    30
  @build     Util
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    31
  @run       main ContainerFocusAutoTransferTest
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    32
*/
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    33
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    34
import java.awt.AWTEvent;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    35
import java.awt.Component;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    36
import java.awt.ComponentOrientation;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    37
import java.awt.DefaultKeyboardFocusManager;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    38
import java.awt.KeyboardFocusManager;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    39
import java.awt.Robot;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    40
import java.awt.Color;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    41
import java.awt.FlowLayout;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    42
import java.awt.Toolkit;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    43
import java.awt.event.AWTEventListener;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    44
import java.awt.event.FocusEvent;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    45
import java.awt.event.WindowEvent;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    46
import javax.swing.JButton;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    47
import javax.swing.JFrame;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    48
import javax.swing.JPanel;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    49
import test.java.awt.regtesthelpers.Util;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    50
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    51
public class ContainerFocusAutoTransferTest {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    52
    Robot robot;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    53
    TestFrame frame;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    54
    KeyboardFocusManager kfm;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    55
    enum TestCase {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    56
        REMOVAL { public String toString() { return "removal"; } },
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    57
        HIDING { public String toString() { return "hiding"; } },
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    58
        DISABLING { public String toString() { return "disabling"; } },
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    59
        DEFOCUSING { public String toString() { return "defocusing"; } };
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    60
        public abstract String toString();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    61
    };
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    62
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    63
    public static void main(String[] args) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    64
        ContainerFocusAutoTransferTest app = new ContainerFocusAutoTransferTest();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    65
        app.init();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    66
        app.start();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    67
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    68
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    69
    public void init() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    70
        robot = Util.createRobot();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    71
        kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    72
        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    73
            public void eventDispatched(AWTEvent event) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    74
                System.out.println("--> " + event);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    75
            }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    76
        }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    77
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    78
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    79
    public void start() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    80
        System.out.println("*** TEST #1 ***");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    81
        test(TestCase.HIDING);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    82
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    83
        System.out.println("*** TEST #2 ***");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    84
        test(TestCase.REMOVAL);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    85
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    86
        System.out.println("*** TEST #3 ***");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    87
        test3(TestCase.DISABLING);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    88
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    89
        System.out.println("*** TEST #4 ***");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    90
        test3(TestCase.DEFOCUSING);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    91
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    92
        System.out.println("*** TEST #5 ***");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    93
        test4();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    94
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    95
        System.out.println("Test passed.");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    96
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    97
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    98
    void test(final TestCase t) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
    99
        showFrame();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   100
        test1(t); // Test for correct auto-transfer
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   101
        test2(t); // Test for clearing focus
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   102
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   103
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   104
    void test1(final TestCase t) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   105
        Runnable action = new Runnable() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   106
            public void run() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   107
                KeyboardFocusManager.setCurrentKeyboardFocusManager(new TestKFM());
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   108
                if (t == TestCase.REMOVAL) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   109
                    frame.remove(frame.panel0);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   110
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   111
                } else if (t == TestCase.HIDING) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   112
                    frame.panel0.setVisible(false);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   113
                }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   114
                frame.repaint();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   115
            }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   116
        };
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   117
        if (!Util.trackFocusGained(frame.b3, action, 2000, false)) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   118
            throw new TestFailedException(t + ": focus wasn't transfered as expected!");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   119
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   120
        KeyboardFocusManager.setCurrentKeyboardFocusManager(kfm);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   121
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   122
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   123
    void test2(TestCase t) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   124
        frame.setFocusable(false); // exclude it from the focus cycle
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   125
        if (t == TestCase.REMOVAL) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   126
            frame.remove(frame.panel1);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   127
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   128
        } else if (t == TestCase.HIDING) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   129
            frame.panel1.setVisible(false);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   130
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   131
        frame.repaint();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   132
        Util.waitForIdle(robot);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   133
        if (kfm.getFocusOwner() != null) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   134
            throw new TestFailedException(t + ": focus wasn't cleared!");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   135
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   136
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   137
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   138
    void test3(final TestCase t) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   139
        showFrame();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   140
        Runnable action = new Runnable() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   141
            public void run() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   142
                if (t == TestCase.DISABLING) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   143
                    frame.b0.setEnabled(false);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   144
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   145
                } else if (t == TestCase.DEFOCUSING) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   146
                    frame.b0.setFocusable(false);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   147
                }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   148
            }};
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   149
        if (!Util.trackFocusGained(frame.b1, action, 2000, false)) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   150
            throw new TestFailedException(t + ": focus wasn't transfered as expected!");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   151
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   152
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   153
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   154
    void test4() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   155
        showFrame();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   156
        frame.setFocusableWindowState(false);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   157
        Util.waitForIdle(robot);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   158
        if (kfm.getFocusOwner() != null) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   159
            throw new TestFailedException("defocusing the frame: focus wasn't cleared!");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   160
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   161
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   162
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   163
    void showFrame() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   164
        if (frame != null) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   165
            frame.dispose();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   166
            Util.waitForIdle(robot);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   167
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   168
        frame = new TestFrame();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   169
        frame.setVisible(true);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   170
        Util.waitTillShown(frame);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   171
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   172
        if (!frame.b0.hasFocus()) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   173
            Util.clickOnComp(frame.b0, robot);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   174
            Util.waitForIdle(robot);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   175
            if (!frame.b0.hasFocus()) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   176
                throw new TestErrorException("couldn't set focus on " + frame.b2);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   177
            }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   178
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   179
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   180
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   181
    class TestKFM extends DefaultKeyboardFocusManager {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   182
        public boolean dispatchEvent(AWTEvent e) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   183
            if (e.getID() == FocusEvent.FOCUS_GAINED) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   184
                System.out.println(e);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   185
                Component src = (Component)e.getSource();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   186
                if (src == frame.b1 || src == frame.b2) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   187
                    throw new TestFailedException("wrong focus transfer on removal!");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   188
                }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   189
            }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   190
            return super.dispatchEvent(e);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   191
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   192
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   193
}
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   194
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   195
class TestFrame extends JFrame {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   196
    public JPanel panel0 = new JPanel();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   197
    public JPanel panel1 = new JPanel();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   198
    public JButton b0 = new JButton("b0");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   199
    public JButton b1 = new JButton("b1");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   200
    public JButton b2 = new JButton("b2");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   201
    public JButton b3 = new JButton("b3");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   202
    public JButton b4 = new JButton("b4");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   203
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   204
    public TestFrame() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   205
        super("TestFrame");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   206
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   207
        // The change of the orientation and the reverse order of
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   208
        // adding the buttons to the panel is because in Container.removeNotify()
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   209
        // the child components are removed in the reverse order.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   210
        // We want that the focus owner (b0) would be removed first and
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   211
        // that the next traversable component would be b1.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   212
        panel0.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   213
        panel0.add(b2);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   214
        panel0.add(b1);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   215
        panel0.add(b0);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   216
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   217
        panel1.add(b3);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   218
        panel1.add(b4);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   219
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   220
        setLayout(new FlowLayout());
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   221
        add(panel0);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   222
        add(panel1);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   223
        pack();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   224
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   225
        panel0.setBackground(Color.red);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   226
        panel1.setBackground(Color.blue);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   227
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   228
}
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   229
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   230
// Thrown when the behavior being verified is found wrong.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   231
class TestFailedException extends RuntimeException {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   232
    TestFailedException(String msg) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   233
        super("Test failed: " + msg);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   234
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   235
}
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   236
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   237
// Thrown when an error not related to the behavior being verified is encountered.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   238
class TestErrorException extends RuntimeException {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   239
    TestErrorException(String msg) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   240
        super("Unexpected error: " + msg);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   241
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents:
diff changeset
   242
}