Package org.esa.snap.core.util.io
Class SnapFileFilter
- java.lang.Object
-
- javax.swing.filechooser.FileFilter
-
- org.esa.snap.core.util.io.SnapFileFilter
-
- Direct Known Subclasses:
DimapFileFilter
public class SnapFileFilter extends FileFilter
AFileFilter
with file extensions support.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SnapFileFilter.FileSelectionMode
File selection modes.
-
Constructor Summary
Constructors Constructor Description SnapFileFilter()
SnapFileFilter(String formatName, String[] extensions, String description)
SnapFileFilter(String formatName, String extension, String description)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.boolean
equals(Object o)
String
getDefaultExtension()
Returns the default extension.String
getDescription()
Returns the description of this filter.String[]
getExtensions()
Returns the accepted extensions of this filter.SnapFileFilter.FileSelectionMode
getFileSelectionMode()
Gets the file selection mode for theJFileChooser
if this filter is used.String
getFormatName()
static <T extends ProductIOPlugIn>
List<SnapFileFilter>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.int
hashCode()
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)
-
-
-
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 thegetExtensions
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 classFileFilter
- 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 nameextensions
- 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 returnstrue
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 returnstrue
- Specified by:
accept
in classFileFilter
- 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 theJFileChooser
. The default implementation returnsfalse
. 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 SnapFileFilter.FileSelectionMode getFileSelectionMode()
Gets the file selection mode for theJFileChooser
if this filter is used. The default implementation returnsSnapFileFilter.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<SnapFileFilter> 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
-
-