notes re JAL-623 and JAL-583, new api methods for adding several structure/seq mappin...
[jalview.git] / src / jalview / bin / JalviewLite.java
index 0e77f02..7bf1a5f 100755 (executable)
@@ -19,6 +19,7 @@ package jalview.bin;
 
 import jalview.api.SequenceStructureBinding;
 import jalview.appletgui.AlignFrame;
+import jalview.appletgui.AppletJmol;
 import jalview.appletgui.EmbmenuFrame;
 import jalview.appletgui.FeatureSettings;
 import jalview.datamodel.Alignment;
@@ -34,6 +35,7 @@ import jalview.io.JnetAnnotationMaker;
 import java.applet.Applet;
 import java.awt.Button;
 import java.awt.Color;
+import java.awt.Component;
 import java.awt.Font;
 import java.awt.Frame;
 import java.awt.Graphics;
@@ -332,6 +334,8 @@ public class JalviewLite extends Applet
 
   public boolean jmolAvailable = false;
 
+  private boolean alignPdbStructures=false;
+
   public static boolean debug = false;
 
   static String builddate = null, version = null;
@@ -896,7 +900,11 @@ public class JalviewLite extends Applet
             ex.printStackTrace();
           }
         }
-
+        /*
+         * <param name="alignpdbfiles" value="false/true"/>
+         * Undocumented for 2.6 - related to JAL-434
+         */
+        applet.setAlignPdbStructures(getDefaultParameter("alignpdbfiles",false));
         /*
          * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
          * PDB|1GAQ|1GAQ|C">
@@ -905,8 +913,10 @@ public class JalviewLite extends Applet
          * 
          * <param name="PDBfile3" value="1q0o Q45135_9MICO">
          */
-
+        
         int pdbFileCount = 0;
+        // Accumulate pdbs here if they are heading for the same view (if alignPdbStructures is true)
+        Vector pdbs=new Vector();
         do
         {
           if (pdbFileCount > 0)
@@ -998,16 +1008,35 @@ public class JalviewLite extends Applet
                   }
                 }
               }
-
-              newAlignFrame.newStructureView(applet, pdb, seqs, chains,
+              
+              if (!alignPdbStructures) {
+                newAlignFrame.newStructureView(applet, pdb, seqs, chains,
                       protocol);
-
+              } else {
+                pdbs.add(new Object[] { pdb, seqs, chains, new String(protocol)});
+              }
             }
           }
 
           pdbFileCount++;
         } while (pdbFileCount < 10);
-
+        if (pdbs.size()>0)
+        {
+          SequenceI[][] seqs = new SequenceI[pdbs.size()][];
+          PDBEntry[] pdb = new PDBEntry[pdbs.size()];
+          String[][] chains = new String[pdbs.size()][];
+          String[] protocols = new String[pdbs.size()];
+          for (int pdbsi=0,pdbsiSize=pdbs.size(); pdbsi<pdbsiSize;pdbsi++)
+          {
+            Object[] o = (Object[]) pdbs.elementAt(pdbsi);
+            pdb[pdbsi] = (PDBEntry) o[0];
+            seqs[pdbsi] = (SequenceI[]) o[1];
+            chains[pdbsi] = (String[]) o[2];
+            protocols[pdbsi] = (String) o[3];
+          }
+          newAlignFrame.alignedStructureView(applet, pdb, seqs, chains, protocols);
+          
+        }
         // ///////////////////////////
         // modify display of features
         //
@@ -1325,6 +1354,37 @@ public class JalviewLite extends Applet
     return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
   }
 
+  protected void setAlignPdbStructures(boolean alignPdbStructures)
+  {
+    this.alignPdbStructures = alignPdbStructures;
+  }
+
+  public boolean isAlignPdbStructures()
+  {
+    return alignPdbStructures;
+  }
+
+  /**
+   * get all components associated with the applet of the given type 
+   * @param class1
+   * @return
+   */
+  public Vector getAppletWindow(Class class1)
+  {
+    Vector wnds = new Vector();
+    Component[] cmp = getComponents();
+    if (cmp!=null)
+    {
+    for (int i=0;i<cmp.length;i++)
+    {
+      if (class1.isAssignableFrom(cmp[i].getClass()))
+      {
+        wnds.addElement(cmp);
+      }
+    }}
+    return wnds;
+  }
+
 
   /**
    * bind structures in a viewer to any matching sequences in an alignFrame (use