package save;

import java.io.File;
import javax.swing.filechooser.FileFilter;

public class Filter extends FileFilter {

	private String extension = ".chr", description = "Chronogram File";
	
	public Filter(String ext, String descrip){
		this.extension = ext;
		this.description = descrip;
	}
	
	public boolean accept(File file){
		String temp = removeChar(extension, ' ');
		String[] exts = temp.split(",");
		boolean res = file.isDirectory();
		for (int i=0; i<exts.length; i++){
			res = res || file.getName().endsWith(exts[i]);
		}
		return res;
	}
	
	public String getDescription(){
		return this.extension + " - " + this.description;
	}
	
	public String removeChar(String s, char c){
		String res="";
		for (int i = 0; i < s.length(); i++) {
	       if (s.charAt(i) != c) res += s.charAt(i);
	    }
		return res;
	}
}
