From: Ben Soares Date: Fri, 4 Aug 2023 15:28:09 +0000 (+0100) Subject: JAL-244 Adjust wrapped alignment widths to always maintain a visible wrapped sequence... X-Git-Tag: Release_2_11_4_0~216^2~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a19aa5efc2e64c17927336f422adde1837c27042;p=jalview.git JAL-244 Adjust wrapped alignment widths to always maintain a visible wrapped sequence width (and also avoid zero divisions) --- 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