JAL-3127 use AlignViewportI.addGroup() to add group and propagate to complement view...
authorJim Procter <jprocter@issues.jalview.org>
Tue, 16 Oct 2018 15:37:13 +0000 (16:37 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Tue, 16 Oct 2018 15:37:13 +0000 (16:37 +0100)
src/jalview/api/AlignViewportI.java
src/jalview/gui/TreeCanvas.java
src/jalview/viewmodel/AlignmentViewport.java

index 5180e20..389d9cf 100644 (file)
@@ -510,4 +510,12 @@ public interface AlignViewportI extends ViewStyleI
    */
   boolean needToUpdateStructureViews();
 
+  /**
+   * Adds sequencegroup to the alignment in the view. Also adds a group to the
+   * complement view if one is defined.
+   * 
+   * @param sequenceGroup
+   *          - a group defined on sequences in the alignment held by the view
+   */
+  void addSequenceGroup(SequenceGroup sequenceGroup);
 }
index dbb7e2b..4658fc9 100755 (executable)
@@ -32,7 +32,6 @@ 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,26 +511,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       return;
     }
 
-    if ((node.left() == null) && (node.right() == null)) // TODO: internal node
-    {
-      node.color = c;
+    node.color = c;
 
-      if (node.element() instanceof SequenceI)
-      {
-        AlignmentPanel[] aps = getAssociatedPanels();
-        if (aps != null)
-        {
-          for (int a = 0; a < aps.length; a++)
-          {
-            final SequenceI seq = (SequenceI) node.element();
-            aps[a].av.setSequenceColour(seq, c);
-          }
-        }
-      }
-    }
-    else
+    if ((node.left() != null) || (node.right() != null)) // TODO: internal node
     {
-      node.color = c;
       setColor((SequenceNode) node.left(), c);
       setColor((SequenceNode) node.right(), c);
     }
@@ -1047,26 +1030,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
           c.verdict(false, aps[a].av.getConsPercGaps());
           sg.cs.setConservation(c);
         }
-
-        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)
-        {
-          SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg, av,
-                  codingComplement);
-          if (mappedGroup.getSequences().size() > 0)
-          {
-            codingComplement.getAlignment().addGroup(mappedGroup);
-            for (SequenceI seq : mappedGroup.getSequences())
-            {
-              codingComplement.setSequenceColour(seq, col.brighter());
-            }
-          }
-        }
         // indicate that associated structure views will need an update
         aps[a].av.setUpdateStructures(true);
+        // propagate structure view update and sequence group to complement view
+        aps[a].av.addSequenceGroup(new SequenceGroup(sg));
       }
     }
 
index c4923cf..6427b45 100644 (file)
@@ -2982,4 +2982,40 @@ public abstract class AlignmentViewport
     return update;
   }
 
+  @Override
+  public void addSequenceGroup(SequenceGroup sequenceGroup)
+  {
+    alignment.addGroup(sequenceGroup);
+
+    Color col = sequenceGroup.idColour;
+    if (col != null)
+    {
+      col = col.brighter();
+
+      for (SequenceI sq : sequenceGroup.getSequences())
+      {
+        setSequenceColour(sq, col);
+      }
+    }
+
+    if (codingComplement != null)
+    {
+      SequenceGroup mappedGroup = MappingUtils
+              .mapSequenceGroup(sequenceGroup, this, codingComplement);
+      if (mappedGroup.getSequences().size() > 0)
+      {
+        codingComplement.getAlignment().addGroup(mappedGroup);
+
+        if (col != null)
+        {
+          for (SequenceI seq : mappedGroup.getSequences())
+          {
+            codingComplement.setSequenceColour(seq, col);
+          }
+        }
+      }
+      // propagate the structure view update flag according to our own setting
+      codingComplement.setUpdateStructures(needToUpdateStructureViews);
+    }
+  }
 }