Moved comment so it doesn't break jalopy (this is not good!)
[jalview.git] / src / jalview / io / JalviewFileChooser.java
index 5b4fa21..eca6e43 100755 (executable)
@@ -31,14 +31,45 @@ public class JalviewFileChooser extends JFileChooser
   private static String[] COLUMNS = null;\r
 \r
 \r
-  public JalviewFileChooser(String dir, String [] suffix, String desc)\r
+  public JalviewFileChooser(String dir, String [] suffix, String [] desc, String selected)\r
   {\r
     super(dir);\r
-    JalviewFileFilter filter = new JalviewFileFilter(suffix, desc);\r
-    this.setFileFilter(filter);\r
+\r
+    JalviewFileFilter chosen = null;\r
+    for(int i=0; i<suffix.length; i++)\r
+    {\r
+      JalviewFileFilter jvf = new JalviewFileFilter(suffix[i], desc[i]);\r
+      addChoosableFileFilter(jvf);\r
+      if(selected!=null && selected.equalsIgnoreCase(desc[i]))\r
+        chosen = jvf;\r
+    }\r
+    if(chosen!=null)\r
+      setFileFilter(chosen);\r
     initColumns();\r
   }\r
 \r
+  public String getSelectedFormat()\r
+  {\r
+\r
+    String format = getFileFilter().getDescription();\r
+\r
+    if (format.toUpperCase().startsWith("JALVIEW"))\r
+      format = "Jalview";\r
+    else if (format.toUpperCase().startsWith("FASTA"))\r
+      format = "FASTA";\r
+    else if (format.toUpperCase().startsWith("MSF"))\r
+      format = "MSF";\r
+    else if (format.toUpperCase().startsWith("CLUSTAL"))\r
+      format = "CLUSTAL";\r
+    else if (format.toUpperCase().startsWith("BLC"))\r
+      format = "BLC";\r
+    else if (format.toUpperCase().startsWith("PIR"))\r
+      format = "PIR";\r
+    else if (format.toUpperCase().startsWith("PFAM"))\r
+      format = "PFAM";\r
+\r
+    return format;\r
+  }\r
   public JalviewFileChooser(String dir)\r
   {\r
     super(dir);\r
@@ -49,6 +80,16 @@ public class JalviewFileChooser extends JFileChooser
       setDialogType(SAVE_DIALOG);\r
       int ret = showDialog(parent, null);\r
 \r
+      if(getFileFilter() instanceof JalviewFileFilter)\r
+      {\r
+        JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter();\r
+        if (!jvf.accept(getSelectedFile()))\r
+        {\r
+          String withExtension = getSelectedFile() + "." + jvf.getAcceptableExtension();\r
+          setSelectedFile(new File(withExtension));\r
+        }\r
+      }\r
+\r
       if(ret == JalviewFileChooser.APPROVE_OPTION  &&  getSelectedFile().exists() )\r
       {\r
        int confirm =  JOptionPane.showConfirmDialog(parent,\r
@@ -202,7 +243,7 @@ public class JalviewFileChooser extends JFileChooser
       *************************************************************************/\r
      protected final boolean lt(File a, File b)\r
      {\r
-       System.out.println("LT called?");\r
+       System.out.println("DEBUG:LT called?");\r
        boolean less = false;\r
        switch (col)\r
        {\r