/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* FileSystemView is JFileChooser's gateway to the
* file system. Since the JDK1.1 File API doesn't allow
* access to such information as root partitions, file type
* information, or hidden file bits, this class is designed
* to intuit as much OS-specific file system information as
* possible.
*
* <p>
*
* Java Licensees may want to provide a different implementation of
* FileSystemView to better handle a given operating system.
*
* @author Jeff Dinkins
*/
// PENDING(jeff) - need to provide a specification for
// to handle their particular type of file system.
public abstract class FileSystemView {
//static FileSystemView macFileSystemView = null;
private boolean useSystemExtensionHiding =
if(windowsFileSystemView == null) {
}
return windowsFileSystemView;
}
if(unixFileSystemView == null) {
unixFileSystemView = new UnixFileSystemView();
}
return unixFileSystemView;
}
// if(File.separatorChar == ':') {
// if(macFileSystemView == null) {
// macFileSystemView = new MacFileSystemView();
// }
// return macFileSystemView;
//}
if(genericFileSystemView == null) {
}
return genericFileSystemView;
}
public FileSystemView() {
if (fileSystemView == null) {
// FileSystemView was destroyed
} else {
}
}
}
});
}
/**
* 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, <code>C:\</code>, <code>D:\</code>, etc. Unix has one root,
* the <code>"/"</code> directory.
*
* The default implementation gets information from the <code>ShellFolder</code> class.
*
* @param f a <code>File</code> object representing a directory
* @return <code>true</code> if <code>f</code> is a root in the navigatable tree.
* @see #isFileSystemRoot
*/
if (f == null || !f.isAbsolute()) {
return false;
}
return true;
}
}
return false;
}
/**
* Returns true if the file (directory) can be visited.
* Returns false if the directory cannot be traversed.
*
* @param f the <code>File</code>
* @see JFileChooser#isTraversable
* @see FileView#isTraversable
* @since 1.4
*/
}
/**
* 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.
*
* @param f a <code>File</code> object
* @return the file name as it would be displayed by a native file chooser
* @see JFileChooser#getName
* @since 1.4
*/
if (f == null) {
return null;
}
(f instanceof ShellFolder || f.exists())) {
try {
} catch (FileNotFoundException e) {
return null;
}
}
}
return name;
}
/**
* 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.
*
* @param f a <code>File</code> object
* @return the file type description as it would be displayed by a native file chooser
* or null if no native information is available.
* @see JFileChooser#getTypeDescription
* @since 1.4
*/
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.
*
* @param f a <code>File</code> object
* @return an icon as it would be displayed by a native file chooser
* @see JFileChooser#getIcon
* @since 1.4
*/
if (f == null) {
return null;
}
try {
sf = getShellFolder(f);
} catch (FileNotFoundException e) {
return null;
}
} else {
}
}
/**
* 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().
*
* @param folder a <code>File</code> object repesenting a directory or special folder
* @param file a <code>File</code> object
* @return <code>true</code> if <code>folder</code> is a directory or special folder and contains <code>file</code>.
* @since 1.4
*/
return false;
} else if (folder instanceof ShellFolder) {
return true;
}
return true;
}
}
return false;
} else {
}
}
/**
*
* @param parent a <code>File</code> object repesenting a directory or special folder
* @param fileName a name of a file or folder which exists in <code>parent</code>
* @return a File object. This is normally constructed with <code>new
* File(parent, fileName)</code> except when parent and child are both
* special folders, in which case the <code>File</code> is a wrapper containing
* a <code>ShellFolder</code> object.
* @since 1.4
*/
if (parent instanceof ShellFolder) {
return child;
}
}
}
}
/**
* Checks if <code>f</code> represents a real directory or file as opposed to a
* special folder such as <code>"Desktop"</code>. Used by UI classes to decide if
* a folder is selectable when doing directory choosing.
*
* @param f a <code>File</code> object
* @return <code>true</code> if <code>f</code> is a real file or directory.
* @since 1.4
*/
if (f instanceof ShellFolder) {
// Shortcuts to directories are treated as not being file system objects,
// so that they are never returned by JFileChooser.
} else {
return true;
}
}
/**
* Creates a new folder with a default folder name.
*/
/**
* Returns whether a file is hidden or not.
*/
return f.isHidden();
}
/**
* 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.
*
* @param dir a <code>File</code> object representing a directory
* @return <code>true</code> if <code>f</code> is a root of a filesystem
* @see #isRoot
* @since 1.4
*/
}
/**
* 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.
*
* @param dir a directory
* @return <code>false</code> always
* @since 1.4
*/
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.
*
* @param dir a directory
* @return <code>false</code> always
* @since 1.4
*/
return false;
}
/**
* 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.
*
* @param dir a directory
* @return <code>false</code> always
* @since 1.4
*/
}
/**
* 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
if (isFileSystemRoot(roots[i])) {
}
}
return roots;
}
// Providing default implementations for the remaining methods
// because most OS file systems will likely be able to use this
// code. If a given OS can't, override these methods in its
// implementation.
}
/**
* Return the user's default starting directory for the file chooser.
*
* @return a <code>File</code> object representing the default
* starting folder
* @since 1.4
*/
if (isFileSystemRoot(f)) {
f = createFileSystemRoot(f);
}
return f;
}
/**
* Returns a File object constructed in dir from the given filename.
*/
} else {
}
}
/**
* Returns a File object constructed from the given path string.
*/
if (isFileSystemRoot(f)) {
f = createFileSystemRoot(f);
}
return f;
}
/**
* Gets the list of shown (i.e. not hidden) files.
*/
// add all files in dir
if (!(dir instanceof ShellFolder)) {
try {
} catch (FileNotFoundException e) {
return new File[0];
}
}
return new File[0];
}
break;
}
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)) {
}
}
}
/**
* Returns the parent directory of <code>dir</code>.
* @param dir the <code>File</code> being queried
* @return the parent directory of <code>dir</code>, or
* <code>null</code> if <code>dir</code> is <code>null</code>
*/
return null;
}
try {
} catch (FileNotFoundException e) {
return null;
}
return null;
}
if (isFileSystem(psf)) {
if (!f.exists()) {
// This could be a node under "Network Neighborhood".
// We're mostly after the exists() override for windows below.
f = createFileSystemRoot(f);
}
}
return f;
} else {
return psf;
}
}
/**
* Throws {@code FileNotFoundException} if file not found or current thread was interrupted
*/
f = createFileSystemRoot(f);
}
try {
return ShellFolder.getShellFolder(f);
} catch (InternalError e) {
e.printStackTrace();
return null;
}
}
/**
* Creates a new <code>File</code> object for <code>f</code> with correct
* behavior for a file system root directory.
*
* @param f a <code>File</code> object representing a file system root
* directory, for example "/" on Unix or "C:\" on Windows.
* @return a new <code>File</code> object
* @since 1.4
*/
return new FileSystemRoot(f);
}
super(f,"");
}
super(s);
}
public boolean isDirectory() {
return true;
}
return getPath();
}
}
}
/**
* FileSystemView that handles some specific unix-isms.
*/
/**
* Creates a new folder with a default folder name.
*/
if(containingDir == null) {
throw new IOException("Containing directory is null:");
}
int i = 1;
newFolderNextString, new Integer(i)));
i++;
}
} else {
}
return newFolder;
}
}
return isFloppyDrive(dir);
}
// Could be looking at the path for Solaris, but wouldn't be reliable.
// For example:
// return (dir != null && dir.getAbsolutePath().toLowerCase().startsWith("/floppy"));
return false;
}
return true;
}
}
return false;
}
}
/**
* FileSystemView that handles some specific windows concepts.
*/
}
&& isFileSystem(parent)) {
//Path is relative to the root of parent's drive
}
}
}
/**
* 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".
*
* The Windows implementation gets information from the ShellFolder class.
*/
if (f == null) {
return null;
}
try {
return getShellFolder(f).getFolderType();
} catch (FileNotFoundException e) {
return null;
}
}
/**
* @return the Desktop folder.
*/
return getRoots()[0];
}
/**
* Creates a new folder with a default folder name.
*/
if(containingDir == null) {
throw new IOException("Containing directory is null:");
}
// Using NT's default folder name
int i = 2;
newFolderNextString, new Integer(i)));
i++;
}
} else {
}
return newFolder;
}
return isFileSystemRoot(dir);
}
return dir.getAbsolutePath();
}
});
}
/**
* Returns a File object constructed from the given path string.
*/
// Check for missing backslash after drive letter such as "C:" or "C:filename"
path += "\\";
}
}
return super.createFileObject(path);
}
// Problem: Removable drives on Windows return false on f.exists()
// Workaround: Override exists() to always return true.
return new FileSystemRoot(f) {
public boolean exists() {
return true;
}
};
}
}
/**
* Fallthrough FileSystemView in case we can't determine the OS.
*/
/**
* Creates a new folder with a default folder name.
*/
if(containingDir == null) {
throw new IOException("Containing directory is null:");
}
// Using NT's default folder name
} else {
}
return newFolder;
}
}