6210674: FileChooser fails to load custom harddrive icon and gets NullPointerException
Summary: WindowsPlacesBar should use default icon for folders that doesn't have own icon
Reviewed-by: loneid
--- a/jdk/src/share/classes/sun/swing/WindowsPlacesBar.java Mon Apr 28 17:17:45 2008 +0400
+++ b/jdk/src/share/classes/sun/swing/WindowsPlacesBar.java Tue Apr 29 13:49:13 2008 +0400
@@ -93,11 +93,18 @@
if (index >= 0 && index < folderName.length() - 1) {
folderName = folderName.substring(index + 1);
}
- Icon icon = null;
+ Icon icon;
if (files[i] instanceof ShellFolder) {
// We want a large icon, fsv only gives us a small.
ShellFolder sf = (ShellFolder)files[i];
- icon = new ImageIcon(sf.getIcon(true), sf.getFolderType());
+ Image image = sf.getIcon(true);
+
+ if (image == null) {
+ // Get default image
+ image = (Image) ShellFolder.get("shell32LargeIcon 1");
+ }
+
+ icon = image == null ? null : new ImageIcon(image, sf.getFolderType());
} else {
icon = fsv.getSystemIcon(files[i]);
}
--- a/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java Mon Apr 28 17:17:45 2008 +0400
+++ b/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java Tue Apr 29 13:49:13 2008 +0400
@@ -910,18 +910,20 @@
/**
* Gets an icon from the Windows system icon list as an <code>Image</code>
*/
- static Image getShell32Icon(int iconID) {
+ static Image getShell32Icon(int iconID, boolean getLargeIcon) {
boolean useVGAColors = true; // Will be ignored on XP and later
+ int size = getLargeIcon ? 32 : 16;
+
Toolkit toolkit = Toolkit.getDefaultToolkit();
String shellIconBPP = (String)toolkit.getDesktopProperty("win.icon.shellIconBPP");
if (shellIconBPP != null) {
useVGAColors = shellIconBPP.equals("4");
}
- long hIcon = getIconResource("shell32.dll", iconID, 16, 16, useVGAColors);
+ long hIcon = getIconResource("shell32.dll", iconID, size, size, useVGAColors);
if (hIcon != 0) {
- Image icon = makeIcon(hIcon, false);
+ Image icon = makeIcon(hIcon, getLargeIcon);
disposeIcon(hIcon);
return icon;
}
--- a/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java Mon Apr 28 17:17:45 2008 +0400
+++ b/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java Tue Apr 29 13:49:13 2008 +0400
@@ -313,13 +313,12 @@
return null;
}
return Win32ShellFolder2.getSystemIcon(iconType);
- } else if (key.startsWith("shell32Icon ")) {
- int i;
- String name = key.substring(key.indexOf(" ")+1);
+ } else if (key.startsWith("shell32Icon ") || key.startsWith("shell32LargeIcon ")) {
+ String name = key.substring(key.indexOf(" ") + 1);
try {
- i = Integer.parseInt(name);
+ int i = Integer.parseInt(name);
if (i >= 0) {
- return Win32ShellFolder2.getShell32Icon(i);
+ return Win32ShellFolder2.getShell32Icon(i, key.startsWith("shell32LargeIcon "));
}
} catch (NumberFormatException ex) {
}