instant update when seq colour is pressed
[jalview.git] / src / jalview / appletgui / AppletJmol.java
index 53115d2..f64014b 100644 (file)
@@ -354,6 +354,7 @@ public class AppletJmol extends Frame
   {
     if (evt.getSource() == seqColour)
     {
+      lastCommand = null;
       colourBySequence = seqColour.getState();
       colourBySequence(ap);
     }
@@ -441,14 +442,11 @@ public class AppletJmol extends Frame
       resetLastRes.append(":" + chain);
     }
 
-    eval.append(";color gold;wireframe 100");
+    eval.append(";wireframe 100;"+eval.toString()+".CA;");
 
-    Color col = new Color(viewer.getAtomArgb(atomIndex));
+    resetLastRes.append(";wireframe 0;"+resetLastRes.toString()+".CA;spacefill 0;");
 
-    resetLastRes.append(";color["
-                        + col.getRed() + ","
-                        + col.getGreen() + ","
-                        + col.getBlue() + "];wireframe 0");
+    eval.append("spacefill 200;select none");
 
     viewer.evalStringQuiet(eval.toString());
 
@@ -470,21 +468,24 @@ public class AppletJmol extends Frame
     return new Color(viewer.getAtomArgb(atomIndex));
   }
 
-  FeatureRenderer fr;
-  public void colourBySequence(AlignmentPanel ap)
+  String lastCommand;
+  FeatureRenderer fr=null;
+  public void colourBySequence(AlignmentPanel sourceap)
   {
-    if(!colourBySequence)
-      return;
+    this.ap = sourceap;
 
+    if (!colourBySequence)
+      return;
 
     StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());
 
     if (mapping.length < 1)
       return;
 
-    SequenceRenderer sr = ap.seqPanel.seqCanvas.getSequenceRenderer();
+    SequenceRenderer sr = new SequenceRenderer(ap.av);
 
     boolean showFeatures = false;
+
     if (ap.av.showSequenceFeatures)
     {
       showFeatures = true;
@@ -504,14 +505,14 @@ public class AppletJmol extends Frame
       for (int m = 0; m < mapping.length; m++)
       {
         if (mapping[m].getSequence() == sequence[s]
-            && ap.av.alignment.findIndex(sequence[s])>-1)
+            && ap.av.alignment.findIndex(sequence[s]) > -1)
         {
           for (int r = 0; r < sequence[s].getLength(); r++)
           {
             int pos = mapping[m].getPDBResNum(
                 sequence[s].findPosition(r));
 
-            if (pos < 1 || pos==lastPos)
+            if (pos < 1 || pos == lastPos)
               continue;
 
             lastPos = pos;
@@ -521,7 +522,7 @@ public class AppletJmol extends Frame
             if (showFeatures)
               col = fr.findFeatureColour(col, sequence[s], r);
 
-            if (command.toString().endsWith(":" + mapping[m].getChain()+
+            if (command.toString().endsWith(":" + mapping[m].getChain() +
                                             ";color["
                                             + col.getRed() + ","
                                             + col.getGreen() + ","
@@ -539,19 +540,23 @@ public class AppletJmol extends Frame
             }
 
             command.append(";color["
-                             + col.getRed() + ","
-                             + col.getGreen() + ","
-                             + col.getBlue() + "]");
-
+                           + col.getRed() + ","
+                           + col.getGreen() + ","
+                           + col.getBlue() + "]");
           }
           break;
         }
       }
     }
 
-    viewer.evalStringQuiet(command.toString());
+    if (lastCommand == null || !lastCommand.equals(command.toString()))
+    {
+      viewer.evalStringQuiet(command.toString());
+    }
+    lastCommand = command.toString();
   }
 
+
   StringBuffer condenseCommand(String command, int pos)
   {
 
@@ -723,7 +728,7 @@ public class AppletJmol extends Frame
       picked+=strInfo.substring(strInfo.indexOf(":")+1,
                                strInfo.indexOf("."));
 
-    picked+=".C";
+    picked+=".CA";
 
     if (!atomsPicked.contains(picked))
     {