From a19aa5efc2e64c17927336f422adde1837c27042 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Fri, 4 Aug 2023 16:28:09 +0100 Subject: [PATCH] JAL-244 Adjust wrapped alignment widths to always maintain a visible wrapped sequence width (and also avoid zero divisions) --- src/jalview/gui/AlignmentPanel.java | 20 +++++++++++++++++--- src/jalview/gui/IdwidthAdjuster.java | 12 ++++++++++++ src/jalview/gui/SeqCanvas.java | 14 ++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 98639be..63455cb 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -886,10 +886,24 @@ public class AlignmentPanel extends GAlignmentPanel implements public void paintComponent(Graphics g) { invalidate(); // needed so that the id width adjuster works correctly - Dimension d = getIdPanel().getIdCanvas().getPreferredSize(); - idPanelHolder.setPreferredSize(d); - hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12)); + int idWidth = d.width; + + // check wrapped alignment as at least 1 residue width + if (av.getWrapAlignment()) + { + SeqCanvas sc = this.getSeqPanel().seqCanvas; + if (sc != null && sc.getWidth() < sc.getMinimumWrappedCanvasWidth()) + { + // need to make some adjustments + idWidth -= (sc.getMinimumWrappedCanvasWidth() - sc.getWidth()); + av.setIdWidth(idWidth); + validateAnnotationDimensions(false); + } + } + + idPanelHolder.setPreferredSize(new Dimension(idWidth, d.height)); + hscrollFillerPanel.setPreferredSize(new Dimension(idWidth, 12)); validate(); // needed so that the id width adjuster works correctly diff --git a/src/jalview/gui/IdwidthAdjuster.java b/src/jalview/gui/IdwidthAdjuster.java index 6de3c97..8a6c7eb 100755 --- a/src/jalview/gui/IdwidthAdjuster.java +++ b/src/jalview/gui/IdwidthAdjuster.java @@ -136,6 +136,18 @@ public class IdwidthAdjuster extends JPanel return; } + /* + * don't allow residue width to be < 1 in wrapped format + */ + if (viewport.getWrapAlignment()) + { + SeqCanvas sc = ap.getSeqPanel().seqCanvas; + if (sc != null && sc.getWrappedCanvasWidth(sc.getWidth() - dif) < 1) + { + return; + } + } + oldX = evt.getX(); /* diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index d15cdcf..19d7c21 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -550,6 +550,20 @@ public class SeqCanvas extends JPanel implements ViewportListenerI return (canvasWidth - labelWidthEast - labelWidthWest) / charWidth; } + public int getMinimumWrappedCanvasWidth() + { + int charWidth = av.getCharWidth(); + FontMetrics fm = getFontMetrics(av.getFont()); + int labelWidth = 0; + if (av.getScaleRightWrapped() || av.getScaleLeftWrapped()) + { + labelWidth = getLabelWidth(fm); + } + labelWidthEast = av.getScaleRightWrapped() ? labelWidth : 0; + labelWidthWest = av.getScaleLeftWrapped() ? labelWidth : 0; + return labelWidthEast + labelWidthWest + charWidth; + } + /** * Returns a pixel width sufficient to show the largest sequence coordinate * (end position) in the alignment, calculated as the FontMetrics width of -- 1.7.10.2