Advertisement
bojjenclon

Image Viewer - ImageFilter

Nov 23rd, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.io.File;
  2.  
  3. import javax.swing.filechooser.FileFilter;;
  4.  
  5. public class ImageFilter extends FileFilter {
  6.     public static String getExtension( File f ) {
  7.         String ext = null;
  8.         String s = f.getName();
  9.         int i = s.lastIndexOf( '.' );
  10.  
  11.         if( i > 0 &&  i < s.length() - 1 ) {
  12.             ext = s.substring( i+1 ).toLowerCase();
  13.         }
  14.        
  15.         return( ext );
  16.     }
  17.    
  18.     public boolean accept( File f ) {
  19.         boolean r = false;
  20.        
  21.         if( f.isDirectory() ) {
  22.             r = true;
  23.         }
  24.         else {
  25.             String extension = getExtension( f );
  26.             if( extension != null ) {
  27.                 r = extension.equals( "png" ) ||
  28.                     extension.equals( "jpeg" ) ||
  29.                     extension.equals( "jpg" ) ||
  30.                     extension.equals( "tif" ) ||
  31.                     extension.equals( "tiff" ) ||
  32.                     extension.equals( "gif" );
  33.             }
  34.         }
  35.        
  36.         return( r );
  37.     }
  38.    
  39.     public String getDescription() {
  40.         return( "Image Files" );
  41.     }
  42. }
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement