From: James Procter Date: Sun, 1 Oct 2023 13:03:57 +0000 (+0100) Subject: JAL-244 JAL-4091 allow calculation of label id width off screen including sequence... X-Git-Tag: Release_2_11_4_0~147 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=56b3e093761bc8b409ffc66fae03d5be40edea89;p=jalview.git JAL-244 JAL-4091 allow calculation of label id width off screen including sequence ids for sequence associated annotation --- diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index cd9b70c..baf9e26 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -317,7 +317,17 @@ public class AlignmentPanel extends GAlignmentPanel implements { return calculateIdWidth(maxwidth, true, false); } - + /** + * Calculate the width of the alignment labels based on the displayed names + * and any bounds on label width set in preferences. + * + * @param maxwidth + * -1 or maximum width allowed for IdWidth + * @param includeAnnotations - when true includes width of any additional marks in annotation id panel + * @param visibleOnly - + * @return Dimension giving the maximum width of the alignment label panel + * that should be used. + */ public Dimension calculateIdWidth(int maxwidth, boolean includeAnnotations, boolean visibleOnly) { @@ -346,7 +356,7 @@ public class AlignmentPanel extends GAlignmentPanel implements { AnnotationLabels aal = getAlabels(); int stringWidth = aal.drawLabels(null, false, idWidth, false, false, - fm); + fm,false); idWidth = Math.max(idWidth, stringWidth); } else diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index d9d6b9f..a3f7e00 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -1211,7 +1211,7 @@ public class AnnotationLabels extends JPanel Graphics2D g2d = (Graphics2D) g; Graphics dummy = g2d.create(); int newAnnotationIdWidth = drawLabels(dummy, clip, width, false, forGUI, - null); + null, false); dummy.dispose(); Dimension d = ap.calculateDefaultAlignmentIdWidth(); int alignmentIdWidth = d.width; @@ -1245,10 +1245,10 @@ public class AnnotationLabels extends JPanel } else { - int newAnnotationIdWidth = drawLabels(g, clip, width, false, forGUI, null); + int newAnnotationIdWidth = drawLabels(g, clip, width, false, forGUI, null, false); width = Math.max(newAnnotationIdWidth, givenWidth); } - drawLabels(g, clip, width, true, forGUI, null); + drawLabels(g, clip, width, true, forGUI, null, false); } /** @@ -1257,8 +1257,6 @@ public class AnnotationLabels extends JPanel * occur, but the widest label width will be returned. If g is null then * fmetrics must be supplied. * - * Returns the width of the annotation labels. - * * @param g * Graphics2D instance (used for rendering and font scaling if no fmetrics supplied) * @param clip @@ -1270,9 +1268,11 @@ public class AnnotationLabels extends JPanel * @param forGUI - when false, GUI relevant marks like indicators for dragging annotation panel height are not rendered * @param fmetrics * FontMetrics if Graphics object g is null + * @param includeHidden - when true returned width includes labels in hidden row width calculation + * @return the width of the annotation labels. */ public int drawLabels(Graphics g0, boolean clip, int width, - boolean actuallyDraw, boolean forGUI, FontMetrics fmetrics) + boolean actuallyDraw, boolean forGUI, FontMetrics fmetrics, boolean includeHidden) { if (clip) { @@ -1361,7 +1361,7 @@ public class AnnotationLabels extends JPanel for (int i = 0; i < aa.length; i++) { visible = true; - if (!aa[i].visible) + if (!aa[i].visible && !includeHidden) { hasHiddenRows = true; continue; @@ -1369,7 +1369,7 @@ public class AnnotationLabels extends JPanel olY = y; // look ahead to next annotation for (nexAA = i + 1; nexAA < aa.length - && !aa[nexAA].visible; nexAA++) + && (!aa[nexAA].visible && includeHidden); nexAA++) ; y += aa[i].height; if (clip) diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index aaded9e..8e49e59 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -454,7 +454,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI if (!manuallyAdjusted()) { int getAnnotationsIdWidth = labels.drawLabels(g, false, -1, false,forGUI, - null); + null, false); thisIdWidth = idWidth < 0 ? getAnnotationsIdWidth : idWidth; if (thisIdWidth > getWidth) {