From 73351640358c1b1fafd2612ac91b706ec4f80f7d Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 20 Jul 2023 12:32:43 +0100 Subject: [PATCH] JAL-244 More accurate width calculation, allow increased id width adjustment after manual adjustment --- src/jalview/gui/AlignmentPanel.java | 23 ++++++++++++++++------- src/jalview/gui/AnnotationLabels.java | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index db193f1..2396329 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -50,6 +50,7 @@ import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; import jalview.bin.Console; import jalview.bin.Jalview; +import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultsI; @@ -296,7 +297,7 @@ public class AlignmentPanel extends GAlignmentPanel implements int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300); int idWidth = Math.min(afwidth - 200, 2 * afwidth / 3); int maxwidth = Math.max(IdwidthAdjuster.MIN_ID_WIDTH, idWidth); - return calculateIdWidth(-1); + return calculateIdWidth(-1, false, true); } /** @@ -310,6 +311,12 @@ public class AlignmentPanel extends GAlignmentPanel implements */ protected Dimension calculateIdWidth(int maxwidth) { + return calculateIdWidth(maxwidth, true, false); + } + + public Dimension calculateIdWidth(int maxwidth, + boolean includeAnnotations, boolean visibleOnly) + { Container c = new Container(); FontMetrics fm = c.getFontMetrics( @@ -329,18 +336,20 @@ public class AlignmentPanel extends GAlignmentPanel implements } // Also check annotation label widths - i = 0; - - if (al.getAlignmentAnnotation() != null) + if (includeAnnotations && al.getAlignmentAnnotation() != null) { fm = c.getFontMetrics(getAlabels().getFont()); - while (i < al.getAlignmentAnnotation().length) + for (i = 0; i < al.getAlignmentAnnotation().length; i++) { - String label = al.getAlignmentAnnotation()[i].label; + AlignmentAnnotation aa = al.getAlignmentAnnotation()[i]; + if (visibleOnly && !aa.visible) + { + continue; + } + String label = aa.label; int stringWidth = fm.stringWidth(label); idWidth = Math.max(idWidth, stringWidth); - i++; } } diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index d459217..ffc565c 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -1194,7 +1194,7 @@ public class AnnotationLabels extends JPanel int width = givenWidth; IdwidthAdjuster iwa = ap.idwidthAdjuster; if ((Cache.getDefault(ADJUST_ANNOTATION_LABELS_WIDTH_PREF, true) - || Jalview.isHeadlessMode()) && !iwa.manuallyAdjusted()) + || Jalview.isHeadlessMode())) { Graphics2D g2d = (Graphics2D) g; Graphics dummy = g2d.create(); -- 1.7.10.2