ikayaki.gui
Class GenericFileFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by ikayaki.gui.GenericFileFilter
All Implemented Interfaces:
FileFilter

public class GenericFileFilter
extends FileFilter
implements FileFilter

A FileFilter for a FileChooser. Can be used to show only some file types, determined by extension.

Author:
Esko Luontola

Field Summary
private  String description
          File type desription for the extensions.
private  String[] extensions
          Extensions to be shown.
 
Constructor Summary
GenericFileFilter(String description, String... extensions)
          Creates a new file filter for the specified file type.
 
Method Summary
 boolean accept(File pathname)
          Tests whether or not the specified abstract pathname should be included in a pathname list.
 String getDescription()
          Returns the file type description.
private static String getExtension(File f)
          Returns the extension of the given file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

extensions

private String[] extensions
Extensions to be shown.


description

private String description
File type desription for the extensions.

Constructor Detail

GenericFileFilter

public GenericFileFilter(String description,
                         String... extensions)
Creates a new file filter for the specified file type. The file extensions can have "." prefixes or not.

Parameters:
description - a description for the file type, or null to have no description.
extensions - the file extensions that should be shown, or null to accept no extensions.
Method Detail

accept

public boolean accept(File pathname)
Tests whether or not the specified abstract pathname should be included in a pathname list.

Specified by:
accept in interface FileFilter
Specified by:
accept in class FileFilter
Parameters:
pathname - the abstract pathname to be tested.
Returns:
true if and only if pathname should be included.

getExtension

private static String getExtension(File f)
Returns the extension of the given file.

Parameters:
f - the file which's extension is wanted
Returns:
the characters after the last dot in the file name

getDescription

public String getDescription()
Returns the file type description.

Specified by:
getDescription in class FileFilter