< prev index next >

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

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 72,81 **** --- 72,87 ---- * @author Kenneth Russell * @since 1.4 */ @SuppressWarnings("serial") // JDK-implementation class final class Win32ShellFolder2 extends ShellFolder { + static final int SMALL_ICON_SIZE = 16; + static final int LARGE_ICON_SIZE = 32; + + static final int FILE_ICON_ID = 1; + static final int FOLDER_ICON_ID = 4; + private static native void initIDs(); static { initIDs(); }
*** 975,985 **** // 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); // 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, --- 981,991 ---- // 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, ! 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,1025 **** } return pIShellIcon; } ! private static Image makeIcon(long hIcon, boolean getLargeIcon) { 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 ? img ! : new MultiResolutionIconImage(baseSize, img); } } return null; } --- 1008,1030 ---- } return pIShellIcon; } ! private static Image makeIcon(long hIcon, int size) { 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 iconSize = (int) Math.sqrt(iconBits.length); final BufferedImage img = ! new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_ARGB); ! img.setRGB(0, 0, iconSize, iconSize, iconBits, 0, iconSize); ! return iconSize == size ? img ! : new MultiResolutionIconImage(size, img); } } return null; }
*** 1027,1036 **** --- 1032,1042 ---- /** * @return The icon image used to display this shell folder */ public Image getIcon(final boolean getLargeIcon) { Image icon = getLargeIcon ? largeIcon : smallIcon; + int size = getLargeIcon ? LARGE_ICON_SIZE : SMALL_ICON_SIZE; if (icon == null) { icon = invoke(new Callable<Image>() { public Image call() { Image newIcon = null;
*** 1056,1066 **** imageCache = getLargeIcon ? largeSystemImages : smallSystemImages; } newIcon = imageCache.get(Integer.valueOf(index)); if (newIcon == null) { long hIcon = getIcon(getAbsolutePath(), getLargeIcon); ! newIcon = makeIcon(hIcon, getLargeIcon); disposeIcon(hIcon); if (newIcon != null) { imageCache.put(Integer.valueOf(index), newIcon); } } --- 1062,1072 ---- imageCache = getLargeIcon ? largeSystemImages : smallSystemImages; } newIcon = imageCache.get(Integer.valueOf(index)); if (newIcon == null) { long hIcon = getIcon(getAbsolutePath(), getLargeIcon); ! newIcon = makeIcon(hIcon, size); disposeIcon(hIcon); if (newIcon != null) { imageCache.put(Integer.valueOf(index), newIcon); } }
*** 1068,1136 **** } if (newIcon == null) { // These are only cached per object long hIcon = extractIcon(getParentIShellFolder(), ! getRelativePIDL(), getLargeIcon, false); // E_PENDING: loading can take time so get the default if(hIcon <= 0) { hIcon = extractIcon(getParentIShellFolder(), ! getRelativePIDL(), getLargeIcon, true); if(hIcon <= 0) { if (isDirectory()) { ! return getShell32Icon(4, getLargeIcon); } else { ! return getShell32Icon(1, getLargeIcon); } } } ! newIcon = makeIcon(hIcon, getLargeIcon); 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); disposeIcon(hIcon); return icon; } /** * Gets an icon from the Windows system icon list as an {@code Image} */ ! 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, size, size, useVGAColors); if (hIcon != 0) { ! Image icon = makeIcon(hIcon, getLargeIcon); disposeIcon(hIcon); return icon; } return null; } --- 1074,1164 ---- } if (newIcon == null) { // These are only cached per object 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(FOLDER_ICON_ID, size); } else { ! return getShell32Icon(FILE_ICON_ID, size); } } } ! newIcon = makeIcon(hIcon, size); disposeIcon(hIcon); } if (newIcon == null) { newIcon = Win32ShellFolder2.super.getIcon(getLargeIcon); } return newIcon; } }); ! } ! return icon; ! } ! ! 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(FOLDER_ICON_ID, size); } else { ! return getShell32Icon(FILE_ICON_ID, size); } } ! } ! newIcon = makeIcon(hIcon, size); ! disposeIcon(hIcon); ! return newIcon; ! }); } /** * 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, LARGE_ICON_SIZE); disposeIcon(hIcon); return icon; } /** * Gets an icon from the Windows system icon list as an {@code Image} */ ! static Image getShell32Icon(int iconID, int size) { boolean useVGAColors = true; // Will be ignored on XP and later 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, size); disposeIcon(hIcon); return icon; } return null; }
< prev index next >