JAL-3127 use AlignViewportI.addGroup() to add group and propagate to complement view...
[jalview.git] / src / jalview / gui / TreeCanvas.java
index 3494fb8..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;
@@ -279,8 +278,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         g.drawString(nodeLabel, xstart + 2, ypos - 2);
       }
 
-      String name = (markPlaceholders && node.isPlaceholder()) ? (PLACEHOLDER + node
-              .getName()) : node.getName();
+      String name = (markPlaceholders && node.isPlaceholder())
+              ? (PLACEHOLDER + node.getName())
+              : node.getName();
 
       int charWidth = fm.stringWidth(name) + 3;
       int charHeight = font.getSize();
@@ -332,9 +332,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         g.fillRect(xend - 2, ypos - 2, 4, 4);
       }
 
-      int ystart = (int) (((SequenceNode) node.left()).ycount * chunk)
-              + offy;
-      int yend = (int) (((SequenceNode) node.right()).ycount * chunk)
+      int ystart = (node.left() == null ? 0
+              : (int) (((SequenceNode) node.left()).ycount * chunk)) + offy;
+      int yend = (node.right() == null ? 0
+              : (int) (((SequenceNode) node.right()).ycount * chunk))
               + offy;
 
       Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
@@ -423,8 +424,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
 
     SequenceNode top = tree.getTopNode();
 
-    double wscale = ((width * .8) - (offx * 2))
-            / tree.getMaxHeight();
+    double wscale = ((width * .8) - (offx * 2)) / tree.getMaxHeight();
 
     if (top.count == 0)
     {
@@ -511,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);
     }
@@ -653,8 +637,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
 
     if (tree == null)
     {
-      g.drawString(MessageManager.getString("label.calculating_tree")
-              + "....", 20, getHeight() / 2);
+      g.drawString(
+              MessageManager.getString("label.calculating_tree") + "....",
+              20, getHeight() / 2);
     }
     else
     {
@@ -665,9 +650,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         repaint();
       }
 
-      if (fitToWindow
-              || (!fitToWindow && (scrollPane.getHeight() > ((fm
-                      .getHeight() * nameHash.size()) + offy))))
+      if (fitToWindow || (!fitToWindow && (scrollPane
+              .getHeight() > ((fm.getHeight() * nameHash.size()) + offy))))
       {
         draw(g, scrollPane.getWidth(), scrollPane.getHeight());
         setPreferredSize(null);
@@ -751,7 +735,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         g2.setColor(Color.gray);
       }
 
-      int x = (int) ((threshold * (getWidth() - labelLength - (2 * offx))) + offx);
+      int x = (int) ((threshold * (getWidth() - labelLength - (2 * offx)))
+              + offx);
 
       g2.drawLine(x, 0, x, getHeight());
     }
@@ -860,8 +845,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
     if (ob instanceof SequenceNode)
     {
       highlightNode = (SequenceNode) ob;
-      this.setToolTipText("<html>"
-              + MessageManager.getString("label.highlightnode"));
+      this.setToolTipText(
+              "<html>" + MessageManager.getString("label.highlightnode"));
       repaint();
 
     }
@@ -960,6 +945,15 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
           }
         }
         colourGroups(groups);
+
+        /*
+         * clear partition (don't show vertical line) if
+         * it is to the right of all nodes
+         */
+        if (groups.isEmpty())
+        {
+          threshold = 0f;
+        }
       }
 
       PaintRefresher.Refresh(tp, ap.av.getSequenceSetId());
@@ -979,7 +973,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
 
       Vector<SequenceNode> l = tree.findLeaves(groups.get(i));
 
-      Vector<SequenceI> sequences = new Vector<SequenceI>();
+      Vector<SequenceI> sequences = new Vector<>();
 
       for (int j = 0; j < l.size(); j++)
       {
@@ -1006,9 +1000,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         }
         else
         {
-          cs = ColourSchemeProperty.getColourScheme(sg,
-                  ColourSchemeProperty.getColourName(av
-                          .getGlobalColourScheme()));
+          cs = ColourSchemeProperty.getColourScheme(av, sg,
+                  ColourSchemeProperty
+                  .getColourName(av.getGlobalColourScheme()));
         }
         // cs is null if shading is an annotationColourGradient
         // if (cs != null)
@@ -1028,8 +1022,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       for (int a = 0; a < aps.length; a++)
       {
         if (aps[a].av.getGlobalColourScheme() != null
-                && aps[a].av.getResidueShading()
-                        .conservationApplied())
+                && aps[a].av.getResidueShading().conservationApplied())
         {
           Conservation c = new Conservation("Group", sg.getSequences(null),
                   sg.getStartRes(), sg.getEndRes());
@@ -1037,33 +1030,18 @@ 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));
       }
     }
 
-    // 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)