package util;
import java.io.File;
public class CustomFileFilter extends javax.swing.filechooser.FileFilter {
private String[] extentions;
public CustomFileFilter(String[] extentions) {
if (extentions == null) { throw new IllegalArgumentException(
"No file extentions are given."); }
this.extentions = extentions;
}
public boolean accept(File file) {
String filename = file.getName();
boolean result = false;
for (int i = 0; i < extentions.length; ++i) {
if (filename.toLowerCase().endsWith(extentions[i].toLowerCase())) {
result = true;
break;
}
}
return result || file.isDirectory();
}
public String getDescription() {
String desc = "";
for (int i = 0; i < extentions.length; ++i) {
desc += "*" + extentions[i] + " ";
}
return desc;
}
}