Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JFileChooser/FileSystemView/SystemIconTest.java
41154 views
1
/*
2
* Copyright (c) 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
/*
25
* @test
26
* @bug 8182043
27
* @summary Access to Windows Large Icons
28
* @run main SystemIconTest
29
*/
30
import javax.swing.Icon;
31
import javax.swing.ImageIcon;
32
import javax.swing.filechooser.FileSystemView;
33
import java.awt.image.MultiResolutionImage;
34
import java.io.File;
35
36
public class SystemIconTest {
37
static final FileSystemView fsv = FileSystemView.getFileSystemView();
38
39
public static void main(String[] args) {
40
testSystemIcon();
41
negativeTests();
42
}
43
44
static void testSystemIcon() {
45
String os = System.getProperty("os.name");
46
if (os.startsWith("Windows")) {
47
String windir = System.getenv("windir");
48
testSystemIcon(new File(windir), true);
49
testSystemIcon(new File(windir + "/explorer.exe"),
50
true);
51
} else {
52
String homedir = System.getProperty("user.home");
53
testSystemIcon(new File(homedir), false);
54
}
55
}
56
57
static void negativeTests() {
58
Icon icon;
59
try {
60
icon = fsv.getSystemIcon(new File("."), -1, 16);
61
throw new RuntimeException("Negative size icon should throw invalid argument exception");
62
} catch (IllegalArgumentException iae) {
63
// Expected
64
}
65
66
icon = fsv.getSystemIcon(new File("thereisdefinitelynosuchfile.why"),
67
16, 16);
68
if (icon != null) {
69
throw new RuntimeException("Icons for files with invalid names should be null");
70
}
71
}
72
73
static void testSystemIcon(File file, boolean implComplete) {
74
int[] sizes = new int[] {16, 32, 48, 64, 128};
75
for (int size : sizes) {
76
ImageIcon icon = (ImageIcon) fsv.getSystemIcon(file, size, size);
77
78
//Enable below to see the icon
79
//JLabel label = new JLabel(icon);
80
//JOptionPane.showMessageDialog(null, label);
81
82
if (icon == null) {
83
throw new RuntimeException("icon is null!!!");
84
}
85
86
if (implComplete && icon.getIconWidth() != size) {
87
throw new RuntimeException("Wrong icon size " +
88
icon.getIconWidth() + " when requested " + size);
89
}
90
91
if (icon.getImage() instanceof MultiResolutionImage) {
92
MultiResolutionImage mri = (MultiResolutionImage) icon.getImage();
93
if (mri.getResolutionVariant(size, size) == null) {
94
throw new RuntimeException("There is no suitable variant for the size "
95
+ size + " in the multi resolution icon");
96
}
97
} else {
98
if (implComplete) {
99
throw new RuntimeException("icon is supposed to be multi-resolution but it is not");
100
}
101
}
102
}
103
}
104
}
105
106