author | rupashka |
Wed, 04 Jun 2008 18:48:42 +0400 | |
changeset 678 | 7d331a53a753 |
parent 2 | 90ce3da70b43 |
child 715 | f16baef3a20e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. |
|
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 |
||
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
28 |
import javax.swing.*; |
2 | 29 |
import java.awt.Image; |
30 |
import java.awt.Toolkit; |
|
31 |
import java.io.*; |
|
32 |
import java.io.FileNotFoundException; |
|
33 |
import java.util.*; |
|
34 |
||
35 |
/** |
|
36 |
* @author Michael Martak |
|
37 |
* @since 1.4 |
|
38 |
*/ |
|
39 |
||
40 |
public abstract class ShellFolder extends File { |
|
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
41 |
private static final String COLUMN_NAME = "FileChooser.fileNameHeaderText"; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
42 |
private static final String COLUMN_SIZE = "FileChooser.fileSizeHeaderText"; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
43 |
private static final String COLUMN_DATE = "FileChooser.fileDateHeaderText"; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
44 |
|
2 | 45 |
protected ShellFolder parent; |
46 |
||
47 |
/** |
|
48 |
* Create a file system shell folder from a file |
|
49 |
*/ |
|
50 |
ShellFolder(ShellFolder parent, String pathname) { |
|
51 |
super((pathname != null) ? pathname : "ShellFolder"); |
|
52 |
this.parent = parent; |
|
53 |
} |
|
54 |
||
55 |
/** |
|
56 |
* @return Whether this is a file system shell folder |
|
57 |
*/ |
|
58 |
public boolean isFileSystem() { |
|
59 |
return (!getPath().startsWith("ShellFolder")); |
|
60 |
} |
|
61 |
||
62 |
/** |
|
63 |
* This method must be implemented to make sure that no instances |
|
64 |
* of <code>ShellFolder</code> are ever serialized. If <code>isFileSystem()</code> returns |
|
65 |
* <code>true</code>, then the object should be representable with an instance of |
|
66 |
* <code>java.io.File</code> instead. If not, then the object is most likely |
|
67 |
* depending on some internal (native) state and cannot be serialized. |
|
68 |
* |
|
69 |
* @returns a <code>java.io.File</code> replacement object, or <code>null</code> |
|
70 |
* if no suitable replacement can be found. |
|
71 |
*/ |
|
72 |
protected abstract Object writeReplace() throws java.io.ObjectStreamException; |
|
73 |
||
74 |
/** |
|
75 |
* Returns the path for this object's parent, |
|
76 |
* or <code>null</code> if this object does not name a parent |
|
77 |
* folder. |
|
78 |
* |
|
79 |
* @return the path as a String for this object's parent, |
|
80 |
* or <code>null</code> if this object does not name a parent |
|
81 |
* folder |
|
82 |
* |
|
83 |
* @see java.io.File#getParent() |
|
84 |
* @since 1.4 |
|
85 |
*/ |
|
86 |
public String getParent() { |
|
87 |
if (parent == null && isFileSystem()) { |
|
88 |
return super.getParent(); |
|
89 |
} |
|
90 |
if (parent != null) { |
|
91 |
return (parent.getPath()); |
|
92 |
} else { |
|
93 |
return null; |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
/** |
|
98 |
* Returns a File object representing this object's parent, |
|
99 |
* or <code>null</code> if this object does not name a parent |
|
100 |
* folder. |
|
101 |
* |
|
102 |
* @return a File object representing this object's parent, |
|
103 |
* or <code>null</code> if this object does not name a parent |
|
104 |
* folder |
|
105 |
* |
|
106 |
* @see java.io.File#getParentFile() |
|
107 |
* @since 1.4 |
|
108 |
*/ |
|
109 |
public File getParentFile() { |
|
110 |
if (parent != null) { |
|
111 |
return parent; |
|
112 |
} else if (isFileSystem()) { |
|
113 |
return super.getParentFile(); |
|
114 |
} else { |
|
115 |
return null; |
|
116 |
} |
|
117 |
} |
|
118 |
||
119 |
public File[] listFiles() { |
|
120 |
return listFiles(true); |
|
121 |
} |
|
122 |
||
123 |
public File[] listFiles(boolean includeHiddenFiles) { |
|
124 |
File[] files = super.listFiles(); |
|
125 |
||
126 |
if (!includeHiddenFiles) { |
|
127 |
Vector v = new Vector(); |
|
128 |
int nameCount = (files == null) ? 0 : files.length; |
|
129 |
for (int i = 0; i < nameCount; i++) { |
|
130 |
if (!files[i].isHidden()) { |
|
131 |
v.addElement(files[i]); |
|
132 |
} |
|
133 |
} |
|
134 |
files = (File[])v.toArray(new File[v.size()]); |
|
135 |
} |
|
136 |
||
137 |
return files; |
|
138 |
} |
|
139 |
||
140 |
||
141 |
/** |
|
142 |
* @return Whether this shell folder is a link |
|
143 |
*/ |
|
144 |
public abstract boolean isLink(); |
|
145 |
||
146 |
/** |
|
147 |
* @return The shell folder linked to by this shell folder, or null |
|
148 |
* if this shell folder is not a link |
|
149 |
*/ |
|
150 |
public abstract ShellFolder getLinkLocation() throws FileNotFoundException; |
|
151 |
||
152 |
/** |
|
153 |
* @return The name used to display this shell folder |
|
154 |
*/ |
|
155 |
public abstract String getDisplayName(); |
|
156 |
||
157 |
/** |
|
158 |
* @return The type of shell folder as a string |
|
159 |
*/ |
|
160 |
public abstract String getFolderType(); |
|
161 |
||
162 |
/** |
|
163 |
* @return The executable type as a string |
|
164 |
*/ |
|
165 |
public abstract String getExecutableType(); |
|
166 |
||
167 |
/** |
|
168 |
* Compares this ShellFolder with the specified ShellFolder for order. |
|
169 |
* |
|
170 |
* @see #compareTo(Object) |
|
171 |
*/ |
|
172 |
public int compareTo(File file2) { |
|
173 |
if (file2 == null || !(file2 instanceof ShellFolder) |
|
174 |
|| ((file2 instanceof ShellFolder) && ((ShellFolder)file2).isFileSystem())) { |
|
175 |
||
176 |
if (isFileSystem()) { |
|
177 |
return super.compareTo(file2); |
|
178 |
} else { |
|
179 |
return -1; |
|
180 |
} |
|
181 |
} else { |
|
182 |
if (isFileSystem()) { |
|
183 |
return 1; |
|
184 |
} else { |
|
185 |
return getName().compareTo(file2.getName()); |
|
186 |
} |
|
187 |
} |
|
188 |
} |
|
189 |
||
190 |
/** |
|
191 |
* @param getLargeIcon whether to return large icon (ignored in base implementation) |
|
192 |
* @return The icon used to display this shell folder |
|
193 |
*/ |
|
194 |
public Image getIcon(boolean getLargeIcon) { |
|
195 |
return null; |
|
196 |
} |
|
197 |
||
198 |
||
199 |
// Static |
|
200 |
||
201 |
private static ShellFolderManager shellFolderManager; |
|
202 |
||
203 |
static { |
|
204 |
Class managerClass = (Class)Toolkit.getDefaultToolkit(). |
|
205 |
getDesktopProperty("Shell.shellFolderManager"); |
|
206 |
if (managerClass == null) { |
|
207 |
managerClass = ShellFolderManager.class; |
|
208 |
} |
|
209 |
try { |
|
210 |
shellFolderManager = |
|
211 |
(ShellFolderManager)managerClass.newInstance(); |
|
212 |
} catch (InstantiationException e) { |
|
213 |
throw new Error("Could not instantiate Shell Folder Manager: " |
|
214 |
+ managerClass.getName()); |
|
215 |
} catch (IllegalAccessException e) { |
|
216 |
throw new Error ("Could not access Shell Folder Manager: " |
|
217 |
+ managerClass.getName()); |
|
218 |
} |
|
219 |
} |
|
220 |
||
221 |
/** |
|
222 |
* Return a shell folder from a file object |
|
223 |
* @exception FileNotFoundException if file does not exist |
|
224 |
*/ |
|
225 |
public static ShellFolder getShellFolder(File file) throws FileNotFoundException { |
|
226 |
if (file instanceof ShellFolder) { |
|
227 |
return (ShellFolder)file; |
|
228 |
} |
|
229 |
if (!file.exists()) { |
|
230 |
throw new FileNotFoundException(); |
|
231 |
} |
|
232 |
return shellFolderManager.createShellFolder(file); |
|
233 |
} |
|
234 |
||
235 |
/** |
|
236 |
* @param key a <code>String</code> |
|
237 |
* @return An Object matching the string <code>key</code>. |
|
238 |
* @see ShellFolderManager#get(String) |
|
239 |
*/ |
|
240 |
public static Object get(String key) { |
|
241 |
return shellFolderManager.get(key); |
|
242 |
} |
|
243 |
||
244 |
/** |
|
245 |
* Does <code>dir</code> represent a "computer" such as a node on the network, or |
|
246 |
* "My Computer" on the desktop. |
|
247 |
*/ |
|
248 |
public static boolean isComputerNode(File dir) { |
|
249 |
return shellFolderManager.isComputerNode(dir); |
|
250 |
} |
|
251 |
||
252 |
/** |
|
253 |
* @return Whether this is a file system root directory |
|
254 |
*/ |
|
255 |
public static boolean isFileSystemRoot(File dir) { |
|
256 |
return shellFolderManager.isFileSystemRoot(dir); |
|
257 |
} |
|
258 |
||
259 |
/** |
|
260 |
* Canonicalizes files that don't have symbolic links in their path. |
|
261 |
* Normalizes files that do, preserving symbolic links from being resolved. |
|
262 |
*/ |
|
263 |
public static File getNormalizedFile(File f) throws IOException { |
|
264 |
File canonical = f.getCanonicalFile(); |
|
265 |
if (f.equals(canonical)) { |
|
266 |
// path of f doesn't contain symbolic links |
|
267 |
return canonical; |
|
268 |
} |
|
269 |
||
270 |
// preserve symbolic links from being resolved |
|
271 |
return new File(f.toURI().normalize()); |
|
272 |
} |
|
273 |
||
274 |
// Override File methods |
|
275 |
||
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
276 |
public static void sort(List<? extends File> files) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
277 |
if (files == null || files.size() <= 1) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
278 |
return; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
279 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
280 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
281 |
// Check that we can use the ShellFolder.sortChildren() method: |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
282 |
// 1. All files have the same non-null parent |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
283 |
// 2. All files is ShellFolders |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
284 |
File commonParent = null; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
285 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
286 |
for (File file : files) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
287 |
File parent = file.getParentFile(); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
288 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
289 |
if (parent == null || !(file instanceof ShellFolder)) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
290 |
commonParent = null; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
291 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
292 |
break; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
293 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
294 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
295 |
if (commonParent == null) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
296 |
commonParent = parent; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
297 |
} else { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
298 |
if (commonParent != parent && !commonParent.equals(parent)) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
299 |
commonParent = null; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
300 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
301 |
break; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
302 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
303 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
304 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
305 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
306 |
if (commonParent instanceof ShellFolder) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
307 |
((ShellFolder) commonParent).sortChildren(files); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
308 |
} else { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
309 |
Collections.sort(files, FILE_COMPARATOR); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
310 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
311 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
312 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
313 |
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:
2
diff
changeset
|
314 |
Collections.sort(files, FILE_COMPARATOR); |
2 | 315 |
} |
316 |
||
317 |
public boolean isAbsolute() { |
|
318 |
return (!isFileSystem() || super.isAbsolute()); |
|
319 |
} |
|
320 |
||
321 |
public File getAbsoluteFile() { |
|
322 |
return (isFileSystem() ? super.getAbsoluteFile() : this); |
|
323 |
} |
|
324 |
||
325 |
public boolean canRead() { |
|
326 |
return (isFileSystem() ? super.canRead() : true); // ((Fix?)) |
|
327 |
} |
|
328 |
||
329 |
/** |
|
330 |
* Returns true if folder allows creation of children. |
|
331 |
* True for the "Desktop" folder, but false for the "My Computer" |
|
332 |
* folder. |
|
333 |
*/ |
|
334 |
public boolean canWrite() { |
|
335 |
return (isFileSystem() ? super.canWrite() : false); // ((Fix?)) |
|
336 |
} |
|
337 |
||
338 |
public boolean exists() { |
|
339 |
// Assume top-level drives exist, because state is uncertain for |
|
340 |
// removable drives. |
|
341 |
return (!isFileSystem() || isFileSystemRoot(this) || super.exists()) ; |
|
342 |
} |
|
343 |
||
344 |
public boolean isDirectory() { |
|
345 |
return (isFileSystem() ? super.isDirectory() : true); // ((Fix?)) |
|
346 |
} |
|
347 |
||
348 |
public boolean isFile() { |
|
349 |
return (isFileSystem() ? super.isFile() : !isDirectory()); // ((Fix?)) |
|
350 |
} |
|
351 |
||
352 |
public long lastModified() { |
|
353 |
return (isFileSystem() ? super.lastModified() : 0L); // ((Fix?)) |
|
354 |
} |
|
355 |
||
356 |
public long length() { |
|
357 |
return (isFileSystem() ? super.length() : 0L); // ((Fix?)) |
|
358 |
} |
|
359 |
||
360 |
public boolean createNewFile() throws IOException { |
|
361 |
return (isFileSystem() ? super.createNewFile() : false); |
|
362 |
} |
|
363 |
||
364 |
public boolean delete() { |
|
365 |
return (isFileSystem() ? super.delete() : false); // ((Fix?)) |
|
366 |
} |
|
367 |
||
368 |
public void deleteOnExit() { |
|
369 |
if (isFileSystem()) { |
|
370 |
super.deleteOnExit(); |
|
371 |
} else { |
|
372 |
// Do nothing // ((Fix?)) |
|
373 |
} |
|
374 |
} |
|
375 |
||
376 |
public boolean mkdir() { |
|
377 |
return (isFileSystem() ? super.mkdir() : false); |
|
378 |
} |
|
379 |
||
380 |
public boolean mkdirs() { |
|
381 |
return (isFileSystem() ? super.mkdirs() : false); |
|
382 |
} |
|
383 |
||
384 |
public boolean renameTo(File dest) { |
|
385 |
return (isFileSystem() ? super.renameTo(dest) : false); // ((Fix?)) |
|
386 |
} |
|
387 |
||
388 |
public boolean setLastModified(long time) { |
|
389 |
return (isFileSystem() ? super.setLastModified(time) : false); // ((Fix?)) |
|
390 |
} |
|
391 |
||
392 |
public boolean setReadOnly() { |
|
393 |
return (isFileSystem() ? super.setReadOnly() : false); // ((Fix?)) |
|
394 |
} |
|
395 |
||
396 |
public String toString() { |
|
397 |
return (isFileSystem() ? super.toString() : getDisplayName()); |
|
398 |
} |
|
399 |
||
400 |
public static ShellFolderColumnInfo[] getFolderColumns(File dir) { |
|
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
401 |
ShellFolderColumnInfo[] columns = null; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
402 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
403 |
if (dir instanceof ShellFolder) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
404 |
columns = ((ShellFolder) dir).getFolderColumns(); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
405 |
} |
2 | 406 |
|
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
407 |
if (columns == null) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
408 |
columns = new ShellFolderColumnInfo[]{ |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
409 |
new ShellFolderColumnInfo(COLUMN_NAME, 150, |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
410 |
SwingConstants.LEADING, true, null, |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
411 |
FILE_COMPARATOR), |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
412 |
new ShellFolderColumnInfo(COLUMN_SIZE, 75, |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
413 |
SwingConstants.RIGHT, true, null, |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
414 |
DEFAULT_COMPARATOR, true), |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
415 |
new ShellFolderColumnInfo(COLUMN_DATE, 130, |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
416 |
SwingConstants.LEADING, true, null, |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
417 |
DEFAULT_COMPARATOR, true) |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
418 |
}; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
419 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
420 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
421 |
return columns; |
2 | 422 |
} |
423 |
||
424 |
public ShellFolderColumnInfo[] getFolderColumns() { |
|
425 |
return null; |
|
426 |
} |
|
427 |
||
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
428 |
public static Object getFolderColumnValue(File file, int column) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
429 |
if (file instanceof ShellFolder) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
430 |
Object value = ((ShellFolder)file).getFolderColumnValue(column); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
431 |
if (value != null) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
432 |
return value; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
433 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
434 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
435 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
436 |
if (file == null || !file.exists()) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
437 |
return null; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
438 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
439 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
440 |
switch (column) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
441 |
case 0: |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
442 |
// By default, file name will be rendered using getSystemDisplayName() |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
443 |
return file; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
444 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
445 |
case 1: // size |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
446 |
return file.isDirectory() ? null : Long.valueOf(file.length()); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
447 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
448 |
case 2: // date |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
449 |
if (isFileSystemRoot(file)) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
450 |
return null; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
451 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
452 |
long time = file.lastModified(); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
453 |
return (time == 0L) ? null : new Date(time); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
454 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
455 |
default: |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
456 |
return null; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
457 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
458 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
459 |
|
2 | 460 |
public Object getFolderColumnValue(int column) { |
461 |
return null; |
|
462 |
} |
|
678
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
463 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
464 |
/** |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
465 |
* Provides a default comparator for the default column set |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
466 |
*/ |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
467 |
private static final Comparator DEFAULT_COMPARATOR = new Comparator() { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
468 |
public int compare(Object o1, Object o2) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
469 |
int gt; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
470 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
471 |
if (o1 == null && o2 == null) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
472 |
gt = 0; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
473 |
} else if (o1 != null && o2 == null) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
474 |
gt = 1; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
475 |
} else if (o1 == null && o2 != null) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
476 |
gt = -1; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
477 |
} else if (o1 instanceof Comparable) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
478 |
gt = ((Comparable) o1).compareTo(o2); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
479 |
} else { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
480 |
gt = 0; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
481 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
482 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
483 |
return gt; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
484 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
485 |
}; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
486 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
487 |
private static final Comparator<File> FILE_COMPARATOR = new Comparator<File>() { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
488 |
public int compare(File f1, File f2) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
489 |
ShellFolder sf1 = null; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
490 |
ShellFolder sf2 = null; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
491 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
492 |
if (f1 instanceof ShellFolder) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
493 |
sf1 = (ShellFolder) f1; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
494 |
if (sf1.isFileSystem()) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
495 |
sf1 = null; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
496 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
497 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
498 |
if (f2 instanceof ShellFolder) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
499 |
sf2 = (ShellFolder) f2; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
500 |
if (sf2.isFileSystem()) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
501 |
sf2 = null; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
502 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
503 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
504 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
505 |
if (sf1 != null && sf2 != null) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
506 |
return sf1.compareTo(sf2); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
507 |
} else if (sf1 != null) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
508 |
// Non-file shellfolders sort before files |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
509 |
return -1; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
510 |
} else if (sf2 != null) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
511 |
return 1; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
512 |
} else { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
513 |
String name1 = f1.getName(); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
514 |
String name2 = f2.getName(); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
515 |
|
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
516 |
// First ignore case when comparing |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
517 |
int diff = name1.compareToIgnoreCase(name2); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
518 |
if (diff != 0) { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
519 |
return diff; |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
520 |
} else { |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
521 |
// May differ in case (e.g. "mail" vs. "Mail") |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
522 |
// We need this test for consistent sorting |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
523 |
return name1.compareTo(name2); |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
524 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
525 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
526 |
} |
7d331a53a753
6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents:
2
diff
changeset
|
527 |
}; |
2 | 528 |
} |