提交 6bf6bca4 编写于 作者: R rupashka

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
上级 64031015
......@@ -93,11 +93,18 @@ public class WindowsPlacesBar extends JToolBar
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]);
}
......
......@@ -910,18 +910,20 @@ final class Win32ShellFolder2 extends ShellFolder {
/**
* 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;
}
......
......@@ -313,13 +313,12 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
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) {
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册