0N/A/*
2362N/A * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/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.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 6541987
0N/A * @summary Tests closing by ESC
0N/A * @author Sergey Malenkov
0N/A */
0N/A
0N/Aimport java.awt.AWTException;
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Robot;
0N/Aimport java.awt.Toolkit;
0N/Aimport java.awt.Window;
0N/Aimport java.awt.event.KeyEvent;
0N/A
0N/Aimport javax.swing.JColorChooser;
0N/Aimport javax.swing.JFrame;
0N/Aimport javax.swing.SwingUtilities;
0N/A
0N/Aimport sun.awt.SunToolkit;
0N/A
0N/Apublic class Test6541987 implements Runnable {
0N/A private static final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
0N/A private static Robot robot;
0N/A
0N/A public static void main(String[] args) throws AWTException {
0N/A robot = new Robot();
0N/A // test escape after selection
0N/A start();
0N/A click(KeyEvent.VK_ESCAPE);
0N/A toolkit.realSync();
0N/A // test double escape after editing
0N/A start();
0N/A click(KeyEvent.VK_1);
0N/A click(KeyEvent.VK_0);
0N/A click(KeyEvent.VK_ESCAPE);
0N/A click(KeyEvent.VK_ESCAPE);
0N/A toolkit.realSync();
0N/A // all windows should be closed
0N/A for (Window window : Window.getWindows()) {
0N/A if (window.isVisible()) {
0N/A throw new Error("found visible window: " + window.getName());
0N/A }
0N/A }
0N/A }
0N/A
0N/A private static void start() {
0N/A SwingUtilities.invokeLater(new Test6541987());
0N/A click(KeyEvent.VK_ALT, KeyEvent.VK_H);
0N/A click(KeyEvent.VK_TAB);
0N/A click(KeyEvent.VK_TAB);
0N/A click(KeyEvent.VK_TAB);
0N/A click(KeyEvent.VK_TAB);
0N/A }
0N/A
0N/A private static void click(int...keys) {
0N/A toolkit.realSync();
0N/A for (int key : keys) {
0N/A robot.keyPress(key);
0N/A }
0N/A for (int key : keys) {
0N/A robot.keyRelease(key);
0N/A }
0N/A }
0N/A
0N/A public void run() {
0N/A String title = getClass().getName();
0N/A JFrame frame = new JFrame(title);
0N/A frame.setVisible(true);
0N/A
0N/A Color color = JColorChooser.showDialog(frame, title, Color.BLACK);
0N/A if (color != null) {
0N/A throw new Error("unexpected color: " + color);
0N/A }
0N/A frame.setVisible(false);
0N/A frame.dispose();
0N/A }
0N/A}