org.proteinshader.gui.utils
Class FileExtensionFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by org.proteinshader.gui.utils.FileExtensionFilter

public class FileExtensionFilter
extends FileFilter

Checks if a filename has an extension.

The extension must have at least one more character after the final dot in the filename, and is usually has three or four characters after the final dot.

Java's class javax.swing.filechooser.FileFilter is abstract and requires a subclass to define a boolean accept( File ) method and a getDescription() method. An example of how to create a FileFilter for image files can be found at Filtering the List of Files in the sun tutorial pages.


Field Summary
static String DEFAULT_EXTENSION
           
 
Constructor Summary
FileExtensionFilter()
          Constructs a FileExtensionFilter using the default file extension.
FileExtensionFilter(String extension)
          Constructs a FileExtensionFilter.
 
Method Summary
 boolean accept(File file)
          Returns true if the file is a directory or has a ".png" extension.
 String getDescription()
          Returns a description of the supported file type.
 String getFilenameExtension(File file)
          Obtains the filename extension (the dot plus the letters after the dot) if it exists and returns it as the dot followed by lowercase letters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EXTENSION

public static final String DEFAULT_EXTENSION
See Also:
Constant Field Values
Constructor Detail

FileExtensionFilter

public FileExtensionFilter()
Constructs a FileExtensionFilter using the default file extension.


FileExtensionFilter

public FileExtensionFilter(String extension)
Constructs a FileExtensionFilter. If the extension given as an argument does not already begin with a dot, then a dot will be added. There must be at least one character after the beginning dot. Otherwise, the default extension will be used.

Parameters:
extension - the file extension to use.
Method Detail

getDescription

public String getDescription()
Returns a description of the supported file type.

Specified by:
getDescription in class FileFilter

accept

public boolean accept(File file)
Returns true if the file is a directory or has a ".png" extension. Otherwise, returns false.

Specified by:
accept in class FileFilter
Parameters:
file - the file to test.
Returns:
True for a directory or a file ending in ".png".

getFilenameExtension

public String getFilenameExtension(File file)
Obtains the filename extension (the dot plus the letters after the dot) if it exists and returns it as the dot followed by lowercase letters.

Parameters:
file - the file to get the filename extension from.
Returns:
The file extension (or null if it does not exist).


Copyright © 2007-2008