Merge branch 'feature/JAL-3127_seqidChainshading' into merge/JAL-3127
[jalview.git] / src / jalview / gui / TreeCanvas.java
index c195c80..180467a 100755 (executable)
@@ -28,11 +28,8 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequenceNode;
 import jalview.schemes.ColourSchemeI;
-import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.UserColourScheme;
 import jalview.structure.SelectionSource;
 import jalview.util.Format;
-import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
@@ -512,29 +509,21 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       return;
     }
 
-    if ((node.left() == null) && (node.right() == null)) // TODO: internal node
+    node.color = c;
+    if (node.element() instanceof SequenceI)
     {
-      node.color = c;
-
-      if (node.element() instanceof SequenceI)
+      final SequenceI seq = (SequenceI) node.element();
+      AlignmentPanel[] aps = getAssociatedPanels();
+      if (aps != null)
       {
-        AlignmentPanel[] aps = getAssociatedPanels();
-        if (aps != null)
+        for (int a = 0; a < aps.length; a++)
         {
-          for (int a = 0; a < aps.length; a++)
-          {
-            final SequenceI seq = (SequenceI) node.element();
-            aps[a].av.setSequenceColour(seq, c);
-          }
+          aps[a].av.setSequenceColour(seq, c);
         }
       }
     }
-    else
-    {
-      node.color = c;
-      setColor((SequenceNode) node.left(), c);
-      setColor((SequenceNode) node.right(), c);
-    }
+    setColor((SequenceNode) node.left(), c);
+    setColor((SequenceNode) node.right(), c);
   }
 
   /**
@@ -960,6 +949,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
                     .deleteAllGroups();
             aps[a].av.getCodingComplement().clearSequenceColours();
           }
+          aps[a].av.setUpdateStructures(true);
         }
         colourGroups(groups);
 
@@ -1003,76 +993,48 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       }
 
       ColourSchemeI cs = null;
-      SequenceGroup sg = new SequenceGroup(sequences, null, cs, true, true,
+      SequenceGroup _sg = new SequenceGroup(sequences, null, cs, true, true,
               false, 0, av.getAlignment().getWidth() - 1);
 
-      if (av.getGlobalColourScheme() != null)
-      {
-        if (av.getGlobalColourScheme() instanceof UserColourScheme)
-        {
-          cs = new UserColourScheme(
-                  ((UserColourScheme) av.getGlobalColourScheme())
-                          .getColours());
-
-        }
-        else
-        {
-          cs = ColourSchemeProperty.getColourScheme(sg, ColourSchemeProperty
-                  .getColourName(av.getGlobalColourScheme()));
-        }
-        // cs is null if shading is an annotationColourGradient
-        // if (cs != null)
-        // {
-        // cs.setThreshold(av.getViewportColourScheme().getThreshold(),
-        // av.isIgnoreGapsConsensus());
-        // }
-      }
-      sg.setColourScheme(cs);
-      sg.getGroupColourScheme().setThreshold(
-              av.getResidueShading().getThreshold(),
-              av.isIgnoreGapsConsensus());
-      // sg.recalcConservation();
-      sg.setName("JTreeGroup:" + sg.hashCode());
-      sg.setIdColour(col);
+      _sg.setName("JTreeGroup:" + _sg.hashCode());
+      _sg.setIdColour(col);
 
       for (int a = 0; a < aps.length; a++)
       {
-        if (aps[a].av.getGlobalColourScheme() != null
-                && aps[a].av.getResidueShading().conservationApplied())
-        {
-          Conservation c = new Conservation("Group", sg.getSequences(null),
-                  sg.getStartRes(), sg.getEndRes());
-          c.calculate();
-          c.verdict(false, aps[a].av.getConsPercGaps());
-          sg.cs.setConservation(c);
-        }
+        SequenceGroup sg = new SequenceGroup(_sg);
+        AlignViewport viewport = aps[a].av;
 
-        aps[a].av.getAlignment().addGroup(new SequenceGroup(sg));
-        // TODO can we push all of the below into AlignViewportI?
-        final AlignViewportI codingComplement = aps[a].av
-                .getCodingComplement();
-        if (codingComplement != null)
+        // Propagate group colours in each view
+        if (viewport.getGlobalColourScheme() != null)
         {
-          SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg, av,
-                  codingComplement);
-          if (mappedGroup.getSequences().size() > 0)
+          cs = viewport.getGlobalColourScheme().getInstance(viewport, sg);
+          sg.setColourScheme(cs);
+          sg.getGroupColourScheme().setThreshold(
+                  viewport.getResidueShading().getThreshold(),
+                  viewport.isIgnoreGapsConsensus());
+
+          if (viewport.getResidueShading().conservationApplied())
           {
-            codingComplement.getAlignment().addGroup(mappedGroup);
-            for (SequenceI seq : mappedGroup.getSequences())
-            {
-              codingComplement.setSequenceColour(seq, col.brighter());
-            }
+            Conservation c = new Conservation("Group",
+                    sg.getSequences(null), sg.getStartRes(),
+                    sg.getEndRes());
+            c.calculate();
+            c.verdict(false, viewport.getConsPercGaps());
+            sg.cs.setConservation(c);
           }
         }
+        // indicate that associated structure views will need an update
+        viewport.setUpdateStructures(true);
+        // propagate structure view update and sequence group to complement view
+        viewport.addSequenceGroup(sg);
       }
     }
 
-    // notify the panel(s) to redo any group specific stuff.
+    // notify the panel(s) to redo any group specific stuff
+    // also updates structure views if necessary
     for (int a = 0; a < aps.length; a++)
     {
       aps[a].updateAnnotation();
-      // TODO: JAL-868 - need to ensure view colour change message is broadcast
-      // to any Jmols listening in
       final AlignViewportI codingComplement = aps[a].av
               .getCodingComplement();
       if (codingComplement != null)