JAL-3809 - Fixed param edit dialog for jalviewjs.
[jalview.git] / src / jalview / gui / AlignFrame.java
index de82fd8..db6870e 100644 (file)
@@ -27,7 +27,7 @@ import jalview.analysis.Dna;
 import jalview.analysis.GeneticCodeI;
 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;
@@ -47,6 +47,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;
@@ -56,7 +57,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;
@@ -64,6 +64,13 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.gui.ColourMenuHelper.ColourChangeListener;
 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
+import jalview.hmmer.HMMAlign;
+import jalview.hmmer.HMMBuild;
+import jalview.hmmer.HMMERParamStore;
+import jalview.hmmer.HMMERPreset;
+import jalview.hmmer.HMMSearch;
+import jalview.hmmer.HmmerCommand;
+import jalview.hmmer.JackHMMER;
 import jalview.io.AlignmentProperties;
 import jalview.io.AnnotationFile;
 import jalview.io.BackupFiles;
@@ -86,22 +93,40 @@ import jalview.io.ScoreMatrixFile;
 import jalview.io.TCoffeeScoreFile;
 import jalview.io.vcf.VCFLoader;
 import jalview.jbgui.GAlignFrame;
+import jalview.project.Jalview2XML;
 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.Platform;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.ViewportRanges;
 import jalview.ws.DBRefFetcher;
 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
+import jalview.ws.ServiceChangeListener;
+import jalview.ws.WSDiscovererI;
+import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.jws1.Discoverer;
 import jalview.ws.jws2.Jws2Discoverer;
-import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.jws2.PreferredServiceRegistry;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.WsParamSetI;
 import jalview.ws.seqfetcher.DbSourceProxy;
+import jalview.ws.slivkaws.SlivkaWSDiscoverer;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
 
 import java.awt.BorderLayout;
+import java.awt.Color;
 import java.awt.Component;
+import java.awt.Dimension;
 import java.awt.Rectangle;
 import java.awt.Toolkit;
 import java.awt.datatransfer.Clipboard;
@@ -125,12 +150,14 @@ import java.awt.event.MouseEvent;
 import java.awt.print.PageFormat;
 import java.awt.print.PrinterJob;
 import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.PrintWriter;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Deque;
 import java.util.Enumeration;
 import java.util.Hashtable;
@@ -139,13 +166,20 @@ import java.util.Vector;
 
 import javax.swing.ButtonGroup;
 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;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
+
+import ext.vamsas.ServiceHandle;
 
 /**
  * DOCUMENT ME!
@@ -153,10 +187,14 @@ import javax.swing.SwingUtilities;
  * @author $author$
  * @version $Revision$
  */
-public class AlignFrame extends GAlignFrame implements DropTargetListener,
-        IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
+@SuppressWarnings("serial")
+public class AlignFrame extends GAlignFrame
+        implements DropTargetListener, IProgressIndicator,
+        AlignViewControllerGuiI, ColourChangeListener, ServiceChangeListener
 {
 
+  public static int frameCount;
+
   public static final int DEFAULT_WIDTH = 700;
 
   public static final int DEFAULT_HEIGHT = 500;
@@ -183,6 +221,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   String fileName = null;
 
   /**
+   * TODO: remove reference to 'FileObject' in AlignFrame - not correct mapping
+   */
+  File fileObject;
+
+  private int id;
+
+  private DataSourceType protocol ;
+
+  /**
    * Creates a new AlignFrame object with specific width and height.
    * 
    * @param al
@@ -276,6 +323,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
           int height, String sequenceSetId, String viewId)
   {
+
+    id = (++frameCount);
+
     setSize(width, height);
 
     if (al.getDataset() == null)
@@ -285,9 +335,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
 
-    alignPanel = new AlignmentPanel(this, viewport);
-
-    addAlignmentPanel(alignPanel, true);
+    // JalviewJS needs to distinguish a new panel from an old one in init()
+    // alignPanel = new AlignmentPanel(this, viewport);
+    // addAlignmentPanel(alignPanel, true);
     init();
   }
 
@@ -307,8 +357,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     {
       viewport.hideSequence(hiddenSeqs);
     }
-    alignPanel = new AlignmentPanel(this, viewport);
-    addAlignmentPanel(alignPanel, true);
+    // alignPanel = new AlignmentPanel(this, viewport);
+    // addAlignmentPanel(alignPanel, true);
     init();
   }
 
@@ -324,7 +374,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     viewport = ap.av;
     alignPanel = ap;
-    addAlignmentPanel(ap, false);
+    // addAlignmentPanel(ap, false);
     init();
   }
 
@@ -332,11 +382,38 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * initalise the alignframe from the underlying viewport data and the
    * configurations
    */
+
   void init()
   {
+    boolean newPanel = (alignPanel == null);
+    viewport.setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
+    if (newPanel)
+    {
+      if (Platform.isJS())
+      {
+        // need to set this up front if NOANNOTATION is
+        // used in conjunction with SHOWOVERVIEW.
+
+        // I have not determined if this is appropriate for
+        // Jalview/Java, as it means we are setting this flag
+        // for all subsequent AlignFrames. For now, at least,
+        // I am setting it to be JalviewJS-only.
+
+        boolean showAnnotation = Jalview.getInstance().getShowAnnotation();
+        viewport.setShowAnnotation(showAnnotation);
+      }
+      alignPanel = new AlignmentPanel(this, viewport);
+    }
+    addAlignmentPanel(alignPanel, newPanel);
+
+    // setBackground(Color.white); // BH 2019
+
     if (!Jalview.isHeadlessMode())
     {
       progressBar = new ProgressBar(this.statusPanel, this.statusBar);
+      // JalviewJS options
+      statusPanel.setVisible(Jalview.getInstance().getShowStatus());
+      alignFrameMenuBar.setVisible(Jalview.getInstance().getAllowMenuBar());
     }
 
     avc = new jalview.controller.AlignViewController(this, viewport,
@@ -351,7 +428,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       // modifyPID.setEnabled(false);
     }
 
-    String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
+    String sortby = jalview.bin.Cache.getDefault(Preferences.SORT_ALIGNMENT,
             "No sort");
 
     if (sortby.equals("Id"))
@@ -363,8 +440,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       sortPairwiseMenuItem_actionPerformed(null);
     }
 
-    this.alignPanel.av
-            .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
+    // BH see above
+    //
+    // this.alignPanel.av
+    // .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
 
     setMenusFromViewport(viewport);
     buildSortByAnnotationScoresMenu();
@@ -379,10 +458,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     });
     buildColourMenu();
 
-    if (Desktop.desktop != null)
+    if (Desktop.getDesktopPane() != null)
     {
       this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
       addServiceListeners();
+      if (!Platform.isJS())
+      {
+      }
       setGUINucleotide();
     }
 
@@ -391,7 +473,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       wrapMenuItem_actionPerformed(null);
     }
 
-    if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
+    if (jalview.bin.Cache.getDefault(Preferences.SHOW_OVERVIEW, false))
     {
       this.overviewMenuItem_actionPerformed(null);
     }
@@ -475,6 +557,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
     addFocusListener(new FocusAdapter()
     {
+
       @Override
       public void focusGained(FocusEvent e)
       {
@@ -493,6 +576,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param format
    *          format of file
    */
+
+  @Deprecated
   public void setFileName(String file, FileFormatI format)
   {
     fileName = file;
@@ -501,13 +586,43 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
+   * 
+   * @param fileName
+   * @param file  from SwingJS; may contain bytes -- for reload
+   * @param protocol from SwingJS; may be RELATIVE_URL
+   * @param format
+   */
+  public void setFile(String fileName, File file, DataSourceType protocol, FileFormatI format)
+  {
+    this.fileName = fileName;
+    this.fileObject = file;
+    this.protocol = protocol;
+    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
    * events
    */
+
   void addKeyListener()
   {
     addKeyListener(new KeyAdapter()
     {
+
       @Override
       public void keyPressed(KeyEvent evt)
       {
@@ -524,8 +639,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         switch (evt.getKeyCode())
         {
 
-        case 27: // escape key
-          deselectAllSequenceMenuItem_actionPerformed(null);
+        case KeyEvent.VK_ESCAPE: // escape key
+                                 // alignPanel.deselectAllSequences();
+          alignPanel.deselectAllSequences();
 
           break;
 
@@ -599,7 +715,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         case KeyEvent.VK_BACK_SPACE:
           if (!viewport.cursorMode)
           {
-            cut_actionPerformed(null);
+            cut_actionPerformed();
           }
           else
           {
@@ -651,7 +767,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)
@@ -708,16 +824,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         case KeyEvent.VK_LEFT:
           if (evt.isAltDown() || !viewport.cursorMode)
           {
-            viewport.firePropertyChange("alignment", null,
-                    viewport.getAlignment().getSequences());
+            viewport.notifyAlignment();
           }
           break;
 
         case KeyEvent.VK_RIGHT:
           if (evt.isAltDown() || !viewport.cursorMode)
           {
-            viewport.firePropertyChange("alignment", null,
-                    viewport.getAlignment().getSequences());
+            viewport.notifyAlignment();
           }
           break;
         }
@@ -763,9 +877,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       {
         ap.av.getAlignment().padGaps();
       }
-      ap.av.updateConservation(ap);
-      ap.av.updateConsensus(ap);
-      ap.av.updateStrucConsensus(ap);
+      if (Jalview.getInstance().getStartCalculations())
+      {
+        ap.av.updateConservation(ap);
+        ap.av.updateConsensus(ap);
+        ap.av.updateStrucConsensus(ap);
+        ap.av.initInformationWorker(ap);
+      }
     }
   }
 
@@ -784,61 +902,50 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     return viewport;
   }
 
+  @Override
+  public void servicesChanged(WSDiscovererI discoverer,
+          Collection<? extends ServiceWithParameters> services)
+  {
+    buildWebServicesMenu();
+  }
+
   /* Set up intrinsic listeners for dynamically generated GUI bits. */
   private void addServiceListeners()
   {
-    final java.beans.PropertyChangeListener thisListener;
-    Desktop.instance.addJalviewPropertyChangeListener("services",
-            thisListener = new java.beans.PropertyChangeListener()
-            {
-              @Override
-              public void propertyChange(PropertyChangeEvent evt)
-              {
-                // // System.out.println("Discoverer property change.");
-                // if (evt.getPropertyName().equals("services"))
-                {
-                  SwingUtilities.invokeLater(new Runnable()
-                  {
-
-                    @Override
-                    public void run()
-                    {
-                      System.err.println(
-                              "Rebuild WS Menu for service change");
-                      BuildWebServiceMenu();
-                    }
-
-                  });
-                }
-              }
-            });
-    addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+    if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
     {
-      @Override
-      public void internalFrameClosed(
-              javax.swing.event.InternalFrameEvent evt)
-      {
-        // System.out.println("deregistering discoverer listener");
-        Desktop.instance.removeJalviewPropertyChangeListener("services",
-                thisListener);
-        closeMenuItem_actionPerformed(true);
-      };
-    });
-    // Finally, build the menu once to get current service state
-    new Thread(new Runnable()
+      WSDiscovererI discoverer = SlivkaWSDiscoverer.getInstance();
+      discoverer.addServiceChangeListener(this);
+    }
+    if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
     {
+      WSDiscovererI discoverer = Jws2Discoverer.getInstance();
+      discoverer.addServiceChangeListener(this);
+    }
+    // legacy event listener for compatibility with jws1
+    PropertyChangeListener legacyListener = (changeEvent) -> {
+      buildWebServicesMenu();
+    };
+    Desktop.getInstance().addJalviewPropertyChangeListener("services",legacyListener);
+    
+    addInternalFrameListener(new InternalFrameAdapter() {
       @Override
-      public void run()
-      {
-        BuildWebServiceMenu();
+      public void internalFrameClosed(InternalFrameEvent e) {
+        System.out.println("deregistering discoverer listener");
+        SlivkaWSDiscoverer.getInstance().removeServiceChangeListener(AlignFrame.this);
+        Jws2Discoverer.getInstance().removeServiceChangeListener(AlignFrame.this);
+        Desktop.getInstance().removeJalviewPropertyChangeListener("services", legacyListener);
+        closeMenuItem_actionPerformed(true);
       }
-    }).start();
+    });
+    buildWebServicesMenu();
   }
 
   /**
    * Configure menu items that vary according to whether the alignment is
    * nucleotide or protein
    */
+
   public void setGUINucleotide()
   {
     AlignmentI al = getViewport().getAlignment();
@@ -863,6 +970,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * operation that affects the data in the current view (selection changed,
    * etc) to update the menus to reflect the new state.
    */
+
   @Override
   public void setMenusForViewport()
   {
@@ -876,6 +984,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param av
    *          AlignViewport
    */
+
   public void setMenusFromViewport(AlignViewport av)
   {
     padGapsMenuitem.setSelected(av.isPadGaps());
@@ -893,13 +1002,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     scaleLeft.setVisible(av.getWrapAlignment());
     scaleRight.setVisible(av.getWrapAlignment());
     annotationPanelMenuItem.setState(av.isShowAnnotation());
-    /*
-     * Show/hide annotations only enabled if annotation panel is shown
-     */
-    showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
-    hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
-    showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
-    hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
+    // Show/hide annotations only enabled if annotation panel is shown
+    syncAnnotationMenuItems(av.isShowAnnotation());
     viewBoxesMenuItem.setSelected(av.getShowBoxes());
     viewTextMenuItem.setSelected(av.getShowText());
     showNonconservedMenuItem.setSelected(av.getShowUnconserved());
@@ -908,6 +1012,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
     showSequenceLogo.setSelected(av.isShowSequenceLogo());
     normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
+    showInformationHistogram.setSelected(av.isShowInformationHistogram());
+    showHMMSequenceLogo.setSelected(av.isShowHMMSequenceLogo());
+    normaliseHMMSequenceLogo.setSelected(av.isNormaliseHMMSequenceLogo());
 
     ColourMenuHelper.setColourSelected(colourMenu,
             av.getGlobalColourScheme());
@@ -917,7 +1024,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     applyToAllGroups.setState(av.getColourAppliesToAllGroups());
     showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
     showDbRefsMenuitem.setSelected(av.isShowDBRefs());
-    autoCalculate.setSelected(av.autoCalculateConsensus);
+    autoCalculate
+            .setSelected(av.getAutoCalculateConsensusAndConservation());
     sortByTree.setSelected(av.sortByTree);
     listenToViewSelections.setSelected(av.followSelection);
 
@@ -932,6 +1040,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param b
    */
+
   public void setGroovyEnabled(boolean b)
   {
     runGroovy.setEnabled(b);
@@ -944,11 +1053,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
    */
+
   @Override
   public void setProgressBar(String message, long id)
   {
     progressBar.setProgressBar(message, id);
   }
+  
+  @Override
+  public void removeProgressBar(long id)
+  {
+    progressBar.removeProgressBar(id);
+  }
 
   @Override
   public void registerHandler(final long id,
@@ -961,6 +1077,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @return true if any progress bars are still active
    */
+
   @Override
   public boolean operationInProgress()
   {
@@ -972,6 +1089,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * will cause the status bar to be hidden, with possibly undesirable flicker
    * of the screen layout.
    */
+
   @Override
   public void setStatus(String text)
   {
@@ -981,6 +1099,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /*
    * Added so Castor Mapping file can obtain Jalview Version
    */
+
   public String getVersion()
   {
     return jalview.bin.Cache.getProperty("VERSION");
@@ -992,99 +1111,370 @@ 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
   public void addFromFile_actionPerformed(ActionEvent e)
   {
-    Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
+    Desktop.getInstance().inputLocalFileMenuItem_actionPerformed(viewport);
+  }
+
+  @Override
+  public void hmmBuild_actionPerformed(boolean withDefaults)
+  {
+    if (!alignmentIsSufficient(1))
+    {
+      return;
+    }
+
+    /*
+     * get default parameters, and optionally show a dialog
+     * to allow them to be modified
+     */
+    ParamDatastoreI store = HMMERParamStore.forBuild(viewport);
+    List<ArgumentI> args = store.getServiceParameters();
+
+    if (!withDefaults)
+    {
+      WsParamSetI set = new HMMERPreset();
+      WsJobParameters params = new WsJobParameters(store, set, args);
+      params.showRunDialog().thenAccept((startJob) -> {
+        if (startJob)
+        {
+          var args2 = params.getJobParams();
+          new Thread(new HMMBuild(this, args2)).start();
+        }
+      });
+    }
+    else
+    {
+      new Thread(new HMMBuild(this, args)).start();
+    }
+  }
+
+  @Override
+  public void hmmAlign_actionPerformed(boolean withDefaults)
+  {
+    if (!(checkForHMM() && alignmentIsSufficient(2)))
+    {
+      return;
+    }
+
+    /*
+     * get default parameters, and optionally show a dialog
+     * to allow them to be modified
+     */
+    ParamDatastoreI store = HMMERParamStore.forAlign(viewport);
+    List<ArgumentI> args = store.getServiceParameters();
+
+    if (!withDefaults)
+    {
+      WsParamSetI set = new HMMERPreset();
+      WsJobParameters params = new WsJobParameters(store, set, args);
+      params.showRunDialog().thenAccept((startJob) -> {
+        if (startJob)
+        {
+          var args2 = params.getJobParams();
+          new Thread(new HMMAlign(this, args2)).start();
+        }
+      });
+    }
+    else
+    {
+      new Thread(new HMMAlign(this, args)).start();
+    }
+  }
+
+  @Override
+  public void hmmSearch_actionPerformed(boolean withDefaults)
+  {
+    if (!checkForHMM())
+    {
+      return;
+    }
+
+    /*
+     * get default parameters, and (if requested) show 
+     * dialog to allow modification
+     */
+    ParamDatastoreI store = HMMERParamStore.forSearch(viewport);
+    List<ArgumentI> args = store.getServiceParameters();
+
+    if (!withDefaults)
+    {
+      WsParamSetI set = new HMMERPreset();
+      WsJobParameters params = new WsJobParameters(store, set, args);
+      params.showRunDialog().thenAccept((startJob) -> {
+        if (startJob)
+        {
+          var args2 = params.getJobParams();
+          new Thread(new HMMSearch(this, args2)).start();
+          alignPanel.repaint();
+        }
+      });
+    }
+    else
+    {
+      new Thread(new HMMSearch(this, args)).start();
+      alignPanel.repaint();
+    }
+  }
+
+  @Override
+  public void jackhmmer_actionPerformed(boolean withDefaults)
+  {
+
+    /*
+     * get default parameters, and (if requested) show 
+     * dialog to allow modification
+     */
+
+    ParamDatastoreI store = HMMERParamStore.forJackhmmer(viewport);
+    List<ArgumentI> args = store.getServiceParameters();
+
+    if (!withDefaults)
+    {
+      WsParamSetI set = new HMMERPreset();
+      WsJobParameters params = new WsJobParameters(store, set, args);
+      params.showRunDialog().thenAccept((startJob) -> {
+        if (startJob)
+        {
+          var args2 = params.getJobParams();
+          new Thread(new JackHMMER(this, args2)).start();
+          alignPanel.repaint();
+        }
+      });
+    }
+    else
+    {
+      new Thread(new JackHMMER(this, args)).start();
+      alignPanel.repaint();
+    }
+  }
+
+  /**
+   * Checks if the alignment has at least one hidden Markov model, if not shows
+   * a dialog advising to run hmmbuild or load an HMM profile
+   * 
+   * @return
+   */
+  private boolean checkForHMM()
+  {
+    if (viewport.getAlignment().getHmmSequences().isEmpty())
+    {
+      JOptionPane.showMessageDialog(this,
+              MessageManager.getString("warn.no_hmm"));
+      return false;
+    }
+    return true;
+  }
+
+  @Override
+  protected void filterByEValue_actionPerformed()
+  {
+    viewport.filterByEvalue(inputDouble("Enter E-Value Cutoff"));
+  }
+
+  @Override
+  protected void filterByScore_actionPerformed()
+  {
+    viewport.filterByScore(inputDouble("Enter Bit Score Threshold"));
+  }
+
+  private double inputDouble(String message)
+  {
+    String str = null;
+    Double d = null;
+    while (d == null || d <= 0)
+    {
+      str = JOptionPane.showInputDialog(this.alignPanel, message);
+      try
+      {
+        d = Double.valueOf(str);
+      } catch (NumberFormatException e)
+      {
+      }
+    }
+    return d;
+  }
+
+  /**
+   * Checks if the alignment contains the required number of sequences.
+   * 
+   * @param required
+   * @return
+   */
+  public boolean alignmentIsSufficient(int required)
+  {
+    if (getViewport().getSequenceSelection().length < required)
+    {
+      JOptionPane.showMessageDialog(this,
+              MessageManager.getString("label.not_enough_sequences"));
+      return false;
+    }
+    return true;
+  }
+
+  /**
+   * Opens a file browser and adds the selected file, if in Fasta, Stockholm or
+   * Pfam format, to the list held under preference key "HMMSEARCH_DBS" (as a
+   * comma-separated list)
+   */
+  @Override
+  public void addDatabase_actionPerformed() throws IOException
+  {
+    if (Cache.getProperty(Preferences.HMMSEARCH_DBS) == null)
+    {
+      Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
+    }
+
+    String path = openFileChooser(false);
+    if (path != null && new File(path).exists())
+    {
+      IdentifyFile identifier = new IdentifyFile();
+      FileFormatI format = identifier.identify(path, DataSourceType.FILE);
+      if (format == FileFormat.Fasta || format == FileFormat.Stockholm
+              || format == FileFormat.Pfam)
+      {
+        String currentDbPaths = Cache
+                .getProperty(Preferences.HMMSEARCH_DBS);
+        currentDbPaths += Preferences.COMMA + path;
+        Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths);
+      }
+      else
+      {
+        JOptionPane.showMessageDialog(this,
+                MessageManager.getString("warn.invalid_format"));
+      }
+    }
+  }
+
+  /**
+   * Opens a file chooser, optionally restricted to selecting folders
+   * (directories) only. Answers the path to the selected file or folder, or
+   * null if none is chosen.
+   * 
+   * @param
+   * @return
+   */
+  protected String openFileChooser(boolean forFolder)
+  {
+    // TODO duplicates GPreferences method - relocate to JalviewFileChooser?
+    String choice = null;
+    JFileChooser chooser = new JFileChooser();
+    if (forFolder)
+    {
+      chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+    }
+    chooser.setDialogTitle(
+            MessageManager.getString("label.open_local_file"));
+    chooser.setToolTipText(MessageManager.getString("action.open"));
+
+    int value = chooser.showOpenDialog(this);
+
+    if (value == JFileChooser.APPROVE_OPTION)
+    {
+      choice = chooser.getSelectedFile().getPath();
+    }
+    return choice;
   }
 
   @Override
   public void reload_actionPerformed(ActionEvent e)
   {
-    if (fileName != null)
+    if (fileName == null && fileObject == null)
+    {
+      return;
+    }
+    // TODO: JAL-1108 - ensure all associated frames are closed regardless of
+    // originating file's format
+    // TODO: work out how to recover feature settings for correct view(s) when
+    // file is reloaded.
+    if (FileFormat.Jalview.equals(currentFileFormat))
     {
-      // TODO: JAL-1108 - ensure all associated frames are closed regardless of
-      // originating file's format
-      // TODO: work out how to recover feature settings for correct view(s) when
-      // file is reloaded.
-      if (FileFormat.Jalview.equals(currentFileFormat))
+      JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
+      for (int i = 0; i < frames.length; i++)
       {
-        JInternalFrame[] frames = Desktop.desktop.getAllFrames();
-        for (int i = 0; i < frames.length; i++)
+        if (frames[i] instanceof AlignFrame && frames[i] != this
+                && ((AlignFrame) frames[i]).fileName != null
+                && ((AlignFrame) frames[i]).fileName.equals(fileName))
         {
-          if (frames[i] instanceof AlignFrame && frames[i] != this
-                  && ((AlignFrame) frames[i]).fileName != null
-                  && ((AlignFrame) frames[i]).fileName.equals(fileName))
+          try
+          {
+            frames[i].setSelected(true);
+            Desktop.getInstance().closeAssociatedWindows();
+          } catch (java.beans.PropertyVetoException ex)
           {
-            try
-            {
-              frames[i].setSelected(true);
-              Desktop.instance.closeAssociatedWindows();
-            } catch (java.beans.PropertyVetoException ex)
-            {
-            }
           }
-
         }
-        Desktop.instance.closeAssociatedWindows();
 
-        FileLoader loader = new FileLoader();
-        DataSourceType protocol = fileName.startsWith("http:")
-                ? DataSourceType.URL
-                : DataSourceType.FILE;
-        loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
+      }
+      Desktop.getInstance().closeAssociatedWindows();
+
+      FileLoader loader = new FileLoader();
+//      DataSourceType protocol = fileName.startsWith("http:")
+//              ? DataSourceType.URL
+//              : DataSourceType.FILE;
+        loader.LoadFile(viewport, (fileObject == null ? fileName : fileObject), protocol, currentFileFormat);
+    }
+    else
+    {
+      Rectangle bounds = this.getBounds();
+
+      FileLoader loader = new FileLoader();
+
+      AlignFrame newframe = null;
+
+      if (fileObject == null)
+      {
+        newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
+                currentFileFormat);
       }
       else
       {
-        Rectangle bounds = this.getBounds();
-
-        FileLoader loader = new FileLoader();
-        DataSourceType protocol = fileName.startsWith("http:")
-                ? DataSourceType.URL
-                : DataSourceType.FILE;
-        AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
-                protocol, currentFileFormat);
+        newframe = loader.LoadFileWaitTillLoaded(fileObject,
+                DataSourceType.FILE, currentFileFormat);
+      }
 
-        newframe.setBounds(bounds);
-        if (featureSettings != null && featureSettings.isShowing())
+      newframe.setBounds(bounds);
+      if (featureSettings != null && featureSettings.isShowing())
+      {
+        final Rectangle fspos = featureSettings.frame.getBounds();
+        // TODO: need a 'show feature settings' function that takes bounds -
+        // need to refactor Desktop.addFrame
+        newframe.featureSettings_actionPerformed(null);
+        final FeatureSettings nfs = newframe.featureSettings;
+        SwingUtilities.invokeLater(new Runnable()
         {
-          final Rectangle fspos = featureSettings.frame.getBounds();
-          // TODO: need a 'show feature settings' function that takes bounds -
-          // need to refactor Desktop.addFrame
-          newframe.featureSettings_actionPerformed(null);
-          final FeatureSettings nfs = newframe.featureSettings;
-          SwingUtilities.invokeLater(new Runnable()
+
+          @Override
+          public void run()
           {
-            @Override
-            public void run()
-            {
-              nfs.frame.setBounds(fspos);
-            }
-          });
-          this.featureSettings.close();
-          this.featureSettings = null;
-        }
-        this.closeMenuItem_actionPerformed(true);
+            nfs.frame.setBounds(fspos);
+          }
+        });
+        this.featureSettings.close();
+        this.featureSettings = null;
       }
+      this.closeMenuItem_actionPerformed(true);
     }
+
   }
 
   @Override
   public void addFromText_actionPerformed(ActionEvent e)
   {
-    Desktop.instance
+    Desktop.getInstance()
             .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
   }
 
   @Override
   public void addFromURL_actionPerformed(ActionEvent e)
   {
-    Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
+    Desktop.getInstance().inputURLMenuItem_actionPerformed(viewport);
   }
 
   @Override
@@ -1093,7 +1483,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (fileName == null || (currentFileFormat == null)
             || fileName.startsWith("http"))
     {
-      saveAs_actionPerformed(null);
+      saveAs_actionPerformed();
     }
     else
     {
@@ -1102,13 +1492,12 @@ 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();
@@ -1122,214 +1511,242 @@ 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.getDesktopPane(),
+              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);
+  }
+
+  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 }));
 
-      Cache.setProperty("LAST_DIRECTORY", fileName);
-      saveAlignment(fileName, currentFileFormat);
     }
+    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 = true;
+    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 = shortName
+                .substring(shortName.lastIndexOf(File.separatorChar) + 1);
       }
-
-      success = new jalview.project.Jalview2XML().saveAlignment(this, file,
+      lastSaveSuccessful = new 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);
+    Runnable cancelAction = new Runnable()
     {
-      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
-      {
-        // create backupfiles object and get new temp filename destination
-        BackupFiles backupfiles = new BackupFiles(file);
+    };
+    Runnable outputAction = new Runnable()
+    {
 
-        try
-        {
-          PrintWriter out = new PrintWriter(
-                  new FileWriter(backupfiles.getTempFilePath()));
-
-          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)
+      @Override
+      public void run()
+      {
+        // 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)
         {
-          success = false;
-          ex.printStackTrace();
+          lastSaveSuccessful = false;
         }
+        else
+        {
+          // create backupfiles object and get new temp filename destination
+          boolean doBackup = BackupFiles.getEnabled();
+          BackupFiles backupfiles = doBackup ? new BackupFiles(file) : null;
+          try
+          {
+            String tempFilePath = doBackup ? backupfiles.getTempFilePath()
+                    : file;
+            PrintWriter out = new PrintWriter(new FileWriter(tempFilePath));
 
-        backupfiles.setWriteSuccess(success);
-        // do the backup file roll and rename the temp file to actual file
-        success = backupfiles.rollBackupsAndRenameTempFile();
+            out.print(output);
+            out.close();
+            AlignFrame.this.setTitle(file);
+            statusBar.setText(MessageManager.formatMessage(
+                    "label.successfully_saved_to_file_in_format",
+                    new Object[]
+                    { fileName, format.getName() }));
+            lastSaveSuccessful = true;
+          } catch (Exception ex)
+          {
+            lastSaveSuccessful = false;
+            ex.printStackTrace();
+          }
 
+          if (doBackup)
+          {
+            backupfiles.setWriteSuccess(lastSaveSuccessful);
+            // do the backup file roll and rename the temp file to actual file
+            lastSaveSuccessful = backupfiles.rollBackupsAndRenameTempFile();
+          }
+        }
       }
-    }
+    };
 
-    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(0, outputAction);
+      choices.setResponseAction(1, 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
+            .forName(fileFormatName);
+    AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
+    Runnable outputAction = new Runnable()
     {
-      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)
-    {
-      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(0, 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;
   }
 
   /**
@@ -1338,6 +1755,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void htmlMenuItem_actionPerformed(ActionEvent e)
   {
@@ -1352,39 +1770,50 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     bjs.exportHTML(null);
   }
 
+  // ??
+
   public void createImageMap(File file, String image)
   {
     alignPanel.makePNGImageMap(file, image);
   }
 
   /**
-   * 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
@@ -1400,6 +1829,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void printMenuItem_actionPerformed(ActionEvent e)
   {
@@ -1422,25 +1852,28 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   @Override
   public void associatedData_actionPerformed(ActionEvent e)
+          throws IOException, InterruptedException
   {
-    // 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"));
-
-    int value = chooser.showOpenDialog(null);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
+    String tooltip = MessageManager
+            .getString("label.load_jalview_annotations");
+    chooser.setDialogTitle(tooltip);
+    chooser.setToolTipText(tooltip);
+    chooser.setResponseHandler(0, new Runnable()
     {
-      String choice = chooser.getSelectedFile().getPath();
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
-      loadJalviewDataFile(choice, null, null, null);
-    }
 
+      @Override
+      public void run()
+      {
+        String choice = chooser.getSelectedFile().getPath();
+        jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
+        loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
+      }
+    });
+
+    chooser.showOpenDialog(this);
   }
 
   /**
@@ -1449,6 +1882,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param closeAllTabs
    */
+
   @Override
   public void closeMenuItem_actionPerformed(boolean closeAllTabs)
   {
@@ -1503,6 +1937,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param panelToClose
    */
+
   public void closeView(AlignmentPanel panelToClose)
   {
     int index = tabbedPane.getSelectedIndex();
@@ -1526,6 +1961,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * DOCUMENT ME!
    */
+
   void updateEditMenuBar()
   {
 
@@ -1579,6 +2015,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @return alignment objects for all views
    */
+
   AlignmentI[] getViewAlignments()
   {
     if (alignPanels != null)
@@ -1604,6 +2041,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void undoMenuItem_actionPerformed(ActionEvent e)
   {
@@ -1631,8 +2069,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       // && viewport.getColumnSelection().getHiddenColumns() != null &&
       // viewport.getColumnSelection()
       // .getHiddenColumns().size() > 0);
-      originalSource.firePropertyChange("alignment", null,
-              originalSource.getAlignment().getSequences());
+      originalSource.notifyAlignment();
+
     }
   }
 
@@ -1642,6 +2080,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void redoMenuItem_actionPerformed(ActionEvent e)
   {
@@ -1671,8 +2110,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       // && viewport.getColumnSelection().getHiddenColumns() != null &&
       // viewport.getColumnSelection()
       // .getHiddenColumns().size() > 0);
-      originalSource.firePropertyChange("alignment", null,
-              originalSource.getAlignment().getSequences());
+      originalSource.notifyAlignment();
+
     }
   }
 
@@ -1724,6 +2163,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param up
    *          DOCUMENT ME!
    */
+
   public void moveSelectedSequences(boolean up)
   {
     SequenceGroup sg = viewport.getSelectionGroup();
@@ -1848,8 +2288,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
-  protected void copy_actionPerformed(ActionEvent e)
+  protected void copy_actionPerformed()
   {
     if (viewport.getSelectionGroup() == null)
     {
@@ -1870,16 +2311,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     StringSelection ss = new StringSelection(output);
 
+    Desktop d = Desktop.getInstance();
     try
     {
-      jalview.gui.Desktop.internalCopy = true;
+      d.internalCopy = true;
       // Its really worth setting the clipboard contents
       // to empty before setting the large StringSelection!!
       Toolkit.getDefaultToolkit().getSystemClipboard()
               .setContents(new StringSelection(""), null);
 
       Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
-              Desktop.instance);
+              Desktop.getInstance());
     } catch (OutOfMemoryError er)
     {
       new OOMWarning("copying region", er);
@@ -1899,9 +2341,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               hiddenCutoff, hiddenOffset);
     }
 
-    Desktop.jalviewClipboard = new Object[] { seqs,
+    d.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() }));
   }
@@ -1911,9 +2353,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param e
    *          DOCUMENT ME!
+   * @throws InterruptedException
+   * @throws IOException
    */
+
   @Override
   protected void pasteNew_actionPerformed(ActionEvent e)
+          throws IOException, InterruptedException
   {
     paste(true);
   }
@@ -1923,9 +2369,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param e
    *          DOCUMENT ME!
+   * @throws InterruptedException
+   * @throws IOException
    */
+
   @Override
   protected void pasteThis_actionPerformed(ActionEvent e)
+          throws IOException, InterruptedException
   {
     paste(false);
   }
@@ -1935,8 +2385,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param newAlignment
    *          true to paste to a new alignment, otherwise add to this.
+   * @throws InterruptedException
+   * @throws IOException
    */
-  void paste(boolean newAlignment)
+  void paste(boolean newAlignment) throws IOException, InterruptedException
   {
     boolean externalPaste = true;
     try
@@ -1971,12 +2423,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       boolean annotationAdded = false;
       AlignmentI alignment = null;
 
-      if (Desktop.jalviewClipboard != null)
+      Desktop d = Desktop.getInstance();
+
+      if (d.jalviewClipboard != null)
       {
         // The clipboard was filled from within Jalview, we must use the
         // sequences
         // And dataset from the copied alignment
-        SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
+        SequenceI[] newseq = (SequenceI[]) d.jalviewClipboard[0];
         // be doubly sure that we create *new* sequence objects.
         sequences = new SequenceI[newseq.length];
         for (int i = 0; i < newseq.length; i++)
@@ -2001,10 +2455,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       if (newAlignment)
       {
 
-        if (Desktop.jalviewClipboard != null)
+        if (d.jalviewClipboard != null)
         {
           // dataset is inherited
-          alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
+          alignment.setDataset((Alignment) d.jalviewClipboard[1]);
         }
         else
         {
@@ -2020,11 +2474,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         alignment = viewport.getAlignment();
         alwidth = alignment.getWidth() + 1;
         // decide if we need to import sequences from an existing dataset
-        boolean importDs = Desktop.jalviewClipboard != null
-                && Desktop.jalviewClipboard[1] != alignment.getDataset();
+        boolean importDs = d.jalviewClipboard != null
+                && d.jalviewClipboard[1] != alignment.getDataset();
         // importDs==true instructs us to copy over new dataset sequences from
         // an existing alignment
-        Vector newDs = (importDs) ? new Vector() : null; // used to create
+        Vector<SequenceI> newDs = (importDs) ? new Vector<>() : null; // used to
+                                                                      // create
         // minimum dataset set
 
         for (int i = 0; i < sequences.length; i++)
@@ -2163,7 +2618,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       {
 
         // propagate alignment changed.
-        viewport.getRanges().setEndSeq(alignment.getHeight());
+        viewport.getRanges().setEndSeq(alignment.getHeight() - 1);
         if (annotationAdded)
         {
           // Duplicate sequence annotation in all views.
@@ -2201,8 +2656,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
           buildSortByAnnotationScoresMenu();
         }
-        viewport.firePropertyChange("alignment", null,
-                alignment.getSequences());
+        viewport.notifyAlignment();
         if (alignPanels != null)
         {
           for (AlignmentPanel ap : alignPanels)
@@ -2222,10 +2676,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 DEFAULT_HEIGHT);
         String newtitle = new String("Copied sequences");
 
-        if (Desktop.jalviewClipboard != null
-                && Desktop.jalviewClipboard[2] != null)
+        if (d.jalviewClipboard != null && d.jalviewClipboard[2] != null)
         {
-          HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
+          HiddenColumns hc = (HiddenColumns) d.jalviewClipboard[2];
           af.viewport.setHiddenColumns(hc);
         }
 
@@ -2264,7 +2717,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       System.out.println("Exception whilst pasting: " + ex);
       // could be anything being pasted in here
     }
-
   }
 
   @Override
@@ -2277,11 +2729,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
               DEFAULT_HEIGHT);
       String newtitle = new String("Flanking alignment");
-
-      if (Desktop.jalviewClipboard != null
-              && Desktop.jalviewClipboard[2] != null)
+      Desktop d = Desktop.getInstance();
+      if (d.jalviewClipboard != null && d.jalviewClipboard[2] != null)
       {
-        HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
+        HiddenColumns hc = (HiddenColumns) d.jalviewClipboard[2];
         af.viewport.setHiddenColumns(hc);
       }
 
@@ -2318,26 +2769,22 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
+   * Action Cut (delete and copy) the selected region
    */
+
   @Override
-  protected void cut_actionPerformed(ActionEvent e)
+  protected void cut_actionPerformed()
   {
-    copy_actionPerformed(null);
-    delete_actionPerformed(null);
+    copy_actionPerformed();
+    delete_actionPerformed();
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
+   * Performs menu option to Delete the currently selected region
    */
+
   @Override
-  protected void delete_actionPerformed(ActionEvent evt)
+  protected void delete_actionPerformed()
   {
 
     SequenceGroup sg = viewport.getSelectionGroup();
@@ -2346,51 +2793,64 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       return;
     }
 
-    /*
-     * If the cut affects all sequences, warn, remove highlighted columns
-     */
-    if (sg.getSize() == viewport.getAlignment().getHeight())
+    Runnable okAction = new Runnable()
     {
-      boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes())
-              + 1) == viewport.getAlignment().getWidth()) ? true : false;
-      if (isEntireAlignWidth)
+
+      @Override
+      public void run()
       {
-        int confirm = JvOptionPane.showConfirmDialog(this,
-                MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
-                MessageManager.getString("label.delete_all"), // $NON-NLS-1$
-                JvOptionPane.OK_CANCEL_OPTION);
+        SequenceI[] cut = sg.getSequences()
+                .toArray(new SequenceI[sg.getSize()]);
 
-        if (confirm == JvOptionPane.CANCEL_OPTION
-                || confirm == JvOptionPane.CLOSED_OPTION)
+        addHistoryItem(new EditCommand(
+                MessageManager.getString("label.cut_sequences"), Action.CUT,
+                cut, sg.getStartRes(),
+                sg.getEndRes() - sg.getStartRes() + 1,
+                viewport.getAlignment()));
+
+        viewport.setSelectionGroup(null);
+        viewport.sendSelection();
+        viewport.getAlignment().deleteGroup(sg);
+
+        viewport.notifyAlignment();
+
+        if (viewport.getAlignment().getHeight() < 1)
         {
-          return;
+          try
+          {
+            AlignFrame.this.setClosed(true);
+          } catch (Exception ex)
+          {
+          }
+        } else {
+          updateAll(null);
         }
       }
-      viewport.getColumnSelection().removeElements(sg.getStartRes(),
-              sg.getEndRes() + 1);
-    }
-    SequenceI[] cut = sg.getSequences()
-            .toArray(new SequenceI[sg.getSize()]);
-
-    addHistoryItem(new EditCommand(
-            MessageManager.getString("label.cut_sequences"), Action.CUT,
-            cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
-            viewport.getAlignment()));
+    };
 
-    viewport.setSelectionGroup(null);
-    viewport.sendSelection();
-    viewport.getAlignment().deleteGroup(sg);
-
-    viewport.firePropertyChange("alignment", null,
-            viewport.getAlignment().getSequences());
-    if (viewport.getAlignment().getHeight() < 1)
+    /*
+     * If the cut affects all sequences, prompt for confirmation
+     */
+    boolean wholeHeight = sg.getSize() == viewport.getAlignment()
+            .getHeight();
+    boolean wholeWidth = (((sg.getEndRes() - sg.getStartRes())
+            + 1) == viewport.getAlignment().getWidth()) ? true : false;
+    if (wholeHeight && wholeWidth)
+    {
+      JvOptionPane dialog = JvOptionPane
+              .newOptionDialog(Desktop.getDesktopPane());
+      dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION
+      Object[] options = new Object[] {
+          MessageManager.getString("action.ok"),
+          MessageManager.getString("action.cancel") };
+      dialog.showDialog(MessageManager.getString("warn.delete_all"),
+              MessageManager.getString("label.delete_all"),
+              JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
+              options, options[0]);
+    }
+    else
     {
-      try
-      {
-        this.setClosed(true);
-      } catch (Exception ex)
-      {
-      }
+      okAction.run();
     }
   }
 
@@ -2400,15 +2860,32 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void deleteGroups_actionPerformed(ActionEvent e)
   {
     if (avc.deleteGroups())
     {
-      PaintRefresher.Refresh(this, viewport.getSequenceSetId());
-      alignPanel.updateAnnotation();
+      updateAll(viewport.getSequenceSetId());
+    }
+  }
+
+  private void updateAll(String id)
+  {
+    if (id == null)
+    {
+      // this will force a non-fast repaint of both the IdPanel and SeqPanel
+      alignPanel.getIdPanel().getIdCanvas().setNoFastPaint();
+      alignPanel.getSeqPanel().seqCanvas.setNoFastPaint();
+      alignPanel.repaint();
+    }
+    else
+    {
+      // original version
+      PaintRefresher.Refresh(this, id);
       alignPanel.paintAlignment(true, true);
     }
+    alignPanel.updateAnnotation();
   }
 
   /**
@@ -2417,21 +2894,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
-  @Override
-  public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
-  {
-    SequenceGroup sg = new SequenceGroup(
-            viewport.getAlignment().getSequences());
-
-    sg.setEndRes(viewport.getAlignment().getWidth() - 1);
-    viewport.setSelectionGroup(sg);
-    viewport.isSelectionGroupChanged(true);
-    viewport.sendSelection();
-    // JAL-2034 - should delegate to
-    // alignPanel to decide if overview needs
-    // updating.
-    alignPanel.paintAlignment(false, false);
-    PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
+
+  @Override
+  public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
+  {
+    alignPanel.selectAllSequences();
   }
 
   /**
@@ -2440,24 +2907,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
   {
-    if (viewport.cursorMode)
-    {
-      alignPanel.getSeqPanel().keyboardNo1 = null;
-      alignPanel.getSeqPanel().keyboardNo2 = null;
-    }
-    viewport.setSelectionGroup(null);
-    viewport.getColumnSelection().clear();
-    viewport.setSelectionGroup(null);
-    alignPanel.getIdPanel().getIdCanvas().searchResults = null;
-    // JAL-2034 - should delegate to
-    // alignPanel to decide if overview needs
-    // updating.
-    alignPanel.paintAlignment(false, false);
-    PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
-    viewport.sendSelection();
+    alignPanel.deselectAllSequences();
   }
 
   /**
@@ -2466,6 +2920,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2473,7 +2928,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     if (sg == null)
     {
-      selectAllSequenceMenuItem_actionPerformed(null);
+      alignPanel.selectAllSequences();
 
       return;
     }
@@ -2505,6 +2960,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2517,6 +2973,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void remove2RightMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2563,8 +3020,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 column, viewport.getAlignment());
       }
 
-      statusBar.setText(MessageManager
-              .formatMessage("label.removed_columns", new String[]
+      setStatus(MessageManager.formatMessage("label.removed_columns",
+              new String[]
               { Integer.valueOf(trimRegion.getSize()).toString() }));
 
       addHistoryItem(trimRegion);
@@ -2578,8 +3035,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         }
       }
 
-      viewport.firePropertyChange("alignment", null,
-              viewport.getAlignment().getSequences());
+      viewport.notifyAlignment();
+
     }
   }
 
@@ -2589,6 +3046,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2613,8 +3071,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     addHistoryItem(removeGapCols);
 
-    statusBar.setText(MessageManager
-            .formatMessage("label.removed_empty_columns", new Object[]
+    setStatus(MessageManager.formatMessage("label.removed_empty_columns",
+            new Object[]
             { Integer.valueOf(removeGapCols.getSize()).toString() }));
 
     // This is to maintain viewport position on first residue
@@ -2628,8 +3086,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     // if (viewport.hasHiddenColumns)
     // viewport.getColumnSelection().compensateForEdits(shifts);
     ranges.setStartRes(seq.findIndex(startRes) - 1);
-    viewport.firePropertyChange("alignment", null,
-            viewport.getAlignment().getSequences());
+    viewport.notifyAlignment();
+
 
   }
 
@@ -2639,6 +3097,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2666,9 +3125,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             viewport.getAlignment()));
 
     viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
-
-    viewport.firePropertyChange("alignment", null,
-            viewport.getAlignment().getSequences());
+    viewport.notifyAlignment();
 
   }
 
@@ -2678,12 +3135,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void padGapsMenuitem_actionPerformed(ActionEvent e)
   {
     viewport.setPadGaps(padGapsMenuitem.isSelected());
-    viewport.firePropertyChange("alignment", null,
-            viewport.getAlignment().getSequences());
+    viewport.notifyAlignment();
+
   }
 
   /**
@@ -2692,6 +3150,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void findMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2701,6 +3160,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Create a new view of the current alignment.
    */
+
   @Override
   public void newView_actionPerformed(ActionEvent e)
   {
@@ -2716,6 +3176,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    *          if true then duplicate all annnotation, groups and settings
    * @return new alignment panel, already displayed.
    */
+
   public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
   {
     /*
@@ -2736,8 +3197,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     if (viewport.getViewName() == null)
     {
-      viewport.setViewName(MessageManager
-              .getString("label.view_name_original"));
+      viewport.setViewName(
+              MessageManager.getString("label.view_name_original"));
     }
 
     /*
@@ -2788,6 +3249,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param viewTitle
    * @return
    */
+
   protected String getNewViewName(String viewTitle)
   {
     int index = Desktop.getViewCount(viewport.getSequenceSetId());
@@ -2822,6 +3284,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param comps
    * @return
    */
+
   protected List<String> getExistingViewNames(List<Component> comps)
   {
     List<String> existingNames = new ArrayList<>();
@@ -2842,6 +3305,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Explode tabbed views into separate windows.
    */
+
   @Override
   public void expandViews_actionPerformed(ActionEvent e)
   {
@@ -2851,10 +3315,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Gather views in separate windows back into a tabbed presentation.
    */
+
   @Override
   public void gatherViews_actionPerformed(ActionEvent e)
   {
-    Desktop.instance.gatherViews(this);
+    Desktop.getInstance().gatherViews(this);
   }
 
   /**
@@ -2863,6 +3328,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void font_actionPerformed(ActionEvent e)
   {
@@ -2875,6 +3341,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void seqLimit_actionPerformed(ActionEvent e)
   {
@@ -2904,6 +3371,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
    */
+
   @Override
   protected void followHighlight_actionPerformed()
   {
@@ -2925,6 +3393,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void colourTextMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2938,6 +3407,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void wrapMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2974,7 +3444,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param toggleSeqs
    * @param toggleCols
    */
-  private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
+
+  protected void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
   {
 
     boolean hide = false;
@@ -3041,6 +3512,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
    * event.ActionEvent)
    */
+
   @Override
   public void hideAllButSelection_actionPerformed(ActionEvent e)
   {
@@ -3055,6 +3527,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
    * .ActionEvent)
    */
+
   @Override
   public void hideAllSelection_actionPerformed(ActionEvent e)
   {
@@ -3074,6 +3547,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
    * ActionEvent)
    */
+
   @Override
   public void showAllhidden_actionPerformed(ActionEvent e)
   {
@@ -3105,6 +3579,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void scaleAbove_actionPerformed(ActionEvent e)
   {
@@ -3119,6 +3594,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void scaleLeft_actionPerformed(ActionEvent e)
   {
@@ -3133,6 +3609,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void scaleRight_actionPerformed(ActionEvent e)
   {
@@ -3147,6 +3624,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3160,6 +3638,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void viewTextMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3173,6 +3652,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3218,6 +3698,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param evt
    *          DOCUMENT ME!
    */
+
   @Override
   public void showSeqFeatures_actionPerformed(ActionEvent evt)
   {
@@ -3234,30 +3715,73 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param e
    */
+
   @Override
   public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
   {
     final boolean setVisible = annotationPanelMenuItem.isSelected();
     viewport.setShowAnnotation(setVisible);
-    this.showAllSeqAnnotations.setEnabled(setVisible);
-    this.hideAllSeqAnnotations.setEnabled(setVisible);
-    this.showAllAlAnnotations.setEnabled(setVisible);
-    this.hideAllAlAnnotations.setEnabled(setVisible);
+    syncAnnotationMenuItems(setVisible);
     alignPanel.updateLayout();
+    repaint();
+    SwingUtilities.invokeLater(new Runnable() {
+
+      @Override
+      public void run()
+      {
+        alignPanel.updateScrollBarsFromRanges();
+      }
+      
+    });
+  }
+
+  private void syncAnnotationMenuItems(boolean setVisible)
+  {
+    showAllSeqAnnotations.setEnabled(setVisible);
+    hideAllSeqAnnotations.setEnabled(setVisible);
+    showAllAlAnnotations.setEnabled(setVisible);
+    hideAllAlAnnotations.setEnabled(setVisible);
   }
 
   @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 (Platform.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
+    /**
+     * Java only
+     * 
+     * @j2sIgnore
+     */
+    {
+      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[]
@@ -3270,6 +3794,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void overviewMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3279,24 +3804,49 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
     JInternalFrame frame = new JInternalFrame();
-    final OverviewPanel overview = new OverviewPanel(alignPanel);
+
+    // BH 2019.07.26 we allow for an embedded
+    // undecorated overview with defined size
+    frame.setName(Platform.getAppID("overview"));
+    //
+    Dimension dim = Platform.getDimIfEmbedded(frame, -1, -1);
+    if (dim != null && dim.width == 0)
+    {
+      dim = null; // hidden, not embedded
+    }
+    OverviewPanel overview = new OverviewPanel(alignPanel, dim);
+
     frame.setContentPane(overview);
+    if (dim == null)
+    {
+      dim = new Dimension();
+      // was frame.getSize(), but that is 0,0 at this point;
+    }
+    else
+    {
+      // we are imbedding, and so we have an undecorated frame
+      // and we can set the the frame dimensions accordingly.
+    }
+    // allowing for unresizable option using, style="resize:none"
+    boolean resizable = (Platform.getEmbeddedAttribute(frame,
+            "resize") != "none");
     Desktop.addInternalFrame(frame, MessageManager
             .formatMessage("label.overview_params", new Object[]
-            { this.getTitle() }), true, frame.getWidth(), frame.getHeight(),
-            true, true);
+            { this.getTitle() }), Desktop.FRAME_MAKE_VISIBLE, dim.width,
+            dim.height, resizable, Desktop.FRAME_ALLOW_ANY_SIZE);
     frame.pack();
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
     frame.addInternalFrameListener(
             new javax.swing.event.InternalFrameAdapter()
             {
+
               @Override
               public void internalFrameClosed(
                       javax.swing.event.InternalFrameEvent evt)
               {
                 overview.dispose();
                 alignPanel.setOverviewPanel(null);
-              };
+              }
             });
     if (getKeyListeners().length > 0)
     {
@@ -3318,6 +3868,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
    * ()[0])); }
    */
+
   @Override
   public void annotationColour_actionPerformed()
   {
@@ -3337,6 +3888,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param selected
    */
+
   @Override
   public void applyToAllGroups_actionPerformed(boolean selected)
   {
@@ -3349,6 +3901,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param name
    *          the name (not the menu item label!) of the colour scheme
    */
+
   @Override
   public void changeColour_actionPerformed(String name)
   {
@@ -3366,8 +3919,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
      * otherwise set the chosen colour scheme (or null for 'None')
      */
     ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
-            viewport,
-            viewport.getAlignment(), viewport.getHiddenRepSequences());
+            viewport, viewport.getAlignment(),
+            viewport.getHiddenRepSequences());
     changeColour(cs);
   }
 
@@ -3376,6 +3929,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param cs
    */
+
   @Override
   public void changeColour(ColourSchemeI cs)
   {
@@ -3390,6 +3944,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Show the PID threshold slider panel
    */
+
   @Override
   protected void modifyPID_actionPerformed()
   {
@@ -3401,6 +3956,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Show the Conservation slider panel
    */
+
   @Override
   protected void modifyConservation_actionPerformed()
   {
@@ -3412,6 +3968,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Action on selecting or deselecting (Colour) By Conservation
    */
+
   @Override
   public void conservationMenuItem_actionPerformed(boolean selected)
   {
@@ -3433,6 +3990,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Action on selecting or deselecting (Colour) Above PID Threshold
    */
+
   @Override
   public void abovePIDThreshold_actionPerformed(boolean selected)
   {
@@ -3461,6 +4019,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3478,6 +4037,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void sortIDMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3494,6 +4054,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void sortLengthMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3510,6 +4071,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void sortGroupMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3521,12 +4083,35 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     alignPanel.paintAlignment(true, false);
   }
 
+  @Override
+  public void sortEValueMenuItem_actionPerformed(ActionEvent e)
+  {
+    SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
+    AlignmentSorter.sortByEValue(viewport.getAlignment());
+    addHistoryItem(new OrderCommand("Group Sort", oldOrder,
+            viewport.getAlignment()));
+    alignPanel.paintAlignment(true, false);
+
+  }
+
+  @Override
+  public void sortBitScoreMenuItem_actionPerformed(ActionEvent e)
+  {
+    SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
+    AlignmentSorter.sortByBitScore(viewport.getAlignment());
+    addHistoryItem(new OrderCommand("Group Sort", oldOrder,
+            viewport.getAlignment()));
+    alignPanel.paintAlignment(true, false);
+
+  }
+
   /**
    * DOCUMENT ME!
    * 
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3539,6 +4124,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3564,11 +4150,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void autoCalculate_actionPerformed(ActionEvent e)
   {
-    viewport.autoCalculateConsensus = autoCalculate.isSelected();
-    if (viewport.autoCalculateConsensus)
+    viewport.setAutoCalculateConsensusAndConservation(
+            autoCalculate.isSelected());
+    if (viewport.getAutoCalculateConsensusAndConservation())
+    // ??
+    // viewport.autoCalculateConsensus = autoCalculate.isSelected();
+    // if (viewport.autoCalculateConsensus)
     {
-      viewport.firePropertyChange("alignment", null,
-              viewport.getAlignment().getSequences());
+      viewport.notifyAlignment();
     }
   }
 
@@ -3594,6 +4183,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param options
    *          parameters for the distance or similarity calculation
    */
+
   void newTreePanel(String type, String modelName,
           SimilarityParamsI options)
   {
@@ -3611,7 +4201,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       {
         if (_s.getLength() < sg.getEndRes())
         {
-          JvOptionPane.showMessageDialog(Desktop.desktop,
+          JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
                   MessageManager.getString(
                           "label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
                   MessageManager.getString(
@@ -3643,7 +4233,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     frameTitle += this.title;
 
-    Desktop.addInternalFrame(tp, frameTitle, 600, 500);
+    Dimension dim = Platform.getDimIfEmbedded(tp, 600, 500);
+    Desktop.addInternalFrame(tp, frameTitle, dim.width, dim.height);
   }
 
   /**
@@ -3654,6 +4245,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param order
    *          DOCUMENT ME!
    */
+
   public void addSortByOrderMenuItem(String title,
           final AlignmentOrder order)
   {
@@ -3663,6 +4255,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     sort.add(item);
     item.addActionListener(new java.awt.event.ActionListener()
     {
+
       @Override
       public void actionPerformed(ActionEvent e)
       {
@@ -3689,6 +4282,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    *          the label used to retrieve scores for each sequence on the
    *          alignment
    */
+
   public void addSortByAnnotScoreMenuItem(JMenu sort,
           final String scoreLabel)
   {
@@ -3696,6 +4290,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     sort.add(item);
     item.addActionListener(new java.awt.event.ActionListener()
     {
+
       @Override
       public void actionPerformed(ActionEvent e)
       {
@@ -3721,6 +4316,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * rebuilding in subsequence calls.
    * 
    */
+
   @Override
   public void buildSortByAnnotationScoresMenu()
   {
@@ -3730,73 +4326,68 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
     if (viewport.getAlignment().getAlignmentAnnotation()
-            .hashCode() != _annotationScoreVectorHash)
+            .hashCode() == _annotationScoreVectorHash)
     {
-      sortByAnnotScore.removeAll();
-      // almost certainly a quicker way to do this - but we keep it simple
-      Hashtable scoreSorts = new Hashtable();
-      AlignmentAnnotation aann[];
-      for (SequenceI sqa : viewport.getAlignment().getSequences())
+      return;
+    }
+
+    sortByAnnotScore.removeAll();
+    Set<String> scoreSorts = new HashSet<>();
+    for (SequenceI sqa : viewport.getAlignment().getSequences())
+    {
+      AlignmentAnnotation[] anns = sqa.getAnnotation();
+      for (int i = 0; anns != null && i < anns.length; i++)
       {
-        aann = sqa.getAnnotation();
-        for (int i = 0; aann != null && i < aann.length; i++)
+        AlignmentAnnotation aa = anns[i];
+        if (aa != null && aa.hasScore() && aa.sequenceRef != null)
         {
-          if (aann[i].hasScore() && aann[i].sequenceRef != null)
-          {
-            scoreSorts.put(aann[i].label, aann[i].label);
-          }
+          scoreSorts.add(aa.label);
         }
       }
-      Enumeration labels = scoreSorts.keys();
-      while (labels.hasMoreElements())
-      {
-        addSortByAnnotScoreMenuItem(sortByAnnotScore,
-                (String) labels.nextElement());
-      }
-      sortByAnnotScore.setVisible(scoreSorts.size() > 0);
-      scoreSorts.clear();
-
-      _annotationScoreVectorHash = viewport.getAlignment()
-              .getAlignmentAnnotation().hashCode();
     }
+    for (String label : scoreSorts)
+    {
+      addSortByAnnotScoreMenuItem(sortByAnnotScore, label);
+    }
+    sortByAnnotScore.setVisible(!scoreSorts.isEmpty());
+
+    _annotationScoreVectorHash = viewport.getAlignment()
+            .getAlignmentAnnotation().hashCode();
   }
 
   /**
+   * Enable (or, if desired, make visible) the By Tree 
+   * submenu only if it has at least one element (or will have).
+   * 
+   */
+  @Override
+  protected void enableSortMenuOptions()
+  {
+    List<TreePanel> treePanels = getTreePanels();
+    sortByTreeMenu.setEnabled(!treePanels.isEmpty());
+  }
+  
+  /**
    * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
    * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
    * call. Listeners are added to remove the menu item when the treePanel is
    * closed, and adjust the tree leaf to sequence mapping when the alignment is
    * modified.
    */
+
   @Override
   public void buildTreeSortMenu()
   {
     sortByTreeMenu.removeAll();
 
-    List<Component> comps = PaintRefresher.components
-            .get(viewport.getSequenceSetId());
-    List<TreePanel> treePanels = new ArrayList<>();
-    for (Component comp : comps)
-    {
-      if (comp instanceof TreePanel)
-      {
-        treePanels.add((TreePanel) comp);
-      }
-    }
-
-    if (treePanels.size() < 1)
-    {
-      sortByTreeMenu.setVisible(false);
-      return;
-    }
-
-    sortByTreeMenu.setVisible(true);
+    List<TreePanel> treePanels = getTreePanels();
 
     for (final TreePanel tp : treePanels)
     {
       final JMenuItem item = new JMenuItem(tp.getTitle());
       item.addActionListener(new java.awt.event.ActionListener()
       {
+
         @Override
         public void actionPerformed(ActionEvent e)
         {
@@ -3810,6 +4401,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
   }
 
+  private List<TreePanel> getTreePanels()
+  {
+    List<Component> comps = PaintRefresher.components
+            .get(viewport.getSequenceSetId());
+    List<TreePanel> treePanels = new ArrayList<>();
+    for (Component comp : comps)
+    {
+      if (comp instanceof TreePanel)
+      {
+        treePanels.add((TreePanel) comp);
+      }
+    }
+    return treePanels;
+  }
+
   public boolean sortBy(AlignmentOrder alorder, String undoname)
   {
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
@@ -3828,6 +4434,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * be submitted for multiple alignment.
    * 
    */
+
   public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
   {
     // Now, check we have enough sequences
@@ -3873,6 +4480,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * region or the whole alignment. (where the first sequence in the set is the
    * one that the prediction will be for).
    */
+
   public AlignmentView gatherSeqOrMsaForSecStrPrediction()
   {
     AlignmentView seqs = null;
@@ -3906,6 +4514,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3918,33 +4527,40 @@ 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.setResponseHandler(0, new Runnable()
     {
-      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.getDesktopPane(),
+                  ex.getMessage(),
+                  MessageManager
+                          .getString("label.problem_reading_tree_file"),
+                  JvOptionPane.WARNING_MESSAGE);
+          ex.printStackTrace();
+        }
+        if (fin != null && fin.hasWarningMessage())
+        {
+          JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
+                  fin.getWarningMessage(),
+                  MessageManager.getString(
+                          "label.possible_problem_with_tree_file"),
+                  JvOptionPane.WARNING_MESSAGE);
+        }
       }
-    }
+    });
+    chooser.showOpenDialog(this);
   }
 
   public TreePanel showNewickTree(NewickFile nf, String treeTitle)
@@ -3978,6 +4594,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    *          position
    * @return TreePanel handle
    */
+
   public TreePanel showNewickTree(NewickFile nf, String treeTitle,
           AlignmentView input, int w, int h, int x, int y)
   {
@@ -3990,15 +4607,24 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       if (nf.getTree() != null)
       {
         tp = new TreePanel(alignPanel, nf, treeTitle, input);
-
-        tp.setSize(w, h);
+        Dimension dim = Platform.getDimIfEmbedded(tp, -1, -1);
+        if (dim == null)
+        {
+          dim = new Dimension(w, h);
+        }
+        else
+        {
+          // no offset, either
+          x = 0;
+        }
+        tp.setSize(dim.width, dim.height);
 
         if (x > 0 && y > 0)
         {
           tp.setLocation(x, y);
         }
 
-        Desktop.addInternalFrame(tp, treeTitle, w, h);
+        Desktop.addInternalFrame(tp, treeTitle, dim.width, dim.height);
       }
     } catch (Exception ex)
     {
@@ -4008,182 +4634,80 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     return tp;
   }
 
-  private boolean buildingMenu = false;
-
   /**
-   * Generates menu items and listener event actions for web service clients
-   * 
+   * Schedule the web services menu rebuild to the event dispatch thread.
    */
-  public void BuildWebServiceMenu()
+  public void buildWebServicesMenu()
   {
-    while (buildingMenu)
-    {
-      try
-      {
-        System.err.println("Waiting for building menu to finish.");
-        Thread.sleep(10);
-      } catch (Exception e)
+    SwingUtilities.invokeLater(() -> {
+      Cache.log.info("Rebuiling WS menu");
+      webService.removeAll();
+      if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
       {
+        Cache.log.info("Building web service menu for slivka");
+        SlivkaWSDiscoverer discoverer = SlivkaWSDiscoverer.getInstance();
+        JMenu submenu = new JMenu("Slivka");
+        buildWebServicesMenu(discoverer, submenu);
+        webService.add(submenu);
       }
-    }
-    final AlignFrame me = this;
-    buildingMenu = true;
-    new Thread(new Runnable()
-    {
-      @Override
-      public void run()
+      if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
       {
-        final List<JMenuItem> legacyItems = new ArrayList<>();
-        try
-        {
-          // System.err.println("Building ws menu again "
-          // + Thread.currentThread());
-          // TODO: add support for context dependent disabling of services based
-          // on
-          // alignment and current selection
-          // TODO: add additional serviceHandle parameter to specify abstract
-          // handler
-          // class independently of AbstractName
-          // TODO: add in rediscovery GUI function to restart discoverer
-          // TODO: group services by location as well as function and/or
-          // introduce
-          // object broker mechanism.
-          final Vector<JMenu> wsmenu = new Vector<>();
-          final IProgressIndicator af = me;
-
-          /*
-           * do not i18n these strings - they are hard-coded in class
-           * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
-           * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
-           */
-          final JMenu msawsmenu = new JMenu("Alignment");
-          final JMenu secstrmenu = new JMenu(
-                  "Secondary Structure Prediction");
-          final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
-          final JMenu analymenu = new JMenu("Analysis");
-          final JMenu dismenu = new JMenu("Protein Disorder");
-          // JAL-940 - only show secondary structure prediction services from
-          // the legacy server
-          if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
-              // &&
-          Discoverer.services != null && (Discoverer.services.size() > 0))
-          {
-            // TODO: refactor to allow list of AbstractName/Handler bindings to
-            // be
-            // stored or retrieved from elsewhere
-            // No MSAWS used any more:
-            // Vector msaws = null; // (Vector)
-            // Discoverer.services.get("MsaWS");
-            Vector secstrpr = (Vector) Discoverer.services
-                    .get("SecStrPred");
-            if (secstrpr != null)
-            {
-              // Add any secondary structure prediction services
-              for (int i = 0, j = secstrpr.size(); i < j; i++)
-              {
-                final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
-                        .get(i);
-                jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
-                        .getServiceClient(sh);
-                int p = secstrmenu.getItemCount();
-                impl.attachWSMenuEntry(secstrmenu, me);
-                int q = secstrmenu.getItemCount();
-                for (int litm = p; litm < q; litm++)
-                {
-                  legacyItems.add(secstrmenu.getItem(litm));
-                }
-              }
-            }
-          }
-
-          // Add all submenus in the order they should appear on the web
-          // services menu
-          wsmenu.add(msawsmenu);
-          wsmenu.add(secstrmenu);
-          wsmenu.add(dismenu);
-          wsmenu.add(analymenu);
-          // No search services yet
-          // wsmenu.add(seqsrchmenu);
-
-          javax.swing.SwingUtilities.invokeLater(new Runnable()
-          {
-            @Override
-            public void run()
-            {
-              try
-              {
-                webService.removeAll();
-                // first, add discovered services onto the webservices menu
-                if (wsmenu.size() > 0)
-                {
-                  for (int i = 0, j = wsmenu.size(); i < j; i++)
-                  {
-                    webService.add(wsmenu.get(i));
-                  }
-                }
-                else
-                {
-                  webService.add(me.webServiceNoServices);
-                }
-                // TODO: move into separate menu builder class.
-                boolean new_sspred = false;
-                if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
-                {
-                  Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
-                  if (jws2servs != null)
-                  {
-                    if (jws2servs.hasServices())
-                    {
-                      jws2servs.attachWSMenuEntry(webService, me);
-                      for (Jws2Instance sv : jws2servs.getServices())
-                      {
-                        if (sv.description.toLowerCase().contains("jpred"))
-                        {
-                          for (JMenuItem jmi : legacyItems)
-                          {
-                            jmi.setVisible(false);
-                          }
-                        }
-                      }
-
-                    }
-                    if (jws2servs.isRunning())
-                    {
-                      JMenuItem tm = new JMenuItem(
-                              "Still discovering JABA Services");
-                      tm.setEnabled(false);
-                      webService.add(tm);
-                    }
-                  }
-                }
-                build_urlServiceMenu(me.webService);
-                build_fetchdbmenu(webService);
-                for (JMenu item : wsmenu)
-                {
-                  if (item.getItemCount() == 0)
-                  {
-                    item.setEnabled(false);
-                  }
-                  else
-                  {
-                    item.setEnabled(true);
-                  }
-                }
-              } catch (Exception e)
-              {
-                Cache.log.debug(
-                        "Exception during web service menu building process.",
-                        e);
-              }
-            }
-          });
-        } catch (Exception e)
+        WSDiscovererI jws2servs = Jws2Discoverer.getInstance();
+        JMenu submenu = new JMenu("JABAWS");
+        buildLegacyWebServicesMenu(submenu);
+        buildWebServicesMenu(jws2servs, submenu);
+        webService.add(submenu);
+      }
+    });
+  }
+
+  private void buildLegacyWebServicesMenu(JMenu menu)
+  {
+    JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
+    if (Discoverer.getServices() != null && Discoverer.getServices().size() > 0) 
+    {
+      var secstrpred = Discoverer.getServices().get("SecStrPred");
+      if (secstrpred != null) 
+      {
+        for (ext.vamsas.ServiceHandle sh : secstrpred) 
         {
+          var menuProvider = Discoverer.getServiceClient(sh);
+          menuProvider.attachWSMenuEntry(secstrmenu, this);
         }
-        buildingMenu = false;
       }
-    }).start();
+    }
+    menu.add(secstrmenu);
+  }
 
+  /**
+   * Constructs the web services menu for the given discoverer under the
+   * specified menu. This method must be called on the EDT
+   * 
+   * @param discoverer
+   *          the discoverer used to build the menu
+   * @param menu
+   *          parent component which the elements will be attached to
+   */
+  private void buildWebServicesMenu(WSDiscovererI discoverer, JMenu menu)
+  {
+    if (discoverer.hasServices())
+    {
+      PreferredServiceRegistry.getRegistry().populateWSMenuEntry(
+              discoverer.getServices(), sv -> buildWebServicesMenu(), menu,
+              this, null);
+    }
+    if (discoverer.isRunning())
+    {
+      JMenuItem item = new JMenuItem("Service discovery in progress.");
+      item.setEnabled(false);
+      menu.add(item);
+    }
+    else if (!discoverer.hasServices())
+    {
+      JMenuItem item = new JMenuItem("No services available.");
+      item.setEnabled(false);
+      menu.add(item);
+    }
   }
 
   /**
@@ -4191,7 +4715,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param webService
    */
-  private void build_urlServiceMenu(JMenu webService)
+
+  protected void build_urlServiceMenu(JMenu webService)
   {
     // TODO: remove this code when 2.7 is released
     // DEBUG - alignmentView
@@ -4199,7 +4724,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
      * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
      * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
      * 
-     * @Override public void actionPerformed(ActionEvent e) {
+     *  public void actionPerformed(ActionEvent e) {
      * jalview.datamodel.AlignmentView
      * .testSelectionViews(af.viewport.getAlignment(),
      * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
@@ -4228,6 +4753,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @return true if Show Cross-references menu should be enabled
    */
+
   public boolean canShowProducts()
   {
     SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
@@ -4255,6 +4781,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         JMenuItem xtype = new JMenuItem(source);
         xtype.addActionListener(new ActionListener()
         {
+
           @Override
           public void actionPerformed(ActionEvent e)
           {
@@ -4287,6 +4814,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param source
    *          the database to show cross-references for
    */
+
   protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
           final String source)
   {
@@ -4298,6 +4826,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * Construct and display a new frame containing the translation of this
    * frame's DNA sequences to their aligned protein (amino acid) equivalents.
    */
+
   @Override
   public void showTranslation_actionPerformed(GeneticCodeI codeTable)
   {
@@ -4316,8 +4845,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       final String errorTitle = MessageManager
               .getString("label.implementation_error")
               + MessageManager.getString("label.translation_failed");
-      JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
-              JvOptionPane.ERROR_MESSAGE);
+      JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), msg,
+              errorTitle, JvOptionPane.ERROR_MESSAGE);
       return;
     }
     if (al == null || al.getHeight() == 0)
@@ -4326,8 +4855,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
       final String errorTitle = MessageManager
               .getString("label.translation_failed");
-      JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
-              JvOptionPane.WARNING_MESSAGE);
+      JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), msg,
+              errorTitle, JvOptionPane.WARNING_MESSAGE);
     }
     else
     {
@@ -4340,7 +4869,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
       {
         final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
-        viewport.openSplitFrame(af, new Alignment(seqs));
+        AlignViewport.openSplitFrame(this, af, new Alignment(seqs));
       }
       else
       {
@@ -4355,6 +4884,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param format
    */
+
   public void setFileFormat(FileFormatI format)
   {
     this.currentFileFormat = format;
@@ -4364,15 +4894,17 @@ 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));
+            Cache.getDefault(Preferences.RELAXEDSEQIDMATCHING, false));
 
   }
 
@@ -4417,174 +4949,191 @@ 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
     {
       Desktop.transferFromDropTarget(files, protocols, evt, t);
+      if (files.size() > 0)
+      {
+        new Thread(new Runnable()
+        {
+
+          @Override
+          public void run()
+          {
+            loadDroppedFiles(files, protocols, evt, t);
+          }
+        }).start();
+      }
     } catch (Exception e)
     {
       e.printStackTrace();
     }
-    if (files != null)
+  }
+
+  protected void loadDroppedFiles(List<Object> files,
+          List<DataSourceType> protocols, DropTargetDropEvent evt,
+          Transferable t)
+  {
+    try
     {
-      new Thread(new Runnable()
+      // check to see if any of these files have names matching sequences
+      // in
+      // the alignment
+      SequenceIdMatcher idm = new SequenceIdMatcher(
+              viewport.getAlignment().getSequencesArray());
+      /**
+       * Object[] { String,SequenceI}
+       */
+      ArrayList<Object[]> filesmatched = new ArrayList<>();
+      ArrayList<Object> filesnotmatched = new ArrayList<>();
+      for (int i = 0; i < files.size(); i++)
       {
-        @Override
-        public void run()
+        // BH 2018
+        Object fileObj = files.get(i);
+        String fileName = fileObj.toString();
+        String pdbfn = "";
+        DataSourceType protocol = (fileObj instanceof File
+                ? DataSourceType.FILE
+                : FormatAdapter.checkProtocol(fileName));
+        if (protocol == DataSourceType.FILE)
         {
-          try
+          File file;
+          if (fileObj instanceof File)
+          {
+            file = (File) fileObj;
+            Platform.cacheFileData(file);
+          }
+          else
+          {
+            file = new File(fileName);
+          }
+          pdbfn = file.getName();
+        }
+        else if (protocol == DataSourceType.URL)
+        {
+          URL url = new URL(fileName);
+          pdbfn = url.getFile();
+        }
+        if (pdbfn.length() > 0)
+        {
+          // attempt to find a match in the alignment
+          SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
+          int l = 0, c = pdbfn.indexOf(".");
+          while (mtch == null && c != -1)
           {
-            // check to see if any of these files have names matching sequences
-            // in
-            // the alignment
-            SequenceIdMatcher idm = new SequenceIdMatcher(
-                    viewport.getAlignment().getSequencesArray());
-            /**
-             * Object[] { String,SequenceI}
-             */
-            ArrayList<Object[]> filesmatched = new ArrayList<>();
-            ArrayList<String> filesnotmatched = new ArrayList<>();
-            for (int i = 0; i < files.size(); i++)
+            do
             {
-              String file = files.get(i).toString();
-              String pdbfn = "";
-              DataSourceType protocol = FormatAdapter.checkProtocol(file);
-              if (protocol == DataSourceType.FILE)
-              {
-                File fl = new File(file);
-                pdbfn = fl.getName();
-              }
-              else if (protocol == DataSourceType.URL)
-              {
-                URL url = new URL(file);
-                pdbfn = url.getFile();
-              }
-              if (pdbfn.length() > 0)
-              {
-                // attempt to find a match in the alignment
-                SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
-                int l = 0, c = pdbfn.indexOf(".");
-                while (mtch == null && c != -1)
-                {
-                  do
-                  {
-                    l = c;
-                  } while ((c = pdbfn.indexOf(".", l)) > l);
-                  if (l > -1)
-                  {
-                    pdbfn = pdbfn.substring(0, l);
-                  }
-                  mtch = idm.findAllIdMatches(pdbfn);
-                }
-                if (mtch != null)
-                {
-                  FileFormatI type = null;
-                  try
-                  {
-                    type = new IdentifyFile().identify(file, protocol);
-                  } catch (Exception ex)
-                  {
-                    type = null;
-                  }
-                  if (type != null && type.isStructureFile())
-                  {
-                    filesmatched.add(new Object[] { file, protocol, mtch });
-                    continue;
-                  }
-                }
-                // File wasn't named like one of the sequences or wasn't a PDB
-                // file.
-                filesnotmatched.add(file);
-              }
+              l = c;
+            } while ((c = pdbfn.indexOf(".", l)) > l);
+            if (l > -1)
+            {
+              pdbfn = pdbfn.substring(0, l);
             }
-            int assocfiles = 0;
-            if (filesmatched.size() > 0)
+            mtch = idm.findAllIdMatches(pdbfn);
+          }
+          if (mtch != null)
+          {
+            FileFormatI type;
+            try
             {
-              boolean autoAssociate = Cache
-                      .getDefault("AUTOASSOCIATE_PDBANDSEQS", false);
-              if (!autoAssociate)
-              {
-                String msg = MessageManager.formatMessage(
-                        "label.automatically_associate_structure_files_with_sequences_same_name",
-                        new Object[]
-                        { Integer.valueOf(filesmatched.size())
-                                .toString() });
-                String ttl = MessageManager.getString(
-                        "label.automatically_associate_structure_files_by_name");
-                int choice = JvOptionPane.showConfirmDialog(thisaf, msg,
-                        ttl, JvOptionPane.YES_NO_OPTION);
-                autoAssociate = choice == JvOptionPane.YES_OPTION;
-              }
-              if (autoAssociate)
-              {
-                for (Object[] fm : filesmatched)
-                {
-                  // try and associate
-                  // TODO: may want to set a standard ID naming formalism for
-                  // associating PDB files which have no IDs.
-                  for (SequenceI toassoc : (SequenceI[]) fm[2])
-                  {
-                    PDBEntry pe = new AssociatePdbFileWithSeq()
-                            .associatePdbWithSeq((String) fm[0],
-                                    (DataSourceType) fm[1], toassoc, false,
-                                    Desktop.instance);
-                    if (pe != null)
-                    {
-                      System.err.println("Associated file : "
-                              + ((String) fm[0]) + " with "
-                              + toassoc.getDisplayId(true));
-                      assocfiles++;
-                    }
-                  }
-                  // TODO: do we need to update overview ? only if features are
-                  // shown I guess
-                  alignPanel.paintAlignment(true, false);
-                }
-              }
-              else
-              {
-                /*
-                 * add declined structures as sequences
-                 */
-                for (Object[] o : filesmatched)
-                {
-                  filesnotmatched.add((String) o[0]);
-                }
-              }
+              type = new IdentifyFile().identify(fileObj, protocol);
+            } catch (Exception ex)
+            {
+              type = null;
             }
-            if (filesnotmatched.size() > 0)
+            if (type != null && type.isStructureFile())
             {
-              if (assocfiles > 0 && (Cache.getDefault(
-                      "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
-                      || JvOptionPane.showConfirmDialog(thisaf,
-                              "<html>" + MessageManager.formatMessage(
-                                      "label.ignore_unmatched_dropped_files_info",
-                                      new Object[]
-                                      { Integer.valueOf(
-                                              filesnotmatched.size())
-                                              .toString() })
-                                      + "</html>",
-                              MessageManager.getString(
-                                      "label.ignore_unmatched_dropped_files"),
-                              JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
-              {
-                return;
-              }
-              for (String fn : filesnotmatched)
+              filesmatched.add(new Object[] { fileObj, protocol, mtch });
+              continue;
+            }
+          }
+          // File wasn't named like one of the sequences or wasn't a PDB
+          // file.
+          filesnotmatched.add(fileObj);
+        }
+      }
+      int assocfiles = 0;
+      if (filesmatched.size() > 0)
+      {
+        boolean autoAssociate = Cache
+                .getDefault(Preferences.AUTOASSOCIATE_PDBANDSEQS, false);
+        if (!autoAssociate)
+        {
+          String msg = MessageManager.formatMessage(
+                  "label.automatically_associate_structure_files_with_sequences_same_name",
+                  new Object[]
+                  { Integer.valueOf(filesmatched.size()).toString() });
+          String ttl = MessageManager.getString(
+                  "label.automatically_associate_structure_files_by_name");
+          int choice = JvOptionPane.showConfirmDialog(this, msg, ttl,
+                  JvOptionPane.YES_NO_OPTION);
+          autoAssociate = choice == JvOptionPane.YES_OPTION;
+        }
+        if (autoAssociate)
+        {
+          for (Object[] fm : filesmatched)
+          {
+            // try and associate
+            // TODO: may want to set a standard ID naming formalism for
+            // associating PDB files which have no IDs.
+            for (SequenceI toassoc : (SequenceI[]) fm[2])
+            {
+              PDBEntry pe = AssociatePdbFileWithSeq.associatePdbWithSeq(
+                      fm[0].toString(), (DataSourceType) fm[1], toassoc,
+                      false);
+              if (pe != null)
               {
-                loadJalviewDataFile(fn, null, null, null);
+                System.err.println("Associated file : " + (fm[0].toString())
+                        + " with " + toassoc.getDisplayId(true));
+                assocfiles++;
               }
-
             }
-          } catch (Exception ex)
+            // TODO: do we need to update overview ? only if features are
+            // shown I guess
+            alignPanel.paintAlignment(true, false);
+          }
+        }
+        else
+        {
+          /*
+           * add declined structures as sequences
+           */
+          for (Object[] o : filesmatched)
           {
-            ex.printStackTrace();
+            filesnotmatched.add(o[0]);
           }
         }
-      }).start();
+      }
+      if (filesnotmatched.size() > 0)
+      {
+        if (assocfiles > 0 && (Cache
+                .getDefault("AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
+                || JvOptionPane.showConfirmDialog(this,
+                        "<html>" + MessageManager.formatMessage(
+                                "label.ignore_unmatched_dropped_files_info",
+                                new Object[]
+                                { Integer.valueOf(filesnotmatched.size())
+                                        .toString() })
+                                + "</html>",
+                        MessageManager.getString(
+                                "label.ignore_unmatched_dropped_files"),
+                        JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
+        {
+          return;
+        }
+        for (Object fn : filesnotmatched)
+        {
+          loadJalviewDataFile(fn, null, null, null);
+        }
+
+      }
+    } catch (Exception ex)
+    {
+      ex.printStackTrace();
     }
   }
 
@@ -4599,10 +5148,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param file
    *          either a filename or a URL string.
+   * @throws InterruptedException
+   * @throws IOException
    */
-  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)
@@ -4633,14 +5186,14 @@ 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
             {
               // some problem - if no warning its probable that the ID matching
               // process didn't work
-              JvOptionPane.showMessageDialog(Desktop.desktop,
+              JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
                       tcf.getWarningMessage() == null
                               ? MessageManager.getString(
                                       "label.check_file_matches_sequence_ids_alignment")
@@ -4676,7 +5229,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()));
           }
@@ -4694,7 +5247,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           {
             if (parseFeaturesFile(file, sourceType))
             {
-              alignPanel.paintAlignment(true, true);
+              SplitFrame splitFrame = (SplitFrame) getSplitViewContainer();
+              if (splitFrame != null)
+              {
+                splitFrame.repaint();
+              }
+              else
+              {
+                alignPanel.paintAlignment(true, true);
+              }
             }
           }
           else
@@ -4705,11 +5266,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
       if (isAnnotation)
       {
-
-        alignPanel.adjustAnnotationHeight();
-        viewport.updateSequenceIdColours();
-        buildSortByAnnotationScoresMenu();
-        alignPanel.paintAlignment(true, true);
+        updateForAnnotations();
       }
     } catch (Exception ex)
     {
@@ -4733,7 +5290,47 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                       + (format != null
                               ? "(parsing as '" + format + "' file)"
                               : ""),
-              oom, Desktop.desktop);
+              oom, Desktop.getDesktopPane());
+    }
+  }
+
+  /**
+   * Do all updates necessary after an annotation file such as jnet. Also called
+   * from Jalview.loadAppletParams for "annotations", "jnetFile"
+   */
+
+  public void updateForAnnotations()
+  {
+    alignPanel.adjustAnnotationHeight();
+    viewport.updateSequenceIdColours();
+    buildSortByAnnotationScoresMenu();
+    alignPanel.paintAlignment(true, true);
+  }
+
+  /**
+   * Change the display state for the given feature groups -- Added by BH from
+   * JalviewLite
+   * 
+   * @param groups
+   *          list of group strings
+   * @param state
+   *          visible or invisible
+   */
+
+  public void setFeatureGroupState(String[] groups, boolean state)
+  {
+    jalview.api.FeatureRenderer fr = null;
+    viewport.setShowSequenceFeatures(true);
+    if (alignPanel != null
+            && (fr = alignPanel.getFeatureRenderer()) != null)
+    {
+
+      fr.setGroupVisibility(Arrays.asList(groups), state);
+      alignPanel.getSeqPanel().seqCanvas.repaint();
+      if (alignPanel.overviewPanel != null)
+      {
+        alignPanel.overviewPanel.updateOverviewImage();
+      }
     }
   }
 
@@ -4741,6 +5338,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * Method invoked by the ChangeListener on the tabbed pane, in other words
    * when a different tabbed pane is selected by the user or programmatically.
    */
+
   @Override
   public void tabSelectionChanged(int index)
   {
@@ -4811,14 +5409,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * On right mouse click on view tab, prompt for and set new view name.
    */
+
   @Override
   public void tabbedPane_mousePressed(MouseEvent e)
   {
     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)
       {
@@ -4837,6 +5436,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Open the dialog for regex description parsing.
    */
+
   @Override
   protected void extractScores_actionPerformed(ActionEvent e)
   {
@@ -4860,6 +5460,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
    * )
    */
+
   @Override
   protected void showDbRefs_actionPerformed(ActionEvent e)
   {
@@ -4872,6 +5473,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
    * ActionEvent)
    */
+
   @Override
   protected void showNpFeats_actionPerformed(ActionEvent e)
   {
@@ -4884,6 +5486,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param av
    */
+
   public boolean closeView(AlignViewportI av)
   {
     if (viewport == av)
@@ -4927,13 +5530,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
     trimrs.addActionListener(new ActionListener()
     {
+
       @Override
       public void actionPerformed(ActionEvent e)
       {
         trimrs.setSelected(trimrs.isSelected());
         Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
                 Boolean.valueOf(trimrs.isSelected()).toString());
-      };
+      }
     });
     rfetch.add(trimrs);
     JMenuItem fetchr = new JMenuItem(
@@ -4948,6 +5552,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       {
         new Thread(new Runnable()
         {
+
           @Override
           public void run()
           {
@@ -4959,6 +5564,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     alignPanel.alignFrame.featureSettings, isNucleotide);
             dbRefFetcher.addListener(new FetchFinishedListenerI()
             {
+
               @Override
               public void finished()
               {
@@ -4980,22 +5586,24 @@ 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);
+        // ??
+        // final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
+        // .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);
+            jalview.ws.SequenceFetcher sf = jalview.ws.SequenceFetcher
+                    .getInstance();
+            String[] dbclasses = sf.getNonAlignmentSources();
             List<DbSourceProxy> otherdb;
             JMenu dfetch = new JMenu();
             JMenu ifetch = new JMenu();
@@ -5012,21 +5620,14 @@ 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;
               }
               if (otherdb.size() == 1)
               {
-                final DbSourceProxy[] dassource = otherdb
-                        .toArray(new DbSourceProxy[0]);
                 DbSourceProxy src = otherdb.get(0);
+                DbSourceProxy[] dassource = new DbSourceProxy[] { src };
                 fetchr = new JMenuItem(src.getDbSource());
                 fetchr.addActionListener(new ActionListener()
                 {
@@ -5051,6 +5652,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                         dbRefFetcher
                                 .addListener(new FetchFinishedListenerI()
                                 {
+
                                   @Override
                                   public void finished()
                                   {
@@ -5085,6 +5687,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                         { src.getDbSource() }));
                 fetchr.addActionListener(new ActionListener()
                 {
+
                   @Override
                   public void actionPerformed(ActionEvent e)
                   {
@@ -5105,6 +5708,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                         dbRefFetcher
                                 .addListener(new FetchFinishedListenerI()
                                 {
+
                                   @Override
                                   public void finished()
                                   {
@@ -5173,6 +5777,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                           dbRefFetcher
                                   .addListener(new FetchFinishedListenerI()
                                   {
+
                                     @Override
                                     public void finished()
                                     {
@@ -5224,23 +5829,23 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Left justify the whole alignment.
    */
+
   @Override
   protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
   {
-    AlignmentI al = viewport.getAlignment();
-    al.justify(false);
-    viewport.firePropertyChange("alignment", null, al);
+    viewport.getAlignment().justify(false);
+    viewport.notifyAlignment();
   }
 
   /**
    * Right justify the whole alignment.
    */
+
   @Override
   protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
   {
-    AlignmentI al = viewport.getAlignment();
-    al.justify(true);
-    viewport.firePropertyChange("alignment", null, al);
+    viewport.getAlignment().justify(true);
+    viewport.notifyAlignment();
   }
 
   @Override
@@ -5257,6 +5862,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
    * awt.event.ActionEvent)
    */
+
   @Override
   protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
   {
@@ -5271,6 +5877,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
    * .ActionEvent)
    */
+
   @Override
   protected void showGroupConsensus_actionPerformed(ActionEvent e)
   {
@@ -5286,6 +5893,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
    * .event.ActionEvent)
    */
+
   @Override
   protected void showGroupConservation_actionPerformed(ActionEvent e)
   {
@@ -5300,6 +5908,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
    * .event.ActionEvent)
    */
+
   @Override
   protected void showConsensusHistogram_actionPerformed(ActionEvent e)
   {
@@ -5314,6 +5923,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
    * .event.ActionEvent)
    */
+
   @Override
   protected void showSequenceLogo_actionPerformed(ActionEvent e)
   {
@@ -5343,6 +5953,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
    * .event.ActionEvent)
    */
+
   @Override
   protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
   {
@@ -5394,6 +6005,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param alignmentPanel
    */
+
   public void setDisplayedView(AlignmentPanel alignmentPanel)
   {
     if (!viewport.getSequenceSetId()
@@ -5418,6 +6030,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param forAlignment
    *          update non-sequence-related annotations
    */
+
   @Override
   protected void setAnnotationsVisibility(boolean visible,
           boolean forSequences, boolean forAlignment)
@@ -5451,6 +6064,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   /**
    * Store selected annotation sort order for the view and repaint.
    */
+
   @Override
   protected void sortAnnotations_actionPerformed()
   {
@@ -5464,6 +6078,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @return alignment panels in this alignment frame
    */
+
   public List<? extends AlignmentViewPanel> getAlignPanels()
   {
     // alignPanels is never null
@@ -5475,6 +6090,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * Open a new alignment window, with the cDNA associated with this (protein)
    * alignment, aligned as is the protein.
    */
+
   protected void viewAsCdna_actionPerformed()
   {
     // TODO no longer a menu action - refactor as required
@@ -5525,6 +6141,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * 
    * @param show
    */
+
   @Override
   protected void showComplement_actionPerformed(boolean show)
   {
@@ -5539,6 +6156,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * Generate the reverse (optionally complemented) of the selected sequences,
    * and add them to the alignment
    */
+
   @Override
   protected void showReverse_actionPerformed(boolean complement)
   {
@@ -5564,6 +6182,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
    * be targeted at this alignment.
    */
+
   @Override
   protected void runGroovy_actionPerformed()
   {
@@ -5577,7 +6196,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       } catch (Exception ex)
       {
         System.err.println((ex.toString()));
-        JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+        JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
                 MessageManager.getString("label.couldnt_run_groovy_script"),
                 MessageManager.getString("label.groovy_support_failed"),
                 JvOptionPane.ERROR_MESSAGE);
@@ -5597,6 +6216,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * @param columnsContaining
    * @return
    */
+
   public boolean hideFeatureColumns(String featureType,
           boolean columnsContaining)
   {
@@ -5629,6 +6249,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * Rebuilds the Colour menu, including any user-defined colours which have
    * been loaded either on startup or during the session
    */
+
   public void buildColourMenu()
   {
     colourMenu.removeAll();
@@ -5656,6 +6277,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    * Open a dialog (if not already open) that allows the user to select and
    * calculate PCA or Tree analysis
    */
+
   protected void openTreePcaDialog()
   {
     if (alignPanel.getCalculationDialog() == null)
@@ -5664,6 +6286,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
   }
 
+  /**
+   * Sets the status of the HMMER menu
+   */
+  public void updateHMMERStatus()
+  {
+    hmmerMenu.setEnabled(HmmerCommand.isHmmerAvailable());
+  }
+
   @Override
   protected void loadVcf_actionPerformed()
   {
@@ -5672,20 +6302,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"));
-
-    int value = chooser.showOpenDialog(null);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
+    final AlignFrame us = this;
+    chooser.setResponseHandler(0, new Runnable()
     {
-      String choice = chooser.getSelectedFile().getPath();
-      Cache.setProperty("LAST_DIRECTORY", choice);
-      SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
-      new VCFLoader(choice).loadVCF(seqs, this);
-    }
+
+      @Override
+      public void run()
+      {
+        String choice = chooser.getSelectedFile().getPath();
+        Cache.setProperty("LAST_DIRECTORY", choice);
+        SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
+        new VCFLoader(choice).loadVCF(seqs, us);
+      }
+    });
+    chooser.showOpenDialog(null);
 
   }
 
   private Rectangle lastFeatureSettingsBounds = null;
+
   @Override
   public void setFeatureSettingsGeometry(Rectangle bounds)
   {
@@ -5697,42 +6332,110 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     return lastFeatureSettingsBounds;
   }
-}
 
-class PrintThread extends Thread
-{
-  AlignmentPanel ap;
+  public void scrollTo(int row, int column)
+  {
+    alignPanel.getSeqPanel().scrollTo(row, column);
+  }
 
-  public PrintThread(AlignmentPanel ap)
+  public void scrollToRow(int row)
   {
-    this.ap = ap;
+    alignPanel.getSeqPanel().scrollToRow(row);
   }
 
-  static PageFormat pf;
+  public void scrollToColumn(int column)
+  {
+    alignPanel.getSeqPanel().scrollToColumn(column);
+  }
 
-  @Override
-  public void run()
+  /**
+   * BH 2019 from JalviewLite
+   * 
+   * get sequence feature groups that are hidden or shown
+   * 
+   * @param visible
+   *          true is visible
+   * @return list
+   */
+
+  public String[] getFeatureGroupsOfState(boolean visible)
   {
-    PrinterJob printJob = PrinterJob.getPrinterJob();
+    jalview.api.FeatureRenderer fr = null;
+    if (alignPanel != null
+            && (fr = alignPanel.getFeatureRenderer()) != null)
+    {
+      List<String> gps = fr.getGroups(visible);
+      String[] _gps = gps.toArray(new String[gps.size()]);
+      return _gps;
+    }
+    return null;
+  }
+
+  /**
+   * 
+   * @return list of feature groups on the view
+   */
 
-    if (pf != null)
+  public String[] getFeatureGroups()
+  {
+    jalview.api.FeatureRenderer fr = null;
+    if (alignPanel != null
+            && (fr = alignPanel.getFeatureRenderer()) != null)
     {
-      printJob.setPrintable(ap, pf);
+      List<String> gps = fr.getFeatureGroups();
+      String[] _gps = gps.toArray(new String[gps.size()]);
+      return _gps;
     }
-    else
+    return null;
+  }
+
+  public void select(SequenceGroup sel, ColumnSelection csel,
+          HiddenColumns hidden)
+  {
+    alignPanel.getSeqPanel().selection(sel, csel, hidden, null);
+  }
+
+  public int getID()
+  {
+    return id;
+  }
+
+  static class PrintThread extends Thread
+  {
+    AlignmentPanel ap;
+
+    public PrintThread(AlignmentPanel ap)
     {
-      printJob.setPrintable(ap);
+      this.ap = ap;
     }
 
-    if (printJob.printDialog())
+    static PageFormat pf;
+
+    @Override
+    public void run()
     {
-      try
+      PrinterJob printJob = PrinterJob.getPrinterJob();
+
+      if (pf != null)
+      {
+        printJob.setPrintable(ap, pf);
+      }
+      else
       {
-        printJob.print();
-      } catch (Exception PrintException)
+        printJob.setPrintable(ap);
+      }
+
+      if (printJob.printDialog())
       {
-        PrintException.printStackTrace();
+        try
+        {
+          printJob.print();
+        } catch (Exception PrintException)
+        {
+          PrintException.printStackTrace();
+        }
       }
     }
   }
 }
+