提交 0c5d9266 编写于 作者: 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
上级 097330a5
...@@ -93,11 +93,18 @@ public class WindowsPlacesBar extends JToolBar ...@@ -93,11 +93,18 @@ public class WindowsPlacesBar extends JToolBar
if (index >= 0 && index < folderName.length() - 1) { if (index >= 0 && index < folderName.length() - 1) {
folderName = folderName.substring(index + 1); folderName = folderName.substring(index + 1);
} }
Icon icon = null; Icon icon;
if (files[i] instanceof ShellFolder) { if (files[i] instanceof ShellFolder) {
// We want a large icon, fsv only gives us a small. // We want a large icon, fsv only gives us a small.
ShellFolder sf = (ShellFolder)files[i]; 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 { } else {
icon = fsv.getSystemIcon(files[i]); icon = fsv.getSystemIcon(files[i]);
} }
......
...@@ -910,18 +910,20 @@ final class Win32ShellFolder2 extends ShellFolder { ...@@ -910,18 +910,20 @@ final class Win32ShellFolder2 extends ShellFolder {
/** /**
* Gets an icon from the Windows system icon list as an <code>Image</code> * 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 boolean useVGAColors = true; // Will be ignored on XP and later
int size = getLargeIcon ? 32 : 16;
Toolkit toolkit = Toolkit.getDefaultToolkit(); Toolkit toolkit = Toolkit.getDefaultToolkit();
String shellIconBPP = (String)toolkit.getDesktopProperty("win.icon.shellIconBPP"); String shellIconBPP = (String)toolkit.getDesktopProperty("win.icon.shellIconBPP");
if (shellIconBPP != null) { if (shellIconBPP != null) {
useVGAColors = shellIconBPP.equals("4"); 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) { if (hIcon != 0) {
Image icon = makeIcon(hIcon, false); Image icon = makeIcon(hIcon, getLargeIcon);
disposeIcon(hIcon); disposeIcon(hIcon);
return icon; return icon;
} }
......
...@@ -313,13 +313,12 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -313,13 +313,12 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return null; return null;
} }
return Win32ShellFolder2.getSystemIcon(iconType); return Win32ShellFolder2.getSystemIcon(iconType);
} else if (key.startsWith("shell32Icon ")) { } else if (key.startsWith("shell32Icon ") || key.startsWith("shell32LargeIcon ")) {
int i; String name = key.substring(key.indexOf(" ") + 1);
String name = key.substring(key.indexOf(" ")+1);
try { try {
i = Integer.parseInt(name); int i = Integer.parseInt(name);
if (i >= 0) { if (i >= 0) {
return Win32ShellFolder2.getShell32Icon(i); return Win32ShellFolder2.getShell32Icon(i, key.startsWith("shell32LargeIcon "));
} }
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册