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/JFileChooser/4150029/bug4150029.java
38854 views
1
/*
2
* Copyright (c) 2010, 2013, 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
bug 4150029 8006087
26
summary BackSpace keyboard button does not lead to parent directory
27
author Oleg Mokhovikov
28
*/
29
30
import javax.swing.*;
31
import java.io.File;
32
import java.io.IOException;
33
34
public class bug4150029 extends JApplet {
35
private boolean res;
36
37
public void init() {
38
if (sun.awt.OSInfo.getOSType() == sun.awt.OSInfo.OSType.MACOSX) {
39
try {
40
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
41
} catch (Exception e) {
42
throw new RuntimeException(e);
43
}
44
}
45
46
String tmpDir = System.getProperty("java.io.tmpdir");
47
48
if (tmpDir.length() == 0) {//'java.io.tmpdir' isn't guaranteed to be defined
49
tmpDir = System.getProperty("user.home");
50
}
51
52
System.out.println("Temp directory: " + tmpDir);
53
54
File testDir = new File(tmpDir, "testDir");
55
56
testDir.mkdir();
57
58
File subDir = new File(testDir, "subDir");
59
60
subDir.mkdir();
61
62
System.out.println("Created directory: " + testDir);
63
System.out.println("Created sub-directory: " + subDir);
64
65
JFileChooser fileChooser = new JFileChooser(testDir);
66
67
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
68
69
try {
70
res = fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION ||
71
testDir.getCanonicalPath().equals(fileChooser.getSelectedFile().getCanonicalPath());
72
} catch (IOException e) {
73
res = false;
74
75
e.printStackTrace();
76
}
77
78
try {
79
subDir.delete();
80
testDir.delete();
81
} catch (SecurityException e) {
82
e.printStackTrace();
83
}
84
}
85
86
public void destroy() {
87
if (!res) {
88
throw new RuntimeException("BackSpace keyboard button does not lead to parent directory");
89
}
90
}
91
}
92
93