/**
|
* <p>Title:</p>
|
* <p>Description:</p>
|
* <p>Copyright: Copyright (C) 2011 </p>
|
* <p>Company: VCI </p>
|
* @author Bear
|
* @time 2011-8-1
|
* @version 1.0
|
*/
|
package com.vci.client.ui.swing.filechooser;
|
|
|
import java.io.File;
|
|
import javax.swing.filechooser.FileFilter;
|
|
public abstract class AbstractFileFilter extends FileFilter {
|
protected String[] suffixs = {};//{ ".jgp", ".jpeg", ".gif", ".png" };
|
protected String descroption = "";//"Image Files";
|
public AbstractFileFilter(String[] suffixs, String descroption){
|
this.suffixs = suffixs;
|
this.descroption = descroption;
|
}
|
|
protected String getStuffixString(){
|
StringBuffer sb = new StringBuffer();
|
if(suffixs.length != 0){
|
for(String str : suffixs){
|
sb.append("*").append(str).append("|");
|
}
|
sb.replace(sb.length() - 1, sb.length(), "");
|
}
|
return this.descroption + "(" + sb.toString() + ")";
|
}
|
|
protected boolean isMatched(String file) {
|
boolean res = false;
|
for (String suffix : suffixs) {
|
res = res || file.toLowerCase().endsWith(suffix);
|
}
|
return res;
|
}
|
|
public String[] getSuffixs() {
|
return suffixs;
|
}
|
|
public void setSuffixs(String[] suffixs) {
|
this.suffixs = suffixs;
|
}
|
|
public void setDescroption(String descroption) {
|
this.descroption = descroption;
|
}
|
|
@Override
|
public boolean accept(File f) {
|
if (f.isDirectory())
|
return true;
|
return isMatched(f.getName());
|
}
|
|
@Override
|
public String getDescription() {
|
return getStuffixString();
|
}
|
}
|