JAL-629 use JalviewStructureDisplayI in place of StructureViewerBase
authorJames Procter <j.procter@dundee.ac.uk>
Tue, 5 Sep 2023 16:03:02 +0000 (17:03 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Tue, 5 Sep 2023 16:03:02 +0000 (17:03 +0100)
src/jalview/api/structures/JalviewStructureDisplayI.java
src/jalview/gui/StructureViewerBase.java
src/jalview/project/Jalview2XML.java

index a1b92df..532e545 100644 (file)
  */
 package jalview.api.structures;
 
+import java.io.File;
+
 import jalview.api.AlignmentViewPanel;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.gui.AlignmentPanel;
+import jalview.gui.StructureViewer;
 import jalview.structures.models.AAStructureBindingModel;
 
 public interface JalviewStructureDisplayI
@@ -172,4 +176,20 @@ public interface JalviewStructureDisplayI
    */
   boolean hasViewerActionsMenu();
 
+  String getViewId();
+
+  StructureViewer.ViewerType getViewerType();
+
+  boolean isUsedforaligment(AlignmentViewPanel ap);
+
+  boolean isColouredByViewer();
+
+  int getHeight();
+
+  int getWidth();
+
+  int getY();
+
+  File saveSession();
+
 }
index 6ebbf89..ff615c8 100644 (file)
@@ -47,6 +47,7 @@ import javax.swing.event.MenuEvent;
 import javax.swing.event.MenuListener;
 
 import jalview.api.AlignmentViewPanel;
+import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.bin.Console;
 import jalview.datamodel.AlignmentI;
@@ -87,12 +88,20 @@ public abstract class StructureViewerBase extends GStructureViewer
     BySequence, ByChain, ChargeCysteine, ByViewer
   }
 
-  private static List<StructureViewerBase> svbs = new ArrayList<>();
+  /**
+   * Singleton list of all (open) instances of structureViewerBase
+   * TODO: JAL-3362 - review and adopt the swingJS-safe singleton pattern so each structure viewer base instance is kept to its own JalviewJS parent
+   */
+  private static List<JalviewStructureDisplayI> svbs = new ArrayList<>();
 
-  public static List<StructureViewerBase> getAllStructureViewerBases()
+  /**
+   * 
+   * @return list with all existing StructureViewers instance
+   */
+  public static List<JalviewStructureDisplayI> getAllStructureViewerBases()
   {
-    List<StructureViewerBase> goodSvbs = new ArrayList<>();
-    for (StructureViewerBase s : svbs)
+    List<JalviewStructureDisplayI> goodSvbs = new ArrayList<>();
+    for (JalviewStructureDisplayI s : svbs)
     {
       if (s != null && !goodSvbs.contains(s))
       {
@@ -196,6 +205,7 @@ public abstract class StructureViewerBase extends GStructureViewer
     return _aps.contains(ap2.av.getSequenceSetId());
   }
 
+  @Override
   public boolean isUsedforaligment(AlignmentViewPanel ap2)
   {
 
index 9499acd..af3b2c8 100644 (file)
@@ -1140,7 +1140,7 @@ public class Jalview2XML
            * only view *should* be coped with sensibly.
            */
           // This must have been loaded, is it still visible?
-          List<StructureViewerBase> viewFrames = new ArrayList<>();
+          List<JalviewStructureDisplayI> viewFrames = new ArrayList<>();
           if (Desktop.desktop != null)
           {
             JInternalFrame[] jifs = Desktop.desktop.getAllFrames();
@@ -1148,9 +1148,9 @@ public class Jalview2XML
             {
               for (JInternalFrame jif : jifs)
               {
-                if (jif instanceof StructureViewerBase)
+                if (jif instanceof JalviewStructureDisplayI)
                 {
-                  viewFrames.add((StructureViewerBase) jif);
+                  viewFrames.add((JalviewStructureDisplayI) jif);
                 }
               }
             }
@@ -1163,7 +1163,7 @@ public class Jalview2XML
           }
 
           String matchedFile = null;
-          for (StructureViewerBase viewFrame : viewFrames)
+          for (JalviewStructureDisplayI viewFrame : viewFrames)
           {
             matchedFile = saveStructureViewer(ap, jds, pdb, entry, viewIds,
                     matchedFile, viewFrame);
@@ -2165,7 +2165,7 @@ public class Jalview2XML
    */
   protected String saveStructureViewer(AlignmentPanel ap, SequenceI jds,
           Pdbids pdb, PDBEntry entry, List<String> viewIds,
-          String matchedFile, StructureViewerBase viewFrame)
+          String matchedFile, JalviewStructureDisplayI viewFrame)
   {
     final AAStructureBindingModel bindingModel = viewFrame.getBinding();
 
@@ -2210,7 +2210,7 @@ public class Jalview2XML
         {
           StructureState state = new StructureState();
           state.setVisible(true);
-          state.setXpos(viewFrame.getX());
+          state.setXpos(viewFrame.getY());
           state.setYpos(viewFrame.getY());
           state.setWidth(viewFrame.getWidth());
           state.setHeight(viewFrame.getHeight());