From 20947b2cc413aba4422bf03466c5f4a60c23bd9b Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 29 Aug 2012 16:27:08 +0100 Subject: [PATCH] JAL-1153 JAL-1155 improved layout and allowed labels to rescale for grouped linegraphs --- src/jalview/gui/AnnotationLabels.java | 60 ++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 6d32c04..665537c 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -23,6 +23,7 @@ import java.util.regex.Pattern; import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.*; +import java.awt.geom.AffineTransform; import java.awt.image.*; import javax.swing.*; @@ -832,12 +833,16 @@ public class AnnotationLabels extends JPanel implements MouseListener, int x = 0; int graphExtras = 0; int offset = 0; - + Font baseFont = g.getFont(); + FontMetrics baseMetrics = fm; + int ofontH = fontHeight; + boolean visible = true; if (aa != null) { hasHiddenRows = false; for (int i = 0; i < aa.length; i++) { + visible = true; g.setColor(Color.black); if (!aa[i].visible) @@ -870,30 +875,55 @@ public class AnnotationLabels extends JPanel implements MouseListener, groupSize++; } } - if (groupSize * (fontHeight + 8) < aa[i].height) { graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2; } - - for (int gg = 0; gg < aa.length; gg++) + else { - if (aa[gg].graphGroup == aa[i].graphGroup) + // scale font to fit + float h = aa[i].height / (float) groupSize, s; + if (h < 9) { - x = width - fm.stringWidth(aa[gg].label) - 3; - g.drawString(aa[gg].label, x, y - graphExtras); - if (aa[gg].annotations[0] != null) + visible = false; + } + else + { + fontHeight = -8 + (int) h; + s = ((float) fontHeight) / (float) ofontH; + Font f = baseFont.deriveFont(AffineTransform + .getScaleInstance(s, s)); + g.setFont(f); + fm = g.getFontMetrics(); + graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2; + } + } + if (visible) + { + for (int gg = 0; gg < aa.length; gg++) + { + if (aa[gg].graphGroup == aa[i].graphGroup) { - g.setColor(aa[gg].annotations[0].colour); + x = width - fm.stringWidth(aa[gg].label) - 3; + g.drawString(aa[gg].label, x, y - graphExtras); + + if (aa[gg]._linecolour != null) + { + + g.setColor(aa[gg]._linecolour); + g.drawLine(x, y - graphExtras + 3, + x + fm.stringWidth(aa[gg].label), y - graphExtras + + 3); + } + + g.setColor(Color.black); + graphExtras += fontHeight + 8; } - - g.drawLine(x, y - graphExtras - 3, - x + fm.stringWidth(aa[gg].label), y - graphExtras - 3); - - g.setColor(Color.black); - graphExtras += fontHeight + 8; } } + g.setFont(baseFont); + fm = baseMetrics; + fontHeight = ofontH; } else { -- 1.7.10.2