X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FTreeCanvas.java;h=b4fd7465772d65d18cc40c69eaafbbce8d2016a4;hb=b2319fcc38be5c500ed7cafc014cf9da96a4ce98;hp=672d2006d368df0606e451de104da936310a753f;hpb=8a5c39442bced20fc95272efe6d3176719ca3f15;p=jalview.git diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 672d200..b4fd746 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 = 12; + 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; @@ -77,6 +77,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, public TreeCanvas(AlignViewport av, JScrollPane scroller) { this.av = av; + font = av.getFont(); scrollPane = scroller; addMouseListener(this); PaintRefresher.Register(this, av.alignment); @@ -194,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) @@ -209,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); @@ -231,12 +232,12 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, { 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 @@ -272,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); } } } @@ -339,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); } @@ -523,18 +524,15 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, public void paintComponent(Graphics g) { super.paintComponent(g); + g.setFont(font); + if(tree==null) { - g.setFont(new Font("Verdana", Font.PLAIN, 18)); g.drawString("Calculating tree....", 20, getHeight()/2); } else { - - font = new Font("Verdana", Font.PLAIN, fontSize); - g.setFont(font); - - FontMetrics fm = g.getFontMetrics(font); + fm = g.getFontMetrics(font); if (nameHash.size() == 0) { @@ -560,24 +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; + this.font = font; repaint(); } @@ -596,7 +585,13 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, g2.setColor(Color.white); g2.fillRect(0, 0, width, height); - labelLength = g2.getFontMetrics(font).stringWidth(longestName) + 20; //20 allows for scrollbar + g2.setFont(font); + + 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(); @@ -608,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);