/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.io;
import javax.swing.filechooser.FileFilter;
/**
* Enumeration of all data handler types.
*
* @author Markus Kraetzig
*/
public enum DataHandlerTypes {
/**
* DAT files.
*/
DAT {
private final ExtensionFileFilter datFileFilter = new ExtensionFileFilter(
getFileExtension(), "JMulTi ASCII Data", this);
public DataHandler getHandler() {
return TSASCIIHandler.getInstance();
}
public FileFilter getFileFilter() {
return datFileFilter;
}
public boolean canWriteFormat() {
return true;
}
public String getFileExtension() {
return "dat";
}
},
/**
* XLS files.
*/
EXCEL {
private final ExtensionFileFilter excelFileFilter = new ExtensionFileFilter(
getFileExtension(), "MS Excel 97/2000", this);
public DataHandler getHandler() {
return TSExcelHandler.getInstance();
}
public FileFilter getFileFilter() {
return excelFileFilter;
}
public boolean canWriteFormat() {
return true;
}
public String getFileExtension() {
return "xls";
}
},
/**
* Gauss .fmt files.
*/
GAUSS_FMT {
private final ExtensionFileFilter gaussFMTFileFilter = new ExtensionFileFilter(
getFileExtension(), "Gauss Matrix Files", this);
public DataHandler getHandler() {
return TSGaussFMTHandler.getInstance();
}
public FileFilter getFileFilter() {
return gaussFMTFileFilter;
}
public boolean canWriteFormat() {
return true;
}
public String getFileExtension() {
return "fmt";
}
},
/**
* Gauss .dat files.
*/
GAUSS_DAT {
private final ExtensionFileFilter gaussDatFileFilter = new ExtensionFileFilter(
getFileExtension(), "Gauss Datasets", this);
public DataHandler getHandler() {
return TSGaussDATHandler.getInstance();
}
public FileFilter getFileFilter() {
return gaussDatFileFilter;
}
public boolean canWriteFormat() {
return true;
}
public String getFileExtension() {
return "dat";
}
},
/**
* Matlab .m files version 5.
*/
MATLAB {
private final ExtensionFileFilter matFileFilter = new ExtensionFileFilter(
getFileExtension(), "Matlab MAT-Files Level 5", this);
public DataHandler getHandler() {
return TSMatlabHandler.getInstance();
}
public FileFilter getFileFilter() {
return matFileFilter;
}
public boolean canWriteFormat() {
return true;
}
public String getFileExtension() {
return "mat";
}
};
/**
* Gets the import handler of this type.
*
* @return handler instance
*/
public abstract DataHandler getHandler();
/**
* Gets the file filer associated with this type. Each type should have a
* unique filter, even if the filename suffixes are the same.
*
* @return file filter
*/
public abstract FileFilter getFileFilter();
/**
* Gets a string with the file extension associated with files that are
* handled by this, for example "xls" for Excel files, or
* "mat" for Matlab files.
*
* @return extension string
*/
public abstract String getFileExtension();
/**
* Gets whether it is possible to write files in the represented type.
*
* @return true if files can be written, false
* otherwise
*/
public abstract boolean canWriteFormat();
/**
* Gets the handler type from the filename. DAT is returned
* as default.
*
* @param fName
* the filename with a descriptive suffix
* @return handler type
* @throws IllegalArgumentException
* if (fName == null)
*/
public static DataHandlerTypes getTypeFromFileName(String fName) {
if (fName == null)
throw new IllegalArgumentException("Argument was null.");
String check = fName.toLowerCase();
if (check.endsWith("xls"))
return EXCEL;
if (check.endsWith("fmt"))
return GAUSS_FMT;
if (check.endsWith("mat"))
return MATLAB;
// default
return DAT;
}
}
Ads help maintain this website.