FileDocCategorySizeDatePackage
ExampleFileView.javaAPI DocSun JDK 1.4.2 Example6570Thu May 12 00:35:27 BST 2005None

ExampleFileView

public class ExampleFileView extends FileView
A convenience implementation of the FileView interface that manages name, icon, traversable, and file type information. This this implemention will work well with file systems that use "dot" extensions to indicate file type. For example: "picture.gif" as a gif image. If the java.io.File ever contains some of this information, such as file type, icon, and hidden file inforation, this implementation may become obsolete. At minimum, it should be rewritten at that time to use any new type information provided by java.io.File Example: JFileChooser chooser = new JFileChooser(); fileView = new ExampleFileView(); fileView.putIcon("jpg", new ImageIcon("images/jpgIcon.jpg")); fileView.putIcon("gif", new ImageIcon("images/gifIcon.gif")); chooser.setFileView(fileView);
version
1.13 01/23/03
author
Jeff Dinkins

Fields Summary
private Hashtable
icons
private Hashtable
fileDescriptions
private Hashtable
typeDescriptions
Constructors Summary
Methods Summary
public java.lang.StringgetDescription(java.io.File f)
A human readable description of the file.

see
FileView#getDescription

	return (String) fileDescriptions.get(f);
    
public java.lang.StringgetExtension(java.io.File f)
Conveinience method that returnsa the "dot" extension for the given file.

	String name = f.getName();
	if(name != null) {
	    int extensionIndex = name.lastIndexOf('.");
	    if(extensionIndex < 0) {
		return null;
	    }
	    return name.substring(extensionIndex+1).toLowerCase();
	}
	return null;
    
public javax.swing.IcongetIcon(java.io.File f)
Icon that reperesents this file. Default implementation returns null. You might want to override this to return something more interesting.

see
FileView#getIcon

	Icon icon = null;
	String extension = getExtension(f);
	if(extension != null) {
	    icon = (Icon) icons.get(extension);
	}
	return icon;
    
public java.lang.StringgetName(java.io.File f)
The name of the file. Do nothing special here. Let the system file view handle this.

see
#setName
see
FileView#getName


                              
        
	return null;
    
public java.lang.StringgetTypeDescription(java.io.File f)
A human readable description of the type of the file.

see
FileView#getTypeDescription

	return (String) typeDescriptions.get(getExtension(f));
    
public java.lang.BooleanisHidden(java.io.File f)
Whether the file is hidden or not. This implementation returns true if the filename starts with a "."

see
FileView#isHidden

	String name = f.getName();
	if(name != null && !name.equals("") && name.charAt(0) == '.") {
	    return Boolean.TRUE;
	} else {
	    return Boolean.FALSE;
	}
    
public java.lang.BooleanisTraversable(java.io.File f)
Whether the directory is traversable or not. Generic implementation returns true for all directories and special folders. You might want to subtype ExampleFileView to do somethimg more interesting, such as recognize compound documents directories; in such a case you might return a special icon for the diretory that makes it look like a regular document, and return false for isTraversable to not allow users to descend into the directory.

see
FileView#isTraversable

	// if (some_reason) {
	//    return Boolean.FALSE;
	// }
	return null;	// Use default from FileSystemView
    
public voidputDescription(java.io.File f, java.lang.String fileDescription)
Adds a human readable description of the file.

	fileDescriptions.put(fileDescription, f);
    
public voidputIcon(java.lang.String extension, javax.swing.Icon icon)
Adds an icon based on the file type "dot" extension string, e.g: ".gif". Case is ignored.

	icons.put(extension, icon);
    
public voidputTypeDescription(java.lang.String extension, java.lang.String typeDescription)
Adds a human readable type description for files. Based on "dot" extension strings, e.g: ".gif". Case is ignored.

	typeDescriptions.put(typeDescription, extension);
    
public voidputTypeDescription(java.io.File f, java.lang.String typeDescription)
Adds a human readable type description for files of the type of the passed in file. Based on "dot" extension strings, e.g: ".gif". Case is ignored.

	putTypeDescription(getExtension(f), typeDescription);