2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
22 import javax.swing.filechooser.FileView;
\r
23 import javax.swing.*;
\r
27 public class JalviewFileView extends FileView
\r
29 static Hashtable alignSuffix = new Hashtable();
\r
31 alignSuffix.put("fasta", "Fasta file");
\r
32 alignSuffix.put("fa", "Fasta file");
\r
33 alignSuffix.put("fastq", "Fasta file");
\r
34 alignSuffix.put("blc", "BLC file");
\r
35 alignSuffix.put("msf", "MSF file");
\r
36 alignSuffix.put("pfam", "PFAM file");
\r
37 alignSuffix.put("aln", "Clustal file");
\r
38 alignSuffix.put("pir", "PIR file");
\r
40 public String getTypeDescription(File f)
\r
42 String extension = getExtension(f);
\r
45 if (extension != null)
\r
47 if (alignSuffix.containsKey(extension))
\r
49 type = alignSuffix.get(extension).toString();
\r
55 public Icon getIcon(File f)
\r
57 String extension = getExtension(f);
\r
60 if (extension != null)
\r
62 if (alignSuffix.containsKey(extension))
\r
64 icon = createImageIcon("/images/file.png");
\r
72 * Get the extension of a file.
\r
74 public static String getExtension(File f) {
\r
76 String s = f.getName();
\r
77 int i = s.lastIndexOf('.');
\r
79 if (i > 0 && i < s.length() - 1) {
\r
80 ext = s.substring(i+1).toLowerCase();
\r
85 /** Returns an ImageIcon, or null if the path was invalid. */
\r
86 protected static ImageIcon createImageIcon(String path) {
\r
87 java.net.URL imgURL = JalviewFileView.class.getResource(path);
\r
88 if (imgURL != null) {
\r
89 return new ImageIcon(imgURL);
\r
91 System.err.println("JalviewFileView.createImageIcon: Couldn't find file: " + path);
\r