2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.util.Hashtable;
26 import javax.swing.Icon;
27 import javax.swing.ImageIcon;
28 import javax.swing.filechooser.FileView;
30 public class JalviewFileView extends FileView
32 static Hashtable<String, String> extensions;
34 static void loadExtensions()
36 extensions = new Hashtable<String, String>();
37 for (FileFormatI ff : FileFormat.values())
39 String desc = ff.toString() + " file";
40 String exts = ff.getExtensions();
41 for (String ext : exts.split(","))
43 extensions.put(ext.trim(), desc
44 + ("jar".equals(ext) ? " (old)" : ""));
50 public String getTypeDescription(File f)
52 String extension = getExtension(f);
53 String type = getDescriptionForExtension(extension);
54 if (extension != null)
56 if (extensions.containsKey(extension))
58 type = extensions.get(extension).toString();
65 private String getDescriptionForExtension(String extension)
69 if (extensions == null)
74 return extensions.get(extension);
78 public Icon getIcon(File f)
80 String extension = getExtension(f);
83 if (getDescriptionForExtension(extension) != null)
85 icon = createImageIcon("/images/file.png");
92 * Get the extension of a file.
94 public static String getExtension(File f)
97 String s = f.getName();
98 int i = s.lastIndexOf('.');
100 if ((i > 0) && (i < (s.length() - 1)))
102 ext = s.substring(i + 1).toLowerCase();
109 * Returns an ImageIcon, or null if the file was not found
113 protected static ImageIcon createImageIcon(String filePath)
115 java.net.URL imgURL = JalviewFileView.class.getResource(filePath);
119 return new ImageIcon(imgURL);
124 .println("JalviewFileView.createImageIcon: Couldn't find file: "