Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JPopupMenu/6217905/bug6217905.java
41155 views
1
/*
2
* Copyright (c) 2011, 2017, 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 6217905
28
* @summary JPopupMenu keyboard navigation stops working
29
* @author Alexander Potochkin
30
* @requires (os.family == "windows")
31
* @library /lib/client
32
* @build ExtendedRobot
33
* @run main bug6217905
34
*/
35
36
import javax.swing.*;
37
import java.awt.*;
38
import java.awt.event.InputEvent;
39
import java.awt.event.KeyEvent;
40
41
public class bug6217905 {
42
private static JPanel popupPanel;
43
private static JMenuItem firstItem;
44
private static JMenuItem lastItem;
45
private static JFrame frame;
46
47
private static void createGui() {
48
frame = new JFrame();
49
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
50
51
JPopupMenu popup = new JPopupMenu("Menu");
52
firstItem = new JMenuItem("MenuItem");
53
popup.add(firstItem);
54
popup.add(new JMenuItem("MenuItem"));
55
lastItem = new JMenuItem("MenuItem");
56
popup.add(lastItem);
57
58
popupPanel = new JPanel();
59
popupPanel.setComponentPopupMenu(popup);
60
frame.add(popupPanel);
61
frame.setSize(100, 100);
62
frame.setVisible(true);
63
}
64
65
public static void main(String[] args) throws Exception {
66
try {
67
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
68
} catch (Exception e) {
69
// This test is for WinLaf only
70
System.out.println("This test is for Windows LaF only.");
71
return;
72
}
73
74
try {
75
ExtendedRobot robot = new ExtendedRobot();
76
robot.setAutoDelay(10);
77
SwingUtilities.invokeLater(new Runnable() {
78
public void run() {
79
bug6217905.createGui();
80
}
81
});
82
robot.waitForIdle();
83
Point loc = popupPanel.getLocationOnScreen();
84
int x = loc.x + popupPanel.getWidth()/2;
85
int y = loc.y + popupPanel.getHeight()/2;
86
robot.glide(0, 0, x, y);
87
robot.mousePress(InputEvent.BUTTON3_MASK);
88
robot.mouseRelease(InputEvent.BUTTON3_MASK);
89
robot.waitForIdle();
90
if (getSelectedPathLength() != 1) {
91
throw new RuntimeException("Only popup must be selected");
92
}
93
robot.glide(x, y, 0, 0);
94
robot.type(KeyEvent.VK_DOWN);
95
robot.waitForIdle();
96
if (getSelectedPathLength() != 2 || !firstItem.isArmed()) {
97
throw new RuntimeException("First item must be selected");
98
}
99
robot.type(KeyEvent.VK_ESCAPE);
100
robot.waitForIdle();
101
if (getSelectedPathLength() != 0) {
102
throw new RuntimeException("There must be no selected items");
103
}
104
robot.glide(0, 0, x, y);
105
robot.mousePress(InputEvent.BUTTON3_MASK);
106
robot.mouseRelease(InputEvent.BUTTON3_MASK);
107
robot.waitForIdle();
108
robot.glide(x, y, 0, 0);
109
robot.type(KeyEvent.VK_UP);
110
robot.waitForIdle();
111
if (getSelectedPathLength() != 2 || !lastItem.isArmed()) {
112
throw new RuntimeException("Last item must be selected");
113
}
114
} finally {
115
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
116
}
117
}
118
119
private static int getSelectedPathLength() {
120
return MenuSelectionManager.defaultManager().getSelectedPath().length;
121
}
122
}
123
124