From: James Procter Date: Sun, 1 Oct 2023 16:06:27 +0000 (+0100) Subject: JAL-244 export image with full width IDs regardless of UI X-Git-Tag: Release_2_11_4_0~146 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4c0d7ee1c9115a5d9ebabc6b34bda6b1af7b9fc4;p=jalview.git JAL-244 export image with full width IDs regardless of UI --- diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index baf9e26..ae561e7 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -352,29 +352,10 @@ public class AlignmentPanel extends GAlignmentPanel implements // Also check annotation label widths if (includeAnnotations && al.getAlignmentAnnotation() != null) { - if (Jalview.isHeadlessMode()) - { - AnnotationLabels aal = getAlabels(); - int stringWidth = aal.drawLabels(null, false, idWidth, false, false, - fm,false); - idWidth = Math.max(idWidth, stringWidth); - } - else - { - fm = c.getFontMetrics(getAlabels().getFont()); - - for (i = 0; i < al.getAlignmentAnnotation().length; i++) - { - AlignmentAnnotation aa = al.getAlignmentAnnotation()[i]; - if (visibleOnly && !aa.visible) - { - continue; - } - String label = aa.label; - int stringWidth = fm.stringWidth(label); - idWidth = Math.max(idWidth, stringWidth); - } - } + AnnotationLabels aal = getAlabels(); + int stringWidth = aal.drawLabels(null, false, idWidth, false, false, + fm, !visibleOnly); + idWidth = Math.max(idWidth, stringWidth); } int w = maxwidth < 0 ? idWidth : Math.min(maxwidth, idWidth); @@ -1012,16 +993,16 @@ public class AlignmentPanel extends GAlignmentPanel implements Graphics idGraphics, Graphics alignmentGraphics) throws PrinterException { - final int idWidth; - if (getIdPanel()!=null && getIdPanel().getWidth()>0) - { - // use the current IdPanel's width, if its set and non-zero - idWidth = getIdPanel().getWidth(); - } else { - // otherwise calculate it - idWidth = getVisibleIdWidth(false); - } - + final int idWidth, idWidthForGui; + // otherwise calculate it + idWidth = getVisibleIdWidth(false); +// if (getIdPanel()!=null && getIdPanel().getWidth()>0) +// { +// // use the current IdPanel's width, if its set and non-zero +// idWidthForGui = getIdPanel().getWidth(); +// } else { +// idWidthForGui=0; +// } /* * Get the horizontal offset to where we draw the sequences. * This is idWidth if using a single Graphics context, else zero. @@ -1086,8 +1067,9 @@ public class AlignmentPanel extends GAlignmentPanel implements IdCanvas idCanvas = getIdPanel().getIdCanvas(); List selection = av.getSelectionGroup() == null ? null : av.getSelectionGroup().getSequences(null); + idCanvas.drawIds((Graphics2D) idGraphics, av, startSeq, endSeq - 1, - selection, false); + selection, false,idWidth); idGraphics.setFont(av.getFont()); idGraphics.translate(0, -scaleHeight); @@ -1234,7 +1216,7 @@ public class AlignmentPanel extends GAlignmentPanel implements // see if rendering offscreen - check preferences and calc width accordingly if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false)) { - return calculateIdWidth(-1).width; + return calculateIdWidth(-1,true,true).width; } Integer idwidth = onscreen ? null : Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH"); diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 8e49e59..2df84a9 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -199,7 +199,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI gg.translate(0, transY); - drawIds(gg, av, ss, es, searchResults,true); + drawIds(gg, av, ss, es, searchResults, true, getWidth()); gg.translate(0, -transY); @@ -256,7 +256,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI gg.fillRect(0, 0, getWidth(), imgHeight); drawIds(gg, av, av.getRanges().getStartSeq(), - av.getRanges().getEndSeq(), searchResults,true); + av.getRanges().getEndSeq(), searchResults,true, getWidth()); gg.dispose(); @@ -274,9 +274,12 @@ public class IdCanvas extends JPanel implements ViewportListenerI * @param startSeq * @param endSeq * @param selection + * @param forGUI when false rendering for print + * @param panelWidth width used to calculate righthand margin - usually idCanvas.getWidth() + * */ void drawIds(Graphics2D g, AlignViewport alignViewport, - final int startSeq, final int endSeq, List selection, boolean forGUI) + final int startSeq, final int endSeq, List selection, boolean forGUI, int panelWidth) { Font font = alignViewport.getFont(); if (alignViewport.isSeqNameItalics()) @@ -309,7 +312,6 @@ public class IdCanvas extends JPanel implements ViewportListenerI } // Now draw the id strings - int panelWidth = getWidth(); int xPos = 0; // Now draw the id strings