new class
authoramwaterhouse <Andrew Waterhouse>
Tue, 15 Mar 2005 16:08:15 +0000 (16:08 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 15 Mar 2005 16:08:15 +0000 (16:08 +0000)
src/jalview/io/JalviewFileView.java [new file with mode: 0755]

diff --git a/src/jalview/io/JalviewFileView.java b/src/jalview/io/JalviewFileView.java
new file mode 100755 (executable)
index 0000000..aa9d6f2
--- /dev/null
@@ -0,0 +1,67 @@
+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