
/**
 * FRETViewFileFilter.java
 * This filters the name of experiment files
 * Created: June 12, 2006
 *
 * @author Nathan Stevens
 * @version 0.1 6/12/2006
 */
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.*;

public class FRETViewFileFilter extends FileFilter {
	private String type;
  private String description;
  private String[] extensions;
	
	public FRETViewFileFilter() {
    extensions = new String[6];
    description = "FRETViewData Files (*.txt, *.csv, *.dal)";
    extensions[0] = "txt";
    extensions[1] = "csv";
    extensions[2] = "dal"; // donor acceptor list binary format
	}
  
	// Except all files that starts with the experiment name
	public boolean accept(File f) {
		if (f.isDirectory()) {
      return true;
    }
		
    String extension = getExtension(f);
    
    if(extension != null) {
      for(int i = 0; i < extensions.length; i++) {
        if(extension.equals(extensions[i])) {
          return true;
        }
      }
    }
    
    return false;
	}
	
	// The description of this filter
  public String getDescription() {
    return description;
  }
	
  // Method to get the file extension
  private String getExtension(File f) {
    String ext = null;
    String s = f.getName();
    int i = s.lastIndexOf('.');
    
    if (i > 0 &&  i < s.length() - 1) {
      ext = s.substring(i+1).toLowerCase();
    }
    return ext;
  }
} // --end class FRETViewFileFilter
