Filters.java
package ac.essex.ooechs.imaging.commons.util;
import java.io.FileFilter;
import java.io.File;
/**
* Allows you to get a filter to only allow common image types through. Useful
* when using the listFiles() method on the File object.
*/
public class Filters {
/**
* Returns a filter that only allows images of type BMP, JPG, PNG and GIF to be used.
* All these can be loaded using the PixelLoader object.
*/
public static FileFilter getImageFilter() {
return new FileFilter() {
public boolean accept(File f) {
String extension = f.getName().substring(f.getName().lastIndexOf('.') + 1).toLowerCase();
if (f.isDirectory()) return true;
if (extension.equals("bmp")) return true;
if (extension.equals("jpg")) return true;
if (extension.equals("png")) return true;
if (extension.equals("gif")) return true;
return false;
}
};
}
}