Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JMenuItem/4654927/bug4654927.java
41154 views
1
/*
2
* Copyright (c) 2012, 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 4654927
28
* @summary Clicking on Greyed Menuitems closes the Menubar Dropdown
29
* @author Alexander Potochkin
30
* @library ../../regtesthelpers
31
* @build Util
32
* @run main bug4654927
33
*/
34
35
import javax.swing.*;
36
37
import java.awt.*;
38
import java.awt.event.InputEvent;
39
import java.util.concurrent.Callable;
40
41
public class bug4654927 {
42
43
private static volatile JMenu menu;
44
private static volatile JMenuItem menuItem;
45
private static JFrame frame;
46
47
public static void main(String[] args) throws Exception {
48
try {
49
String systemLAF = UIManager.getSystemLookAndFeelClassName();
50
// the test is not applicable to Motif L&F
51
if(systemLAF.endsWith("MotifLookAndFeel")){
52
return;
53
}
54
55
UIManager.setLookAndFeel(systemLAF);
56
Robot robot = new Robot();
57
robot.setAutoDelay(10);
58
59
SwingUtilities.invokeAndWait(new Runnable() {
60
61
public void run() {
62
createAndShowUI();
63
}
64
});
65
robot.waitForIdle();
66
67
// test mouse press
68
Point point = Util.getCenterPoint(menu);
69
robot.mouseMove(point.x, point.y);
70
robot.mousePress(InputEvent.BUTTON1_MASK);
71
robot.mouseRelease(InputEvent.BUTTON1_MASK);
72
robot.waitForIdle();
73
74
point = Util.getCenterPoint(menuItem);
75
robot.mouseMove(point.x, point.y);
76
robot.mousePress(InputEvent.BUTTON1_MASK);
77
robot.mouseRelease(InputEvent.BUTTON1_MASK);
78
robot.waitForIdle();
79
80
if (!isMenuItemShowing()) {
81
throw new RuntimeException("Popup is unexpectedly closed");
82
}
83
84
// test mouse drag
85
point = Util.getCenterPoint(menu);
86
robot.mouseMove(point.x, point.y);
87
Point menuLocation = Util.invokeOnEDT(new Callable<Point>() {
88
89
@Override
90
public Point call() throws Exception {
91
return menu.getLocationOnScreen();
92
}
93
});
94
95
Point itemLocation = Util.invokeOnEDT(new Callable<Point>() {
96
97
@Override
98
public Point call() throws Exception {
99
return menuItem.getLocationOnScreen();
100
}
101
});
102
103
int x0 = menuLocation.x + 10;
104
int y0 = menuLocation.y + 10;
105
int x1 = itemLocation.x + 10;
106
int y1 = itemLocation.y + 10;
107
108
// close menu
109
robot.mousePress(InputEvent.BUTTON1_MASK);
110
robot.mouseRelease(InputEvent.BUTTON1_MASK);
111
robot.waitForIdle();
112
113
robot.mousePress(InputEvent.BUTTON1_MASK);
114
Util.glide(robot, x0, y0, x1, y1);
115
robot.mouseRelease(InputEvent.BUTTON1_MASK);
116
robot.waitForIdle();
117
118
if (!isMenuItemShowing()) {
119
throw new RuntimeException("Popup is unexpectedly closed");
120
}
121
} finally {
122
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
123
}
124
}
125
126
private static boolean isMenuItemShowing() throws Exception {
127
return Util.invokeOnEDT(new Callable<Boolean>() {
128
129
@Override
130
public Boolean call() throws Exception {
131
return menuItem.isShowing();
132
}
133
});
134
}
135
136
private static void createAndShowUI() {
137
frame = new JFrame();
138
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
139
140
menu = new JMenu("Menu");
141
menu.add(new JMenuItem("menuItem"));
142
menuItem = new JMenuItem("menuItem");
143
menuItem.setEnabled(false);
144
menu.add(menuItem);
145
menu.add(new JMenuItem("menuItem"));
146
147
JMenuBar bar = new JMenuBar();
148
bar.add(menu);
149
frame.setJMenuBar(bar);
150
151
frame.setSize(200, 200);
152
frame.setLocationRelativeTo(null);
153
frame.setVisible(true);
154
155
}
156
}
157
158