/*
 *
 * Copyright (C)  12-sept-2003 Jean-Yves Beaujean
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,  59
 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 */
package jxtray;


import javax.swing.filechooser.FileFilter; 

import java.io.File;

import jxtray.util.FileUtilities;

/**
 * CustomFileFilter class. 
 * This class allow to filter some types of files
 * Use it with the JFileChooser.
 */
public class CustomFileFilter extends FileFilter
{
		/** Accepted extension */
		private String filterExtension ;
		/** Filter description */
		private String description;
		
		/** Constructor */
		public CustomFileFilter(String description, String filterExtension)
		{
				super();
				this.filterExtension = filterExtension;
				this.description = description;
				
		}
		
		/** Override method : from FileFilter interface */
		public boolean accept(File f)
		{
				if ( f.isDirectory()) return true;

				String extension = FileUtilities.getExtension(f);
				
				if ( extension != null)
				{
					if ( extension.equals(filterExtension))
							return true;
				}
				
				return false;
		}
		
		/** Return the filter description 
		 * 	@return String 
		 */
		public String getDescription()
		{
				return description;
		}
		
		/** Return the file extension
		 * 	@return String 
		 */
		public String getExtension()
		{
				return filterExtension;
		}		
		
		
}
