Quaqua 7.4.2 2011-07-05

ch.randelshofer.quaqua.filechooser
Class FileSystemViewFilter

java.lang.Object
  extended by javax.swing.filechooser.FileSystemView
      extended by ch.randelshofer.quaqua.filechooser.FileSystemViewFilter
Direct Known Subclasses:
QuaquaFileSystemView

public abstract class FileSystemViewFilter
extends javax.swing.filechooser.FileSystemView

This is a filter for the FileSystemView provided by the Java VM. The filter can change some of the behaviour of its target FileSystemView.

Version:
$Id: FileSystemViewFilter.java 363 2010-11-21 17:41:04Z wrandelshofer $
Author:
Werner Randelshofer

Field Summary
protected  javax.swing.filechooser.FileSystemView target
           
 
Constructor Summary
FileSystemViewFilter()
          Creates a new instance.
 
Method Summary
 java.io.File createFileObject(java.io.File dir, java.lang.String filename)
          Returns a File object constructed in dir from the given filename.
 java.io.File createFileObject(java.lang.String path)
          Returns a File object constructed from the given path string.
 java.io.File createNewFolder(java.io.File containingDir)
          Creates a new folder with a default folder name.
 java.io.File getChild(java.io.File parent, java.lang.String fileName)
           
abstract  java.io.File getDefaultDirectory()
          Return the user's default starting directory for the file chooser.
 java.io.File[] getFiles(java.io.File dir, boolean useFileHiding)
          Gets the list of shown (i.e.
 java.io.File getHomeDirectory()
           
 java.io.File getParentDirectory(java.io.File dir)
          Returns the parent directory of dir.
 java.io.File[] getRoots()
          Returns all root partitions on this system.
 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.
 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.
 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.
 boolean isComputerNode(java.io.File dir)
          Used by UI classes to decide whether to display a special icon for a computer node, e.g.
 boolean isDrive(java.io.File dir)
          Used by UI classes to decide whether to display a special icon for drives or partitions, e.g.
 boolean isFileSystem(java.io.File f)
          Checks if f represents a real directory or file as opposed to a special folder such as "Desktop".
 boolean isFileSystemRoot(java.io.File dir)
          Is dir the root of a tree in the file system, such as a drive or partition.
 boolean isFloppyDrive(java.io.File dir)
          Used by UI classes to decide whether to display a special icon for a floppy disk.
 boolean isHiddenFile(java.io.File f)
          Returns whether a file is hidden or not.
 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.
 boolean isRoot(java.io.File f)
          Determines if the given file is a root in the navigatable tree(s).
 java.lang.Boolean isTraversable(java.io.File f)
          Returns true if the file (directory) can be visited.
 
Methods inherited from class javax.swing.filechooser.FileSystemView
createFileSystemRoot, getFileSystemView
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

target

protected javax.swing.filechooser.FileSystemView target
Constructor Detail

FileSystemViewFilter

public FileSystemViewFilter()
Creates a new instance.

Method Detail

createNewFolder

public java.io.File createNewFolder(java.io.File containingDir)
                             throws java.io.IOException
Creates a new folder with a default folder name.

Specified by:
createNewFolder in class javax.swing.filechooser.FileSystemView
Throws:
java.io.IOException

isRoot

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.

Overrides:
isRoot in class javax.swing.filechooser.FileSystemView
Parameters:
f - a File object representing a directory
Returns:
true if f is a root in the navigatable tree.
See Also:
isFileSystemRoot(java.io.File)

isTraversable

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.

Overrides:
isTraversable in class javax.swing.filechooser.FileSystemView
Parameters:
f - the File
Returns:
true if the file/directory can be traversed, otherwise false
See Also:
JFileChooser.isTraversable(java.io.File), FileView.isTraversable(java.io.File)

getSystemDisplayName

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.

Overrides:
getSystemDisplayName in class javax.swing.filechooser.FileSystemView
Parameters:
f - a File object
Returns:
the file name as it would be displayed by a native file chooser
See Also:
JFileChooser.getName(java.io.File)

getSystemTypeDescription

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.

Overrides:
getSystemTypeDescription in class javax.swing.filechooser.FileSystemView
Parameters:
f - a File object
Returns:
the file type description as it would be displayed by a native file chooser or null if no native information is available.
See Also:
JFileChooser.getTypeDescription(java.io.File)

getSystemIcon

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.

Overrides:
getSystemIcon in class javax.swing.filechooser.FileSystemView
Parameters:
f - a File object
Returns:
an icon as it would be displayed by a native file chooser
See Also:
JFileChooser.getIcon(java.io.File)

isParent

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().

Overrides:
isParent in class javax.swing.filechooser.FileSystemView
Parameters:
folder - a File object repesenting a directory or special folder
file - a File object
Returns:
true if folder is a directory or special folder and contains file.

getChild

public java.io.File getChild(java.io.File parent,
                             java.lang.String fileName)
Overrides:
getChild in class javax.swing.filechooser.FileSystemView
Parameters:
parent - a File object repesenting a directory or special folder
fileName - a name of a file or folder which exists in parent
Returns:
a File object. This is normally constructed with new File(parent, fileName) except when parent and child are both special folders, in which case the File is a wrapper containing a ShellFolder object.

isFileSystem

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.

Overrides:
isFileSystem in class javax.swing.filechooser.FileSystemView
Parameters:
f - a File object
Returns:
true if f is a real file or directory.

isHiddenFile

public boolean isHiddenFile(java.io.File f)
Returns whether a file is hidden or not.

Overrides:
isHiddenFile in class javax.swing.filechooser.FileSystemView

isFileSystemRoot

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.

Overrides:
isFileSystemRoot in class javax.swing.filechooser.FileSystemView
Parameters:
dir - a File object representing a directory
Returns:
true if f is a root of a filesystem
See Also:
isRoot(java.io.File)

isDrive

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.

Overrides:
isDrive in class javax.swing.filechooser.FileSystemView
Parameters:
dir - a directory
Returns:
false always

isFloppyDrive

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.

Overrides:
isFloppyDrive in class javax.swing.filechooser.FileSystemView
Parameters:
dir - a directory
Returns:
false always

isComputerNode

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.

Overrides:
isComputerNode in class javax.swing.filechooser.FileSystemView
Parameters:
dir - a directory
Returns:
false always

getRoots

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.

Overrides:
getRoots in class javax.swing.filechooser.FileSystemView

getHomeDirectory

public java.io.File getHomeDirectory()
Overrides:
getHomeDirectory in class javax.swing.filechooser.FileSystemView

getDefaultDirectory

public abstract java.io.File getDefaultDirectory()
Return the user's default starting directory for the file chooser.

Overrides:
getDefaultDirectory in class javax.swing.filechooser.FileSystemView
Returns:
a File object representing the default starting folder

createFileObject

public java.io.File createFileObject(java.io.File dir,
                                     java.lang.String filename)
Returns a File object constructed in dir from the given filename.

Overrides:
createFileObject in class javax.swing.filechooser.FileSystemView

createFileObject

public java.io.File createFileObject(java.lang.String path)
Returns a File object constructed from the given path string.

Overrides:
createFileObject in class javax.swing.filechooser.FileSystemView

getFiles

public java.io.File[] getFiles(java.io.File dir,
                               boolean useFileHiding)
Gets the list of shown (i.e. not hidden) files.

Overrides:
getFiles in class javax.swing.filechooser.FileSystemView

getParentDirectory

public java.io.File getParentDirectory(java.io.File dir)
Returns the parent directory of dir.

Overrides:
getParentDirectory in class javax.swing.filechooser.FileSystemView
Parameters:
dir - the File being queried
Returns:
the parent directory of dir, or null if dir is null

Copyright 2003-2007 (c) Werner Randelshofer.
All rights reserved.