X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FTreeCanvas.java;h=1628f58d1c911e86b752e51252897843b2c850e4;hb=6bfaf3d3a82e4eece77dc1c2d83aede7c4dbb690;hp=eea181f476701e4d2a58abcf7b5068100d337692;hpb=eee02848424734a9466de35ff19636377652e59b;p=jalview.git diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index eea181f..1628f58 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -50,13 +50,13 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, JScrollPane scrollPane; AlignViewport av; Font font; - int fontSize; + FontMetrics fm; boolean fitToWindow = true; boolean showDistances = false; boolean showBootstrap = false; boolean markPlaceholders = false; int offx = 20; - int offy = 20; + int offy; float threshold; String longestName; int labelLength = -1; @@ -195,7 +195,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (showDistances && (node.dist > 0)) { - nodeLabel = new Format("%5.2f").form(node.dist); + nodeLabel = new Format("%-.2f").form(node.dist); } if (showBootstrap) @@ -210,16 +210,16 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (!nodeLabel.equals("")) { - g.drawString(nodeLabel, xstart, ypos - 10); + g.drawString(nodeLabel, xstart+2, ypos - 2); } String name = (markPlaceholders && node.isPlaceholder()) ? (PLACEHOLDER + node.getName()) : node.getName(); - FontMetrics fm = g.getFontMetrics(font); + int charWidth = fm.stringWidth(name) + 3; - int charHeight = fm.getHeight(); + int charHeight = font.getSize(); - Rectangle rect = new Rectangle(xend + 20, ypos - charHeight, + Rectangle rect = new Rectangle(xend+10, ypos-charHeight/2, charWidth, charHeight); nameHash.put((SequenceI) node.element(), rect); @@ -228,16 +228,16 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, SequenceGroup selected = av.getSelectionGroup(); if ((selected != null) && - selected.sequences.contains((SequenceI) node.element())) + selected.getSequences(false).contains((SequenceI) node.element())) { g.setColor(Color.gray); - g.fillRect(xend + 10, ypos - charHeight + 3, charWidth, + g.fillRect(xend + 10, ypos-charHeight/2, charWidth, charHeight); g.setColor(Color.white); } - g.drawString(name, xend + 10, ypos); + g.drawString(name, xend + 10, ypos+fm.getDescent()); g.setColor(Color.black); } else @@ -273,8 +273,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, 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).trim(), xstart+2, + ypos - 2); } } } @@ -340,7 +340,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, ((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); } @@ -532,7 +532,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } else { - FontMetrics fm = g.getFontMetrics(font); + fm = g.getFontMetrics(font); if (nameHash.size() == 0) { @@ -558,25 +558,15 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getFontSize() - { - return fontSize; - } /** * DOCUMENT ME! * * @param fontSize DOCUMENT ME! */ - public void setFontSize(int fontSize) + public void setFont(Font font) { - this.fontSize = fontSize; - font = new Font(font.getName(), font.getStyle(), fontSize); + this.font = font; repaint(); } @@ -597,7 +587,11 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, g2.setFont(font); - labelLength = g2.getFontMetrics(font).stringWidth(longestName) + 20; //20 allows for scrollbar + offy = font.getSize()+10; + + fm = g2.getFontMetrics(font); + + labelLength = fm.stringWidth(longestName) + 20; //20 allows for scrollbar float wscale = (float) (width - labelLength - (offx * 2)) / tree.getMaxHeight(); @@ -609,7 +603,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, ((SequenceNode) top.right()).count; } - float chunk = (float) (height - (offy * 2)) / top.count; + float chunk = (float) (height - (offy)) / top.count; drawNode(g2, tree.getTopNode(), chunk, wscale, width, offx, offy); @@ -757,14 +751,15 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, SequenceGroup sg = new SequenceGroup(sequences, "TreeGroup", cs, true, true, false, 0, - av.alignment.getWidth()); + av.alignment.getWidth()-1); if ( av.getGlobalColourScheme()!=null && av.getGlobalColourScheme().conservationApplied()) { Conservation c = new Conservation("Group", - ResidueProperties.propHash, 3, sg.sequences, + ResidueProperties.propHash, 3, + sg.getSequences(false), sg.getStartRes(), sg.getEndRes()); c.calculate();