Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JPopupMenu/6580930/bug6580930.java
41153 views
1
/*
2
* Copyright (c) 2007, 2019, 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
* @key headful
26
* @bug 6580930 7184956
27
* @summary Swing Popups should overlap taskbar
28
* @author Alexander Potochkin
29
* @library /lib/client
30
* @build ExtendedRobot
31
* @run main bug6580930
32
*/
33
34
import javax.swing.*;
35
import java.awt.*;
36
import java.awt.event.InputEvent;
37
import java.awt.event.KeyEvent;
38
39
public class bug6580930 {
40
private static ExtendedRobot robot;
41
private static JFrame frame;
42
private static JPopupMenu popup;
43
private static Toolkit toolkit;
44
private static volatile boolean skipTest = false;
45
private static Point loc;
46
private static int y;
47
48
private static void createGui() {
49
frame = new JFrame();
50
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
51
frame.setUndecorated(true);
52
53
popup = new JPopupMenu("Menu");
54
for (int i = 0; i < 7; i++) {
55
popup.add(new JMenuItem("MenuItem"));
56
}
57
JPanel panel = new JPanel();
58
panel.setComponentPopupMenu(popup);
59
frame.add(panel);
60
61
frame.setSize(200, 200);
62
}
63
64
65
public static void main(String[] args) throws Exception {
66
try {
67
SwingUtilities.invokeAndWait(new Runnable() {
68
public void run() {
69
JPopupMenu.setDefaultLightWeightPopupEnabled(true);
70
bug6580930.createGui();
71
}
72
});
73
74
toolkit = Toolkit.getDefaultToolkit();
75
robot = new ExtendedRobot();
76
robot.setAutoDelay(10);
77
robot.waitForIdle();
78
79
SwingUtilities.invokeAndWait(new Runnable() {
80
public void run() {
81
Insets insets = toolkit.getScreenInsets(frame.getGraphicsConfiguration());
82
if (insets.bottom == 0) {
83
System.out.println("This test is only for configurations with taskbar on the bottom");
84
85
skipTest = true;
86
}
87
88
Dimension screenSize = toolkit.getScreenSize();
89
frame.setLocation(screenSize.width/2, screenSize.height - frame.getHeight() - insets.bottom + 10);
90
frame.setVisible(true);
91
}
92
});
93
94
robot.waitForIdle();
95
96
if(skipTest) {
97
return;
98
}
99
100
SwingUtilities.invokeAndWait(() -> loc = frame.getLocationOnScreen());
101
robot.waitForIdle();
102
103
robot.mouseMove(loc.x, loc.y);
104
showPopup();
105
robot.waitForIdle();
106
if (!System.getProperty("os.name").startsWith("Mac")
107
&& isHeavyWeightMenuVisible()) {
108
throw new RuntimeException("HeavyWeightPopup is unexpectedly visible");
109
}
110
111
robot.keyPress(KeyEvent.VK_ESCAPE);
112
robot.keyRelease(KeyEvent.VK_ESCAPE);
113
114
int x = loc.x;
115
SwingUtilities.invokeAndWait( () -> y = loc.y + (frame.getHeight() -
116
popup.getPreferredSize().height) + 1);
117
robot.waitForIdle();
118
robot.mouseMove(x, y);
119
120
showPopup();
121
SwingUtilities.invokeAndWait(() -> loc = popup.getLocationOnScreen());
122
robot.waitForIdle();
123
124
if (!loc.equals(new Point(x, y))) {
125
throw new RuntimeException("Popup is unexpectedly shifted");
126
}
127
128
if (!isHeavyWeightMenuVisible()) {
129
throw new RuntimeException("HeavyWeightPopup is unexpectedly hidden");
130
}
131
} finally {
132
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
133
}
134
}
135
136
private static void showPopup() {
137
robot.mousePress(InputEvent.BUTTON1_MASK);
138
robot.mouseRelease(InputEvent.BUTTON1_MASK);
139
robot.waitForIdle();
140
if (!popup.isShowing()) {
141
robot.mousePress(InputEvent.BUTTON2_MASK);
142
robot.mouseRelease(InputEvent.BUTTON2_MASK);
143
robot.waitForIdle();
144
if (!popup.isShowing()) {
145
robot.mousePress(InputEvent.BUTTON3_MASK);
146
robot.mouseRelease(InputEvent.BUTTON3_MASK);
147
robot.waitForIdle();
148
}
149
}
150
}
151
152
private static boolean isHeavyWeightMenuVisible() {
153
Window[] windows = Window.getWindows();
154
for (Window window : windows) {
155
if (window.getClass().getSimpleName().equals("HeavyWeightWindow")
156
&& window.isVisible()) {
157
return true;
158
}
159
}
160
return false;
161
}
162
}
163
164