X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=31277319d6333abfe6c5be9e65270eb2f8942a8c;hb=5d225e1798ef42d0c49784f9ef24e76e2d0cf014;hp=c7c03b341a133bf2b92fdc4e7d4a731f312d7be3;hpb=15c3c0e89d9157187e1ccc6962b115cb255dd04a;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index c7c03b3..3127731 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -302,7 +302,11 @@ public class AlignmentPanel extends GAlignmentPanel implements /** * Calculate the width of the alignment labels based on the displayed names - * and any bounds on label width set in preferences. + * and any bounds on label width set in preferences. Also includes annotations + * not actually visible. + * + * FIXME JAL-244 JAL-4091 - doesn't include sequence associated annotation + * label decorators and only called during tests * * @param maxwidth * -1 or maximum width allowed for IdWidth @@ -313,7 +317,17 @@ public class AlignmentPanel extends GAlignmentPanel implements { return calculateIdWidth(maxwidth, true, false); } - + /** + * Calculate the width of the alignment labels based on the displayed names + * and any bounds on label width set in preferences. + * + * @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 - + * @return Dimension giving the maximum width of the alignment label panel + * that should be used. + */ public Dimension calculateIdWidth(int maxwidth, boolean includeAnnotations, boolean visibleOnly) { @@ -338,28 +352,10 @@ public class AlignmentPanel extends GAlignmentPanel implements // Also check annotation label widths if (includeAnnotations && al.getAlignmentAnnotation() != null) { - if (Jalview.isHeadlessMode()) - { - AnnotationLabels aal = this.getAlabels(); - int stringWidth = aal.drawLabels(null, false, idWidth, false, fm); - 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); @@ -566,7 +562,7 @@ public class AlignmentPanel extends GAlignmentPanel implements // this is called after loading new annotation onto alignment if (alignFrame.getHeight() == 0) { - System.out.println("NEEDS FIXING"); + jalview.bin.Console.outPrintln("NEEDS FIXING"); } validateAnnotationDimensions(true); addNotify(); @@ -596,14 +592,20 @@ public class AlignmentPanel extends GAlignmentPanel implements annotationHeight); hscroll.addNotify(); - annotationScroller.setPreferredSize( - new Dimension(annotationScroller.getWidth(), annotationHeight)); - Dimension e = idPanel.getSize(); - alabels.setSize(new Dimension(e.width, annotationHeight)); + int idWidth = e.width; + boolean manuallyAdjusted = this.getIdPanel().getIdCanvas() + .manuallyAdjusted(); + annotationScroller.setPreferredSize(new Dimension( + manuallyAdjusted ? idWidth : annotationScroller.getWidth(), + annotationHeight)); + + alabels.setPreferredSize(new Dimension(idWidth, annotationHeight)); annotationSpaceFillerHolder.setPreferredSize(new Dimension( - annotationSpaceFillerHolder.getWidth(), annotationHeight)); + manuallyAdjusted ? idWidth + : annotationSpaceFillerHolder.getWidth(), + annotationHeight)); annotationScroller.validate(); annotationScroller.addNotify(); ap.validate(); @@ -622,7 +624,7 @@ public class AlignmentPanel extends GAlignmentPanel implements boolean wrap = av.getWrapAlignment(); ViewportRanges ranges = av.getRanges(); ranges.setStartSeq(0); - scalePanelHolder.setVisible(!wrap); + // scalePanelHolder.setVisible(!wrap); hscroll.setVisible(!wrap); // Allow idPanel width adjustment in wrap mode idwidthAdjuster.setVisible(true); @@ -880,10 +882,27 @@ 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); + av.getAlignPanel().getIdPanel().getIdCanvas() + .setManuallyAdjusted(true); + + 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 @@ -974,8 +993,16 @@ public class AlignmentPanel extends GAlignmentPanel implements Graphics idGraphics, Graphics alignmentGraphics) throws PrinterException { - final int 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. @@ -1024,6 +1051,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) */ @@ -1040,8 +1070,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); + selection, false,idWidth); idGraphics.setFont(av.getFont()); idGraphics.translate(0, -scaleHeight); @@ -1065,7 +1096,7 @@ public class AlignmentPanel extends GAlignmentPanel implements int offset = getAlabels().getScrollOffset(); idGraphics.translate(0, -offset); idGraphics.translate(0, alignmentDrawnHeight); - getAlabels().drawComponent(idGraphics, idWidth); + getAlabels().drawComponentNotGUI(idGraphics, idWidth); idGraphics.translate(0, -alignmentDrawnHeight); /* @@ -1146,7 +1177,7 @@ public class AlignmentPanel extends GAlignmentPanel implements * draw sequence ids and annotation labels (if shown) */ IdCanvas idCanvas = getIdPanel().getIdCanvas(); - idCanvas.drawIdsWrapped((Graphics2D) g, av, 0, totalHeight); + idCanvas.drawIdsWrappedNoGUI((Graphics2D) g, av, 0, totalHeight); g.translate(idWidth, 0); @@ -1188,7 +1219,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"); @@ -1206,7 +1237,7 @@ public class AlignmentPanel extends GAlignmentPanel implements throws ImageOutputException { makeAlignmentImage(type, file, renderer, - BitmapImageSizing.nullBitmapImageSizing()); + BitmapImageSizing.defaultBitmapImageSizing()); } /**