|
| 1 | +/* |
| 2 | + * Copyright (c) 2002, 2023, 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 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 4732229 |
| 27 | + * @summary Ctrl+Space, bringing up System menu on a JIF errors using Win LAF |
| 28 | + * @key headful |
| 29 | + * @run main bug4732229 |
| 30 | + */ |
| 31 | + |
| 32 | +import javax.swing.JFrame; |
| 33 | +import javax.swing.JDesktopPane; |
| 34 | +import javax.swing.JInternalFrame; |
| 35 | +import javax.swing.JTextArea; |
| 36 | +import javax.swing.SwingUtilities; |
| 37 | +import javax.swing.UIManager; |
| 38 | +import java.awt.Robot; |
| 39 | +import java.awt.event.FocusAdapter; |
| 40 | +import java.awt.event.FocusEvent; |
| 41 | +import java.awt.event.KeyEvent; |
| 42 | + |
| 43 | +public class bug4732229 { |
| 44 | + |
| 45 | + JFrame frame; |
| 46 | + JDesktopPane desktop; |
| 47 | + JInternalFrame jif; |
| 48 | + JTextArea ta; |
| 49 | + Robot robot; |
| 50 | + volatile boolean keyTyped = false; |
| 51 | + |
| 52 | + public static void main(String[] args) throws Exception { |
| 53 | + bug4732229 b = new bug4732229(); |
| 54 | + b.init(); |
| 55 | + } |
| 56 | + |
| 57 | + public void init() throws Exception { |
| 58 | + robot = new Robot(); |
| 59 | + robot.setAutoDelay(100); |
| 60 | + try { |
| 61 | + SwingUtilities.invokeAndWait(() -> { |
| 62 | + frame = new JFrame("bug4732229"); |
| 63 | + desktop = new JDesktopPane(); |
| 64 | + frame.getContentPane().add(desktop); |
| 65 | + |
| 66 | + ta = new JTextArea(); |
| 67 | + ta.addFocusListener(new FocusAdapter() { |
| 68 | + public void focusGained(FocusEvent e) { |
| 69 | + synchronized (bug4732229.this) { |
| 70 | + keyTyped = true; |
| 71 | + bug4732229.this.notifyAll(); |
| 72 | + } |
| 73 | + } |
| 74 | + }); |
| 75 | + frame.setSize(200, 200); |
| 76 | + frame.setLocationRelativeTo(null); |
| 77 | + frame.setVisible(true); |
| 78 | + jif = new JInternalFrame("Internal Frame", true, false, true, |
| 79 | + true); |
| 80 | + jif.setBounds(10, 10, 100, 100); |
| 81 | + jif.getContentPane().add(ta); |
| 82 | + jif.setVisible(true); |
| 83 | + desktop.add(jif); |
| 84 | + try { |
| 85 | + jif.setSelected(true); |
| 86 | + } catch (Exception e) { |
| 87 | + throw new RuntimeException(e); |
| 88 | + } |
| 89 | + |
| 90 | + }); |
| 91 | + synchronized (this) { |
| 92 | + while (!keyTyped) { |
| 93 | + bug4732229.this.wait(); |
| 94 | + } |
| 95 | + } |
| 96 | + robot.waitForIdle(); |
| 97 | + robot.delay(200); |
| 98 | + robot.keyPress(KeyEvent.VK_CONTROL); |
| 99 | + robot.keyPress(KeyEvent.VK_SPACE); |
| 100 | + robot.keyRelease(KeyEvent.VK_SPACE); |
| 101 | + robot.keyRelease(KeyEvent.VK_CONTROL); |
| 102 | + robot.waitForIdle(); |
| 103 | + robot.delay(200); |
| 104 | + SwingUtilities.invokeAndWait(() -> { |
| 105 | + try { |
| 106 | + jif.setSelected(false); |
| 107 | + } catch (Exception e) { |
| 108 | + throw new RuntimeException(e); |
| 109 | + } |
| 110 | + jif.setVisible(false); |
| 111 | + desktop.remove(jif); |
| 112 | + try { |
| 113 | + UIManager.setLookAndFeel( |
| 114 | + UIManager.getSystemLookAndFeelClassName()); |
| 115 | + } catch (Exception e) { |
| 116 | + throw new RuntimeException(e); |
| 117 | + } |
| 118 | + desktop.updateUI(); |
| 119 | + |
| 120 | + jif = new JInternalFrame("Internal Frame", true, false, true, |
| 121 | + true); |
| 122 | + jif.setBounds(10, 10, 100, 100); |
| 123 | + jif.getContentPane().add(ta); |
| 124 | + jif.setVisible(true); |
| 125 | + desktop.add(jif); |
| 126 | + try { |
| 127 | + jif.setSelected(true); |
| 128 | + } catch (Exception e) { |
| 129 | + throw new RuntimeException(e); |
| 130 | + } |
| 131 | + }); |
| 132 | + synchronized (this) { |
| 133 | + while (!keyTyped) { |
| 134 | + bug4732229.this.wait(); |
| 135 | + } |
| 136 | + } |
| 137 | + robot.keyPress(KeyEvent.VK_CONTROL); |
| 138 | + robot.keyPress(KeyEvent.VK_SPACE); |
| 139 | + robot.keyRelease(KeyEvent.VK_SPACE); |
| 140 | + robot.keyRelease(KeyEvent.VK_CONTROL); |
| 141 | + robot.waitForIdle(); |
| 142 | + robot.delay(200); |
| 143 | + } finally { |
| 144 | + SwingUtilities.invokeAndWait(() -> { |
| 145 | + if (frame != null) { |
| 146 | + frame.dispose(); |
| 147 | + } |
| 148 | + }); |
| 149 | + } |
| 150 | + } |
| 151 | +} |
0 commit comments