| Method from javax.swing.filechooser.FileSystemView Detail: |
public File createFileObject(String path) {
File f = new File(path);
if (isFileSystemRoot(f)) {
f = createFileSystemRoot(f);
}
return f;
}
Returns a File object constructed from the given path string. |
public File createFileObject(File dir,
String filename) {
if(dir == null) {
return new File(filename);
} else {
return new File(dir, filename);
}
}
Returns a File object constructed in dir from the given filename. |
protected File createFileSystemRoot(File f) {
return new FileSystemRoot(f);
}
Creates a new File object for f with correct
behavior for a file system root directory. |
abstract public File createNewFolder(File containingDir) throws IOException
Creates a new folder with a default folder name. |
public File getChild(File parent,
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 File getDefaultDirectory() {
File f = (File)ShellFolder.get("fileChooserDefaultFolder");
if (isFileSystemRoot(f)) {
f = createFileSystemRoot(f);
}
return f;
}
Return the user's default starting directory for the file chooser. |
public static FileSystemView getFileSystemView() {
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 File[] getFiles(File dir,
boolean useFileHiding) {
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()]);
}
Gets the list of shown (i.e. not hidden) files. |
public File getHomeDirectory() {
return createFileObject(System.getProperty("user.home"));
}
|
public File getParentDirectory(File 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;
}
Returns the parent directory of dir. |
public File[] getRoots() {
// 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;
}
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. |
ShellFolder getShellFolder(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 String getSystemDisplayName(File f) {
String name = null;
if (f != null) {
name = f.getName();
if (!name.equals("..") && !name.equals(".") &&
(useSystemExtensionHiding ||
!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;
}
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. |
public Icon getSystemIcon(File f) {
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;
}
}
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. |
public String getSystemTypeDescription(File f) {
return null;
}
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. |
public boolean isComputerNode(File dir) {
return ShellFolder.isComputerNode(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. |
public boolean isDrive(File dir) {
return false;
}
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. |
public boolean isFileSystem(File f) {
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;
}
}
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. |
public boolean isFileSystemRoot(File dir) {
return ShellFolder.isFileSystemRoot(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. |
public boolean isFloppyDrive(File dir) {
return false;
}
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. |
public boolean isHiddenFile(File f) {
return f.isHidden();
}
Returns whether a file is hidden or not. |
public boolean isParent(File folder,
File file) {
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());
}
}
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(). |
public boolean isRoot(File f) {
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;
}
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. |
public Boolean isTraversable(File f) {
return Boolean.valueOf(f.isDirectory());
}
Returns true if the file (directory) can be visited.
Returns false if the directory cannot be traversed. |