1 /*
2 * Copyright (c) 2007, 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 test
25 @bug 6533175
26 @summary Block F10 if closest toplevel to keystroke target is not a Frame.
27 @author yuri nesterenko : area=awt.toplevel
28 @run applet F10TopToplevel.html
29 */
30
31
32
33 /**
34 * F10TopToplevel.java
35 *
36 * summary: tests if F10 has no effect if focused toplevel if not Frame
37 */
38
39 import java.applet.Applet;
40 import java.awt.*;
41 import java.awt.event.*;
42
43
44 public class F10TopToplevel extends Applet
45 {
46 //Declare things used in the test, like buttons and labels here
47 Frame frame;
48 Dialog dialog;
49 volatile boolean menuToggled = false;
50
51 public void init()
52 {
53 setLayout (new BorderLayout ());
54
55 }//End init()
56
57 public void start ()
58 {
59 //Get things going. Request focus, set size, et cetera
60 setSize (200,200);
61 setVisible(true);
62 validate();
63
64
65 //What would normally go into main() will probably go here.
66 //Use System.out.println for diagnostic messages that you want
67 //to read after the test is done.
68 MenuBar mb;
69 Menu menu;
70 MenuItem item;
71 frame = new Frame("am below");
72 frame.setMenuBar( (mb=new MenuBar()) );
73 menu = new Menu("nu");
74 menu.add((item = new MenuItem("item")));
75 item.addActionListener( new ActionListener() {
76 public void actionPerformed( ActionEvent ae ) {
77 menuToggled = true;
78 }
79 });
80 mb.add(menu);
81
82 frame.setSize(200,200);
83 frame.setLocation( 400,100 );
84 frame.setVisible( true );
85
86 dialog = new Dialog(frame);
87 dialog.setSize( 100,100 );
98 robot.mouseMove(dialog.getLocationOnScreen().x + dialog.getWidth()/2,
99 dialog.getLocationOnScreen().y + dialog.getHeight()/2 );
100 robot.waitForIdle();
101 robot.mousePress(InputEvent.BUTTON1_MASK);
102 robot.mouseRelease(InputEvent.BUTTON1_MASK);
103 robot.waitForIdle();
104 robot.keyPress(KeyEvent.VK_F10);
105 robot.keyRelease(KeyEvent.VK_F10);
106
107 robot.delay(10);
108 robot.keyPress(KeyEvent.VK_ENTER);
109 robot.waitForIdle();
110 robot.keyRelease(KeyEvent.VK_ENTER);
111
112 robot.waitForIdle();
113
114 if(menuToggled) {
115 throw new RuntimeException("Oops! Menu should not open.");
116 }
117
118 }// start()
119
120 }// class F10TopToplevel
|
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 );
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
|