public boolean accept(File f) {

       if (f.isDirectory()) {
           return true;
       }

       String extension = f.getName();
       int i = extension.lastIndexOf('.');

       if (i > 0 &&  i < extension.length() - 1) {
           extension = extension.substring(i+1).toLowerCase();
       }

       if (extension != null) {
           if ((extension.equals("ppm")) ||
               (extension.equals("pnm")) ||
               (extension.equals("jpg")) ||
               (extension.equals("jpeg"))) {
                   return true;
            } else {
                return false;
            }
        }

        return false;
    }