JAL-823 and JAL-824 - seqColour no longer the default colouring state unless PDB...
[jalview.git] / src / jalview / gui / AppJmol.java
index fd7e297..9d68c1b 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, loadStatus, bounds, viewid);
   }
 
   ViewSelectionMenu seqColourBy;
@@ -90,15 +90,19 @@ public class AppJmol extends GStructureViewer implements Runnable,
    * @param ids
    * @param seqs
    * @param ap
-   * @param usetoColour - add the alignment panel to the list used for colouring these structures
-   * @param useToAlign - add the alignment panel to the list used for aligning these structures
+   * @param usetoColour
+   *          - add the alignment panel to the list used for colouring these
+   *          structures
+   * @param useToAlign
+   *          - add the alignment panel to the list used for aligning these
+   *          structures
    * @param loadStatus
    * @param bounds
    * @param viewid
    */
   public AppJmol(String[] files, String[] ids, SequenceI[][] seqs,
-          AlignmentPanel ap, boolean usetoColour,boolean useToAlign, String loadStatus, Rectangle bounds,
-          String viewid)
+          AlignmentPanel ap, boolean usetoColour, boolean useToAlign,
+          String loadStatus, Rectangle bounds, String viewid)
   {
     PDBEntry[] pdbentrys = new PDBEntry[files.length];
     for (int i = 0; i < pdbentrys.length; i++)
@@ -121,10 +125,14 @@ public class AppJmol extends GStructureViewer implements Runnable,
     if (usetoColour)
     {
       useAlignmentPanelForColourbyseq(ap);
+      jmb.setColourBySequence(true);
+      seqColour.setSelected(true);
+    } else {
+      jmb.setColourBySequence(false);
+      seqColour.setSelected(false);
+      jmolColour.setSelected(true);
     }
     this.setBounds(bounds);
-    jmb.setColourBySequence(false);
-    seqColour.setSelected(false);
     initMenus();
     viewId = viewid;
     // jalview.gui.Desktop.addInternalFrame(this, "Loading File",
@@ -140,7 +148,11 @@ public class AppJmol extends GStructureViewer implements Runnable,
     initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
 
   }
-  private void initMenus() {
+
+  private void initMenus()
+  {
+    seqColour.setSelected(jmb.isColourBySequence());
+    jmolColour.setSelected(!jmb.isColourBySequence());
     seqColourBy = new ViewSelectionMenu("Colour by ..", this, _colourwith,
             new ItemListener()
             {
@@ -162,7 +174,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
     viewMenu.add(seqColourBy);
     final ItemListener handler;
     JMenu alpanels = new ViewSelectionMenu("Superpose with ..", this,
-            _alignwith, handler=new ItemListener()
+            _alignwith, handler = new ItemListener()
             {
 
               @Override
@@ -177,29 +189,51 @@ public class AppJmol extends GStructureViewer implements Runnable,
     jmolActionMenu.add(alpanels);
     jmolActionMenu.addMenuListener(new MenuListener()
     {
-      
+
       @Override
       public void menuSelected(MenuEvent e)
       {
         handler.itemStateChanged(null);
       }
-      
+
       @Override
       public void menuDeselected(MenuEvent e)
       {
         // TODO Auto-generated method stub
-        
+
       }
-      
+
       @Override
       public void menuCanceled(MenuEvent e)
       {
         // TODO Auto-generated method stub
+
+      }
+    });
+    colourMenu.addMenuListener(new MenuListener()
+    {
+      
+      @Override
+      public void menuSelected(MenuEvent arg0)
+      {
         
+        handlingGuiEvents=true;
+      }
+      
+      @Override
+      public void menuDeselected(MenuEvent arg0)
+      {
+        handlingGuiEvents=false;
+      }
+      
+      @Override
+      public void menuCanceled(MenuEvent arg0)
+      {
+        handlingGuiEvents=false;
       }
     });
-
   }
+
   IProgressIndicator progressBar = null;
 
   public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
@@ -288,9 +322,11 @@ public class AppJmol extends GStructureViewer implements Runnable,
     { pdbentry }, new SequenceI[][]
     { seq }, null, null);
     addAlignmentPanel(ap);
+    useAlignmentPanelForColourbyseq(ap);
+    jmb.setColourBySequence(true);
     setSize(400, 400); // probably should be a configurable/dynamic default here
     initMenus();
-    
+
     if (pdbentry.getFile() != null)
     {
       initJmol("load \"" + pdbentry.getFile() + "\"");
@@ -533,6 +569,10 @@ public class AppJmol extends GStructureViewer implements Runnable,
     jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow,
             null);
     jmb.newJmolPopup(true, "Jmol", true);
+    if (command==null)
+    {
+      command="";
+    }
     jmb.evalStateCommand(command);
     jmb.setFinishedInit(true);
   }
@@ -618,6 +658,13 @@ public class AppJmol extends GStructureViewer implements Runnable,
    */
   private boolean _started = false;
 
+  /**
+   * state flag indicating if the GUI is active when a particular button event
+   * takes place (e.g. when a stateChange occurs on a checkbox - this could be
+   * programmatic or due to the user doing something)
+   */
+  private boolean handlingGuiEvents=false;
+
   public void run()
   {
     _started = true;
@@ -895,17 +942,34 @@ public class AppJmol extends GStructureViewer implements Runnable,
       im.writeImage();
     }
   }
-
+  public void jmolColour_actionPerformed(ActionEvent actionEvent)
+  {
+    if (jmolColour.isSelected()) {
+      // disable automatic sequence colouring.
+      jmb.setColourBySequence(false);
+    }
+  }
   public void seqColour_actionPerformed(ActionEvent actionEvent)
   {
     jmb.setColourBySequence(seqColour.isSelected());
-    if (_colourwith==null) { _colourwith=new ArrayList<AlignmentPanel>();};
-    if (_colourwith.size()==0){ _colourwith.add(ap); };
-
-    // Set the colour using the current view for the associated alignframe
-    for (AlignmentPanel ap : _colourwith)
+    if (_colourwith == null)
+    {
+      _colourwith = new ArrayList<AlignmentPanel>();
+    }
+    if (jmb.isColourBySequence())
     {
-      jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
+      if (!jmb.isLoadingFromArchive() && handlingGuiEvents)
+      {
+        if (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
+      for (AlignmentPanel ap : _colourwith)
+      {
+        jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
+      }
     }
   }
 
@@ -1099,15 +1163,23 @@ public class AppJmol extends GStructureViewer implements Runnable,
     {
       jmolActionMenu.setVisible(true);
     }
-    if (!jmb.isLoadingFromArchive()) {
+    if (!jmb.isLoadingFromArchive())
+    {
       seqColour_actionPerformed(null);
     }
   }
 
   protected void buildJmolActionMenu()
   {
-    if (_alignwith==null) { _alignwith=new ArrayList<AlignmentPanel>();}
-    if (_alignwith.size()==0 && ap!=null) { _alignwith.add(ap);};
+    if (_alignwith == null)
+    {
+      _alignwith = new ArrayList<AlignmentPanel>();
+    }
+    if (_alignwith.size() == 0 && ap != null)
+    {
+      _alignwith.add(ap);
+    }
+    ;
     for (Component c : jmolActionMenu.getMenuComponents())
     {
       if (c != alignStructs)
@@ -1133,8 +1205,16 @@ public class AppJmol extends GStructureViewer implements Runnable,
 
   private void alignStructs_withAllAlignPanels()
   {
-    if (ap==null) { return; };
-    if (_alignwith.size()==0) { _alignwith.add(ap);};
+    if (ap == null)
+    {
+      return;
+    }
+    ;
+    if (_alignwith.size() == 0)
+    {
+      _alignwith.add(ap);
+    }
+    ;
     try
     {
       AlignmentI[] als = new Alignment[_alignwith.size()];