update author list in license for (JAL-826)
[jalview.git] / src / jalview / io / JalviewFileView.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.io;
19
20 import java.io.*;
21 import java.util.*;
22
23 import javax.swing.*;
24 import javax.swing.filechooser.*;
25
26 public class JalviewFileView extends FileView
27 {
28   static Hashtable alignSuffix = new Hashtable();
29
30   static
31   {
32     alignSuffix.put("fasta", "Fasta file");
33     alignSuffix.put("fa", "Fasta file");
34     alignSuffix.put("fastq", "Fasta file");
35     alignSuffix.put("blc", "BLC file");
36     alignSuffix.put("msf", "MSF file");
37     alignSuffix.put("pfam", "PFAM file");
38     alignSuffix.put("aln", "Clustal file");
39     alignSuffix.put("pir", "PIR file");
40     alignSuffix.put("jar", "Jalview file");
41   }
42
43   public String getTypeDescription(File f)
44   {
45     String extension = getExtension(f);
46     String type = null;
47
48     if (extension != null)
49     {
50       if (alignSuffix.containsKey(extension))
51       {
52         type = alignSuffix.get(extension).toString();
53       }
54     }
55
56     return type;
57   }
58
59   public Icon getIcon(File f)
60   {
61     String extension = getExtension(f);
62     Icon icon = null;
63
64     if (extension != null)
65     {
66       if (alignSuffix.containsKey(extension))
67       {
68         icon = createImageIcon("/images/file.png");
69       }
70     }
71
72     return icon;
73   }
74
75   /*
76    * Get the extension of a file.
77    */
78   public static String getExtension(File f)
79   {
80     String ext = null;
81     String s = f.getName();
82     int i = s.lastIndexOf('.');
83
84     if ((i > 0) && (i < (s.length() - 1)))
85     {
86       ext = s.substring(i + 1).toLowerCase();
87     }
88
89     return ext;
90   }
91
92   /** Returns an ImageIcon, or null if the path was invalid. */
93   protected static ImageIcon createImageIcon(String path)
94   {
95     java.net.URL imgURL = JalviewFileView.class.getResource(path);
96
97     if (imgURL != null)
98     {
99       return new ImageIcon(imgURL);
100     }
101     else
102     {
103       System.err
104               .println("JalviewFileView.createImageIcon: Couldn't find file: "
105                       + path);
106
107       return null;
108     }
109   }
110 }