excluded methods related to broken Jmol applet binding mechanism (JAL-621) and implem...
[jalview.git] / src / jalview / appletgui / AlignFrame.java
index 14606b7..adb0da5 100755 (executable)
@@ -21,6 +21,7 @@ import java.io.*;
 import java.net.*;
 import java.util.*;
 
+import java.applet.Applet;
 import java.awt.*;
 import java.awt.event.*;
 
@@ -3190,21 +3191,152 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }
   }
 
-  public SequenceStructureBinding addJmolInstance(JmolViewer viewer, String[] sequenceIds)
+  /**
+   * create a new binding between structures in an existing jmol viewer instance
+   * and an alignpanel with sequences that have existing PDBFile entries. Note,
+   * this does not open a new Jmol window, or modify the display of the
+   * structures in the original jmol window. Note
+   * 
+   * @param viewer JmolViewer instance
+   * @param sequenceIds
+   *          - sequence Ids to search for associations
+   * This method doesn't work. See http://issues.jalview.org/browse/JAL-621
+   * 
+  public SequenceStructureBinding addStructureViewInstance(Object jmolviewer, String[] sequenceIds)
   {
+    org.jmol.api.JmolViewer viewer=null;
+    try {
+      viewer = (org.jmol.api.JmolViewer) jmolviewer;
+    } 
+    catch (ClassCastException ex) {
+      System.err.println("Unsupported viewer object :"+jmolviewer.getClass());
+    }
+    if (viewer==null)
+    {
+      System.err.println("Can't use this object as a structure viewer:"+jmolviewer.getClass());
+      return null;
+    }
     SequenceI[] seqs=null;
     if (sequenceIds==null || sequenceIds.length==0)
     {
       seqs = viewport.getAlignment().getSequencesArray();
     } else {
-      // resolve seqs for sequenceIds.
+      Vector sqi=new Vector();
+      AlignmentI al = viewport.getAlignment();
+      for (int sid=0;sid<sequenceIds.length;sid++) {
+        SequenceI sq = al.findName(sequenceIds[sid]);
+        if (sq!=null) {
+          sqi.addElement(sq);
+        }
+      }
+      if (sqi.size()>0) {
+        seqs = new SequenceI[sqi.size()];
+        for (int sid=0,sSize=sqi.size();sid<sSize;sid++)
+        {
+          seqs[sid] = (SequenceI) sqi.elementAt(sid);
+        }
+      } else {
+        return null;
+      }
     }
-    if (// viewer is not mapped)
-            true){
-      AppletJmol jmv = new AppletJmol(viewer, alignPanel, seqs);
-      return jmv;
+    ExtJmol jmv=null;
+    // TODO: search for a jmv that involves viewer
+    if (jmv==null){
+      // create a new viewer/jalview binding.
+      jmv = new ExtJmol(viewer, alignPanel, seqs);
     }
-    return null;
+    return jmv;
     
   }
+  **/
+  public boolean addPdbFile(String sequenceId, String pdbEntryString,
+          String pdbFile)
+  {
+    SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId);
+    boolean needtoadd=false;
+    if (toaddpdb!=null)
+    {
+      Vector pdbe = toaddpdb.getPDBId();
+      PDBEntry pdbentry = null;
+      if (pdbe!=null && pdbe.size()>0)
+      {
+        for (int pe=0,peSize=pdbe.size(); pe<peSize; pe++)
+        {
+          pdbentry = (PDBEntry) pdbe.elementAt(pe);
+          if (!pdbentry.getId().equals(pdbEntryString) && !pdbentry.getFile().equals(pdbFile))
+          {
+            pdbentry = null;
+          }
+          else
+          {
+              continue;
+          }
+        }
+      }
+      if (pdbentry==null)
+      {
+        pdbentry = new PDBEntry();
+        pdbentry.setId(pdbEntryString);
+        pdbentry.setFile(pdbFile);
+        needtoadd=true; // add this new entry to sequence.
+      }
+      // resolve data source
+      // TODO: this code should be a refactored to an io package
+      String protocol = AppletFormatAdapter.resolveProtocol(pdbFile, "PDB");
+      if (protocol == null)
+      {
+        return false;
+      }
+      if (needtoadd)
+      {
+        // make a note of the access mode and add
+        pdbentry.getProperty().put("protocol", protocol);
+        toaddpdb.addPDBId(pdbentry);
+      }
+    }
+    return true;
+  }
+
+  public void newStructureView(JalviewLite applet, PDBEntry pdb, SequenceI[] seqs,
+          String[] chains, String protocol)
+  {
+    if (seqs!=null)
+    {
+      Vector sequences=new Vector();
+     for (int i=0;i<seqs.length;i++) {
+       if (seqs[i]!=null)
+       {
+         sequences.addElement(seqs[i]);
+       }
+     }
+     seqs = new SequenceI[sequences.size()];
+     for (int i=0,isize=sequences.size(); i<isize; i++)
+     {
+       seqs[i] = (SequenceI) sequences.elementAt(i);
+     }
+    }
+    if (seqs==null || seqs.length==0)
+    {
+      System.err.println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
+    }
+    if (protocol==null || protocol.trim().length()==0 || protocol.equals("null"))
+    {
+      protocol = (String) pdb.getProperty().get("protocol");
+      if (protocol==null)
+      {
+        System.err.println("Couldn't work out protocol to open structure: "+pdb.getId());
+        return;
+      }
+    }
+    if (applet.jmolAvailable)
+    {
+      new jalview.appletgui.AppletJmol(pdb, seqs, chains,
+              alignPanel, protocol);
+      applet.lastFrameX += 40;
+      applet.lastFrameY += 40;
+    }
+    else
+      new MCview.AppletPDBViewer(pdb, seqs, chains,
+              alignPanel, protocol);
+  }
 }