3 import javax.swing.filechooser.FileView;
\r
4 import javax.swing.*;
\r
7 public class JalviewFileView extends FileView
\r
9 public String getTypeDescription(File f)
\r
11 String extension = getExtension(f);
\r
14 if (extension != null)
\r
16 if (extension.equals("fasta") || extension.equals("fa") || extension.equals("fastq"))
\r
18 type = "Fasta file";
\r
24 public Icon getIcon(File f)
\r
26 String extension = getExtension(f);
\r
29 if (extension != null)
\r
31 if (extension.equals("fasta") || extension.equals("fa") || extension.equals("fastq"))
\r
33 icon = createImageIcon("/images/file.png");
\r
41 * Get the extension of a file.
\r
43 public static String getExtension(File f) {
\r
45 String s = f.getName();
\r
46 int i = s.lastIndexOf('.');
\r
48 if (i > 0 && i < s.length() - 1) {
\r
49 ext = s.substring(i+1).toLowerCase();
\r
54 /** Returns an ImageIcon, or null if the path was invalid. */
\r
55 protected static ImageIcon createImageIcon(String path) {
\r
56 java.net.URL imgURL = JalviewFileView.class.getResource(path);
\r
57 if (imgURL != null) {
\r
58 return new ImageIcon(imgURL);
\r
60 System.err.println("Couldn't find file: " + path);
\r