org.esa.beam.util.io
Class BeamFileFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by org.esa.beam.util.io.BeamFileFilter

public class BeamFileFilter
extends FileFilter

A FileFilter with file extensions support.

Version:
$Revision$ $Date$
Author:
Norman Fomferra

Nested Class Summary
static class BeamFileFilter.FileSelectionMode
          File selection modes.
 
Constructor Summary
BeamFileFilter()
           
BeamFileFilter(String formatName, String[] extensions, String description)
           
BeamFileFilter(String formatName, String extension, String description)
           
 
Method Summary
 boolean accept(File file)
          Tests whether or not the given file is accepted by this filter.
 boolean checkExtension(File file)
          Utility method which checks the extension the given file.
 boolean checkExtension(String filename)
          Utility method which checks the extension the given filename.
static boolean checkExtensions(String filename, String[] extensions)
          Utility method which checks the extension the given filename.
 String getDefaultExtension()
          Returns the default extension.
 String getDescription()
          Returns the description of this filter.
 String[] getExtensions()
          Returns the accepted extensions of this filter.
 BeamFileFilter.FileSelectionMode getFileSelectionMode()
          Gets the file selection mode for the BeamFileChooser if this filter is used.
 String getFormatName()
           
static
<T extends ProductIOPlugIn>
List<BeamFileFilter>
getSortedFileFilters(Iterator<T> pluginIterator)
          Return a alphabetically sorted list of file filters originating from a productIO plugin iterator.
 boolean hasExtensions()
          Returns whether or not this file filter has extensions.
 boolean isCompoundDocument(File dir)
          Checks if the given directory represents a compound document.
 void setDescription(String description)
          Returns the description of this filter.
 void setExtensions(String[] extensions)
          Sets the accepted extensions of this filter.
 void setFormatName(String formatName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeamFileFilter

public BeamFileFilter()

BeamFileFilter

public BeamFileFilter(String formatName,
                      String extension,
                      String description)

BeamFileFilter

public BeamFileFilter(String formatName,
                      String[] extensions,
                      String description)
Method Detail

getFormatName

public String getFormatName()

setFormatName

public void setFormatName(String formatName)

hasExtensions

public boolean hasExtensions()
Returns whether or not this file filter has extensions.

Returns:
true if so

getDefaultExtension

public String getDefaultExtension()
Returns the default extension. The default extension is the first entry in the array returned by the getExtensions method.

Returns:
the default extension or null if no extensions have bees specified.
See Also:
getExtensions()

getExtensions

public String[] getExtensions()
Returns the accepted extensions of this filter. For example: {".jpg", ".gif", ".png"}.

Returns:
The array of extensions.
See Also:
setExtensions(java.lang.String[])

setExtensions

public void setExtensions(String[] extensions)
Sets the accepted extensions of this filter. For example: {".jpg", ".gif", ".png"}.

Parameters:
extensions - The array of extensions.
See Also:
getExtensions()

getDescription

public String getDescription()
Returns the description of this filter. For example: "JPEG Images (*.jpg,*.jpeg)".

Specified by:
getDescription in class FileFilter
See Also:
FileView.getTypeDescription(java.io.File)

setDescription

public void setDescription(String description)
Returns the description of this filter. For example: "JPEG Images (*.jpg,*.jpeg)". If the extension list is missing in the description text, it is automatically appended.

Parameters:
description - The description, must not be null.
See Also:
getDescription()

checkExtension

public boolean checkExtension(File file)
Utility method which checks the extension the given file.

Parameters:
file - the file
Returns:
true if the given file path ends with one of the registered extensions, false otherwise.

checkExtension

public boolean checkExtension(String filename)
Utility method which checks the extension the given filename.

Parameters:
filename - the file name
Returns:
true if the given file name ends with one of the registered extensions, false otherwise.

checkExtensions

public static boolean checkExtensions(String filename,
                                      String[] extensions)
Utility method which checks the extension the given filename.

Parameters:
filename - the file name
extensions - the extension
Returns:
true if the given file name ends with one of the registered extensions, false otherwise.

accept

public boolean accept(File file)
Tests whether or not the given file is accepted by this filter. The default implementation returns true if the given file is a directory or the path string ends with one of the registered extensions. if no extension are defined, the method always returns true

Specified by:
accept in class FileFilter
Parameters:
file - the file to be or not be accepted.
Returns:
true if given file is accepted by this filter

isCompoundDocument

public boolean isCompoundDocument(File dir)
Checks if the given directory represents a compound document. If so, we don't want the user to descend into it when using the BeamFileChooser. The default implementation returns false. Clients may override.

Parameters:
dir - The directory to check.
Returns:
true If the given directory represents a compound document.
Since:
BEAM 4.6.1

getFileSelectionMode

public BeamFileFilter.FileSelectionMode getFileSelectionMode()
Gets the file selection mode for the BeamFileChooser if this filter is used. The default implementation returns BeamFileFilter.FileSelectionMode.FILES_ONLY. Clients may override.

Returns:
true if the user can also select directories using this filter.
Since:
BEAM 4.6.1

getSortedFileFilters

public static <T extends ProductIOPlugIn> List<BeamFileFilter> getSortedFileFilters(Iterator<T> pluginIterator)
Return a alphabetically sorted list of file filters originating from a productIO plugin iterator.

Parameters:
pluginIterator - a productIO plugin iterator
Returns:
a sorted list of file filters
Since:
BEAM 4.10


Copyright © 2002-2013 Brockmann Consult GmbH. All Rights Reserved.