2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.datamodel.AlignmentI;
24 import jalview.datamodel.HiddenColumns;
25 import jalview.datamodel.SearchResultsI;
26 import jalview.datamodel.SequenceGroup;
27 import jalview.datamodel.SequenceI;
28 import jalview.datamodel.VisibleContigsIterator;
29 import jalview.renderer.ScaleRenderer;
30 import jalview.renderer.ScaleRenderer.ScaleMark;
31 import jalview.util.Comparison;
32 import jalview.viewmodel.ViewportListenerI;
33 import jalview.viewmodel.ViewportRanges;
35 import java.awt.BasicStroke;
36 import java.awt.BorderLayout;
37 import java.awt.Color;
38 import java.awt.FontMetrics;
39 import java.awt.Graphics;
40 import java.awt.Graphics2D;
41 import java.awt.RenderingHints;
42 import java.awt.Shape;
43 import java.awt.image.BufferedImage;
44 import java.beans.PropertyChangeEvent;
45 import java.util.Iterator;
46 import java.util.List;
48 import javax.swing.JComponent;
51 * The Swing component on which the alignment sequences, and annotations (if
52 * shown), are drawn. This includes scales above, left and right (if shown) in
53 * Wrapped mode, but not the scale above in Unwrapped mode.
56 public class SeqCanvas extends JComponent implements ViewportListenerI
59 * pixels gap between sequences and annotations when in wrapped mode
61 static final int SEQS_ANNOTATION_GAP = 3;
63 private static final String ZEROS = "0000000000";
65 final FeatureRenderer fr;
75 private final SequenceRenderer seqRdr;
77 private boolean fastPaint = false;
79 private boolean fastpainting = false;
81 private AnnotationPanel annotations;
84 * measurements for drawing a wrapped alignment
86 private int labelWidthEast; // label right width in pixels if shown
88 private int labelWidthWest; // label left width in pixels if shown
90 int wrappedSpaceAboveAlignment; // gap between widths
92 int wrappedRepeatHeightPx; // height in pixels of wrapped width
94 private int wrappedVisibleWidths; // number of wrapped widths displayed
96 private Graphics2D gg;
99 * Creates a new SeqCanvas object.
103 public SeqCanvas(AlignmentPanel ap)
106 fr = new FeatureRenderer(ap);
107 seqRdr = new SequenceRenderer(av);
108 setLayout(new BorderLayout());
109 PaintRefresher.Register(this, av.getSequenceSetId());
110 setBackground(Color.white);
112 av.getRanges().addPropertyChangeListener(this);
115 public SequenceRenderer getSequenceRenderer()
120 public FeatureRenderer getFeatureRenderer()
126 * Draws the scale above a region of a wrapped alignment, consisting of a
127 * column number every major interval (10 columns).
130 * the graphics context to draw on, positioned at the start (bottom
131 * left) of the line on which to draw any scale marks
133 * start alignment column (0..)
135 * end alignment column (0..)
137 * y offset to draw at
139 private void drawNorthScale(Graphics g, int startx, int endx, int ypos)
141 int charHeight = av.getCharHeight();
142 int charWidth = av.getCharWidth();
145 * white fill the scale space (for the fastPaint case)
147 g.setColor(Color.white);
148 g.fillRect(0, ypos - charHeight - charHeight / 2, getWidth(),
149 charHeight * 3 / 2 + 2);
150 g.setColor(Color.black);
152 List<ScaleMark> marks = new ScaleRenderer().calculateMarks(av, startx,
154 for (ScaleMark mark : marks)
156 int mpos = mark.column; // (i - startx - 1)
161 String mstring = mark.text;
167 g.drawString(mstring, mpos * charWidth, ypos - (charHeight / 2));
171 * draw a tick mark below the column number, centred on the column;
172 * height of tick mark is 4 pixels less than half a character
174 int xpos = (mpos * charWidth) + (charWidth / 2);
175 g.drawLine(xpos, (ypos + 2) - (charHeight / 2), xpos, ypos - 2);
181 * Draw the scale to the left or right of a wrapped alignment
184 * graphics context, positioned at the start of the scale to be drawn
186 * first column of wrapped width (0.. excluding any hidden columns)
188 * last column of wrapped width (0.. excluding any hidden columns)
190 * vertical offset at which to begin the scale
192 * if true, scale is left of residues, if false, scale is right
194 void drawVerticalScale(Graphics g, final int startx, final int endx,
195 final int ypos, final boolean left)
197 int charHeight = av.getCharHeight();
198 int charWidth = av.getCharWidth();
200 int yPos = ypos + charHeight;
204 if (av.hasHiddenColumns())
206 HiddenColumns hiddenColumns = av.getAlignment().getHiddenColumns();
207 startX = hiddenColumns.visibleToAbsoluteColumn(startx);
208 endX = hiddenColumns.visibleToAbsoluteColumn(endx);
210 FontMetrics fm = getFontMetrics(av.getFont());
212 for (int i = 0; i < av.getAlignment().getHeight(); i++)
214 SequenceI seq = av.getAlignment().getSequenceAt(i);
217 * find sequence position of first non-gapped position -
218 * to the right if scale left, to the left if scale right
220 int index = left ? startX : endX;
222 while (index >= startX && index <= endX)
224 if (!Comparison.isGap(seq.getCharAt(index)))
226 value = seq.findPosition(index);
240 * white fill the space for the scale
242 g.setColor(Color.white);
243 int y = (yPos + (i * charHeight)) - (charHeight / 5);
244 // fillRect origin is top left of rectangle
245 g.fillRect(0, y - charHeight, left ? labelWidthWest : labelWidthEast,
251 * draw scale value, right justified within its width less half a
252 * character width padding on the right
254 int labelSpace = left ? labelWidthWest : labelWidthEast;
255 labelSpace -= charWidth / 2; // leave space to the right
256 String valueAsString = String.valueOf(value);
257 int labelLength = fm.stringWidth(valueAsString);
258 int xOffset = labelSpace - labelLength;
259 g.setColor(Color.black);
260 g.drawString(valueAsString, xOffset, y);
266 * Does a fast paint of an alignment in response to a scroll. Most of the
267 * visible region is simply copied and shifted, and then any newly visible
268 * columns or rows are drawn. The scroll may be horizontal or vertical, but
269 * not both at once. Scrolling may be the result of
271 * <li>dragging a scroll bar</li>
272 * <li>clicking in the scroll bar</li>
273 * <li>scrolling by trackpad, middle mouse button, or other device</li>
274 * <li>by moving the box in the Overview window</li>
275 * <li>programmatically to make a highlighted position visible</li>
279 * columns to shift right (positive) or left (negative)
281 * rows to shift down (positive) or up (negative)
283 public void fastPaint(int horizontal, int vertical)
285 if (fastpainting || gg == null || img == null)
294 int charHeight = av.getCharHeight();
295 int charWidth = av.getCharWidth();
297 ViewportRanges ranges = av.getRanges();
298 int startRes = ranges.getStartRes();
299 int endRes = ranges.getEndRes();
300 int startSeq = ranges.getStartSeq();
301 int endSeq = ranges.getEndSeq();
305 gg.copyArea(horizontal * charWidth, vertical * charHeight,
306 img.getWidth(), img.getHeight(), -horizontal * charWidth,
307 -vertical * charHeight);
309 if (horizontal > 0) // scrollbar pulled right, image to the left
311 transX = (endRes - startRes - horizontal) * charWidth;
312 startRes = endRes - horizontal;
314 else if (horizontal < 0)
316 endRes = startRes - horizontal;
319 if (vertical > 0) // scroll down
321 startSeq = endSeq - vertical;
323 if (startSeq < ranges.getStartSeq())
324 { // ie scrolling too fast, more than a page at a time
325 startSeq = ranges.getStartSeq();
329 transY = img.getHeight() - ((vertical + 1) * charHeight);
332 else if (vertical < 0)
334 endSeq = startSeq - vertical;
336 if (endSeq > ranges.getEndSeq())
338 endSeq = ranges.getEndSeq();
342 gg.translate(transX, transY);
343 drawPanel(gg, startRes, endRes, startSeq, endSeq, 0);
344 gg.translate(-transX, -transY);
346 // Call repaint on alignment panel so that repaints from other alignment
347 // panel components can be aggregated. Otherwise performance of the
348 // overview window and others may be adversely affected.
349 av.getAlignPanel().repaint();
352 fastpainting = false;
357 public void paintComponent(Graphics g)
359 super.paintComponent(g);
361 int charHeight = av.getCharHeight();
362 int charWidth = av.getCharWidth();
364 ViewportRanges ranges = av.getRanges();
366 int width = getWidth();
367 int height = getHeight();
369 width -= (width % charWidth);
370 height -= (height % charHeight);
372 if ((img != null) && (fastPaint
373 || (getVisibleRect().width != g.getClipBounds().width)
374 || (getVisibleRect().height != g.getClipBounds().height)))
376 g.drawImage(img, 0, 0, this);
378 drawSelectionGroup((Graphics2D) g, ranges.getStartRes(),
379 ranges.getEndRes(), ranges.getStartSeq(), ranges.getEndSeq());
383 else if (width > 0 && height > 0)
386 * img is a cached version of the last view we drew, if any
387 * if we have no img or the size has changed, make a new one
389 if (img == null || width != img.getWidth()
390 || height != img.getHeight())
392 img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
393 gg = (Graphics2D) img.getGraphics();
394 gg.setFont(av.getFont());
399 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
400 RenderingHints.VALUE_ANTIALIAS_ON);
403 gg.setColor(Color.white);
404 gg.fillRect(0, 0, img.getWidth(), img.getHeight());
406 if (av.getWrapAlignment())
408 drawWrappedPanel(gg, getWidth(), getHeight(), ranges.getStartRes());
412 drawPanel(gg, ranges.getStartRes(), ranges.getEndRes(),
413 ranges.getStartSeq(), ranges.getEndSeq(), 0);
416 drawSelectionGroup(gg, ranges.getStartRes(),
417 ranges.getEndRes(), ranges.getStartSeq(), ranges.getEndSeq());
419 g.drawImage(img, 0, 0, this);
424 drawCursor(g, ranges.getStartRes(), ranges.getEndRes(),
425 ranges.getStartSeq(), ranges.getEndSeq());
430 * Draw an alignment panel for printing
433 * Graphics object to draw with
435 * start residue of print area
437 * end residue of print area
439 * start sequence of print area
441 * end sequence of print area
443 public void drawPanelForPrinting(Graphics g1, int startRes, int endRes,
444 int startSeq, int endSeq)
446 drawPanel(g1, startRes, endRes, startSeq, endSeq, 0);
448 drawSelectionGroup((Graphics2D) g1, startRes, endRes,
453 * Draw a wrapped alignment panel for printing
456 * Graphics object to draw with
458 * width of drawing area
459 * @param canvasHeight
460 * height of drawing area
462 * start residue of print area
464 public void drawWrappedPanelForPrinting(Graphics g, int canvasWidth,
465 int canvasHeight, int startRes)
467 drawWrappedPanel(g, canvasWidth, canvasHeight, startRes);
469 SequenceGroup group = av.getSelectionGroup();
472 drawWrappedSelection((Graphics2D) g, group, canvasWidth, canvasHeight,
478 * Returns the visible width of the canvas in residues, after allowing for
479 * East or West scales (if shown)
482 * the width in pixels (possibly including scales)
486 public int getWrappedCanvasWidth(int canvasWidth)
488 int charWidth = av.getCharWidth();
490 FontMetrics fm = getFontMetrics(av.getFont());
494 if (av.getScaleRightWrapped() || av.getScaleLeftWrapped())
496 labelWidth = getLabelWidth(fm);
499 labelWidthEast = av.getScaleRightWrapped() ? labelWidth : 0;
501 labelWidthWest = av.getScaleLeftWrapped() ? labelWidth : 0;
503 return (canvasWidth - labelWidthEast - labelWidthWest) / charWidth;
507 * Returns a pixel width sufficient to show the largest sequence coordinate
508 * (end position) in the alignment, calculated as the FontMetrics width of
509 * zeroes "0000000" limited to the number of decimal digits to be shown (3 for
510 * 1-10, 4 for 11-99 etc). One character width is added to this, to allow for
511 * half a character width space on either side.
516 protected int getLabelWidth(FontMetrics fm)
519 * find the biggest sequence end position we need to show
520 * (note this is not necessarily the sequence length)
523 AlignmentI alignment = av.getAlignment();
524 for (int i = 0; i < alignment.getHeight(); i++)
526 maxWidth = Math.max(maxWidth, alignment.getSequenceAt(i).getEnd());
530 for (int i = maxWidth; i > 0; i /= 10)
535 return fm.stringWidth(ZEROS.substring(0, length)) + av.getCharWidth();
539 * Draws as many widths of a wrapped alignment as can fit in the visible
544 * available width in pixels
545 * @param canvasHeight
546 * available height in pixels
548 * the first column (0...) of the alignment to draw
550 public void drawWrappedPanel(Graphics g, int canvasWidth,
551 int canvasHeight, final int startColumn)
553 int wrappedWidthInResidues = calculateWrappedGeometry(canvasWidth,
556 av.setWrappedWidth(wrappedWidthInResidues);
558 ViewportRanges ranges = av.getRanges();
559 ranges.setViewportStartAndWidth(startColumn, wrappedWidthInResidues);
561 // we need to call this again to make sure the startColumn +
562 // wrappedWidthInResidues values are used to calculate wrappedVisibleWidths
564 calculateWrappedGeometry(canvasWidth, canvasHeight);
567 * draw one width at a time (excluding any scales shown),
568 * until we have run out of either alignment or vertical space available
570 int ypos = wrappedSpaceAboveAlignment;
571 int maxWidth = ranges.getVisibleAlignmentWidth();
573 int start = startColumn;
574 int currentWidth = 0;
575 while ((currentWidth < wrappedVisibleWidths) && (start < maxWidth))
578 .min(maxWidth, start + wrappedWidthInResidues - 1);
579 drawWrappedWidth(g, ypos, start, endColumn, canvasHeight);
580 ypos += wrappedRepeatHeightPx;
581 start += wrappedWidthInResidues;
585 drawWrappedDecorators(g, startColumn);
589 * Calculates and saves values needed when rendering a wrapped alignment.
590 * These depend on many factors, including
592 * <li>canvas width and height</li>
593 * <li>number of visible sequences, and height of annotations if shown</li>
594 * <li>font and character width</li>
595 * <li>whether scales are shown left, right or above the alignment</li>
599 * @param canvasHeight
600 * @return the number of residue columns in each width
602 protected int calculateWrappedGeometry(int canvasWidth, int canvasHeight)
604 int charHeight = av.getCharHeight();
607 * vertical space in pixels between wrapped widths of alignment
608 * - one character height, or two if scale above is drawn
610 wrappedSpaceAboveAlignment = charHeight
611 * (av.getScaleAboveWrapped() ? 2 : 1);
614 * compute height in pixels of the wrapped widths
615 * - start with space above plus sequences
617 wrappedRepeatHeightPx = wrappedSpaceAboveAlignment;
618 wrappedRepeatHeightPx += av.getAlignment().getHeight()
622 * add annotations panel height if shown
623 * also gap between sequences and annotations
625 if (av.isShowAnnotation())
627 wrappedRepeatHeightPx += getAnnotationHeight();
628 wrappedRepeatHeightPx += SEQS_ANNOTATION_GAP; // 3px
632 * number of visible widths (the last one may be part height),
633 * ensuring a part height includes at least one sequence
635 ViewportRanges ranges = av.getRanges();
636 wrappedVisibleWidths = canvasHeight / wrappedRepeatHeightPx;
637 int remainder = canvasHeight % wrappedRepeatHeightPx;
638 if (remainder >= (wrappedSpaceAboveAlignment + charHeight))
640 wrappedVisibleWidths++;
644 * compute width in residues; this also sets East and West label widths
646 int wrappedWidthInResidues = getWrappedCanvasWidth(canvasWidth);
649 * limit visibleWidths to not exceed width of alignment
651 int xMax = ranges.getVisibleAlignmentWidth();
652 int startToEnd = xMax - ranges.getStartRes();
653 int maxWidths = startToEnd / wrappedWidthInResidues;
654 if (startToEnd % wrappedWidthInResidues > 0)
658 wrappedVisibleWidths = Math.min(wrappedVisibleWidths, maxWidths);
660 return wrappedWidthInResidues;
664 * Draws one width of a wrapped alignment, including sequences and
665 * annnotations, if shown, but not scales or hidden column markers
671 * @param canvasHeight
673 protected void drawWrappedWidth(Graphics g, final int ypos,
674 final int startColumn, final int endColumn,
675 final int canvasHeight)
677 ViewportRanges ranges = av.getRanges();
678 int viewportWidth = ranges.getViewportWidth();
680 int endx = Math.min(startColumn + viewportWidth - 1, endColumn);
683 * move right before drawing by the width of the scale left (if any)
684 * plus column offset from left margin (usually zero, but may be non-zero
685 * when fast painting is drawing just a few columns)
687 int charWidth = av.getCharWidth();
688 int xOffset = labelWidthWest
689 + ((startColumn - ranges.getStartRes()) % viewportWidth)
691 g.translate(xOffset, 0);
693 // When printing we have an extra clipped region,
694 // the Printable page which we need to account for here
695 Shape clip = g.getClip();
699 g.setClip(0, 0, viewportWidth * charWidth, canvasHeight);
703 g.setClip(0, (int) clip.getBounds().getY(),
704 viewportWidth * charWidth, (int) clip.getBounds().getHeight());
708 * white fill the region to be drawn (so incremental fast paint doesn't
709 * scribble over an existing image)
711 g.setColor(Color.white);
712 g.fillRect(0, ypos, (endx - startColumn + 1) * charWidth,
713 wrappedRepeatHeightPx);
715 drawPanel(g, startColumn, endx, 0, av.getAlignment().getHeight() - 1,
718 int cHeight = av.getAlignment().getHeight() * av.getCharHeight();
720 if (av.isShowAnnotation())
722 final int yShift = cHeight + ypos + SEQS_ANNOTATION_GAP;
723 g.translate(0, yShift);
724 if (annotations == null)
726 annotations = new AnnotationPanel(av);
729 annotations.renderer.drawComponent(annotations, av, g, -1,
730 startColumn, endx + 1);
731 g.translate(0, -yShift);
734 g.translate(-xOffset, 0);
738 * Draws scales left, right and above (if shown), and any hidden column
739 * markers, on all widths of the wrapped alignment
744 protected void drawWrappedDecorators(Graphics g, final int startColumn)
746 int charWidth = av.getCharWidth();
748 g.setFont(av.getFont());
749 g.setColor(Color.black);
751 int ypos = wrappedSpaceAboveAlignment;
752 ViewportRanges ranges = av.getRanges();
753 int viewportWidth = ranges.getViewportWidth();
754 int maxWidth = ranges.getVisibleAlignmentWidth();
756 int startCol = startColumn;
758 while (widthsDrawn < wrappedVisibleWidths)
760 int endColumn = Math.min(maxWidth, startCol + viewportWidth - 1);
762 if (av.getScaleLeftWrapped())
764 drawVerticalScale(g, startCol, endColumn - 1, ypos, true);
767 if (av.getScaleRightWrapped())
769 int x = labelWidthWest + viewportWidth * charWidth;
771 drawVerticalScale(g, startCol, endColumn, ypos, false);
776 * white fill region of scale above and hidden column markers
777 * (to support incremental fast paint of image)
779 g.translate(labelWidthWest, 0);
780 g.setColor(Color.white);
781 g.fillRect(0, ypos - wrappedSpaceAboveAlignment, viewportWidth
782 * charWidth + labelWidthWest, wrappedSpaceAboveAlignment);
783 g.setColor(Color.black);
784 g.translate(-labelWidthWest, 0);
786 g.translate(labelWidthWest, 0);
788 if (av.getScaleAboveWrapped())
790 drawNorthScale(g, startCol, endColumn, ypos);
793 if (av.hasHiddenColumns() && av.getShowHiddenMarkers())
795 drawHiddenColumnMarkers(g, ypos, startCol, endColumn);
798 g.translate(-labelWidthWest, 0);
800 ypos += wrappedRepeatHeightPx;
801 startCol += viewportWidth;
807 * Draws markers (triangles) above hidden column positions between startColumn
815 protected void drawHiddenColumnMarkers(Graphics g, int ypos,
816 int startColumn, int endColumn)
818 int charHeight = av.getCharHeight();
819 int charWidth = av.getCharWidth();
821 g.setColor(Color.blue);
823 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
825 Iterator<Integer> it = hidden.getStartRegionIterator(startColumn,
829 res = it.next() - startColumn;
831 if (res < 0 || res > endColumn - startColumn + 1)
837 * draw a downward-pointing triangle at the hidden columns location
838 * (before the following visible column)
840 int xMiddle = res * charWidth;
841 int[] xPoints = new int[] { xMiddle - charHeight / 4,
842 xMiddle + charHeight / 4, xMiddle };
843 int yTop = ypos - (charHeight / 2);
844 int[] yPoints = new int[] { yTop, yTop, yTop + 8 };
845 g.fillPolygon(xPoints, yPoints, 3);
850 * Draw a selection group over a wrapped alignment
852 private void drawWrappedSelection(Graphics2D g, SequenceGroup group,
854 int canvasHeight, int startRes)
856 int charHeight = av.getCharHeight();
857 int charWidth = av.getCharWidth();
859 // height gap above each panel
860 int hgap = charHeight;
861 if (av.getScaleAboveWrapped())
866 int cWidth = (canvasWidth - labelWidthEast - labelWidthWest)
868 int cHeight = av.getAlignment().getHeight() * charHeight;
870 int startx = startRes;
872 int ypos = hgap; // vertical offset
873 int maxwidth = av.getAlignment().getWidth();
875 if (av.hasHiddenColumns())
877 maxwidth = av.getAlignment().getHiddenColumns()
878 .absoluteToVisibleColumn(maxwidth);
881 // chop the wrapped alignment extent up into panel-sized blocks and treat
882 // each block as if it were a block from an unwrapped alignment
883 g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
884 BasicStroke.JOIN_ROUND, 3f, new float[]
886 g.setColor(Color.RED);
887 while ((ypos <= canvasHeight) && (startx < maxwidth))
889 // set end value to be start + width, or maxwidth, whichever is smaller
890 endx = startx + cWidth - 1;
897 g.translate(labelWidthWest, 0);
899 drawUnwrappedSelection(g, group, startx, endx, 0,
900 av.getAlignment().getHeight() - 1,
903 g.translate(-labelWidthWest, 0);
905 // update vertical offset
906 ypos += cHeight + getAnnotationHeight() + hgap;
908 // update horizontal offset
911 g.setStroke(new BasicStroke());
914 int getAnnotationHeight()
916 if (!av.isShowAnnotation())
921 if (annotations == null)
923 annotations = new AnnotationPanel(av);
926 return annotations.adjustPanelHeight();
930 * Draws the visible region of the alignment on the graphics context. If there
931 * are hidden column markers in the visible region, then each sub-region
932 * between the markers is drawn separately, followed by the hidden column
936 * the graphics context, positioned at the first residue to be drawn
938 * offset of the first column to draw (0..)
940 * offset of the last column to draw (0..)
942 * offset of the first sequence to draw (0..)
944 * offset of the last sequence to draw (0..)
946 * vertical offset at which to draw (for wrapped alignments)
948 public void drawPanel(Graphics g1, final int startRes, final int endRes,
949 final int startSeq, final int endSeq, final int yOffset)
951 int charHeight = av.getCharHeight();
952 int charWidth = av.getCharWidth();
954 if (!av.hasHiddenColumns())
956 draw(g1, startRes, endRes, startSeq, endSeq, yOffset);
964 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
965 VisibleContigsIterator regions = hidden
966 .getVisContigsIterator(startRes, endRes + 1, true);
968 while (regions.hasNext())
970 int[] region = regions.next();
971 blockEnd = region[1];
972 blockStart = region[0];
975 * draw up to just before the next hidden region, or the end of
976 * the visible region, whichever comes first
978 g1.translate(screenY * charWidth, 0);
980 draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset);
983 * draw the downline of the hidden column marker (ScalePanel draws the
984 * triangle on top) if we reached it
986 if (av.getShowHiddenMarkers()
987 && (regions.hasNext() || regions.endsAtHidden()))
989 g1.setColor(Color.blue);
991 g1.drawLine((blockEnd - blockStart + 1) * charWidth - 1,
992 0 + yOffset, (blockEnd - blockStart + 1) * charWidth - 1,
993 (endSeq - startSeq + 1) * charHeight + yOffset);
996 g1.translate(-screenY * charWidth, 0);
997 screenY += blockEnd - blockStart + 1;
1004 * Draws a region of the visible alignment
1008 * offset of the first column in the visible region (0..)
1010 * offset of the last column in the visible region (0..)
1012 * offset of the first sequence in the visible region (0..)
1014 * offset of the last sequence in the visible region (0..)
1016 * vertical offset at which to draw (for wrapped alignments)
1018 private void draw(Graphics g, int startRes, int endRes, int startSeq,
1019 int endSeq, int offset)
1021 int charHeight = av.getCharHeight();
1022 int charWidth = av.getCharWidth();
1024 g.setFont(av.getFont());
1025 seqRdr.prepare(g, av.isRenderGaps());
1029 // / First draw the sequences
1030 // ///////////////////////////
1031 for (int i = startSeq; i <= endSeq; i++)
1033 nextSeq = av.getAlignment().getSequenceAt(i);
1034 if (nextSeq == null)
1036 // occasionally, a race condition occurs such that the alignment row is
1040 seqRdr.drawSequence(nextSeq, av.getAlignment().findAllGroups(nextSeq),
1041 startRes, endRes, offset + ((i - startSeq) * charHeight));
1043 if (av.isShowSequenceFeatures())
1045 fr.drawSequence(g, nextSeq, startRes, endRes,
1046 offset + ((i - startSeq) * charHeight), false);
1050 * highlight search Results once sequence has been drawn
1052 if (av.hasSearchResults())
1054 SearchResultsI searchResults = av.getSearchResults();
1055 int[] visibleResults = searchResults.getResults(nextSeq, startRes,
1057 if (visibleResults != null)
1059 for (int r = 0; r < visibleResults.length; r += 2)
1061 seqRdr.drawHighlightedText(nextSeq, visibleResults[r],
1062 visibleResults[r + 1],
1063 (visibleResults[r] - startRes) * charWidth,
1064 offset + ((i - startSeq) * charHeight));
1070 if (av.getSelectionGroup() != null
1071 || av.getAlignment().getGroups().size() > 0)
1073 drawGroupsBoundaries(g, startRes, endRes, startSeq, endSeq, offset);
1079 * Draws the outlines of any groups defined on the alignment (excluding the
1080 * current selection group, if any)
1089 void drawGroupsBoundaries(Graphics g1, int startRes, int endRes,
1090 int startSeq, int endSeq, int offset)
1092 Graphics2D g = (Graphics2D) g1;
1094 SequenceGroup group = null;
1095 int groupIndex = -1;
1097 if (av.getAlignment().getGroups().size() > 0)
1099 group = av.getAlignment().getGroups().get(0);
1107 g.setColor(group.getOutlineColour());
1109 drawPartialGroupOutline(g, group, startRes, endRes, startSeq,
1114 if (groupIndex >= av.getAlignment().getGroups().size())
1119 group = av.getAlignment().getGroups().get(groupIndex);
1121 } while (groupIndex < av.getAlignment().getGroups().size());
1128 * Draws the outline of the current selection group (if any)
1136 private void drawSelectionGroup(Graphics2D g, int startRes, int endRes,
1137 int startSeq, int endSeq)
1139 SequenceGroup group = av.getSelectionGroup();
1145 g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
1146 BasicStroke.JOIN_ROUND, 3f, new float[]
1148 g.setColor(Color.RED);
1149 if (!av.getWrapAlignment())
1151 drawUnwrappedSelection(g, group, startRes, endRes, startSeq, endSeq,
1156 drawWrappedSelection(g, group, getWidth(), getHeight(),
1157 av.getRanges().getStartRes());
1159 g.setStroke(new BasicStroke());
1163 * Draw the cursor as a separate image and overlay
1166 * start residue of area to draw cursor in
1168 * end residue of area to draw cursor in
1170 * start sequence of area to draw cursor in
1172 * end sequence of are to draw cursor in
1173 * @return a transparent image of the same size as the sequence canvas, with
1174 * the cursor drawn on it, if any
1176 private void drawCursor(Graphics g, int startRes, int endRes,
1180 // convert the cursorY into a position on the visible alignment
1181 int cursor_ypos = cursorY;
1183 // don't do work unless we have to
1184 if (cursor_ypos >= startSeq && cursor_ypos <= endSeq)
1188 int startx = startRes;
1191 // convert the cursorX into a position on the visible alignment
1192 int cursor_xpos = av.getAlignment().getHiddenColumns()
1193 .absoluteToVisibleColumn(cursorX);
1195 if (av.getAlignment().getHiddenColumns().isVisible(cursorX))
1198 if (av.getWrapAlignment())
1200 // work out the correct offsets for the cursor
1201 int charHeight = av.getCharHeight();
1202 int charWidth = av.getCharWidth();
1203 int canvasWidth = getWidth();
1204 int canvasHeight = getHeight();
1206 // height gap above each panel
1207 int hgap = charHeight;
1208 if (av.getScaleAboveWrapped())
1213 int cWidth = (canvasWidth - labelWidthEast - labelWidthWest)
1215 int cHeight = av.getAlignment().getHeight() * charHeight;
1217 endx = startx + cWidth - 1;
1218 int ypos = hgap; // vertical offset
1220 // iterate down the wrapped panels
1221 while ((ypos <= canvasHeight) && (endx < cursor_xpos))
1223 // update vertical offset
1224 ypos += cHeight + getAnnotationHeight() + hgap;
1226 // update horizontal offset
1228 endx = startx + cWidth - 1;
1231 xoffset = labelWidthWest;
1234 // now check if cursor is within range for x values
1235 if (cursor_xpos >= startx && cursor_xpos <= endx)
1237 // get the character the cursor is drawn at
1238 SequenceI seq = av.getAlignment().getSequenceAt(cursorY);
1239 char s = seq.getCharAt(cursorX);
1241 seqRdr.drawCursor(g, s,
1242 xoffset + (cursor_xpos - startx) * av.getCharWidth(),
1243 yoffset + (cursor_ypos - startSeq) * av.getCharHeight());
1251 * Draw a selection group over an unwrapped alignment
1254 * graphics object to draw with
1258 * start residue of area to draw
1260 * end residue of area to draw
1262 * start sequence of area to draw
1264 * end sequence of area to draw
1266 * vertical offset (used when called from wrapped alignment code)
1268 private void drawUnwrappedSelection(Graphics2D g, SequenceGroup group,
1269 int startRes, int endRes, int startSeq, int endSeq, int offset)
1271 int charWidth = av.getCharWidth();
1273 if (!av.hasHiddenColumns())
1275 drawPartialGroupOutline(g, group, startRes, endRes, startSeq, endSeq,
1280 // package into blocks of visible columns
1285 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
1286 VisibleContigsIterator regions = hidden
1287 .getVisContigsIterator(startRes, endRes + 1, true);
1288 while (regions.hasNext())
1290 int[] region = regions.next();
1291 blockEnd = region[1];
1292 blockStart = region[0];
1294 g.translate(screenY * charWidth, 0);
1295 drawPartialGroupOutline(g, group,
1296 blockStart, blockEnd, startSeq, endSeq, offset);
1298 g.translate(-screenY * charWidth, 0);
1299 screenY += blockEnd - blockStart + 1;
1305 * Draws part of a selection group outline
1313 * @param verticalOffset
1315 private void drawPartialGroupOutline(Graphics2D g, SequenceGroup group,
1316 int startRes, int endRes, int startSeq, int endSeq,
1319 int charHeight = av.getCharHeight();
1320 int charWidth = av.getCharWidth();
1321 int visWidth = (endRes - startRes + 1) * charWidth;
1325 boolean inGroup = false;
1330 List<SequenceI> seqs = group.getSequences(null);
1332 // position of start residue of group relative to startRes, in pixels
1333 int sx = (group.getStartRes() - startRes) * charWidth;
1335 // width of group in pixels
1336 int xwidth = (((group.getEndRes() + 1) - group.getStartRes())
1339 if (!(sx + xwidth < 0 || sx > visWidth))
1341 for (i = startSeq; i <= endSeq; i++)
1343 sy = verticalOffset + (i - startSeq) * charHeight;
1345 if ((sx <= (endRes - startRes) * charWidth)
1346 && seqs.contains(av.getAlignment().getSequenceAt(i)))
1349 && !seqs.contains(av.getAlignment().getSequenceAt(i + 1)))
1351 bottom = sy + charHeight;
1356 if (((top == -1) && (i == 0)) || !seqs
1357 .contains(av.getAlignment().getSequenceAt(i - 1)))
1368 drawVerticals(g, sx, xwidth, visWidth, oldY, sy);
1369 drawHorizontals(g, sx, xwidth, visWidth, top, bottom);
1371 // reset top and bottom
1379 sy = verticalOffset + ((i - startSeq) * charHeight);
1380 drawVerticals(g, sx, xwidth, visWidth, oldY, sy);
1381 drawHorizontals(g, sx, xwidth, visWidth, top, bottom);
1387 * Draw horizontal selection group boundaries at top and bottom positions
1390 * graphics object to draw on
1396 * visWidth maximum available width
1398 * position to draw top of group at
1400 * position to draw bottom of group at
1402 private void drawHorizontals(Graphics2D g, int sx, int xwidth,
1403 int visWidth, int top, int bottom)
1413 // don't let width extend beyond current block, or group extent
1415 if (startx + width >= visWidth)
1417 width = visWidth - startx;
1422 g.drawLine(startx, top, startx + width, top);
1427 g.drawLine(startx, bottom - 1, startx + width, bottom - 1);
1432 * Draw vertical lines at sx and sx+xwidth providing they lie within
1436 * graphics object to draw on
1442 * visWidth maximum available width
1448 private void drawVerticals(Graphics2D g, int sx, int xwidth, int visWidth,
1451 // if start position is visible, draw vertical line to left of
1453 if (sx >= 0 && sx < visWidth)
1455 g.drawLine(sx, oldY, sx, sy);
1458 // if end position is visible, draw vertical line to right of
1460 if (sx + xwidth < visWidth)
1462 g.drawLine(sx + xwidth, oldY, sx + xwidth, sy);
1467 * Highlights search results in the visible region by rendering as white text
1468 * on a black background. Any previous highlighting is removed. Answers true
1469 * if any highlight was left on the visible alignment (so status bar should be
1470 * set to match), else false.
1472 * Currently fastPaint is not implemented for wrapped alignments. If a wrapped
1473 * alignment had to be scrolled to show the highlighted region, then it should
1474 * be fully redrawn, otherwise a fast paint can be performed. This argument
1475 * could be removed if fast paint of scrolled wrapped alignment is coded in
1476 * future (JAL-2609).
1479 * @param noFastPaint
1482 public boolean highlightSearchResults(SearchResultsI results,
1483 boolean noFastPaint)
1489 boolean wrapped = av.getWrapAlignment();
1492 fastPaint = !noFastPaint;
1493 fastpainting = fastPaint;
1496 * to avoid redrawing the whole visible region, we instead
1497 * redraw just the minimal regions to remove previous highlights
1500 SearchResultsI previous = av.getSearchResults();
1501 av.setSearchResults(results);
1502 boolean redrawn = false;
1503 boolean drawn = false;
1506 redrawn = drawMappedPositionsWrapped(previous);
1507 drawn = drawMappedPositionsWrapped(results);
1512 redrawn = drawMappedPositions(previous);
1513 drawn = drawMappedPositions(results);
1518 * if highlights were either removed or added, repaint
1526 * return true only if highlights were added
1532 fastpainting = false;
1537 * Redraws the minimal rectangle in the visible region (if any) that includes
1538 * mapped positions of the given search results. Whether or not positions are
1539 * highlighted depends on the SearchResults set on the Viewport. This allows
1540 * this method to be called to either clear or set highlighting. Answers true
1541 * if any positions were drawn (in which case a repaint is still required),
1547 protected boolean drawMappedPositions(SearchResultsI results)
1549 if ((results == null) || (gg == null)) // JAL-2784 check gg is not null
1555 * calculate the minimal rectangle to redraw that
1556 * includes both new and existing search results
1558 int firstSeq = Integer.MAX_VALUE;
1560 int firstCol = Integer.MAX_VALUE;
1562 boolean matchFound = false;
1564 ViewportRanges ranges = av.getRanges();
1565 int firstVisibleColumn = ranges.getStartRes();
1566 int lastVisibleColumn = ranges.getEndRes();
1567 AlignmentI alignment = av.getAlignment();
1568 if (av.hasHiddenColumns())
1570 firstVisibleColumn = alignment.getHiddenColumns()
1571 .visibleToAbsoluteColumn(firstVisibleColumn);
1572 lastVisibleColumn = alignment.getHiddenColumns()
1573 .visibleToAbsoluteColumn(lastVisibleColumn);
1576 for (int seqNo = ranges.getStartSeq(); seqNo <= ranges
1577 .getEndSeq(); seqNo++)
1579 SequenceI seq = alignment.getSequenceAt(seqNo);
1581 int[] visibleResults = results.getResults(seq, firstVisibleColumn,
1583 if (visibleResults != null)
1585 for (int i = 0; i < visibleResults.length - 1; i += 2)
1587 int firstMatchedColumn = visibleResults[i];
1588 int lastMatchedColumn = visibleResults[i + 1];
1589 if (firstMatchedColumn <= lastVisibleColumn
1590 && lastMatchedColumn >= firstVisibleColumn)
1593 * found a search results match in the visible region -
1594 * remember the first and last sequence matched, and the first
1595 * and last visible columns in the matched positions
1598 firstSeq = Math.min(firstSeq, seqNo);
1599 lastSeq = Math.max(lastSeq, seqNo);
1600 firstMatchedColumn = Math.max(firstMatchedColumn,
1601 firstVisibleColumn);
1602 lastMatchedColumn = Math.min(lastMatchedColumn,
1604 firstCol = Math.min(firstCol, firstMatchedColumn);
1605 lastCol = Math.max(lastCol, lastMatchedColumn);
1613 if (av.hasHiddenColumns())
1615 firstCol = alignment.getHiddenColumns()
1616 .absoluteToVisibleColumn(firstCol);
1617 lastCol = alignment.getHiddenColumns().absoluteToVisibleColumn(lastCol);
1619 int transX = (firstCol - ranges.getStartRes()) * av.getCharWidth();
1620 int transY = (firstSeq - ranges.getStartSeq()) * av.getCharHeight();
1621 gg.translate(transX, transY);
1622 drawPanel(gg, firstCol, lastCol, firstSeq, lastSeq, 0);
1623 gg.translate(-transX, -transY);
1630 public void propertyChange(PropertyChangeEvent evt)
1632 String eventName = evt.getPropertyName();
1634 if (eventName.equals(SequenceGroup.SEQ_GROUP_CHANGED))
1640 else if (eventName.equals(ViewportRanges.MOVE_VIEWPORT))
1648 if (eventName.equals(ViewportRanges.STARTRES)
1649 || eventName.equals(ViewportRanges.STARTRESANDSEQ))
1651 // Make sure we're not trying to draw a panel
1652 // larger than the visible window
1653 if (eventName.equals(ViewportRanges.STARTRES))
1655 scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
1659 scrollX = ((int[]) evt.getNewValue())[0]
1660 - ((int[]) evt.getOldValue())[0];
1662 ViewportRanges vpRanges = av.getRanges();
1664 int range = vpRanges.getEndRes() - vpRanges.getStartRes();
1665 if (scrollX > range)
1669 else if (scrollX < -range)
1674 // Both scrolling and resizing change viewport ranges: scrolling changes
1675 // both start and end points, but resize only changes end values.
1676 // Here we only want to fastpaint on a scroll, with resize using a normal
1677 // paint, so scroll events are identified as changes to the horizontal or
1678 // vertical start value.
1679 if (eventName.equals(ViewportRanges.STARTRES))
1681 if (av.getWrapAlignment())
1683 fastPaintWrapped(scrollX);
1687 fastPaint(scrollX, 0);
1690 else if (eventName.equals(ViewportRanges.STARTSEQ))
1693 fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
1695 else if (eventName.equals(ViewportRanges.STARTRESANDSEQ))
1697 if (av.getWrapAlignment())
1699 fastPaintWrapped(scrollX);
1703 fastPaint(scrollX, 0);
1706 else if (eventName.equals(ViewportRanges.STARTSEQ))
1709 fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
1711 else if (eventName.equals(ViewportRanges.STARTRESANDSEQ))
1713 if (av.getWrapAlignment())
1715 fastPaintWrapped(scrollX);
1721 * Does a minimal update of the image for a scroll movement. This method
1722 * handles scroll movements of up to one width of the wrapped alignment (one
1723 * click in the vertical scrollbar). Larger movements (for example after a
1724 * scroll to highlight a mapped position) trigger a full redraw instead.
1727 * number of positions scrolled (right if positive, left if negative)
1729 protected void fastPaintWrapped(int scrollX)
1731 ViewportRanges ranges = av.getRanges();
1733 if (Math.abs(scrollX) > ranges.getViewportWidth())
1736 * shift of more than one view width is
1737 * overcomplicated to handle in this method
1744 if (fastpainting || gg == null)
1750 fastpainting = true;
1754 calculateWrappedGeometry(getWidth(), getHeight());
1757 * relocate the regions of the alignment that are still visible
1759 shiftWrappedAlignment(-scrollX);
1762 * add new columns (sequence, annotation)
1763 * - at top left if scrollX < 0
1764 * - at right of last two widths if scrollX > 0
1768 int startRes = ranges.getStartRes();
1769 drawWrappedWidth(gg, wrappedSpaceAboveAlignment, startRes, startRes
1770 - scrollX - 1, getHeight());
1774 fastPaintWrappedAddRight(scrollX);
1778 * draw all scales (if shown) and hidden column markers
1780 drawWrappedDecorators(gg, ranges.getStartRes());
1785 fastpainting = false;
1790 * Draws the specified number of columns at the 'end' (bottom right) of a
1791 * wrapped alignment view, including sequences and annotations if shown, but
1792 * not scales. Also draws the same number of columns at the right hand end of
1793 * the second last width shown, if the last width is not full height (so
1794 * cannot simply be copied from the graphics image).
1798 protected void fastPaintWrappedAddRight(int columns)
1805 ViewportRanges ranges = av.getRanges();
1806 int viewportWidth = ranges.getViewportWidth();
1807 int charWidth = av.getCharWidth();
1810 * draw full height alignment in the second last row, last columns, if the
1811 * last row was not full height
1813 int visibleWidths = wrappedVisibleWidths;
1814 int canvasHeight = getHeight();
1815 boolean lastWidthPartHeight = (wrappedVisibleWidths * wrappedRepeatHeightPx) > canvasHeight;
1817 if (lastWidthPartHeight)
1819 int widthsAbove = Math.max(0, visibleWidths - 2);
1820 int ypos = wrappedRepeatHeightPx * widthsAbove
1821 + wrappedSpaceAboveAlignment;
1822 int endRes = ranges.getEndRes();
1823 endRes += widthsAbove * viewportWidth;
1824 int startRes = endRes - columns;
1825 int xOffset = ((startRes - ranges.getStartRes()) % viewportWidth)
1829 * white fill first to erase annotations
1831 gg.translate(xOffset, 0);
1832 gg.setColor(Color.white);
1833 gg.fillRect(labelWidthWest, ypos,
1834 (endRes - startRes + 1) * charWidth, wrappedRepeatHeightPx);
1835 gg.translate(-xOffset, 0);
1837 drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight);
1841 * draw newly visible columns in last wrapped width (none if we
1842 * have reached the end of the alignment)
1843 * y-offset for drawing last width is height of widths above,
1846 int widthsAbove = visibleWidths - 1;
1847 int ypos = wrappedRepeatHeightPx * widthsAbove
1848 + wrappedSpaceAboveAlignment;
1849 int endRes = ranges.getEndRes();
1850 endRes += widthsAbove * viewportWidth;
1851 int startRes = endRes - columns + 1;
1854 * white fill first to erase annotations
1856 int xOffset = ((startRes - ranges.getStartRes()) % viewportWidth)
1858 gg.translate(xOffset, 0);
1859 gg.setColor(Color.white);
1860 int width = viewportWidth * charWidth - xOffset;
1861 gg.fillRect(labelWidthWest, ypos, width, wrappedRepeatHeightPx);
1862 gg.translate(-xOffset, 0);
1864 gg.setFont(av.getFont());
1865 gg.setColor(Color.black);
1867 if (startRes < ranges.getVisibleAlignmentWidth())
1869 drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight);
1873 * and finally, white fill any space below the visible alignment
1875 int heightBelow = canvasHeight - visibleWidths * wrappedRepeatHeightPx;
1876 if (heightBelow > 0)
1878 gg.setColor(Color.white);
1879 gg.fillRect(0, canvasHeight - heightBelow, getWidth(), heightBelow);
1884 * Shifts the visible alignment by the specified number of columns - left if
1885 * negative, right if positive. Copies and moves sequences and annotations (if
1886 * shown). Scales, hidden column markers and any newly visible columns must be
1891 protected void shiftWrappedAlignment(int positions)
1897 int charWidth = av.getCharWidth();
1899 int canvasHeight = getHeight();
1900 ViewportRanges ranges = av.getRanges();
1901 int viewportWidth = ranges.getViewportWidth();
1902 int widthToCopy = (ranges.getViewportWidth() - Math.abs(positions))
1904 int heightToCopy = wrappedRepeatHeightPx - wrappedSpaceAboveAlignment;
1905 int xMax = ranges.getVisibleAlignmentWidth();
1910 * shift right (after scroll left)
1911 * for each wrapped width (starting with the last), copy (width-positions)
1912 * columns from the left margin to the right margin, and copy positions
1913 * columns from the right margin of the row above (if any) to the
1914 * left margin of the current row
1918 * get y-offset of last wrapped width, first row of sequences
1920 int y = canvasHeight / wrappedRepeatHeightPx * wrappedRepeatHeightPx;
1921 y += wrappedSpaceAboveAlignment;
1922 int copyFromLeftStart = labelWidthWest;
1923 int copyFromRightStart = copyFromLeftStart + widthToCopy;
1927 gg.copyArea(copyFromLeftStart, y, widthToCopy, heightToCopy,
1928 positions * charWidth, 0);
1931 gg.copyArea(copyFromRightStart, y - wrappedRepeatHeightPx,
1932 positions * charWidth, heightToCopy, -widthToCopy,
1933 wrappedRepeatHeightPx);
1936 y -= wrappedRepeatHeightPx;
1942 * shift left (after scroll right)
1943 * for each wrapped width (starting with the first), copy (width-positions)
1944 * columns from the right margin to the left margin, and copy positions
1945 * columns from the left margin of the row below (if any) to the
1946 * right margin of the current row
1948 int xpos = av.getRanges().getStartRes();
1949 int y = wrappedSpaceAboveAlignment;
1950 int copyFromRightStart = labelWidthWest - positions * charWidth;
1952 while (y < canvasHeight)
1954 gg.copyArea(copyFromRightStart, y, widthToCopy, heightToCopy,
1955 positions * charWidth, 0);
1956 if (y + wrappedRepeatHeightPx < canvasHeight - wrappedRepeatHeightPx
1957 && (xpos + viewportWidth <= xMax))
1959 gg.copyArea(labelWidthWest, y + wrappedRepeatHeightPx, -positions
1960 * charWidth, heightToCopy, widthToCopy,
1961 -wrappedRepeatHeightPx);
1964 y += wrappedRepeatHeightPx;
1965 xpos += viewportWidth;
1972 * Redraws any positions in the search results in the visible region of a
1973 * wrapped alignment. Any highlights are drawn depending on the search results
1974 * set on the Viewport, not the <code>results</code> argument. This allows
1975 * this method to be called either to clear highlights (passing the previous
1976 * search results), or to draw new highlights.
1981 protected boolean drawMappedPositionsWrapped(SearchResultsI results)
1983 if ((results == null) || (gg == null)) // JAL-2784 check gg is not null
1987 int charHeight = av.getCharHeight();
1989 boolean matchFound = false;
1991 calculateWrappedGeometry(getWidth(), getHeight());
1992 int wrappedWidth = av.getWrappedWidth();
1993 int wrappedHeight = wrappedRepeatHeightPx;
1995 ViewportRanges ranges = av.getRanges();
1996 int canvasHeight = getHeight();
1997 int repeats = canvasHeight / wrappedHeight;
1998 if (canvasHeight / wrappedHeight > 0)
2003 int firstVisibleColumn = ranges.getStartRes();
2004 int lastVisibleColumn = ranges.getStartRes() + repeats
2005 * ranges.getViewportWidth() - 1;
2007 AlignmentI alignment = av.getAlignment();
2008 if (av.hasHiddenColumns())
2010 firstVisibleColumn = alignment.getHiddenColumns()
2011 .visibleToAbsoluteColumn(firstVisibleColumn);
2012 lastVisibleColumn = alignment.getHiddenColumns()
2013 .visibleToAbsoluteColumn(lastVisibleColumn);
2016 int gapHeight = charHeight * (av.getScaleAboveWrapped() ? 2 : 1);
2018 for (int seqNo = ranges.getStartSeq(); seqNo <= ranges
2019 .getEndSeq(); seqNo++)
2021 SequenceI seq = alignment.getSequenceAt(seqNo);
2023 int[] visibleResults = results.getResults(seq, firstVisibleColumn,
2025 if (visibleResults != null)
2027 for (int i = 0; i < visibleResults.length - 1; i += 2)
2029 int firstMatchedColumn = visibleResults[i];
2030 int lastMatchedColumn = visibleResults[i + 1];
2031 if (firstMatchedColumn <= lastVisibleColumn
2032 && lastMatchedColumn >= firstVisibleColumn)
2035 * found a search results match in the visible region
2037 firstMatchedColumn = Math.max(firstMatchedColumn,
2038 firstVisibleColumn);
2039 lastMatchedColumn = Math.min(lastMatchedColumn,
2043 * draw each mapped position separately (as contiguous positions may
2044 * wrap across lines)
2046 for (int mappedPos = firstMatchedColumn; mappedPos <= lastMatchedColumn; mappedPos++)
2048 int displayColumn = mappedPos;
2049 if (av.hasHiddenColumns())
2051 displayColumn = alignment.getHiddenColumns()
2052 .absoluteToVisibleColumn(displayColumn);
2056 * transX: offset from left edge of canvas to residue position
2058 int transX = labelWidthWest
2059 + ((displayColumn - ranges.getStartRes()) % wrappedWidth)
2060 * av.getCharWidth();
2063 * transY: offset from top edge of canvas to residue position
2065 int transY = gapHeight;
2066 transY += (displayColumn - ranges.getStartRes())
2067 / wrappedWidth * wrappedHeight;
2068 transY += (seqNo - ranges.getStartSeq()) * av.getCharHeight();
2071 * yOffset is from graphics origin to start of visible region
2073 int yOffset = 0;// (displayColumn / wrappedWidth) * wrappedHeight;
2074 if (transY < getHeight())
2077 gg.translate(transX, transY);
2078 drawPanel(gg, displayColumn, displayColumn, seqNo, seqNo,
2080 gg.translate(-transX, -transY);
2092 * Answers the width in pixels of the left scale labels (0 if not shown)
2096 int getLabelWidthWest()
2098 return labelWidthWest;