JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.util.swing
Class JCFileFilter

java.lang.Object
  |
  +--javax.swing.filechooser.FileFilter
        |
        +--com.klg.jclass.util.swing.JCFileFilter
All Implemented Interfaces:
FileFilter

public class JCFileFilter
extends FileFilter
implements FileFilter

A convenience implementation of FileFilter that filters out all files except for those type extensions that it knows about.

Extensions are of the type .foo, which is typically found on Windows and Unix boxes, but not on Macintosh. Case is ignored.

Example - create a new filter that filters out all files but gif and jpg image files:

     JFileChooser chooser = new JFileChooser();
     JCFileFilter filter = new JCFileFilter(
                   new String{"gif", "jpg"}, "JPEG & GIF Images")
     chooser.addChoosableFileFilter(filter);
     chooser.showOpenDialog(this);
 


Field Summary
protected  Hashtable filters
           
 
Constructor Summary
JCFileFilter()
          Creates a file filter.
JCFileFilter(String extension)
          Creates a file filter that accepts files with the given extension.
Example: new JCFileFilter("jpg");
JCFileFilter(String[] filters)
          Creates a file filter from the given String array.
Example: new JCFileFilter(String {"gif", "jpg"});
JCFileFilter(String[] filters, String description)
          Creates a file filter from the given string array and description.
Example: new JCFileFilter(String {"gif", "jpg"}, "Gif and JPG Images");
JCFileFilter(String extension, String description)
          Creates a file filter that accepts the given file type.
Example: new JCFileFilter("jpg", "JPEG Image Images");
 
Method Summary
 boolean accept(File f)
          Returns true if this file should be shown in the directory pane; false if it shouldn't.
 void addExtension(String extension)
          Adds a filetype "dot" extension to filter against.
 String getDescription()
          Returns the human readable description of this filter.
 String getExtension(File f)
          Returns the extension portion of the file's name.
 String getExtension(String s)
          Returns the extension portion of a String.
 boolean isExtensionListInDescription()
          Returns whether the extension list (.jpg, .gif, etc) should show up in the human readable description.
 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
 

Field Detail

filters

protected Hashtable filters
Constructor Detail

JCFileFilter

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

See Also:
addExtension(java.lang.String)

JCFileFilter

public JCFileFilter(String extension)
Creates a file filter that accepts files with the given extension.
Example: new JCFileFilter("jpg");

Parameters:
extension -
See Also:
addExtension(java.lang.String)

JCFileFilter

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

Note: The "." before the extension is not needed. If provided, it will be ignored.

Parameters:
extension -
description -
See Also:
addExtension(java.lang.String)

JCFileFilter

public JCFileFilter(String[] filters)
Creates a file filter from the given String array.
Example: new JCFileFilter(String {"gif", "jpg"});

Note: The "." before the extension is not needed and will be ignored.

Parameters:
filters -
See Also:
addExtension(java.lang.String)

JCFileFilter

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

Note: The "." before the extension is not needed and will be ignored.

Parameters:
filters -
description -
See Also:
addExtension(java.lang.String)
Method Detail

accept

public boolean accept(File f)
Returns true if this file should be shown in the directory pane; false if it shouldn't.
Files that begin with "." are ignored.

Specified by:
accept in interface FileFilter
Specified by:
accept in class FileFilter
Parameters:
f -
Returns:
See Also:
getExtension(java.lang.String), FileFilter.accept(java.io.File)

getExtension

public String getExtension(String s)
Returns the extension portion of a String.

Parameters:
s -
Returns:
the extension portion of a String

getExtension

public String getExtension(File f)
Returns the extension portion of the file's name.

Parameters:
f -
Returns:
extension portion of the file's name
See Also:
getExtension(java.lang.String), FileFilter.accept(java.io.File)

addExtension

public void addExtension(String extension)
Adds a filetype "dot" extension to filter against.
For example: The following code will create a filter that filters out all files except those that end in ".jpg" and ".tif":
   JCFileFilter filter = new JCFileFilter();
   filter.addExtension("jpg");
   filter.addExtension("tif");
 

Note: The "." before the extension is not needed and will be ignored.

Parameters:
extension -

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
Returns:
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");

Parameters:
description -
See Also:
getDescription(), 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().

Parameters:
b -
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 relevant if a description was provided in the constructor or using setDescription().

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

Copyright © 2004 Quest Software Inc..
All rights reserved.