sequences are private in SequenceGroup
[jalview.git] / src / jalview / appletgui / TreeCanvas.java
index 136be52..af1d752 100755 (executable)
@@ -37,15 +37,13 @@ public class TreeCanvas
   AlignViewport av;\r
   public static final String PLACEHOLDER = " * ";\r
   Font font;\r
-  int fontSize = 12;\r
-\r
   boolean fitToWindow = true;\r
   boolean showDistances = false;\r
   boolean showBootstrap = false;\r
   boolean markPlaceholders = false;\r
 \r
   int offx = 20;\r
-  int offy = 20;\r
+  int offy;\r
 \r
   float threshold;\r
 \r
@@ -59,15 +57,12 @@ public class TreeCanvas
   Hashtable nameHash = new Hashtable();\r
   Hashtable nodeHash = new Hashtable();\r
 \r
-  public TreeCanvas(AlignViewport av, NJTree tree, ScrollPane scroller,\r
-                    String label)\r
+  public TreeCanvas(AlignViewport av, ScrollPane scroller)\r
   {\r
     this.av = av;\r
-    this.tree = tree;\r
+    font = av.getFont();\r
     scrollPane = scroller;\r
     addMouseListener(this);\r
-    tree.findHeight(tree.getTopNode());\r
-    longestName = label;\r
     setLayout(null);\r
 \r
     PaintRefresher.Register(this, av.alignment);\r
@@ -82,10 +77,9 @@ public class TreeCanvas
       av.setSelectionGroup(selected);\r
     }\r
 \r
-    selected.setEndRes(av.alignment.getWidth());\r
+    selected.setEndRes(av.alignment.getWidth()-1);\r
     selected.addOrRemove(sequence, true);\r
 \r
-System.out.println("called here");\r
     PaintRefresher.Refresh(this, av.alignment);\r
     repaint();\r
   }\r
@@ -94,6 +88,30 @@ System.out.println("called here");
   {\r
     this.tree = tree;\r
     tree.findHeight(tree.getTopNode());\r
+\r
+    // Now have to calculate longest name based on the leaves\r
+    Vector leaves = tree.findLeaves(tree.getTopNode(), new Vector());\r
+    boolean has_placeholders = false;\r
+    longestName = "";\r
+\r
+    for (int i = 0; i < leaves.size(); i++)\r
+    {\r
+      SequenceNode lf = (SequenceNode) leaves.elementAt(i);\r
+\r
+      if (lf.isPlaceholder())\r
+      {\r
+        has_placeholders = true;\r
+      }\r
+\r
+      if (longestName.length() < ( (Sequence) lf.element()).getName()\r
+          .length())\r
+      {\r
+        longestName = TreeCanvas.PLACEHOLDER +\r
+            ( (Sequence) lf.element()).getName();\r
+      }\r
+    }\r
+\r
+    setMarkPlaceholders(has_placeholders);\r
   }\r
 \r
   public void drawNode(Graphics g, SequenceNode node, float chunk, float scale,\r
@@ -141,7 +159,7 @@ System.out.println("called here");
       String nodeLabel = "";\r
       if (showDistances && node.dist > 0)\r
       {\r
-        nodeLabel = new Format("%5.2f").form(node.dist);\r
+        nodeLabel = new Format("%-.2f").form(node.dist);\r
       }\r
       if (showBootstrap)\r
       {\r
@@ -153,7 +171,7 @@ System.out.println("called here");
       }\r
       if (!nodeLabel.equals(""))\r
       {\r
-        g.drawString(nodeLabel, xstart, ypos - 10);\r
+        g.drawString(nodeLabel, xstart+2, ypos - 2);\r
       }\r
 \r
       String name = (markPlaceholders && node.isPlaceholder()) ?\r
@@ -162,7 +180,7 @@ System.out.println("called here");
       int charWidth = fm.stringWidth(name) + 3;\r
       int charHeight = fm.getHeight();\r
 \r
-      Rectangle rect = new Rectangle(xend + 20, ypos - charHeight,\r
+      Rectangle rect = new Rectangle(xend + 10, ypos - charHeight,\r
                                      charWidth, charHeight);\r
 \r
       nameHash.put( (SequenceI) node.element(), rect);\r
@@ -170,7 +188,7 @@ System.out.println("called here");
       // Colour selected leaves differently\r
       SequenceGroup selected = av.getSelectionGroup();\r
       if (selected != null &&\r
-          selected.sequences.contains( (SequenceI) node.element()))\r
+          selected.getSequences(false).contains( (SequenceI) node.element()))\r
       {\r
         g.setColor(Color.gray);\r
 \r
@@ -209,7 +227,7 @@ System.out.println("called here");
 \r
       if (showDistances && node.dist > 0)\r
       {\r
-        g.drawString(new Format("%5.2f").form(node.dist), xstart, ypos - 5);\r
+        g.drawString(new Format("%-.2f").form(node.dist), xstart+2, ypos - 2);\r
       }\r
 \r
     }\r
@@ -261,7 +279,7 @@ System.out.println("called here");
       top.count = ( (SequenceNode) top.left()).count +\r
           ( (SequenceNode) top.right()).count;\r
     }\r
-    float chunk = (float) (height - offy * 2) / top.count;\r
+    float chunk = (float) (height - offy) / top.count;\r
 \r
     pickNode(pickBox, top, chunk, wscale, width, offx, offy);\r
   }\r
@@ -277,9 +295,9 @@ System.out.println("called here");
     if (node.left() == null && node.right() == null)\r
     {\r
       float height = node.height;\r
-      float dist = node.dist;\r
+      //float dist = node.dist;\r
 \r
-      int xstart = (int) ( (height - dist) * scale) + offx;\r
+      //int xstart = (int) ( (height - dist) * scale) + offx;\r
       int xend = (int) (height * scale) + offx;\r
 \r
       int ypos = (int) (node.ycount * chunk) + offy;\r
@@ -333,9 +351,12 @@ System.out.println("called here");
   public void paint(Graphics g)\r
   {\r
 \r
-    font = new Font("Verdana", Font.PLAIN, fontSize);\r
+    if(tree==null)\r
+      return;\r
+\r
     g.setFont(font);\r
 \r
+\r
     FontMetrics fm = g.getFontMetrics(font);\r
 \r
     if (nameHash.size() == 0)\r
@@ -359,19 +380,10 @@ System.out.println("called here");
     scrollPane.validate();\r
   }\r
 \r
-  public int getFontSize()\r
-  {\r
-    return fontSize;\r
-  }\r
-\r
-  public void setFontSize(int fontSize)\r
-  {\r
-    this.fontSize = fontSize;\r
-    repaint();\r
-  }\r
 \r
   public void draw(Graphics g, int width, int height)\r
   {\r
+    offy = font.getSize()+10;\r
 \r
     g.setColor(Color.white);\r
     g.fillRect(0, 0, width, height);\r
@@ -387,7 +399,7 @@ System.out.println("called here");
       top.count = ( (SequenceNode) top.left()).count +\r
           ( (SequenceNode) top.right()).count;\r
     }\r
-    float chunk = (float) (height - offy * 2) / top.count;\r
+    float chunk = (float) (height - offy) / top.count;\r
 \r
     drawNode(g, tree.getTopNode(), chunk, wscale, width, offx, offy);\r
 \r
@@ -476,32 +488,50 @@ System.out.println("called here");
           Vector sequences = new Vector();\r
           for (int j = 0; j < l.size(); j++)\r
           {\r
-            sequences.addElement( (Sequence) ( (SequenceNode) l.elementAt(j)).element());\r
+            SequenceI s1 = (SequenceI) ( (SequenceNode) l.elementAt(j)).element();\r
+            if(!sequences.contains(s1))\r
+              sequences.addElement(s1);\r
           }\r
 \r
-          ColourSchemeI cs = ColourSchemeProperty.getColour(sequences, av.alignment.getWidth(),\r
-              ColourSchemeProperty.getColourName(av.getGlobalColourScheme()));\r
+          ColourSchemeI cs = null;\r
 \r
+          if (av.getGlobalColourScheme() != null)\r
+          {\r
+            if (av.getGlobalColourScheme() instanceof UserColourScheme)\r
+            {\r
+              cs = new UserColourScheme(\r
+                  ( (UserColourScheme) av.getGlobalColourScheme()).getColours());\r
+\r
+            }\r
+            else\r
+              cs = ColourSchemeProperty.getColour(sequences,\r
+                                                  av.alignment.getWidth(),\r
+                                                  ColourSchemeProperty.getColourName(\r
+                                                      av.getGlobalColourScheme()));\r
+\r
+              cs.setThreshold(av.getGlobalColourScheme().getThreshold(),\r
+                                                   av.getIgnoreGapsConsensus());\r
+          }\r
 \r
           SequenceGroup sg = new SequenceGroup(sequences, "TreeGroup",\r
                                                cs, true, true,\r
-                                               false, 0, av.alignment.getWidth());\r
+                                               false, 0, av.alignment.getWidth()-1);\r
 \r
 \r
-          if (av.getGlobalColourScheme() instanceof ConservationColourScheme)\r
-          {\r
-            ConservationColourScheme ccs = (ConservationColourScheme) av.\r
-                getGlobalColourScheme();\r
+          if (  av.getGlobalColourScheme()!=null\r
+             && av.getGlobalColourScheme().conservationApplied())\r
+            {\r
             Conservation c = new Conservation("Group",\r
                                               ResidueProperties.propHash, 3,\r
-                                              sg.sequences, sg.getStartRes(),\r
+                                              sg.getSequences(false),\r
+                                              sg.getStartRes(),\r
                                               sg.getEndRes());\r
 \r
             c.calculate();\r
             c.verdict(false, av.ConsPercGaps);\r
-            ccs = new ConservationColourScheme(c, ccs.cs);\r
+            cs.setConservation(c);\r
 \r
-            sg.cs = ccs;\r
+            sg.cs = cs;\r
 \r
           }\r
 \r