Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JFileChooser/TestJFileChooserNewFolderAction.java
41152 views
1
/*
2
* Copyright (c) 2020, 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 8231042
28
* @requires (os.family == "mac")
29
* @summary Verify that JFileChooser's New Folder option works correctly
30
* in AquaLookAndFeel
31
* @run main/manual TestJFileChooserNewFolderAction
32
*/
33
34
import javax.swing.JFrame;
35
import javax.swing.JTextArea;
36
import javax.swing.JPanel;
37
import javax.swing.SwingUtilities;
38
import javax.swing.JButton;
39
import javax.swing.JFileChooser;
40
import javax.swing.UIManager;
41
import javax.swing.UnsupportedLookAndFeelException;
42
import java.awt.Color;
43
import java.awt.GridBagLayout;
44
import java.awt.GridBagConstraints;
45
import java.awt.Insets;
46
import java.awt.event.ActionEvent;
47
import java.util.concurrent.CountDownLatch;
48
import java.util.concurrent.TimeUnit;
49
50
public class TestJFileChooserNewFolderAction {
51
private static final JFrame instructionFrame = new JFrame();
52
private static final String lafName = "AquaLookAndFeel";
53
private static volatile boolean testPassed = false;
54
private static volatile CountDownLatch countDownLatch;
55
56
private static final String INSTRUCTIONS = "INSTRUCTIONS:\n\n" +
57
"Make sure there is no folder named \"uninitializedValue\" in\n"+
58
"JFileChooser directory, else change JFileChooser directory.\n"+
59
"Click on \"New Folder\" button in JFileChooser. \n" +
60
"A JOptionPane will be opened to write the name of the folder.\n"+
61
"Press \"ESC\" key to close the JOptionPane without creating \n"+
62
"new folder. Verify that JFileChooser current directory has not\n"+
63
"changed and there is no folder named \"uninitializedValue\"\n"+
64
"created in the JFileChooser directory.\n" +
65
"If yes, Press Pass, Otherwise, Press Fail.\n";
66
67
68
public static void main(String[] args) throws Exception{
69
70
if (!System.getProperty("os.name").startsWith("Mac")) {
71
System.out.println("This test is meant for Mac platform only");
72
return;
73
}
74
75
countDownLatch = new CountDownLatch(1);
76
for (UIManager.LookAndFeelInfo lookAndFeelInfo :
77
UIManager.getInstalledLookAndFeels()) {
78
if (lookAndFeelInfo.getClassName().contains(lafName)) {
79
try {
80
UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
81
} catch (final UnsupportedLookAndFeelException ignored) {
82
System.out.println("Aqua L&F could not be set, so this " +
83
"test can not be run in this scenario ");
84
return;
85
}
86
}
87
}
88
89
SwingUtilities.invokeAndWait(TestJFileChooserNewFolderAction::createInstructionUI);
90
91
SwingUtilities.invokeAndWait(TestJFileChooserNewFolderAction::createTestUI);
92
93
countDownLatch.await(15, TimeUnit.MINUTES);
94
95
SwingUtilities.invokeAndWait(TestJFileChooserNewFolderAction::disposeUI);
96
if (!testPassed) {
97
throw new RuntimeException("Test failed!");
98
}
99
}
100
101
private static void createInstructionUI() {
102
GridBagLayout layout = new GridBagLayout();
103
JPanel mainControlPanel = new JPanel(layout);
104
JPanel resultButtonPanel = new JPanel(layout);
105
106
GridBagConstraints gbc = new GridBagConstraints();
107
108
gbc.gridx = 0;
109
gbc.gridy = 0;
110
gbc.insets = new Insets(5, 15, 5, 15);
111
gbc.fill = GridBagConstraints.HORIZONTAL;
112
113
JTextArea instructionTextArea = new JTextArea();
114
instructionTextArea.setText(INSTRUCTIONS);
115
instructionTextArea.setEditable(false);
116
instructionTextArea.setBackground(Color.white);
117
mainControlPanel.add(instructionTextArea, gbc);
118
119
JButton passButton = new JButton("Pass");
120
passButton.setActionCommand("Pass");
121
passButton.addActionListener((ActionEvent e) -> {
122
testPassed = true;
123
countDownLatch.countDown();
124
125
});
126
127
JButton failButton = new JButton("Fail");
128
failButton.setActionCommand("Fail");
129
failButton.addActionListener(e -> {
130
countDownLatch.countDown();
131
});
132
133
gbc.gridx = 0;
134
gbc.gridy = 0;
135
136
resultButtonPanel.add(passButton, gbc);
137
138
gbc.gridx = 1;
139
gbc.gridy = 0;
140
resultButtonPanel.add(failButton, gbc);
141
142
gbc.gridx = 0;
143
gbc.gridy = 2;
144
mainControlPanel.add(resultButtonPanel, gbc);
145
146
instructionFrame.pack();
147
instructionFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
148
instructionFrame.add(mainControlPanel);
149
instructionFrame.pack();
150
instructionFrame.setVisible(true);
151
}
152
153
private static void createTestUI() {
154
new JFileChooser().showSaveDialog(null);
155
}
156
157
private static void disposeUI() {
158
instructionFrame.dispose();
159
}
160
}
161
162