ncsa.hdf.view
Class DefaultFileFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by ncsa.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.

Version:
2.4 9/6/2007
Author:
Peter X. Cao

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 getFileFilterBinary()
          Return a file filter for binary file.
static javax.swing.filechooser.FileFilter getFileFilterBMP()
          Return a file filter for BMP image files.
static javax.swing.filechooser.FileFilter getFileFilterGIF()
          Return a file filter for GIF image files.
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 files.
static javax.swing.filechooser.FileFilter getFileFilterPNG()
          Return a file filter for PNG image files.
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 files.
static byte[] getHDF5UserBlock(java.lang.String filename)
          Read HDF5 user block data into byte array.
static javax.swing.filechooser.FileFilter getImageFileFilter()
          Return a file filter for GIF, JPEG, BMP, or PNG image files.
 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
equals, 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.

Specified by:
accept in class javax.swing.filechooser.FileFilter
See Also:
getExtension(java.io.File)

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)"

Specified by:
getDescription in class javax.swing.filechooser.FileFilter

setDescription

public void setDescription(java.lang.String description)
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();


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 files.


getFileFilterTIFF

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


getFileFilterPNG

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


getFileFilterBMP

public static javax.swing.filechooser.FileFilter getFileFilterBMP()
Return a file filter for BMP image files.


getFileFilterGIF

public static javax.swing.filechooser.FileFilter getFileFilterGIF()
Return a file filter for GIF image files.


getImageFileFilter

public static javax.swing.filechooser.FileFilter getImageFileFilter()
Return a file filter for GIF, JPEG, BMP, or PNG image files.


getFileFilterText

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


getFileFilterBinary

public static javax.swing.filechooser.FileFilter getFileFilterBinary()
Return a file filter for binary 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.