146 IDI_HAND(32513),
147 IDI_ERROR(32513),
148 IDI_QUESTION(32514),
149 IDI_EXCLAMATION(32515),
150 IDI_WARNING(32515),
151 IDI_ASTERISK(32516),
152 IDI_INFORMATION(32516),
153 IDI_WINLOGO(32517);
154
155 private final int iconID;
156
157 SystemIcon(int iconID) {
158 this.iconID = iconID;
159 }
160
161 public int getIconID() {
162 return iconID;
163 }
164 }
165
166 static class FolderDisposer implements sun.java2d.DisposerRecord {
167 /*
168 * This is cached as a concession to getFolderType(), which needs
169 * an absolute PIDL.
170 */
171 long absolutePIDL;
172 /*
173 * We keep track of shell folders through the IShellFolder
174 * interface of their parents plus their relative PIDL.
175 */
176 long pIShellFolder;
177 long relativePIDL;
178
179 boolean disposed;
180 public void dispose() {
181 if (disposed) return;
182 invoke(new Callable<Void>() {
183 public Void call() {
184 if (relativePIDL != 0) {
185 releasePIDL(relativePIDL);
561 * with a full attrsMask
562 * NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
563 */
564
565 private static native int getAttributes0(long pParentIShellFolder, long pIDL, int attrsMask);
566
567 // Return the path to the underlying file system object
568 // Should be called from the COM thread
569 private static String getFileSystemPath(final long parentIShellFolder, final long relativePIDL) {
570 int linkedFolder = ATTRIB_LINK | ATTRIB_FOLDER;
571 if (parentIShellFolder == Win32ShellFolderManager2.getNetwork().getIShellFolder() &&
572 getAttributes0(parentIShellFolder, relativePIDL, linkedFolder) == linkedFolder) {
573
574 String s =
575 getFileSystemPath(Win32ShellFolderManager2.getDesktop().getIShellFolder(),
576 getLinkLocation(parentIShellFolder, relativePIDL, false));
577 if (s != null && s.startsWith("\\\\")) {
578 return s;
579 }
580 }
581 return getDisplayNameOf(parentIShellFolder, relativePIDL, SHGDN_FORPARSING);
582 }
583
584 // Needs to be accessible to Win32ShellFolderManager2
585 static String getFileSystemPath(final int csidl) throws IOException, InterruptedException {
586 String path = invoke(new Callable<String>() {
587 public String call() throws IOException {
588 return getFileSystemPath0(csidl);
589 }
590 }, IOException.class);
591 if (path != null) {
592 SecurityManager security = System.getSecurityManager();
593 if (security != null) {
594 security.checkRead(path);
595 }
596 }
597 return path;
598 }
599
600 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
601 private static native String getFileSystemPath0(int csidl) throws IOException;
831 }
832
833 // Parse a display name into a PIDL relative to the current IShellFolder.
834 long parseDisplayName(final String name) throws IOException, InterruptedException {
835 return invoke(new Callable<Long>() {
836 public Long call() throws IOException {
837 return parseDisplayName0(getIShellFolder(), name);
838 }
839 }, IOException.class);
840 }
841
842 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
843 private static native long parseDisplayName0(long pIShellFolder, String name) throws IOException;
844
845 // Return the display name of a shell folder
846 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
847 private static native String getDisplayNameOf(long parentIShellFolder,
848 long relativePIDL,
849 int attrs);
850
851 /**
852 * @return The name used to display this shell folder
853 */
854 public String getDisplayName() {
855 if (displayName == null) {
856 displayName =
857 invoke(new Callable<String>() {
858 public String call() {
859 return getDisplayNameOf(getParentIShellFolder(),
860 getRelativePIDL(), SHGDN_NORMAL);
861 }
862 });
863 }
864 return displayName;
865 }
866
867 // Return the folder type of a shell folder
868 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
869 private static native String getFolderType(long pIDL);
870
1161
1162 // compares 2 objects within this folder by the specified column
1163 public int compare(final File o, final File o1) {
1164 Integer result = invoke(new Callable<Integer>() {
1165 public Integer call() {
1166 if (o instanceof Win32ShellFolder2
1167 && o1 instanceof Win32ShellFolder2) {
1168 // delegates comparison to native method
1169 return compareIDsByColumn(shellFolder.getIShellFolder(),
1170 ((Win32ShellFolder2) o).getRelativePIDL(),
1171 ((Win32ShellFolder2) o1).getRelativePIDL(),
1172 columnIdx);
1173 }
1174 return 0;
1175 }
1176 });
1177
1178 return result == null ? 0 : result;
1179 }
1180 }
1181 }
|
146 IDI_HAND(32513),
147 IDI_ERROR(32513),
148 IDI_QUESTION(32514),
149 IDI_EXCLAMATION(32515),
150 IDI_WARNING(32515),
151 IDI_ASTERISK(32516),
152 IDI_INFORMATION(32516),
153 IDI_WINLOGO(32517);
154
155 private final int iconID;
156
157 SystemIcon(int iconID) {
158 this.iconID = iconID;
159 }
160
161 public int getIconID() {
162 return iconID;
163 }
164 }
165
166 // Known Folder data
167 static class KnownFolderDefinition {
168 String guid;
169 int category;
170 String name;
171 String description;
172 String parent;
173 String relativePath;
174 String parsingName;
175 String tooltip;
176 String localizedName;
177 String icon;
178 String security;
179 long attributes;
180 int defenitionFlags;
181 String ftidType;
182 String path;
183 String saveLocation;
184 static final List<KnownFolderDefinition> libraries = getLibraries();
185 }
186
187 static class FolderDisposer implements sun.java2d.DisposerRecord {
188 /*
189 * This is cached as a concession to getFolderType(), which needs
190 * an absolute PIDL.
191 */
192 long absolutePIDL;
193 /*
194 * We keep track of shell folders through the IShellFolder
195 * interface of their parents plus their relative PIDL.
196 */
197 long pIShellFolder;
198 long relativePIDL;
199
200 boolean disposed;
201 public void dispose() {
202 if (disposed) return;
203 invoke(new Callable<Void>() {
204 public Void call() {
205 if (relativePIDL != 0) {
206 releasePIDL(relativePIDL);
582 * with a full attrsMask
583 * NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
584 */
585
586 private static native int getAttributes0(long pParentIShellFolder, long pIDL, int attrsMask);
587
588 // Return the path to the underlying file system object
589 // Should be called from the COM thread
590 private static String getFileSystemPath(final long parentIShellFolder, final long relativePIDL) {
591 int linkedFolder = ATTRIB_LINK | ATTRIB_FOLDER;
592 if (parentIShellFolder == Win32ShellFolderManager2.getNetwork().getIShellFolder() &&
593 getAttributes0(parentIShellFolder, relativePIDL, linkedFolder) == linkedFolder) {
594
595 String s =
596 getFileSystemPath(Win32ShellFolderManager2.getDesktop().getIShellFolder(),
597 getLinkLocation(parentIShellFolder, relativePIDL, false));
598 if (s != null && s.startsWith("\\\\")) {
599 return s;
600 }
601 }
602 String path = getDisplayNameOf(parentIShellFolder, relativePIDL,
603 SHGDN_FORPARSING);
604 // if this is a library its default save location is taken as a path
605 // this is a temp fix until java.io starts support Libraries
606 if( path != null && path.startsWith("::{") &&
607 path.toLowerCase().endsWith(".library-ms")) {
608 for (KnownFolderDefinition kf : KnownFolderDefinition.libraries) {
609 if( path.toLowerCase().endsWith(
610 kf.relativePath.toLowerCase()) &&
611 path.toUpperCase().startsWith(
612 kf.parsingName.substring(0, 40).toUpperCase()) ) {
613 return kf.saveLocation;
614 }
615 }
616 }
617 return path;
618 }
619
620 // Needs to be accessible to Win32ShellFolderManager2
621 static String getFileSystemPath(final int csidl) throws IOException, InterruptedException {
622 String path = invoke(new Callable<String>() {
623 public String call() throws IOException {
624 return getFileSystemPath0(csidl);
625 }
626 }, IOException.class);
627 if (path != null) {
628 SecurityManager security = System.getSecurityManager();
629 if (security != null) {
630 security.checkRead(path);
631 }
632 }
633 return path;
634 }
635
636 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
637 private static native String getFileSystemPath0(int csidl) throws IOException;
867 }
868
869 // Parse a display name into a PIDL relative to the current IShellFolder.
870 long parseDisplayName(final String name) throws IOException, InterruptedException {
871 return invoke(new Callable<Long>() {
872 public Long call() throws IOException {
873 return parseDisplayName0(getIShellFolder(), name);
874 }
875 }, IOException.class);
876 }
877
878 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
879 private static native long parseDisplayName0(long pIShellFolder, String name) throws IOException;
880
881 // Return the display name of a shell folder
882 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
883 private static native String getDisplayNameOf(long parentIShellFolder,
884 long relativePIDL,
885 int attrs);
886
887 // Returns data of all Known Folders registered in the system
888 private static native KnownFolderDefinition[] loadKnownFolders();
889
890 /**
891 * @return The name used to display this shell folder
892 */
893 public String getDisplayName() {
894 if (displayName == null) {
895 displayName =
896 invoke(new Callable<String>() {
897 public String call() {
898 return getDisplayNameOf(getParentIShellFolder(),
899 getRelativePIDL(), SHGDN_NORMAL);
900 }
901 });
902 }
903 return displayName;
904 }
905
906 // Return the folder type of a shell folder
907 // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
908 private static native String getFolderType(long pIDL);
909
1200
1201 // compares 2 objects within this folder by the specified column
1202 public int compare(final File o, final File o1) {
1203 Integer result = invoke(new Callable<Integer>() {
1204 public Integer call() {
1205 if (o instanceof Win32ShellFolder2
1206 && o1 instanceof Win32ShellFolder2) {
1207 // delegates comparison to native method
1208 return compareIDsByColumn(shellFolder.getIShellFolder(),
1209 ((Win32ShellFolder2) o).getRelativePIDL(),
1210 ((Win32ShellFolder2) o1).getRelativePIDL(),
1211 columnIdx);
1212 }
1213 return 0;
1214 }
1215 });
1216
1217 return result == null ? 0 : result;
1218 }
1219 }
1220
1221 // Extracts libraries and their default save locations from Known Folders list
1222 private static List<KnownFolderDefinition> getLibraries() {
1223 return invoke(new Callable<List<KnownFolderDefinition>>() {
1224 @Override
1225 public List<KnownFolderDefinition> call() throws Exception {
1226 KnownFolderDefinition[] all = loadKnownFolders();
1227 List<KnownFolderDefinition> folders = new ArrayList<>();
1228 if (all != null) {
1229 for (KnownFolderDefinition kf : all) {
1230 if (kf.relativePath == null || kf.parsingName == null ||
1231 kf.saveLocation == null) {
1232 continue;
1233 }
1234 folders.add(kf);
1235 }
1236 }
1237 return folders;
1238 }
1239 });
1240 }
1241
1242 }
|