1 7 8 package com.memoire.vainstall.builder.util; 9 10 import java.io.File ; 11 12 import javax.swing.filechooser.FileFilter ; 13 14 23 public class VAIImageFileFilter extends FileFilter { 24 25 public VAIImageFileFilter() { 26 super(); 27 } 28 29 public boolean accept(java.io.File file) { 30 31 if (file != null) { 32 33 if(file.isDirectory() == true) { 34 return true; 35 } 36 37 String extension = getExtension(file); 38 if (extension == null) { 39 return false; 40 } 41 42 if (extension.equals("gif") == true) { 43 return true; 44 } 45 46 if (extension.equals("jpg") == true) { 47 return true; 48 } 49 50 if(extension.equals("png") == true) { 51 return true; 52 } 53 } 54 return false; 55 } 56 57 public String getDescription() { 58 return "Java Image Files (*.png, *.jpg or *.gif)"; 59 } 60 61 public String getExtension(File file) { 62 63 if (file != null) { 64 String filename = file.getName(); 65 66 int i = filename.lastIndexOf('.'); 67 if (i > 0 && i < filename.length() - 1) { 68 return filename.substring(i+1).toLowerCase(); 69 } 70 } 71 return null; 72 } 73 74 } 75 | Popular Tags |