Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JInternalFrame/Test6325652.java
38839 views
/*1* Copyright (c) 2009, 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* @bug 632565226* @summary Tests keyboard shortcuts27* @author Sergey Malenkov28* @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 time65click(KeyEvent.VK_CONTROL, KeyEvent.VK_F9); // iconify internal frame66}6768public void stepFirstValidate() {69if (!this.internal.isIcon()) {70throw new Error("frame should be an icon");71}72}7374public static void stepSecond() {75click(KeyEvent.VK_CONTROL, KeyEvent.VK_F6); // navigate to the icon76click(KeyEvent.VK_CONTROL, KeyEvent.VK_F5); // restore the icon77}7879public void stepSecondValidate() {80if (this.internal.isIcon()) {81throw new Error("frame should not be an icon");82}83}8485private static void click(int... keys) {86for (int key : keys) {87robot.keyPress(key);88}89for (int key : keys) {90robot.keyRelease(key);91}92}9394private static JInternalFrame create(int index) {95String text = "test" + index; // NON-NLS: frame identification96index = index * 3 + 1;9798JInternalFrame internal = new JInternalFrame(text, true, true, true, true);99internal.getContentPane().add(new JTextArea(text));100internal.setBounds(10 * index, 10 * index, WIDTH, HEIGHT);101internal.setVisible(true);102return internal;103}104}105106107