JAL-2909 Wire up coordinates dialog with bam file reader
[jalview.git] / src / jalview / io / FileLoader.java
index 11432bd..96ab8bb 100755 (executable)
@@ -32,6 +32,7 @@ import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.AlignViewport;
+import jalview.gui.BamFileOptionsChooser;
 import jalview.gui.Desktop;
 import jalview.gui.Jalview2XML;
 import jalview.gui.JvOptionPane;
@@ -310,7 +311,34 @@ public class FileLoader implements Runnable
 
       if (FileFormat.Bam.equals(format))
       {
+        FormatAdapter fa = new FormatAdapter();
+        if (source == null)
+        {
+          fa.prepareFileReader(file, protocol, format);
+          source = fa.getAlignFile();
+        }
+
+        BamFileOptionsChooser bamoptions = new BamFileOptionsChooser(
+                source);
+
         // ask the user which bit of the bam they want to load
+        int confirm = JvOptionPane.showConfirmDialog(null,
+                bamoptions,
+                MessageManager.getString("label.bam_file_options"),
+                JvOptionPane.OK_CANCEL_OPTION,
+                JvOptionPane.PLAIN_MESSAGE);
+        
+        if (confirm == JvOptionPane.CANCEL_OPTION
+                || confirm == JvOptionPane.CLOSED_OPTION)
+        {
+          Desktop.instance.stopLoading();
+          return;
+        }
+        else
+        {
+          bamoptions.update(source);
+          al = fa.readFile(file, protocol, format);
+        }
       }
 
       if (FileFormat.Jalview.equals(format))
@@ -329,37 +357,40 @@ public class FileLoader implements Runnable
         String error = AppletFormatAdapter.getSupportedFormats();
         try
         {
-          if (source != null)
+          if (al == null)
           {
-            // read from the provided source
-            al = new FormatAdapter().readFromFile(source, format);
-          }
-          else
-          {
-
-            // open a new source and read from it
-            FormatAdapter fa = new FormatAdapter();
-            boolean downloadStructureFile = format.isStructureFile()
-                    && protocol.equals(DataSourceType.URL);
-            if (downloadStructureFile)
+            if (source != null)
             {
-              String structExt = format.getExtensions().split(",")[0];
-              String urlLeafName = file.substring(
-                      file.lastIndexOf(
-                              System.getProperty("file.separator")),
-                      file.lastIndexOf("."));
-              String tempStructureFileStr = createNamedJvTempFile(
-                      urlLeafName, structExt);
-              UrlDownloadClient.download(file, tempStructureFileStr);
-              al = fa.readFile(tempStructureFileStr, DataSourceType.FILE,
-                      format);
-              source = fa.getAlignFile();
+              // read from the provided source
+              al = new FormatAdapter().readFromFile(source, format);
             }
             else
             {
-              al = fa.readFile(file, protocol, format);
-              source = fa.getAlignFile(); // keep reference for later if
-                                          // necessary.
+
+              // open a new source and read from it
+              FormatAdapter fa = new FormatAdapter();
+              boolean downloadStructureFile = format.isStructureFile()
+                      && protocol.equals(DataSourceType.URL);
+              if (downloadStructureFile)
+              {
+                String structExt = format.getExtensions().split(",")[0];
+                String urlLeafName = file.substring(
+                        file.lastIndexOf(
+                                System.getProperty("file.separator")),
+                        file.lastIndexOf("."));
+                String tempStructureFileStr = createNamedJvTempFile(
+                        urlLeafName, structExt);
+                UrlDownloadClient.download(file, tempStructureFileStr);
+                al = fa.readFile(tempStructureFileStr, DataSourceType.FILE,
+                        format);
+                source = fa.getAlignFile();
+              }
+              else
+              {
+                al = fa.readFile(file, protocol, format);
+                source = fa.getAlignFile(); // keep reference for later if
+                                            // necessary.
+              }
             }
           }
         } catch (java.io.IOException ex)