Merge branch 'Jalview-BH/JAL-3026-JAL-3063-JAXB' into trialMerge
[jalview.git] / src / jalview / gui / AlignFrame.java
index 477db0c..56ef63b 100644 (file)
@@ -26,7 +26,7 @@ import jalview.analysis.CrossRef;
 import jalview.analysis.Dna;
 import jalview.analysis.ParseProperties;
 import jalview.analysis.SequenceIdMatcher;
-import jalview.api.AlignExportSettingI;
+import jalview.api.AlignExportSettingsI;
 import jalview.api.AlignViewControllerGuiI;
 import jalview.api.AlignViewControllerI;
 import jalview.api.AlignViewportI;
@@ -45,6 +45,7 @@ import jalview.commands.RemoveGapColCommand;
 import jalview.commands.RemoveGapsCommand;
 import jalview.commands.SlideSequencesCommand;
 import jalview.commands.TrimRegionCommand;
+import jalview.datamodel.AlignExportSettingsAdapter;
 import jalview.datamodel.AlignedCodonFrame;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
@@ -54,7 +55,6 @@ import jalview.datamodel.AlignmentOrder;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
-import jalview.datamodel.HiddenSequences;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SeqCigar;
 import jalview.datamodel.Sequence;
@@ -87,7 +87,9 @@ import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemes;
 import jalview.schemes.ResidueColourScheme;
 import jalview.schemes.TCoffeeColourScheme;
+import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
+import jalview.util.dialogrunner.RunResponse;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.ViewportRanges;
 import jalview.ws.DBRefFetcher;
@@ -98,6 +100,7 @@ import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.seqfetcher.DbSourceProxy;
 
 import java.awt.BorderLayout;
+import java.awt.Color;
 import java.awt.Component;
 import java.awt.Rectangle;
 import java.awt.Toolkit;
@@ -135,11 +138,14 @@ import java.util.List;
 import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JComponent;
 import javax.swing.JEditorPane;
 import javax.swing.JInternalFrame;
+import javax.swing.JLabel;
 import javax.swing.JLayeredPane;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
+import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.SwingUtilities;
 
@@ -178,6 +184,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   String fileName = null;
 
+  File fileObject;
+
   /**
    * Creates a new AlignFrame object with specific width and height.
    * 
@@ -378,7 +386,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (Desktop.desktop != null)
     {
       this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
-      addServiceListeners();
+      /**
+       * BH 2018 ignore service listeners
+       * 
+       * @j2sNative
+       * 
+       */
+      {
+        addServiceListeners();
+      }
       setGUINucleotide();
     }
 
@@ -497,6 +513,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
+   * 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
    * events
    */
@@ -647,7 +674,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
         case KeyEvent.VK_F2:
           viewport.cursorMode = !viewport.cursorMode;
-          statusBar.setText(MessageManager
+          setStatus(MessageManager
                   .formatMessage("label.keyboard_editing_mode", new String[]
                   { (viewport.cursorMode ? "on" : "off") }));
           if (viewport.cursorMode)
@@ -983,9 +1010,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   @Override
-  public void fetchSequence_actionPerformed(ActionEvent e)
+  public void fetchSequence_actionPerformed()
   {
-    new jalview.gui.SequenceFetcher(this);
+    new SequenceFetcher(this);
   }
 
   @Override
@@ -1035,11 +1062,23 @@ 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())
@@ -1084,7 +1123,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (fileName == null || (currentFileFormat == null)
             || fileName.startsWith("http"))
     {
-      saveAs_actionPerformed(null);
+      saveAs_actionPerformed();
     }
     else
     {
@@ -1093,13 +1132,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
+   * Saves the alignment to a file with a name chosen by the user, if necessary
+   * warning if a file would be overwritten
    */
   @Override
-  public void saveAs_actionPerformed(ActionEvent e)
+  public void saveAs_actionPerformed()
   {
     String format = currentFileFormat == null ? null
             : currentFileFormat.getName();
@@ -1113,205 +1150,222 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     int value = chooser.showSaveDialog(this);
 
-    if (value == JalviewFileChooser.APPROVE_OPTION)
+    if (value != JalviewFileChooser.APPROVE_OPTION)
+    {
+      return;
+    }
+    currentFileFormat = chooser.getSelectedFormat();
+    // todo is this (2005) test now obsolete - value is never null?
+    while (currentFileFormat == null)
     {
+      JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+              MessageManager
+                      .getString("label.select_file_format_before_saving"),
+              MessageManager.getString("label.file_format_not_specified"),
+              JvOptionPane.WARNING_MESSAGE);
       currentFileFormat = chooser.getSelectedFormat();
-      while (currentFileFormat == null)
+      value = chooser.showSaveDialog(this);
+      if (value != JalviewFileChooser.APPROVE_OPTION)
       {
-        JvOptionPane.showInternalMessageDialog(Desktop.desktop,
-                MessageManager.getString(
-                        "label.select_file_format_before_saving"),
-                MessageManager.getString("label.file_format_not_specified"),
-                JvOptionPane.WARNING_MESSAGE);
-        currentFileFormat = chooser.getSelectedFormat();
-        value = chooser.showSaveDialog(this);
-        if (value != JalviewFileChooser.APPROVE_OPTION)
-        {
-          return;
-        }
+        return;
       }
+    }
 
-      fileName = chooser.getSelectedFile().getPath();
+    fileName = chooser.getSelectedFile().getPath();
 
-      Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
+    Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
+    Cache.setProperty("LAST_DIRECTORY", fileName);
+    saveAlignment(fileName, currentFileFormat);
+  }
 
-      Cache.setProperty("LAST_DIRECTORY", fileName);
-      saveAlignment(fileName, currentFileFormat);
+  boolean lastSaveSuccessful = false;
+
+  FileFormatI lastFormatSaved;
+
+  String lastFilenameSaved;
+
+  /**
+   * Raise a dialog or status message for the last call to saveAlignment.
+   *
+   * @return true if last call to saveAlignment(file, format) was successful.
+   */
+  public boolean isSaveAlignmentSuccessful()
+  {
+
+    if (!lastSaveSuccessful)
+    {
+      JvOptionPane.showInternalMessageDialog(this, MessageManager
+              .formatMessage("label.couldnt_save_file", new Object[]
+              { lastFilenameSaved }),
+              MessageManager.getString("label.error_saving_file"),
+              JvOptionPane.WARNING_MESSAGE);
     }
+    else
+    {
+
+      setStatus(MessageManager.formatMessage(
+              "label.successfully_saved_to_file_in_format", new Object[]
+              { lastFilenameSaved, lastFormatSaved }));
+
+    }
+    return lastSaveSuccessful;
   }
 
-  public boolean saveAlignment(String file, FileFormatI format)
+  /**
+   * Saves the alignment to the specified file path, in the specified format,
+   * which may be an alignment format, or Jalview project format. If the
+   * alignment has hidden regions, or the format is one capable of including
+   * non-sequence data (features, annotations, groups), then the user may be
+   * prompted to specify what to include in the output.
+   * 
+   * @param file
+   * @param format
+   */
+  public void saveAlignment(String file, FileFormatI format)
   {
-    boolean success = true;
+    lastSaveSuccessful = false;
+    lastFilenameSaved = file;
+    lastFormatSaved = format;
 
     if (FileFormat.Jalview.equals(format))
     {
       String shortName = title;
-
-      if (shortName.indexOf(java.io.File.separatorChar) > -1)
+      if (shortName.indexOf(File.separatorChar) > -1)
       {
         shortName = shortName.substring(
-                shortName.lastIndexOf(java.io.File.separatorChar) + 1);
+                shortName.lastIndexOf(File.separatorChar) + 1);
       }
-
-      success = new jalview.project.Jalview2XML().saveAlignment(this, file,
+      lastSaveSuccessful = new jalview.project.Jalview2XML().saveAlignment(this, file,
               shortName);
-
+      
       statusBar.setText(MessageManager.formatMessage(
               "label.successfully_saved_to_file_in_format", new Object[]
               { fileName, format }));
-
+      
+      return;
     }
-    else
+
+    AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
+    RunResponse cancelAction = new RunResponse(JvOptionPane.CANCEL_OPTION)
     {
-      AlignmentExportData exportData = getAlignmentForExport(format,
-              viewport, null);
-      if (exportData.getSettings().isCancelled())
-      {
-        return false;
-      }
-      FormatAdapter f = new FormatAdapter(alignPanel,
-              exportData.getSettings());
-      String output = f.formatSequences(format, exportData.getAlignment(), // class
-                                                                           // cast
-                                                                           // exceptions
-                                                                           // will
-              // occur in the distant future
-              exportData.getOmitHidden(), exportData.getStartEndPostions(),
-              f.getCacheSuffixDefault(format),
-              viewport.getAlignment().getHiddenColumns());
-
-      if (output == null)
+      @Override
+      public void run()
       {
-        success = false;
+        lastSaveSuccessful = false;
       }
-      else
+    };
+    RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION)
+    {
+      @Override
+      public void run()
       {
-        try
+        // todo defer this to inside formatSequences (or later)
+        AlignmentExportData exportData = viewport
+                .getAlignExportData(options);
+        String output = new FormatAdapter(alignPanel, options)
+                .formatSequences(format, exportData.getAlignment(),
+                        exportData.getOmitHidden(),
+                        exportData.getStartEndPostions(),
+                        viewport.getAlignment().getHiddenColumns());
+        if (output == null)
         {
-          PrintWriter out = new PrintWriter(new FileWriter(file));
-
-          out.print(output);
-          out.close();
-          this.setTitle(file);
-          statusBar.setText(MessageManager.formatMessage(
-                  "label.successfully_saved_to_file_in_format", new Object[]
-                  { fileName, format.getName() }));
-        } catch (Exception ex)
+          lastSaveSuccessful = false;
+        }
+        else
         {
-          success = false;
-          ex.printStackTrace();
+          try
+          {
+            PrintWriter out = new PrintWriter(new FileWriter(file));
+            out.print(output);
+            out.close();
+            AlignFrame.this.setTitle(file);
+            setStatus(MessageManager.formatMessage(
+                    "label.successfully_saved_to_file_in_format",
+                    new Object[]
+                    { fileName, format.getName() }));
+          } catch (Exception ex)
+          {
+            lastSaveSuccessful = false;
+            ex.printStackTrace();
+          }
         }
       }
-    }
-
-    if (!success)
-    {
-      JvOptionPane.showInternalMessageDialog(this, MessageManager
-              .formatMessage("label.couldnt_save_file", new Object[]
-              { fileName }),
-              MessageManager.getString("label.error_saving_file"),
-              JvOptionPane.WARNING_MESSAGE);
-    }
-
-    return success;
-  }
+    };
 
-  private void warningMessage(String warning, String title)
-  {
-    if (new jalview.util.Platform().isHeadless())
+    /*
+     * show dialog with export options if applicable; else just do it
+     */
+    if (AlignExportOptions.isNeeded(viewport, format))
     {
-      System.err.println("Warning: " + title + "\nWarning: " + warning);
-
+      AlignExportOptions choices = new AlignExportOptions(
+              alignPanel.getAlignViewport(), format, options);
+      choices.setResponseAction(outputAction);
+      choices.setResponseAction(cancelAction);
+      choices.showDialog();
     }
     else
     {
-      JvOptionPane.showInternalMessageDialog(this, warning, title,
-              JvOptionPane.WARNING_MESSAGE);
+      outputAction.run();
     }
-    return;
   }
 
   /**
-   * DOCUMENT ME!
+   * Outputs the alignment to textbox in the requested format, if necessary
+   * first prompting the user for whether to include hidden regions or
+   * non-sequence data
    * 
-   * @param e
-   *          DOCUMENT ME!
+   * @param fileFormatName
    */
   @Override
-  protected void outputText_actionPerformed(ActionEvent e)
+  protected void outputText_actionPerformed(String fileFormatName)
   {
     FileFormatI fileFormat = FileFormats.getInstance()
-            .forName(e.getActionCommand());
-    AlignmentExportData exportData = getAlignmentForExport(fileFormat,
-            viewport, null);
-    if (exportData.getSettings().isCancelled())
-    {
-      return;
-    }
-    CutAndPasteTransfer cap = new CutAndPasteTransfer();
-    cap.setForInput(null);
-    try
-    {
-      FileFormatI format = fileFormat;
-      cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
-              .formatSequences(format, exportData.getAlignment(),
-                      exportData.getOmitHidden(),
-                      exportData.getStartEndPostions(),
-                      viewport.getAlignment().getHiddenColumns()));
-      Desktop.addInternalFrame(cap, MessageManager
-              .formatMessage("label.alignment_output_command", new Object[]
-              { e.getActionCommand() }), 600, 500);
-    } catch (OutOfMemoryError oom)
-    {
-      new OOMWarning("Outputting alignment as " + e.getActionCommand(),
-              oom);
-      cap.dispose();
-    }
-
-  }
-
-  public static AlignmentExportData getAlignmentForExport(
-          FileFormatI format, AlignViewportI viewport,
-          AlignExportSettingI exportSettings)
-  {
-    AlignmentI alignmentToExport = null;
-    AlignExportSettingI settings = exportSettings;
-    String[] omitHidden = null;
-
-    HiddenSequences hiddenSeqs = viewport.getAlignment()
-            .getHiddenSequences();
-
-    alignmentToExport = viewport.getAlignment();
-
-    boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
-    if (settings == null)
+            .forName(fileFormatName);
+    AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
+    RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION)
     {
-      settings = new AlignExportSettings(hasHiddenSeqs,
-              viewport.hasHiddenColumns(), format);
-    }
-    // settings.isExportAnnotations();
-
-    if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
-    {
-      omitHidden = viewport.getViewAsString(false,
-              settings.isExportHiddenSequences());
-    }
+      @Override
+      public void run()
+      {
+        // todo defer this to inside formatSequences (or later)
+        AlignmentExportData exportData = viewport
+                .getAlignExportData(options);
+        CutAndPasteTransfer cap = new CutAndPasteTransfer();
+        cap.setForInput(null);
+        try
+        {
+          FileFormatI format = fileFormat;
+          cap.setText(new FormatAdapter(alignPanel, options)
+                  .formatSequences(format, exportData.getAlignment(),
+                          exportData.getOmitHidden(),
+                          exportData.getStartEndPostions(),
+                          viewport.getAlignment().getHiddenColumns()));
+          Desktop.addInternalFrame(cap, MessageManager.formatMessage(
+                  "label.alignment_output_command", new Object[]
+                  { fileFormat.getName() }), 600, 500);
+        } catch (OutOfMemoryError oom)
+        {
+          new OOMWarning("Outputting alignment as " + fileFormat.getName(),
+                  oom);
+          cap.dispose();
+        }
+      }
+    };
 
-    int[] alignmentStartEnd = new int[2];
-    if (hasHiddenSeqs && settings.isExportHiddenSequences())
+    /*
+     * show dialog with export options if applicable; else just do it
+     */
+    if (AlignExportOptions.isNeeded(viewport, fileFormat))
     {
-      alignmentToExport = hiddenSeqs.getFullAlignment();
+      AlignExportOptions choices = new AlignExportOptions(
+              alignPanel.getAlignViewport(), fileFormat, options);
+      choices.setResponseAction(outputAction);
+      choices.showDialog();
     }
     else
     {
-      alignmentToExport = viewport.getAlignment();
+      outputAction.run();
     }
-    alignmentStartEnd = viewport.getAlignment().getHiddenColumns()
-            .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
-    AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
-            omitHidden, alignmentStartEnd, settings);
-    return ed;
   }
 
   /**
@@ -1340,33 +1394,39 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
-   * DOCUMENT ME!
+   * Creates a PNG image of the alignment and writes it to the given file. If
+   * the file is null, the user is prompted to choose a file.
    * 
-   * @param e
-   *          DOCUMENT ME!
+   * @param f
    */
   @Override
   public void createPNG(File f)
   {
-    alignPanel.makePNG(f);
+    alignPanel.makeAlignmentImage(TYPE.PNG, f);
   }
 
   /**
-   * DOCUMENT ME!
+   * Creates an EPS image of the alignment and writes it to the given file. If
+   * the file is null, the user is prompted to choose a file.
    * 
-   * @param e
-   *          DOCUMENT ME!
+   * @param f
    */
   @Override
   public void createEPS(File f)
   {
-    alignPanel.makeEPS(f);
+    alignPanel.makeAlignmentImage(TYPE.EPS, f);
   }
 
+  /**
+   * Creates an SVG image of the alignment and writes it to the given file. If
+   * the file is null, the user is prompted to choose a file.
+   * 
+   * @param f
+   */
   @Override
   public void createSVG(File f)
   {
-    alignPanel.makeSVG(f);
+    alignPanel.makeAlignmentImage(TYPE.SVG, f);
   }
 
   @Override
@@ -1405,24 +1465,27 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void associatedData_actionPerformed(ActionEvent e)
   {
-    // Pick the tree file
-    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"));
+    chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+    {
 
-    int value = chooser.showOpenDialog(null);
+      @Override
+      public void run()
+      {
+        String choice = chooser.getSelectedFile().getPath();
+        jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
+        loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
+      }
 
-    if (value == JalviewFileChooser.APPROVE_OPTION)
-    {
-      String choice = chooser.getSelectedFile().getPath();
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
-      loadJalviewDataFile(choice, null, null, null);
-    }
+    });
 
+    chooser.openDialog(this);
   }
 
   /**
@@ -1879,7 +1942,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     Desktop.jalviewClipboard = new Object[] { seqs,
         viewport.getAlignment().getDataset(), hiddenColumns };
-    statusBar.setText(MessageManager.formatMessage(
+    setStatus(MessageManager.formatMessage(
             "label.copied_sequences_to_clipboard", new Object[]
             { Integer.valueOf(seqs.length).toString() }));
   }
@@ -2544,7 +2607,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 column, viewport.getAlignment());
       }
 
-      statusBar.setText(MessageManager
+      setStatus(MessageManager
               .formatMessage("label.removed_columns", new String[]
               { Integer.valueOf(trimRegion.getSize()).toString() }));
 
@@ -2594,7 +2657,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     addHistoryItem(removeGapCols);
 
-    statusBar.setText(MessageManager
+    setStatus(MessageManager
             .formatMessage("label.removed_empty_columns", new Object[]
             { Integer.valueOf(removeGapCols.getSize()).toString() }));
 
@@ -3213,15 +3276,37 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void alignmentProperties()
   {
-    JEditorPane editPane = new JEditorPane("text/html", "");
-    editPane.setEditable(false);
+    JComponent pane;
     StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
+
             .formatAsHtml();
-    editPane.setText(
-            MessageManager.formatMessage("label.html_content", new Object[]
-            { contents.toString() }));
+    String content = MessageManager.formatMessage("label.html_content",
+            new Object[]
+            { contents.toString() });
+    contents = null;
+
+    if (Jalview.isJS())
+    {
+      JLabel textLabel = new JLabel();
+      textLabel.setText(content);
+      textLabel.setBackground(Color.WHITE);
+      
+      pane = new JPanel(new BorderLayout());
+      ((JPanel) pane).setOpaque(true);
+      pane.setBackground(Color.WHITE);
+      ((JPanel) pane).add(textLabel, BorderLayout.NORTH);
+    }
+    else
+    {
+      JEditorPane editPane = new JEditorPane("text/html", "");
+      editPane.setEditable(false);
+      editPane.setText(content);
+      pane = editPane;
+    }
+
     JInternalFrame frame = new JInternalFrame();
-    frame.getContentPane().add(new JScrollPane(editPane));
+
+    frame.getContentPane().add(new JScrollPane(pane));
 
     Desktop.addInternalFrame(frame, MessageManager
             .formatMessage("label.alignment_properties", new Object[]
@@ -3881,33 +3966,38 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     chooser.setToolTipText(
             MessageManager.getString("label.load_tree_file"));
 
-    int value = chooser.showOpenDialog(null);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
+    chooser.response(new jalview.util.dialogrunner.RunResponse(
+            JalviewFileChooser.APPROVE_OPTION)
     {
-      String filePath = chooser.getSelectedFile().getPath();
-      Cache.setProperty("LAST_DIRECTORY", filePath);
-      NewickFile fin = null;
-      try
-      {
-        fin = new NewickFile(filePath, DataSourceType.FILE);
-        viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
-      } catch (Exception ex)
-      {
-        JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
-                MessageManager.getString("label.problem_reading_tree_file"),
-                JvOptionPane.WARNING_MESSAGE);
-        ex.printStackTrace();
-      }
-      if (fin != null && fin.hasWarningMessage())
+      @Override
+      public void run()
       {
-        JvOptionPane.showMessageDialog(Desktop.desktop,
-                fin.getWarningMessage(),
-                MessageManager
-                        .getString("label.possible_problem_with_tree_file"),
-                JvOptionPane.WARNING_MESSAGE);
+        String filePath = chooser.getSelectedFile().getPath();
+        Cache.setProperty("LAST_DIRECTORY", filePath);
+        NewickFile fin = null;
+        try
+        {
+          fin = new NewickFile(new FileParse(chooser.getSelectedFile(),
+                  DataSourceType.FILE));
+          viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
+        } catch (Exception ex)
+        {
+          JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
+                  MessageManager
+                          .getString("label.problem_reading_tree_file"),
+                  JvOptionPane.WARNING_MESSAGE);
+          ex.printStackTrace();
+        }
+        if (fin != null && fin.hasWarningMessage())
+        {
+          JvOptionPane.showMessageDialog(Desktop.desktop,
+                  fin.getWarningMessage(),
+                  MessageManager.getString(
+                          "label.possible_problem_with_tree_file"),
+                  JvOptionPane.WARNING_MESSAGE);
+        }
       }
-    }
+    }).openDialog(this);
   }
 
   public TreePanel showNewickTree(NewickFile nf, String treeTitle)
@@ -4327,13 +4417,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * Try to load a features file onto the alignment.
    * 
    * @param file
-   *          contents or path to retrieve file
+   *          contents or path to retrieve file or a File object
    * @param sourceType
    *          access mode of file (see jalview.io.AlignFile)
    * @return true if features file was parsed correctly.
    */
-  public boolean parseFeaturesFile(String file, DataSourceType sourceType)
+  public boolean parseFeaturesFile(Object file, DataSourceType sourceType)
   {
+    // BH 2018
     return avc.parseFeaturesFile(file, sourceType,
             Cache.getDefault("RELAXEDSEQIDMATCHING", false));
 
@@ -4380,8 +4471,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     // Java's Transferable for native dnd
     evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
     Transferable t = evt.getTransferable();
+
     final AlignFrame thisaf = this;
-    final List<String> files = new ArrayList<>();
+    final List<Object> files = new ArrayList<>();
     List<DataSourceType> protocols = new ArrayList<>();
 
     try
@@ -4409,20 +4501,25 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
              * Object[] { String,SequenceI}
              */
             ArrayList<Object[]> filesmatched = new ArrayList<>();
-            ArrayList<String> filesnotmatched = new ArrayList<>();
+            ArrayList<Object> filesnotmatched = new ArrayList<>();
             for (int i = 0; i < files.size(); i++)
             {
-              String file = files.get(i).toString();
+              // BH 2018
+              Object file = files.get(i);
+              String fileName = file.toString();
               String pdbfn = "";
-              DataSourceType protocol = FormatAdapter.checkProtocol(file);
+              DataSourceType protocol = (file instanceof File
+                      ? DataSourceType.FILE
+                      : FormatAdapter.checkProtocol(fileName));
               if (protocol == DataSourceType.FILE)
               {
-                File fl = new File(file);
+                File fl = (file instanceof File ? (File) file
+                        : new File(fileName));
                 pdbfn = fl.getName();
               }
               else if (protocol == DataSourceType.URL)
               {
-                URL url = new URL(file);
+                URL url = new URL(fileName);
                 pdbfn = url.getFile();
               }
               if (pdbfn.length() > 0)
@@ -4444,7 +4541,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 }
                 if (mtch != null)
                 {
-                  FileFormatI type = null;
+                  FileFormatI type;
                   try
                   {
                     type = new IdentifyFile().identify(file, protocol);
@@ -4466,7 +4563,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             int assocfiles = 0;
             if (filesmatched.size() > 0)
             {
-              boolean autoAssociate = Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false);
+              boolean autoAssociate = Cache
+                      .getDefault("AUTOASSOCIATE_PDBANDSEQS", false);
               if (!autoAssociate)
               {
                 String msg = MessageManager.formatMessage(
@@ -4490,13 +4588,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                   for (SequenceI toassoc : (SequenceI[]) fm[2])
                   {
                     PDBEntry pe = new AssociatePdbFileWithSeq()
-                            .associatePdbWithSeq((String) fm[0],
+                            .associatePdbWithSeq(fm[0].toString(),
                                     (DataSourceType) fm[1], toassoc, false,
                                     Desktop.instance);
                     if (pe != null)
                     {
                       System.err.println("Associated file : "
-                              + ((String) fm[0]) + " with "
+                              + (fm[0].toString()) + " with "
                               + toassoc.getDisplayId(true));
                       assocfiles++;
                     }
@@ -4513,7 +4611,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                  */
                 for (Object[] o : filesmatched)
                 {
-                  filesnotmatched.add((String) o[0]);
+                  filesnotmatched.add(o[0]);
                 }
               }
             }
@@ -4535,7 +4633,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               {
                 return;
               }
-              for (String fn : filesnotmatched)
+              for (Object fn : filesnotmatched)
               {
                 loadJalviewDataFile(fn, null, null, null);
               }
@@ -4562,9 +4660,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param file
    *          either a filename or a URL string.
    */
-  public void loadJalviewDataFile(String file, DataSourceType sourceType,
+  public void loadJalviewDataFile(Object file, DataSourceType sourceType,
           FileFormatI format, SequenceI assocSeq)
   {
+    // BH 2018 was String file
     try
     {
       if (sourceType == null)
@@ -4595,7 +4694,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               changeColour(
                       new TCoffeeColourScheme(viewport.getAlignment()));
               isAnnotation = true;
-              statusBar.setText(MessageManager.getString(
+              setStatus(MessageManager.getString(
                       "label.successfully_pasted_tcoffee_scores_to_alignment"));
             }
             else
@@ -4638,7 +4737,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     new FileParse(file, sourceType));
             sm.parse();
             // todo: i18n this message
-            statusBar.setText(MessageManager.formatMessage(
+            setStatus(MessageManager.formatMessage(
                     "label.successfully_loaded_matrix",
                     sm.getMatrixName()));
           }
@@ -4764,8 +4863,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (e.isPopupTrigger())
     {
       String msg = MessageManager.getString("label.enter_view_name");
-      String reply = JvOptionPane.showInternalInputDialog(this, msg, msg,
-              JvOptionPane.QUESTION_MESSAGE);
+      String ttl = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
+      String reply = JvOptionPane.showInputDialog(msg, ttl);
 
       if (reply != null)
       {
@@ -4920,22 +5019,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     });
     rfetch.add(fetchr);
-    final AlignFrame me = this;
     new Thread(new Runnable()
     {
       @Override
       public void run()
       {
         final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
-                .getSequenceFetcherSingleton(me);
+                .getSequenceFetcherSingleton();
         javax.swing.SwingUtilities.invokeLater(new Runnable()
         {
           @Override
           public void run()
           {
-            String[] dbclasses = sf.getOrderedSupportedSources();
-            // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
-            // jalview.util.QuickSort.sort(otherdb, otherdb);
+            String[] dbclasses = sf.getNonAlignmentSources();
             List<DbSourceProxy> otherdb;
             JMenu dfetch = new JMenu();
             JMenu ifetch = new JMenu();
@@ -4952,12 +5048,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               {
                 continue;
               }
-              // List<DbSourceProxy> dbs=otherdb;
-              // otherdb=new ArrayList<DbSourceProxy>();
-              // for (DbSourceProxy db:dbs)
-              // {
-              // if (!db.isA(DBRefSource.ALIGNMENTDB)
-              // }
               if (mname == null)
               {
                 mname = "From " + dbclass;
@@ -5606,18 +5696,25 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
     chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
+    final AlignFrame us = this;
+    chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+    {
+      @Override
+      public void run()
+      {
 
-    int value = chooser.showOpenDialog(null);
+        {
+          String choice = chooser.getSelectedFile().getPath();
+          Cache.setProperty("LAST_DIRECTORY", choice);
+          SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
+          new VCFLoader(choice).loadVCF(seqs, us);
+        }
 
-    if (value == JalviewFileChooser.APPROVE_OPTION)
-    {
-      String choice = chooser.getSelectedFile().getPath();
-      Cache.setProperty("LAST_DIRECTORY", choice);
-      SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
-      new VCFLoader(choice).loadVCF(seqs, this);
-    }
+      };
+    }).openDialog(null);
 
   }
+
 }
 
 class PrintThread extends Thread