package chronoSave;

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

public class filter extends FileFilter
{
	private String description = "Chronogram File";
	private String extension = ".chr";
  
	public filter(String ext, String descrip)
	{
		this.extension = ext;
		this.description = descrip;
	}
  
	public boolean accept(File file)
	{
		String temp = removeChar(this.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 = res + s.charAt(i);
			}
		}
		return res;
	}
}
