1 /*
2 * Copyright (c) 2003, 2015, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
109 private static final int VIEW_NEWFOLDER = 11;
110
111 private static final Image[] STANDARD_VIEW_BUTTONS = new Image[12];
112
113 private static Image getStandardViewButton(int iconIndex) {
114 Image result = STANDARD_VIEW_BUTTONS[iconIndex];
115
116 if (result != null) {
117 return result;
118 }
119
120 final int[] iconBits = Win32ShellFolder2
121 .getStandardViewButton0(iconIndex, true);
122 if (iconBits != null) {
123 // icons are always square
124 final int size = (int) Math.sqrt(iconBits.length);
125 final BufferedImage img =
126 new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
127 img.setRGB(0, 0, size, size, iconBits, 0, size);
128
129 STANDARD_VIEW_BUTTONS[iconIndex] = (size == 16)
130 ? img
131 : new MultiResolutionIconImage(16, img);
132 }
133
134 return STANDARD_VIEW_BUTTONS[iconIndex];
135 }
136
137 // Special folders
138 private static Win32ShellFolder2 desktop;
139 private static Win32ShellFolder2 drives;
140 private static Win32ShellFolder2 recent;
141 private static Win32ShellFolder2 network;
142 private static Win32ShellFolder2 personal;
143
144 static Win32ShellFolder2 getDesktop() {
145 if (desktop == null) {
146 try {
147 desktop = new Win32ShellFolder2(DESKTOP);
148 } catch (SecurityException e) {
149 // Ignore error
150 } catch (IOException e) {
151 // Ignore error
362 return getStandardViewButton(iconIndex);
363 } else if (key.startsWith("optionPaneIcon ")) {
364 Win32ShellFolder2.SystemIcon iconType;
365 if (key == "optionPaneIcon Error") {
366 iconType = Win32ShellFolder2.SystemIcon.IDI_ERROR;
367 } else if (key == "optionPaneIcon Information") {
368 iconType = Win32ShellFolder2.SystemIcon.IDI_INFORMATION;
369 } else if (key == "optionPaneIcon Question") {
370 iconType = Win32ShellFolder2.SystemIcon.IDI_QUESTION;
371 } else if (key == "optionPaneIcon Warning") {
372 iconType = Win32ShellFolder2.SystemIcon.IDI_EXCLAMATION;
373 } else {
374 return null;
375 }
376 return Win32ShellFolder2.getSystemIcon(iconType);
377 } else if (key.startsWith("shell32Icon ") || key.startsWith("shell32LargeIcon ")) {
378 String name = key.substring(key.indexOf(" ") + 1);
379 try {
380 int i = Integer.parseInt(name);
381 if (i >= 0) {
382 return Win32ShellFolder2.getShell32Icon(i, key.startsWith("shell32LargeIcon "));
383 }
384 } catch (NumberFormatException ex) {
385 }
386 }
387 return null;
388 }
389
390 private File checkFile(File file) {
391 SecurityManager sm = System.getSecurityManager();
392 return (sm == null || file == null) ? file : checkFile(file, sm);
393 }
394
395 private File checkFile(File file, SecurityManager sm) {
396 try {
397 sm.checkRead(file.getPath());
398 return file;
399 } catch (SecurityException se) {
400 return null;
401 }
402 }
|
1 /*
2 * Copyright (c) 2003, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
109 private static final int VIEW_NEWFOLDER = 11;
110
111 private static final Image[] STANDARD_VIEW_BUTTONS = new Image[12];
112
113 private static Image getStandardViewButton(int iconIndex) {
114 Image result = STANDARD_VIEW_BUTTONS[iconIndex];
115
116 if (result != null) {
117 return result;
118 }
119
120 final int[] iconBits = Win32ShellFolder2
121 .getStandardViewButton0(iconIndex, true);
122 if (iconBits != null) {
123 // icons are always square
124 final int size = (int) Math.sqrt(iconBits.length);
125 final BufferedImage img =
126 new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
127 img.setRGB(0, 0, size, size, iconBits, 0, size);
128
129 STANDARD_VIEW_BUTTONS[iconIndex] = (size == SMALL_ICON_SIZE)
130 ? img
131 : new MultiResolutionIconImage(SMALL_ICON_SIZE, img);
132 }
133
134 return STANDARD_VIEW_BUTTONS[iconIndex];
135 }
136
137 // Special folders
138 private static Win32ShellFolder2 desktop;
139 private static Win32ShellFolder2 drives;
140 private static Win32ShellFolder2 recent;
141 private static Win32ShellFolder2 network;
142 private static Win32ShellFolder2 personal;
143
144 static Win32ShellFolder2 getDesktop() {
145 if (desktop == null) {
146 try {
147 desktop = new Win32ShellFolder2(DESKTOP);
148 } catch (SecurityException e) {
149 // Ignore error
150 } catch (IOException e) {
151 // Ignore error
362 return getStandardViewButton(iconIndex);
363 } else if (key.startsWith("optionPaneIcon ")) {
364 Win32ShellFolder2.SystemIcon iconType;
365 if (key == "optionPaneIcon Error") {
366 iconType = Win32ShellFolder2.SystemIcon.IDI_ERROR;
367 } else if (key == "optionPaneIcon Information") {
368 iconType = Win32ShellFolder2.SystemIcon.IDI_INFORMATION;
369 } else if (key == "optionPaneIcon Question") {
370 iconType = Win32ShellFolder2.SystemIcon.IDI_QUESTION;
371 } else if (key == "optionPaneIcon Warning") {
372 iconType = Win32ShellFolder2.SystemIcon.IDI_EXCLAMATION;
373 } else {
374 return null;
375 }
376 return Win32ShellFolder2.getSystemIcon(iconType);
377 } else if (key.startsWith("shell32Icon ") || key.startsWith("shell32LargeIcon ")) {
378 String name = key.substring(key.indexOf(" ") + 1);
379 try {
380 int i = Integer.parseInt(name);
381 if (i >= 0) {
382 return Win32ShellFolder2.getShell32Icon(i,
383 key.startsWith("shell32LargeIcon ")?LARGE_ICON_SIZE : SMALL_ICON_SIZE);
384 }
385 } catch (NumberFormatException ex) {
386 }
387 }
388 return null;
389 }
390
391 private File checkFile(File file) {
392 SecurityManager sm = System.getSecurityManager();
393 return (sm == null || file == null) ? file : checkFile(file, sm);
394 }
395
396 private File checkFile(File file, SecurityManager sm) {
397 try {
398 sm.checkRead(file.getPath());
399 return file;
400 } catch (SecurityException se) {
401 return null;
402 }
403 }
|