FreeHEP API
Version current

org.freehep.swing
Class ExtensionFileFilter

java.lang.Object
  extended byjavax.swing.filechooser.FileFilter
      extended byorg.freehep.swing.ExtensionFileFilter

public class ExtensionFileFilter
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. You may add extensions with or without the leading dot. The comparison always uses the leading dot. Long extensions such as ".heprep.zip" are also allowed. Example - create a new filter that filerts out all files but gif and jpg image files:

     JFileChooser chooser = new JFileChooser();
     ExtensionFileFilter filter = new ExtensionFileFilter(
                   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.

Version:
$Id: ExtensionFileFilter.java,v 1.3 2003/10/10 21:47:31 duns Exp $
Author:
Charles A. Loomis, Jr., Mark Donszelmann
Source Code:
ExtensionFileFilter.java

Constructor Summary
ExtensionFileFilter()
          Creates a file filter.
ExtensionFileFilter(String extension)
          Creates a file filter that accepts files with the given ending.
ExtensionFileFilter(String[] filters)
          Creates a file filter from the array of given endings.
ExtensionFileFilter(String[] filters, String description)
          Creates a file filter from the given string array and description.
ExtensionFileFilter(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 extension to filter against.
 String getDescription()
          Returns the human readable description of this filter.
 String getExtension(File f)
          Returns the extension portion of the files name (if part of this file 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

ExtensionFileFilter

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

See Also:
addExtension(java.lang.String)

ExtensionFileFilter

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

See Also:
addExtension(java.lang.String)

ExtensionFileFilter

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

See Also:
addExtension(java.lang.String)

ExtensionFileFilter

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

See Also:
addExtension(java.lang.String)

ExtensionFileFilter

public ExtensionFileFilter(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.

See Also:
FileFilter.accept(java.io.File)

match

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


getExtension

public String getExtension(File f)
Returns the extension portion of the files name (if part of this file filter).

Returns:
extension including leading ".", or null if not found in filter.

addExtension

public void addExtension(String extension)
Adds an extension to filter against. Leading "." is not mandatory.


getDescription

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

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 current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.