1 /* 2 * Copyright (c) 2007, 2018, 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 @key headful 27 @bug 6533175 28 @summary Block F10 if closest toplevel to keystroke target is not a Frame. 29 @run main F10TopToplevel 30 */ 31 32 import java.awt.*; 33 import java.awt.event.*; 34 35 public class F10TopToplevel { 36 37 static Frame frame; 38 static Dialog dialog; 39 static volatile boolean menuToggled = false; 40 41 public static void main(final String[] args) { 42 MenuBar mb; 43 Menu menu; 44 MenuItem item; 45 frame = new Frame("am below"); 46 frame.setMenuBar( (mb=new MenuBar()) ); 47 menu = new Menu("nu"); 48 menu.add((item = new MenuItem("item"))); 49 item.addActionListener( new ActionListener() { 50 public void actionPerformed( ActionEvent ae ) { 51 menuToggled = true; 52 } 53 }); 54 mb.add(menu); 55 56 frame.setSize(200,200); 57 frame.setLocation( 400,100 ); 58 frame.setVisible( true ); 59 60 dialog = new Dialog(frame); 61 dialog.setSize( 100,100 ); 62 dialog.setVisible(true); 63 64 Robot robot; 65 try { 66 robot = new Robot(); 67 robot.setAutoDelay(5); 68 } catch(AWTException e){ 69 throw new RuntimeException("cannot create robot.", e); 70 } 71 robot.waitForIdle(); 72 robot.mouseMove(dialog.getLocationOnScreen().x + dialog.getWidth()/2, 73 dialog.getLocationOnScreen().y + dialog.getHeight()/2 ); 74 robot.waitForIdle(); 75 robot.mousePress(InputEvent.BUTTON1_MASK); 76 robot.mouseRelease(InputEvent.BUTTON1_MASK); 77 robot.waitForIdle(); 78 robot.keyPress(KeyEvent.VK_F10); 79 robot.keyRelease(KeyEvent.VK_F10); 80 81 robot.delay(10); 82 robot.keyPress(KeyEvent.VK_ENTER); 83 robot.waitForIdle(); 84 robot.keyRelease(KeyEvent.VK_ENTER); 85 86 robot.waitForIdle(); 87 88 if(menuToggled) { 89 throw new RuntimeException("Oops! Menu should not open."); 90 } 91 92 } 93 }// class F10TopToplevel