edu.stanford.hci.r3.util.files.filters
Class FileExtensionFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by edu.stanford.hci.r3.util.files.filters.FileExtensionFilter
All Implemented Interfaces:
java.io.FileFilter, java.io.FilenameFilter
Direct Known Subclasses:
FileExcludeHiddenFilter, FilesOnlyFilter

public class FileExtensionFilter
extends javax.swing.filechooser.FileFilter
implements java.io.FileFilter, java.io.FilenameFilter

A Java FileFilter that accepts file extensions as Strings

This software is distributed under the BSD License.


Field Summary
static java.lang.String[] ACCEPT_ALL
           
 
Constructor Summary
FileExtensionFilter()
           
FileExtensionFilter(java.lang.String[] exts)
           
FileExtensionFilter(java.lang.String[] exts, boolean directories, Visibility vis)
          If there are dots in the beginning of the exts, we remove them, so that they will still work.
 
Method Summary
 boolean accept(java.io.File f)
          This method is for filechoosers, and makes use of acceptDirectories
 boolean accept(java.io.File parentDir, java.lang.String name)
           
 java.lang.String getDescription()
          A string description to display in file choosers.
 void setAcceptDirectories(boolean acceptDirs)
          If we are accepting directories, then ALL directories will be accepted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCEPT_ALL

public static final java.lang.String[] ACCEPT_ALL
Constructor Detail

FileExtensionFilter

public FileExtensionFilter()

FileExtensionFilter

public FileExtensionFilter(java.lang.String[] exts)
Parameters:
exts -

FileExtensionFilter

public FileExtensionFilter(java.lang.String[] exts,
                           boolean directories,
                           Visibility vis)
If there are dots in the beginning of the exts, we remove them, so that they will still work.

Parameters:
exts - Pass in null or "" to accept all files. Otherwise, pass in an array of extensions without dots, such as {"jpg", "jpeg", "mpg", "mpeg"}. The matching is case INSENSITIVE.
directories - true --> we will include directories.
vis - BOTH --> we will include files or directories that are hidden or whose names start with dots (e.g., .bashrc).
Method Detail

accept

public boolean accept(java.io.File f)
This method is for filechoosers, and makes use of acceptDirectories

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

accept

public boolean accept(java.io.File parentDir,
                      java.lang.String name)
Specified by:
accept in interface java.io.FilenameFilter

getDescription

public java.lang.String getDescription()
A string description to display in file choosers.

Specified by:
getDescription in class javax.swing.filechooser.FileFilter
See Also:
FileFilter.getDescription()

setAcceptDirectories

public void setAcceptDirectories(boolean acceptDirs)
If we are accepting directories, then ALL directories will be accepted. We do not apply extensions to directory names. This makes it so that directories will appear in the file chooser even if we have this FileExtensionFilter applied.

Parameters:
acceptDirs -

Copyright 2006 Stanford University