com.isti.util
Class IstiFileFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by com.isti.util.IstiFileFilter
All Implemented Interfaces:
java.io.FileFilter

public class IstiFileFilter
extends javax.swing.filechooser.FileFilter
implements java.io.FileFilter

A convenience implementation of FileFilter that filters out all files except for those type files that it knows about. Case is ignored. Example - create a new filter that filters out all files but gif and jpg image files: JFileChooser chooser = new JFileChooser(); IstiFileFilter filter = new IstiFileFilter( new String[]{"*.gif", "*.jpg"}, "JPEG & GIF Images") chooser.addChoosableFileFilter(filter); chooser.showOpenDialog(this);


Field Summary
protected static boolean DEBUG_FLAG
           
protected static java.lang.String WC_STRING
           
 
Constructor Summary
IstiFileFilter()
          Creates a file filter.
IstiFileFilter(java.lang.String filter)
          Creates a file filter that accepts the given file type.
IstiFileFilter(java.lang.String[] filters, java.lang.String description)
          Creates a file filter from the given string array and description.
IstiFileFilter(java.lang.String filter, java.lang.String description)
          Creates a file filter that accepts the given file type.
 
Method Summary
 boolean accept(java.io.File f)
          Determines if this file should be shown in the directory pane.
 void addFilter(java.lang.String filter)
          Adds a filetype filter to filter against.
static java.io.FileFilter createFileFilter(java.lang.String filter)
          Create the file filter for the specified filter string.
 java.lang.String getDescription()
          Returns the human readable description of this filter.
static java.lang.String getExtension(java.lang.String s)
          Gets the extension portion of the string.
static java.lang.String getPrefix(java.lang.String s)
          Gets the prefix portion of the string.
protected static boolean hasMultipleWildcards(java.lang.String filter)
          Determines if the filter has multiple wildcards.
protected static boolean hasWildcards(java.lang.String filter)
          Determines if the filter has wildcards.
 boolean isAcceptingDirectories()
          Determines if directories should always be accepted.
 boolean isFilterListInDescription()
          Determines whether the filter list (*.jpg, *.gif, etc) should show up in the human readable description.
 void setAcceptDirectories(boolean b)
          Select if directories should always be accepted.
 void setDescription(java.lang.String description)
          Sets the human readable description of this filter.
 void setFilterListInDescription(boolean b)
          Determines whether the filter list (*.jpg, *.gif, etc) should show up in the human readable description.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG_FLAG

protected static final boolean DEBUG_FLAG
See Also:
Constant Field Values

WC_STRING

protected static final java.lang.String WC_STRING
See Also:
Constant Field Values
Constructor Detail

IstiFileFilter

public IstiFileFilter()
Creates a file filter. If no filters are added, then all files are accepted.

See Also:
addFilter(java.lang.String), By default all directories are accepted to allow directory traversal with file choosers., isAcceptingDirectories, setAcceptDirectories

IstiFileFilter

public IstiFileFilter(java.lang.String filter)
Creates a file filter that accepts the given file type. Example: new IstiFileFilter("*.jpg");

Parameters:
filter - filter file string
See Also:
addFilter(java.lang.String), FileFilter, By default directories are not accepted for use with FileUtils.listFiles., FileUtils.listFiles, isAcceptingDirectories, If a simple "java.io.FileFilter" is needed the 'createFileFilter' method may be used., createFileFilter

IstiFileFilter

public IstiFileFilter(java.lang.String filter,
                      java.lang.String description)
Creates a file filter that accepts the given file type. Example: new IstiFileFilter("*.jpg", "JPEG Image Images");

Parameters:
filter - filter file string.
description - file description, or null for none.
See Also:
addFilter(java.lang.String), FileFilter, By default all directories are accepted to allow directory traversal with file choosers., isAcceptingDirectories, setAcceptDirectories

IstiFileFilter

public IstiFileFilter(java.lang.String[] filters,
                      java.lang.String description)
Creates a file filter from the given string array and description. Example: new IstiFileFilter(String {"*.gif", "*.jpg"}, "Gif and JPG Images");

Parameters:
filters - array of filter file string.
description - file description, or null for none.
See Also:
addFilter(java.lang.String)
Method Detail

isAcceptingDirectories

public boolean isAcceptingDirectories()
Determines if directories should always be accepted.

Returns:
true if always accepting directories.

setAcceptDirectories

public void setAcceptDirectories(boolean b)
Select if directories should always be accepted.

Parameters:
b - true if always accepting directories

accept

public boolean accept(java.io.File f)
Determines if this file should be shown in the directory pane.

Specified by:
accept in interface java.io.FileFilter
Specified by:
accept in class javax.swing.filechooser.FileFilter
Parameters:
f - file
Returns:
true if this file should be shown in the directory pane, false if it shouldn't.
See Also:
#getFilter, FileFilter#accepts

getExtension

public static java.lang.String getExtension(java.lang.String s)
Gets the extension portion of the string.

Parameters:
s - file name string
Returns:
the extension portion of the string.
See Also:
FileFilter#accept

getPrefix

public static java.lang.String getPrefix(java.lang.String s)
Gets the prefix portion of the string.

Parameters:
s - file name string
Returns:
the prefix portion of the string.
See Also:
FileFilter#accept

addFilter

public void addFilter(java.lang.String filter)
Adds a filetype filter to filter against.

Parameters:
filter - filter file string For example: the following code will create a filter that filters out all files except those that end in "jpg" and "tif": IstiFileFilter filter = new IstiFileFilter(); filter.addFilter("*.jpg"); filter.addFilter("*.tif");

getDescription

public java.lang.String getDescription()
Returns the human readable description of this filter. For example: "JPEG and GIF Image Files (*.jpg, *.gif)"

Specified by:
getDescription in class javax.swing.filechooser.FileFilter
Returns:
the human readable description of this filter
See Also:
setDescription, setFilterListInDescription, isFilterListInDescription, FileFilter#getDescription

setDescription

public void setDescription(java.lang.String description)
Sets the human readable description of this filter.

Parameters:
description - file description. For example: filter.setDescription("Gif and JPG Images");
See Also:
setDescription, setFilterListInDescription, isFilterListInDescription

setFilterListInDescription

public void setFilterListInDescription(boolean b)
Determines whether the filter list (*.jpg, *.gif, etc) should show up in the human readable description.

Parameters:
b - true if the filter list should show up. Only relevent if a description was provided in the constructor or using setDescription();
See Also:
getDescription, setDescription, isFilterListInDescription

isFilterListInDescription

public boolean isFilterListInDescription()
Determines whether the filter list (*.jpg, *.gif, etc) should show up in the human readable description.

Returns:
true if the filter list (*.jpg, *.gif, etc) should show up in the human readable description, false otherwise. Only relevent if a description was provided in the constructor or using setDescription();
See Also:
getDescription, setDescription, setFilterListInDescription

hasWildcards

protected static boolean hasWildcards(java.lang.String filter)
Determines if the filter has wildcards.

Parameters:
filter - filter file string
Returns:
true if the filter has wildcards.

hasMultipleWildcards

protected static boolean hasMultipleWildcards(java.lang.String filter)
Determines if the filter has multiple wildcards.

Parameters:
filter - filter file string
Returns:
true if the filter has multiple wildcards.

createFileFilter

public static java.io.FileFilter createFileFilter(java.lang.String filter)
Create the file filter for the specified filter string.

Parameters:
filter - filter file string ("*.txt", "temp.*", "temp.txt", "*bak*")
Returns:
the file filter.