WebNFS Developer's Guide

Appendix D The XFileChooser Sample Program

Overview

This demo is based on the JFileChooser demo of the JDK1.2. This XFileChooserDemo has been modified to support the XFileChooser object. The source JFileChooserDemo.java has been changed by replacing references to JFileChooser objects with XFileChooser objects and File with XFile. This program is described in detail in "The XFileChooserDemo Sample Program".

FileChooserDemo demonstrates some of the capabilities of the Swing JFileChooser object. It brings up a window displaying several configuration controls that allow you to play with the JFileChooser options dynamically.

To compile the FileChooserDemo demo on 1.2 on Solaris:


% javac -classpath ../../xfilechooser.jar  \
         ExampleFileFilter.java FileChooserDemo.java ExampleFileView.java
To run the compiled bytecode:

% java -classpath ../../xfilechooser.jar:. FileChooserDemo
If compiling or running on Windows, use backslashes in the path, and semicolon as separator, e.g.:

% java -classpath ..\..\xfilechooser.jar;. FileChooserDemo


Note -

You must be using the java in JDK1.2, thus set your path accordingly. If you are using a Java2 release prior to JDK 1.2.1 you may need the JFileChooser patch to fix bug 4169763. The XFileChooser release notes describe how to use the the Xbootclasspath to include the patch.


The XFileChooserDemo Program

This is the main program. It makes use of "ExampleFileFilter" and "ExampleFileView" to bring up an file chooser with numerous options.


Example D-1 The XFileChooser Demo Program

/*
 * @(#)FileChooserDemo.java	1.2 99/04/18
 *
 * Copyright 1999 by Sun Microsystems, Inc.,
 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Sun Microsystems, Inc. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Sun.
 */

import javax.swing.*;
import javax.swing.filechooser.*;

import java.awt.*;
import java.io.File;
import java.awt.event.*;
import java.beans.*;
import com.sun.xfile.*;
import com.sun.xfilechooser.*;

/**
 *
 * A demo which makes extensive use of the file chooser.
 *
 * 1.7 08/26/98
 * @author Jeff Dinkins
 */
public class FileChooserDemo extends JPanel implements ActionListener {
    static JFrame frame;

    static String metal= "Metal";
    static String metalClassName = "javax.swing.plaf.metal.MetalLookAndFeel";

    static String motif = "Motif";
    static String motifClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";

    static String windows = "Windows";
    static String windowsClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";


    JButton button;
    JCheckBox useFileViewButton, accessoryButton, hiddenButton, showFullDescriptionButton;
    JRadioButton noFilterButton, addFiltersButton;
    JRadioButton openButton, saveButton, customButton;
    JRadioButton metalButton, motifButton, windowsButton;
    JRadioButton justFilesButton, justDirectoriesButton, bothFilesAndDirectoriesButton;

    JTextField customField;

    ExampleFileFilter jpgFilter, gifFilter, bothFilter;
    ExampleFileView fileView;

    JPanel buttonPanel;

    public final static Dimension hpad10 = new Dimension(10,1);
    public final static Dimension vpad10 = new Dimension(1,10);

    FilePreviewer previewer;
    XFileChooser chooser;

    public FileChooserDemo() {
	setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

	chooser = new XFileChooser();
	previewer = new FilePreviewer(chooser);
	chooser.setAccessory(previewer);

	jpgFilter = new ExampleFileFilter("jpg", "JPEG Compressed Image Files");
	gifFilter = new ExampleFileFilter("gif", "GIF Image Files");
	bothFilter = new ExampleFileFilter(new String[] {"jpg", "gif"}, "JPEG and GIF Image Files");

	fileView = new ExampleFileView();
	fileView.putIcon("jpg", new ImageIcon("images/jpgIcon.jpg"));
	fileView.putIcon("gif", new ImageIcon("images/gifIcon.gif"));

	chooser.setAccessory(previewer);
	chooser.setFileView(fileView);

	// create a radio listener to listen to option changes
	OptionListener optionListener = new OptionListener();

	// Create options
	openButton = new JRadioButton("Open");
	openButton.setSelected(true);
	openButton.addActionListener(optionListener);

	saveButton = new JRadioButton("Save");
	saveButton.addActionListener(optionListener);

	customButton = new JRadioButton("Custom");
	customButton.addActionListener(optionListener);

	customField = new JTextField("Doit");
	customField.setAlignmentY(JComponent.TOP_ALIGNMENT);
	customField.setEnabled(false);
	customField.addActionListener(optionListener);

	ButtonGroup group1 = new ButtonGroup();
	group1.add(openButton);
	group1.add(saveButton);
	group1.add(customButton);

	// filter buttons
	noFilterButton = new JRadioButton("No Filtering");
	noFilterButton.setSelected(true);
	noFilterButton.addActionListener(optionListener);

	addFiltersButton = new JRadioButton("Add JPG and GIF Filters");
	addFiltersButton.addActionListener(optionListener);

	ButtonGroup group2 = new ButtonGroup();
	group2.add(noFilterButton);
	group2.add(addFiltersButton);

	accessoryButton = new JCheckBox("Show Preview");
	accessoryButton.addActionListener(optionListener);
	accessoryButton.setSelected(true);

	// more options
	hiddenButton = new JCheckBox("Show Hidden Files");
	hiddenButton.addActionListener(optionListener);

	showFullDescriptionButton = new JCheckBox("Show Extensions");
	showFullDescriptionButton.addActionListener(optionListener);
	showFullDescriptionButton.setSelected(true);

	useFileViewButton = new JCheckBox("Use FileView");
	useFileViewButton.addActionListener(optionListener);
	useFileViewButton.setSelected(true);

	// File or Directory chooser options
	ButtonGroup group3 = new ButtonGroup();
	justFilesButton = new JRadioButton("Just Select Files");
	justFilesButton.setSelected(true);
	group3.add(justFilesButton);
	justFilesButton.addActionListener(optionListener);

	justDirectoriesButton = new JRadioButton("Just Select Directories");
	group3.add(justDirectoriesButton);
	justDirectoriesButton.addActionListener(optionListener);

	bothFilesAndDirectoriesButton = new JRadioButton("Select Files or Directories");
	group3.add(bothFilesAndDirectoriesButton);
	bothFilesAndDirectoriesButton.addActionListener(optionListener);

	// Create show button
	button = new JButton("Show FileChooser");
	button.addActionListener(this);
        button.setMnemonic('s');

	// Create laf buttons.
	metalButton = new JRadioButton(metal);
        metalButton.setMnemonic('o');
	metalButton.setActionCommand(metalClassName);

	motifButton = new JRadioButton(motif);
        motifButton.setMnemonic('m');
	motifButton.setActionCommand(motifClassName);

	windowsButton = new JRadioButton(windows);
        windowsButton.setMnemonic('w');
	windowsButton.setActionCommand(windowsClassName);

	ButtonGroup group4 = new ButtonGroup();
	group4.add(metalButton);
	group4.add(motifButton);
	group4.add(windowsButton);

        // Register a listener for the laf buttons.
	metalButton.addActionListener(optionListener);
	motifButton.addActionListener(optionListener);
	windowsButton.addActionListener(optionListener);

	JPanel control1 = new JPanel();
	control1.setLayout(new BoxLayout(control1, BoxLayout.X_AXIS));
	control1.add(Box.createRigidArea(hpad10));
	control1.add(openButton);
	control1.add(Box.createRigidArea(hpad10));
	control1.add(saveButton);
	control1.add(Box.createRigidArea(hpad10));
	control1.add(customButton);
	control1.add(customField);
	control1.add(Box.createRigidArea(hpad10));

	JPanel control2 = new JPanel();
	control2.setLayout(new BoxLayout(control2, BoxLayout.X_AXIS));
	control2.add(Box.createRigidArea(hpad10));
	control2.add(noFilterButton);
	control2.add(Box.createRigidArea(hpad10));
	control2.add(addFiltersButton);
	control2.add(Box.createRigidArea(hpad10));
	control2.add(accessoryButton);
	control2.add(Box.createRigidArea(hpad10));

	JPanel control3 = new JPanel();
	control3.setLayout(new BoxLayout(control3, BoxLayout.X_AXIS));
	control3.add(Box.createRigidArea(hpad10));
	control3.add(hiddenButton);
	control3.add(Box.createRigidArea(hpad10));
	control3.add(showFullDescriptionButton);
	control3.add(Box.createRigidArea(hpad10));
	control3.add(useFileViewButton);
	control3.add(Box.createRigidArea(hpad10));

	JPanel control4 = new JPanel();
	control4.setLayout(new BoxLayout(control4, BoxLayout.X_AXIS));
	control4.add(Box.createRigidArea(hpad10));
	control4.add(justFilesButton);
	control4.add(Box.createRigidArea(hpad10));
	control4.add(justDirectoriesButton);
	control4.add(Box.createRigidArea(hpad10));
	control4.add(bothFilesAndDirectoriesButton);
	control4.add(Box.createRigidArea(hpad10));

	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
	panel.add(Box.createRigidArea(hpad10));
	panel.add(button);
	panel.add(Box.createRigidArea(hpad10));
	panel.add(metalButton);
	panel.add(Box.createRigidArea(hpad10));
	panel.add(motifButton);
	panel.add(Box.createRigidArea(hpad10));
	panel.add(windowsButton);
	panel.add(Box.createRigidArea(hpad10));

	add(Box.createRigidArea(vpad10));
	add(control1);
	add(Box.createRigidArea(vpad10));
	add(control2);
	add(Box.createRigidArea(vpad10));
	add(control3);
	add(Box.createRigidArea(vpad10));
	add(control4);
	add(Box.createRigidArea(vpad10));
	add(Box.createRigidArea(vpad10));
	add(panel);
	add(Box.createRigidArea(vpad10));
    }

    public void actionPerformed(ActionEvent e) {
	int retval = chooser.showDialog(frame, null);
	if(retval == XFileChooser.APPROVE_OPTION) {
	    XFile theFile = chooser.getSelectedXFile();
	    if(theFile != null) {
		if(theFile.isDirectory()) {
		    JOptionPane.showMessageDialog(
			frame, "You chose this directory: " +
			chooser.getSelectedXFile().getAbsolutePath()
		    );
		} else {
		    JOptionPane.showMessageDialog(
			frame, "You chose this file: " +
			chooser.getSelectedXFile().getAbsolutePath()
		    );
		}
		return;
	    }
	}
	JOptionPane.showMessageDialog(frame, "No file was chosen.");
    }

    /** An ActionListener that listens to the radio buttons. */
    class OptionListener implements ActionListener {
	public void actionPerformed(ActionEvent e) {
	    JComponent c = (JComponent) e.getSource();
	    if(c == openButton) {
		chooser.setDialogType(XFileChooser.OPEN_DIALOG);
		customField.setEnabled(false);
		repaint();
	    } else if (c == saveButton) {
		chooser.setDialogType(XFileChooser.SAVE_DIALOG);
		customField.setEnabled(false);
		repaint();
	    } else if (c == customButton || c == customField) {
		customField.setEnabled(true);
		chooser.setDialogType(XFileChooser.CUSTOM_DIALOG);
		chooser.setApproveButtonText(customField.getText());
		repaint();
	    } else if(c == noFilterButton) {
		chooser.resetChoosableFileFilters();
	    } else if(c == addFiltersButton) {
		chooser.addChoosableFileFilter(bothFilter);
		chooser.addChoosableFileFilter(jpgFilter);
		chooser.addChoosableFileFilter(gifFilter);
	    } else if(c == hiddenButton) {
		chooser.setFileHidingEnabled(!hiddenButton.isSelected());
	    } else if(c == accessoryButton) {
		if(accessoryButton.isSelected()) {
		    chooser.setAccessory(previewer);
		} else {
		    chooser.setAccessory(null);
		}
	    } else if(c == useFileViewButton) {
		if(useFileViewButton.isSelected()) {
		    chooser.setFileView(fileView);
		} else {
		    chooser.setFileView(null);
		}
	    } else if(c == showFullDescriptionButton) {
		jpgFilter.setExtensionListInDescription(showFullDescriptionButton.isSelected());
		gifFilter.setExtensionListInDescription(showFullDescriptionButton.isSelected());
		bothFilter.setExtensionListInDescription(showFullDescriptionButton.isSelected());
		if(addFiltersButton.isSelected()) {
		    chooser.resetChoosableFileFilters();
		    chooser.addChoosableFileFilter(bothFilter);
		    chooser.addChoosableFileFilter(jpgFilter);
		    chooser.setFileFilter(gifFilter);
		}
	    } else if(c == justFilesButton) {
		chooser.setFileSelectionMode(XFileChooser.FILES_ONLY);
	    } else if(c == justDirectoriesButton) {
		chooser.setFileSelectionMode(XFileChooser.DIRECTORIES_ONLY);
	    } else if(c == bothFilesAndDirectoriesButton) {
		chooser.setFileSelectionMode(XFileChooser.FILES_AND_DIRECTORIES);
	    } else {
		String lnfName = e.getActionCommand();

		try {
		    UIManager.setLookAndFeel(lnfName);
		    SwingUtilities.updateComponentTreeUI(frame);
		    if(chooser != null) {
			SwingUtilities.updateComponentTreeUI(chooser);
		    }
		    frame.pack();
		} catch (UnsupportedLookAndFeelException exc) {
		    System.out.println("Unsupported L&F Error:" + exc);
		    JRadioButton button = (JRadioButton)e.getSource();
		    button.setEnabled(false);
		    updateState();
		} catch (IllegalAccessException exc) {
		    System.out.println("IllegalAccessException Error:" + exc);
		} catch (ClassNotFoundException exc) {
		    System.out.println("ClassNotFoundException Error:" + exc);
		} catch (InstantiationException exc) {
		    System.out.println("InstantiateException Error:" + exc);
		}
	    }

	}
    }

    public void updateState() {
	String lnfName = UIManager.getLookAndFeel().getClass().getName();
	if (lnfName.indexOf(metal) >= 0) {
	    metalButton.setSelected(true);
	} else if (lnfName.indexOf(windows) >= 0) {
	    windowsButton.setSelected(true);
	} else if (lnfName.indexOf(motif) >= 0) {
	    motifButton.setSelected(true);
	} else {
	    System.err.println("FileChooserDemo if using an unknown L&F: " + lnfName);
	}
    }

    class FilePreviewer extends JComponent implements PropertyChangeListener {
	ImageIcon thumbnail = null;
	File f = null;

	public FilePreviewer(XFileChooser fc) {
	    setPreferredSize(new Dimension(100, 50));
	    fc.addPropertyChangeListener(this);
	}

	public void loadImage() {
	    if(f != null) {
		ImageIcon tmpIcon = new ImageIcon(f.getPath());
		if(tmpIcon.getIconWidth() > 90) {
		    thumbnail = new ImageIcon(
			tmpIcon.getImage().getScaledInstance(90, -1, Image.SCALE_DEFAULT));
		} else {
		    thumbnail = tmpIcon;
		}
	    }
	}

	public void propertyChange(PropertyChangeEvent e) {
	    String prop = e.getPropertyName();
	    if(prop == XFileChooser.SELECTED_FILE_CHANGED_PROPERTY) {
		f = (File) e.getNewValue();
		if(isShowing()) {
		    loadImage();
		    repaint();
		}
	    }
	}

	public void paint(Graphics g) {
	    if(thumbnail == null) {
		loadImage();
	    }
	    if(thumbnail != null) {
		int x = getWidth()/2 - thumbnail.getIconWidth()/2;
		int y = getHeight()/2 - thumbnail.getIconHeight()/2;
		if(y < 0) {
		    y = 0;
		}

		if(x < 5) {
		    x = 5;
		}
		thumbnail.paintIcon(this, g, x, y);
	    }
	}
    }

    public static void main(String s[]) {
	/*
	   NOTE: By default, the look and feel will be set to the
	   Cross Platform Look and Feel (which is currently Metal).
	   The user may someday be able to override the default
	   via a system property. If you as the developer want to
	   be sure that a particular L&F is set, you can do so
	   by calling UIManager.setLookAndFeel(). For example, the
	   first code snippet below forcibly sets the UI to be the
	   System Look and Feel. The second code snippet forcibly
	   sets the look and feel to the Cross Platform Look & Feel.

	   Snippet 1:
	   try {
	      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	   } catch (Exception exc) {
	      System.err.println("Error loading L&F: " + exc);
	   }

	   Snippet 2:
	   try {
	      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
	   } catch (Exception exc) {
	      System.err.println("Error loading L&F: " + exc);
	   }
	*/

	try {
	    // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
	} catch (Exception exc) {
	    System.err.println("Error loading L&F: " + exc);
	}

	FileChooserDemo panel = new FileChooserDemo();

	frame = new JFrame("FileChooserDemo");
	frame.addWindowListener(new WindowAdapter() {
	    public void windowClosing(WindowEvent e) {System.exit(0);}
	});
	frame.getContentPane().add("Center", panel);
	frame.pack();
	frame.setVisible(true);

	panel.updateState();
    }
}

ExampleFileFilter

This program is used by the XFileChooser demo program to filter files for display.


Example D-2 ExampleFileFilter

/*
 * @(#)ExampleFileFilter.java	1.2 99/04/18
 *
 * Copyright 1999 by Sun Microsystems, Inc.,
 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Sun Microsystems, Inc. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Sun.
 */


import java.io.File;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.swing.*;
import javax.swing.filechooser.*;

/**
 * A convenience implementation of FileFilter that filters out
 * all files except for those type extensions that it knows about.
 *
 * Extensions are of the type ".foo", which is typically found on
 * Windows and Unix boxes, but not on Macinthosh. Case is ignored.
 *
 * Example - create a new filter that filerts out all files
 * but gif and jpg image files:
 *
 *     JFileChooser chooser = new JFileChooser();
 *     ExampleFileFilter filter = new ExampleFileFilter(
 *                   new String{"gif", "jpg"}, "JPEG & GIF Images")
 *     chooser.addChoosableFileFilter(filter);
 *     chooser.showOpenDialog(this);
 *
 * @version 1.8 08/26/98
 * @author Jeff Dinkins
 */
public class ExampleFileFilter extends FileFilter {

    private static String TYPE_UNKNOWN = "Type Unknown";
    private static String HIDDEN_FILE = "Hidden File";

    private Hashtable filters = null;
    private String description = null;
    private String fullDescription = null;
    private boolean useExtensionsInDescription = true;

    /**
     * Creates a file filter. If no filters are added, then all
     * files are accepted.
     *
     * @see #addExtension
     */
    public ExampleFileFilter() {
	this.filters = new Hashtable();
    }

    /**
     * Creates a file filter that accepts files with the given extension.
     * Example: new ExampleFileFilter("jpg");
     *
     * @see #addExtension
     */
    public ExampleFileFilter(String extension) {
	this(extension,null);
    }

    /**
     * Creates a file filter that accepts the given file type.
     * Example: new ExampleFileFilter("jpg", "JPEG Image Images");
     *
     * Note that the "." before the extension is not needed. If
     * provided, it will be ignored.
     *
     * @see #addExtension
     */
    public ExampleFileFilter(String extension, String description) {
	this();
	if(extension!=null) addExtension(extension);
 	if(description!=null) setDescription(description);
    }

    /**
     * Creates a file filter from the given string array.
     * Example: new ExampleFileFilter(String {"gif", "jpg"});
     *
     * Note that the "." before the extension is not needed adn
     * will be ignored.
     *
     * @see #addExtension
     */
    public ExampleFileFilter(String[] filters) {
	this(filters, null);
    }

    /**
     * Creates a file filter from the given string array and description.
     * Example: new ExampleFileFilter(String {"gif", "jpg"}, "Gif and JPG Images");
     *
     * Note that the "." before the extension is not needed and will be ignored.
     *
     * @see #addExtension
     */
    public ExampleFileFilter(String[] filters, String description) {
	this();
	for (int i = 0; i < filters.length; i++) {
	    // add filters one by one
	    addExtension(filters[i]);
	}
 	if(description!=null) setDescription(description);
    }

    /**
     * Return true if this file should be shown in the directory pane,
     * false if it shouldn't.
     *
     * Files that begin with "." are ignored.
     *
     * @see #getExtension
     * @see FileFilter#accepts
     */
    public boolean accept(File f) {
	if(f != null) {
	    if(f.isDirectory()) {
		return true;
	    }
	    String extension = getExtension(f);
	    if(extension != null && filters.get(getExtension(f)) != null) {
		return true;
	    };
	}
	return false;
    }

    /**
     * Return the extension portion of the file's name .
     *
     * @see #getExtension
     * @see FileFilter#accept
     */
     public String getExtension(File f) {
	if(f != null) {
	    String filename = f.getName();
	    int i = filename.lastIndexOf('.');
	    if(i>0 && i
	    if(i>0 && i

ExampleFileView

This program is used by the XFileChooserDemo program to set the way a file in a file list is displayed by the file chooser.


Example D-3 ExampleFileView

/*
 * @(#)ExampleFileView.java	1.2 99/04/18
 *
 * Copyright 1999 by Sun Microsystems, Inc.,
 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Sun Microsystems, Inc. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Sun.
 */

import javax.swing.*;
import javax.swing.filechooser.*;

import java.io.File;
import java.util.Hashtable;

/**
 * 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.7 08/26/98
 * @author Jeff Dinkins
 */
public class ExampleFileView extends FileView {
    private Hashtable icons = new Hashtable(5);
    private Hashtable fileDescriptions = new Hashtable(5);
    private Hashtable typeDescriptions = new Hashtable(5);

    /**
     * The name of the file.  Do nothing special here. Let
     * the system file view handle this.
     * @see #setName
     * @see FileView#getName
     */
    public String getName(File f) {
	return null;
    }

    /**
     * Adds a human readable description of the file.
     */
    public void putDescription(File f, String fileDescription) {
	fileDescriptions.put(fileDescription, f);
    }

    /**
     * A human readable description of the file.
     *
     * @see FileView#getDescription
     */
    public String getDescription(File f) {
	return (String) fileDescriptions.get(f);
    };

    /**
     * Adds a human readable type description for files. Based on "dot"
     * extension strings, e.g: ".gif". Case is ignored.
     */
    public void putTypeDescription(String extension, String typeDescription) {
	typeDescriptions.put(typeDescription, extension);
    }

    /**
     * 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.
     */
    public void putTypeDescription(File f, String typeDescription) {
	putTypeDescription(getExtension(f), typeDescription);
    }

    /**
     * A human readable description of the type of the file.
     *
     * @see FileView#getTypeDescription
     */
    public String getTypeDescription(File f) {
	return (String) typeDescriptions.get(getExtension(f));
    }

    /**
     * Conveinience method that returnsa the "dot" extension for the
     * given file.
     */
    public String getExtension(File f) {
	String name = f.getName();
	if(name != null) {
	    int extensionIndex = name.lastIndexOf('.');
	    if(extensionIndex < 0) {
		return null;
	    }
	    return name.substring(extensionIndex+1).toLowerCase();
	}
	return null;
    }

    /**
     * Adds an icon based on the file type "dot" extension
     * string, e.g: ".gif". Case is ignored.
     */
    public void putIcon(String extension, Icon icon) {
	icons.put(extension, icon);
    }

    /**
     * Icon that reperesents this file. Default implementation returns
     * null. You might want to override this to return something more
     * interesting.
     *
     * @see FileView#getIcon
     */
    public Icon getIcon(File f) {
	Icon icon = null;
	String extension = getExtension(f);
	if(extension != null) {
	    icon = (Icon) icons.get(extension);
	}
	return icon;
    }

    /**
     * Whether the file is hidden or not. This implementation returns
     * true if the filename starts with a "."
     *
     * @see FileView#isHidden
     */
    public Boolean isHidden(File f) {
	String name = f.getName();
	if(name != null && !name.equals("") && name.charAt(0) == '.') {
	    return Boolean.TRUE;
	} else {
	    return Boolean.FALSE;
	}
    };

    /**
     * Whether the directory is traversable or not. Generic implementation
     * returns true for all directories.
     *
     * 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
     */
    public Boolean isTraversable(File f) {
	if(f.isDirectory()) {
	    return Boolean.TRUE;
	} else {
	    return Boolean.FALSE;
	}
    };

}