6210674: FileChooser fails to load custom harddrive icon and gets NullPointerException
WindowsPlacesBar should use default icon for folders that doesn't have own icon Reviewed-by: loneid
This commit is contained in:
parent
9d90ce5781
commit
c091ee49da
@ -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) {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user