< prev index next >

src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolder2.java

Print this page

        

@@ -975,11 +975,11 @@
     // Return the icon of a file system shell folder in the form of an HICON
     private static native long getIcon(String absolutePath, boolean getLargeIcon);
 
     // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
     private static native long extractIcon(long parentIShellFolder, long relativePIDL,
-                                           boolean getLargeIcon, boolean getDefaultIcon);
+                                           int size, boolean getDefaultIcon);
 
     // Returns an icon from the Windows system icon list in the form of an HICON
     private static native long getSystemIcon(int iconID);
     private static native long getIconResource(String libName, int iconID,
                                                int cxDesired, int cyDesired,

@@ -1002,34 +1002,62 @@
         }
 
         return pIShellIcon;
     }
 
-    private static Image makeIcon(long hIcon, boolean getLargeIcon) {
+    private static Image makeIcon(long hIcon, int bsize) {
         if (hIcon != 0L && hIcon != -1L) {
             // Get the bits.  This has the side effect of setting the imageHash value for this object.
             final int[] iconBits = getIconBits(hIcon);
             if (iconBits != null) {
                 // icons are always square
                 final int size = (int) Math.sqrt(iconBits.length);
-                final int baseSize = getLargeIcon ? 32 : 16;
                 final BufferedImage img =
                         new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
                 img.setRGB(0, 0, size, size, iconBits, 0, size);
-                return size == baseSize
+                return size == bsize
                         ? img
-                        : new MultiResolutionIconImage(baseSize, img);
+                        : new MultiResolutionIconImage(bsize, img);
             }
         }
         return null;
     }
 
+    public Image getIcon(int size) {
+        return invoke(() -> {
+            Image newIcon = null;
+            if (isLink()) {
+                Win32ShellFolder2 folder = getLinkLocation(false);
+                if (folder != null && folder.isLibrary()) {
+                    return folder.getIcon(size);
+                }
+            }
+            long hIcon = extractIcon(getParentIShellFolder(),
+                    getRelativePIDL(), size, false);
+            // E_PENDING: loading can take time so get the default
+            if(hIcon <= 0) {
+                hIcon = extractIcon(getParentIShellFolder(),
+                        getRelativePIDL(), size, true);
+                if(hIcon <= 0) {
+                    if (isDirectory()) {
+                        return getShell32Icon(4, size);
+                    } else {
+                        return getShell32Icon(1, size);
+                    }
+                }
+            }
+            newIcon = makeIcon(hIcon, size);
+            disposeIcon(hIcon);
+            return newIcon;
+        });
+    }
 
     /**
      * @return The icon image used to display this shell folder
      */
     public Image getIcon(final boolean getLargeIcon) {
+        int size = getLargeIcon ? 32 : 16;
         Image icon = getLargeIcon ? largeIcon : smallIcon;
         if (icon == null) {
             icon =
                 invoke(new Callable<Image>() {
                     public Image call() {

@@ -1056,11 +1084,11 @@
                                     imageCache = getLargeIcon ? largeSystemImages : smallSystemImages;
                                 }
                                 newIcon = imageCache.get(Integer.valueOf(index));
                                 if (newIcon == null) {
                                     long hIcon = getIcon(getAbsolutePath(), getLargeIcon);
-                                    newIcon = makeIcon(hIcon, getLargeIcon);
+                                    newIcon = makeIcon(hIcon, size);
                                     disposeIcon(hIcon);
                                     if (newIcon != null) {
                                         imageCache.put(Integer.valueOf(index), newIcon);
                                     }
                                 }

@@ -1068,69 +1096,59 @@
                         }
 
                         if (newIcon == null) {
                             // These are only cached per object
                             long hIcon = extractIcon(getParentIShellFolder(),
-                                    getRelativePIDL(), getLargeIcon, false);
+                                    getRelativePIDL(), size, false);
                             // E_PENDING: loading can take time so get the default
                             if(hIcon <= 0) {
                                 hIcon = extractIcon(getParentIShellFolder(),
-                                         getRelativePIDL(), getLargeIcon, true);
+                                         getRelativePIDL(), size, true);
                                 if(hIcon <= 0) {
                                     if (isDirectory()) {
-                                        return getShell32Icon(4, getLargeIcon);
+                                        return getShell32Icon(4, size);
                                     } else {
-                                        return getShell32Icon(1, getLargeIcon);
+                                        return getShell32Icon(1, size);
                                     }
                                 }
                             }
-                            newIcon = makeIcon(hIcon, getLargeIcon);
+                            newIcon = makeIcon(hIcon, size);
                             disposeIcon(hIcon);
                         }
 
-                        if (newIcon == null) {
-                            newIcon = Win32ShellFolder2.super.getIcon(getLargeIcon);
-                        }
                         return newIcon;
                     }
                 });
-            if (getLargeIcon) {
-                largeIcon = icon;
-            } else {
-                smallIcon = icon;
-            }
         }
         return icon;
     }
 
     /**
      * Gets an icon from the Windows system icon list as an {@code Image}
      */
     static Image getSystemIcon(SystemIcon iconType) {
         long hIcon = getSystemIcon(iconType.getIconID());
-        Image icon = makeIcon(hIcon, true);
+        Image icon = makeIcon(hIcon, 32);
         disposeIcon(hIcon);
         return icon;
     }
 
     /**
      * Gets an icon from the Windows system icon list as an {@code Image}
      */
-    static Image getShell32Icon(int iconID, boolean getLargeIcon) {
+    static Image getShell32Icon(int iconID, int size) {
         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, size, size, useVGAColors);
         if (hIcon != 0) {
-            Image icon = makeIcon(hIcon, getLargeIcon);
+            Image icon = makeIcon(hIcon, size);
             disposeIcon(hIcon);
             return icon;
         }
         return null;
     }
< prev index next >