2
|
1 |
/*
|
715
|
2 |
* Copyright 2000-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.io.File;
|
|
29 |
import java.io.FileNotFoundException;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* @author Michael Martak
|
|
33 |
* @since 1.4
|
|
34 |
*/
|
|
35 |
|
|
36 |
class ShellFolderManager {
|
|
37 |
/**
|
|
38 |
* Create a shell folder from a file.
|
|
39 |
* Override to return machine-dependent behavior.
|
|
40 |
*/
|
|
41 |
public ShellFolder createShellFolder(File file) throws FileNotFoundException {
|
|
42 |
return new DefaultShellFolder(null, file);
|
|
43 |
}
|
|
44 |
|
|
45 |
/**
|
|
46 |
* @param key a <code>String</code>
|
|
47 |
* "fileChooserDefaultFolder":
|
|
48 |
* Returns a <code>File</code> - the default shellfolder for a new filechooser
|
|
49 |
* "roots":
|
|
50 |
* Returns a <code>File[]</code> - containing the root(s) of the displayable hieararchy
|
|
51 |
* "fileChooserComboBoxFolders":
|
|
52 |
* Returns a <code>File[]</code> - an array of shellfolders representing the list to
|
|
53 |
* show by default in the file chooser's combobox
|
|
54 |
* "fileChooserShortcutPanelFolders":
|
|
55 |
* Returns a <code>File[]</code> - an array of shellfolders representing well-known
|
|
56 |
* folders, such as Desktop, Documents, History, Network, Home, etc.
|
|
57 |
* This is used in the shortcut panel of the filechooser on Windows 2000
|
|
58 |
* and Windows Me.
|
|
59 |
* "fileChooserIcon nn":
|
|
60 |
* Returns an <code>Image</code> - icon nn from resource 124 in comctl32.dll (Windows only).
|
|
61 |
*
|
|
62 |
* @return An Object matching the key string.
|
|
63 |
*/
|
|
64 |
public Object get(String key) {
|
|
65 |
if (key.equals("fileChooserDefaultFolder")) {
|
|
66 |
// Return the default shellfolder for a new filechooser
|
|
67 |
File homeDir = new File(System.getProperty("user.home"));
|
|
68 |
try {
|
|
69 |
return createShellFolder(homeDir);
|
|
70 |
} catch (FileNotFoundException e) {
|
|
71 |
return homeDir;
|
|
72 |
}
|
|
73 |
} else if (key.equals("roots")) {
|
|
74 |
// The root(s) of the displayable hieararchy
|
|
75 |
return File.listRoots();
|
|
76 |
} else if (key.equals("fileChooserComboBoxFolders")) {
|
|
77 |
// Return an array of ShellFolders representing the list to
|
|
78 |
// show by default in the file chooser's combobox
|
|
79 |
return get("roots");
|
|
80 |
} else if (key.equals("fileChooserShortcutPanelFolders")) {
|
|
81 |
// Return an array of ShellFolders representing well-known
|
|
82 |
// folders, such as Desktop, Documents, History, Network, Home, etc.
|
|
83 |
// This is used in the shortcut panel of the filechooser on Windows 2000
|
|
84 |
// and Windows Me
|
|
85 |
return new File[] { (File)get("fileChooserDefaultFolder") };
|
|
86 |
}
|
|
87 |
return null;
|
|
88 |
}
|
|
89 |
|
|
90 |
/**
|
|
91 |
* Does <code>dir</code> represent a "computer" such as a node on the network, or
|
|
92 |
* "My Computer" on the desktop.
|
|
93 |
*/
|
|
94 |
public boolean isComputerNode(File dir) {
|
|
95 |
return false;
|
|
96 |
}
|
|
97 |
|
|
98 |
public boolean isFileSystemRoot(File dir) {
|
|
99 |
if (dir instanceof ShellFolder && !((ShellFolder)dir).isFileSystem()) {
|
|
100 |
return false;
|
|
101 |
}
|
|
102 |
return (dir.getParentFile() == null);
|
|
103 |
}
|
|
104 |
}
|