com.pietschy.command.file
Class ExtensionFileFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by com.pietschy.command.file.ExtensionFileFilter

public class ExtensionFileFilter
extends javax.swing.filechooser.FileFilter

An implementation of FileFilter that is based on the extension of a file.

This filter is also capable of checking and adding the extension if it's missing. See checkAndAddExtension(File).

Version:
$Revision: 1.3 $
Author:
andrewp
See Also:
checkAndAddExtension(File)

Constructor Summary
ExtensionFileFilter(java.lang.String extension, java.lang.String description)
          Creates a new filter for the specified file extension with that has the specified description.
 
Method Summary
 boolean accept(java.io.File f)
          Accepts files that end with the specified extension.
 java.io.File checkAndAddExtension(java.io.File file)
          Checks that the specified file has an extension defined.
 java.lang.String getDescription()
          Gets this filters description
 boolean isIgnoreCase()
          Checks if this filter should ignore case
 void setIgnoreCase(boolean ignoreCase)
          Configures this filter to ignore case.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtensionFileFilter

public ExtensionFileFilter(java.lang.String extension,
                           java.lang.String description)
Creates a new filter for the specified file extension with that has the specified description.

Parameters:
extension - the file extension to excluding the preceeding '.', ie "java", not ".java".
description - the user friendly description of the file filter.
Method Detail

accept

public boolean accept(java.io.File f)
Accepts files that end with the specified extension.

Specified by:
accept in class javax.swing.filechooser.FileFilter
Parameters:
f - the file to check.
Returns:
true if the file name ends with this filters extension.

getDescription

public java.lang.String getDescription()
Gets this filters description

Specified by:
getDescription in class javax.swing.filechooser.FileFilter
Returns:
this filters description

isIgnoreCase

public boolean isIgnoreCase()
Checks if this filter should ignore case

Returns:
true if this filter should ignore case, false otherwise.

setIgnoreCase

public void setIgnoreCase(boolean ignoreCase)
Configures this filter to ignore case.

Parameters:
ignoreCase - true to ignore case, false otherwise.

checkAndAddExtension

public java.io.File checkAndAddExtension(java.io.File file)
Checks that the specified file has an extension defined. If it does, it is returned as is, even if the extension doesn't match that of the filter. If no extension is specified, a new file is returned based on the original but with the extension defined by this filter.

Parameters:
file - the file to check.
Returns:
a file guarenteed to have the extension specified by this filter.


Copyright © 2006 - 2007 Andrew Pietsch