< prev index next >
src/windows/classes/sun/awt/shell/Win32ShellFolder2.java
Print this page
@@ -926,11 +926,11 @@
boolean useVGAColors);
// Note: useVGAColors is ignored on XP and later
// Return the bits from an HICON. This has a side effect of setting
// the imageHash variable for efficient caching / comparing.
- private static native int[] getIconBits(long hIcon, int iconSize);
+ private static native int[] getIconBits(long hIcon);
// Dispose the HICON
private static native void disposeIcon(long hIcon);
static native int[] getStandardViewButton0(int iconIndex);
@@ -941,17 +941,18 @@
}
return pIShellIcon;
}
- private static Image makeIcon(long hIcon, boolean getLargeIcon) {
+ private static Image makeIcon(long hIcon) {
if (hIcon != 0L && hIcon != -1L) {
// Get the bits. This has the side effect of setting the imageHash value for this object.
- int size = getLargeIcon ? 32 : 16;
- int[] iconBits = getIconBits(hIcon, size);
+ final int[] iconBits = getIconBits(hIcon);
+ // icons are always square
+ final int size = (int)Math.sqrt(iconBits.length);
if (iconBits != null) {
- BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
+ final BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
img.setRGB(0, 0, size, size, iconBits, 0, size);
return img;
}
}
return null;
@@ -984,11 +985,11 @@
imageCache = getLargeIcon ? largeSystemImages : smallSystemImages;
}
newIcon = (Image) imageCache.get(Integer.valueOf(index));
if (newIcon == null) {
long hIcon = getIcon(getAbsolutePath(), getLargeIcon);
- newIcon = makeIcon(hIcon, getLargeIcon);
+ newIcon = makeIcon(hIcon);
disposeIcon(hIcon);
if (newIcon != null) {
imageCache.put(Integer.valueOf(index), newIcon);
}
}
@@ -997,11 +998,11 @@
if (newIcon == null) {
// These are only cached per object
long hIcon = extractIcon(getParentIShellFolder(),
getRelativePIDL(), getLargeIcon);
- newIcon = makeIcon(hIcon, getLargeIcon);
+ newIcon = makeIcon(hIcon);
disposeIcon(hIcon);
}
if (newIcon == null) {
newIcon = Win32ShellFolder2.super.getIcon(getLargeIcon);
@@ -1021,11 +1022,11 @@
/**
* Gets an icon from the Windows system icon list as an <code>Image</code>
*/
static Image getSystemIcon(SystemIcon iconType) {
long hIcon = getSystemIcon(iconType.getIconID());
- Image icon = makeIcon(hIcon, true);
+ Image icon = makeIcon(hIcon);
disposeIcon(hIcon);
return icon;
}
/**
@@ -1042,11 +1043,11 @@
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);
disposeIcon(hIcon);
return icon;
}
return null;
}
< prev index next >