revised sequence/structure binding so one structure associated with x-seuqenceI's...
[jalview.git] / src / jalview / gui / AppJmol.java
index 6312cb1..df4efd9 100644 (file)
@@ -73,7 +73,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
     // / TODO: check if protocol is needed to be set, and if chains are
     // autodiscovered.
     jmb = new AppJmolBinding(this, new PDBEntry[]
-    { pdbentry }, seq, null, null);
+    { pdbentry }, new SequenceI[][] { seq }, null, null);
 
     jmb.setLoadingFromArchive(true);
     this.ap = ap;
@@ -141,7 +141,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
             {
               if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
               {
-                topJmol.jmb.addSequence(seq);
+                topJmol.jmb.addSequence(pe, seq);
                 break;
               }
             }
@@ -152,9 +152,33 @@ public class AppJmol extends GStructureViewer implements Runnable,
       }
     }
     // /////////////////////////////////
+    // Check if there are other Jmol views involving this alignment
+    // and prompt user about adding this molecule to one of them
+    Vector existingViews = getJmolsFor(ap);
+    if (existingViews.size()>0)
+    {
+      Enumeration jm = existingViews.elements();
+      while (jm.hasMoreElements()) {
+        AppJmol topJmol = (AppJmol) jm.nextElement();
+        // TODO: highlight topJmol in view somehow
+        int option = JOptionPane
+        .showInternalConfirmDialog(
+              Desktop.desktop, "Do you want to add "+
+              pdbentry.getId()+" to the view called\n'"+topJmol.getTitle()
+                      + "'\n",
+              "Align to existing structure view"
+                      , JOptionPane.YES_NO_OPTION);
+        if (option == JOptionPane.YES_OPTION)
+        {
+          topJmol.jmb.addStructure(pdbentry, seq, chains,true);
+          return;
+        }
+      }
+    }
+    // /////////////////////////////////
 
     jmb = new AppJmolBinding(this, new PDBEntry[]
-    { pdbentry }, seq, null, null);
+    { pdbentry }, new SequenceI[][]{seq}, null, null);
     this.ap = ap;
     setSize(400, 400); // probably should be a configurable/dynamic default here
 
@@ -178,6 +202,27 @@ public class AppJmol extends GStructureViewer implements Runnable,
 
   }
 
+  private Vector getJmolsFor(AlignmentPanel ap2)
+  {
+    Vector otherJmols= new Vector();
+    // Now this AppJmol is mapped to new sequences. We must add them to
+    // the exisiting array
+    JInternalFrame[] frames = Desktop.instance.getAllFrames();
+
+    for (int i = 0; i < frames.length; i++)
+    {
+      if (frames[i] instanceof AppJmol)
+      {
+        AppJmol topJmol = ((AppJmol) frames[i]);
+        if (topJmol.ap==ap2)
+        {
+          otherJmols.addElement(topJmol);
+        }
+      }
+    }
+    return otherJmols;
+  }
+
   void initJmol(String command)
   {
     jmb.setFinishedInit(false);
@@ -617,8 +662,27 @@ public class AppJmol extends GStructureViewer implements Runnable,
     }
     setChainMenuItems(jmb.chainNames);
     jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
-
+    
     this.setTitle(jmb.getViewerTitle());
+    if (jmb.getPdbFile().length>1 && jmb.sequence.length>1) {
+       jmolActionMenu.setVisible(true);
+    }
+  }
+
+  /* (non-Javadoc)
+   * @see jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event.ActionEvent)
+   */
+  @Override
+  protected void alignStructs_actionPerformed(ActionEvent actionEvent)
+  {
+    
+    try {
+      jmb.superposeStructures(ap.av.getAlignment(), -1, ap.av.getColumnSelection());
+    } catch (Exception e)
+    {
+      Cache.log.info("Couldn't align structures in alignframe "+ap.alignFrame.getTitle(),e);
+      
+    }
   }
 
   public void setJalviewColourScheme(ColourSchemeI ucs)