ncsa.hdf.view
Class DefaultFileFilter

java.lang.Object
  extended byjavax.swing.filechooser.FileFilter
      extended byncsa.hdf.view.DefaultFileFilter

public class DefaultFileFilter
extends javax.swing.filechooser.FileFilter

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


Constructor Summary
DefaultFileFilter()
          Creates a file filter.
DefaultFileFilter(java.lang.String extension)
          Creates a file filter that accepts files with the given extension.
DefaultFileFilter(java.lang.String[] filters)
          Creates a file filter from the given string array.
DefaultFileFilter(java.lang.String[] filters, java.lang.String description)
          Creates a file filter from the given string array and description.
DefaultFileFilter(java.lang.String extension, java.lang.String description)
          Creates a file filter that accepts the given file type.
 
Method Summary
 boolean accept(java.io.File f)
          Return true if this file should be shown in the directory pane, false if it shouldn't.
 void addExtension(java.lang.String extension)
          Adds a filetype "dot" extension to filter against.
 java.lang.String getDescription()
          Returns the human readable description of this filter.
 java.lang.String getExtension(java.io.File f)
          Return the extension portion of the file's name .
static javax.swing.filechooser.FileFilter getFileFilter()
          Return a file filter for HDF4/5 file.
static javax.swing.filechooser.FileFilter getFileFilterHDF4()
          Return a file filter for HDF4 file.
static javax.swing.filechooser.FileFilter getFileFilterHDF5()
          Return a file filter for HDF5 file.
static javax.swing.filechooser.FileFilter getFileFilterJPEG()
          Return a file filter for JPEG image file.
static javax.swing.filechooser.FileFilter getFileFilterPNG()
          Return a file filter for PNG image file.
static javax.swing.filechooser.FileFilter getFileFilterText()
          Return a file filter for text file.
static javax.swing.filechooser.FileFilter getFileFilterTIFF()
          Return a file filter for TIFF image file.
static byte[] getHDF5UserBlock(java.lang.String filename)
          Read HDF5 user block data into byte array.
 boolean isExtensionListInDescription()
          Returns whether the extension list (.jpg, .gif, etc) should show up in the human readable description.
static boolean isHDF4(java.lang.String filename)
          look at the first 4 bytes of the file to see if it is an HDF4 file.
static boolean isHDF5(java.lang.String filename)
          look at the first 8 bytes of the file to see if it is an HDF5 file.
static boolean isNetcdf(java.lang.String filename)
          look at the first 4 bytes of the file to see if it is a netCDF file byte[0]=67, byte[1]=68, byte[2]=70, byte[3]=1 or
 void setDescription(java.lang.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.
static boolean setHDF5UserBlock(java.lang.String fin, java.lang.String fout, byte[] buf)
          Write HDF5 user block data into byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFileFilter

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

See Also:
addExtension(java.lang.String)

DefaultFileFilter

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

See Also:
addExtension(java.lang.String)

DefaultFileFilter

public DefaultFileFilter(java.lang.String extension,
                         java.lang.String description)
Creates a file filter that accepts the given file type. Example: new DefaultFileFilter("jpg", "JPEG Image Images"); Note that the "." before the extension is not needed. If provided, it will be ignored.

See Also:
addExtension(java.lang.String)

DefaultFileFilter

public DefaultFileFilter(java.lang.String[] filters)
Creates a file filter from the given string array. Example: new DefaultFileFilter(String {"gif", "jpg"}); Note that the "." before the extension is not needed adn will be ignored.

See Also:
addExtension(java.lang.String)

DefaultFileFilter

public DefaultFileFilter(java.lang.String[] filters,
                         java.lang.String description)
Creates a file filter from the given string array and description. Example: new DefaultFileFilter(String {"gif", "jpg"}, "Gif and JPG Images"); Note that the "." before the extension is not needed and will be ignored.

See Also:
addExtension(java.lang.String)
Method Detail

accept

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

See Also:
getExtension(java.io.File), FileFilter#accepts

getExtension

public java.lang.String getExtension(java.io.File f)
Return the extension portion of the file's name .

See Also:
getExtension(java.io.File), FileFilter.accept(java.io.File)

addExtension

public void addExtension(java.lang.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": DefaultFileFilter filter = new DefaultFileFilter(); filter.addExtension("jpg"); filter.addExtension("tif"); or filter.addExtension("jpg, tif"); Note that the "." before the extension is not needed and will be ignored.


getDescription

public java.lang.String getDescription()
Returns the human readable description of this filter. For example: "JPEG and GIF Image Files (*.jpg, *.gif)"

See Also:
setDescription, setExtensionListInDescription, isExtensionListInDescription, FileFilter.getDescription()

setDescription

public void setDescription(java.lang.String description)
Sets the human readable description of this filter. For example: filter.setDescription("Gif and JPG Images");

See Also:
setDescription, setExtensionListInDescription, 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();

See Also:
getDescription, setDescription, isExtensionListInDescription

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();

See Also:
getDescription, setDescription, setExtensionListInDescription

getFileFilter

public static javax.swing.filechooser.FileFilter getFileFilter()
Return a file filter for HDF4/5 file.


getFileFilterHDF4

public static javax.swing.filechooser.FileFilter getFileFilterHDF4()
Return a file filter for HDF4 file.


getFileFilterHDF5

public static javax.swing.filechooser.FileFilter getFileFilterHDF5()
Return a file filter for HDF5 file.


getFileFilterJPEG

public static javax.swing.filechooser.FileFilter getFileFilterJPEG()
Return a file filter for JPEG image file.


getFileFilterTIFF

public static javax.swing.filechooser.FileFilter getFileFilterTIFF()
Return a file filter for TIFF image file.


getFileFilterPNG

public static javax.swing.filechooser.FileFilter getFileFilterPNG()
Return a file filter for PNG image file.


getFileFilterText

public static javax.swing.filechooser.FileFilter getFileFilterText()
Return a file filter for text file.


isHDF4

public static boolean isHDF4(java.lang.String filename)
look at the first 4 bytes of the file to see if it is an HDF4 file. byte[0]=14, byte[1]=3, byte[2]=19, byte[3]=1 or if it is a netCDF file byte[0]=67, byte[1]=68, byte[2]=70, byte[3]=1 or


isHDF5

public static boolean isHDF5(java.lang.String filename)
look at the first 8 bytes of the file to see if it is an HDF5 file. byte[0]=-199 which is 137 in unsigned byte, byte[1]=72, byte[2]=68, byte[3]=70, byte[4]=13, byte[5]=10, byte[6]=26, byte[7]=10


isNetcdf

public static boolean isNetcdf(java.lang.String filename)
look at the first 4 bytes of the file to see if it is a netCDF file byte[0]=67, byte[1]=68, byte[2]=70, byte[3]=1 or


getHDF5UserBlock

public static byte[] getHDF5UserBlock(java.lang.String filename)
Read HDF5 user block data into byte array.

Returns:
a byte array of user block, or null if there is user data.

setHDF5UserBlock

public static boolean setHDF5UserBlock(java.lang.String fin,
                                       java.lang.String fout,
                                       byte[] buf)
Write HDF5 user block data into byte array.

Returns:
a byte array of user block, or null if there is user data.