From 4f8aeb51377ccad6ecf76fcd1e57c35517a839c1 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 14 Feb 2011 10:51:25 +0000 Subject: [PATCH] refactored annotation panel height calculation --- src/jalview/appletgui/AnnotationPanel.java | 34 +++++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index fb7bce5..fedf796 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -355,7 +355,7 @@ public class AnnotationPanel extends Panel implements AdjustmentListener, av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0; } graphStretchY = evt.getY(); - adjustPanelHeight(); + calcPanelHeight(); needValidating = true; ap.paintAlignment(true); } @@ -426,7 +426,21 @@ public class AnnotationPanel extends Panel implements AdjustmentListener, public int adjustPanelHeight(boolean repaint) { - + int height = calcPanelHeight(); + this.setSize(new Dimension(getSize().width, height)); + if (repaint) + { + repaint(); + } + return height; + } + /** + * calculate the height for visible annotation, revalidating bounds where necessary + * ABSTRACT GUI METHOD + * @return total height of annotation + */ + public int calcPanelHeight() + { // setHeight of panels AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); int height = 0; @@ -469,11 +483,6 @@ public class AnnotationPanel extends Panel implements AdjustmentListener, { height = 20; } - this.setSize(new Dimension(getSize().width, height)); - if (repaint) - { - repaint(); - } return height; @@ -516,13 +525,16 @@ public class AnnotationPanel extends Panel implements AdjustmentListener, public void paint(Graphics g) { - - imgWidth = getSize().width; + Dimension d = getSize(); + imgWidth = d.width; // (av.endRes - av.startRes + 1) * av.charWidth; - + if (imgWidth<1 || d.height<1) + { + return; + } if (image == null || imgWidth != image.getWidth(this)) { - image = createImage(imgWidth, ap.annotationPanel.getSize().height); + image = createImage(imgWidth, d.height); gg = image.getGraphics(); gg.setFont(av.getFont()); fm = gg.getFontMetrics(); -- 1.7.10.2