001    /*
002     * Copyright (C) 2008-2010 by Holger Arndt
003     *
004     * This file is part of the Universal Java Matrix Package (UJMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * UJMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * UJMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with UJMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.ujmp.core.enums;
025    
026    import java.io.File;
027    
028    import org.ujmp.core.util.io.UJMPFileFilter;
029    
030    /**
031     * Import and export formats that are supported.
032     */
033    public enum FileFormat {
034            CSV("Comma Separated Files", "csv"), //
035            TXT("Text Files", "txt"), //
036            M("Matlab Script Files", "m"), //
037            MAT("Matlab Data Files", "mat"), //
038            GIF("GIF Image Files", "gif"), //
039            FILE("Text Files", "*"), //
040            MDB("Microsoft Access Files", "mdb"), //
041            R("R Files", "r"), //
042            RSS("RSS Feed", "rss", "rdf", "xml"), //
043            ATOM("Atom Feed", "atom", "xml"), //
044            JPG("JPG Image Files", "jpg", "jpeg"), //
045            HTML("HTML Files", "html", "htm"), //
046            MTX("Matrix Data Format", "mtx"), //
047            XLS("Microsoft Excel Files", "xls"), //
048            SER("Serialized Data Files", "ser", "obj", "dat"), //
049            GRAPHML("GraphML Files", "graphml", "gml"), //
050            TEX("Latex Files", "tex"), //
051            WAV("Wave Audio Files", "wav"), //
052            BMP("BMP Image Files", "bmp"), //
053            TIFF("TIFF Image Files", "tif"), //
054            PLT("GnuPlot Files", "plt"), //
055            PDF("PDF Files", "pdf"), //
056            PNG("PNG Images Files", "png"), //
057            XML("XML Files", "xml"), //
058            AML("AML Files", "aml"), //
059            ARFF("ARFF Files", "arf"), //
060            ATT("ATT Files", "att"), //
061            LOG("Log Files", "log"), //
062            NET("Net Files", "net"), //
063            STRING("String files", "txt"), //
064            SPARSECSV("Sparse CSV Files", "csv"), //
065            RAW("Binary Files", "raw", "bin"), //
066            ImapMessages("Imap Messages", "imap"), //
067            ImapFolders("Imap Folders", "imap");
068    
069            private String[] extensions = null;
070    
071            private String description = null;
072    
073            private javax.swing.filechooser.FileFilter fileFilter = null;
074    
075            FileFormat(String description, String... extensions) {
076                    this.extensions = extensions;
077                    this.description = description;
078                    this.fileFilter = new UJMPFileFilter(getDescription(), getExtensions());
079            }
080    
081            public String[] getExtensions() {
082                    return extensions;
083            }
084    
085            public javax.swing.filechooser.FileFilter getFileFilter() {
086                    return fileFilter;
087            }
088    
089            public String getDescription() {
090                    return description;
091            }
092    
093            public static FileFormat guess(File file) {
094                    String name = file.getName().toLowerCase();
095                    for (FileFormat f : FileFormat.values()) {
096                            for (String e : f.getExtensions()) {
097                                    if (name.endsWith(e)) {
098                                            return f;
099                                    }
100                            }
101                    }
102                    return FileFormat.TXT;
103            }
104    
105    }