1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /* @test 24 @bug 4251301 25 @summary Keybinding for show/hide the system menu. 26 @author Andrey Pikalev 27 @library /test/lib 28 @build jdk.test.lib.Platform 29 @run main/manual bug4251301 30 */ 31 32 import javax.swing.*; 33 import java.awt.*; 34 import java.awt.event.ActionEvent; 35 import java.awt.event.ActionListener; 36 import java.beans.*; 37 38 import jdk.test.lib.Platform; 39 40 public class bug4251301 { 41 static Test test = new Test(); 42 public static void main(String[] args) throws Exception { 43 if (Platform.isOSX()) { 44 System.out.println("This test is not applicable for MacOS. Passed."); 45 return; 46 } 47 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 48 SwingUtilities.invokeAndWait(new Runnable() { 49 public void run() { 50 createAndShowGUI(); 51 } 52 }); 53 Robot robot = new Robot(); 54 robot.waitForIdle(); 55 test.waitTestResult(); 56 } 57 58 public static void createAndShowGUI() { 59 final StringBuilder instructions = new StringBuilder(); 60 instructions.append("Click with your mouse the content area of the internal frame with the title \"IFrame\" "); 61 instructions.append("and press Ctrl+Space. \n"); 62 instructions.append("If the system menu shows up, press Esc. Then system menu should hide. \n"); 63 instructions.append("If you success then press \"Pass\", else press \"Fail\".\n"); 64 65 JDesktopPane dp = new JDesktopPane(); 66 JInternalFrame jif = new JInternalFrame("IFrame",true,true,true,true); 67 dp.add(jif); 68 jif.setBounds(20, 20, 220, 100); 69 jif.setVisible(true); 70 try { 71 jif.setSelected(true); 72 } catch(PropertyVetoException pve) { 73 pve.printStackTrace(); 74 throw new Error("Occures PropertyVetoException while set selection..."); 75 } 76 JScrollPane dtScrollPane = new JScrollPane(dp); 77 JFrame testFrame = test.createTestFrame("Instructions", dtScrollPane, instructions.toString(), 500); 78 testFrame.setSize(500, 400); 79 testFrame.setVisible(true); 80 } 81 static class Test { 82 private boolean pass; 83 JFrame createTestFrame(String name, Component topComponent, String instructions, int instrHeight) { 84 final String PASS = "Pass"; 85 final String FAIL = "Fail"; 86 JFrame frame = new JFrame(name); 87 frame.setLayout(new BorderLayout()); 88 89 JPanel testButtonsPanel = new JPanel(); 90 testButtonsPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20)); 91 92 ActionListener btnAL = new ActionListener() { 93 public void actionPerformed(ActionEvent event) { 94 switch (event.getActionCommand()) { 95 case PASS: 96 pass(); 97 break; 98 default: 99 throw new RuntimeException("Test failed."); 100 } 101 } 102 }; 103 JButton passBtn = new JButton(PASS); 104 passBtn.addActionListener(btnAL); 105 passBtn.setActionCommand(PASS); 106 107 JButton failBtn = new JButton(FAIL); 108 failBtn.addActionListener(btnAL); 109 failBtn.setActionCommand(FAIL); 110 111 testButtonsPanel.add(BorderLayout.WEST, passBtn); 112 testButtonsPanel.add(BorderLayout.EAST, failBtn); 113 114 JTextArea instrText = new JTextArea(); 115 instrText.setLineWrap(true); 116 instrText.setEditable(false); 117 JScrollPane instrScrollPane = new JScrollPane(instrText); 118 instrScrollPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, instrHeight)); 119 instrText.append(instructions); 120 121 JPanel servicePanel = new JPanel(); 122 servicePanel.setLayout(new BorderLayout()); 123 servicePanel.add(BorderLayout.CENTER, instrScrollPane); 124 servicePanel.add(BorderLayout.SOUTH, testButtonsPanel); 125 126 frame.add(BorderLayout.SOUTH, servicePanel); 127 frame.add(BorderLayout.CENTER, topComponent); 128 return frame; 129 } 130 synchronized void pass() { 131 pass = true; 132 notifyAll(); 133 } 134 synchronized void waitTestResult() throws InterruptedException { 135 while (!pass) { 136 wait(); 137 } 138 } 139 } 140 }