JAL-2944 allow StructureViewer proxy to be created for an existing view in order...
authorJim Procter <jprocter@issues.jalview.org>
Thu, 5 Apr 2018 13:26:26 +0000 (14:26 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 5 Apr 2018 13:26:26 +0000 (14:26 +0100)
src/jalview/gui/StructureViewer.java

index f37df71..8b501ad 100644 (file)
@@ -64,6 +64,17 @@ public class StructureViewer
     ssm = structureSelectionManager;
   }
 
+  /**
+   * Factory to create a proxy for modifying existing structure viewer
+   * 
+   */
+  public static StructureViewer reconfigure(
+          JalviewStructureDisplayI display)
+  {
+    StructureViewer sv = new StructureViewer(display.getBinding().getSsm());
+    sv.sview = display;
+    return sv;
+  }
   public ViewerType getViewerType()
   {
     String viewType = Cache.getDefault(Preferences.STRUCTURE_DISPLAY,
@@ -104,6 +115,30 @@ public class StructureViewer
             new PDBEntry[seqsForPdbs.size()]);
     SequenceI[][] theSeqs = seqsForPdbs.values().toArray(
             new SequenceI[seqsForPdbs.size()][]);
+    if (sview != null)
+    {
+      new Thread(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+
+          for (int pdbep = 0; pdbep < pdbsForFile.length; pdbep++)
+          {
+            PDBEntry pdb = pdbsForFile[pdbep];
+            if (!sview.addAlreadyLoadedFile(theSeqs[pdbep], null, ap,
+                    pdb.getId()))
+            {
+              sview.addToExistingViewer(pdb, theSeqs[pdbep], null, ap,
+                      pdb.getId());
+            }
+          }
+
+          sview.updateTitleAndMenus();
+        }
+      }).start();
+      return sview;
+    }
 
     if (viewerType.equals(ViewerType.JMOL))
     {
@@ -232,6 +267,15 @@ public class StructureViewer
   public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
           SequenceI[] seqsForPdb, AlignmentPanel ap)
   {
+    if (sview != null)
+    {
+      if (!sview.addAlreadyLoadedFile(seqsForPdb, null, ap, pdb.getId()))
+      {
+        sview.addToExistingViewer(pdb, seqsForPdb, null, ap, pdb.getId());
+      }
+      sview.updateTitleAndMenus();
+      return sview;
+    }
     ViewerType viewerType = getViewerType();
     if (viewerType.equals(ViewerType.JMOL))
     {