2362N/A * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * FileSystemView is JFileChooser's gateway to the 0N/A * file system. Since the JDK1.1 File API doesn't allow 0N/A * access to such information as root partitions, file type 0N/A * information, or hidden file bits, this class is designed 0N/A * to intuit as much OS-specific file system information as 0N/A * Java Licensees may want to provide a different implementation of 0N/A * FileSystemView to better handle a given operating system. 0N/A * @author Jeff Dinkins 0N/A// PENDING(jeff) - need to provide a specification for 0N/A// to handle their particular type of file system. 0N/A //static FileSystemView macFileSystemView = null; 0N/A // if(File.separatorChar == ':') { 0N/A // if(macFileSystemView == null) { 0N/A // macFileSystemView = new MacFileSystemView(); 0N/A // return macFileSystemView; 239N/A // FileSystemView was destroyed 0N/A * Determines if the given file is a root in the navigatable tree(s). 0N/A * Examples: Windows 98 has one root, the Desktop folder. DOS has one root 0N/A * per drive letter, <code>C:\</code>, <code>D:\</code>, etc. Unix has one root, 0N/A * the <code>"/"</code> directory. 0N/A * The default implementation gets information from the <code>ShellFolder</code> class. 0N/A * @param f a <code>File</code> object representing a directory 0N/A * @return <code>true</code> if <code>f</code> is a root in the navigatable tree. 0N/A * @see #isFileSystemRoot 0N/A * Returns true if the file (directory) can be visited. 0N/A * Returns false if the directory cannot be traversed. 0N/A * @param f the <code>File</code> 0N/A * @return <code>true</code> if the file/directory can be traversed, otherwise <code>false</code> 0N/A * @see JFileChooser#isTraversable 0N/A * @see FileView#isTraversable 0N/A * Name of a file, directory, or folder as it would be displayed in 0N/A * a system file browser. Example from Windows: the "M:\" directory 0N/A * displays as "CD-ROM (M:)" 0N/A * The default implementation gets information from the ShellFolder class. 0N/A * @param f a <code>File</code> object 0N/A * @return the file name as it would be displayed by a native file chooser 0N/A * @see JFileChooser#getName 0N/A * Type description for a file, directory, or folder as it would be displayed in 0N/A * a system file browser. Example from Windows: the "Desktop" folder 0N/A * is desribed as "Desktop". 0N/A * Override for platforms with native ShellFolder implementations. 0N/A * @param f a <code>File</code> object 0N/A * @return the file type description as it would be displayed by a native file chooser 0N/A * or null if no native information is available. 0N/A * @see JFileChooser#getTypeDescription 0N/A * Icon for a file, directory, or folder as it would be displayed in 0N/A * a system file browser. Example from Windows: the "M:\" directory 0N/A * displays a CD-ROM icon. 0N/A * The default implementation gets information from the ShellFolder class. 0N/A * @param f a <code>File</code> object 0N/A * @return an icon as it would be displayed by a native file chooser 0N/A * @see JFileChooser#getIcon 0N/A * On Windows, a file can appear in multiple folders, other than its 0N/A * parent directory in the filesystem. Folder could for example be the 0N/A * "Desktop" folder which is not the same as file.getParentFile(). 0N/A * @param folder a <code>File</code> object repesenting a directory or special folder 0N/A * @param file a <code>File</code> object 0N/A * @return <code>true</code> if <code>folder</code> is a directory or special folder and contains <code>file</code>. 0N/A * @param parent a <code>File</code> object repesenting a directory or special folder 0N/A * @param fileName a name of a file or folder which exists in <code>parent</code> 0N/A * @return a File object. This is normally constructed with <code>new 0N/A * File(parent, fileName)</code> except when parent and child are both 0N/A * special folders, in which case the <code>File</code> is a wrapper containing 0N/A * a <code>ShellFolder</code> object. 0N/A * Checks if <code>f</code> represents a real directory or file as opposed to a 0N/A * special folder such as <code>"Desktop"</code>. Used by UI classes to decide if 0N/A * a folder is selectable when doing directory choosing. 0N/A * @param f a <code>File</code> object 0N/A * @return <code>true</code> if <code>f</code> is a real file or directory. 0N/A // Shortcuts to directories are treated as not being file system objects, 0N/A // so that they are never returned by JFileChooser. 0N/A * Creates a new folder with a default folder name. 0N/A * Returns whether a file is hidden or not. 0N/A * Is dir the root of a tree in the file system, such as a drive 0N/A * or partition. Example: Returns true for "C:\" on Windows 98. 0N/A * @param dir a <code>File</code> object representing a directory 0N/A * @return <code>true</code> if <code>f</code> is a root of a filesystem 0N/A * Used by UI classes to decide whether to display a special icon 0N/A * for drives or partitions, e.g. a "hard disk" icon. 0N/A * The default implementation has no way of knowing, so always returns false. 0N/A * @param dir a directory 0N/A * @return <code>false</code> always 0N/A * Used by UI classes to decide whether to display a special icon 0N/A * for a floppy disk. Implies isDrive(dir). 0N/A * The default implementation has no way of knowing, so always returns false. 0N/A * @param dir a directory 0N/A * @return <code>false</code> always 0N/A * Used by UI classes to decide whether to display a special icon 0N/A * for a computer node, e.g. "My Computer" or a network server. 0N/A * The default implementation has no way of knowing, so always returns false. 0N/A * @param dir a directory 0N/A * @return <code>false</code> always 0N/A * Returns all root partitions on this system. For example, on 0N/A * Windows, this would be the "Desktop" folder, while on DOS this 0N/A * would be the A: through Z: drives. 0N/A // Don't cache this array, because filesystem might change 0N/A // Providing default implementations for the remaining methods 0N/A // because most OS file systems will likely be able to use this 0N/A // code. If a given OS can't, override these methods in its 0N/A * Return the user's default starting directory for the file chooser. 0N/A * @return a <code>File</code> object representing the default 0N/A * Returns a File object constructed in dir from the given filename. 0N/A * Returns a File object constructed from the given path string. 0N/A * Gets the list of shown (i.e. not hidden) files. 0N/A // add all files in dir 0N/A // Not a valid file (wouldn't show in native file chooser) 0N/A // Example: C:\pagefile.sys 0N/A // Not a valid file (wouldn't show in native file chooser) 0N/A // Example C:\Winnt\Profiles\joe\history\History.IE5 0N/A * Returns the parent directory of <code>dir</code>. 0N/A * @param dir the <code>File</code> being queried 0N/A * @return the parent directory of <code>dir</code>, or 0N/A * <code>null</code> if <code>dir</code> is <code>null</code> 1915N/A // This could be a node under "Network Neighborhood". 1915N/A // We're mostly after the exists() override for windows below. 1915N/A * Throws {@code FileNotFoundException} if file not found or current thread was interrupted 0N/A * Creates a new <code>File</code> object for <code>f</code> with correct 0N/A * behavior for a file system root directory. 0N/A * @param f a <code>File</code> object representing a file system root 0N/A * directory, for example "/" on Unix or "C:\" on Windows. 0N/A * @return a new <code>File</code> object 0N/A * FileSystemView that handles some specific unix-isms. 0N/A * Creates a new folder with a default folder name. 0N/A // Unix - using OpenWindows' default folder name. Can't find one for Motif/CDE. 0N/A // Could be looking at the path for Solaris, but wouldn't be reliable. 0N/A // return (dir != null && dir.getAbsolutePath().toLowerCase().startsWith("/floppy")); 0N/A * FileSystemView that handles some specific windows concepts. 0N/A //Path is relative to the root of parent's drive 0N/A * Type description for a file, directory, or folder as it would be displayed in 0N/A * a system file browser. Example from Windows: the "Desktop" folder 0N/A * is desribed as "Desktop". 0N/A * The Windows implementation gets information from the ShellFolder class. 0N/A * @return the Desktop folder. 0N/A * Creates a new folder with a default folder name. 0N/A // Using NT's default folder name 0N/A * Returns a File object constructed from the given path string. 0N/A // Check for missing backslash after drive letter such as "C:" or "C:filename" 0N/A // Problem: Removable drives on Windows return false on f.exists() 0N/A // Workaround: Override exists() to always return true. 0N/A * Fallthrough FileSystemView in case we can't determine the OS. 0N/A * Creates a new folder with a default folder name. 0N/A // Using NT's default folder name