Class BasicFileFilter
java.lang.Object
javax.swing.filechooser.FileFilter
uk.ac.starlink.util.gui.BasicFileFilter
- All Implemented Interfaces:
FilenameFilter
A FileFilter for configuring a
JFileChooser to only show
files that have one of a set of file extensions. Also implements
FilenameFilter to provide similar services for filtering directory
contents using the File class
(see File.listFiles()).
Example - create filters for HDS and FITS files and use with a BasicFileChooser.
BasicFileChooser chooser = new BasicFileChooser();
BasicFileFilter fitsFilter = new BasicFileFilter(
new String{ "fit", "fits" }, "FITS files" )
chooser.addChoosableFileFilter( fitsFilter );
BasicFileFilter hdsFilter =
new BasicFileFilter( "hds", "HDS container files" );
chooser.addChoosableFileFilter( hdsFilter );
chooser.showOpenDialog( this );
Example - filter the files in a directory.
BasicFileFilter idsFilter = new BasicFileFilter( "ids" ); File dir = new File( "." ); File[] files = dir.listFiles( idsFilter );
- Version:
- $Id$
- Author:
- Jeff Dinkins, Peter W. Draper
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a file filter.BasicFileFilter(String extension) Creates a file filter that accepts files with the given extension.BasicFileFilter(String[] filters) Creates a file filter from the given string array.BasicFileFilter(String[] filters, String description) Creates a file filter from the given string array and description.BasicFileFilter(String extension, String description) Creates a file filter that accepts the given file type. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturn true if this file should be shown in the directory pane, false if it shouldn't.booleanvoidaddExtension(String extension) Adds a filetype "dot" extension to filter against.Returns the human readable description of this filter.static StringgetExtension(File f) Return the extension of a file's name.static StringgetExtension(String name) Return the extension of a file's name.booleanReturns whether the extension list (.jpg, .gif, etc) should show up in the human readable description.voidsetDescription(String description) Sets the human readable description of this filter.voidsetExtensionListInDescription(boolean b) Determines whether the extension list (.jpg, .gif, etc) should show up in the human readable description.
-
Constructor Details
-
BasicFileFilter
public BasicFileFilter()Creates a file filter. If no filters are added, then all files are accepted.- See Also:
-
BasicFileFilter
Creates a file filter that accepts files with the given extension. Example: new BasicFileFilter("jpg");- See Also:
-
BasicFileFilter
-
BasicFileFilter
Creates a file filter from the given string array. Example: new BasicFileFilter(String {"gif", "jpg"}); Note that the "." before the extension is not needed and will be ignored.- See Also:
-
BasicFileFilter
-
-
Method Details
-
accept
Return true if this file should be shown in the directory pane, false if it shouldn't. Files that begin with "." are ignored.- Specified by:
acceptin classFileFilter- See Also:
-
getExtension
-
getExtension
-
addExtension
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": BasicFileFilter filter = new BasicFileFilter(); filter.addExtension("jpg"); filter.addExtension("tif"); Note that the "." before the extension is not needed and will be ignored. -
getDescription
Returns the human readable description of this filter. For example: "JPEG and GIF Image Files (*.jpg, *.gif)"- Specified by:
getDescriptionin classFileFilter
-
setDescription
Sets the human readable description of this filter. For example: filter.setDescription("Gif and JPG Images"); -
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(); -
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(); -
accept
- Specified by:
acceptin interfaceFilenameFilter
-