JAL-1894 update year/version in copyright
[jalview.git] / src / jalview / gui / StructureViewer.java
index 8ff4c70..9a13b5e 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -28,6 +28,8 @@ import jalview.datamodel.StructureViewerModel;
 import jalview.structure.StructureSelectionManager;
 
 import java.awt.Rectangle;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * proxy for handling structure viewers.
@@ -64,23 +66,84 @@ public class StructureViewer
     ssm = structureSelectionManager;
   }
 
-  public JalviewStructureDisplayI viewStructures(AlignmentPanel ap,
-          PDBEntry[] pr, SequenceI[][] collateForPDB)
+  /**
+   * View multiple PDB entries, each with associated sequences
+   * 
+   * @param pdbs
+   * @param seqsForPdbs
+   * @param ap
+   * @return
+   */
+  public JalviewStructureDisplayI viewStructures(PDBEntry[] pdbs,
+          SequenceI[][] seqsForPdbs, AlignmentPanel ap)
   {
-    return viewStructures(getViewerType(), ap, pr, collateForPDB);
+    JalviewStructureDisplayI viewer = onlyOnePdb(pdbs, seqsForPdbs, ap);
+    if (viewer != null)
+    {
+      return viewer;
+    }
+    return viewStructures(getViewerType(), pdbs, seqsForPdbs, ap);
   }
 
-  public JalviewStructureDisplayI viewStructures(ViewerType viewerType,
-          AlignmentPanel ap, PDBEntry[] pr, SequenceI[][] collateForPDB)
+  /**
+   * A strictly temporary method pending JAL-1761 refactoring. Determines if all
+   * the passed PDB entries are the same (this is the case if selected sequences
+   * to view structure for are chains of the same structure). If so, calls the
+   * single-pdb version of viewStructures and returns the viewer, else returns
+   * null.
+   * 
+   * @param pdbs
+   * @param seqsForPdbs
+   * @param ap
+   * @return
+   */
+  private JalviewStructureDisplayI onlyOnePdb(PDBEntry[] pdbs,
+          SequenceI[][] seqsForPdbs, AlignmentPanel ap)
+  {
+    List<SequenceI> seqs = new ArrayList<SequenceI>();
+    if (pdbs == null || pdbs.length == 0)
+    {
+      return null;
+    }
+    int i = 0;
+    String firstFile = pdbs[0].getFile();
+    for (PDBEntry pdb : pdbs)
+    {
+      String pdbFile = pdb.getFile();
+      if (pdbFile == null || !pdbFile.equals(firstFile))
+      {
+        return null;
+      }
+      SequenceI[] pdbseqs = seqsForPdbs[i++];
+      if (pdbseqs != null)
+      {
+        for (SequenceI sq : pdbseqs)
+        {
+          seqs.add(sq);
+        }
+      }
+    }
+    return viewStructures(pdbs[0],
+            seqs.toArray(new SequenceI[seqs.size()]), ap);
+  }
+
+  public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
+          SequenceI[] seqsForPdb, AlignmentPanel ap)
+  {
+    return viewStructures(getViewerType(), pdb, seqsForPdb, ap);
+  }
+
+  protected JalviewStructureDisplayI viewStructures(ViewerType viewerType,
+          PDBEntry[] pdbs, SequenceI[][] seqsForPdbs, AlignmentPanel ap)
   {
     JalviewStructureDisplayI sview = null;
     if (viewerType.equals(ViewerType.JMOL))
     {
-      sview = new AppJmol(ap, pr, ap.av.collateForPDB(pr));
+      sview = new AppJmol(ap, pdbs, ap.av.collateForPDB(pdbs));
     }
     else if (viewerType.equals(ViewerType.CHIMERA))
     {
-      sview = new ChimeraViewFrame(ap, pr, ap.av.collateForPDB(pr));
+      sview = new ChimeraViewFrame(pdbs, ap.av.collateForPDB(pdbs), ap);
     }
     else
     {
@@ -90,17 +153,17 @@ public class StructureViewer
     return sview;
   }
 
-  public JalviewStructureDisplayI viewStructures(ViewerType viewerType,
-          AlignmentPanel ap, PDBEntry pr, SequenceI[] collateForPDB)
+  protected JalviewStructureDisplayI viewStructures(ViewerType viewerType,
+          PDBEntry pdb, SequenceI[] seqsForPdb, AlignmentPanel ap)
   {
     JalviewStructureDisplayI sview = null;
     if (viewerType.equals(ViewerType.JMOL))
     {
-      sview = new AppJmol(pr, collateForPDB, null, ap);
+      sview = new AppJmol(pdb, seqsForPdb, null, ap);
     }
     else if (viewerType.equals(ViewerType.CHIMERA))
     {
-      sview = new ChimeraViewFrame(pr, collateForPDB, null, ap);
+      sview = new ChimeraViewFrame(pdb, seqsForPdb, null, ap);
     }
     else
     {
@@ -110,12 +173,6 @@ public class StructureViewer
     return sview;
   }
 
-  public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
-          SequenceI[] sequenceIs, Object object, AlignmentPanel ap)
-  {
-    return viewStructures(getViewerType(), ap, pdb, sequenceIs);
-  }
-
   /**
    * Create a new panel controlling a structure viewer.
    * 
@@ -132,8 +189,8 @@ public class StructureViewer
    */
   public JalviewStructureDisplayI createView(ViewerType type,
           String[] pdbf, String[] id, SequenceI[][] sq,
-          AlignmentPanel alignPanel, StructureViewerModel viewerData, String fileloc,
-          Rectangle rect, String vid)
+          AlignmentPanel alignPanel, StructureViewerModel viewerData,
+          String fileloc, Rectangle rect, String vid)
   {
     final boolean useinViewerSuperpos = viewerData.isAlignWithPanel();
     final boolean usetoColourbyseq = viewerData.isColourWithAlignPanel();