/*
 * Created on 2004/11/02
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package jp.riken.brain.ni.samuraigraph.base;

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


public class SGExtensionFileFilter extends FileFilter
{

	/**
	 * 
	 */
	private String mDescription = "";


	/**
	 * 
	 */
	private ArrayList mExtensionsList = new ArrayList();


	/**
	 * 
	 * @param extension
	 */
	public void addExtension( String extension )
	{
		if ( !extension.startsWith(".") )
		{
			extension = "." + extension;
			this.mExtensionsList.add( extension.toLowerCase() );
		}
	}


	/**
	 * 
	 * @param aDescription
	 */
	public void setDescription( String d )
	{
		this.mDescription = d;
	}


	/**
	 * 
	 */
	public String getDescription()
	{
              String sufx = "";
              int ii;
              for(ii=0; ii<mExtensionsList.size(); ii++)
              {
                  if(ii!=0)
                        sufx += ", ";
                  sufx += "*" + (String)mExtensionsList.get(ii);
              }
              if(ii==0)
                  sufx = "*.*";
              return this.mDescription + " (" + sufx + ")";
	}


	/**
	 * 
	 */
	public boolean accept( File file )
	{
		if( file.isDirectory() )
		{
			return true;
		}

		String name = file.getName().toLowerCase();

		// check if the file name ends with any of the extensions
		for( int ii=0; ii<mExtensionsList.size(); ii++ )
		{
			if( name.endsWith( (String)mExtensionsList.get(ii) ) )
			{
				return true;
			}
		}

		return false;
	}
   
}


