Path: blob/master/test/jdk/javax/swing/JInternalFrame/Test6325652.java
41149 views
/*1* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @key headful26* @bug 6325652 815915227* @summary Tests keyboard shortcuts28* @library ..29*/3031import java.awt.AWTException;32import java.awt.Robot;33import java.awt.event.KeyEvent;34import java.beans.PropertyVetoException;35import javax.swing.JDesktopPane;36import javax.swing.JFrame;37import javax.swing.JInternalFrame;38import javax.swing.JTextArea;3940public class Test6325652 {4142private static final int WIDTH = 300;43private static final int HEIGHT = 300;4445public static void main(String[] args) throws Throwable {46SwingTest.start(Test6325652.class);47}4849private static Robot robot;50private JInternalFrame internal;5152public Test6325652(JFrame frame) {53JDesktopPane desktop = new JDesktopPane();54desktop.add(create(0));55desktop.add(this.internal = create(1));56frame.add(desktop);57}5859public void select() throws PropertyVetoException {60this.internal.setSelected(true);61}6263public static void stepFirst() throws AWTException {64robot = new Robot(); // initialize shared static field first time65robot.setAutoDelay(50);66click(KeyEvent.VK_CONTROL, KeyEvent.VK_F9); // iconify internal frame67}6869public void stepFirstValidate() {70if (!this.internal.isIcon()) {71throw new Error("frame should be an icon");72}73}7475public static void stepSecond() {76click(KeyEvent.VK_CONTROL, KeyEvent.VK_F6); // navigate to the icon77click(KeyEvent.VK_CONTROL, KeyEvent.VK_F5); // restore the icon78}7980public void stepSecondValidate() {81if (this.internal.isIcon()) {82throw new Error("frame should not be an icon");83}84}8586private static void click(int... keys) {87for (int key : keys) {88robot.keyPress(key);89}90for (int key : keys) {91robot.keyRelease(key);92}93}9495private static JInternalFrame create(int index) {96String text = "test" + index; // NON-NLS: frame identification97index = index * 3 + 1;9899JInternalFrame internal = new JInternalFrame(text, true, true, true, true);100internal.getContentPane().add(new JTextArea(text));101internal.setBounds(10 * index, 10 * index, WIDTH, HEIGHT);102internal.setVisible(true);103return internal;104}105}106107108