JAL-3210 Barebones gradle/buildship/eclipse. See README
[jalview.git] / src / jalview / project / Jalview2XML.java
index c28f24d..5618529 100644 (file)
@@ -28,7 +28,6 @@ import jalview.analysis.Conservation;
 import jalview.analysis.PCA;
 import jalview.analysis.scoremodels.ScoreModels;
 import jalview.analysis.scoremodels.SimilarityParams;
-import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureColourI;
 import jalview.api.ViewStyleI;
 import jalview.api.analysis.ScoreModelI;
@@ -83,6 +82,7 @@ import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.FeatureColour;
 import jalview.schemes.ResidueProperties;
 import jalview.schemes.UserColourScheme;
+import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.Format;
 import jalview.util.MessageManager;
@@ -163,6 +163,7 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
 import java.math.BigInteger;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -623,14 +624,13 @@ public class Jalview2XML
    * core method for storing state for a set of AlignFrames.
    * 
    * @param frames
-   *          - frames involving all data to be exported (including those
-   *          contained in splitframes, though not the split frames themselves)
+   *          - frames involving all data to be exported (including containing
+   *          splitframes)
    * @param jout
    *          - project output stream
    */
   private void saveAllFrames(List<AlignFrame> frames, JarOutputStream jout)
   {
-
     Hashtable<String, AlignFrame> dsses = new Hashtable<>();
 
     /*
@@ -653,22 +653,21 @@ public class Jalview2XML
       for (int i = frames.size() - 1; i > -1; i--)
       {
         AlignFrame af = frames.get(i);
-        AlignViewport vp = af.getViewport();
         // skip ?
         if (skipList != null && skipList
-                .containsKey(vp.getSequenceSetId()))
+                .containsKey(af.getViewport().getSequenceSetId()))
         {
           continue;
         }
 
         String shortName = makeFilename(af, shortNames);
 
-        AlignmentI alignment = vp.getAlignment();
-        List<? extends AlignmentViewPanel> panels = af.getAlignPanels();
-        int apSize = panels.size();
+        int apSize = af.getAlignPanels().size();
+
         for (int ap = 0; ap < apSize; ap++)
-          {
-          AlignmentPanel apanel = (AlignmentPanel) panels.get(ap);
+        {
+          AlignmentPanel apanel = (AlignmentPanel) af.getAlignPanels()
+                  .get(ap);
           String fileName = apSize == 1 ? shortName : ap + shortName;
           if (!fileName.endsWith(".xml"))
           {
@@ -676,17 +675,11 @@ public class Jalview2XML
           }
 
           saveState(apanel, fileName, jout, viewIds);
-        }
-        if (apSize > 0)
-        {
-          // BH moved next bit out of inner loop, not that it really matters.
-          // so we are testing to make sure we actually have an alignment,
-          // apparently.
-          String dssid = getDatasetIdRef(alignment.getDataset());
+
+          String dssid = getDatasetIdRef(
+                  af.getViewport().getAlignment().getDataset());
           if (!dsses.containsKey(dssid))
           {
-            // We have not already covered this data by reference from another
-            // frame.
             dsses.put(dssid, af);
           }
         }
@@ -804,22 +797,10 @@ public class Jalview2XML
     }
   }
 
-  /**
-   * Each AlignFrame has a single data set associated with it. Note that none of
-   * these frames are split frames, because Desktop.getAlignFrames() collects
-   * top and bottom separately here.
-   * 
-   * @param dsses
-   * @param fileName
-   * @param jout
-   */
   private void writeDatasetFor(Hashtable<String, AlignFrame> dsses,
           String fileName, JarOutputStream jout)
   {
 
-    // Note that in saveAllFrames we have associated each specific dataset to
-    // ONE of its associated frames.
-
     for (String dssids : dsses.keySet())
     {
       AlignFrame _af = dsses.get(dssids);
@@ -1100,7 +1081,7 @@ public class Jalview2XML
            * only view *should* be coped with sensibly.
            */
           // This must have been loaded, is it still visible?
-          JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
+          JInternalFrame[] frames = Desktop.desktop.getAllFrames();
           String matchedFile = null;
           for (int f = frames.length - 1; f > -1; f--)
           {
@@ -1252,9 +1233,9 @@ public class Jalview2XML
     {
       // FIND ANY ASSOCIATED TREES
       // NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT
-      if (Desktop.getDesktopPane() != null)
+      if (Desktop.desktop != null)
       {
-        JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
+        JInternalFrame[] frames = Desktop.desktop.getAllFrames();
 
         for (int t = 0; t < frames.length; t++)
         {
@@ -1298,9 +1279,9 @@ public class Jalview2XML
     /*
      * save PCA viewers
      */
-    if (!storeDS && Desktop.getDesktopPane() != null)
+    if (!storeDS && Desktop.desktop != null)
     {
-      for (JInternalFrame frame : Desktop.getDesktopPane().getAllFrames())
+      for (JInternalFrame frame : Desktop.desktop.getAllFrames())
       {
         if (frame instanceof PCAPanel)
         {
@@ -1691,7 +1672,7 @@ public class Jalview2XML
       // using save and then load
       try
       {
-       fileName = fileName.replace('\\', '/');
+        fileName = fileName.replace('\\', '/');
         System.out.println("Writing jar entry " + fileName);
         JarEntry entry = new JarEntry(fileName);
         jout.putNextEntry(entry);
@@ -1938,11 +1919,11 @@ public class Jalview2XML
           final SequenceI jds, List<String> viewIds, AlignmentPanel ap,
           boolean storeDataset)
   {
-    if (Desktop.getDesktopPane() == null)
+    if (Desktop.desktop == null)
     {
       return;
     }
-    JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
+    JInternalFrame[] frames = Desktop.desktop.getAllFrames();
     for (int f = frames.length - 1; f > -1; f--)
     {
       if (frames[f] instanceof AppVarna)
@@ -2398,7 +2379,7 @@ public class Jalview2XML
     if (calcIdParam.getVersion().equals("1.0"))
     {
       final String[] calcIds = calcIdParam.getServiceURL().toArray(new String[0]);
-      Jws2Instance service = Jws2Discoverer.getInstance()
+      Jws2Instance service = Jws2Discoverer.getDiscoverer()
               .getPreferredServiceFor(calcIds);
       if (service != null)
       {
@@ -2774,8 +2755,7 @@ public class Jalview2XML
     {
       try
       {
-         // BH 2019 -- can't wait
-        SwingUtilities.invokeLater(new Runnable()
+        SwingUtilities.invokeAndWait(new Runnable()
         {
           @Override
           public void run()
@@ -2791,52 +2771,52 @@ public class Jalview2XML
     return af;
   }
 
-       @SuppressWarnings("unused")
-       private jarInputStreamProvider createjarInputStreamProvider(final Object ofile) throws MalformedURLException {
+        @SuppressWarnings("unused")
+        private jarInputStreamProvider createjarInputStreamProvider(final Object ofile) throws MalformedURLException {
 
-               // BH 2018 allow for bytes already attached to File object
-               try {
-                       String file = (ofile instanceof File ? ((File) ofile).getCanonicalPath() : ofile.toString());
+                // BH 2018 allow for bytes already attached to File object
+                try {
+                        String file = (ofile instanceof File ? ((File) ofile).getCanonicalPath() : ofile.toString());
       byte[] bytes = Platform.isJS() ? Platform.getFileBytes((File) ofile)
               : null;
-                       URL url = null;
-                       errorMessage = null;
-                       uniqueSetSuffix = null;
-                       seqRefIds = null;
-                       viewportsAdded.clear();
-                       frefedSequence = null;
-
-                       if (file.startsWith("http://")) {
-                               url = new URL(file);
-                       }
-                       final URL _url = url;
-                       return new jarInputStreamProvider() {
-
-                               @Override
-                               public JarInputStream getJarInputStream() throws IOException {
-                                       if (bytes != null) {
-//                                             System.out.println("Jalview2XML: opening byte jarInputStream for bytes.length=" + bytes.length);
-                                               return new JarInputStream(new ByteArrayInputStream(bytes));
-                                       }
-                                       if (_url != null) {
-//                                             System.out.println("Jalview2XML: opening url jarInputStream for " + _url);
-                                               return new JarInputStream(_url.openStream());
-                                       } else {
-//                                             System.out.println("Jalview2XML: opening file jarInputStream for " + file);
-                                               return new JarInputStream(new FileInputStream(file));
-                                       }
-                               }
-
-                               @Override
-                               public String getFilename() {
-                                       return file;
-                               }
-                       };
-               } catch (IOException e) {
-                       e.printStackTrace();
-                       return null;
-               }
-       }
+                        URL url = null;
+                        errorMessage = null;
+                        uniqueSetSuffix = null;
+                        seqRefIds = null;
+                        viewportsAdded.clear();
+                        frefedSequence = null;
+
+                        if (file.startsWith("http://")) {
+                                url = new URL(file);
+                        }
+                        final URL _url = url;
+                        return new jarInputStreamProvider() {
+
+                                @Override
+                                public JarInputStream getJarInputStream() throws IOException {
+                                        if (bytes != null) {
+//                                              System.out.println("Jalview2XML: opening byte jarInputStream for bytes.length=" + bytes.length);
+                                                return new JarInputStream(new ByteArrayInputStream(bytes));
+                                        }
+                                        if (_url != null) {
+//                                              System.out.println("Jalview2XML: opening url jarInputStream for " + _url);
+                                                return new JarInputStream(_url.openStream());
+                                        } else {
+//                                              System.out.println("Jalview2XML: opening file jarInputStream for " + file);
+                                                return new JarInputStream(new FileInputStream(file));
+                                        }
+                                }
+
+                                @Override
+                                public String getFilename() {
+                                        return file;
+                                }
+                        };
+                } catch (IOException e) {
+                        e.printStackTrace();
+                        return null;
+                }
+        }
 
   /**
    * Recover jalview session from a jalview project archive. Caller may
@@ -2862,19 +2842,12 @@ public class Jalview2XML
     IdentityHashMap<AlignmentI, AlignmentI> importedDatasets = new IdentityHashMap<>();
     Map<String, AlignFrame> gatherToThisFrame = new HashMap<>();
     final String file = jprovider.getFilename();
-
-    List<AlignFrame> alignFrames = new ArrayList<>();
-
     try
     {
       JarInputStream jin = null;
       JarEntry jarentry = null;
       int entryCount = 1;
 
-
-      // Look for all the entry names ending with ".xml"
-      // This includes all panels and at least one frame.
-//      Platform.timeCheck(null, Platform.TIME_MARK);
       do
       {
         jin = jprovider.getJarInputStream();
@@ -2882,27 +2855,9 @@ public class Jalview2XML
         {
           jarentry = jin.getNextJarEntry();
         }
-        String name = (jarentry == null ? null : jarentry.getName());
 
-//        System.out.println("Jalview2XML opening " + name);
-        if (name != null && name.endsWith(".xml"))
+        if (jarentry != null && jarentry.getName().endsWith(".xml"))
         {
-
-          // DataSet for.... is read last.
-          
-          
-          // The question here is what to do with the two
-          // .xml files in the jvp file.
-          // Some number of them, "...Dataset for...", will be the
-          // Only AlignPanels and will have Viewport.
-          // One or more will be the source data, with the DBRefs.
-          //
-          // JVP file writing (above) ensures tha the AlignPanels are written
-          // first, then all relevant datasets (which are
-          // Jalview.datamodel.Alignment).
-          //
-
-//          Platform.timeCheck("Jalview2XML JAXB " + name, Platform.TIME_MARK);
           JAXBContext jc = JAXBContext
                   .newInstance("jalview.xml.binding.jalview");
           XMLStreamReader streamReader = XMLInputFactory.newInstance()
@@ -2910,25 +2865,14 @@ public class Jalview2XML
           javax.xml.bind.Unmarshaller um = jc.createUnmarshaller();
           JAXBElement<JalviewModel> jbe = um
                   .unmarshal(streamReader, JalviewModel.class);
-          JalviewModel model = jbe.getValue();
+          JalviewModel object = jbe.getValue();
 
           if (true) // !skipViewport(object))
           {
-            // Q: Do we have to load from the model, even if it
-            // does not have a viewport, could we discover that early on?
-            // Q: Do we need to load this object?
-            _af = loadFromObject(model, file, true, jprovider);
-//            Platform.timeCheck("Jalview2XML.loadFromObject",
-            // Platform.TIME_MARK);
-
-            if (_af != null)
-            {
-              alignFrames.add(_af);
-            }
-            if (_af != null && model.getViewport().size() > 0)
+            _af = loadFromObject(object, file, true, jprovider);
+            if (_af != null && object.getViewport().size() > 0)
+            // getJalviewModelSequence().getViewportCount() > 0)
             {
-
-              // That is, this is one of the AlignmentPanel models
               if (af == null)
               {
                 // store a reference to the first view
@@ -2948,7 +2892,6 @@ public class Jalview2XML
                       af.getViewport().getAlignment().getDataset());
             }
           }
-//          Platform.timeCheck("JAXB " + name, Platform.TIME_MARK);
           entryCount++;
         }
         else if (jarentry != null)
@@ -2957,10 +2900,7 @@ public class Jalview2XML
           entryCount++;
         }
       } while (jarentry != null);
-//      Platform.timeCheck("JAXB loop exit", Platform.TIME_MARK);
       resolveFrefedSequences();
-//      Platform.timeCheck("JAXB resolveFrefed", Platform.TIME_MARK);
-
     } catch (IOException ex)
     {
       ex.printStackTrace();
@@ -2975,9 +2915,9 @@ public class Jalview2XML
       {
         // used to attempt to parse as V1 castor-generated xml
       }
-      if (Desktop.getInstance() != null)
+      if (Desktop.instance != null)
       {
-        Desktop.getInstance().stopLoading();
+        Desktop.instance.stopLoading();
       }
       if (af != null)
       {
@@ -2994,13 +2934,6 @@ public class Jalview2XML
       errorMessage = "Out of memory loading jalview XML file";
       System.err.println("Out of memory whilst loading jalview XML file");
       e.printStackTrace();
-    } finally
-    {
-      for (AlignFrame alf : alignFrames)
-      {
-        alf.alignPanel.setHoldRepaint(false);
-      }
-
     }
 
     /*
@@ -3012,7 +2945,7 @@ public class Jalview2XML
      */
     for (AlignFrame fr : gatherToThisFrame.values())
     {
-      Desktop.getInstance().gatherViews(fr);
+      Desktop.instance.gatherViews(fr);
     }
 
     restoreSplitFrames();
@@ -3020,7 +2953,8 @@ public class Jalview2XML
     {
       if (ds.getCodonFrames() != null)
       {
-        Desktop.getInstance().getStructureSelectionManager()
+        StructureSelectionManager
+                .getStructureSelectionManager(Desktop.instance)
                 .registerMappings(ds.getCodonFrames());
       }
     }
@@ -3029,9 +2963,9 @@ public class Jalview2XML
       reportErrors();
     }
 
-    if (Desktop.getInstance() != null)
+    if (Desktop.instance != null)
     {
-      Desktop.getInstance().stopLoading();
+      Desktop.instance.stopLoading();
     }
 
     return af;
@@ -3112,7 +3046,7 @@ public class Jalview2XML
      */
     for (SplitFrame sf : gatherTo)
     {
-      Desktop.getInstance().gatherViews(sf);
+      Desktop.instance.gatherViews(sf);
     }
 
     splitFrameCandidates.clear();
@@ -3171,7 +3105,7 @@ public class Jalview2XML
           @Override
           public void run()
           {
-            JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
+            JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                     finalErrorMessage,
                     "Error " + (saving ? "saving" : "loading")
                             + " Jalview file",
@@ -3330,9 +3264,7 @@ public class Jalview2XML
   }
 
   /**
-   * Load alignment frame from jalview XML DOM object. For a DOM object that
-   * includes one or more Viewport elements (one with a title that does NOT
-   * contain "Dataset for"), create the frame.
+   * Load alignment frame from jalview XML DOM object
    * 
    * @param jalviewModel
    *          DOM
@@ -3347,13 +3279,9 @@ public class Jalview2XML
   AlignFrame loadFromObject(JalviewModel jalviewModel, String file,
           boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
   {
-
-//    Platform.timeCheck("Jalview2XML.loadFromObject0", Platform.TIME_MARK);
-
     SequenceSet vamsasSet = jalviewModel.getVamsasModel().getSequenceSet().get(0);
     List<Sequence> vamsasSeqs = vamsasSet.getSequence();
 
-
     // JalviewModelSequence jms = object.getJalviewModelSequence();
 
     // Viewport view = (jms.getViewportCount() > 0) ? jms.getViewport(0)
@@ -3384,7 +3312,6 @@ public class Jalview2XML
               : view.getId() + uniqueSetSuffix);
     }
 
-//    Platform.timeCheck("Jalview2XML.loadFromObject1", Platform.TIME_MARK);
     // ////////////////////////////////
     // LOAD SEQUENCES
 
@@ -3405,7 +3332,6 @@ public class Jalview2XML
       SequenceI tmpSeq = seqRefIds.get(seqId);
       if (tmpSeq != null)
       {
-        //
         if (!incompleteSeqs.containsKey(seqId))
         {
           // may not need this check, but keep it for at least 2.9,1 release
@@ -3470,8 +3396,6 @@ public class Jalview2XML
       }
     }
 
-//    Platform.timeCheck("Jalview2XML.loadFromObject-seq",
-//            Platform.TIME_MARK);
     // /
     // Create the alignment object from the sequence set
     // ///////////////////////////////
@@ -3512,8 +3436,6 @@ public class Jalview2XML
       recoverDatasetFor(vamsasSet, al, isdsal, uniqueSeqSetId);
     }
 
-//    Platform.timeCheck("Jalview2XML.loadFromObject-align",
-//            Platform.TIME_MARK);
     if (referenceseqForView != null)
     {
       al.setSeqrep(referenceseqForView);
@@ -3526,8 +3448,6 @@ public class Jalview2XML
       al.setProperty(ssp.getKey(), ssp.getValue());
     }
 
-//    Platform.timeCheck("Jalview2XML.loadFromObject-setseqprop",
-//            Platform.TIME_MARK);
     // ///////////////////////////////
 
     Hashtable pdbloaded = new Hashtable(); // TODO nothing writes to this??
@@ -3541,7 +3461,6 @@ public class Jalview2XML
       // now, for 2.10 projects, this is also done if the xml doc includes
       // dataset sequences not actually present in any particular view.
       //
-//      Platform.timeCheck("J2XML features0", Platform.TIME_RESET);
       for (int i = 0; i < vamsasSeqs.size(); i++)
       {
         JSeq jseq = jseqs.get(i);
@@ -3596,9 +3515,7 @@ public class Jalview2XML
             }
 
             // adds feature to datasequence's feature set (since Jalview 2.10)
-//            Platform.timeCheck(null, Platform.TIME_SET);
             al.getSequenceAt(i).addSequenceFeature(sf);
-//            Platform.timeCheck(null, Platform.TIME_MARK);
           }
         }
         if (vamsasSeqs.get(i).getDBRef().size() > 0)
@@ -3658,7 +3575,8 @@ public class Jalview2XML
             {
               entry.setProperty(prop.getName(), prop.getValue());
             }
-            Desktop.getInstance().getStructureSelectionManager()
+            StructureSelectionManager
+                    .getStructureSelectionManager(Desktop.instance)
                     .registerPDBEntry(entry);
             // adds PDBEntry to datasequence's set (since Jalview 2.10)
             if (al.getSequenceAt(i).getDatasetSequence() != null)
@@ -3671,12 +3589,7 @@ public class Jalview2XML
             }
           }
         }
-
       }
-
-//      Platform.timeCheck("features done", Platform.TIME_GET);
-//      Platform.timeCheck("Jalview2XML.loadFromObject-endmultiview",
-//              Platform.TIME_MARK);
     } // end !multipleview
 
     // ///////////////////////////////
@@ -3718,8 +3631,6 @@ public class Jalview2XML
           al.addCodonFrame(cf);
         }
       }
-//      Platform.timeCheck("Jalview2XML.loadFromObject-seqmap",
-//              Platform.TIME_MARK);
     }
 
     // ////////////////////////////////
@@ -3780,9 +3691,6 @@ public class Jalview2XML
         }
         // Construct new annotation from model.
         List<AnnotationElement> ae = annotation.getAnnotationElement();
-//        System.err.println(
-//                "Jalview2XML processing " + ae.size() + " annotations");
-
         jalview.datamodel.Annotation[] anot = null;
         java.awt.Color firstColour = null;
         int anpos;
@@ -3818,7 +3726,6 @@ public class Jalview2XML
             }
           }
         }
-        // create the new AlignmentAnnotation
         jalview.datamodel.AlignmentAnnotation jaa = null;
 
         if (annotation.isGraph())
@@ -3855,7 +3762,6 @@ public class Jalview2XML
           jaa._linecolour = firstColour;
         }
         // register new annotation
-        // Annotation graphs such as Conservation will not have id.
         if (annotation.getId() != null)
         {
           annotationIds.put(annotation.getId(), jaa);
@@ -3944,8 +3850,6 @@ public class Jalview2XML
           al.addAnnotation(jaa);
         }
       }
-//      Platform.timeCheck("Jalview2XML.loadFromObject-annot",
-//              Platform.TIME_MARK);
     }
     // ///////////////////////
     // LOAD GROUPS
@@ -4060,8 +3964,6 @@ public class Jalview2XML
                   jGroup.getAnnotationColours(), null, al, jalviewModel, false));
         }
       }
-//      Platform.timeCheck("Jalview2XML.loadFromObject-groups",
-//              Platform.TIME_MARK);
     }
     if (view == null)
     {
@@ -4071,6 +3973,8 @@ public class Jalview2XML
     // ///////////////////////////////
     // LOAD VIEWPORT
 
+    AlignFrame af = null;
+    AlignViewport av = null;
     // now check to see if we really need to create a new viewport.
     if (multipleView && viewportsAdded.size() == 0)
     {
@@ -4101,8 +4005,6 @@ public class Jalview2XML
         }
 
       }
-//      Platform.timeCheck("Jalview2XML.loadFromObject-viewport",
-//              Platform.TIME_MARK);
     }
     /**
      * indicate that annotation colours are applied across all groups (pre
@@ -4111,9 +4013,8 @@ public class Jalview2XML
     boolean doGroupAnnColour = Jalview2XML.isVersionStringLaterThan("2.8.1",
             jalviewModel.getVersion());
 
-    AlignFrame af = null;
     AlignmentPanel ap = null;
-    AlignViewport av = null;
+    boolean isnewview = true;
     if (viewId != null)
     {
       // Check to see if this alignment already has a view id == viewId
@@ -4123,27 +4024,25 @@ public class Jalview2XML
       {
         for (int v = 0; v < views.length; v++)
         {
-          ap = views[v];
-          av = ap.av;
-          if (av.getViewId().equalsIgnoreCase(viewId))
+          if (views[v].av.getViewId().equalsIgnoreCase(viewId))
           {
             // recover the existing alignpanel, alignframe, viewport
-            af = ap.alignFrame;
-            break;
+            af = views[v].alignFrame;
+            av = views[v].av;
+            ap = views[v];
             // TODO: could even skip resetting view settings if we don't want to
             // change the local settings from other jalview processes
+            isnewview = false;
           }
         }
       }
     }
 
-    if (af == null)
+    if (isnewview)
     {
       af = loadViewport(file, jseqs, hiddenSeqs, al, jalviewModel, view,
               uniqueSeqSetId, viewId, autoAlan);
       av = af.getViewport();
-      // note that this only retrieves the most recently accessed
-      // tab of an AlignFrame.
       ap = af.alignPanel;
     }
 
@@ -4152,61 +4051,14 @@ public class Jalview2XML
      * 
      * Not done if flag is false (when this method is used for New View)
      */
-    final AlignFrame af0 = af;
-    final AlignViewport av0 = av;
-    final AlignmentPanel ap0 = ap;
-//    Platform.timeCheck("Jalview2XML.loadFromObject-beforetree",
-//            Platform.TIME_MARK);
     if (loadTreesAndStructures)
     {
-      if (!jalviewModel.getTree().isEmpty())
-      {
-        SwingUtilities.invokeLater(new Runnable()
-        {
-          @Override
-          public void run()
-          {
-//            Platform.timeCheck(null, Platform.TIME_MARK);
-            loadTrees(jalviewModel, view, af0, av0, ap0);
-//            Platform.timeCheck("Jalview2XML.loadTrees", Platform.TIME_MARK);
-          }
-        });
-      }
-      if (!jalviewModel.getPcaViewer().isEmpty())
-      {
-        SwingUtilities.invokeLater(new Runnable()
-        {
-          @Override
-          public void run()
-          {
-//            Platform.timeCheck(null, Platform.TIME_MARK);
-            loadPCAViewers(jalviewModel, ap0);
-//            Platform.timeCheck("Jalview2XML.loadPCA", Platform.TIME_MARK);
-          }
-        });
-      }
-      SwingUtilities.invokeLater(new Runnable()
-      {
-        @Override
-        public void run()
-        {
-//          Platform.timeCheck(null, Platform.TIME_MARK);
-          loadPDBStructures(jprovider, jseqs, af0, ap0);
-//          Platform.timeCheck("Jalview2XML.loadPDB", Platform.TIME_MARK);
-        }
-      });
-      SwingUtilities.invokeLater(new Runnable()
-      {
-        @Override
-        public void run()
-        {
-          loadRnaViewers(jprovider, jseqs, ap0);
-        }
-      });
+      loadTrees(jalviewModel, view, af, av, ap);
+      loadPCAViewers(jalviewModel, ap);
+      loadPDBStructures(jprovider, jseqs, af, ap);
+      loadRnaViewers(jprovider, jseqs, ap);
     }
     // and finally return.
-    // but do not set holdRepaint true just yet, because this could be the
-    // initial frame with just its dataset.
     return af;
   }
 
@@ -4223,7 +4075,7 @@ public class Jalview2XML
    * @param jseqs
    * @param ap
    */
-  protected void loadRnaViewers(jarInputStreamProvider jprovider,
+  private void loadRnaViewers(jarInputStreamProvider jprovider,
           List<JSeq> jseqs, AlignmentPanel ap)
   {
     /*
@@ -4442,7 +4294,7 @@ public class Jalview2XML
             int height = safeInt(structureState.getHeight());
 
             // Probably don't need to do this anymore...
-            // Desktop.getDesktop().getComponentAt(x, y);
+            // Desktop.desktop.getComponentAt(x, y);
             // TODO: NOW: check that this recovers the PDB file correctly.
             String pdbFile = loadPDBFile(jprovider, pdbid.getId(),
                     pdbid.getFile());
@@ -4684,7 +4536,7 @@ public class Jalview2XML
           String reformatedOldFilename = oldfilenam.replaceAll("/", "\\\\");
           filedat = oldFiles.get(new File(reformatedOldFilename));
         }
-        newFileLoc.append(Platform.escapeString(filedat.getFilePath()));
+        newFileLoc.append(Platform.escapeBackslashes(filedat.getFilePath()));
         pdbfilenames.add(filedat.getFilePath());
         pdbids.add(filedat.getPdbId());
         seqmaps.add(filedat.getSeqList().toArray(new SequenceI[0]));
@@ -4761,9 +4613,9 @@ public class Jalview2XML
     final AlignFrame alf = af;
     final Rectangle rect = new Rectangle(svattrib.getX(), svattrib.getY(),
             svattrib.getWidth(), svattrib.getHeight());
-    // try
-    // {
-      javax.swing.SwingUtilities.invokeLater(new Runnable()
+    try
+    {
+      javax.swing.SwingUtilities.invokeAndWait(new Runnable()
       {
         @Override
         public void run()
@@ -4790,14 +4642,14 @@ public class Jalview2XML
           }
         }
       });
-    // } catch (InvocationTargetException ex)
-    // {
-    // warn("Unexpected error when opening Jmol view.", ex);
-    //
-    // } catch (InterruptedException e)
-    // {
-    // // e.printStackTrace();
-    // }
+    } catch (InvocationTargetException ex)
+    {
+      warn("Unexpected error when opening Jmol view.", ex);
+
+    } catch (InterruptedException e)
+    {
+      // e.printStackTrace();
+    }
 
   }
 
@@ -4926,7 +4778,7 @@ public class Jalview2XML
     {
       try
       {
-        frames = Desktop.getDesktopPane().getAllFrames();
+        frames = Desktop.desktop.getAllFrames();
       } catch (ArrayIndexOutOfBoundsException e)
       {
         // occasional No such child exceptions are thrown here...
@@ -5003,19 +4855,19 @@ public class Jalview2XML
   {
     AlignFrame af = null;
     af = new AlignFrame(al, safeInt(view.getWidth()),
-            safeInt(view.getHeight()), uniqueSeqSetId, viewId)
+            safeInt(view.getHeight()), uniqueSeqSetId, viewId) 
 //    {
-//     
-//     @Override
-//     protected void processKeyEvent(java.awt.event.KeyEvent e) {
-//             System.out.println("Jalview2XML   AF " + e);
-//             super.processKeyEvent(e);
-//             
-//     }
-//     
+//      
+//      @Override
+//      protected void processKeyEvent(java.awt.event.KeyEvent e) {
+//              System.out.println("Jalview2XML   AF " + e);
+//              super.processKeyEvent(e);
+//              
+//      }
+//      
 //    }
     ;
-    af.alignPanel.setHoldRepaint(true);
+
     af.setFileName(file, FileFormat.Jalview);
 
     final AlignViewport viewport = af.getViewport();
@@ -5124,18 +4976,8 @@ public class Jalview2XML
       viewport.setViewName(view.getViewName());
       af.setInitialTabVisible();
     }
-    int x = safeInt(view.getXpos());
-    int y = safeInt(view.getYpos());
-    int w = safeInt(view.getWidth());
-    int h = safeInt(view.getHeight());
-    // // BH we cannot let the title bar go off the top
-    // if (Platform.isJS())
-    // {
-    // x = Math.max(50 - w, x);
-    // y = Math.max(0, y);
-    // }
-
-    af.setBounds(x, y, w, h);
+    af.setBounds(safeInt(view.getXpos()), safeInt(view.getYpos()),
+            safeInt(view.getWidth()), safeInt(view.getHeight()));
     // startSeq set in af.alignPanel.updateLayout below
     af.alignPanel.updateLayout();
     ColourSchemeI cs = null;
@@ -5298,7 +5140,7 @@ public class Jalview2XML
         }
         else
         {
-          featureOrder.put(featureType, new Float(
+          featureOrder.put(featureType, Float.valueOf(
                   fs / jm.getFeatureSettings().getSetting().size()));
         }
         if (safeBoolean(setting.isDisplay()))
@@ -5310,7 +5152,7 @@ public class Jalview2XML
       for (int gs = 0; gs < jm.getFeatureSettings().getGroup().size(); gs++)
       {
         Group grp = jm.getFeatureSettings().getGroup().get(gs);
-        fgtable.put(grp.getName(), new Boolean(grp.isDisplay()));
+        fgtable.put(grp.getName(), Boolean.valueOf(grp.isDisplay()));
       }
       // FeatureRendererSettings frs = new FeatureRendererSettings(renderOrder,
       // fgtable, featureColours, jms.getFeatureSettings().hasTransparency() ?
@@ -5703,8 +5545,8 @@ public class Jalview2XML
       SequenceI[] dsseqs = new SequenceI[dseqs.size()];
       dseqs.copyInto(dsseqs);
       ds = new jalview.datamodel.Alignment(dsseqs);
-//      debug("Jalview2XML Created new dataset " + vamsasSet.getDatasetId()
-//              + " for alignment " + System.identityHashCode(al));
+      debug("Created new dataset " + vamsasSet.getDatasetId()
+              + " for alignment " + System.identityHashCode(al));
       addDatasetRef(vamsasSet.getDatasetId(), ds);
     }
     // set the dataset for the newly imported alignment.