Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JPopupMenu/8075063/ContextMenuScrollTest.java
41155 views
1
/*
2
* Copyright (c) 2017, 2021, 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 8075063
27
* @summary Verifies if Context menu closes on mouse scroll
28
* @run main ContextMenuScrollTest
29
*/
30
import java.awt.Dimension;
31
import java.awt.Point;
32
import java.awt.Robot;
33
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionListener;
35
import java.awt.event.InputEvent;
36
import java.awt.event.KeyEvent;
37
import javax.swing.JComponent;
38
import javax.swing.JFrame;
39
import javax.swing.JMenu;
40
import javax.swing.JMenuBar;
41
import javax.swing.JMenuItem;
42
import javax.swing.JPopupMenu;
43
import javax.swing.JSeparator;
44
import javax.swing.KeyStroke;
45
import javax.swing.SwingUtilities;
46
47
public class ContextMenuScrollTest extends JPopupMenu
48
{
49
private static Robot robot;
50
private static JFrame frame;
51
private static JMenu menu;
52
private static volatile Point p = null;
53
private static volatile Dimension d = null;
54
private static volatile boolean popupVisible = false;
55
56
public static void main(String[] args) throws Exception {
57
robot = new Robot();
58
robot.setAutoDelay(100);
59
try {
60
SwingUtilities.invokeAndWait(()->createGUI());
61
robot.waitForIdle();
62
robot.delay(1000);
63
64
SwingUtilities.invokeAndWait(() -> {
65
p = menu.getLocationOnScreen();
66
d = menu.getSize();
67
});
68
System.out.println("p " + p + " d " + d);
69
robot.mouseMove(p.x + d.width/2, p.y + d.height/2);
70
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
71
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
72
robot.waitForIdle();
73
robot.delay(1000);
74
75
robot.mouseWheel(1);
76
robot.waitForIdle();
77
78
SwingUtilities.invokeAndWait(() -> {
79
popupVisible = menu.isPopupMenuVisible();
80
});
81
if (!popupVisible) {
82
throw new RuntimeException("Popup closes on mouse scroll");
83
}
84
} finally {
85
SwingUtilities.invokeAndWait(()->frame.dispose());
86
}
87
}
88
89
90
public static void createGUI() {
91
frame = new JFrame();
92
JMenuBar menuBar = new JMenuBar();
93
menu = new JMenu("Menu");
94
menuBar.add(menu);
95
96
JMenuItem undo = new JMenuItem("Undo");
97
undo.setEnabled(false);
98
undo.setAccelerator(KeyStroke.getKeyStroke("control Z"));
99
undo.addActionListener(new ActionListener() {
100
@Override
101
public void actionPerformed(ActionEvent event) {
102
}
103
});
104
105
menu.add(undo);
106
107
JMenuItem redo = new JMenuItem("Redo");
108
redo.setEnabled(false);
109
redo.setAccelerator(KeyStroke.getKeyStroke("control Y"));
110
redo.addActionListener(new ActionListener() {
111
@Override
112
public void actionPerformed(ActionEvent event) {
113
}
114
});
115
menu.add(redo);
116
117
menu.add(new JSeparator());
118
119
JMenuItem cut = new JMenuItem("Cut");
120
cut.setEnabled(false);
121
cut.setAccelerator(KeyStroke.getKeyStroke("control X"));
122
cut.addActionListener(new ActionListener() {
123
@Override
124
public void actionPerformed(ActionEvent event) {
125
}
126
});
127
128
menu.add(cut);
129
130
JMenuItem copy = new JMenuItem("Copy");
131
copy.setEnabled(false);
132
copy.setAccelerator(KeyStroke.getKeyStroke("control C"));
133
copy.addActionListener(new ActionListener() {
134
@Override
135
public void actionPerformed(ActionEvent event) {
136
}
137
});
138
139
menu.add(copy);
140
141
JMenuItem paste = new JMenuItem("Paste");
142
paste.setEnabled(false);
143
paste.setAccelerator(KeyStroke.getKeyStroke("control V"));
144
paste.addActionListener(new ActionListener() {
145
@Override
146
public void actionPerformed(ActionEvent event) {
147
}
148
});
149
150
menu.add(paste);
151
152
JMenuItem delete = new JMenuItem("Delete");
153
delete.setEnabled(false);
154
delete.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
155
delete.addActionListener(new ActionListener() {
156
@Override
157
public void actionPerformed(ActionEvent event) {
158
}
159
});
160
161
menu.add(delete);
162
163
menu.add(new JSeparator());
164
165
JMenuItem selectAll = new JMenuItem("Select All");
166
selectAll.setEnabled(false);
167
selectAll.setAccelerator(KeyStroke.getKeyStroke("control A"));
168
selectAll.addActionListener(new ActionListener() {
169
@Override
170
public void actionPerformed(ActionEvent event) {
171
}
172
});
173
menu.add(selectAll);
174
frame.setJMenuBar(menuBar);
175
176
frame.pack();
177
frame.setLocationRelativeTo(null);
178
frame.setVisible(true);
179
}
180
}
181
182