JAL-4134 - refactor tree calculation code to work with binaryNode base type.
[jalview.git] / src / jalview / gui / TreeCanvas.java
index 6f143db..a5f1ab9 100755 (executable)
@@ -50,6 +50,7 @@ import javax.swing.ToolTipManager;
 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;
@@ -332,9 +333,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       }
 
       int ystart = (node.left() == null ? 0
-              : (int) (((SequenceNode) node.left()).ycount * chunk)) + offy;
+              : (int) (((BinaryNode) node.left()).ycount * chunk)) + offy;
       int yend = (node.right() == null ? 0
-              : (int) (((SequenceNode) node.right()).ycount * chunk))
+              : (int) (((BinaryNode) node.right()).ycount * chunk))
               + offy;
 
       Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
@@ -415,14 +416,14 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
     int width = getWidth();
     int height = getHeight();
 
-    SequenceNode top = tree.getTopNode();
+    BinaryNode top = tree.getTopNode();
 
     double wscale = ((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;
@@ -448,7 +449,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
    * @param offy
    *          DOCUMENT ME!
    */
-  public void pickNode(Rectangle pickBox, SequenceNode node, float chunk,
+  public void pickNode(Rectangle pickBox, BinaryNode node, float chunk,
           double wscale, int width, int offx, int offy)
   {
     if (node == null)
@@ -481,9 +482,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
     }
     else
     {
-      pickNode(pickBox, (SequenceNode) node.left(), chunk, wscale, width,
+      pickNode(pickBox, (BinaryNode) node.left(), chunk, wscale, width,
               offx, offy);
-      pickNode(pickBox, (SequenceNode) node.right(), chunk, wscale, width,
+      pickNode(pickBox, (BinaryNode) node.right(), chunk, wscale, width,
               offx, offy);
     }
   }
@@ -496,7 +497,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
    * @param c
    *          DOCUMENT ME!
    */
-  public void setColor(SequenceNode node, Color c)
+  public void setColor(BinaryNode node, Color c)
   {
     if (node == null)
     {
@@ -516,8 +517,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         }
       }
     }
-    setColor((SequenceNode) node.left(), c);
-    setColor((SequenceNode) node.right(), c);
+    setColor((BinaryNode) node.left(), c);
+    setColor((BinaryNode) node.right(), c);
   }
 
   /**
@@ -713,12 +714,12 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
     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;