Methods Summary |
---|
public java.io.File | createFileObject(java.io.File dir, java.lang.String filename)Returns a File object constructed in dir from the given filename.
if(dir == null) {
return new File(filename);
} else {
return new File(dir, filename);
}
|
public java.io.File | createFileObject(java.lang.String path)Returns a File object constructed from the given path string.
File f = new File(path);
if (isFileSystemRoot(f)) {
f = createFileSystemRoot(f);
}
return f;
|
protected java.io.File | createFileSystemRoot(java.io.File f)Creates a new File object for f with correct
behavior for a file system root directory.
return new FileSystemRoot(f);
|
public abstract java.io.File | createNewFolder(java.io.File containingDir)Creates a new folder with a default folder name.
|
public java.io.File | getChild(java.io.File parent, java.lang.String fileName)
if (parent instanceof ShellFolder) {
File[] children = getFiles(parent, false);
for (int i = 0; i < children.length; i++) {
if (children[i].getName().equals(fileName)) {
return children[i];
}
}
}
return createFileObject(parent, fileName);
|
public java.io.File | getDefaultDirectory()Return the user's default starting directory for the file chooser.
File f = (File)ShellFolder.get("fileChooserDefaultFolder");
if (isFileSystemRoot(f)) {
f = createFileSystemRoot(f);
}
return f;
|
public static javax.swing.filechooser.FileSystemView | getFileSystemView()
useSystemExtensionsHiding = UIManager.getDefaults().getBoolean("FileChooser.useSystemExtensionHiding");
UIManager.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
if (e.getPropertyName().equals("lookAndFeel")) {
useSystemExtensionsHiding = UIManager.getDefaults().getBoolean("FileChooser.useSystemExtensionHiding");
}
}
});
if(File.separatorChar == '\\") {
if(windowsFileSystemView == null) {
windowsFileSystemView = new WindowsFileSystemView();
}
return windowsFileSystemView;
}
if(File.separatorChar == '/") {
if(unixFileSystemView == null) {
unixFileSystemView = new UnixFileSystemView();
}
return unixFileSystemView;
}
// if(File.separatorChar == ':') {
// if(macFileSystemView == null) {
// macFileSystemView = new MacFileSystemView();
// }
// return macFileSystemView;
//}
if(genericFileSystemView == null) {
genericFileSystemView = new GenericFileSystemView();
}
return genericFileSystemView;
|
public java.io.File[] | getFiles(java.io.File dir, boolean useFileHiding)Gets the list of shown (i.e. not hidden) files.
Vector files = new Vector();
// add all files in dir
File[] names;
if (!(dir instanceof ShellFolder)) {
dir = getShellFolder(dir);
}
names = ((ShellFolder)dir).listFiles(!useFileHiding);
File f;
int nameCount = (names == null) ? 0 : names.length;
for (int i = 0; i < nameCount; i++) {
if (Thread.currentThread().isInterrupted()) {
break;
}
f = names[i];
if (!(f instanceof ShellFolder)) {
if (isFileSystemRoot(f)) {
f = createFileSystemRoot(f);
}
try {
f = ShellFolder.getShellFolder(f);
} catch (FileNotFoundException e) {
// Not a valid file (wouldn't show in native file chooser)
// Example: C:\pagefile.sys
continue;
} catch (InternalError e) {
// Not a valid file (wouldn't show in native file chooser)
// Example C:\Winnt\Profiles\joe\history\History.IE5
continue;
}
}
if (!useFileHiding || !isHiddenFile(f)) {
files.addElement(f);
}
}
return (File[])files.toArray(new File[files.size()]);
|
public java.io.File | getHomeDirectory()
return createFileObject(System.getProperty("user.home"));
|
public java.io.File | getParentDirectory(java.io.File dir)Returns the parent directory of dir .
if (dir != null && dir.exists()) {
ShellFolder sf = getShellFolder(dir);
File psf = sf.getParentFile();
if (psf != null) {
if (isFileSystem(psf)) {
File f = psf;
if (f != null && !f.exists()) {
// This could be a node under "Network Neighborhood".
File ppsf = psf.getParentFile();
if (ppsf == null || !isFileSystem(ppsf)) {
// We're mostly after the exists() override for windows below.
f = createFileSystemRoot(f);
}
}
return f;
} else {
return psf;
}
}
}
return null;
|
public java.io.File[] | getRoots()Returns all root partitions on this system. For example, on
Windows, this would be the "Desktop" folder, while on DOS this
would be the A: through Z: drives.
// Don't cache this array, because filesystem might change
File[] roots = (File[])ShellFolder.get("roots");
for (int i = 0; i < roots.length; i++) {
if (isFileSystemRoot(roots[i])) {
roots[i] = createFileSystemRoot(roots[i]);
}
}
return roots;
|
sun.awt.shell.ShellFolder | getShellFolder(java.io.File f)
if (!(f instanceof ShellFolder)
&& !(f instanceof FileSystemRoot)
&& isFileSystemRoot(f)) {
f = createFileSystemRoot(f);
}
try {
return ShellFolder.getShellFolder(f);
} catch (FileNotFoundException e) {
System.err.println("FileSystemView.getShellFolder: f="+f);
e.printStackTrace();
return null;
} catch (InternalError e) {
System.err.println("FileSystemView.getShellFolder: f="+f);
e.printStackTrace();
return null;
}
|
public java.lang.String | getSystemDisplayName(java.io.File f)Name of a file, directory, or folder as it would be displayed in
a system file browser. Example from Windows: the "M:\" directory
displays as "CD-ROM (M:)"
The default implementation gets information from the ShellFolder class.
String name = null;
if (f != null) {
name = f.getName();
if (!name.equals("..") && !name.equals(".") &&
(useSystemExtensionsHiding ||
!isFileSystem(f) ||
isFileSystemRoot(f)) &&
((f instanceof ShellFolder) ||
f.exists())) {
name = getShellFolder(f).getDisplayName();
if (name == null || name.length() == 0) {
name = f.getPath(); // e.g. "/"
}
}
}
return name;
|
public javax.swing.Icon | getSystemIcon(java.io.File f)Icon for a file, directory, or folder as it would be displayed in
a system file browser. Example from Windows: the "M:\" directory
displays a CD-ROM icon.
The default implementation gets information from the ShellFolder class.
if (f != null) {
ShellFolder sf = getShellFolder(f);
Image img = sf.getIcon(false);
if (img != null) {
return new ImageIcon(img, sf.getFolderType());
} else {
return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
}
} else {
return null;
}
|
public java.lang.String | getSystemTypeDescription(java.io.File f)Type description for a file, directory, or folder as it would be displayed in
a system file browser. Example from Windows: the "Desktop" folder
is desribed as "Desktop".
Override for platforms with native ShellFolder implementations.
return null;
|
public boolean | isComputerNode(java.io.File dir)Used by UI classes to decide whether to display a special icon
for a computer node, e.g. "My Computer" or a network server.
The default implementation has no way of knowing, so always returns false.
return ShellFolder.isComputerNode(dir);
|
public boolean | isDrive(java.io.File dir)Used by UI classes to decide whether to display a special icon
for drives or partitions, e.g. a "hard disk" icon.
The default implementation has no way of knowing, so always returns false.
return false;
|
public boolean | isFileSystem(java.io.File f)Checks if f represents a real directory or file as opposed to a
special folder such as "Desktop" . Used by UI classes to decide if
a folder is selectable when doing directory choosing.
if (f instanceof ShellFolder) {
ShellFolder sf = (ShellFolder)f;
// Shortcuts to directories are treated as not being file system objects,
// so that they are never returned by JFileChooser.
return sf.isFileSystem() && !(sf.isLink() && sf.isDirectory());
} else {
return true;
}
|
public boolean | isFileSystemRoot(java.io.File dir)Is dir the root of a tree in the file system, such as a drive
or partition. Example: Returns true for "C:\" on Windows 98.
return ShellFolder.isFileSystemRoot(dir);
|
public boolean | isFloppyDrive(java.io.File dir)Used by UI classes to decide whether to display a special icon
for a floppy disk. Implies isDrive(dir).
The default implementation has no way of knowing, so always returns false.
return false;
|
public boolean | isHiddenFile(java.io.File f)Returns whether a file is hidden or not.
return f.isHidden();
|
public boolean | isParent(java.io.File folder, java.io.File file)On Windows, a file can appear in multiple folders, other than its
parent directory in the filesystem. Folder could for example be the
"Desktop" folder which is not the same as file.getParentFile().
if (folder == null || file == null) {
return false;
} else if (folder instanceof ShellFolder) {
File parent = file.getParentFile();
if (parent != null && parent.equals(folder)) {
return true;
}
File[] children = getFiles(folder, false);
for (int i = 0; i < children.length; i++) {
if (file.equals(children[i])) {
return true;
}
}
return false;
} else {
return folder.equals(file.getParentFile());
}
|
public boolean | isRoot(java.io.File f)Determines if the given file is a root in the navigatable tree(s).
Examples: Windows 98 has one root, the Desktop folder. DOS has one root
per drive letter, C:\ , D:\ , etc. Unix has one root,
the "/" directory.
The default implementation gets information from the ShellFolder class.
if (f == null || !f.isAbsolute()) {
return false;
}
File[] roots = getRoots();
for (int i = 0; i < roots.length; i++) {
if (roots[i].equals(f)) {
return true;
}
}
return false;
|
public java.lang.Boolean | isTraversable(java.io.File f)Returns true if the file (directory) can be visited.
Returns false if the directory cannot be traversed.
return Boolean.valueOf(f.isDirectory());
|