refactor to allow distinct StructureSelectionManager instances for
[jalview.git] / src / jalview / gui / AppJmol.java
index d5148ba..fdf00c0 100644 (file)
@@ -79,7 +79,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
     this(new String[]
     { file }, new String[]
     { id }, new SequenceI[][]
-    { seq }, ap, true, true, loadStatus, bounds, viewid);
+    { seq }, ap, true, true, false, loadStatus, bounds, viewid);
   }
 
   ViewSelectionMenu seqColourBy;
@@ -96,12 +96,14 @@ public class AppJmol extends GStructureViewer implements Runnable,
    * @param useToAlign
    *          - add the alignment panel to the list used for aligning these
    *          structures
+   * @param leaveColouringToJmol
+   *          - do not update the colours from any other source. Jmol is handling them
    * @param loadStatus
    * @param bounds
    * @param viewid
    */
   public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
-          AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
+          AlignmentPanel ap, boolean usetoColour, boolean useToAlign, boolean leaveColouringToJmol,
           String loadStatus, Rectangle bounds, String viewid)
   {
     PDBEntry[] pdbentrys = new PDBEntry[files.length];
@@ -114,7 +116,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, pdbentrys, seqs, null, null);
+    jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), pdbentrys, seqs, null, null);
 
     jmb.setLoadingFromArchive(true);
     addAlignmentPanel(ap);
@@ -122,15 +124,18 @@ public class AppJmol extends GStructureViewer implements Runnable,
     {
       useAlignmentPanelForSuperposition(ap);
     }
+    if (leaveColouringToJmol || !usetoColour)
+    {
+      jmb.setColourBySequence(false);
+      seqColour.setSelected(false);
+      jmolColour.setSelected(true);
+    }
     if (usetoColour)
     {
       useAlignmentPanelForColourbyseq(ap);
       jmb.setColourBySequence(true);
       seqColour.setSelected(true);
-    } else {
-      jmb.setColourBySequence(false);
-      seqColour.setSelected(false);
-      jmolColour.setSelected(true);
+      jmolColour.setSelected(false);
     }
     this.setBounds(bounds);
     initMenus();
@@ -153,6 +158,15 @@ public class AppJmol extends GStructureViewer implements Runnable,
   {
     seqColour.setSelected(jmb.isColourBySequence());
     jmolColour.setSelected(!jmb.isColourBySequence());
+    if (_colourwith==null)
+    {
+      _colourwith=new Vector<AlignmentPanel>();
+    }
+    if (_alignwith==null)
+    {
+      _alignwith=new Vector<AlignmentPanel>();
+    }
+    
     seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
             new ItemListener()
             {
@@ -219,8 +233,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
     progressBar = ap.alignFrame;
     // ////////////////////////////////
     // Is the pdb file already loaded?
-    String alreadyMapped = StructureSelectionManager
-            .getStructureSelectionManager().alreadyMappedToFile(
+    String alreadyMapped = jmb.ssm.alreadyMappedToFile(
                     pdbentry.getId());
 
     if (alreadyMapped != null)
@@ -233,8 +246,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
 
       if (option == JOptionPane.YES_OPTION)
       {
-        StructureSelectionManager.getStructureSelectionManager()
-                .setMapping(seq, chains, alreadyMapped,
+        jmb.ssm.setMapping(seq, chains, alreadyMapped,
                         AppletFormatAdapter.FILE);
         if (ap.seqPanel.seqCanvas.fr != null)
         {
@@ -295,7 +307,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
     }
     // /////////////////////////////////
 
-    jmb = new AppJmolBinding(this, new PDBEntry[]
+    jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), new PDBEntry[]
     { pdbentry }, new SequenceI[][]
     { seq }, null, null);
     addAlignmentPanel(ap);
@@ -351,13 +363,13 @@ public class AppJmol extends GStructureViewer implements Runnable,
   /**
    * list of alignment panels to use for superposition
    */
-  ArrayList<AlignmentPanel> _alignwith = new ArrayList();
+  Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
 
   /**
    * list of alignment panels that are used for colouring structures by aligned
    * sequences
    */
-  ArrayList<AlignmentPanel> _colourwith = new ArrayList();
+  Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
 
   /**
    * set the primary alignmentPanel reference and add another alignPanel to the
@@ -426,6 +438,13 @@ public class AppJmol extends GStructureViewer implements Runnable,
     }
   }
 
+  public void useAlignmentPanelForColourbyseq(AlignmentPanel nap, boolean enableColourBySeq)
+  {
+    useAlignmentPanelForColourbyseq(nap);
+    jmb.setColourBySequence(enableColourBySeq);
+    seqColour.setSelected(enableColourBySeq);
+    jmolColour.setSelected(!enableColourBySeq);
+  }
   public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
   {
     addAlignmentPanel(nap);
@@ -847,8 +866,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
     {
       for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
       {
-        cap.appendText(StructureSelectionManager
-                .getStructureSelectionManager().printMapping(
+        cap.appendText(jmb.printMapping(
                         jmb.pdbentry[pdbe].getFile()));
         cap.appendText("\n");
       }
@@ -924,15 +942,15 @@ public class AppJmol extends GStructureViewer implements Runnable,
     jmb.setColourBySequence(seqColour.isSelected());
     if (_colourwith == null)
     {
-      _colourwith = new ArrayList<AlignmentPanel>();
+      _colourwith = new Vector<AlignmentPanel>();
     }
     if (jmb.isColourBySequence())
     {
       if (!jmb.isLoadingFromArchive())
       {
-        if (ap!=null) {
-               // Make the currently displayed alignment panel the associated view
-               _colourwith.add(ap.alignFrame.alignPanel);
+        if (_colourwith.size()==0 && ap!=null) {
+          // Make the currently displayed alignment panel the associated view
+          _colourwith.add(ap.alignFrame.alignPanel);
         }
       }
       // Set the colour using the current view for the associated alignframe
@@ -1143,7 +1161,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
   {
     if (_alignwith == null)
     {
-      _alignwith = new ArrayList<AlignmentPanel>();
+      _alignwith = new Vector<AlignmentPanel>();
     }
     if (_alignwith.size() == 0 && ap != null)
     {
@@ -1258,4 +1276,14 @@ public class AppJmol extends GStructureViewer implements Runnable,
     return (_colourwith != null) && _colourwith.contains(ap2);
   }
 
+  /**
+   * 
+   * @return TRUE if the view is NOT being coloured by sequence associations.
+   */
+  public boolean isColouredByJmol()
+  {
+    return !jmb.isColourBySequence();
+    }
+  
+
 }