From: gmungoc Date: Tue, 30 Jul 2019 12:41:35 +0000 (+0100) Subject: JAL-3364 use larger of top/bottom 'auto id width' for split frame image X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a7d5ffd03eeb334a09f94f3ea741d366e0f12fbe;p=jalview.git JAL-3364 use larger of top/bottom 'auto id width' for split frame image --- diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 3c86653..b77f9db 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -1205,21 +1205,43 @@ public class AlignmentPanel extends GAlignmentPanel implements { type.getLabel() }), pSessionId); } } + + /* + * cache preferences in case we need to fudge them for export of + * split frame with 'protein scaled to codons' and 'auto id width' + */ + + final boolean autoIdWidth = Cache.getDefault("FIGURE_AUTOIDWIDTH", + false); + final Integer fixedIdWidth = Cache + .getIntegerProperty("FIGURE_FIXEDIDWIDTH"); + try { /* * if exporting a split frame image, the graphics object has * width: maximum of the top and bottom image widths * height: sum of the top and bottom image heights + * if 'protein scaled to codons' and 'auto id width', fudge + * to a fixed width (and restore preferences afterwards) */ - AlignmentPanel comp = null; + AlignmentPanel complement = null; AlignmentDimension dim1 = getAlignmentDimension(); AlignmentDimension dim2 = new AlignmentDimension(0, 0); + if (forSplitFrame) { - comp = ((AlignViewport) av.getCodingComplement()) + complement = ((AlignViewport) av.getCodingComplement()) .getAlignPanel(); - dim2 = comp.getAlignmentDimension(); + dim2 = complement.getAlignmentDimension(); + if (autoIdWidth && av.isScaleProteinAsCdna()) + { + int w1 = this.getVisibleIdWidth(false); + int w2 = complement.getVisibleIdWidth(false); + Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.FALSE.toString()); + Cache.setProperty("FIGURE_FIXEDIDWIDTH", + String.valueOf(Math.max(w1, w2))); + } } final int graphicsHeight = dim1.height + dim2.height + borderBottomOffset; @@ -1258,12 +1280,12 @@ public class AlignmentPanel extends GAlignmentPanel implements // graphics.drawString("Hello world", 0, 0); if (av.getCodingComplement().getWrapAlignment()) { - comp.printWrappedAlignment(dim2.width, + complement.printWrappedAlignment(dim2.width, dim2.height + borderBottomOffset, 0, graphics, false); } else { - comp.printUnwrapped(dim2.width, dim2.height, 0, graphics, + complement.printUnwrapped(dim2.width, dim2.height, 0, graphics, graphics); } } @@ -1279,6 +1301,15 @@ public class AlignmentPanel extends GAlignmentPanel implements } catch (Exception ex) { ex.printStackTrace(); + } finally + { + /* + * restore preference settings in case they were fudged + */ + Cache.setProperty("FIGURE_AUTOIDWIDTH", + String.valueOf(autoIdWidth)); + Cache.setProperty("FIGURE_FIXEDIDWIDTH", + String.valueOf(fixedIdWidth)); } }