Further tweaks to get tests passing
[jalview.git] / src / jalview / io / JalviewFileChooser.java
index a4362dc..e4317bd 100755 (executable)
@@ -76,7 +76,7 @@ public class JalviewFileChooser extends JFileChooser
       if (format.isReadable())
       {
         extensions.add(format.getExtensions());
-        descs.add(format.getShortDescription());
+        descs.add(format.toString());
       }
     }
     return new JalviewFileChooser(directory,
@@ -106,7 +106,7 @@ public class JalviewFileChooser extends JFileChooser
       if (format.isWritable())
       {
         extensions.add(format.getExtensions());
-        descs.add(format.getShortDescription());
+        descs.add(format.toString());
       }
     }
     return new JalviewFileChooser(directory,
@@ -233,6 +233,11 @@ public class JalviewFileChooser extends JFileChooser
     }
   }
 
+  /**
+   * Returns the selected file format, or null if none selected
+   * 
+   * @return
+   */
   public FileFormatI getSelectedFormat()
   {
     if (getFileFilter() == null)
@@ -240,8 +245,27 @@ public class JalviewFileChooser extends JFileChooser
       return null;
     }
 
+    /*
+     * logic here depends on option description being formatted as 
+     * formatName (extension, extension...)
+     * or the 'no option selected' value
+     * All Files
+     * @see JalviewFileFilter.getDescription
+     */
     String format = getFileFilter().getDescription();
-    return FileFormat.valueOf(format);
+    int parenPos = format.indexOf("(");
+    if (parenPos > 0)
+    {
+      format = format.substring(0, parenPos).trim();
+      try
+      {
+        return FileFormat.valueOf(format);
+      } catch (IllegalArgumentException e)
+      {
+        System.err.println("Unexpected format: " + format);
+      }
+    }
+    return null;
   }
 
   @Override