Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/javax/swing/JFileChooser/FileSystemView/SystemIconTest.java
66646 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
Icon i = fsv.getSystemIcon(file, size, size);
77
78
if (i == null) {
79
throw new RuntimeException(file.getAbsolutePath() + " icon is null");
80
}
81
82
if (!(i instanceof ImageIcon)) {
83
// Default UI resource icon returned - it is not covered
84
// by new implementation so we can not test it
85
continue;
86
}
87
88
ImageIcon icon = (ImageIcon) i;
89
//Enable below to see the icon
90
//JLabel label = new JLabel(icon);
91
//JOptionPane.showMessageDialog(null, label);
92
93
if (implComplete && icon.getIconWidth() != size) {
94
throw new RuntimeException("Wrong icon size " +
95
icon.getIconWidth() + " when requested " + size +
96
" for file " + file.getAbsolutePath());
97
}
98
99
if (icon.getImage() instanceof MultiResolutionImage) {
100
MultiResolutionImage mri = (MultiResolutionImage) icon.getImage();
101
if (mri.getResolutionVariant(size, size) == null) {
102
throw new RuntimeException("There is no suitable variant for the size "
103
+ size + " in the multi resolution icon " + file.getAbsolutePath());
104
}
105
} else {
106
if (implComplete) {
107
throw new RuntimeException("icon is supposed to be" +
108
" multi-resolution but it is not for " + file.getAbsolutePath());
109
}
110
}
111
}
112
}
113
}
114
115