FreeHEP API
Version v1.2

org.freehep.swing
Class EndingFileFilter

java.lang.Object
  |
  +--javax.swing.filechooser.FileFilter
        |
        +--org.freehep.swing.EndingFileFilter

public class EndingFileFilter
extends FileFilter

A FileFilter which filters out all files except those which end with the given tag. This filter is case sensitive and the string is compared literally. That is, if you want the string to contain ".jpg" you must include the dot. Example - create a new filter that filerts out all files but gif and jpg image files:

     JFileChooser chooser = new JFileChooser();
     EndingFileFilter filter = new EndingFileFilter(
                   new String{".gif", ".jpg"}, "JPEG & GIF Images")
     chooser.addChoosableFileFilter(filter);
     chooser.showOpenDialog(this);
 
Based on the ExtensionFileFilter written by Jeff Dinkins and provided by Sun.

Author:
Charles A. Loomis, Jr.

Constructor Summary
EndingFileFilter()
          Creates a file filter.
EndingFileFilter(String extension)
          Creates a file filter that accepts files with the given ending.
EndingFileFilter(String[] filters)
          Creates a file filter from the array of given endings.
EndingFileFilter(String[] filters, String description)
          Creates a file filter from the given string array and description.
EndingFileFilter(String extension, String description)
          Creates a file filter that accepts the files with the given endings.
 
Method Summary
 boolean accept(File f)
          Return true if this file should be shown in the directory pane, false if it shouldn't.
 void addExtension(String extension)
          Adds an ending to filter against.
 String getDescription()
          Returns the human readable description of this filter.
 boolean isExtensionListInDescription()
          Returns whether the extension list (.jpg, .gif, etc) should show up in the human readable description.
protected  boolean match(File f)
          This determines if the file matches any of the extensions.
 void setDescription(String description)
          Sets the human readable description of this filter.
 void setExtensionListInDescription(boolean b)
          Determines whether the extension 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
 

Constructor Detail

EndingFileFilter

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

See Also:
addExtension(java.lang.String)

EndingFileFilter

public EndingFileFilter(String extension)
Creates a file filter that accepts files with the given ending.

See Also:
addExtension(java.lang.String)

EndingFileFilter

public EndingFileFilter(String extension,
                        String description)
Creates a file filter that accepts the files with the given endings.

See Also:
addExtension(java.lang.String)

EndingFileFilter

public EndingFileFilter(String[] filters)
Creates a file filter from the array of given endings.

See Also:
addExtension(java.lang.String)

EndingFileFilter

public EndingFileFilter(String[] filters,
                        String description)
Creates a file filter from the given string array and description.

See Also:
addExtension(java.lang.String)
Method Detail

accept

public boolean accept(File f)
Return true if this file should be shown in the directory pane, false if it shouldn't.

Specified by:
accept in class FileFilter
See Also:
FileFilter.accept(java.io.File)

match

protected boolean match(File f)
This determines if the file matches any of the extensions.


addExtension

public void addExtension(String extension)
Adds an ending to filter against.


getDescription

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

Specified by:
getDescription in class FileFilter
See Also:
setDescription(java.lang.String), setExtensionListInDescription(boolean), isExtensionListInDescription(), FileFilter.getDescription()

setDescription

public void setDescription(String description)
Sets the human readable description of this filter. For example: filter.setDescription("Gif and JPG Images");

See Also:
setDescription(java.lang.String), setExtensionListInDescription(boolean), isExtensionListInDescription()

setExtensionListInDescription

public void setExtensionListInDescription(boolean b)
Determines whether the extension list (.jpg, .gif, etc) should show up in the human readable description. Only relevent if a description was provided in the constructor or using setDescription();

See Also:
getDescription(), setDescription(java.lang.String), isExtensionListInDescription()

isExtensionListInDescription

public boolean isExtensionListInDescription()
Returns whether the extension list (.jpg, .gif, etc) should show up in the human readable description. Only relevent if a description was provided in the constructor or using setDescription();

See Also:
getDescription(), setDescription(java.lang.String), setExtensionListInDescription(boolean)

FreeHEP API
Version v1.2

Copyright © 2000-2003 FreeHEP, All Rights Reserved.