X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=fe6477e9b5bff1b8c348a03ba342027aaf9db6a4;hb=1140532d01b32b648e7e5b17ea717ae790625f8f;hp=baf9e2654d8a8223fd16460d20490f6986d98e9e;hpb=56b3e093761bc8b409ffc66fae03d5be40edea89;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index baf9e26..fe6477e 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -256,8 +256,10 @@ public class AlignmentPanel extends GAlignmentPanel implements /** * Calculates the width of the alignment labels based on the displayed names - * and any bounds on label width set in preferences. The calculated width is - * also set as a property of the viewport. + * and any bounds on label width set in preferences. + * + * The calculated width is set as a property of the viewport and the layout is + * updated. * * @return Dimension giving the maximum width of the alignment label panel * that should be used. @@ -294,10 +296,19 @@ public class AlignmentPanel extends GAlignmentPanel implements public Dimension calculateDefaultAlignmentIdWidth() { + return calculateIdWidth(-1, false, false); + } + /** + * pre 2.11.3 Id width calculation - used when importing old projects only + * @return + */ + public int getLegacyIdWidth() + { 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, false, false); + Dimension w = calculateIdWidthOrLegacy(true, maxwidth, false, false); + return w.width; } /** @@ -324,13 +335,27 @@ public class AlignmentPanel extends GAlignmentPanel implements * @param maxwidth * -1 or maximum width allowed for IdWidth * @param includeAnnotations - when true includes width of any additional marks in annotation id panel - * @param visibleOnly - + * @param visibleOnly - when true, ignore label widths for hidden annotation rows * @return Dimension giving the maximum width of the alignment label panel * that should be used. */ public Dimension calculateIdWidth(int maxwidth, boolean includeAnnotations, boolean visibleOnly) { + return calculateIdWidthOrLegacy(false, maxwidth, includeAnnotations, visibleOnly); + } + + /** + * legacy mode or post 2.11.3 ID width calculation + * @param legacy - uses annotation labels, not rendered label width (excludes additional decorators) + * @param maxwidth + * @param includeAnnotations + * @param visibleOnly + * @return + */ + private Dimension calculateIdWidthOrLegacy(boolean legacy, int maxwidth, + boolean includeAnnotations, boolean visibleOnly) + { Container c = new Container(); FontMetrics fm = c.getFontMetrics( @@ -352,17 +377,17 @@ public class AlignmentPanel extends GAlignmentPanel implements // Also check annotation label widths if (includeAnnotations && al.getAlignmentAnnotation() != null) { - if (Jalview.isHeadlessMode()) + fm = c.getFontMetrics(getAlabels().getFont()); + + if (!legacy || Jalview.isHeadlessMode()) { AnnotationLabels aal = getAlabels(); int stringWidth = aal.drawLabels(null, false, idWidth, false, false, - fm,false); + fm, !visibleOnly); idWidth = Math.max(idWidth, stringWidth); } else { - fm = c.getFontMetrics(getAlabels().getFont()); - for (i = 0; i < al.getAlignmentAnnotation().length; i++) { AlignmentAnnotation aa = al.getAlignmentAnnotation()[i]; @@ -581,7 +606,7 @@ public class AlignmentPanel extends GAlignmentPanel implements // this is called after loading new annotation onto alignment if (alignFrame.getHeight() == 0) { - jalview.bin.Console.outPrintln("NEEDS FIXING"); + jalview.bin.Console.error("adjustAnnotationHeight called with zero height alignment window"); } validateAnnotationDimensions(true); addNotify(); @@ -614,7 +639,7 @@ public class AlignmentPanel extends GAlignmentPanel implements Dimension e = idPanel.getSize(); int idWidth = e.width; boolean manuallyAdjusted = this.getIdPanel().getIdCanvas() - .manuallyAdjusted(); + .isManuallyAdjusted(); annotationScroller.setPreferredSize(new Dimension( manuallyAdjusted ? idWidth : annotationScroller.getWidth(), annotationHeight)); @@ -1012,16 +1037,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. @@ -1070,6 +1095,9 @@ public class AlignmentPanel extends GAlignmentPanel implements } final int alignmentDrawnHeight = (endSeq - startSeq) * charHeight + 3; + alignmentGraphics.setColor(Color.white); + alignmentGraphics.fillRect(0, 0, pageWidth, pageHeight+scaleHeight); + /* * draw the Scale at horizontal offset, then reset to top left (0, 0) */ @@ -1086,8 +1114,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 +1263,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"); @@ -1244,7 +1273,7 @@ public class AlignmentPanel extends GAlignmentPanel implements } int w = getIdPanel().getWidth(); - w = this.calculateIdWidth(-1, true, true).width; + w = calculateIdWidth(-1, true, true).width; return (w > 0 ? w : calculateIdWidth().width); } @@ -1872,5 +1901,4 @@ public class AlignmentPanel extends GAlignmentPanel implements overviewPanel = null; } } - }