HiRISE

HiRISE.HiPlan.IO
Class Basic_Filename_Filter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by HiRISE.HiPlan.IO.Basic_Filename_Filter
All Implemented Interfaces:
FilenameFilter

public class Basic_Filename_Filter
extends FileFilter
implements FilenameFilter

A filename filter that uses filename extensions. An instance of this class contains a user-configurable list of extensions. As a FilenameFilter, these extensions are used in comparison tests to filter directory listings in the list methods of the File class and by the AWT FileDialog component. As a FileFilter, they are used by the Swing JFileChooser.

Note: the "." before the extension is not needed. If provided, it will be ignored. Furthermore, all comparisons are performed in a case-insensitive manner (by coercing extensions to lowercase).

Version:
1.8
Author:
Christian Schaller - UA/PIRL
See Also:
Regex_Filename_Filter

Field Summary
static Basic_Filename_Filter CSV
           
static String ID
          Class identification name with source code version and date.
static Basic_Filename_Filter PTF
           
static Basic_Filename_Filter TEXT
           
 
Constructor Summary
Basic_Filename_Filter()
          Creates a new filter with an empty extension list and no description.
Basic_Filename_Filter(String[] extensions, String description)
          Creates a new filter with the specified set of extensions and the given description.
Basic_Filename_Filter(String extension, String description)
          Creates a new filter with the single specified extension and the given description.
 
Method Summary
 boolean accept(File file)
          Tests whether the specified file is accepted by this filter.
 boolean accept(File directory, String name)
          Tests whether the specified file is accepted by this filter.
 void addExtension(String extension)
          Adds a single extension to the list of extensions currently used by this filter.
 String description()
          Deprecated. Use getDescription() instead.
 void description(String description)
          Deprecated. Use setDescription(String) instead.
 String[] extensions()
          Deprecated. Use getExtensions() instead.
 void extensions(String[] extensions)
          Deprecated. Use setExtensions(String[]) instead.
 String getDescription()
          Gets the description of this filter.
 String[] getExtensions()
          Gets the list of extensions currently used by the filter.
 String removeExtension(String extension)
          Removes a single extension from the list of extensions currently used by this filter.
 void setDescription(String description)
          Sets the description of this filter.
 void setExtensions(String... extensions)
          Sets the list of extensions currently used by this filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

public static final String ID
Class identification name with source code version and date.

See Also:
Constant Field Values

PTF

public static final Basic_Filename_Filter PTF

CSV

public static final Basic_Filename_Filter CSV

TEXT

public static final Basic_Filename_Filter TEXT
Constructor Detail

Basic_Filename_Filter

public Basic_Filename_Filter()
Creates a new filter with an empty extension list and no description.


Basic_Filename_Filter

public Basic_Filename_Filter(String extension,
                             String description)
Creates a new filter with the single specified extension and the given description.

Parameters:
extension - a filename extension; may be null.
description - the description of this filter; may be null.

Basic_Filename_Filter

public Basic_Filename_Filter(String[] extensions,
                             String description)
Creates a new filter with the specified set of extensions and the given description.

Parameters:
extensions - a set of filename extensions; may be null.
description - the description of this filter; may be null.
Method Detail

getExtensions

public String[] getExtensions()
Gets the list of extensions currently used by the filter. The extensions will be lowercase; the filter itself is not case sensitive.

Returns:
the extensions this filter uses; or null if the filter has no extensions.

setExtensions

public void setExtensions(String... extensions)
Sets the list of extensions currently used by this filter. Any pre-existing extensions are removed in the process.

Parameters:
extensions - the extensions this filter is to use; if this value is null, all extensions will be removed and the filter will accept all filenames.

getDescription

public String getDescription()
Gets the description of this filter.

Specified by:
getDescription in class FileFilter
Returns:
the description of this filter.

setDescription

public void setDescription(String description)
Sets the description of this filter.

Parameters:
description - the new description of this filter.

accept

public boolean accept(File file)
Tests whether the specified file is accepted by this filter. If the file is accepted (i.e., if this method returns true), the file will be listed.

If file is null, this method returns false.

If file is a directory, this method returns true.

If this filter's list of extensions is empty, this method returns true.

If file's extension matches any of this filter's extensions, this method returns true.

Otherwise, this method returns false, including the case where the file's name has no extension.

Specified by:
accept in class FileFilter
Parameters:
file - the file in question.
Returns:
true if the file's extension is in the filter's list; false otherwise.

accept

public boolean accept(File directory,
                      String name)
Tests whether the specified file is accepted by this filter. If the file is accepted (i.e., if this method returns true), the file will be listed.

If name is null, this method returns false.

If this filter's list of extensions is empty, this method returns true.

If name's extension matches any of this filter's extensions, this method returns true.

Otherwise, this method returns false, including the case where the file's name has no extension.

Specified by:
accept in interface FilenameFilter
Parameters:
directory - the directory in which the file was found.
name - the file's name.
Returns:
true if the filename extension is in the filter's list; false otherwise.

addExtension

public void addExtension(String extension)
Adds a single extension to the list of extensions currently used by this filter. If extension is null, this method does nothing.

Note that the extension parameter is converted to lowercase, and everything up to an including the final "." is stripped from it before being added to the list.

Parameters:
extension - the extension to add to the list of extensions; may be null.

removeExtension

public String removeExtension(String extension)
Removes a single extension from the list of extensions currently used by this filter. Note that the input extension parameter is converted to lowercase, and everything up to an including the final "." is stripped from it before testing whether it is included in the list of extensions.

Parameters:
extension - the extension to remove from the list of extensions; may be null.
Returns:
the extension removed or null if the extension did not exist in the list.

extensions

@Deprecated
public String[] extensions()
Deprecated. Use getExtensions() instead.


extensions

@Deprecated
public void extensions(String[] extensions)
Deprecated. Use setExtensions(String[]) instead.


description

@Deprecated
public String description()
Deprecated. Use getDescription() instead.


description

@Deprecated
public void description(String description)
Deprecated. Use setDescription(String) instead.


HiRISE

Copyright (C) Arizona Board of Regents on behalf of the Planetary Image Research Laboratory, Lunar and Planetary Laboratory at the University of Arizona