JAL-2344 now flagging formats as 'identifiable' instead of 'dynamic'
[jalview.git] / src / jalview / gui / Desktop.java
index 77bc7d4..4ce42dc 100644 (file)
@@ -31,6 +31,7 @@ import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
 import jalview.io.FileFormatException;
 import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
 import jalview.io.FileLoader;
 import jalview.io.IdentifyFile;
 import jalview.io.JalviewFileChooser;
@@ -102,7 +103,6 @@ import javax.swing.JFrame;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JProgressBar;
@@ -455,7 +455,6 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       }
     });
 
-    // displayed.
     // Thread off a new instance of the file chooser - this reduces the time it
     // takes to open it later on.
     new Thread(new Runnable()
@@ -466,9 +465,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         Cache.log.debug("Filechooser init thread started.");
         String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
         JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"),
-        // jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
-        // jalview.io.AppletFormatAdapter.READABLE_FNAMES,
-                fileFormat, true);
+                fileFormat);
         Cache.log.debug("Filechooser init thread finished.");
       }
     }).start();
@@ -894,9 +891,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       }
     });
 
+    desktop.add(frame);
+
     windowMenu.add(menuItem);
 
-    desktop.add(frame);
     frame.toFront();
     try
     {
@@ -1013,10 +1011,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   {
     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
     JalviewFileChooser chooser = JalviewFileChooser.forRead(
-            Cache.getProperty("LAST_DIRECTORY"),
-            // AppletFormatAdapter.READABLE_EXTENSIONS,
-            // AppletFormatAdapter.READABLE_FNAMES,
-            fileFormat, true);
+            Cache.getProperty("LAST_DIRECTORY"), fileFormat);
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
@@ -1031,20 +1026,21 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       Cache.setProperty("LAST_DIRECTORY", chooser
               .getSelectedFile().getParent());
 
-      FileFormatI format = null;
-      FileFormatI selectedFormat = chooser.getSelectedFormat();
-      if (FileFormat.Jalview.equals(selectedFormat))
-      {
-        format = FileFormat.Jalview;
-      }
-      else
+      FileFormatI format = chooser.getSelectedFormat();
+
+      /*
+       * Call IdentifyFile to verify the file contains what its extension implies.
+       * Skip this step for dynamically added file formats, because
+       * IdentifyFile does not know how to recognise them.
+       */
+      if (FileFormats.getInstance().isIdentifiable(format))
       {
         try
         {
           format = new IdentifyFile().identify(choice, DataSourceType.FILE);
         } catch (FileFormatException e)
         {
-          // format is null
+          // format = null; //??
         }
       }
 
@@ -1536,8 +1532,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   public void saveState_actionPerformed(ActionEvent e)
   {
     JalviewFileChooser chooser = new JalviewFileChooser(
-            Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project",
-            "Jalview Project");
+            Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project");
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.save_state"));
@@ -2192,7 +2187,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     {
       JalviewFileChooser chooser = new JalviewFileChooser(
               Cache.getProperty("LAST_DIRECTORY"), "vdj",// TODO: VAMSAS DOCUMENT EXTENSION is VDJ
-              "Vamsas Document", "Vamsas Document");
+              "Vamsas Document");
 
       chooser.setFileView(new JalviewFileView());
       chooser.setDialogTitle(MessageManager