330 return new Win32ShellFolder2(parent, 0, pIDL, libPath, true);
331 }
332 }
333
334 // Initializes the desktop shell folder
335 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
336 private native void initDesktop();
337
338 // Initializes a special, non-file system shell folder
339 // from one of the above constants
340 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
341 private native void initSpecial(long desktopIShellFolder, int csidl);
342
343 /** Marks this folder as being the My Documents (Personal) folder */
344 public void setIsPersonal() {
345 isPersonal = true;
346 }
347
348 /**
349 * This method is implemented to make sure that no instances
350 * of <code>ShellFolder</code> are ever serialized. If <code>isFileSystem()</code> returns
351 * <code>true</code>, then the object is representable with an instance of
352 * <code>java.io.File</code> instead. If not, then the object depends
353 * on native PIDL state and should not be serialized.
354 *
355 * @return a <code>java.io.File</code> replacement object. If the folder
356 * is a not a normal directory, then returns the first non-removable
357 * drive (normally "C:\").
358 */
359 protected Object writeReplace() throws java.io.ObjectStreamException {
360 return invoke(new Callable<File>() {
361 public File call() {
362 if (isFileSystem()) {
363 return new File(getPath());
364 } else {
365 Win32ShellFolder2 drives = Win32ShellFolderManager2.getDrives();
366 if (drives != null) {
367 File[] driveRoots = drives.listFiles();
368 if (driveRoots != null) {
369 for (int i = 0; i < driveRoots.length; i++) {
370 if (driveRoots[i] instanceof Win32ShellFolder2) {
371 Win32ShellFolder2 sf = (Win32ShellFolder2) driveRoots[i];
372 if (sf.isFileSystem() && !sf.hasAttribute(ATTRIB_REMOVABLE)) {
373 return new File(sf.getPath());
374 }
375 }
698 private native long getEnumObjects(long pIShellFolder, boolean isDesktop,
699 boolean includeHiddenFiles);
700 // Returns the next sequential child as a relative PIDL
701 // from an IEnumIDList interface. The value returned must
702 // be released using releasePIDL().
703 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
704 private native long getNextChild(long pEnumObjects);
705 // Releases the IEnumIDList interface
706 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
707 private native void releaseEnumObjects(long pEnumObjects);
708
709 // Returns the IShellFolder of a child from a parent IShellFolder
710 // and a relative PIDL. The value returned must be released
711 // using releaseIShellFolder().
712 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
713 private static native long bindToObject(long parentIShellFolder, long pIDL);
714
715 /**
716 * @return An array of shell folders that are children of this shell folder
717 * object. The array will be empty if the folder is empty. Returns
718 * <code>null</code> if this shellfolder does not denote a directory.
719 */
720 public File[] listFiles(final boolean includeHiddenFiles) {
721 SecurityManager security = System.getSecurityManager();
722 if (security != null) {
723 security.checkRead(getPath());
724 }
725
726 try {
727 return invoke(new Callable<File[]>() {
728 public File[] call() throws InterruptedException {
729 if (!isDirectory()) {
730 return null;
731 }
732 // Links to directories are not directories and cannot be parents.
733 // This does not apply to folders in My Network Places (NetHood)
734 // because they are both links and real directories!
735 if (isLink() && !hasAttribute(ATTRIB_FOLDER)) {
736 return new File[0];
737 }
738
1071 newIcon = makeIcon(hIcon, getLargeIcon);
1072 disposeIcon(hIcon);
1073 }
1074
1075 if (newIcon == null) {
1076 newIcon = Win32ShellFolder2.super.getIcon(getLargeIcon);
1077 }
1078 return newIcon;
1079 }
1080 });
1081 if (getLargeIcon) {
1082 largeIcon = icon;
1083 } else {
1084 smallIcon = icon;
1085 }
1086 }
1087 return icon;
1088 }
1089
1090 /**
1091 * Gets an icon from the Windows system icon list as an <code>Image</code>
1092 */
1093 static Image getSystemIcon(SystemIcon iconType) {
1094 long hIcon = getSystemIcon(iconType.getIconID());
1095 Image icon = makeIcon(hIcon, true);
1096 disposeIcon(hIcon);
1097 return icon;
1098 }
1099
1100 /**
1101 * Gets an icon from the Windows system icon list as an <code>Image</code>
1102 */
1103 static Image getShell32Icon(int iconID, boolean getLargeIcon) {
1104 boolean useVGAColors = true; // Will be ignored on XP and later
1105
1106 int size = getLargeIcon ? 32 : 16;
1107
1108 Toolkit toolkit = Toolkit.getDefaultToolkit();
1109 String shellIconBPP = (String)toolkit.getDesktopProperty("win.icon.shellIconBPP");
1110 if (shellIconBPP != null) {
1111 useVGAColors = shellIconBPP.equals("4");
1112 }
1113
1114 long hIcon = getIconResource("shell32.dll", iconID, size, size, useVGAColors);
1115 if (hIcon != 0) {
1116 Image icon = makeIcon(hIcon, getLargeIcon);
1117 disposeIcon(hIcon);
1118 return icon;
1119 }
1120 return null;
1121 }
|
330 return new Win32ShellFolder2(parent, 0, pIDL, libPath, true);
331 }
332 }
333
334 // Initializes the desktop shell folder
335 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
336 private native void initDesktop();
337
338 // Initializes a special, non-file system shell folder
339 // from one of the above constants
340 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
341 private native void initSpecial(long desktopIShellFolder, int csidl);
342
343 /** Marks this folder as being the My Documents (Personal) folder */
344 public void setIsPersonal() {
345 isPersonal = true;
346 }
347
348 /**
349 * This method is implemented to make sure that no instances
350 * of {@code ShellFolder} are ever serialized. If {@code isFileSystem()} returns
351 * {@code true}, then the object is representable with an instance of
352 * {@code java.io.File} instead. If not, then the object depends
353 * on native PIDL state and should not be serialized.
354 *
355 * @return a {@code java.io.File} replacement object. If the folder
356 * is a not a normal directory, then returns the first non-removable
357 * drive (normally "C:\").
358 */
359 protected Object writeReplace() throws java.io.ObjectStreamException {
360 return invoke(new Callable<File>() {
361 public File call() {
362 if (isFileSystem()) {
363 return new File(getPath());
364 } else {
365 Win32ShellFolder2 drives = Win32ShellFolderManager2.getDrives();
366 if (drives != null) {
367 File[] driveRoots = drives.listFiles();
368 if (driveRoots != null) {
369 for (int i = 0; i < driveRoots.length; i++) {
370 if (driveRoots[i] instanceof Win32ShellFolder2) {
371 Win32ShellFolder2 sf = (Win32ShellFolder2) driveRoots[i];
372 if (sf.isFileSystem() && !sf.hasAttribute(ATTRIB_REMOVABLE)) {
373 return new File(sf.getPath());
374 }
375 }
698 private native long getEnumObjects(long pIShellFolder, boolean isDesktop,
699 boolean includeHiddenFiles);
700 // Returns the next sequential child as a relative PIDL
701 // from an IEnumIDList interface. The value returned must
702 // be released using releasePIDL().
703 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
704 private native long getNextChild(long pEnumObjects);
705 // Releases the IEnumIDList interface
706 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
707 private native void releaseEnumObjects(long pEnumObjects);
708
709 // Returns the IShellFolder of a child from a parent IShellFolder
710 // and a relative PIDL. The value returned must be released
711 // using releaseIShellFolder().
712 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
713 private static native long bindToObject(long parentIShellFolder, long pIDL);
714
715 /**
716 * @return An array of shell folders that are children of this shell folder
717 * object. The array will be empty if the folder is empty. Returns
718 * {@code null} if this shellfolder does not denote a directory.
719 */
720 public File[] listFiles(final boolean includeHiddenFiles) {
721 SecurityManager security = System.getSecurityManager();
722 if (security != null) {
723 security.checkRead(getPath());
724 }
725
726 try {
727 return invoke(new Callable<File[]>() {
728 public File[] call() throws InterruptedException {
729 if (!isDirectory()) {
730 return null;
731 }
732 // Links to directories are not directories and cannot be parents.
733 // This does not apply to folders in My Network Places (NetHood)
734 // because they are both links and real directories!
735 if (isLink() && !hasAttribute(ATTRIB_FOLDER)) {
736 return new File[0];
737 }
738
1071 newIcon = makeIcon(hIcon, getLargeIcon);
1072 disposeIcon(hIcon);
1073 }
1074
1075 if (newIcon == null) {
1076 newIcon = Win32ShellFolder2.super.getIcon(getLargeIcon);
1077 }
1078 return newIcon;
1079 }
1080 });
1081 if (getLargeIcon) {
1082 largeIcon = icon;
1083 } else {
1084 smallIcon = icon;
1085 }
1086 }
1087 return icon;
1088 }
1089
1090 /**
1091 * Gets an icon from the Windows system icon list as an {@code Image}
1092 */
1093 static Image getSystemIcon(SystemIcon iconType) {
1094 long hIcon = getSystemIcon(iconType.getIconID());
1095 Image icon = makeIcon(hIcon, true);
1096 disposeIcon(hIcon);
1097 return icon;
1098 }
1099
1100 /**
1101 * Gets an icon from the Windows system icon list as an {@code Image}
1102 */
1103 static Image getShell32Icon(int iconID, boolean getLargeIcon) {
1104 boolean useVGAColors = true; // Will be ignored on XP and later
1105
1106 int size = getLargeIcon ? 32 : 16;
1107
1108 Toolkit toolkit = Toolkit.getDefaultToolkit();
1109 String shellIconBPP = (String)toolkit.getDesktopProperty("win.icon.shellIconBPP");
1110 if (shellIconBPP != null) {
1111 useVGAColors = shellIconBPP.equals("4");
1112 }
1113
1114 long hIcon = getIconResource("shell32.dll", iconID, size, size, useVGAColors);
1115 if (hIcon != 0) {
1116 Image icon = makeIcon(hIcon, getLargeIcon);
1117 disposeIcon(hIcon);
1118 return icon;
1119 }
1120 return null;
1121 }
|