Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JFileChooser/ExternalDriveNameTest.java
41149 views
1
/*
2
* Copyright (c) 2018, 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 8191957
28
* @requires (os.family == "Windows")
29
* @summary Check Verifies that external drive names are shown properly when
30
* "Desktop" is selected in JFileChooser
31
* @run main/manual ExternalDriveNameTest
32
*/
33
import java.awt.Color;
34
import java.awt.GridBagConstraints;
35
import java.awt.GridBagLayout;
36
import java.util.concurrent.CountDownLatch;
37
import javax.swing.JPanel;
38
import javax.swing.JTextArea;
39
import javax.swing.SwingUtilities;
40
import javax.swing.JButton;
41
import javax.swing.JFrame;
42
import java.awt.event.ActionEvent;
43
import java.awt.event.ActionListener;
44
import java.util.concurrent.TimeUnit;
45
import javax.swing.JFileChooser;
46
47
public class ExternalDriveNameTest {
48
49
public static void main(String args[]) throws Exception {
50
final CountDownLatch latch = new CountDownLatch(1);
51
TestUI test = new TestUI(latch);
52
SwingUtilities.invokeAndWait(() -> {
53
try {
54
test.createUI();
55
} catch (Exception ex) {
56
throw new RuntimeException("Exception while creating UI");
57
}
58
});
59
60
boolean status = latch.await(5, TimeUnit.MINUTES);
61
62
if (!status) {
63
System.out.println("Test timed out.");
64
}
65
66
SwingUtilities.invokeAndWait(() -> {
67
try {
68
test.disposeUI();
69
} catch (Exception ex) {
70
throw new RuntimeException("Exception while disposing UI");
71
}
72
});
73
74
if (test.testResult == false) {
75
throw new RuntimeException("Test Failed.");
76
}
77
}
78
}
79
80
class TestUI {
81
82
private static JFrame mainFrame;
83
private static JPanel mainControlPanel;
84
85
private static JTextArea instructionTextArea;
86
87
private static JPanel resultButtonPanel;
88
private static JButton passButton;
89
private static JButton failButton;
90
91
private static GridBagLayout layout;
92
private final CountDownLatch latch;
93
public boolean testResult = false;
94
95
public TestUI(CountDownLatch latch) throws Exception {
96
this.latch = latch;
97
}
98
99
public final void createUI() throws Exception {
100
mainFrame = new JFrame("JFileChooser_ExternalDriveNameTest");
101
102
layout = new GridBagLayout();
103
mainControlPanel = new JPanel(layout);
104
resultButtonPanel = new JPanel(layout);
105
106
GridBagConstraints gbc = new GridBagConstraints();
107
108
// Create Test instructions
109
String instructions
110
= "INSTRUCTIONS:" +
111
"\n 1. This is a Windows 10 specific test. If you are not on " +
112
"Windows 10, press Pass." +
113
"\n 2. Make sure you have an External Drive attached to your " +
114
"computer." +
115
"\n 3. Open a JFileChooser by clicking on launch button." +
116
"\n 4. In JFileChooser dropdown, there are two Desktop " +
117
"locations." +
118
"\n 5. One Desktop is child of My PC and one is parent of it." +
119
"\n 6. Open the parent Desktop folder." +
120
"\n 7. You should see the External Drive in the list of " +
121
"files." +
122
"\n 8. If the External drive name is empty (it does not have " +
123
"any name), press Fail, else press Pass.";
124
125
instructionTextArea = new JTextArea();
126
instructionTextArea.setText(instructions);
127
instructionTextArea.setEnabled(false);
128
instructionTextArea.setDisabledTextColor(Color.black);
129
instructionTextArea.setBackground(Color.white);
130
131
gbc.gridx = 0;
132
gbc.gridy = 0;
133
gbc.fill = GridBagConstraints.HORIZONTAL;
134
mainControlPanel.add(instructionTextArea, gbc);
135
JButton launchButton = new JButton("Launch");
136
launchButton.setActionCommand("Launch");
137
launchButton.addActionListener((ActionEvent e) -> {
138
JFileChooser fileChooser = new JFileChooser();
139
fileChooser.showOpenDialog(null);
140
}
141
);
142
143
gbc.gridx = 0;
144
gbc.gridy = 1;
145
mainControlPanel.add(launchButton, gbc);
146
147
passButton = new JButton("Pass");
148
passButton.setActionCommand("Pass");
149
passButton.addActionListener((ActionEvent e) -> {
150
testResult = true;
151
mainFrame.dispose();
152
latch.countDown();
153
154
});
155
failButton = new JButton("Fail");
156
failButton.setActionCommand("Fail");
157
failButton.addActionListener(new ActionListener() {
158
@Override
159
public void actionPerformed(ActionEvent e) {
160
testResult = false;
161
mainFrame.dispose();
162
latch.countDown();
163
}
164
});
165
gbc.gridx = 0;
166
gbc.gridy = 0;
167
resultButtonPanel.add(passButton, gbc);
168
gbc.gridx = 1;
169
gbc.gridy = 0;
170
resultButtonPanel.add(failButton, gbc);
171
172
gbc.gridx = 0;
173
gbc.gridy = 2;
174
mainControlPanel.add(resultButtonPanel, gbc);
175
176
mainFrame.add(mainControlPanel);
177
mainFrame.pack();
178
mainFrame.setVisible(true);
179
}
180
181
public void disposeUI() {
182
mainFrame.setVisible(false);
183
mainFrame.dispose();
184
}
185
}
186
187