Merge branch 'Jalview-JS/develop' into merge_js_develop
[jalview.git] / src / jalview / gui / AlignFrame.java
index c30a5a9..9d8407a 100644 (file)
  */
 package jalview.gui;
 
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Rectangle;
-import java.awt.Toolkit;
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.StringSelection;
-import java.awt.datatransfer.Transferable;
-import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DropTargetDragEvent;
-import java.awt.dnd.DropTargetDropEvent;
-import java.awt.dnd.DropTargetEvent;
-import java.awt.dnd.DropTargetListener;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.FocusAdapter;
-import java.awt.event.FocusEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.print.PageFormat;
-import java.awt.print.PrinterJob;
-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.List;
-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 jalview.analysis.AlignmentSorter;
 import jalview.analysis.AlignmentUtils;
 import jalview.analysis.CrossRef;
@@ -175,6 +123,64 @@ 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;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DropTargetDragEvent;
+import java.awt.dnd.DropTargetDropEvent;
+import java.awt.dnd.DropTargetEvent;
+import java.awt.dnd.DropTargetListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+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;
+import java.util.List;
+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!
  * 
@@ -186,6 +192,9 @@ 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;
@@ -216,6 +225,10 @@ public class AlignFrame extends GAlignFrame
    */
   File fileObject;
 
+  private int id;
+
+  private DataSourceType protocol ;
+
   /**
    * Creates a new AlignFrame object with specific width and height.
    * 
@@ -310,6 +323,9 @@ public class AlignFrame extends GAlignFrame
   public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
           int height, String sequenceSetId, String viewId)
   {
+
+    id = (++frameCount);
+
     setSize(width, height);
 
     if (al.getDataset() == null)
@@ -319,9 +335,9 @@ public class AlignFrame extends GAlignFrame
 
     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();
   }
 
@@ -341,8 +357,8 @@ public class AlignFrame extends GAlignFrame
     {
       viewport.hideSequence(hiddenSeqs);
     }
-    alignPanel = new AlignmentPanel(this, viewport);
-    addAlignmentPanel(alignPanel, true);
+    // alignPanel = new AlignmentPanel(this, viewport);
+    // addAlignmentPanel(alignPanel, true);
     init();
   }
 
@@ -358,7 +374,7 @@ public class AlignFrame extends GAlignFrame
   {
     viewport = ap.av;
     alignPanel = ap;
-    addAlignmentPanel(ap, false);
+    // addAlignmentPanel(ap, false);
     init();
   }
 
@@ -366,13 +382,38 @@ public class AlignFrame extends GAlignFrame
    * 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,
@@ -387,7 +428,7 @@ public class AlignFrame extends GAlignFrame
       // 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"))
@@ -399,8 +440,10 @@ public class AlignFrame extends GAlignFrame
       sortPairwiseMenuItem_actionPerformed(null);
     }
 
-    this.alignPanel.av
-            .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
+    // BH see above
+    //
+    // this.alignPanel.av
+    // .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
 
     setMenusFromViewport(viewport);
     buildSortByAnnotationScoresMenu();
@@ -415,7 +458,7 @@ public class AlignFrame extends GAlignFrame
     });
     buildColourMenu();
 
-    if (Desktop.desktop != null)
+    if (Desktop.getDesktopPane() != null)
     {
       this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
       addServiceListeners();
@@ -430,7 +473,7 @@ public class AlignFrame extends GAlignFrame
       wrapMenuItem_actionPerformed(null);
     }
 
-    if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
+    if (jalview.bin.Cache.getDefault(Preferences.SHOW_OVERVIEW, false))
     {
       this.overviewMenuItem_actionPerformed(null);
     }
@@ -514,6 +557,7 @@ public class AlignFrame extends GAlignFrame
     }
     addFocusListener(new FocusAdapter()
     {
+
       @Override
       public void focusGained(FocusEvent e)
       {
@@ -532,6 +576,8 @@ public class AlignFrame extends GAlignFrame
    * @param format
    *          format of file
    */
+
+  @Deprecated
   public void setFileName(String file, FileFormatI format)
   {
     fileName = file;
@@ -540,11 +586,28 @@ public class AlignFrame extends GAlignFrame
   }
 
   /**
+   * 
+   * @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;
@@ -554,10 +617,12 @@ public class AlignFrame extends GAlignFrame
    * Add a KeyListener with handlers for various KeyPressed and KeyReleased
    * events
    */
+
   void addKeyListener()
   {
     addKeyListener(new KeyAdapter()
     {
+
       @Override
       public void keyPressed(KeyEvent evt)
       {
@@ -574,8 +639,9 @@ public class AlignFrame extends GAlignFrame
         switch (evt.getKeyCode())
         {
 
-        case 27: // escape key
-          deselectAllSequenceMenuItem_actionPerformed(null);
+        case KeyEvent.VK_ESCAPE: // escape key
+                                 // alignPanel.deselectAllSequences();
+          alignPanel.deselectAllSequences();
 
           break;
 
@@ -758,16 +824,14 @@ public class AlignFrame extends GAlignFrame
         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;
         }
@@ -813,10 +877,13 @@ public class AlignFrame extends GAlignFrame
       {
         ap.av.getAlignment().padGaps();
       }
-      ap.av.updateConservation(ap);
-      ap.av.updateConsensus(ap);
-      ap.av.updateStrucConsensus(ap);
-      ap.av.initInformationWorker(ap);
+      if (Jalview.getInstance().getStartCalculations())
+      {
+        ap.av.updateConservation(ap);
+        ap.av.updateConsensus(ap);
+        ap.av.updateStrucConsensus(ap);
+        ap.av.initInformationWorker(ap);
+      }
     }
   }
 
@@ -852,22 +919,22 @@ public class AlignFrame extends GAlignFrame
     }
     if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
     {
-      WSDiscovererI discoverer = Jws2Discoverer.getDiscoverer();
+      WSDiscovererI discoverer = Jws2Discoverer.getInstance();
       discoverer.addServiceChangeListener(this);
     }
     // legacy event listener for compatibility with jws1
     PropertyChangeListener legacyListener = (changeEvent) -> {
       buildWebServicesMenu();
     };
-    Desktop.instance.addJalviewPropertyChangeListener("services",legacyListener);
+    Desktop.getInstance().addJalviewPropertyChangeListener("services",legacyListener);
     
     addInternalFrameListener(new InternalFrameAdapter() {
       @Override
       public void internalFrameClosed(InternalFrameEvent e) {
         System.out.println("deregistering discoverer listener");
         SlivkaWSDiscoverer.getInstance().removeServiceChangeListener(AlignFrame.this);
-        Jws2Discoverer.getDiscoverer().removeServiceChangeListener(AlignFrame.this);
-        Desktop.instance.removeJalviewPropertyChangeListener("services", legacyListener);
+        Jws2Discoverer.getInstance().removeServiceChangeListener(AlignFrame.this);
+        Desktop.getInstance().removeJalviewPropertyChangeListener("services", legacyListener);
         closeMenuItem_actionPerformed(true);
       }
     });
@@ -878,6 +945,7 @@ public class AlignFrame extends GAlignFrame
    * Configure menu items that vary according to whether the alignment is
    * nucleotide or protein
    */
+
   public void setGUINucleotide()
   {
     AlignmentI al = getViewport().getAlignment();
@@ -902,6 +970,7 @@ public class AlignFrame extends GAlignFrame
    * 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()
   {
@@ -915,6 +984,7 @@ public class AlignFrame extends GAlignFrame
    * @param av
    *          AlignViewport
    */
+
   public void setMenusFromViewport(AlignViewport av)
   {
     padGapsMenuitem.setSelected(av.isPadGaps());
@@ -932,13 +1002,8 @@ public class AlignFrame extends GAlignFrame
     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());
@@ -959,7 +1024,8 @@ public class AlignFrame extends GAlignFrame
     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);
 
@@ -974,6 +1040,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param b
    */
+
   public void setGroovyEnabled(boolean b)
   {
     runGroovy.setEnabled(b);
@@ -986,6 +1053,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
    */
+
   @Override
   public void setProgressBar(String message, long id)
   {
@@ -1009,6 +1077,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @return true if any progress bars are still active
    */
+
   @Override
   public boolean operationInProgress()
   {
@@ -1020,6 +1089,7 @@ public class AlignFrame extends GAlignFrame
    * will cause the status bar to be hidden, with possibly undesirable flicker
    * of the screen layout.
    */
+
   @Override
   public void setStatus(String text)
   {
@@ -1029,6 +1099,7 @@ public class AlignFrame extends GAlignFrame
   /*
    * Added so Castor Mapping file can obtain Jalview Version
    */
+
   public String getVersion()
   {
     return jalview.bin.Cache.getProperty("VERSION");
@@ -1048,7 +1119,7 @@ public class AlignFrame extends GAlignFrame
   @Override
   public void addFromFile_actionPerformed(ActionEvent e)
   {
-    Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
+    Desktop.getInstance().inputLocalFileMenuItem_actionPerformed(viewport);
   }
 
   @Override
@@ -1305,97 +1376,96 @@ public class AlignFrame extends GAlignFrame
   @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);
       }
-      else
-      {
-        Rectangle bounds = this.getBounds();
+      Desktop.getInstance().closeAssociatedWindows();
 
-        FileLoader loader = new FileLoader();
+      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();
 
-        AlignFrame newframe = null;
+      FileLoader loader = new FileLoader();
 
-        if (fileObject == null)
-        {
+      AlignFrame newframe = null;
 
-          DataSourceType protocol = (fileName.startsWith("http:")
-                  ? DataSourceType.URL
-                  : DataSourceType.FILE);
-          newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
-                  currentFileFormat);
-        }
-        else
-        {
-          newframe = loader.LoadFileWaitTillLoaded(fileObject,
-                  DataSourceType.FILE, currentFileFormat);
-        }
+      if (fileObject == null)
+      {
+        newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
+                currentFileFormat);
+      }
+      else
+      {
+        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
@@ -1416,6 +1486,7 @@ public class AlignFrame extends GAlignFrame
    * 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()
   {
@@ -1439,7 +1510,7 @@ public class AlignFrame extends GAlignFrame
     // todo is this (2005) test now obsolete - value is never null?
     while (currentFileFormat == null)
     {
-      JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+      JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
               MessageManager
                       .getString("label.select_file_format_before_saving"),
               MessageManager.getString("label.file_format_not_specified"),
@@ -1470,6 +1541,7 @@ public class AlignFrame extends GAlignFrame
    *
    * @return true if last call to saveAlignment(file, format) was successful.
    */
+
   public boolean isSaveAlignmentSuccessful()
   {
 
@@ -1502,6 +1574,7 @@ public class AlignFrame extends GAlignFrame
    * @param file
    * @param format
    */
+
   public void saveAlignment(String file, FileFormatI format)
   {
     lastSaveSuccessful = true;
@@ -1529,6 +1602,7 @@ public class AlignFrame extends GAlignFrame
     AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
     Runnable cancelAction = new Runnable()
     {
+
       @Override
       public void run()
       {
@@ -1537,6 +1611,7 @@ public class AlignFrame extends GAlignFrame
     };
     Runnable outputAction = new Runnable()
     {
+
       @Override
       public void run()
       {
@@ -1611,6 +1686,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param fileFormatName
    */
+
   @Override
   protected void outputText_actionPerformed(String fileFormatName)
   {
@@ -1619,6 +1695,7 @@ public class AlignFrame extends GAlignFrame
     AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
     Runnable outputAction = new Runnable()
     {
+
       @Override
       public void run()
       {
@@ -1669,6 +1746,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void htmlMenuItem_actionPerformed(ActionEvent e)
   {
@@ -1683,6 +1761,8 @@ public class AlignFrame extends GAlignFrame
     bjs.exportHTML(null);
   }
 
+  // ??
+
   public void createImageMap(File file, String image)
   {
     alignPanel.makePNGImageMap(file, image);
@@ -1694,6 +1774,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param f
    */
+
   @Override
   public void createPNG(File f)
   {
@@ -1706,6 +1787,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param f
    */
+
   @Override
   public void createEPS(File f)
   {
@@ -1718,6 +1800,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param f
    */
+
   @Override
   public void createSVG(File f)
   {
@@ -1737,6 +1820,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void printMenuItem_actionPerformed(ActionEvent e)
   {
@@ -1770,6 +1854,7 @@ public class AlignFrame extends GAlignFrame
     chooser.setToolTipText(tooltip);
     chooser.setResponseHandler(0, new Runnable()
     {
+
       @Override
       public void run()
       {
@@ -1788,6 +1873,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param closeAllTabs
    */
+
   @Override
   public void closeMenuItem_actionPerformed(boolean closeAllTabs)
   {
@@ -1842,6 +1928,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param panelToClose
    */
+
   public void closeView(AlignmentPanel panelToClose)
   {
     int index = tabbedPane.getSelectedIndex();
@@ -1865,6 +1952,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * DOCUMENT ME!
    */
+
   void updateEditMenuBar()
   {
 
@@ -1918,6 +2006,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @return alignment objects for all views
    */
+
   AlignmentI[] getViewAlignments()
   {
     if (alignPanels != null)
@@ -1943,6 +2032,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void undoMenuItem_actionPerformed(ActionEvent e)
   {
@@ -1970,8 +2060,8 @@ public class AlignFrame extends GAlignFrame
       // && viewport.getColumnSelection().getHiddenColumns() != null &&
       // viewport.getColumnSelection()
       // .getHiddenColumns().size() > 0);
-      originalSource.firePropertyChange("alignment", null,
-              originalSource.getAlignment().getSequences());
+      originalSource.notifyAlignment();
+
     }
   }
 
@@ -1981,6 +2071,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void redoMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2010,8 +2101,8 @@ public class AlignFrame extends GAlignFrame
       // && viewport.getColumnSelection().getHiddenColumns() != null &&
       // viewport.getColumnSelection()
       // .getHiddenColumns().size() > 0);
-      originalSource.firePropertyChange("alignment", null,
-              originalSource.getAlignment().getSequences());
+      originalSource.notifyAlignment();
+
     }
   }
 
@@ -2063,6 +2154,7 @@ public class AlignFrame extends GAlignFrame
    * @param up
    *          DOCUMENT ME!
    */
+
   public void moveSelectedSequences(boolean up)
   {
     SequenceGroup sg = viewport.getSelectionGroup();
@@ -2187,6 +2279,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void copy_actionPerformed()
   {
@@ -2209,16 +2302,17 @@ public class AlignFrame extends GAlignFrame
 
     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);
@@ -2238,7 +2332,7 @@ public class AlignFrame extends GAlignFrame
               hiddenCutoff, hiddenOffset);
     }
 
-    Desktop.jalviewClipboard = new Object[] { seqs,
+    d.jalviewClipboard = new Object[] { seqs,
         viewport.getAlignment().getDataset(), hiddenColumns };
     setStatus(MessageManager.formatMessage(
             "label.copied_sequences_to_clipboard", new Object[]
@@ -2253,6 +2347,7 @@ public class AlignFrame extends GAlignFrame
    * @throws InterruptedException
    * @throws IOException
    */
+
   @Override
   protected void pasteNew_actionPerformed(ActionEvent e)
           throws IOException, InterruptedException
@@ -2268,6 +2363,7 @@ public class AlignFrame extends GAlignFrame
    * @throws InterruptedException
    * @throws IOException
    */
+
   @Override
   protected void pasteThis_actionPerformed(ActionEvent e)
           throws IOException, InterruptedException
@@ -2318,12 +2414,14 @@ public class AlignFrame extends GAlignFrame
       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++)
@@ -2348,10 +2446,10 @@ public class AlignFrame extends GAlignFrame
       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
         {
@@ -2367,8 +2465,8 @@ public class AlignFrame extends GAlignFrame
         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<SequenceI> newDs = (importDs) ? new Vector<>() : null; // used to
@@ -2549,8 +2647,7 @@ public class AlignFrame extends GAlignFrame
           }
           buildSortByAnnotationScoresMenu();
         }
-        viewport.firePropertyChange("alignment", null,
-                alignment.getSequences());
+        viewport.notifyAlignment();
         if (alignPanels != null)
         {
           for (AlignmentPanel ap : alignPanels)
@@ -2570,10 +2667,9 @@ public class AlignFrame extends GAlignFrame
                 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);
         }
 
@@ -2624,11 +2720,10 @@ public class AlignFrame extends GAlignFrame
       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);
       }
 
@@ -2667,6 +2762,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * Action Cut (delete and copy) the selected region
    */
+
   @Override
   protected void cut_actionPerformed()
   {
@@ -2677,6 +2773,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * Performs menu option to Delete the currently selected region
    */
+
   @Override
   protected void delete_actionPerformed()
   {
@@ -2689,6 +2786,7 @@ public class AlignFrame extends GAlignFrame
 
     Runnable okAction = new Runnable()
     {
+
       @Override
       public void run()
       {
@@ -2705,8 +2803,8 @@ public class AlignFrame extends GAlignFrame
         viewport.sendSelection();
         viewport.getAlignment().deleteGroup(sg);
 
-        viewport.firePropertyChange("alignment", null,
-                viewport.getAlignment().getSequences());
+        viewport.notifyAlignment();
+
         if (viewport.getAlignment().getHeight() < 1)
         {
           try
@@ -2715,6 +2813,8 @@ public class AlignFrame extends GAlignFrame
           } catch (Exception ex)
           {
           }
+        } else {
+          updateAll(null);
         }
       }
     };
@@ -2728,7 +2828,8 @@ public class AlignFrame extends GAlignFrame
             + 1) == viewport.getAlignment().getWidth()) ? true : false;
     if (wholeHeight && wholeWidth)
     {
-      JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
+      JvOptionPane dialog = JvOptionPane
+              .newOptionDialog(Desktop.getDesktopPane());
       dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION
       Object[] options = new Object[] {
           MessageManager.getString("action.ok"),
@@ -2750,15 +2851,32 @@ public class AlignFrame extends GAlignFrame
    * @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();
   }
 
   /**
@@ -2767,21 +2885,11 @@ public class AlignFrame extends GAlignFrame
    * @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());
+    alignPanel.selectAllSequences();
   }
 
   /**
@@ -2790,24 +2898,11 @@ public class AlignFrame extends GAlignFrame
    * @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();
   }
 
   /**
@@ -2816,6 +2911,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2823,7 +2919,7 @@ public class AlignFrame extends GAlignFrame
 
     if (sg == null)
     {
-      selectAllSequenceMenuItem_actionPerformed(null);
+      alignPanel.selectAllSequences();
 
       return;
     }
@@ -2855,6 +2951,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2867,6 +2964,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void remove2RightMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2913,8 +3011,8 @@ public class AlignFrame extends GAlignFrame
                 column, viewport.getAlignment());
       }
 
-      setStatus(MessageManager
-              .formatMessage("label.removed_columns", new String[]
+      setStatus(MessageManager.formatMessage("label.removed_columns",
+              new String[]
               { Integer.valueOf(trimRegion.getSize()).toString() }));
 
       addHistoryItem(trimRegion);
@@ -2928,8 +3026,8 @@ public class AlignFrame extends GAlignFrame
         }
       }
 
-      viewport.firePropertyChange("alignment", null,
-              viewport.getAlignment().getSequences());
+      viewport.notifyAlignment();
+
     }
   }
 
@@ -2939,6 +3037,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
   {
@@ -2963,8 +3062,8 @@ public class AlignFrame extends GAlignFrame
 
     addHistoryItem(removeGapCols);
 
-    setStatus(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
@@ -2978,8 +3077,8 @@ public class AlignFrame extends GAlignFrame
     // if (viewport.hasHiddenColumns)
     // viewport.getColumnSelection().compensateForEdits(shifts);
     ranges.setStartRes(seq.findIndex(startRes) - 1);
-    viewport.firePropertyChange("alignment", null,
-            viewport.getAlignment().getSequences());
+    viewport.notifyAlignment();
+
 
   }
 
@@ -2989,6 +3088,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3016,9 +3116,7 @@ public class AlignFrame extends GAlignFrame
             viewport.getAlignment()));
 
     viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
-
-    viewport.firePropertyChange("alignment", null,
-            viewport.getAlignment().getSequences());
+    viewport.notifyAlignment();
 
   }
 
@@ -3028,12 +3126,13 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void padGapsMenuitem_actionPerformed(ActionEvent e)
   {
     viewport.setPadGaps(padGapsMenuitem.isSelected());
-    viewport.firePropertyChange("alignment", null,
-            viewport.getAlignment().getSequences());
+    viewport.notifyAlignment();
+
   }
 
   /**
@@ -3042,6 +3141,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void findMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3051,6 +3151,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * Create a new view of the current alignment.
    */
+
   @Override
   public void newView_actionPerformed(ActionEvent e)
   {
@@ -3066,6 +3167,7 @@ public class AlignFrame extends GAlignFrame
    *          if true then duplicate all annnotation, groups and settings
    * @return new alignment panel, already displayed.
    */
+
   public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
   {
     /*
@@ -3086,8 +3188,8 @@ public class AlignFrame extends GAlignFrame
 
     if (viewport.getViewName() == null)
     {
-      viewport.setViewName(MessageManager
-              .getString("label.view_name_original"));
+      viewport.setViewName(
+              MessageManager.getString("label.view_name_original"));
     }
 
     /*
@@ -3138,6 +3240,7 @@ public class AlignFrame extends GAlignFrame
    * @param viewTitle
    * @return
    */
+
   protected String getNewViewName(String viewTitle)
   {
     int index = Desktop.getViewCount(viewport.getSequenceSetId());
@@ -3172,6 +3275,7 @@ public class AlignFrame extends GAlignFrame
    * @param comps
    * @return
    */
+
   protected List<String> getExistingViewNames(List<Component> comps)
   {
     List<String> existingNames = new ArrayList<>();
@@ -3192,6 +3296,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * Explode tabbed views into separate windows.
    */
+
   @Override
   public void expandViews_actionPerformed(ActionEvent e)
   {
@@ -3201,10 +3306,11 @@ public class AlignFrame extends GAlignFrame
   /**
    * 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);
   }
 
   /**
@@ -3213,6 +3319,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void font_actionPerformed(ActionEvent e)
   {
@@ -3225,6 +3332,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void seqLimit_actionPerformed(ActionEvent e)
   {
@@ -3254,6 +3362,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
    */
+
   @Override
   protected void followHighlight_actionPerformed()
   {
@@ -3275,6 +3384,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void colourTextMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3288,6 +3398,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void wrapMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3324,6 +3435,7 @@ public class AlignFrame extends GAlignFrame
    * @param toggleSeqs
    * @param toggleCols
    */
+
   protected void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
   {
 
@@ -3391,6 +3503,7 @@ public class AlignFrame extends GAlignFrame
    * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
    * event.ActionEvent)
    */
+
   @Override
   public void hideAllButSelection_actionPerformed(ActionEvent e)
   {
@@ -3405,6 +3518,7 @@ public class AlignFrame extends GAlignFrame
    * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
    * .ActionEvent)
    */
+
   @Override
   public void hideAllSelection_actionPerformed(ActionEvent e)
   {
@@ -3424,6 +3538,7 @@ public class AlignFrame extends GAlignFrame
    * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
    * ActionEvent)
    */
+
   @Override
   public void showAllhidden_actionPerformed(ActionEvent e)
   {
@@ -3455,6 +3570,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void scaleAbove_actionPerformed(ActionEvent e)
   {
@@ -3469,6 +3585,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void scaleLeft_actionPerformed(ActionEvent e)
   {
@@ -3483,6 +3600,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void scaleRight_actionPerformed(ActionEvent e)
   {
@@ -3497,6 +3615,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3510,6 +3629,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void viewTextMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3523,6 +3643,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3568,6 +3689,7 @@ public class AlignFrame extends GAlignFrame
    * @param evt
    *          DOCUMENT ME!
    */
+
   @Override
   public void showSeqFeatures_actionPerformed(ActionEvent evt)
   {
@@ -3584,16 +3706,32 @@ public class AlignFrame extends GAlignFrame
    * 
    * @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
@@ -3647,6 +3785,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void overviewMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3656,17 +3795,42 @@ public class AlignFrame extends GAlignFrame
     }
 
     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)
@@ -3695,6 +3859,7 @@ public class AlignFrame extends GAlignFrame
    * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
    * ()[0])); }
    */
+
   @Override
   public void annotationColour_actionPerformed()
   {
@@ -3714,6 +3879,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param selected
    */
+
   @Override
   public void applyToAllGroups_actionPerformed(boolean selected)
   {
@@ -3726,6 +3892,7 @@ public class AlignFrame extends GAlignFrame
    * @param name
    *          the name (not the menu item label!) of the colour scheme
    */
+
   @Override
   public void changeColour_actionPerformed(String name)
   {
@@ -3753,6 +3920,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param cs
    */
+
   @Override
   public void changeColour(ColourSchemeI cs)
   {
@@ -3767,6 +3935,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * Show the PID threshold slider panel
    */
+
   @Override
   protected void modifyPID_actionPerformed()
   {
@@ -3778,6 +3947,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * Show the Conservation slider panel
    */
+
   @Override
   protected void modifyConservation_actionPerformed()
   {
@@ -3789,6 +3959,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * Action on selecting or deselecting (Colour) By Conservation
    */
+
   @Override
   public void conservationMenuItem_actionPerformed(boolean selected)
   {
@@ -3810,6 +3981,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * Action on selecting or deselecting (Colour) Above PID Threshold
    */
+
   @Override
   public void abovePIDThreshold_actionPerformed(boolean selected)
   {
@@ -3838,6 +4010,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3855,6 +4028,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void sortIDMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3871,6 +4045,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void sortLengthMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3887,6 +4062,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void sortGroupMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3926,6 +4102,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3938,6 +4115,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
   {
@@ -3963,11 +4141,14 @@ public class AlignFrame extends GAlignFrame
   @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();
     }
   }
 
@@ -3993,6 +4174,7 @@ public class AlignFrame extends GAlignFrame
    * @param options
    *          parameters for the distance or similarity calculation
    */
+
   void newTreePanel(String type, String modelName,
           SimilarityParamsI options)
   {
@@ -4010,7 +4192,7 @@ public class AlignFrame extends GAlignFrame
       {
         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(
@@ -4042,7 +4224,8 @@ public class AlignFrame extends GAlignFrame
 
     frameTitle += this.title;
 
-    Desktop.addInternalFrame(tp, frameTitle, 600, 500);
+    Dimension dim = Platform.getDimIfEmbedded(tp, 600, 500);
+    Desktop.addInternalFrame(tp, frameTitle, dim.width, dim.height);
   }
 
   /**
@@ -4053,6 +4236,7 @@ public class AlignFrame extends GAlignFrame
    * @param order
    *          DOCUMENT ME!
    */
+
   public void addSortByOrderMenuItem(String title,
           final AlignmentOrder order)
   {
@@ -4062,6 +4246,7 @@ public class AlignFrame extends GAlignFrame
     sort.add(item);
     item.addActionListener(new java.awt.event.ActionListener()
     {
+
       @Override
       public void actionPerformed(ActionEvent e)
       {
@@ -4088,6 +4273,7 @@ public class AlignFrame extends GAlignFrame
    *          the label used to retrieve scores for each sequence on the
    *          alignment
    */
+
   public void addSortByAnnotScoreMenuItem(JMenu sort,
           final String scoreLabel)
   {
@@ -4095,6 +4281,7 @@ public class AlignFrame extends GAlignFrame
     sort.add(item);
     item.addActionListener(new java.awt.event.ActionListener()
     {
+
       @Override
       public void actionPerformed(ActionEvent e)
       {
@@ -4120,6 +4307,7 @@ public class AlignFrame extends GAlignFrame
    * rebuilding in subsequence calls.
    * 
    */
+
   @Override
   public void buildSortByAnnotationScoresMenu()
   {
@@ -4159,41 +4347,38 @@ public class AlignFrame extends GAlignFrame
   }
 
   /**
+   * 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)
         {
@@ -4207,6 +4392,21 @@ public class AlignFrame extends GAlignFrame
     }
   }
 
+  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();
@@ -4225,6 +4425,7 @@ public class AlignFrame extends GAlignFrame
    * be submitted for multiple alignment.
    * 
    */
+
   public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
   {
     // Now, check we have enough sequences
@@ -4270,6 +4471,7 @@ public class AlignFrame extends GAlignFrame
    * 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;
@@ -4303,6 +4505,7 @@ public class AlignFrame extends GAlignFrame
    * @param e
    *          DOCUMENT ME!
    */
+
   @Override
   protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
   {
@@ -4317,6 +4520,7 @@ public class AlignFrame extends GAlignFrame
 
     chooser.setResponseHandler(0, new Runnable()
     {
+
       @Override
       public void run()
       {
@@ -4330,7 +4534,8 @@ public class AlignFrame extends GAlignFrame
           viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
         } catch (Exception ex)
         {
-          JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
+          JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
+                  ex.getMessage(),
                   MessageManager
                           .getString("label.problem_reading_tree_file"),
                   JvOptionPane.WARNING_MESSAGE);
@@ -4338,7 +4543,7 @@ public class AlignFrame extends GAlignFrame
         }
         if (fin != null && fin.hasWarningMessage())
         {
-          JvOptionPane.showMessageDialog(Desktop.desktop,
+          JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
                   fin.getWarningMessage(),
                   MessageManager.getString(
                           "label.possible_problem_with_tree_file"),
@@ -4380,6 +4585,7 @@ public class AlignFrame extends GAlignFrame
    *          position
    * @return TreePanel handle
    */
+
   public TreePanel showNewickTree(NewickFile nf, String treeTitle,
           AlignmentView input, int w, int h, int x, int y)
   {
@@ -4392,15 +4598,24 @@ public class AlignFrame extends GAlignFrame
       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)
     {
@@ -4428,7 +4643,7 @@ public class AlignFrame extends GAlignFrame
       }
       if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
       {
-        WSDiscovererI jws2servs = Jws2Discoverer.getDiscoverer();
+        WSDiscovererI jws2servs = Jws2Discoverer.getInstance();
         JMenu submenu = new JMenu("JABAWS");
         buildLegacyWebServicesMenu(submenu);
         buildWebServicesMenu(jws2servs, submenu);
@@ -4440,9 +4655,9 @@ public class AlignFrame extends GAlignFrame
   private void buildLegacyWebServicesMenu(JMenu menu)
   {
     JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
-    if (Discoverer.services != null && Discoverer.services.size() > 0) 
+    if (Discoverer.getServices() != null && Discoverer.getServices().size() > 0) 
     {
-      var secstrpred = Discoverer.services.get("SecStrPred");
+      var secstrpred = Discoverer.getServices().get("SecStrPred");
       if (secstrpred != null) 
       {
         for (ext.vamsas.ServiceHandle sh : secstrpred) 
@@ -4491,6 +4706,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param webService
    */
+
   protected void build_urlServiceMenu(JMenu webService)
   {
     // TODO: remove this code when 2.7 is released
@@ -4499,7 +4715,7 @@ public class AlignFrame extends GAlignFrame
      * 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); }
@@ -4528,6 +4744,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @return true if Show Cross-references menu should be enabled
    */
+
   public boolean canShowProducts()
   {
     SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
@@ -4555,6 +4772,7 @@ public class AlignFrame extends GAlignFrame
         JMenuItem xtype = new JMenuItem(source);
         xtype.addActionListener(new ActionListener()
         {
+
           @Override
           public void actionPerformed(ActionEvent e)
           {
@@ -4587,6 +4805,7 @@ public class AlignFrame extends GAlignFrame
    * @param source
    *          the database to show cross-references for
    */
+
   protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
           final String source)
   {
@@ -4598,6 +4817,7 @@ public class AlignFrame extends GAlignFrame
    * 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)
   {
@@ -4616,8 +4836,8 @@ public class AlignFrame extends GAlignFrame
       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)
@@ -4626,8 +4846,8 @@ public class AlignFrame extends GAlignFrame
               "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
     {
@@ -4640,7 +4860,7 @@ public class AlignFrame extends GAlignFrame
       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
       {
@@ -4655,6 +4875,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param format
    */
+
   public void setFileFormat(FileFormatI format)
   {
     this.currentFileFormat = format;
@@ -4669,11 +4890,12 @@ public class AlignFrame extends GAlignFrame
    *          access mode of file (see jalview.io.AlignFile)
    * @return true if features file was parsed correctly.
    */
+
   public boolean parseFeaturesFile(Object file, DataSourceType sourceType)
   {
     // BH 2018
     return avc.parseFeaturesFile(file, sourceType,
-            Cache.getDefault("RELAXEDSEQIDMATCHING", false));
+            Cache.getDefault(Preferences.RELAXEDSEQIDMATCHING, false));
 
   }
 
@@ -4719,187 +4941,190 @@ public class AlignFrame extends GAlignFrame
     evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
     Transferable t = evt.getTransferable();
 
-    final AlignFrame thisaf = this;
     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
           {
-            // 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++)
+            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)
+          {
+            do
             {
-              // BH 2018
-              Object file = files.get(i);
-              String fileName = file.toString();
-              String pdbfn = "";
-              DataSourceType protocol = (file instanceof File
-                      ? DataSourceType.FILE
-                      : FormatAdapter.checkProtocol(fileName));
-              if (protocol == DataSourceType.FILE)
-              {
-                File fl;
-                if (file instanceof File)
-                {
-                  fl = (File) file;
-                  Platform.cacheFileData(fl);
-                }
-                else
-                {
-                  fl = new File(fileName);
-                }
-                pdbfn = fl.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)
-                {
-                  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;
-                  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(fm[0].toString(),
-                                    (DataSourceType) fm[1], toassoc, false,
-                                    Desktop.instance);
-                    if (pe != null)
-                    {
-                      System.err.println("Associated file : "
-                              + (fm[0].toString()) + " 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(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 (Object 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();
     }
   }
 
@@ -4917,6 +5142,7 @@ public class AlignFrame extends GAlignFrame
    * @throws InterruptedException
    * @throws IOException
    */
+
   public void loadJalviewDataFile(Object file, DataSourceType sourceType,
           FileFormatI format, SequenceI assocSeq)
   {
@@ -4958,7 +5184,7 @@ public class AlignFrame extends GAlignFrame
             {
               // 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")
@@ -5031,10 +5257,7 @@ public class AlignFrame extends GAlignFrame
       }
       if (isAnnotation)
       {
-        alignPanel.adjustAnnotationHeight();
-        viewport.updateSequenceIdColours();
-        buildSortByAnnotationScoresMenu();
-        alignPanel.paintAlignment(true, true);
+        updateForAnnotations();
       }
     } catch (Exception ex)
     {
@@ -5058,7 +5281,47 @@ public class AlignFrame extends GAlignFrame
                       + (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();
+      }
     }
   }
 
@@ -5066,6 +5329,7 @@ public class AlignFrame extends GAlignFrame
    * 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)
   {
@@ -5136,6 +5400,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * On right mouse click on view tab, prompt for and set new view name.
    */
+
   @Override
   public void tabbedPane_mousePressed(MouseEvent e)
   {
@@ -5162,6 +5427,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * Open the dialog for regex description parsing.
    */
+
   @Override
   protected void extractScores_actionPerformed(ActionEvent e)
   {
@@ -5185,6 +5451,7 @@ public class AlignFrame extends GAlignFrame
    * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
    * )
    */
+
   @Override
   protected void showDbRefs_actionPerformed(ActionEvent e)
   {
@@ -5197,6 +5464,7 @@ public class AlignFrame extends GAlignFrame
    * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
    * ActionEvent)
    */
+
   @Override
   protected void showNpFeats_actionPerformed(ActionEvent e)
   {
@@ -5209,6 +5477,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param av
    */
+
   public boolean closeView(AlignViewportI av)
   {
     if (viewport == av)
@@ -5252,6 +5521,7 @@ public class AlignFrame extends GAlignFrame
             Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
     trimrs.addActionListener(new ActionListener()
     {
+
       @Override
       public void actionPerformed(ActionEvent e)
       {
@@ -5273,6 +5543,7 @@ public class AlignFrame extends GAlignFrame
       {
         new Thread(new Runnable()
         {
+
           @Override
           public void run()
           {
@@ -5284,6 +5555,7 @@ public class AlignFrame extends GAlignFrame
                     alignPanel.alignFrame.featureSettings, isNucleotide);
             dbRefFetcher.addListener(new FetchFinishedListenerI()
             {
+
               @Override
               public void finished()
               {
@@ -5307,16 +5579,21 @@ public class AlignFrame extends GAlignFrame
     rfetch.add(fetchr);
     new Thread(new Runnable()
     {
+
       @Override
       public void run()
       {
-        final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
-                .getSequenceFetcherSingleton();
+        // ??
+        // final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
+        // .getSequenceFetcherSingleton();
         javax.swing.SwingUtilities.invokeLater(new Runnable()
         {
+
           @Override
           public void run()
           {
+            jalview.ws.SequenceFetcher sf = jalview.ws.SequenceFetcher
+                    .getInstance();
             String[] dbclasses = sf.getNonAlignmentSources();
             List<DbSourceProxy> otherdb;
             JMenu dfetch = new JMenu();
@@ -5340,9 +5617,8 @@ public class AlignFrame extends GAlignFrame
               }
               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()
                 {
@@ -5367,6 +5643,7 @@ public class AlignFrame extends GAlignFrame
                         dbRefFetcher
                                 .addListener(new FetchFinishedListenerI()
                                 {
+
                                   @Override
                                   public void finished()
                                   {
@@ -5401,6 +5678,7 @@ public class AlignFrame extends GAlignFrame
                         { src.getDbSource() }));
                 fetchr.addActionListener(new ActionListener()
                 {
+
                   @Override
                   public void actionPerformed(ActionEvent e)
                   {
@@ -5421,6 +5699,7 @@ public class AlignFrame extends GAlignFrame
                         dbRefFetcher
                                 .addListener(new FetchFinishedListenerI()
                                 {
+
                                   @Override
                                   public void finished()
                                   {
@@ -5489,6 +5768,7 @@ public class AlignFrame extends GAlignFrame
                           dbRefFetcher
                                   .addListener(new FetchFinishedListenerI()
                                   {
+
                                     @Override
                                     public void finished()
                                     {
@@ -5540,23 +5820,23 @@ public class AlignFrame extends GAlignFrame
   /**
    * 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
@@ -5573,6 +5853,7 @@ public class AlignFrame extends GAlignFrame
    * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
    * awt.event.ActionEvent)
    */
+
   @Override
   protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
   {
@@ -5587,6 +5868,7 @@ public class AlignFrame extends GAlignFrame
    * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
    * .ActionEvent)
    */
+
   @Override
   protected void showGroupConsensus_actionPerformed(ActionEvent e)
   {
@@ -5602,6 +5884,7 @@ public class AlignFrame extends GAlignFrame
    * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
    * .event.ActionEvent)
    */
+
   @Override
   protected void showGroupConservation_actionPerformed(ActionEvent e)
   {
@@ -5616,6 +5899,7 @@ public class AlignFrame extends GAlignFrame
    * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
    * .event.ActionEvent)
    */
+
   @Override
   protected void showConsensusHistogram_actionPerformed(ActionEvent e)
   {
@@ -5630,6 +5914,7 @@ public class AlignFrame extends GAlignFrame
    * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
    * .event.ActionEvent)
    */
+
   @Override
   protected void showSequenceLogo_actionPerformed(ActionEvent e)
   {
@@ -5659,6 +5944,7 @@ public class AlignFrame extends GAlignFrame
    * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
    * .event.ActionEvent)
    */
+
   @Override
   protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
   {
@@ -5710,6 +5996,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param alignmentPanel
    */
+
   public void setDisplayedView(AlignmentPanel alignmentPanel)
   {
     if (!viewport.getSequenceSetId()
@@ -5734,6 +6021,7 @@ public class AlignFrame extends GAlignFrame
    * @param forAlignment
    *          update non-sequence-related annotations
    */
+
   @Override
   protected void setAnnotationsVisibility(boolean visible,
           boolean forSequences, boolean forAlignment)
@@ -5767,6 +6055,7 @@ public class AlignFrame extends GAlignFrame
   /**
    * Store selected annotation sort order for the view and repaint.
    */
+
   @Override
   protected void sortAnnotations_actionPerformed()
   {
@@ -5780,6 +6069,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @return alignment panels in this alignment frame
    */
+
   public List<? extends AlignmentViewPanel> getAlignPanels()
   {
     // alignPanels is never null
@@ -5791,6 +6081,7 @@ public class AlignFrame extends GAlignFrame
    * 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
@@ -5841,6 +6132,7 @@ public class AlignFrame extends GAlignFrame
    * 
    * @param show
    */
+
   @Override
   protected void showComplement_actionPerformed(boolean show)
   {
@@ -5855,6 +6147,7 @@ public class AlignFrame extends GAlignFrame
    * Generate the reverse (optionally complemented) of the selected sequences,
    * and add them to the alignment
    */
+
   @Override
   protected void showReverse_actionPerformed(boolean complement)
   {
@@ -5880,6 +6173,7 @@ public class AlignFrame extends GAlignFrame
    * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
    * be targeted at this alignment.
    */
+
   @Override
   protected void runGroovy_actionPerformed()
   {
@@ -5893,7 +6187,7 @@ public class AlignFrame extends GAlignFrame
       } 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);
@@ -5913,6 +6207,7 @@ public class AlignFrame extends GAlignFrame
    * @param columnsContaining
    * @return
    */
+
   public boolean hideFeatureColumns(String featureType,
           boolean columnsContaining)
   {
@@ -5945,6 +6240,7 @@ public class AlignFrame extends GAlignFrame
    * 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();
@@ -5972,6 +6268,7 @@ public class AlignFrame extends GAlignFrame
    * 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)
@@ -5999,6 +6296,7 @@ public class AlignFrame extends GAlignFrame
     final AlignFrame us = this;
     chooser.setResponseHandler(0, new Runnable()
     {
+
       @Override
       public void run()
       {
@@ -6025,42 +6323,110 @@ public class AlignFrame extends GAlignFrame
   {
     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;
+  }
 
-    if (pf != null)
+  /**
+   * 
+   * @return list of feature groups on the view
+   */
+
+  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.print();
-      } catch (Exception PrintException)
+        printJob.setPrintable(ap, pf);
+      }
+      else
+      {
+        printJob.setPrintable(ap);
+      }
+
+      if (printJob.printDialog())
       {
-        PrintException.printStackTrace();
+        try
+        {
+          printJob.print();
+        } catch (Exception PrintException)
+        {
+          PrintException.printStackTrace();
+        }
       }
     }
   }
 }
+