X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FTreeCanvas.java;h=e3f6c3cd0911a241b955545d8d6d968df4ac1e28;hb=b437b816507d2acc59e34f70a9cf8c7f81921681;hp=075d8cb9c8121975ae5329158cc4731c31d81489;hpb=6495cefecdc75353b5fb9e8af9e45cc7069b4cc2;p=jalview.git diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java index 075d8cb..e3f6c3c 100755 --- a/src/jalview/appletgui/TreeCanvas.java +++ b/src/jalview/appletgui/TreeCanvas.java @@ -37,15 +37,13 @@ public class TreeCanvas AlignViewport av; public static final String PLACEHOLDER = " * "; Font font; - int fontSize = 12; - boolean fitToWindow = true; boolean showDistances = false; boolean showBootstrap = false; boolean markPlaceholders = false; int offx = 20; - int offy = 20; + int offy; float threshold; @@ -59,15 +57,12 @@ public class TreeCanvas Hashtable nameHash = new Hashtable(); Hashtable nodeHash = new Hashtable(); - public TreeCanvas(AlignViewport av, NJTree tree, ScrollPane scroller, - String label) + public TreeCanvas(AlignViewport av, ScrollPane scroller) { this.av = av; - this.tree = tree; + font = av.getFont(); scrollPane = scroller; addMouseListener(this); - tree.findHeight(tree.getTopNode()); - longestName = label; setLayout(null); PaintRefresher.Register(this, av.alignment); @@ -93,6 +88,30 @@ public class TreeCanvas { this.tree = tree; tree.findHeight(tree.getTopNode()); + + // Now have to calculate longest name based on the leaves + Vector leaves = tree.findLeaves(tree.getTopNode(), new Vector()); + boolean has_placeholders = false; + longestName = ""; + + for (int i = 0; i < leaves.size(); i++) + { + SequenceNode lf = (SequenceNode) leaves.elementAt(i); + + if (lf.isPlaceholder()) + { + has_placeholders = true; + } + + if (longestName.length() < ( (Sequence) lf.element()).getName() + .length()) + { + longestName = TreeCanvas.PLACEHOLDER + + ( (Sequence) lf.element()).getName(); + } + } + + setMarkPlaceholders(has_placeholders); } public void drawNode(Graphics g, SequenceNode node, float chunk, float scale, @@ -140,7 +159,7 @@ public class TreeCanvas String nodeLabel = ""; if (showDistances && node.dist > 0) { - nodeLabel = new Format("%5.2f").form(node.dist); + nodeLabel = new Format("%-.2f").form(node.dist); } if (showBootstrap) { @@ -152,7 +171,7 @@ public class TreeCanvas } if (!nodeLabel.equals("")) { - g.drawString(nodeLabel, xstart, ypos - 10); + g.drawString(nodeLabel, xstart+2, ypos - 2); } String name = (markPlaceholders && node.isPlaceholder()) ? @@ -161,7 +180,7 @@ public class TreeCanvas int charWidth = fm.stringWidth(name) + 3; int charHeight = fm.getHeight(); - Rectangle rect = new Rectangle(xend + 20, ypos - charHeight, + Rectangle rect = new Rectangle(xend + 10, ypos - charHeight, charWidth, charHeight); nameHash.put( (SequenceI) node.element(), rect); @@ -208,7 +227,7 @@ public class TreeCanvas if (showDistances && node.dist > 0) { - g.drawString(new Format("%5.2f").form(node.dist), xstart, ypos - 5); + g.drawString(new Format("%-.2f").form(node.dist), xstart+2, ypos - 2); } } @@ -260,7 +279,7 @@ public class TreeCanvas top.count = ( (SequenceNode) top.left()).count + ( (SequenceNode) top.right()).count; } - float chunk = (float) (height - offy * 2) / top.count; + float chunk = (float) (height - offy) / top.count; pickNode(pickBox, top, chunk, wscale, width, offx, offy); } @@ -276,9 +295,9 @@ public class TreeCanvas if (node.left() == null && node.right() == null) { float height = node.height; - float dist = node.dist; + //float dist = node.dist; - int xstart = (int) ( (height - dist) * scale) + offx; + //int xstart = (int) ( (height - dist) * scale) + offx; int xend = (int) (height * scale) + offx; int ypos = (int) (node.ycount * chunk) + offy; @@ -332,9 +351,12 @@ public class TreeCanvas public void paint(Graphics g) { - font = new Font("Verdana", Font.PLAIN, fontSize); + if(tree==null) + return; + g.setFont(font); + FontMetrics fm = g.getFontMetrics(font); if (nameHash.size() == 0) @@ -358,19 +380,10 @@ public class TreeCanvas scrollPane.validate(); } - public int getFontSize() - { - return fontSize; - } - - public void setFontSize(int fontSize) - { - this.fontSize = fontSize; - repaint(); - } public void draw(Graphics g, int width, int height) { + offy = font.getSize()+10; g.setColor(Color.white); g.fillRect(0, 0, width, height); @@ -386,7 +399,7 @@ public class TreeCanvas top.count = ( (SequenceNode) top.left()).count + ( (SequenceNode) top.right()).count; } - float chunk = (float) (height - offy * 2) / top.count; + float chunk = (float) (height - offy) / top.count; drawNode(g, tree.getTopNode(), chunk, wscale, width, offx, offy); @@ -480,9 +493,25 @@ public class TreeCanvas sequences.addElement(s1); } - ColourSchemeI cs = ColourSchemeProperty.getColour(sequences, av.alignment.getWidth(), - ColourSchemeProperty.getColourName(av.getGlobalColourScheme())); + ColourSchemeI cs = null; + if (av.getGlobalColourScheme() != null) + { + if (av.getGlobalColourScheme() instanceof UserColourScheme) + { + cs = new UserColourScheme( + ( (UserColourScheme) av.getGlobalColourScheme()).getColours()); + + } + else + cs = ColourSchemeProperty.getColour(sequences, + av.alignment.getWidth(), + ColourSchemeProperty.getColourName( + av.getGlobalColourScheme())); + + cs.setThreshold(av.getGlobalColourScheme().getThreshold(), + av.getIgnoreGapsConsensus()); + } SequenceGroup sg = new SequenceGroup(sequences, "TreeGroup", cs, true, true,