Path: blob/master/test/jdk/javax/swing/JInternalFrame/4251301/bug4251301.java
41153 views
/*1* Copyright (c) 2013, 2018, 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*/22/* @test23@bug 425130124@summary Keybinding for show/hide the system menu.25@author Andrey Pikalev26@library /test/lib27@build jdk.test.lib.Platform28@run main/manual bug425130129*/3031import javax.swing.*;32import java.awt.*;33import java.awt.event.ActionEvent;34import java.awt.event.ActionListener;35import java.beans.*;3637import jdk.test.lib.Platform;3839public class bug4251301 {40static Test test = new Test();41public static void main(String[] args) throws Exception {42if (Platform.isOSX()) {43System.out.println("This test is not applicable for MacOS. Passed.");44return;45}46UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());47SwingUtilities.invokeAndWait(new Runnable() {48public void run() {49createAndShowGUI();50}51});52Robot robot = new Robot();53robot.waitForIdle();54test.waitTestResult();55}5657public static void createAndShowGUI() {58final StringBuilder instructions = new StringBuilder();59instructions.append("Click with your mouse the content area of the internal frame with the title \"IFrame\" ");60instructions.append("and press Ctrl+Space. \n");61instructions.append("If the system menu shows up, press Esc. Then system menu should hide. \n");62instructions.append("If you success then press \"Pass\", else press \"Fail\".\n");6364JDesktopPane dp = new JDesktopPane();65JInternalFrame jif = new JInternalFrame("IFrame",true,true,true,true);66dp.add(jif);67jif.setBounds(20, 20, 220, 100);68jif.setVisible(true);69try {70jif.setSelected(true);71} catch(PropertyVetoException pve) {72pve.printStackTrace();73throw new Error("Occures PropertyVetoException while set selection...");74}75JScrollPane dtScrollPane = new JScrollPane(dp);76JFrame testFrame = test.createTestFrame("Instructions", dtScrollPane, instructions.toString(), 500);77testFrame.setSize(500, 400);78testFrame.setVisible(true);79}80static class Test {81private boolean pass;82JFrame createTestFrame(String name, Component topComponent, String instructions, int instrHeight) {83final String PASS = "Pass";84final String FAIL = "Fail";85JFrame frame = new JFrame(name);86frame.setLayout(new BorderLayout());8788JPanel testButtonsPanel = new JPanel();89testButtonsPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));9091ActionListener btnAL = new ActionListener() {92public void actionPerformed(ActionEvent event) {93switch (event.getActionCommand()) {94case PASS:95pass();96break;97default:98throw new RuntimeException("Test failed.");99}100}101};102JButton passBtn = new JButton(PASS);103passBtn.addActionListener(btnAL);104passBtn.setActionCommand(PASS);105106JButton failBtn = new JButton(FAIL);107failBtn.addActionListener(btnAL);108failBtn.setActionCommand(FAIL);109110testButtonsPanel.add(BorderLayout.WEST, passBtn);111testButtonsPanel.add(BorderLayout.EAST, failBtn);112113JTextArea instrText = new JTextArea();114instrText.setLineWrap(true);115instrText.setEditable(false);116JScrollPane instrScrollPane = new JScrollPane(instrText);117instrScrollPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, instrHeight));118instrText.append(instructions);119120JPanel servicePanel = new JPanel();121servicePanel.setLayout(new BorderLayout());122servicePanel.add(BorderLayout.CENTER, instrScrollPane);123servicePanel.add(BorderLayout.SOUTH, testButtonsPanel);124125frame.add(BorderLayout.SOUTH, servicePanel);126frame.add(BorderLayout.CENTER, topComponent);127return frame;128}129synchronized void pass() {130pass = true;131notifyAll();132}133synchronized void waitTestResult() throws InterruptedException {134while (!pass) {135wait();136}137}138}139}140141142