author | xdono |
Wed, 02 Jul 2008 12:55:45 -0700 | |
changeset 715 | f16baef3a20e |
parent 678 | 7d331a53a753 |
child 2489 | 5052722686e2 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.awt.shell; |
|
27 |
||
28 |
import java.awt.Image; |
|
29 |
import java.awt.Toolkit; |
|
30 |
import java.awt.image.BufferedImage; |
|
31 |
import java.io.File; |
|
32 |
import java.io.FileNotFoundException; |
|
33 |
import java.io.IOException; |
|
34 |
import java.util.*; |
|
35 |
import javax.swing.SwingConstants; |
|
36 |
||
37 |
// NOTE: This class supersedes Win32ShellFolder, which was removed from |
|
38 |
// distribution after version 1.4.2. |
|
39 |
||
40 |
/** |
|
41 |
* Win32 Shell Folders |
|
42 |
* <P> |
|
43 |
* <BR> |
|
44 |
* There are two fundamental types of shell folders : file system folders |
|
45 |
* and non-file system folders. File system folders are relatively easy |
|
46 |
* to deal with. Non-file system folders are items such as My Computer, |
|
47 |
* Network Neighborhood, and the desktop. Some of these non-file system |
|
48 |
* folders have special values and properties. |
|
49 |
* <P> |
|
50 |
* <BR> |
|
51 |
* Win32 keeps two basic data structures for shell folders. The first |
|
52 |
* of these is called an ITEMIDLIST. Usually a pointer, called an |
|
53 |
* LPITEMIDLIST, or more frequently just "PIDL". This structure holds |
|
54 |
* a series of identifiers and can be either relative to the desktop |
|
55 |
* (an absolute PIDL), or relative to the shell folder that contains them. |
|
56 |
* Some Win32 functions can take absolute or relative PIDL values, and |
|
57 |
* others can only accept relative values. |
|
58 |
* <BR> |
|
59 |
* The second data structure is an IShellFolder COM interface. Using |
|
60 |
* this interface, one can enumerate the relative PIDLs in a shell |
|
61 |
* folder, get attributes, etc. |
|
62 |
* <BR> |
|
63 |
* All Win32ShellFolder2 objects which are folder types (even non-file |
|
64 |
* system folders) contain an IShellFolder object. Files are named in |
|
65 |
* directories via relative PIDLs. |
|
66 |
* |
|
67 |
* @author Michael Martak |
|
68 |
* @author Leif Samuelsson |
|
69 |
* @author Kenneth Russell |
|
70 |
* @since 1.4 */ |
|
71 |
||
72 |
final class Win32ShellFolder2 extends ShellFolder { |
|
73 |
||
74 |
private static native void initIDs(); |
|
75 |
||
76 |
private static final boolean is98; |
|
77 |
||
78 |
static { |
|
79 |
String osName = System.getProperty("os.name"); |
|
80 |
is98 = (osName != null && osName.startsWith("Windows 98")); |
|
81 |
||
82 |
initIDs(); |
|
83 |
} |
|
84 |
||
85 |
// Win32 Shell Folder Constants |
|
86 |
public static final int DESKTOP = 0x0000; |
|
87 |
public static final int INTERNET = 0x0001; |
|
88 |
public static final int PROGRAMS = 0x0002; |
|
89 |
public static final int CONTROLS = 0x0003; |
|
90 |
public static final int PRINTERS = 0x0004; |
|
91 |
public static final int PERSONAL = 0x0005; |
|
92 |
public static final int FAVORITES = 0x0006; |
|
93 |
public static final int STARTUP = 0x0007; |
|
94 |
public static final int RECENT = 0x0008; |
|
95 |
public static final int SENDTO = 0x0009; |
|
96 |
public static final int BITBUCKET = 0x000a; |
|
97 |
public static final int STARTMENU = 0x000b; |
|
98 |
public static final int DESKTOPDIRECTORY = 0x0010; |
|
99 |
public static final int DRIVES = 0x0011; |
|
100 |
public static final int NETWORK = 0x0012; |
|
101 |
public static final int NETHOOD = 0x0013; |
|
102 |
public static final int FONTS = 0x0014; |
|
103 |
public static final int TEMPLATES = 0x0015; |
|
104 |
public static final int COMMON_STARTMENU = 0x0016; |
|
105 |
public static final int COMMON_PROGRAMS = 0X0017; |
|
106 |
public static final int COMMON_STARTUP = 0x0018; |
|
107 |
public static final int COMMON_DESKTOPDIRECTORY = 0x0019; |
|
108 |
public static final int APPDATA = 0x001a; |
|
109 |
public static final int PRINTHOOD = 0x001b; |
|
110 |
public static final int ALTSTARTUP = 0x001d; |
|
111 |
public static final int COMMON_ALTSTARTUP = 0x001e; |
|
112 |
public static final int COMMON_FAVORITES = 0x001f; |
|
113 |
public static final int INTERNET_CACHE = 0x0020; |
|
114 |
public static final int COOKIES = 0x0021; |
|
115 |
public static final int HISTORY = 0x0022; |
|
116 |
||
117 |
// Win32 shell folder attributes |
|
118 |
public static final int ATTRIB_CANCOPY = 0x00000001; |
|
119 |
public static final int ATTRIB_CANMOVE = 0x00000002; |
|
120 |
public static final int ATTRIB_CANLINK = 0x00000004; |
|
121 |
public static final int ATTRIB_CANRENAME = 0x00000010; |
|
122 |
public static final int ATTRIB_CANDELETE = 0x00000020; |
|
123 |
public static final int ATTRIB_HASPROPSHEET = 0x00000040; |
|
124 |
public static final int ATTRIB_DROPTARGET = 0x00000100; |
|
125 |
public static final int ATTRIB_LINK = 0x00010000; |
|
126 |
public static final int ATTRIB_SHARE = 0x00020000; |
|
127 |
public static final int ATTRIB_READONLY = 0x00040000; |
|
128 |
public static final int ATTRIB_GHOSTED = 0x00080000; |
|
129 |
public static final int ATTRIB_HIDDEN = 0x00080000; |
|
130 |
public static final int ATTRIB_FILESYSANCESTOR = 0x10000000; |
|
131 |
public static final int ATTRIB_FOLDER = 0x20000000; |
|
132 |
public static final int ATTRIB_FILESYSTEM = 0x40000000; |
|
133 |
public static final int ATTRIB_HASSUBFOLDER = 0x80000000; |
|
134 |
public static final int ATTRIB_VALIDATE = 0x01000000; |
|
135 |
public static final int ATTRIB_REMOVABLE = 0x02000000; |
|
136 |
public static final int ATTRIB_COMPRESSED = 0x04000000; |
|
137 |
public static final int ATTRIB_BROWSABLE = 0x08000000; |
|
138 |
public static final int ATTRIB_NONENUMERATED = 0x00100000; |
|
139 |
public static final int ATTRIB_NEWCONTENT = 0x00200000; |
|
140 |
||
141 |
// IShellFolder::GetDisplayNameOf constants |
|
142 |
public static final int SHGDN_NORMAL = 0; |
|
143 |
public static final int SHGDN_INFOLDER = 1; |
|
144 |
public static final int SHGDN_INCLUDE_NONFILESYS= 0x2000; |
|
145 |
public static final int SHGDN_FORADDRESSBAR = 0x4000; |
|
146 |
public static final int SHGDN_FORPARSING = 0x8000; |
|
147 |
||
148 |
// Values for system call LoadIcon() |
|
149 |
public enum SystemIcon { |
|
150 |
IDI_APPLICATION(32512), |
|
151 |
IDI_HAND(32513), |
|
152 |
IDI_ERROR(32513), |
|
153 |
IDI_QUESTION(32514), |
|
154 |
IDI_EXCLAMATION(32515), |
|
155 |
IDI_WARNING(32515), |
|
156 |
IDI_ASTERISK(32516), |
|
157 |
IDI_INFORMATION(32516), |
|
158 |
IDI_WINLOGO(32517); |
|
159 |
||
160 |
private final int iconID; |
|
161 |
||
162 |
SystemIcon(int iconID) { |
|
163 |
this.iconID = iconID; |
|
164 |
} |
|
165 |
||
166 |
public int getIconID() { |
|
167 |
return iconID; |
|
168 |
} |
|
169 |
} |
|
170 |
||
171 |
static class FolderDisposer implements sun.java2d.DisposerRecord { |
|
172 |
/* |
|
173 |
* This is cached as a concession to getFolderType(), which needs |
|
174 |
* an absolute PIDL. |
|
175 |
*/ |
|
176 |
long absolutePIDL; |
|
177 |
/* |
|
178 |
* We keep track of shell folders through the IShellFolder |
|
179 |
* interface of their parents plus their relative PIDL. |
|
180 |
*/ |
|
181 |
long pIShellFolder; |
|
182 |
long relativePIDL; |
|
183 |
||
184 |
boolean disposed; |
|
185 |
public void dispose() { |
|
186 |
if (disposed) return; |
|
187 |
if (relativePIDL != 0) { |
|
188 |
releasePIDL(relativePIDL); |
|
189 |
} |
|
190 |
if (absolutePIDL != 0) { |
|
191 |
releasePIDL(absolutePIDL); |
|
192 |
} |
|
193 |
if (pIShellFolder != 0) { |
|
194 |
releaseIShellFolder(pIShellFolder); |
|
195 |
} |
|
196 |
disposed = true; |
|
197 |
} |
|
198 |
} |
|
199 |
FolderDisposer disposer = new FolderDisposer(); |
|
200 |
private void setIShellFolder(long pIShellFolder) { |
|
201 |
disposer.pIShellFolder = pIShellFolder; |
|
202 |
} |
|
203 |
private void setRelativePIDL(long relativePIDL) { |
|
204 |
disposer.relativePIDL = relativePIDL; |
|
205 |
} |
|
206 |
/* |
|
207 |
* The following are for caching various shell folder properties. |
|
208 |
*/ |
|
209 |
private long pIShellIcon = -1L; |
|
210 |
private String folderType = null; |
|
211 |
private String displayName = null; |
|
212 |
private Image smallIcon = null; |
|
213 |
private Image largeIcon = null; |
|
214 |
private Boolean isDir = null; |
|
215 |
||
216 |
/* |
|
217 |
* The following is to identify the My Documents folder as being special |
|
218 |
*/ |
|
219 |
private boolean isPersonal; |
|
220 |
||
221 |
||
222 |
/** |
|
223 |
* Create a system special shell folder, such as the |
|
224 |
* desktop or Network Neighborhood. |
|
225 |
*/ |
|
226 |
Win32ShellFolder2(int csidl) throws IOException { |
|
227 |
// Desktop is parent of DRIVES and NETWORK, not necessarily |
|
228 |
// other special shell folders. |
|
229 |
super(null, |
|
230 |
(getFileSystemPath(csidl) == null) |
|
231 |
? ("ShellFolder: 0x"+Integer.toHexString(csidl)) : getFileSystemPath(csidl)); |
|
232 |
if (csidl == DESKTOP) { |
|
233 |
initDesktop(); |
|
234 |
} else { |
|
235 |
initSpecial(getDesktop().getIShellFolder(), csidl); |
|
236 |
// At this point, the native method initSpecial() has set our relativePIDL |
|
237 |
// relative to the Desktop, which may not be our immediate parent. We need |
|
238 |
// to traverse this ID list and break it into a chain of shell folders from |
|
239 |
// the top, with each one having an immediate parent and a relativePIDL |
|
240 |
// relative to that parent. |
|
241 |
long pIDL = disposer.relativePIDL; |
|
242 |
parent = getDesktop(); |
|
243 |
while (pIDL != 0) { |
|
244 |
// Get a child pidl relative to 'parent' |
|
245 |
long childPIDL = copyFirstPIDLEntry(pIDL); |
|
246 |
if (childPIDL != 0) { |
|
247 |
// Get a handle to the the rest of the ID list |
|
248 |
// i,e, parent's grandchilren and down |
|
249 |
pIDL = getNextPIDLEntry(pIDL); |
|
250 |
if (pIDL != 0) { |
|
251 |
// Now we know that parent isn't immediate to 'this' because it |
|
252 |
// has a continued ID list. Create a shell folder for this child |
|
253 |
// pidl and make it the new 'parent'. |
|
254 |
parent = new Win32ShellFolder2((Win32ShellFolder2)parent, childPIDL); |
|
255 |
} else { |
|
256 |
// No grandchildren means we have arrived at the parent of 'this', |
|
257 |
// and childPIDL is directly relative to parent. |
|
258 |
disposer.relativePIDL = childPIDL; |
|
259 |
} |
|
260 |
} else { |
|
261 |
break; |
|
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
||
266 |
sun.java2d.Disposer.addRecord(this, disposer); |
|
267 |
} |
|
268 |
||
269 |
||
270 |
/** |
|
271 |
* Create a system shell folder |
|
272 |
*/ |
|
273 |
Win32ShellFolder2(Win32ShellFolder2 parent, long pIShellFolder, long relativePIDL, String path) { |
|
274 |
super(parent, (path != null) ? path : "ShellFolder: "); |
|
275 |
this.disposer.pIShellFolder = pIShellFolder; |
|
276 |
this.disposer.relativePIDL = relativePIDL; |
|
277 |
sun.java2d.Disposer.addRecord(this, disposer); |
|
278 |
} |
|
279 |
||
280 |
||
281 |
/** |
|
282 |
* Creates a shell folder with a parent and relative PIDL |
|
283 |
*/ |
|
284 |
Win32ShellFolder2(Win32ShellFolder2 parent, long relativePIDL) { |
|
285 |
super(parent, getFileSystemPath(parent.getIShellFolder(), relativePIDL)); |
|
286 |
this.disposer.relativePIDL = relativePIDL; |
|
287 |
getAbsolutePath(); |
|
288 |
sun.java2d.Disposer.addRecord(this, disposer); |
|
289 |
} |
|
290 |
||
291 |
// Initializes the desktop shell folder |
|
292 |
private native void initDesktop(); |
|
293 |
// Initializes a special, non-file system shell folder |
|
294 |
// from one of the above constants |
|
295 |
private native void initSpecial(long desktopIShellFolder, int csidl); |
|
296 |
||
297 |
/** Marks this folder as being the My Documents (Personal) folder */ |
|
298 |
public void setIsPersonal() { |
|
299 |
isPersonal = true; |
|
300 |
} |
|
301 |
||
302 |
/** |
|
303 |
* This method is implemented to make sure that no instances |
|
304 |
* of <code>ShellFolder</code> are ever serialized. If <code>isFileSystem()</code> returns |
|
305 |
* <code>true</code>, then the object is representable with an instance of |
|
306 |
* <code>java.io.File</code> instead. If not, then the object depends |
|
307 |
* on native PIDL state and should not be serialized. |
|
308 |
* |
|
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
309 |
* @return a <code>java.io.File</code> replacement object. If the folder |
2 | 310 |
* is a not a normal directory, then returns the first non-removable |
311 |
* drive (normally "C:\"). |
|
312 |
*/ |
|
313 |
protected Object writeReplace() throws java.io.ObjectStreamException { |
|
314 |
if (isFileSystem()) { |
|
315 |
return new File(getPath()); |
|
316 |
} else { |
|
317 |
Win32ShellFolder2 drives = Win32ShellFolderManager2.getDrives(); |
|
318 |
if (drives != null) { |
|
319 |
File[] driveRoots = drives.listFiles(); |
|
320 |
if (driveRoots != null) { |
|
321 |
for (int i = 0; i < driveRoots.length; i++) { |
|
322 |
if (driveRoots[i] instanceof Win32ShellFolder2) { |
|
323 |
Win32ShellFolder2 sf = (Win32ShellFolder2)driveRoots[i]; |
|
324 |
if (sf.isFileSystem() && !sf.hasAttribute(ATTRIB_REMOVABLE)) { |
|
325 |
return new File(sf.getPath()); |
|
326 |
} |
|
327 |
} |
|
328 |
} |
|
329 |
} |
|
330 |
} |
|
331 |
// Ouch, we have no hard drives. Return something "valid" anyway. |
|
332 |
return new File("C:\\"); |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
||
337 |
/** |
|
338 |
* Finalizer to clean up any COM objects or PIDLs used by this object. |
|
339 |
*/ |
|
340 |
protected void dispose() { |
|
341 |
disposer.dispose(); |
|
342 |
} |
|
343 |
||
344 |
||
345 |
// Given a (possibly multi-level) relative PIDL (with respect to |
|
346 |
// the desktop, at least in all of the usage cases in this code), |
|
347 |
// return a pointer to the next entry. Does not mutate the PIDL in |
|
348 |
// any way. Returns 0 if the null terminator is reached. |
|
349 |
// Needs to be accessible to Win32ShellFolderManager2 |
|
350 |
static native long getNextPIDLEntry(long pIDL); |
|
351 |
||
352 |
// Given a (possibly multi-level) relative PIDL (with respect to |
|
353 |
// the desktop, at least in all of the usage cases in this code), |
|
354 |
// copy the first entry into a newly-allocated PIDL. Returns 0 if |
|
355 |
// the PIDL is at the end of the list. |
|
356 |
// Needs to be accessible to Win32ShellFolderManager2 |
|
357 |
static native long copyFirstPIDLEntry(long pIDL); |
|
358 |
||
359 |
// Given a parent's absolute PIDL and our relative PIDL, build an absolute PIDL |
|
360 |
private static native long combinePIDLs(long ppIDL, long pIDL); |
|
361 |
||
362 |
// Release a PIDL object |
|
363 |
// Needs to be accessible to Win32ShellFolderManager2 |
|
364 |
static native void releasePIDL(long pIDL); |
|
365 |
||
366 |
// Release an IShellFolder object |
|
367 |
private static native void releaseIShellFolder(long pIShellFolder); |
|
368 |
||
369 |
/** |
|
370 |
* Accessor for IShellFolder |
|
371 |
*/ |
|
372 |
public long getIShellFolder() { |
|
373 |
if (disposer.pIShellFolder == 0) { |
|
374 |
assert(isDirectory()); |
|
375 |
assert(parent != null); |
|
376 |
long parentIShellFolder = getParentIShellFolder(); |
|
377 |
if (parentIShellFolder == 0) { |
|
378 |
throw new InternalError("Parent IShellFolder was null for " + getAbsolutePath()); |
|
379 |
} |
|
380 |
// We are a directory with a parent and a relative PIDL. |
|
381 |
// We want to bind to the parent so we get an IShellFolder instance associated with us. |
|
382 |
disposer.pIShellFolder = bindToObject(parentIShellFolder, disposer.relativePIDL); |
|
383 |
if (disposer.pIShellFolder == 0) { |
|
384 |
throw new InternalError("Unable to bind " + getAbsolutePath() + " to parent"); |
|
385 |
} |
|
386 |
} |
|
387 |
return disposer.pIShellFolder; |
|
388 |
} |
|
389 |
||
390 |
/** |
|
391 |
* Get the parent ShellFolder's IShellFolder interface |
|
392 |
*/ |
|
393 |
public long getParentIShellFolder() { |
|
394 |
Win32ShellFolder2 parent = (Win32ShellFolder2)getParentFile(); |
|
395 |
if (parent == null) { |
|
396 |
// Parent should only be null if this is the desktop, whose |
|
397 |
// relativePIDL is relative to its own IShellFolder. |
|
398 |
return getIShellFolder(); |
|
399 |
} |
|
400 |
return parent.getIShellFolder(); |
|
401 |
} |
|
402 |
||
403 |
/** |
|
404 |
* Accessor for relative PIDL |
|
405 |
*/ |
|
406 |
public long getRelativePIDL() { |
|
407 |
if (disposer.relativePIDL == 0) { |
|
408 |
throw new InternalError("Should always have a relative PIDL"); |
|
409 |
} |
|
410 |
return disposer.relativePIDL; |
|
411 |
} |
|
412 |
||
413 |
private long getAbsolutePIDL() { |
|
414 |
if (parent == null) { |
|
415 |
// This is the desktop |
|
416 |
return getRelativePIDL(); |
|
417 |
} else { |
|
418 |
if (disposer.absolutePIDL == 0) { |
|
419 |
disposer.absolutePIDL = combinePIDLs(((Win32ShellFolder2)parent).getAbsolutePIDL(), getRelativePIDL()); |
|
420 |
} |
|
421 |
||
422 |
return disposer.absolutePIDL; |
|
423 |
} |
|
424 |
} |
|
425 |
||
426 |
/** |
|
427 |
* Helper function to return the desktop |
|
428 |
*/ |
|
429 |
public Win32ShellFolder2 getDesktop() { |
|
430 |
return Win32ShellFolderManager2.getDesktop(); |
|
431 |
} |
|
432 |
||
433 |
/** |
|
434 |
* Helper function to return the desktop IShellFolder interface |
|
435 |
*/ |
|
436 |
public long getDesktopIShellFolder() { |
|
437 |
return getDesktop().getIShellFolder(); |
|
438 |
} |
|
439 |
||
440 |
private static boolean pathsEqual(String path1, String path2) { |
|
441 |
// Same effective implementation as Win32FileSystem |
|
442 |
return path1.equalsIgnoreCase(path2); |
|
443 |
} |
|
444 |
||
445 |
/** |
|
446 |
* Check to see if two ShellFolder objects are the same |
|
447 |
*/ |
|
448 |
public boolean equals(Object o) { |
|
449 |
if (o == null || !(o instanceof Win32ShellFolder2)) { |
|
450 |
// Short-circuit circuitous delegation path |
|
451 |
if (!(o instanceof File)) { |
|
452 |
return super.equals(o); |
|
453 |
} |
|
454 |
return pathsEqual(getPath(), ((File) o).getPath()); |
|
455 |
} |
|
456 |
Win32ShellFolder2 rhs = (Win32ShellFolder2) o; |
|
457 |
if ((parent == null && rhs.parent != null) || |
|
458 |
(parent != null && rhs.parent == null)) { |
|
459 |
return false; |
|
460 |
} |
|
461 |
||
462 |
if (isFileSystem() && rhs.isFileSystem()) { |
|
463 |
// Only folders with identical parents can be equal |
|
464 |
return (pathsEqual(getPath(), rhs.getPath()) && |
|
465 |
(parent == rhs.parent || parent.equals(rhs.parent))); |
|
466 |
} |
|
467 |
||
468 |
if (parent == rhs.parent || parent.equals(rhs.parent)) { |
|
469 |
return pidlsEqual(getParentIShellFolder(), disposer.relativePIDL, rhs.disposer.relativePIDL); |
|
470 |
} |
|
471 |
||
472 |
return false; |
|
473 |
} |
|
474 |
||
475 |
private static boolean pidlsEqual(long pIShellFolder, long pidl1, long pidl2) { |
|
476 |
return (compareIDs(pIShellFolder, pidl1, pidl2) == 0); |
|
477 |
} |
|
478 |
private static native int compareIDs(long pParentIShellFolder, long pidl1, long pidl2); |
|
479 |
||
480 |
/** |
|
481 |
* @return Whether this is a file system shell folder |
|
482 |
*/ |
|
483 |
public boolean isFileSystem() { |
|
484 |
return hasAttribute(ATTRIB_FILESYSTEM); |
|
485 |
} |
|
486 |
||
487 |
/** |
|
488 |
* Return whether the given attribute flag is set for this object |
|
489 |
*/ |
|
490 |
public boolean hasAttribute(int attribute) { |
|
491 |
// Caching at this point doesn't seem to be cost efficient |
|
492 |
return (getAttributes0(getParentIShellFolder(), getRelativePIDL(), attribute) & attribute) != 0; |
|
493 |
} |
|
494 |
||
495 |
/** |
|
496 |
* Returns the queried attributes specified in attrsMask. |
|
497 |
* |
|
498 |
* Could plausibly be used for attribute caching but have to be |
|
499 |
* very careful not to touch network drives and file system roots |
|
500 |
* with a full attrsMask |
|
501 |
*/ |
|
502 |
private static native int getAttributes0(long pParentIShellFolder, long pIDL, int attrsMask); |
|
503 |
||
504 |
// Return the path to the underlying file system object |
|
505 |
private static String getFileSystemPath(long parentIShellFolder, long relativePIDL) { |
|
506 |
int linkedFolder = ATTRIB_LINK | ATTRIB_FOLDER; |
|
507 |
if (parentIShellFolder == Win32ShellFolderManager2.getNetwork().getIShellFolder() && |
|
508 |
getAttributes0(parentIShellFolder, relativePIDL, linkedFolder) == linkedFolder) { |
|
509 |
||
510 |
String s = |
|
511 |
getFileSystemPath(Win32ShellFolderManager2.getDesktop().getIShellFolder(), |
|
512 |
getLinkLocation(parentIShellFolder, relativePIDL, false)); |
|
513 |
if (s != null && s.startsWith("\\\\")) { |
|
514 |
return s; |
|
515 |
} |
|
516 |
} |
|
517 |
return getDisplayNameOf(parentIShellFolder, relativePIDL, SHGDN_NORMAL | SHGDN_FORPARSING); |
|
518 |
} |
|
519 |
// Needs to be accessible to Win32ShellFolderManager2 |
|
520 |
static native String getFileSystemPath(int csidl) throws IOException; |
|
521 |
||
522 |
// Return whether the path is a network root. |
|
523 |
// Path is assumed to be non-null |
|
524 |
private static boolean isNetworkRoot(String path) { |
|
525 |
return (path.equals("\\\\") || path.equals("\\") || path.equals("//") || path.equals("/")); |
|
526 |
} |
|
527 |
||
528 |
/** |
|
529 |
* @return The parent shell folder of this shell folder, null if |
|
530 |
* there is no parent |
|
531 |
*/ |
|
532 |
public File getParentFile() { |
|
533 |
return parent; |
|
534 |
} |
|
535 |
||
536 |
public boolean isDirectory() { |
|
537 |
if (isDir == null) { |
|
538 |
// Folders with SFGAO_BROWSABLE have "shell extension" handlers and are |
|
539 |
// not traversable in JFileChooser. An exception is "My Documents" on |
|
540 |
// Windows 98. |
|
541 |
if (hasAttribute(ATTRIB_FOLDER) |
|
542 |
&& (!hasAttribute(ATTRIB_BROWSABLE) || |
|
543 |
(is98 && equals(Win32ShellFolderManager2.getPersonal())))) { |
|
544 |
isDir = Boolean.TRUE; |
|
545 |
} else if (isLink()) { |
|
546 |
ShellFolder linkLocation = getLinkLocation(false); |
|
547 |
isDir = Boolean.valueOf(linkLocation != null && linkLocation.isDirectory()); |
|
548 |
} else { |
|
549 |
isDir = Boolean.FALSE; |
|
550 |
} |
|
551 |
} |
|
552 |
return isDir.booleanValue(); |
|
553 |
} |
|
554 |
||
555 |
/* |
|
556 |
* Functions for enumerating an IShellFolder's children |
|
557 |
*/ |
|
558 |
// Returns an IEnumIDList interface for an IShellFolder. The value |
|
559 |
// returned must be released using releaseEnumObjects(). |
|
560 |
private long getEnumObjects(long pIShellFolder, boolean includeHiddenFiles) { |
|
561 |
boolean isDesktop = (disposer.pIShellFolder == getDesktopIShellFolder()); |
|
562 |
return getEnumObjects(disposer.pIShellFolder, isDesktop, includeHiddenFiles); |
|
563 |
} |
|
564 |
// Returns an IEnumIDList interface for an IShellFolder. The value |
|
565 |
// returned must be released using releaseEnumObjects(). |
|
566 |
private native long getEnumObjects(long pIShellFolder, boolean isDesktop, |
|
567 |
boolean includeHiddenFiles); |
|
568 |
// Returns the next sequential child as a relative PIDL |
|
569 |
// from an IEnumIDList interface. The value returned must |
|
570 |
// be released using releasePIDL(). |
|
571 |
private native long getNextChild(long pEnumObjects); |
|
572 |
// Releases the IEnumIDList interface |
|
573 |
private native void releaseEnumObjects(long pEnumObjects); |
|
574 |
||
575 |
// Returns the IShellFolder of a child from a parent IShellFolder |
|
576 |
// and a relative PIDL. The value returned must be released |
|
577 |
// using releaseIShellFolder(). |
|
578 |
private static native long bindToObject(long parentIShellFolder, long pIDL); |
|
579 |
||
580 |
/** |
|
581 |
* @return An array of shell folders that are children of this shell folder |
|
582 |
* object. The array will be empty if the folder is empty. Returns |
|
583 |
* <code>null</code> if this shellfolder does not denote a directory. |
|
584 |
*/ |
|
585 |
public File[] listFiles(boolean includeHiddenFiles) { |
|
586 |
SecurityManager security = System.getSecurityManager(); |
|
587 |
if (security != null) { |
|
588 |
security.checkRead(getPath()); |
|
589 |
} |
|
590 |
if (!isDirectory()) { |
|
591 |
return null; |
|
592 |
} |
|
593 |
// Links to directories are not directories and cannot be parents. |
|
594 |
// This does not apply to folders in My Network Places (NetHood) |
|
595 |
// because they are both links and real directories! |
|
596 |
if (isLink() && !hasAttribute(ATTRIB_FOLDER)) { |
|
597 |
return new File[0]; |
|
598 |
} |
|
599 |
||
600 |
Win32ShellFolder2 desktop = Win32ShellFolderManager2.getDesktop(); |
|
601 |
Win32ShellFolder2 personal = Win32ShellFolderManager2.getPersonal(); |
|
602 |
||
603 |
// If we are a directory, we have a parent and (at least) a |
|
604 |
// relative PIDL. We must first ensure we are bound to the |
|
605 |
// parent so we have an IShellFolder to query. |
|
606 |
long pIShellFolder = getIShellFolder(); |
|
607 |
// Now we can enumerate the objects in this folder. |
|
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
608 |
ArrayList<Win32ShellFolder2> list = new ArrayList<Win32ShellFolder2>(); |
2 | 609 |
long pEnumObjects = getEnumObjects(pIShellFolder, includeHiddenFiles); |
610 |
if (pEnumObjects != 0) { |
|
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
611 |
long childPIDL; |
2 | 612 |
int testedAttrs = ATTRIB_FILESYSTEM | ATTRIB_FILESYSANCESTOR; |
613 |
do { |
|
614 |
if (Thread.currentThread().isInterrupted()) { |
|
615 |
return new File[0]; |
|
616 |
} |
|
617 |
childPIDL = getNextChild(pEnumObjects); |
|
618 |
boolean releasePIDL = true; |
|
619 |
if (childPIDL != 0 && |
|
620 |
(getAttributes0(pIShellFolder, childPIDL, testedAttrs) & testedAttrs) != 0) { |
|
621 |
Win32ShellFolder2 childFolder = null; |
|
622 |
if (this.equals(desktop) |
|
623 |
&& personal != null |
|
624 |
&& pidlsEqual(pIShellFolder, childPIDL, personal.disposer.relativePIDL)) { |
|
625 |
childFolder = personal; |
|
626 |
} else { |
|
627 |
childFolder = new Win32ShellFolder2(this, childPIDL); |
|
628 |
releasePIDL = false; |
|
629 |
} |
|
630 |
list.add(childFolder); |
|
631 |
} |
|
632 |
if (releasePIDL) { |
|
633 |
releasePIDL(childPIDL); |
|
634 |
} |
|
635 |
} while (childPIDL != 0); |
|
636 |
releaseEnumObjects(pEnumObjects); |
|
637 |
} |
|
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
638 |
return list.toArray(new ShellFolder[list.size()]); |
2 | 639 |
} |
640 |
||
641 |
||
642 |
/** |
|
643 |
* Look for (possibly special) child folder by it's path |
|
644 |
* |
|
645 |
* @return The child shellfolder, or null if not found. |
|
646 |
*/ |
|
647 |
Win32ShellFolder2 getChildByPath(String filePath) { |
|
648 |
long pIShellFolder = getIShellFolder(); |
|
649 |
long pEnumObjects = getEnumObjects(pIShellFolder, true); |
|
650 |
Win32ShellFolder2 child = null; |
|
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
651 |
long childPIDL; |
2 | 652 |
|
653 |
while ((childPIDL = getNextChild(pEnumObjects)) != 0) { |
|
654 |
if (getAttributes0(pIShellFolder, childPIDL, ATTRIB_FILESYSTEM) != 0) { |
|
655 |
String path = getFileSystemPath(pIShellFolder, childPIDL); |
|
656 |
if (path != null && path.equalsIgnoreCase(filePath)) { |
|
657 |
long childIShellFolder = bindToObject(pIShellFolder, childPIDL); |
|
658 |
child = new Win32ShellFolder2(this, childIShellFolder, childPIDL, path); |
|
659 |
break; |
|
660 |
} |
|
661 |
} |
|
662 |
releasePIDL(childPIDL); |
|
663 |
} |
|
664 |
releaseEnumObjects(pEnumObjects); |
|
665 |
return child; |
|
666 |
} |
|
667 |
||
668 |
||
669 |
/** |
|
670 |
* @return Whether this shell folder is a link |
|
671 |
*/ |
|
672 |
public boolean isLink() { |
|
673 |
return hasAttribute(ATTRIB_LINK); |
|
674 |
} |
|
675 |
||
676 |
/** |
|
677 |
* @return Whether this shell folder is marked as hidden |
|
678 |
*/ |
|
679 |
public boolean isHidden() { |
|
680 |
return hasAttribute(ATTRIB_HIDDEN); |
|
681 |
} |
|
682 |
||
683 |
||
684 |
// Return the link location of a shell folder |
|
685 |
private static native long getLinkLocation(long parentIShellFolder, |
|
686 |
long relativePIDL, boolean resolve); |
|
687 |
||
688 |
/** |
|
689 |
* @return The shell folder linked to by this shell folder, or null |
|
690 |
* if this shell folder is not a link or is a broken or invalid link |
|
691 |
*/ |
|
692 |
public ShellFolder getLinkLocation() { |
|
693 |
return getLinkLocation(true); |
|
694 |
} |
|
695 |
||
696 |
private ShellFolder getLinkLocation(boolean resolve) { |
|
697 |
if (!isLink()) { |
|
698 |
return null; |
|
699 |
} |
|
700 |
||
701 |
ShellFolder location = null; |
|
702 |
long linkLocationPIDL = getLinkLocation(getParentIShellFolder(), |
|
703 |
getRelativePIDL(), resolve); |
|
704 |
if (linkLocationPIDL != 0) { |
|
705 |
try { |
|
706 |
location = |
|
707 |
Win32ShellFolderManager2.createShellFolderFromRelativePIDL(getDesktop(), |
|
708 |
linkLocationPIDL); |
|
709 |
} catch (InternalError e) { |
|
710 |
// Could be a link to a non-bindable object, such as a network connection |
|
711 |
// TODO: getIShellFolder() should throw FileNotFoundException instead |
|
712 |
} |
|
713 |
} |
|
714 |
return location; |
|
715 |
} |
|
716 |
||
717 |
// Parse a display name into a PIDL relative to the current IShellFolder. |
|
718 |
long parseDisplayName(String name) throws FileNotFoundException { |
|
719 |
try { |
|
720 |
return parseDisplayName0(getIShellFolder(), name); |
|
721 |
} catch (IOException e) { |
|
722 |
throw new FileNotFoundException("Could not find file " + name); |
|
723 |
} |
|
724 |
} |
|
725 |
private static native long parseDisplayName0(long pIShellFolder, String name) throws IOException; |
|
726 |
||
727 |
// Return the display name of a shell folder |
|
728 |
private static native String getDisplayNameOf(long parentIShellFolder, |
|
729 |
long relativePIDL, |
|
730 |
int attrs); |
|
731 |
||
732 |
/** |
|
733 |
* @return The name used to display this shell folder |
|
734 |
*/ |
|
735 |
public String getDisplayName() { |
|
736 |
if (displayName == null) { |
|
737 |
displayName = getDisplayNameOf(getParentIShellFolder(), getRelativePIDL(), SHGDN_NORMAL); |
|
738 |
} |
|
739 |
return displayName; |
|
740 |
} |
|
741 |
||
742 |
// Return the folder type of a shell folder |
|
743 |
private static native String getFolderType(long pIDL); |
|
744 |
||
745 |
/** |
|
746 |
* @return The type of shell folder as a string |
|
747 |
*/ |
|
748 |
public String getFolderType() { |
|
749 |
if (folderType == null) { |
|
750 |
folderType = getFolderType(getAbsolutePIDL()); |
|
751 |
} |
|
752 |
return folderType; |
|
753 |
} |
|
754 |
||
755 |
// Return the executable type of a file system shell folder |
|
756 |
private native String getExecutableType(String path); |
|
757 |
||
758 |
/** |
|
759 |
* @return The executable type as a string |
|
760 |
*/ |
|
761 |
public String getExecutableType() { |
|
762 |
if (!isFileSystem()) { |
|
763 |
return null; |
|
764 |
} |
|
765 |
return getExecutableType(getAbsolutePath()); |
|
766 |
} |
|
767 |
||
768 |
||
769 |
||
770 |
// Icons |
|
771 |
||
772 |
private static Map smallSystemImages = new HashMap(); |
|
773 |
private static Map largeSystemImages = new HashMap(); |
|
774 |
private static Map smallLinkedSystemImages = new HashMap(); |
|
775 |
private static Map largeLinkedSystemImages = new HashMap(); |
|
776 |
||
777 |
private static native long getIShellIcon(long pIShellFolder); |
|
778 |
private static native int getIconIndex(long parentIShellIcon, long relativePIDL); |
|
779 |
||
780 |
// Return the icon of a file system shell folder in the form of an HICON |
|
781 |
private static native long getIcon(String absolutePath, boolean getLargeIcon); |
|
782 |
private static native long extractIcon(long parentIShellFolder, long relativePIDL, |
|
783 |
boolean getLargeIcon); |
|
784 |
||
785 |
// Returns an icon from the Windows system icon list in the form of an HICON |
|
786 |
private static native long getSystemIcon(int iconID); |
|
787 |
private static native long getIconResource(String libName, int iconID, |
|
788 |
int cxDesired, int cyDesired, |
|
789 |
boolean useVGAColors); |
|
790 |
// Note: useVGAColors is ignored on XP and later |
|
791 |
||
792 |
// Return the bits from an HICON. This has a side effect of setting |
|
793 |
// the imageHash variable for efficient caching / comparing. |
|
794 |
private static native int[] getIconBits(long hIcon, int iconSize); |
|
795 |
// Dispose the HICON |
|
796 |
private static native void disposeIcon(long hIcon); |
|
797 |
||
798 |
public static native int[] getFileChooserBitmapBits(); |
|
799 |
||
800 |
private long getIShellIcon() { |
|
801 |
if (pIShellIcon == -1L) { |
|
802 |
pIShellIcon = getIShellIcon(getIShellFolder()); |
|
803 |
} |
|
804 |
return pIShellIcon; |
|
805 |
} |
|
806 |
||
807 |
||
808 |
static int[] fileChooserBitmapBits = null; |
|
809 |
static Image[] fileChooserIcons = new Image[47]; |
|
810 |
||
811 |
static Image getFileChooserIcon(int i) { |
|
812 |
if (fileChooserIcons[i] != null) { |
|
813 |
return fileChooserIcons[i]; |
|
814 |
} else { |
|
815 |
if (fileChooserBitmapBits == null) { |
|
816 |
fileChooserBitmapBits = getFileChooserBitmapBits(); |
|
817 |
} |
|
818 |
if (fileChooserBitmapBits != null) { |
|
819 |
int nImages = fileChooserBitmapBits.length / (16*16); |
|
820 |
int[] bitmapBits = new int[16 * 16]; |
|
821 |
for (int y = 0; y < 16; y++) { |
|
822 |
for (int x = 0; x < 16; x++) { |
|
823 |
bitmapBits[y * 16 + x] = fileChooserBitmapBits[y * (nImages * 16) + (i * 16) + x]; |
|
824 |
} |
|
825 |
} |
|
826 |
BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); |
|
827 |
img.setRGB(0, 0, 16, 16, bitmapBits, 0, 16); |
|
828 |
fileChooserIcons[i] = img; |
|
829 |
} |
|
830 |
} |
|
831 |
return fileChooserIcons[i]; |
|
832 |
} |
|
833 |
||
834 |
||
835 |
private static Image makeIcon(long hIcon, boolean getLargeIcon) { |
|
836 |
if (hIcon != 0L && hIcon != -1L) { |
|
837 |
// Get the bits. This has the side effect of setting the imageHash value for this object. |
|
838 |
int size = getLargeIcon ? 32 : 16; |
|
839 |
int[] iconBits = getIconBits(hIcon, size); |
|
840 |
if (iconBits != null) { |
|
841 |
BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); |
|
842 |
img.setRGB(0, 0, size, size, iconBits, 0, size); |
|
843 |
return img; |
|
844 |
} |
|
845 |
} |
|
846 |
return null; |
|
847 |
} |
|
848 |
||
849 |
||
850 |
/** |
|
851 |
* @return The icon image used to display this shell folder |
|
852 |
*/ |
|
853 |
public Image getIcon(boolean getLargeIcon) { |
|
854 |
Image icon = getLargeIcon ? largeIcon : smallIcon; |
|
855 |
if (icon == null) { |
|
856 |
long parentIShellIcon = (parent != null) ? ((Win32ShellFolder2)parent).getIShellIcon() : 0L; |
|
857 |
long relativePIDL = getRelativePIDL(); |
|
858 |
||
859 |
if (isFileSystem()) { |
|
860 |
// These are cached per type (using the index in the system image list) |
|
861 |
int index = getIconIndex(parentIShellIcon, relativePIDL); |
|
862 |
if (index > 0) { |
|
863 |
Map imageCache; |
|
864 |
if (isLink()) { |
|
865 |
imageCache = getLargeIcon ? largeLinkedSystemImages : smallLinkedSystemImages; |
|
866 |
} else { |
|
867 |
imageCache = getLargeIcon ? largeSystemImages : smallSystemImages; |
|
868 |
} |
|
869 |
icon = (Image)imageCache.get(Integer.valueOf(index)); |
|
870 |
if (icon == null) { |
|
871 |
long hIcon = getIcon(getAbsolutePath(), getLargeIcon); |
|
872 |
icon = makeIcon(hIcon, getLargeIcon); |
|
873 |
disposeIcon(hIcon); |
|
874 |
if (icon != null) { |
|
875 |
imageCache.put(Integer.valueOf(index), icon); |
|
876 |
} |
|
877 |
} |
|
878 |
} |
|
879 |
} |
|
880 |
||
881 |
if (icon == null) { |
|
882 |
// These are only cached per object |
|
883 |
long hIcon = extractIcon(getParentIShellFolder(), getRelativePIDL(), getLargeIcon); |
|
884 |
icon = makeIcon(hIcon, getLargeIcon); |
|
885 |
disposeIcon(hIcon); |
|
886 |
} |
|
887 |
||
888 |
if (getLargeIcon) { |
|
889 |
largeIcon = icon; |
|
890 |
} else { |
|
891 |
smallIcon = icon; |
|
892 |
} |
|
893 |
} |
|
894 |
if (icon == null) { |
|
895 |
icon = super.getIcon(getLargeIcon); |
|
896 |
} |
|
897 |
return icon; |
|
898 |
} |
|
899 |
||
900 |
/** |
|
901 |
* Gets an icon from the Windows system icon list as an <code>Image</code> |
|
902 |
*/ |
|
903 |
static Image getSystemIcon(SystemIcon iconType) { |
|
904 |
long hIcon = getSystemIcon(iconType.getIconID()); |
|
905 |
Image icon = makeIcon(hIcon, true); |
|
906 |
disposeIcon(hIcon); |
|
907 |
return icon; |
|
908 |
} |
|
909 |
||
910 |
/** |
|
911 |
* Gets an icon from the Windows system icon list as an <code>Image</code> |
|
912 |
*/ |
|
454
2f4f4fef8880
6210674: FileChooser fails to load custom harddrive icon and gets NullPointerException
rupashka
parents:
2
diff
changeset
|
913 |
static Image getShell32Icon(int iconID, boolean getLargeIcon) { |
2 | 914 |
boolean useVGAColors = true; // Will be ignored on XP and later |
915 |
||
454
2f4f4fef8880
6210674: FileChooser fails to load custom harddrive icon and gets NullPointerException
rupashka
parents:
2
diff
changeset
|
916 |
int size = getLargeIcon ? 32 : 16; |
2f4f4fef8880
6210674: FileChooser fails to load custom harddrive icon and gets NullPointerException
rupashka
parents:
2
diff
changeset
|
917 |
|
2 | 918 |
Toolkit toolkit = Toolkit.getDefaultToolkit(); |
919 |
String shellIconBPP = (String)toolkit.getDesktopProperty("win.icon.shellIconBPP"); |
|
920 |
if (shellIconBPP != null) { |
|
921 |
useVGAColors = shellIconBPP.equals("4"); |
|
922 |
} |
|
923 |
||
454
2f4f4fef8880
6210674: FileChooser fails to load custom harddrive icon and gets NullPointerException
rupashka
parents:
2
diff
changeset
|
924 |
long hIcon = getIconResource("shell32.dll", iconID, size, size, useVGAColors); |
2 | 925 |
if (hIcon != 0) { |
454
2f4f4fef8880
6210674: FileChooser fails to load custom harddrive icon and gets NullPointerException
rupashka
parents:
2
diff
changeset
|
926 |
Image icon = makeIcon(hIcon, getLargeIcon); |
2 | 927 |
disposeIcon(hIcon); |
928 |
return icon; |
|
929 |
} |
|
930 |
return null; |
|
931 |
} |
|
932 |
||
933 |
/** |
|
934 |
* Returns the canonical form of this abstract pathname. Equivalent to |
|
935 |
* <code>new Win32ShellFolder2(getParentFile(), this.{@link java.io.File#getCanonicalPath}())</code>. |
|
936 |
* |
|
937 |
* @see java.io.File#getCanonicalFile |
|
938 |
*/ |
|
939 |
public File getCanonicalFile() throws IOException { |
|
940 |
return this; |
|
941 |
} |
|
942 |
||
943 |
/* |
|
944 |
* Indicates whether this is a special folder (includes My Documents) |
|
945 |
*/ |
|
946 |
public boolean isSpecial() { |
|
947 |
return isPersonal || !isFileSystem() || (this == getDesktop()); |
|
948 |
} |
|
949 |
||
950 |
/** |
|
951 |
* Compares this object with the specified object for order. |
|
952 |
* |
|
953 |
* @see sun.awt.shell.ShellFolder#compareTo(File) |
|
954 |
*/ |
|
955 |
public int compareTo(File file2) { |
|
956 |
if (!(file2 instanceof Win32ShellFolder2)) { |
|
957 |
if (isFileSystem() && !isSpecial()) { |
|
958 |
return super.compareTo(file2); |
|
959 |
} else { |
|
960 |
return -1; // Non-file shellfolders sort before files |
|
961 |
} |
|
962 |
} |
|
963 |
return Win32ShellFolderManager2.compareShellFolders(this, (Win32ShellFolder2) file2); |
|
964 |
} |
|
965 |
||
966 |
// native constants from commctrl.h |
|
967 |
private static final int LVCFMT_LEFT = 0; |
|
968 |
private static final int LVCFMT_RIGHT = 1; |
|
969 |
private static final int LVCFMT_CENTER = 2; |
|
970 |
||
971 |
public ShellFolderColumnInfo[] getFolderColumns() { |
|
972 |
ShellFolderColumnInfo[] columns = doGetColumnInfo(getIShellFolder()); |
|
973 |
||
974 |
if (columns != null) { |
|
975 |
List<ShellFolderColumnInfo> notNullColumns = |
|
976 |
new ArrayList<ShellFolderColumnInfo>(); |
|
977 |
for (int i = 0; i < columns.length; i++) { |
|
978 |
ShellFolderColumnInfo column = columns[i]; |
|
979 |
if (column != null) { |
|
980 |
column.setAlignment(column.getAlignment() == LVCFMT_RIGHT |
|
981 |
? SwingConstants.RIGHT |
|
982 |
: column.getAlignment() == LVCFMT_CENTER |
|
983 |
? SwingConstants.CENTER |
|
984 |
: SwingConstants.LEADING); |
|
985 |
||
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
986 |
column.setComparator(new ColumnComparator(getIShellFolder(), i)); |
2 | 987 |
|
988 |
notNullColumns.add(column); |
|
989 |
} |
|
990 |
} |
|
991 |
columns = new ShellFolderColumnInfo[notNullColumns.size()]; |
|
992 |
notNullColumns.toArray(columns); |
|
993 |
} |
|
994 |
return columns; |
|
995 |
} |
|
996 |
||
997 |
public Object getFolderColumnValue(int column) { |
|
998 |
return doGetColumnValue(getParentIShellFolder(), getRelativePIDL(), column); |
|
999 |
} |
|
1000 |
||
1001 |
private native ShellFolderColumnInfo[] doGetColumnInfo(long iShellFolder2); |
|
1002 |
||
1003 |
private native Object doGetColumnValue(long parentIShellFolder2, long childPIDL, int columnIdx); |
|
1004 |
||
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1005 |
private static native int compareIDsByColumn(long pParentIShellFolder, long pidl1, long pidl2, int columnIdx); |
2 | 1006 |
|
1007 |
||
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1008 |
public void sortChildren(List<? extends File> files) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1009 |
Collections.sort(files, new ColumnComparator(getIShellFolder(), 0)); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1010 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1011 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1012 |
private static class ColumnComparator implements Comparator<File> { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1013 |
private final long parentIShellFolder; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1014 |
|
2 | 1015 |
private final int columnIdx; |
1016 |
||
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1017 |
public ColumnComparator(long parentIShellFolder, int columnIdx) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1018 |
this.parentIShellFolder = parentIShellFolder; |
2 | 1019 |
this.columnIdx = columnIdx; |
1020 |
} |
|
1021 |
||
1022 |
// compares 2 objects within this folder by the specified column |
|
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1023 |
public int compare(File o, File o1) { |
2 | 1024 |
if (o instanceof Win32ShellFolder2 |
1025 |
&& o1 instanceof Win32ShellFolder2) { |
|
1026 |
// delegates comparison to native method |
|
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
454
diff
changeset
|
1027 |
return compareIDsByColumn(parentIShellFolder, |
2 | 1028 |
((Win32ShellFolder2) o).getRelativePIDL(), |
1029 |
((Win32ShellFolder2) o1).getRelativePIDL(), |
|
1030 |
columnIdx); |
|
1031 |
} |
|
1032 |
return 0; |
|
1033 |
} |
|
1034 |
} |
|
1035 |
||
1036 |
} |