JAL-4134 - refactor tree calculation code to work with binaryNode base type.
[jalview.git] / src / jalview / appletgui / TreeCanvas.java
index 2e5f938..1355916 100755 (executable)
@@ -23,6 +23,7 @@ package jalview.appletgui;
 import jalview.analysis.Conservation;
 import jalview.analysis.TreeModel;
 import jalview.api.AlignViewportI;
+import jalview.datamodel.BinaryNode;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
@@ -263,9 +264,9 @@ public class TreeCanvas extends Panel
       }
 
       int ystart = (int) (node.left() == null ? 0
-              : (((SequenceNode) node.left()).ycount * chunk)) + offy;
+              : (((BinaryNode) node.left()).ycount * chunk)) + offy;
       int yend = (int) (node.right() == null ? 0
-              : (((SequenceNode) node.right()).ycount * chunk)) + offy;
+              : (((BinaryNode) node.right()).ycount * chunk)) + offy;
 
       Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
       nodeHash.put(node, pos);
@@ -338,20 +339,20 @@ public class TreeCanvas extends Panel
     int width = getSize().width;
     int height = getSize().height;
 
-    SequenceNode top = tree.getTopNode();
+    BinaryNode top = tree.getTopNode();
 
     double wscale = (float) (width * .8 - offx * 2) / tree.getMaxHeight();
     if (top.count == 0)
     {
-      top.count = ((SequenceNode) top.left()).count
-              + ((SequenceNode) top.right()).count;
+      top.count = ((BinaryNode) top.left()).count
+              + ((BinaryNode) top.right()).count;
     }
     float chunk = (float) (height - offy) / top.count;
 
     pickNode(pickBox, top, chunk, wscale, width, offx, offy);
   }
 
-  public void pickNode(Rectangle pickBox, SequenceNode node, float chunk,
+  public void pickNode(Rectangle pickBox, BinaryNode node, float chunk,
           double scale, int width, int offx, int offy)
   {
     if (node == null)
@@ -384,14 +385,14 @@ public class TreeCanvas extends Panel
     }
     else
     {
-      pickNode(pickBox, (SequenceNode) node.left(), chunk, scale, width,
+      pickNode(pickBox, (BinaryNode) node.left(), chunk, scale, width,
               offx, offy);
-      pickNode(pickBox, (SequenceNode) node.right(), chunk, scale, width,
+      pickNode(pickBox, (BinaryNode) node.right(), chunk, scale, width,
               offx, offy);
     }
   }
 
-  public void setColor(SequenceNode node, Color c)
+  public void setColor(BinaryNode node, Color c)
   {
     if (node == null)
     {
@@ -410,8 +411,8 @@ public class TreeCanvas extends Panel
     else
     {
       node.color = c;
-      setColor((SequenceNode) node.left(), c);
-      setColor((SequenceNode) node.right(), c);
+      setColor((BinaryNode) node.left(), c);
+      setColor((BinaryNode) node.right(), c);
     }
   }
 
@@ -469,12 +470,12 @@ public class TreeCanvas extends Panel
 
     double wscale = (width - labelLength - offx * 2) / tree.getMaxHeight();
 
-    SequenceNode top = tree.getTopNode();
+    BinaryNode top = tree.getTopNode();
 
     if (top.count == 0)
     {
-      top.count = ((SequenceNode) top.left()).count
-              + ((SequenceNode) top.right()).count;
+      top.count = ((BinaryNode) top.left()).count
+              + ((BinaryNode) top.right()).count;
     }
     float chunk = (float) (height - offy) / top.count;