< prev index next >

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

Print this page




 911 
 912     // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
 913     private static native int getIconIndex(long parentIShellIcon, long relativePIDL);
 914 
 915     // Return the icon of a file system shell folder in the form of an HICON
 916     private static native long getIcon(String absolutePath, boolean getLargeIcon);
 917 
 918     // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
 919     private static native long extractIcon(long parentIShellFolder, long relativePIDL,
 920                                            boolean getLargeIcon);
 921 
 922     // Returns an icon from the Windows system icon list in the form of an HICON
 923     private static native long getSystemIcon(int iconID);
 924     private static native long getIconResource(String libName, int iconID,
 925                                                int cxDesired, int cyDesired,
 926                                                boolean useVGAColors);
 927                                                // Note: useVGAColors is ignored on XP and later
 928 
 929     // Return the bits from an HICON.  This has a side effect of setting
 930     // the imageHash variable for efficient caching / comparing.
 931     private static native int[] getIconBits(long hIcon, int iconSize);
 932     // Dispose the HICON
 933     private static native void disposeIcon(long hIcon);
 934 
 935     static native int[] getStandardViewButton0(int iconIndex);
 936 
 937     // Should be called from the COM thread
 938     private long getIShellIcon() {
 939         if (pIShellIcon == -1L) {
 940             pIShellIcon = getIShellIcon(getIShellFolder());
 941         }
 942 
 943         return pIShellIcon;
 944     }
 945 
 946     private static Image makeIcon(long hIcon, boolean getLargeIcon) {
 947         if (hIcon != 0L && hIcon != -1L) {
 948             // Get the bits.  This has the side effect of setting the imageHash value for this object.
 949             int size = getLargeIcon ? 32 : 16;
 950             int[] iconBits = getIconBits(hIcon, size);

 951             if (iconBits != null) {
 952                 BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
 953                 img.setRGB(0, 0, size, size, iconBits, 0, size);
 954                 return img;
 955             }
 956         }
 957         return null;
 958     }
 959 
 960 
 961     /**
 962      * @return The icon image used to display this shell folder
 963      */
 964     public Image getIcon(final boolean getLargeIcon) {
 965         Image icon = getLargeIcon ? largeIcon : smallIcon;
 966         if (icon == null) {
 967             icon =
 968                 invoke(new Callable<Image>() {
 969                     public Image call() {
 970                         Image newIcon = null;
 971                         if (isFileSystem()) {
 972                             long parentIShellIcon = (parent != null)
 973                                 ? ((Win32ShellFolder2) parent).getIShellIcon()
 974                                 : 0L;
 975                             long relativePIDL = getRelativePIDL();
 976 
 977                             // These are cached per type (using the index in the system image list)
 978                             int index = getIconIndex(parentIShellIcon, relativePIDL);
 979                             if (index > 0) {
 980                                 Map imageCache;
 981                                 if (isLink()) {
 982                                     imageCache = getLargeIcon ? largeLinkedSystemImages : smallLinkedSystemImages;
 983                                 } else {
 984                                     imageCache = getLargeIcon ? largeSystemImages : smallSystemImages;
 985                                 }
 986                                 newIcon = (Image) imageCache.get(Integer.valueOf(index));
 987                                 if (newIcon == null) {
 988                                     long hIcon = getIcon(getAbsolutePath(), getLargeIcon);
 989                                     newIcon = makeIcon(hIcon, getLargeIcon);
 990                                     disposeIcon(hIcon);
 991                                     if (newIcon != null) {
 992                                         imageCache.put(Integer.valueOf(index), newIcon);
 993                                     }
 994                                 }
 995                             }
 996                         }
 997 
 998                         if (newIcon == null) {
 999                             // These are only cached per object
1000                             long hIcon = extractIcon(getParentIShellFolder(),
1001                                 getRelativePIDL(), getLargeIcon);
1002                             newIcon = makeIcon(hIcon, getLargeIcon);
1003                             disposeIcon(hIcon);
1004                         }
1005 
1006                         if (newIcon == null) {
1007                             newIcon = Win32ShellFolder2.super.getIcon(getLargeIcon);
1008                         }
1009                         return newIcon;
1010                     }
1011                 });
1012             if (getLargeIcon) {
1013                 largeIcon = icon;
1014             } else {
1015                 smallIcon = icon;
1016             }
1017         }
1018         return icon;
1019     }
1020 
1021     /**
1022      * Gets an icon from the Windows system icon list as an <code>Image</code>
1023      */
1024     static Image getSystemIcon(SystemIcon iconType) {
1025         long hIcon = getSystemIcon(iconType.getIconID());
1026         Image icon = makeIcon(hIcon, true);
1027         disposeIcon(hIcon);
1028         return icon;
1029     }
1030 
1031     /**
1032      * Gets an icon from the Windows system icon list as an <code>Image</code>
1033      */
1034     static Image getShell32Icon(int iconID, boolean getLargeIcon) {
1035         boolean useVGAColors = true; // Will be ignored on XP and later
1036 
1037         int size = getLargeIcon ? 32 : 16;
1038 
1039         Toolkit toolkit = Toolkit.getDefaultToolkit();
1040         String shellIconBPP = (String)toolkit.getDesktopProperty("win.icon.shellIconBPP");
1041         if (shellIconBPP != null) {
1042             useVGAColors = shellIconBPP.equals("4");
1043         }
1044 
1045         long hIcon = getIconResource("shell32.dll", iconID, size, size, useVGAColors);
1046         if (hIcon != 0) {
1047             Image icon = makeIcon(hIcon, getLargeIcon);
1048             disposeIcon(hIcon);
1049             return icon;
1050         }
1051         return null;
1052     }
1053 
1054     /**
1055      * Returns the canonical form of this abstract pathname.  Equivalent to
1056      * <code>new&nbsp;Win32ShellFolder2(getParentFile(), this.{@link java.io.File#getCanonicalPath}())</code>.
1057      *
1058      * @see java.io.File#getCanonicalFile
1059      */
1060     public File getCanonicalFile() throws IOException {
1061         return this;
1062     }
1063 
1064     /*
1065      * Indicates whether this is a special folder (includes My Documents)
1066      */
1067     public boolean isSpecial() {




 911 
 912     // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
 913     private static native int getIconIndex(long parentIShellIcon, long relativePIDL);
 914 
 915     // Return the icon of a file system shell folder in the form of an HICON
 916     private static native long getIcon(String absolutePath, boolean getLargeIcon);
 917 
 918     // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
 919     private static native long extractIcon(long parentIShellFolder, long relativePIDL,
 920                                            boolean getLargeIcon);
 921 
 922     // Returns an icon from the Windows system icon list in the form of an HICON
 923     private static native long getSystemIcon(int iconID);
 924     private static native long getIconResource(String libName, int iconID,
 925                                                int cxDesired, int cyDesired,
 926                                                boolean useVGAColors);
 927                                                // Note: useVGAColors is ignored on XP and later
 928 
 929     // Return the bits from an HICON.  This has a side effect of setting
 930     // the imageHash variable for efficient caching / comparing.
 931     private static native int[] getIconBits(long hIcon);
 932     // Dispose the HICON
 933     private static native void disposeIcon(long hIcon);
 934 
 935     static native int[] getStandardViewButton0(int iconIndex);
 936 
 937     // Should be called from the COM thread
 938     private long getIShellIcon() {
 939         if (pIShellIcon == -1L) {
 940             pIShellIcon = getIShellIcon(getIShellFolder());
 941         }
 942 
 943         return pIShellIcon;
 944     }
 945 
 946     private static Image makeIcon(long hIcon) {
 947         if (hIcon != 0L && hIcon != -1L) {
 948             // Get the bits.  This has the side effect of setting the imageHash value for this object.
 949             final int[] iconBits = getIconBits(hIcon);
 950             // icons are always square
 951             final int size = (int)Math.sqrt(iconBits.length);
 952             if (iconBits != null) {
 953                 final BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
 954                 img.setRGB(0, 0, size, size, iconBits, 0, size);
 955                 return img;
 956             }
 957         }
 958         return null;
 959     }
 960 
 961 
 962     /**
 963      * @return The icon image used to display this shell folder
 964      */
 965     public Image getIcon(final boolean getLargeIcon) {
 966         Image icon = getLargeIcon ? largeIcon : smallIcon;
 967         if (icon == null) {
 968             icon =
 969                 invoke(new Callable<Image>() {
 970                     public Image call() {
 971                         Image newIcon = null;
 972                         if (isFileSystem()) {
 973                             long parentIShellIcon = (parent != null)
 974                                 ? ((Win32ShellFolder2) parent).getIShellIcon()
 975                                 : 0L;
 976                             long relativePIDL = getRelativePIDL();
 977 
 978                             // These are cached per type (using the index in the system image list)
 979                             int index = getIconIndex(parentIShellIcon, relativePIDL);
 980                             if (index > 0) {
 981                                 Map imageCache;
 982                                 if (isLink()) {
 983                                     imageCache = getLargeIcon ? largeLinkedSystemImages : smallLinkedSystemImages;
 984                                 } else {
 985                                     imageCache = getLargeIcon ? largeSystemImages : smallSystemImages;
 986                                 }
 987                                 newIcon = (Image) imageCache.get(Integer.valueOf(index));
 988                                 if (newIcon == null) {
 989                                     long hIcon = getIcon(getAbsolutePath(), getLargeIcon);
 990                                     newIcon = makeIcon(hIcon);
 991                                     disposeIcon(hIcon);
 992                                     if (newIcon != null) {
 993                                         imageCache.put(Integer.valueOf(index), newIcon);
 994                                     }
 995                                 }
 996                             }
 997                         }
 998 
 999                         if (newIcon == null) {
1000                             // These are only cached per object
1001                             long hIcon = extractIcon(getParentIShellFolder(),
1002                                 getRelativePIDL(), getLargeIcon);
1003                             newIcon = makeIcon(hIcon);
1004                             disposeIcon(hIcon);
1005                         }
1006 
1007                         if (newIcon == null) {
1008                             newIcon = Win32ShellFolder2.super.getIcon(getLargeIcon);
1009                         }
1010                         return newIcon;
1011                     }
1012                 });
1013             if (getLargeIcon) {
1014                 largeIcon = icon;
1015             } else {
1016                 smallIcon = icon;
1017             }
1018         }
1019         return icon;
1020     }
1021 
1022     /**
1023      * Gets an icon from the Windows system icon list as an <code>Image</code>
1024      */
1025     static Image getSystemIcon(SystemIcon iconType) {
1026         long hIcon = getSystemIcon(iconType.getIconID());
1027         Image icon = makeIcon(hIcon);
1028         disposeIcon(hIcon);
1029         return icon;
1030     }
1031 
1032     /**
1033      * Gets an icon from the Windows system icon list as an <code>Image</code>
1034      */
1035     static Image getShell32Icon(int iconID, boolean getLargeIcon) {
1036         boolean useVGAColors = true; // Will be ignored on XP and later
1037 
1038         int size = getLargeIcon ? 32 : 16;
1039 
1040         Toolkit toolkit = Toolkit.getDefaultToolkit();
1041         String shellIconBPP = (String)toolkit.getDesktopProperty("win.icon.shellIconBPP");
1042         if (shellIconBPP != null) {
1043             useVGAColors = shellIconBPP.equals("4");
1044         }
1045 
1046         long hIcon = getIconResource("shell32.dll", iconID, size, size, useVGAColors);
1047         if (hIcon != 0) {
1048             Image icon = makeIcon(hIcon);
1049             disposeIcon(hIcon);
1050             return icon;
1051         }
1052         return null;
1053     }
1054 
1055     /**
1056      * Returns the canonical form of this abstract pathname.  Equivalent to
1057      * <code>new&nbsp;Win32ShellFolder2(getParentFile(), this.{@link java.io.File#getCanonicalPath}())</code>.
1058      *
1059      * @see java.io.File#getCanonicalFile
1060      */
1061     public File getCanonicalFile() throws IOException {
1062         return this;
1063     }
1064 
1065     /*
1066      * Indicates whether this is a special folder (includes My Documents)
1067      */
1068     public boolean isSpecial() {


< prev index next >