--- /dev/null
+package jalview.io;\r
+\r
+import javax.swing.filechooser.FileView;\r
+import javax.swing.*;\r
+import java.io.*;\r
+\r
+public class JalviewFileView extends FileView\r
+{\r
+ public String getTypeDescription(File f)\r
+ {\r
+ String extension = getExtension(f);\r
+ String type = null;\r
+\r
+ if (extension != null)\r
+ {\r
+ if (extension.equals("fasta") || extension.equals("fa") || extension.equals("fastq"))\r
+ {\r
+ type = "Fasta file";\r
+ }\r
+ }\r
+ return type;\r
+ }\r
+\r
+ public Icon getIcon(File f)\r
+ {\r
+ String extension = getExtension(f);\r
+ Icon icon = null;\r
+\r
+ if (extension != null)\r
+ {\r
+ if (extension.equals("fasta") || extension.equals("fa") || extension.equals("fastq"))\r
+ {\r
+ icon = createImageIcon("/images/file.png");\r
+ }\r
+ }\r
+ return icon;\r
+ }\r
+\r
+\r
+ /*\r
+ * Get the extension of a file.\r
+ */\r
+ public static String getExtension(File f) {\r
+ String ext = null;\r
+ String s = f.getName();\r
+ int i = s.lastIndexOf('.');\r
+\r
+ if (i > 0 && i < s.length() - 1) {\r
+ ext = s.substring(i+1).toLowerCase();\r
+ }\r
+ return ext;\r
+ }\r
+\r
+ /** Returns an ImageIcon, or null if the path was invalid. */\r
+ protected static ImageIcon createImageIcon(String path) {\r
+ java.net.URL imgURL = JalviewFileView.class.getResource(path);\r
+ if (imgURL != null) {\r
+ return new ImageIcon(imgURL);\r
+ } else {\r
+ System.err.println("Couldn't find file: " + path);\r
+ return null;\r
+ }\r
+ }\r
+\r
+}\r
+\r
+\r