JAL-3048 switch from 'dialogdata' to DialogRunner for load Features/Annotations/Other...
[jalview.git] / src / jalview / gui / AlignFrame.java
index 1ca2f36..95f1ed1 100644 (file)
@@ -182,6 +182,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   String fileName = null;
 
+  File fileObject;
+
   /**
    * Creates a new AlignFrame object with specific width and height.
    * 
@@ -334,6 +336,27 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     Desktop.getDesktop().propertyChange(evt);
   }
 
+  
+  /**
+   *  BH 2018
+   *   
+   * @return true if we have any features
+   */
+  @Override
+  protected boolean haveAlignmentFeatures() { 
+    AlignmentI alignment = getViewport().getAlignment();
+
+    for (int i = 0; i < alignment.getHeight(); i++)
+    {
+      SequenceI seq = alignment.getSequenceAt(i);
+      for (String group : seq.getFeatures().getFeatureGroups(true))
+      {
+        if (group != null)return true;
+      }
+    }
+    return  false; 
+  }
+  
   /**
    * initalise the alignframe from the underlying viewport data and the
    * configurations
@@ -513,6 +536,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     setFileFormat(format);
     reload.setEnabled(true);
   }
+  
+  /**
+   * JavaScript will have this, maybe others. More dependable than a file name
+   * and maintains a reference to the actual bytes loaded.
+   * 
+   * @param file
+   */
+  public void setFileObject(File file) {
+    this.fileObject = file;
+  }
 
   /**
    * Add a KeyListener with handlers for various KeyPressed and KeyReleased
@@ -1044,8 +1077,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
         FileLoader loader = new FileLoader();
         DataSourceType protocol = fileName.startsWith("http:")
-                ? DataSourceType.URL
-                : DataSourceType.FILE;
+                ? DataSourceType.URL : DataSourceType.FILE;
         loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
       }
       else
@@ -1053,11 +1085,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         Rectangle bounds = this.getBounds();
 
         FileLoader loader = new FileLoader();
-        DataSourceType protocol = fileName.startsWith("http:")
-                ? DataSourceType.URL
-                : DataSourceType.FILE;
-        AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
-                protocol, currentFileFormat);
+
+        AlignFrame newframe = null;
+
+        if (fileObject == null)
+        {
+
+          DataSourceType protocol = (fileName.startsWith("http:")
+                  ? DataSourceType.URL : DataSourceType.FILE);
+          newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
+                  currentFileFormat);
+        }
+        else
+        {
+          newframe = loader.LoadFileWaitTillLoaded(fileObject, DataSourceType.FILE, currentFileFormat);
+        }
 
         newframe.setBounds(bounds);
         if (featureSettings != null && featureSettings.isShowing())
@@ -1422,39 +1464,27 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void associatedData_actionPerformed(ActionEvent e)
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(
+    final JalviewFileChooser chooser = new JalviewFileChooser(
             jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(
             MessageManager.getString("label.load_jalview_annotations"));
     chooser.setToolTipText(
             MessageManager.getString("label.load_jalview_annotations"));
-
-    Desktop.getDesktop().dialogData = new Object[] { "SelectedFile",
-        new Runnable()
+    chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
         {
 
           @Override
           public void run()
           {
-            Object[] data = Desktop.getDesktop().dialogData;
-            int value = ((Integer) data[0]).intValue();
-
-            if (value == JFileChooser.APPROVE_OPTION)
-            {
-              JalviewFileChooser chooser = (JalviewFileChooser) data[2];
-              String choice = chooser.getSelectedFile().getPath();
-              jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
-              loadJalviewDataFile(choice, null, null, null);
-            }
+            String choice = chooser.getSelectedFile().getPath();
+            jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
+            loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
           }
 
-        }, chooser };
-
-    chooser.showOpenDialog(null);
-
-
+        });
 
+    chooser.openDialog(this);
   }
 
   /**