Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import javax.swing.filechooser.FileFilter;;
- public class ImageFilter extends FileFilter {
- public static String getExtension( File f ) {
- String ext = null;
- String s = f.getName();
- int i = s.lastIndexOf( '.' );
- if( i > 0 && i < s.length() - 1 ) {
- ext = s.substring( i+1 ).toLowerCase();
- }
- return( ext );
- }
- public boolean accept( File f ) {
- boolean r = false;
- if( f.isDirectory() ) {
- r = true;
- }
- else {
- String extension = getExtension( f );
- if( extension != null ) {
- r = extension.equals( "png" ) ||
- extension.equals( "jpeg" ) ||
- extension.equals( "jpg" ) ||
- extension.equals( "tif" ) ||
- extension.equals( "tiff" ) ||
- extension.equals( "gif" );
- }
- }
- return( r );
- }
- public String getDescription() {
- return( "Image Files" );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement