java.lang.Object
javax.swing.filechooser.FileSystemView
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.
Java Licensees may want to provide a different implementation of FileSystemView to better handle a given operating system.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateFileObject
(File dir, String filename) Returns a File object constructed in dir from the given filename.createFileObject
(String path) Returns a File object constructed from the given path string.protected File
Creates a newFile
object forf
with correct behavior for a file system root directory.abstract File
createNewFolder
(File containingDir) Creates a new folder with a default folder name.Returns aFile
object which is normally constructed withnew File(parent, fileName)
except when the parent and child are both special folders, in which case theFile
is a wrapper containing a ShellFolder object.File[]
Returns an array of files representing the values which will be shown in the file chooser selector.final File[]
Returns an array of files representing the values to show by default in the file chooser shortcuts panel.Return the user's default starting directory for the file chooser.File[]
Gets the list of shown (i.e. not hidden) files.static FileSystemView
Returns the file system view.Returns the home directory.getLinkLocation
(File file) Returns the regular file referenced by the specified link file if the specified file is a shell interpreted link.getParentDirectory
(File dir) Returns the parent directory ofdir
.File[]
getRoots()
Returns all root partitions on this system.Name of a file, directory, or folder as it would be displayed in a system file browser.Icon for a file, directory, or folder as it would be displayed in a system file browser.getSystemIcon
(File f, int width, int height) Returns an icon for a file, directory, or folder as it would be displayed in a system file browser for the requested size.Type description for a file, directory, or folder as it would be displayed in a system file browser.boolean
isComputerNode
(File dir) Used by UI classes to decide whether to display a special icon for a computer node, e.g.boolean
Used by UI classes to decide whether to display a special icon for drives or partitions, e.g. a "hard disk" icon.boolean
isFileSystem
(File f) Checks iff
represents a real directory or file as opposed to a special folder such as"Desktop"
.boolean
isFileSystemRoot
(File dir) Is dir the root of a tree in the file system, such as a drive or partition.boolean
isFloppyDrive
(File dir) Used by UI classes to decide whether to display a special icon for a floppy disk.boolean
isHiddenFile
(File f) Returns whether a file is hidden or not.boolean
Returns whether the specified file denotes a shell interpreted link which can be obtained by thegetLinkLocation(File)
.boolean
On Windows, a file can appear in multiple folders, other than its parent directory in the filesystem.boolean
Determines if the given file is a root in the navigable tree(s).Returns true if the file (directory) can be visited.
-
Constructor Details
-
FileSystemView
public FileSystemView()Constructs a FileSystemView.
-
-
Method Details
-
getFileSystemView
Returns the file system view.- Returns:
- the file system view
-
isRoot
Determines if the given file is a root in the navigable 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 theShellFolder
class.- Parameters:
f
- aFile
object representing a directory- Returns:
true
iff
is a root in the navigable tree.- See Also:
-
isTraversable
Returns true if the file (directory) can be visited. Returns false if the directory cannot be traversed.- Parameters:
f
- theFile
- Returns:
true
if the file/directory can be traversed, otherwisefalse
- Since:
- 1.4
- See Also:
-
getSystemDisplayName
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.- Parameters:
f
- aFile
object- Returns:
- the file name as it would be displayed by a native file chooser
- Since:
- 1.4
- See Also:
-
getSystemTypeDescription
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 described as "Desktop". Override for platforms with native ShellFolder implementations.- Parameters:
f
- aFile
object- Returns:
- the file type description as it would be displayed by a native file chooser or null if no native information is available.
- Since:
- 1.4
- See Also:
-
getSystemIcon
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.
- Parameters:
f
- aFile
object- Returns:
- an icon as it would be displayed by a native file chooser
- Since:
- 1.4
- See Also:
-
getSystemIcon
Returns an icon for a file, directory, or folder as it would be displayed in a system file browser for the requested size.Example:
FileSystemView fsv = FileSystemView.getFileSystemView(); Icon icon = fsv.getSystemIcon(new File("application.exe"), 64, 64); JLabel label = new JLabel(icon);
- Implementation Requirements:
- The available icons may be platform specific and so the available sizes determined by the platform. Therefore an exact match for the requested size may not be possible. The icon returned may be a multi-resolution icon image, which allows better support for High DPI environments with different scaling factors.
- Parameters:
f
- aFile
object for which the icon will be retrievedwidth
- width of the icon in user coordinate system.height
- height of the icon in user coordinate system.- Returns:
- an icon as it would be displayed by a native file chooser or null for a non-existent or inaccessible file.
- Throws:
IllegalArgumentException
- if an invalid parameter such as a negative size or a null file reference is passed.- Since:
- 17
- See Also:
-
isParent
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().- Parameters:
folder
- aFile
object representing a directory or special folderfile
- aFile
object- Returns:
true
iffolder
is a directory or special folder and containsfile
.- Since:
- 1.4
-
getChild
Returns aFile
object which is normally constructed withnew File(parent, fileName)
except when the parent and child are both special folders, in which case theFile
is a wrapper containing a ShellFolder object.- Parameters:
parent
- aFile
object representing a directory or special folderfileName
- a name of a file or folder which exists inparent
- Returns:
- a File object.
- Since:
- 1.4
-
isFileSystem
Checks iff
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.- Parameters:
f
- aFile
object- Returns:
true
iff
is a real file or directory.- Since:
- 1.4
-
createNewFolder
Creates a new folder with a default folder name.- Parameters:
containingDir
- aFile
object denoting directory to contain the new folder- Returns:
- a
File
object denoting the newly created folder - Throws:
IOException
- if new folder could not be created
-
isHiddenFile
Returns whether a file is hidden or not.- Parameters:
f
- aFile
object- Returns:
- true if the given
File
denotes a hidden file
-
isFileSystemRoot
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.- Parameters:
dir
- aFile
object representing a directory- Returns:
true
iff
is a root of a filesystem- Since:
- 1.4
- See Also:
-
isDrive
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.- Parameters:
dir
- a directory- Returns:
false
always- Since:
- 1.4
-
isFloppyDrive
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.- Parameters:
dir
- a directory- Returns:
false
always- Since:
- 1.4
-
isComputerNode
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.- Parameters:
dir
- a directory- Returns:
false
always- Since:
- 1.4
-
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.- Returns:
- an array of
File
objects representing all root partitions on this system
-
getHomeDirectory
Returns the home directory.- Returns:
- the home directory
-
getDefaultDirectory
Return the user's default starting directory for the file chooser.- Returns:
- a
File
object representing the default starting folder - Since:
- 1.4
-
createFileObject
Returns a File object constructed in dir from the given filename.- Parameters:
dir
- an abstract pathname denoting a directoryfilename
- aString
representation of a pathname- Returns:
- a
File
object created fromdir
andfilename
-
createFileObject
Returns a File object constructed from the given path string.- Parameters:
path
-String
representation of path- Returns:
- a
File
object created from the givenpath
-
getFiles
Gets the list of shown (i.e. not hidden) files.- Parameters:
dir
- the root directory of files to be returneduseFileHiding
- determine if hidden files are returned- Returns:
- an array of
File
objects representing files and directories in the givendir
. It includes hidden files ifuseFileHiding
is false.
-
getParentDirectory
Returns the parent directory ofdir
.- Parameters:
dir
- theFile
being queried- Returns:
- the parent directory of
dir
, ornull
ifdir
isnull
-
getChooserComboBoxFiles
Returns an array of files representing the values which will be shown in the file chooser selector.- Returns:
- an array of
File
objects. The array returned may be possibly empty if there are no appropriate permissions. - Since:
- 9
-
getChooserShortcutPanelFiles
Returns an array of files representing the values to show by default in the file chooser shortcuts panel.- Returns:
- an array of
File
objects. The array returned may be possibly empty if there are no appropriate permissions. - Since:
- 12
-
isLink
Returns whether the specified file denotes a shell interpreted link which can be obtained by thegetLinkLocation(File)
.- Parameters:
file
- a file- Returns:
- whether this is a link
- Throws:
NullPointerException
- iffile
equalsnull
SecurityException
- if the caller does not have necessary permissions- Since:
- 9
- See Also:
-
getLinkLocation
Returns the regular file referenced by the specified link file if the specified file is a shell interpreted link. Returnsnull
if the specified file is not a shell interpreted link.- Parameters:
file
- a file- Returns:
- the linked file or
null
. - Throws:
FileNotFoundException
- if the linked file does not existNullPointerException
- iffile
equalsnull
SecurityException
- if the caller does not have necessary permissions- Since:
- 9
-
createFileSystemRoot
Creates a newFile
object forf
with correct behavior for a file system root directory.- Parameters:
f
- aFile
object representing a file system root directory, for example "/" on Unix or "C:\" on Windows.- Returns:
- a new
File
object - Since:
- 1.4
-