changeset 231:0447f9c7aed7

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
author rupashka
date Tue, 29 Apr 2008 13:49:13 +0400
parents 97240b4b5074
children 5b1734431fa5
files src/share/classes/sun/swing/WindowsPlacesBar.java src/windows/classes/sun/awt/shell/Win32ShellFolder2.java src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java
diffstat 3 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/swing/WindowsPlacesBar.java	Mon Apr 28 17:17:45 2008 +0400
+++ b/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/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java	Mon Apr 28 17:17:45 2008 +0400
+++ b/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/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java	Mon Apr 28 17:17:45 2008 +0400
+++ b/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) {
             }