Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JOptionPane/6428694/bug6428694.java
38918 views
1
/*
2
* Copyright (c) 2011, 2014, 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 6428694
26
@summary Checks that double click closes JOptionPane's input dialog.
27
@library ../../../../lib/testlibrary
28
@build ExtendedRobot
29
@author Mikhail Lapshin
30
@run main bug6428694
31
*/
32
33
import javax.swing.JFrame;
34
import javax.swing.SwingUtilities;
35
import javax.swing.JOptionPane;
36
import java.awt.*;
37
import java.awt.event.InputEvent;
38
39
public class bug6428694 {
40
private static JFrame frame;
41
private static boolean mainIsWaitingForDialogClosing;
42
private static ExtendedRobot robot;
43
private static volatile boolean testPassed;
44
45
public static void main(String[] args) throws Exception {
46
robot = new ExtendedRobot();
47
try {
48
SwingUtilities.invokeLater(new Runnable() {
49
public void run() {
50
bug6428694.setupUI();
51
}
52
});
53
robot.waitForIdle();
54
test();
55
} finally {
56
stopEDT();
57
}
58
59
if (testPassed) {
60
System.out.println("Test passed");
61
} else {
62
throw new RuntimeException("JOptionPane doesn't close input dialog " +
63
"by double click!");
64
}
65
}
66
67
private static void setupUI() {
68
frame = new JFrame("bug6428694 test");
69
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
70
frame.setVisible(true);
71
72
Object[] selectedItems = new Object[40];
73
for (int i = 0; i < 39; i++) {
74
selectedItems[i] = ("item: " + i);
75
}
76
JOptionPane.showInputDialog(frame,
77
"Double click on selected item then click cancel",
78
"Test Option Dialog", JOptionPane.WARNING_MESSAGE, null,
79
selectedItems, selectedItems[0]);
80
81
// We are here if double click has closed the dialog
82
// or when the EDT is stopping
83
testPassed = mainIsWaitingForDialogClosing;
84
}
85
86
private static void test() {
87
88
mainIsWaitingForDialogClosing = true;
89
90
// Perform double click on an item
91
int frameLeftX = frame.getLocationOnScreen().x;
92
int frameUpperY = frame.getLocationOnScreen().y;
93
robot.mouseMove(frameLeftX + 150, frameUpperY + 120);
94
robot.waitForIdle();
95
robot.delay(100);
96
robot.setAutoDelay(50);
97
robot.mousePress(InputEvent.BUTTON1_MASK);
98
robot.mouseRelease(InputEvent.BUTTON1_MASK);
99
robot.mousePress(InputEvent.BUTTON1_MASK);
100
robot.mouseRelease(InputEvent.BUTTON1_MASK);
101
102
// Wait for the input dialog closing
103
robot.waitForIdle();
104
robot.delay(2000);
105
106
mainIsWaitingForDialogClosing = false;
107
}
108
109
private static void stopEDT() {
110
if (frame != null) {
111
frame.dispose();
112
}
113
}
114
}
115
116