1058N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1058N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1058N/A *
1058N/A * This code is free software; you can redistribute it and/or modify it
1058N/A * under the terms of the GNU General Public License version 2 only, as
1058N/A * published by the Free Software Foundation.
1058N/A *
1058N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1058N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1058N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1058N/A * version 2 for more details (a copy is included in the LICENSE file that
1058N/A * accompanied this code).
1058N/A *
1058N/A * You should have received a copy of the GNU General Public License version
1058N/A * 2 along with this work; if not, write to the Free Software Foundation,
1058N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1058N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1058N/A */
1058N/A
1058N/A/*
1058N/A @test
1058N/A @bug 6411406
1058N/A @summary Components automatically transfer focus on removal, even if developer requests focus elsewhere first
1058N/A @author oleg.sukhodolsky, anton.tarasov: area=awt.focus
1058N/A @library ../../regtesthelpers
1058N/A @build Util
1058N/A @run main RemoveAfterRequest
1058N/A*/
1058N/A
1058N/A/**
1058N/A * RemoveAfterRequest.java
1058N/A *
1058N/A * summary: Components automatically transfer focus on removal, even if developer requests focus elsewhere first
1058N/A */
1058N/A
1058N/Aimport java.awt.*;
1058N/Aimport java.awt.event.*;
1058N/Aimport test.java.awt.regtesthelpers.Util;
1058N/A
1058N/Apublic class RemoveAfterRequest {
1058N/A final static Frame frame = new Frame("test frame");
1058N/A final static Button btn1 = new Button("btn1");
1058N/A final static Button btn2 = new Button("btn2");
1058N/A final static Button btn3 = new Button("btn3");
1058N/A
1058N/A public static void main(String[] args) {
1058N/A frame.setLayout(new GridLayout(3, 1));
1058N/A frame.add(btn1);
1058N/A frame.add(btn2);
1058N/A frame.add(btn3);
1058N/A frame.pack();
1058N/A frame.setVisible(true);
1058N/A
1058N/A Util.waitForIdle(null);
1058N/A
1058N/A if (!btn1.hasFocus()) {
1058N/A btn1.requestFocus();
1058N/A Util.waitForIdle(null);
1058N/A if (!btn1.hasFocus()) {
1058N/A throw new TestErrorException("couldn't focus " + btn1);
1058N/A }
1058N/A }
1058N/A
1058N/A if (!Util.trackFocusGained(btn3, new Runnable() {
1058N/A public void run() {
1058N/A btn3.requestFocus();
1058N/A frame.remove(btn1);
1058N/A frame.invalidate();
1058N/A frame.validate();
1058N/A frame.repaint();
1058N/A }
1058N/A }, 2000, true))
1058N/A {
1058N/A throw new TestFailedException("focus request on removal failed");
1058N/A }
1058N/A
1058N/A System.out.println("Test passed.");
1058N/A }
1058N/A}
1058N/A
1058N/A/**
1058N/A * Thrown when the behavior being verified is found wrong.
1058N/A */
1058N/Aclass TestFailedException extends RuntimeException {
1058N/A TestFailedException(String msg) {
1058N/A super("Test failed: " + msg);
1058N/A }
1058N/A}
1058N/A
1058N/A/**
1058N/A * Thrown when an error not related to the behavior being verified is encountered.
1058N/A */
1058N/Aclass TestErrorException extends RuntimeException {
1058N/A TestErrorException(String msg) {
1058N/A super("Unexpected error: " + msg);
1058N/A }
1058N/A}
1058N/A