JAL-3253 temporary branch SwingJS upgrade with testNG fixes Java 8
[jalview.git] / src / jalview / project / Jalview2XML.java
index 0291a0a..2c93ee5 100644 (file)
@@ -35,6 +35,7 @@ import jalview.api.analysis.ScoreModelI;
 import jalview.api.analysis.SimilarityParamsI;
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
+import jalview.bin.Jalview;
 import jalview.datamodel.AlignedCodonFrame;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
@@ -150,6 +151,7 @@ import jalview.xml.binding.jalview.ThresholdType;
 import jalview.xml.binding.jalview.VAMSAS;
 
 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.Rectangle;
 import java.io.BufferedReader;
@@ -160,6 +162,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
@@ -187,7 +190,6 @@ import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
 
 import javax.swing.JInternalFrame;
-import javax.swing.SwingUtilities;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.Marshaller;
@@ -265,6 +267,25 @@ public class Jalview2XML
   private Map<RnaModel, String> rnaSessions = new HashMap<>();
 
   /**
+   * contains last error message (if any) encountered by XML loader.
+   */
+  String errorMessage = null;
+
+  /**
+   * flag to control whether the Jalview2XML_V1 parser should be deferred to if
+   * exceptions are raised during project XML parsing
+   */
+  public boolean attemptversion1parse = false;
+
+  /*
+   * JalviewJS only -- to allow read file bytes to be saved in the
+   * created AlignFrame, allowing File | Reload of a project file to work
+   * 
+   * BH 2019 JAL-3436
+   */
+  private File jarFile;
+
+  /**
    * A helper method for safely using the value of an optional attribute that
    * may be null if not present in the XML. Answers the boolean value, or false
    * if null.
@@ -424,7 +445,7 @@ public class Jalview2XML
    * @param _jmap
    * @return
    */
-  public SeqFref newMappingRef(final String sref,
+  protected SeqFref newMappingRef(final String sref,
           final jalview.datamodel.Mapping _jmap)
   {
     SeqFref fref = new SeqFref(sref, "Mapping")
@@ -446,7 +467,7 @@ public class Jalview2XML
     return fref;
   }
 
-  public SeqFref newAlcodMapRef(final String sref,
+  protected SeqFref newAlcodMapRef(final String sref,
           final AlignedCodonFrame _cf,
           final jalview.datamodel.Mapping _jmap)
   {
@@ -478,7 +499,7 @@ public class Jalview2XML
     return fref;
   }
 
-  public void resolveFrefedSequences()
+  protected void resolveFrefedSequences()
   {
     Iterator<SeqFref> nextFref = frefedSequence.iterator();
     int toresolve = frefedSequence.size();
@@ -846,7 +867,7 @@ public class Jalview2XML
    * @param out
    *          jar entry name
    */
-  public JalviewModel saveState(AlignmentPanel ap, String fileName,
+  protected JalviewModel saveState(AlignmentPanel ap, String fileName,
           JarOutputStream jout, List<String> viewIds)
   {
     return saveState(ap, fileName, false, jout, viewIds);
@@ -868,7 +889,7 @@ public class Jalview2XML
    * @param out
    *          jar entry name
    */
-  public JalviewModel saveState(AlignmentPanel ap, String fileName,
+  protected JalviewModel saveState(AlignmentPanel ap, String fileName,
           boolean storeDS, JarOutputStream jout, List<String> viewIds)
   {
     if (viewIds == null)
@@ -2730,17 +2751,6 @@ public class Jalview2XML
   }
 
   /**
-   * contains last error message (if any) encountered by XML loader.
-   */
-  String errorMessage = null;
-
-  /**
-   * flag to control whether the Jalview2XML_V1 parser should be deferred to if
-   * exceptions are raised during project XML parsing
-   */
-  public boolean attemptversion1parse = false;
-
-  /**
    * Load a jalview project archive from a jar file
    * 
    * @param file
@@ -2774,8 +2784,9 @@ public class Jalview2XML
     {
       try
       {
+
          // BH 2019 -- can't wait
-        SwingUtilities.invokeLater(new Runnable()
+        Jalview.execRunnable(new Runnable()
         {
           @Override
           public void run()
@@ -2788,55 +2799,55 @@ public class Jalview2XML
         System.err.println("Error loading alignment: " + x.getMessage());
       }
     }
+    this.jarFile = null;
     return af;
   }
 
        @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());
+  private jarInputStreamProvider createjarInputStreamProvider(
+          final Object ofile) throws MalformedURLException
+  {
+    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;
-               }
-       }
+      if (bytes != null)
+      {
+        this.jarFile = (File) ofile;
+      }
+      errorMessage = null;
+      uniqueSetSuffix = null;
+      seqRefIds = null;
+      viewportsAdded.clear();
+      frefedSequence = null;
+
+      URL url = file.startsWith("http://") ? new URL(file) : null;
+      return new jarInputStreamProvider()
+      {
+        @Override
+        public JarInputStream getJarInputStream() throws IOException
+        {
+          InputStream is = bytes != null ? new ByteArrayInputStream(bytes)
+                  : (url != null ? url.openStream()
+                          : new FileInputStream(file));
+          return new JarInputStream(is);
+        }
+
+        @Override
+        public String getFilename()
+        {
+          return file;
+        }
+      };
+    } catch (IOException e)
+    {
+      e.printStackTrace();
+      return null;
+    }
+  }
 
   /**
    * Recover jalview session from a jalview project archive. Caller may
@@ -2862,12 +2873,16 @@ 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);
@@ -2879,9 +2894,14 @@ 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"))
         {
 
+          // 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
@@ -2911,8 +2931,14 @@ public class Jalview2XML
             _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)
             {
+
               // That is, this is one of the AlignmentPanel models
               if (af == null)
               {
@@ -2979,6 +3005,13 @@ 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);
+      }
+
     }
 
     /*
@@ -2998,7 +3031,7 @@ public class Jalview2XML
     {
       if (ds.getCodonFrames() != null)
       {
-        Desktop.getInstance().getStructureSelectionManager()
+        Desktop.getStructureSelectionManager()
                 .registerMappings(ds.getCodonFrames());
       }
     }
@@ -3322,16 +3355,16 @@ public class Jalview2XML
    *          data source provider
    * @return alignment frame created from view stored in DOM
    */
-  AlignFrame loadFromObject(JalviewModel jalviewModel, String file,
+  private AlignFrame loadFromObject(JalviewModel jalviewModel, String file,
           boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
   {
 
-//    Platform.timeCheck("Jalview2XML.loadFromObject0", Platform.TIME_MARK);
+    // Platform.timeCheck("Jalview2XML.loadFromObject0", Platform.TIME_MARK);
 
-    SequenceSet vamsasSet = jalviewModel.getVamsasModel().getSequenceSet().get(0);
+    SequenceSet vamsasSet = jalviewModel.getVamsasModel().getSequenceSet()
+            .get(0);
     List<Sequence> vamsasSeqs = vamsasSet.getSequence();
 
-
     // JalviewModelSequence jms = object.getJalviewModelSequence();
 
     // Viewport view = (jms.getViewportCount() > 0) ? jms.getViewport(0)
@@ -3362,7 +3395,7 @@ public class Jalview2XML
               : view.getId() + uniqueSetSuffix);
     }
 
-//    Platform.timeCheck("Jalview2XML.loadFromObject1", Platform.TIME_MARK);
+    // Platform.timeCheck("Jalview2XML.loadFromObject1", Platform.TIME_MARK);
     // ////////////////////////////////
     // LOAD SEQUENCES
 
@@ -3448,8 +3481,8 @@ public class Jalview2XML
       }
     }
 
-//    Platform.timeCheck("Jalview2XML.loadFromObject-seq",
-//            Platform.TIME_MARK);
+    // Platform.timeCheck("Jalview2XML.loadFromObject-seq",
+    // Platform.TIME_MARK);
     // /
     // Create the alignment object from the sequence set
     // ///////////////////////////////
@@ -3490,8 +3523,8 @@ public class Jalview2XML
       recoverDatasetFor(vamsasSet, al, isdsal, uniqueSeqSetId);
     }
 
-//    Platform.timeCheck("Jalview2XML.loadFromObject-align",
-//            Platform.TIME_MARK);
+    // Platform.timeCheck("Jalview2XML.loadFromObject-align",
+    // Platform.TIME_MARK);
     if (referenceseqForView != null)
     {
       al.setSeqrep(referenceseqForView);
@@ -3504,8 +3537,8 @@ public class Jalview2XML
       al.setProperty(ssp.getKey(), ssp.getValue());
     }
 
-//    Platform.timeCheck("Jalview2XML.loadFromObject-setseqprop",
-//            Platform.TIME_MARK);
+    // Platform.timeCheck("Jalview2XML.loadFromObject-setseqprop",
+    // Platform.TIME_MARK);
     // ///////////////////////////////
 
     Hashtable pdbloaded = new Hashtable(); // TODO nothing writes to this??
@@ -3519,7 +3552,7 @@ 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_MARK);
+      // Platform.timeCheck("J2XML features0", Platform.TIME_RESET);
       for (int i = 0; i < vamsasSeqs.size(); i++)
       {
         JSeq jseq = jseqs.get(i);
@@ -3574,11 +3607,11 @@ 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);
           }
         }
-        Platform.timeCheck("J2XML features done", Platform.TIME_MARK);
-
         if (vamsasSeqs.get(i).getDBRef().size() > 0)
         {
           // adds dbrefs to datasequence's set (since Jalview 2.10)
@@ -3636,8 +3669,7 @@ public class Jalview2XML
             {
               entry.setProperty(prop.getName(), prop.getValue());
             }
-            Desktop.getInstance().getStructureSelectionManager()
-                    .registerPDBEntry(entry);
+            Desktop.getStructureSelectionManager().registerPDBEntry(entry);
             // adds PDBEntry to datasequence's set (since Jalview 2.10)
             if (al.getSequenceAt(i).getDatasetSequence() != null)
             {
@@ -3649,9 +3681,12 @@ public class Jalview2XML
             }
           }
         }
+
       }
-//      Platform.timeCheck("Jalview2XML.loadFromObject-endmultiview",
-//              Platform.TIME_MARK);
+
+      // Platform.timeCheck("features done", Platform.TIME_GET);
+      // Platform.timeCheck("Jalview2XML.loadFromObject-endmultiview",
+      // Platform.TIME_MARK);
     } // end !multipleview
 
     // ///////////////////////////////
@@ -3685,16 +3720,16 @@ public class Jalview2XML
               else
               {
                 // defer to later
-                frefedSequence.add(
-                        newAlcodMapRef(map.getDnasq(), cf, mapping));
+                frefedSequence
+                        .add(newAlcodMapRef(map.getDnasq(), cf, mapping));
               }
             }
           }
           al.addCodonFrame(cf);
         }
       }
-//      Platform.timeCheck("Jalview2XML.loadFromObject-seqmap",
-//              Platform.TIME_MARK);
+      // Platform.timeCheck("Jalview2XML.loadFromObject-seqmap",
+      // Platform.TIME_MARK);
     }
 
     // ////////////////////////////////
@@ -3755,8 +3790,8 @@ public class Jalview2XML
         }
         // Construct new annotation from model.
         List<AnnotationElement> ae = annotation.getAnnotationElement();
-//        System.err.println(
-//                "Jalview2XML processing " + ae.size() + " annotations");
+        // System.err.println(
+        // "Jalview2XML processing " + ae.size() + " annotations");
 
         jalview.datamodel.Annotation[] anot = null;
         java.awt.Color firstColour = null;
@@ -3901,8 +3936,7 @@ public class Jalview2XML
         jaa.setCalcId(annotation.getCalcId());
         if (annotation.getProperty().size() > 0)
         {
-          for (Annotation.Property prop : annotation
-                  .getProperty())
+          for (Annotation.Property prop : annotation.getProperty())
           {
             jaa.setProperty(prop.getName(), prop.getValue());
           }
@@ -3919,8 +3953,8 @@ public class Jalview2XML
           al.addAnnotation(jaa);
         }
       }
-//      Platform.timeCheck("Jalview2XML.loadFromObject-annot",
-//              Platform.TIME_MARK);
+      // Platform.timeCheck("Jalview2XML.loadFromObject-annot",
+      // Platform.TIME_MARK);
     }
     // ///////////////////////
     // LOAD GROUPS
@@ -3985,9 +4019,9 @@ public class Jalview2XML
         sg.setShowNonconserved(safeBoolean(jGroup.isShowUnconserved()));
         sg.thresholdTextColour = safeInt(jGroup.getTextColThreshold());
         // attributes with a default in the schema are never null
-          sg.setShowConsensusHistogram(jGroup.isShowConsensusHistogram());
-          sg.setshowSequenceLogo(jGroup.isShowSequenceLogo());
-          sg.setNormaliseSequenceLogo(jGroup.isNormaliseSequenceLogo());
+        sg.setShowConsensusHistogram(jGroup.isShowConsensusHistogram());
+        sg.setshowSequenceLogo(jGroup.isShowSequenceLogo());
+        sg.setNormaliseSequenceLogo(jGroup.isNormaliseSequenceLogo());
         sg.setIgnoreGapsConsensus(jGroup.isIgnoreGapsinConsensus());
         if (jGroup.getConsThreshold() != null
                 && jGroup.getConsThreshold().intValue() != 0)
@@ -4031,12 +4065,13 @@ public class Jalview2XML
         if (addAnnotSchemeGroup)
         {
           // reconstruct the annotation colourscheme
-          sg.setColourScheme(constructAnnotationColour(
-                  jGroup.getAnnotationColours(), null, al, jalviewModel, false));
+          sg.setColourScheme(
+                  constructAnnotationColour(jGroup.getAnnotationColours(),
+                          null, al, jalviewModel, false));
         }
       }
-//      Platform.timeCheck("Jalview2XML.loadFromObject-groups",
-//              Platform.TIME_MARK);
+      // Platform.timeCheck("Jalview2XML.loadFromObject-groups",
+      // Platform.TIME_MARK);
     }
     if (view == null)
     {
@@ -4076,8 +4111,8 @@ public class Jalview2XML
         }
 
       }
-//      Platform.timeCheck("Jalview2XML.loadFromObject-viewport",
-//              Platform.TIME_MARK);
+      // Platform.timeCheck("Jalview2XML.loadFromObject-viewport",
+      // Platform.TIME_MARK);
     }
     /**
      * indicate that annotation colours are applied across all groups (pre
@@ -4130,47 +4165,47 @@ public class Jalview2XML
     final AlignFrame af0 = af;
     final AlignViewport av0 = av;
     final AlignmentPanel ap0 = ap;
-//    Platform.timeCheck("Jalview2XML.loadFromObject-beforetree",
-//            Platform.TIME_MARK);
+    // Platform.timeCheck("Jalview2XML.loadFromObject-beforetree",
+    // Platform.TIME_MARK);
     if (loadTreesAndStructures)
     {
       if (!jalviewModel.getTree().isEmpty())
       {
-        SwingUtilities.invokeLater(new Runnable()
+        Jalview.execRunnable(new Runnable()
         {
           @Override
           public void run()
           {
-//            Platform.timeCheck(null, Platform.TIME_MARK);
+            // Platform.timeCheck(null, Platform.TIME_MARK);
             loadTrees(jalviewModel, view, af0, av0, ap0);
-//            Platform.timeCheck("Jalview2XML.loadTrees", Platform.TIME_MARK);
+            // Platform.timeCheck("Jalview2XML.loadTrees", Platform.TIME_MARK);
           }
         });
       }
       if (!jalviewModel.getPcaViewer().isEmpty())
       {
-        SwingUtilities.invokeLater(new Runnable()
+        Jalview.execRunnable(new Runnable()
         {
           @Override
           public void run()
           {
-//            Platform.timeCheck(null, Platform.TIME_MARK);
+            // Platform.timeCheck(null, Platform.TIME_MARK);
             loadPCAViewers(jalviewModel, ap0);
-//            Platform.timeCheck("Jalview2XML.loadPCA", Platform.TIME_MARK);
+            // Platform.timeCheck("Jalview2XML.loadPCA", Platform.TIME_MARK);
           }
         });
       }
-      SwingUtilities.invokeLater(new Runnable()
+      Jalview.execRunnable(new Runnable()
       {
         @Override
         public void run()
         {
-//          Platform.timeCheck(null, Platform.TIME_MARK);
+          // Platform.timeCheck(null, Platform.TIME_MARK);
           loadPDBStructures(jprovider, jseqs, af0, ap0);
-//          Platform.timeCheck("Jalview2XML.loadPDB", Platform.TIME_MARK);
+          // Platform.timeCheck("Jalview2XML.loadPDB", Platform.TIME_MARK);
         }
       });
-      SwingUtilities.invokeLater(new Runnable()
+      Jalview.execRunnable(new Runnable()
       {
         @Override
         public void run()
@@ -4178,8 +4213,11 @@ public class Jalview2XML
           loadRnaViewers(jprovider, jseqs, ap0);
         }
       });
+
     }
     // and finally return.
+    // but do not set holdRepaint true just yet, because this could be the
+    // initial frame with just its dataset.
     return af;
   }
 
@@ -4736,7 +4774,7 @@ public class Jalview2XML
             svattrib.getWidth(), svattrib.getHeight());
     // try
     // {
-      javax.swing.SwingUtilities.invokeLater(new Runnable()
+    Jalview.execRunnable(new Runnable()
       {
         @Override
         public void run()
@@ -4762,7 +4800,8 @@ public class Jalview2XML
             }
           }
         }
-      });
+    });
+    // javax.swing.SwingUtilities.invokeLater(r);
     // } catch (InvocationTargetException ex)
     // {
     // warn("Unexpected error when opening Jmol view.", ex);
@@ -4969,27 +5008,28 @@ public class Jalview2XML
     }
   }
 
-  AlignFrame loadViewport(String file, List<JSeq> JSEQ,
-          List<SequenceI> hiddenSeqs, AlignmentI al,
-          JalviewModel jm, Viewport view, String uniqueSeqSetId,
-          String viewId, List<JvAnnotRow> autoAlan)
+  AlignFrame loadViewport(String fileName, List<JSeq> JSEQ,
+          List<SequenceI> hiddenSeqs, AlignmentI al, JalviewModel jm,
+          Viewport view, String uniqueSeqSetId, String viewId,
+          List<JvAnnotRow> autoAlan)
   {
     AlignFrame af = null;
     af = new AlignFrame(al, safeInt(view.getWidth()),
-            safeInt(view.getHeight()), uniqueSeqSetId, viewId) 
-//    {
-//     
-//     @Override
-//     protected void processKeyEvent(java.awt.event.KeyEvent e) {
-//             System.out.println("Jalview2XML   AF " + e);
-//             super.processKeyEvent(e);
-//             
-//     }
-//     
-//    }
+            safeInt(view.getHeight()), uniqueSeqSetId, viewId)
+    // {
+    //
+    // @Override
+    // protected void processKeyEvent(java.awt.event.KeyEvent e) {
+    // System.out.println("Jalview2XML AF " + e);
+    // super.processKeyEvent(e);
+    //
+    // }
+    //
+    // }
     ;
-
-    af.setFileName(file, FileFormat.Jalview);
+    af.alignPanel.setHoldRepaint(true);
+    af.setFileName(fileName, FileFormat.Jalview);
+    af.setFileObject(jarFile); // BH 2019 JAL-3436
 
     final AlignViewport viewport = af.getViewport();
     for (int i = 0; i < JSEQ.size(); i++)
@@ -5064,9 +5104,8 @@ public class Jalview2XML
 
     viewport.setColourText(safeBoolean(view.isShowColourText()));
 
-    viewport
-            .setConservationSelected(
-                    safeBoolean(view.isConservationSelected()));
+    viewport.setConservationSelected(
+            safeBoolean(view.isConservationSelected()));
     viewport.setIncrement(safeInt(view.getConsThreshold()));
     viewport.setShowJVSuffix(safeBoolean(view.isShowFullId()));
     viewport.setRightAlignIds(safeBoolean(view.isRightAlignIds()));
@@ -5152,9 +5191,8 @@ public class Jalview2XML
     af.changeColour(cs);
     viewport.setColourAppliesToAllGroups(true);
 
-    viewport
-            .setShowSequenceFeatures(
-                    safeBoolean(view.isShowSequenceFeatures()));
+    viewport.setShowSequenceFeatures(
+            safeBoolean(view.isShowSequenceFeatures()));
 
     viewport.setCentreColumnLabels(view.isCentreColumnLabels());
     viewport.setIgnoreGapsConsensus(view.isIgnoreGapsinConsensus(), null);
@@ -5175,13 +5213,13 @@ public class Jalview2XML
               .getFeatureRenderer();
       FeaturesDisplayed fdi;
       viewport.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
-      String[] renderOrder = new String[jm.getFeatureSettings()
-              .getSetting().size()];
+      String[] renderOrder = new String[jm.getFeatureSettings().getSetting()
+              .size()];
       Map<String, FeatureColourI> featureColours = new Hashtable<>();
       Map<String, Float> featureOrder = new Hashtable<>();
 
-      for (int fs = 0; fs < jm.getFeatureSettings()
-              .getSetting().size(); fs++)
+      for (int fs = 0; fs < jm.getFeatureSettings().getSetting()
+              .size(); fs++)
       {
         Setting setting = jm.getFeatureSettings().getSetting().get(fs);
         String featureType = setting.getType();
@@ -5193,8 +5231,8 @@ public class Jalview2XML
                 .getMatcherSet();
         if (filters != null)
         {
-          FeatureMatcherSetI filter = Jalview2XML
-                  .parseFilter(featureType, filters);
+          FeatureMatcherSetI filter = Jalview2XML.parseFilter(featureType,
+                  filters);
           if (!filter.isEmpty())
           {
             fr.setFeatureFilter(featureType, filter);
@@ -5226,8 +5264,7 @@ public class Jalview2XML
           float max = setting.getMax() == null ? 1f
                   : setting.getMax().floatValue();
           FeatureColourI gc = new FeatureColour(maxColour, minColour,
-                  maxColour,
-                  noValueColour, min, max);
+                  maxColour, noValueColour, min, max);
           if (setting.getAttributeName().size() > 0)
           {
             gc.setAttributeName(setting.getAttributeName().toArray(
@@ -5261,8 +5298,7 @@ public class Jalview2XML
         }
         else
         {
-          featureColours.put(featureType,
-                  new FeatureColour(maxColour));
+          featureColours.put(featureType, new FeatureColour(maxColour));
         }
         renderOrder[fs] = featureType;
         if (setting.getOrder() != null)
@@ -5330,8 +5366,9 @@ public class Jalview2XML
     String complementaryViewId = view.getComplementId();
     if (complementaryViewId == null)
     {
-      Desktop.addInternalFrame(af, view.getTitle(),
+      Dimension dim = Platform.getDimIfEmbedded(af,
               safeInt(view.getWidth()), safeInt(view.getHeight()));
+      Desktop.addInternalFrame(af, view.getTitle(), dim.width, dim.height);
       // recompute any autoannotation
       af.alignPanel.updateAnnotation(false, true);
       reorderAutoannotation(af, al, autoAlan);
@@ -5598,7 +5635,7 @@ public class Jalview2XML
     return false;
   }
 
-  public void addToSkipList(AlignFrame af)
+  protected void addToSkipList(AlignFrame af)
   {
     if (skipList == null)
     {
@@ -5607,7 +5644,7 @@ public class Jalview2XML
     skipList.put(af.getViewport().getSequenceSetId(), af);
   }
 
-  public void clearSkipList()
+  protected void clearSkipList()
   {
     if (skipList != null)
     {
@@ -5676,8 +5713,8 @@ public class Jalview2XML
       SequenceI[] dsseqs = new SequenceI[dseqs.size()];
       dseqs.copyInto(dsseqs);
       ds = new jalview.datamodel.Alignment(dsseqs);
-      debug("Created new dataset " + vamsasSet.getDatasetId()
-              + " for alignment " + System.identityHashCode(al));
+//      debug("Jalview2XML Created new dataset " + vamsasSet.getDatasetId()
+//              + " for alignment " + System.identityHashCode(al));
       addDatasetRef(vamsasSet.getDatasetId(), ds);
     }
     // set the dataset for the newly imported alignment.
@@ -6091,14 +6128,8 @@ public class Jalview2XML
     AlignFrame af = loadFromObject(jm, null, false, null);
     af.getAlignPanels().clear();
     af.closeMenuItem_actionPerformed(true);
-
-    /*
-     * if(ap.av.getAlignment().getAlignmentAnnotation()!=null) { for(int i=0;
-     * i<ap.av.getAlignment().getAlignmentAnnotation().length; i++) {
-     * if(!ap.av.getAlignment().getAlignmentAnnotation()[i].autoCalculated) {
-     * af.alignPanel.av.getAlignment().getAlignmentAnnotation()[i] =
-     * ap.av.getAlignment().getAlignmentAnnotation()[i]; } } }
-     */
+    af.alignPanel.setHoldRepaint(false);
+    this.jarFile = null;
 
     return af.alignPanel;
   }
@@ -6449,8 +6480,10 @@ public class Jalview2XML
                   axis.getXPos(), axis.getYPos(), axis.getZPos());
         }
 
+        Dimension dim = Platform.getDimIfEmbedded(panel, 475, 450);
         Desktop.addInternalFrame(panel, MessageManager.formatMessage(
-                "label.calc_title", "PCA", modelName), 475, 450);
+                "label.calc_title", "PCA", modelName), dim.width,
+                dim.height);
       }
     } catch (Exception ex)
     {