public class JalviewFileView extends FileView
{
- static Hashtable alignSuffix = new Hashtable();
+ static Hashtable<String, String> extensions;
- static
+ static void loadExtensions()
{
- // TODO: these names should come from the FormatAdapter lists for
- // readable/writable extensions
- alignSuffix.put("amsa", "AMSA file");
- alignSuffix.put("fasta", "Fasta file");
- alignSuffix.put("fa", "Fasta file");
- alignSuffix.put("fastq", "Fasta file");
- alignSuffix.put("mfa", "Fasta file");
- alignSuffix.put("blc", "BLC file");
- alignSuffix.put("msf", "MSF file");
- alignSuffix.put("pfam", "PFAM file");
- alignSuffix.put("aln", "Clustal file");
- alignSuffix.put("pir", "PIR file");
- alignSuffix.put("jar", "Jalview Project file (old)");
- alignSuffix.put("jvp", "Jalview Project file");
- alignSuffix.put("amsa", "AMSA file");
- alignSuffix.put("sto", "Stockholm File");
- alignSuffix.put("stk", "Stockholm File");
- alignSuffix.put("sto", "Stockholm File");
+ extensions = new Hashtable<String, String>();
+ for (FileFormatI ff : FileFormat.values())
+ {
+ String desc = ff.toString() + " file";
+ String exts = ff.getExtensions();
+ for (String ext : exts.split(","))
+ {
+ extensions.put(ext.trim(), desc
+ + ("jar".equals(ext) ? " (old)" : ""));
+ }
+ }
}
@Override
public String getTypeDescription(File f)
{
String extension = getExtension(f);
- String type = null;
-
+ String type = getDescriptionForExtension(extension);
if (extension != null)
{
- if (alignSuffix.containsKey(extension))
+ if (extensions.containsKey(extension))
{
- type = alignSuffix.get(extension).toString();
+ type = extensions.get(extension).toString();
}
}
return type;
}
+ private String getDescriptionForExtension(String extension)
+ {
+ synchronized (this)
+ {
+ if (extensions == null)
+ {
+ loadExtensions();
+ }
+ }
+ return extensions.get(extension);
+ }
+
@Override
public Icon getIcon(File f)
{
String extension = getExtension(f);
Icon icon = null;
- if (extension != null)
+ if (getDescriptionForExtension(extension) != null)
{
- if (alignSuffix.containsKey(extension))
- {
- icon = createImageIcon("/images/file.png");
- }
+ icon = createImageIcon("/images/file.png");
}
return icon;
return ext;
}
- /** Returns an ImageIcon, or null if the path was invalid. */
- protected static ImageIcon createImageIcon(String path)
+ /**
+ * Returns an ImageIcon, or null if the file was not found
+ *
+ * @param filePath
+ */
+ protected static ImageIcon createImageIcon(String filePath)
{
- java.net.URL imgURL = JalviewFileView.class.getResource(path);
+ java.net.URL imgURL = JalviewFileView.class.getResource(filePath);
if (imgURL != null)
{
{
System.err
.println("JalviewFileView.createImageIcon: Couldn't find file: "
- + path);
+ + filePath);
return null;
}