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
58 private static final String ZEROS = "0000000000";
60 final FeatureRenderer fr;
70 private final SequenceRenderer seqRdr;
72 private boolean fastPaint = false;
74 private boolean fastpainting = false;
76 private AnnotationPanel annotations;
79 * measurements for drawing a wrapped alignment
81 private int labelWidthEast; // label right width in pixels if shown
83 private int labelWidthWest; // label left width in pixels if shown
85 private int wrappedSpaceAboveAlignment; // gap between widths
87 private int wrappedRepeatHeightPx; // height in pixels of wrapped width
89 private int wrappedVisibleWidths; // number of wrapped widths displayed
91 private Graphics2D gg;
94 * Creates a new SeqCanvas object.
98 public SeqCanvas(AlignmentPanel ap)
101 fr = new FeatureRenderer(ap);
102 seqRdr = new SequenceRenderer(av);
103 setLayout(new BorderLayout());
104 PaintRefresher.Register(this, av.getSequenceSetId());
105 setBackground(Color.white);
107 av.getRanges().addPropertyChangeListener(this);
110 public SequenceRenderer getSequenceRenderer()
115 public FeatureRenderer getFeatureRenderer()
121 * Draws the scale above a region of a wrapped alignment, consisting of a
122 * column number every major interval (10 columns).
125 * the graphics context to draw on, positioned at the start (bottom
126 * left) of the line on which to draw any scale marks
128 * start alignment column (0..)
130 * end alignment column (0..)
132 * y offset to draw at
134 private void drawNorthScale(Graphics g, int startx, int endx, int ypos)
136 int charHeight = av.getCharHeight();
137 int charWidth = av.getCharWidth();
140 * white fill the scale space (for the fastPaint case)
142 g.setColor(Color.white);
143 g.fillRect(0, ypos - charHeight - charHeight / 2, getWidth(),
144 charHeight * 3 / 2 + 2);
145 g.setColor(Color.black);
147 List<ScaleMark> marks = new ScaleRenderer().calculateMarks(av, startx,
149 for (ScaleMark mark : marks)
151 int mpos = mark.column; // (i - startx - 1)
156 String mstring = mark.text;
162 g.drawString(mstring, mpos * charWidth, ypos - (charHeight / 2));
166 * draw a tick mark below the column number, centred on the column;
167 * height of tick mark is 4 pixels less than half a character
169 int xpos = (mpos * charWidth) + (charWidth / 2);
170 g.drawLine(xpos, (ypos + 2) - (charHeight / 2), xpos, ypos - 2);
176 * Draw the scale to the left or right of a wrapped alignment
179 * graphics context, positioned at the start of the scale to be drawn
181 * first column of wrapped width (0.. excluding any hidden columns)
183 * last column of wrapped width (0.. excluding any hidden columns)
185 * vertical offset at which to begin the scale
187 * if true, scale is left of residues, if false, scale is right
189 void drawVerticalScale(Graphics g, final int startx, final int endx,
190 final int ypos, final boolean left)
192 int charHeight = av.getCharHeight();
193 int charWidth = av.getCharWidth();
195 int yPos = ypos + charHeight;
199 if (av.hasHiddenColumns())
201 HiddenColumns hiddenColumns = av.getAlignment().getHiddenColumns();
202 startX = hiddenColumns.visibleToAbsoluteColumn(startx);
203 endX = hiddenColumns.visibleToAbsoluteColumn(endx);
205 FontMetrics fm = getFontMetrics(av.getFont());
207 for (int i = 0; i < av.getAlignment().getHeight(); i++)
209 SequenceI seq = av.getAlignment().getSequenceAt(i);
212 * find sequence position of first non-gapped position -
213 * to the right if scale left, to the left if scale right
215 int index = left ? startX : endX;
217 while (index >= startX && index <= endX)
219 if (!Comparison.isGap(seq.getCharAt(index)))
221 value = seq.findPosition(index);
235 * white fill the space for the scale
237 g.setColor(Color.white);
238 int y = (yPos + (i * charHeight)) - (charHeight / 5);
239 // fillRect origin is top left of rectangle
240 g.fillRect(0, y - charHeight, left ? labelWidthWest : labelWidthEast,
246 * draw scale value, right justified within its width less half a
247 * character width padding on the right
249 int labelSpace = left ? labelWidthWest : labelWidthEast;
250 labelSpace -= charWidth / 2; // leave space to the right
251 String valueAsString = String.valueOf(value);
252 int labelLength = fm.stringWidth(valueAsString);
253 int xOffset = labelSpace - labelLength;
254 g.setColor(Color.black);
255 g.drawString(valueAsString, xOffset, y);
261 * Does a fast paint of an alignment in response to a scroll. Most of the
262 * visible region is simply copied and shifted, and then any newly visible
263 * columns or rows are drawn. The scroll may be horizontal or vertical, but
264 * not both at once. Scrolling may be the result of
266 * <li>dragging a scroll bar</li>
267 * <li>clicking in the scroll bar</li>
268 * <li>scrolling by trackpad, middle mouse button, or other device</li>
269 * <li>by moving the box in the Overview window</li>
270 * <li>programmatically to make a highlighted position visible</li>
274 * columns to shift right (positive) or left (negative)
276 * rows to shift down (positive) or up (negative)
278 public void fastPaint(int horizontal, int vertical)
280 if (fastpainting || gg == null || img == null)
289 int charHeight = av.getCharHeight();
290 int charWidth = av.getCharWidth();
292 ViewportRanges ranges = av.getRanges();
293 int startRes = ranges.getStartRes();
294 int endRes = ranges.getEndRes();
295 int startSeq = ranges.getStartSeq();
296 int endSeq = ranges.getEndSeq();
300 gg.copyArea(horizontal * charWidth, vertical * charHeight,
301 img.getWidth(), img.getHeight(), -horizontal * charWidth,
302 -vertical * charHeight);
304 if (horizontal > 0) // scrollbar pulled right, image to the left
306 transX = (endRes - startRes - horizontal) * charWidth;
307 startRes = endRes - horizontal;
309 else if (horizontal < 0)
311 endRes = startRes - horizontal;
314 if (vertical > 0) // scroll down
316 startSeq = endSeq - vertical;
318 if (startSeq < ranges.getStartSeq())
319 { // ie scrolling too fast, more than a page at a time
320 startSeq = ranges.getStartSeq();
324 transY = img.getHeight() - ((vertical + 1) * charHeight);
327 else if (vertical < 0)
329 endSeq = startSeq - vertical;
331 if (endSeq > ranges.getEndSeq())
333 endSeq = ranges.getEndSeq();
337 gg.translate(transX, transY);
338 drawPanel(gg, startRes, endRes, startSeq, endSeq, 0);
339 gg.translate(-transX, -transY);
341 // Call repaint on alignment panel so that repaints from other alignment
342 // panel components can be aggregated. Otherwise performance of the
343 // overview window and others may be adversely affected.
344 av.getAlignPanel().repaint();
347 fastpainting = false;
352 public void paintComponent(Graphics g)
354 super.paintComponent(g);
356 int charHeight = av.getCharHeight();
357 int charWidth = av.getCharWidth();
359 ViewportRanges ranges = av.getRanges();
361 int width = getWidth();
362 int height = getHeight();
364 width -= (width % charWidth);
365 height -= (height % charHeight);
367 if ((img != null) && (fastPaint
368 || (getVisibleRect().width != g.getClipBounds().width)
369 || (getVisibleRect().height != g.getClipBounds().height)))
371 g.drawImage(img, 0, 0, this);
373 drawSelectionGroup((Graphics2D) g, ranges.getStartRes(),
374 ranges.getEndRes(), ranges.getStartSeq(), ranges.getEndSeq());
378 else if (width > 0 && height > 0)
381 * img is a cached version of the last view we drew, if any
382 * if we have no img or the size has changed, make a new one
384 if (img == null || width != img.getWidth()
385 || height != img.getHeight())
387 img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
388 gg = (Graphics2D) img.getGraphics();
389 gg.setFont(av.getFont());
394 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
395 RenderingHints.VALUE_ANTIALIAS_ON);
398 gg.setColor(Color.white);
399 gg.fillRect(0, 0, img.getWidth(), img.getHeight());
401 if (av.getWrapAlignment())
403 drawWrappedPanel(gg, getWidth(), getHeight(), ranges.getStartRes());
407 drawPanel(gg, ranges.getStartRes(), ranges.getEndRes(),
408 ranges.getStartSeq(), ranges.getEndSeq(), 0);
411 drawSelectionGroup(gg, ranges.getStartRes(),
412 ranges.getEndRes(), ranges.getStartSeq(), ranges.getEndSeq());
414 g.drawImage(img, 0, 0, this);
419 drawCursor(g, ranges.getStartRes(), ranges.getEndRes(),
420 ranges.getStartSeq(), ranges.getEndSeq());
425 * Draw an alignment panel for printing
428 * Graphics object to draw with
430 * start residue of print area
432 * end residue of print area
434 * start sequence of print area
436 * end sequence of print area
438 public void drawPanelForPrinting(Graphics g1, int startRes, int endRes,
439 int startSeq, int endSeq)
441 drawPanel(g1, startRes, endRes, startSeq, endSeq, 0);
443 drawSelectionGroup((Graphics2D) g1, startRes, endRes,
448 * Draw a wrapped alignment panel for printing
451 * Graphics object to draw with
453 * width of drawing area
454 * @param canvasHeight
455 * height of drawing area
457 * start residue of print area
459 public void drawWrappedPanelForPrinting(Graphics g, int canvasWidth,
460 int canvasHeight, int startRes)
462 drawWrappedPanel(g, canvasWidth, canvasHeight, startRes);
464 SequenceGroup group = av.getSelectionGroup();
467 drawWrappedSelection((Graphics2D) g, group, canvasWidth, canvasHeight,
473 * Returns the visible width of the canvas in residues, after allowing for
474 * East or West scales (if shown)
477 * the width in pixels (possibly including scales)
481 public int getWrappedCanvasWidth(int canvasWidth)
483 int charWidth = av.getCharWidth();
485 FontMetrics fm = getFontMetrics(av.getFont());
489 if (av.getScaleRightWrapped() || av.getScaleLeftWrapped())
491 labelWidth = getLabelWidth(fm);
494 labelWidthEast = av.getScaleRightWrapped() ? labelWidth : 0;
496 labelWidthWest = av.getScaleLeftWrapped() ? labelWidth : 0;
498 return (canvasWidth - labelWidthEast - labelWidthWest) / charWidth;
502 * Returns a pixel width sufficient to show the largest sequence coordinate
503 * (end position) in the alignment, calculated as the FontMetrics width of
504 * zeroes "0000000" limited to the number of decimal digits to be shown (3 for
505 * 1-10, 4 for 11-99 etc). One character width is added to this, to allow for
506 * half a character width space on either side.
511 protected int getLabelWidth(FontMetrics fm)
514 * find the biggest sequence end position we need to show
515 * (note this is not necessarily the sequence length)
518 AlignmentI alignment = av.getAlignment();
519 for (int i = 0; i < alignment.getHeight(); i++)
521 maxWidth = Math.max(maxWidth, alignment.getSequenceAt(i).getEnd());
525 for (int i = maxWidth; i > 0; i /= 10)
530 return fm.stringWidth(ZEROS.substring(0, length)) + av.getCharWidth();
534 * Draws as many widths of a wrapped alignment as can fit in the visible
539 * available width in pixels
540 * @param canvasHeight
541 * available height in pixels
543 * the first column (0...) of the alignment to draw
545 public void drawWrappedPanel(Graphics g, int canvasWidth,
546 int canvasHeight, final int startColumn)
548 int wrappedWidthInResidues = calculateWrappedGeometry(canvasWidth,
551 av.setWrappedWidth(wrappedWidthInResidues);
553 ViewportRanges ranges = av.getRanges();
554 ranges.setViewportStartAndWidth(startColumn, wrappedWidthInResidues);
556 // we need to call this again to make sure the startColumn +
557 // wrappedWidthInResidues values are used to calculate wrappedVisibleWidths
559 calculateWrappedGeometry(canvasWidth, canvasHeight);
562 * draw one width at a time (excluding any scales or annotation shown),
563 * until we have run out of either alignment or vertical space available
565 int ypos = wrappedSpaceAboveAlignment;
566 int maxWidth = ranges.getVisibleAlignmentWidth();
568 int start = startColumn;
569 int currentWidth = 0;
570 while ((currentWidth < wrappedVisibleWidths) && (start < maxWidth))
573 .min(maxWidth, start + wrappedWidthInResidues - 1);
574 drawWrappedWidth(g, ypos, start, endColumn, canvasHeight);
575 ypos += wrappedRepeatHeightPx;
576 start += wrappedWidthInResidues;
580 drawWrappedDecorators(g, startColumn);
584 * Calculates and saves values needed when rendering a wrapped alignment.
585 * These depend on many factors, including
587 * <li>canvas width and height</li>
588 * <li>number of visible sequences, and height of annotations if shown</li>
589 * <li>font and character width</li>
590 * <li>whether scales are shown left, right or above the alignment</li>
594 * @param canvasHeight
595 * @return the number of residue columns in each width
597 protected int calculateWrappedGeometry(int canvasWidth, int canvasHeight)
599 int charHeight = av.getCharHeight();
602 * vertical space in pixels between wrapped widths of alignment
603 * - one character height, or two if scale above is drawn
605 wrappedSpaceAboveAlignment = charHeight
606 * (av.getScaleAboveWrapped() ? 2 : 1);
609 * height in pixels of the wrapped widths
611 wrappedRepeatHeightPx = wrappedSpaceAboveAlignment;
613 wrappedRepeatHeightPx += av.getAlignment().getHeight()
615 // add annotations panel height if shown
616 wrappedRepeatHeightPx += getAnnotationHeight();
619 * number of visible widths (the last one may be part height),
620 * ensuring a part height includes at least one sequence
622 ViewportRanges ranges = av.getRanges();
623 wrappedVisibleWidths = canvasHeight / wrappedRepeatHeightPx;
624 int remainder = canvasHeight % wrappedRepeatHeightPx;
625 if (remainder >= (wrappedSpaceAboveAlignment + charHeight))
627 wrappedVisibleWidths++;
631 * compute width in residues; this also sets East and West label widths
633 int wrappedWidthInResidues = getWrappedCanvasWidth(canvasWidth);
636 * limit visibleWidths to not exceed width of alignment
638 int xMax = ranges.getVisibleAlignmentWidth();
639 int startToEnd = xMax - ranges.getStartRes();
640 int maxWidths = startToEnd / wrappedWidthInResidues;
641 if (startToEnd % wrappedWidthInResidues > 0)
645 wrappedVisibleWidths = Math.min(wrappedVisibleWidths, maxWidths);
647 return wrappedWidthInResidues;
651 * Draws one width of a wrapped alignment, including sequences and
652 * annnotations, if shown, but not scales or hidden column markers
658 * @param canvasHeight
660 protected void drawWrappedWidth(Graphics g, int ypos, int startColumn,
661 int endColumn, int canvasHeight)
663 ViewportRanges ranges = av.getRanges();
664 int viewportWidth = ranges.getViewportWidth();
666 int endx = Math.min(startColumn + viewportWidth - 1, endColumn);
669 * move right before drawing by the width of the scale left (if any)
670 * plus column offset from left margin (usually zero, but may be non-zero
671 * when fast painting is drawing just a few columns)
673 int charWidth = av.getCharWidth();
674 int xOffset = labelWidthWest
675 + ((startColumn - ranges.getStartRes()) % viewportWidth)
677 g.translate(xOffset, 0);
679 // When printing we have an extra clipped region,
680 // the Printable page which we need to account for here
681 Shape clip = g.getClip();
685 g.setClip(0, 0, viewportWidth * charWidth, canvasHeight);
689 g.setClip(0, (int) clip.getBounds().getY(),
690 viewportWidth * charWidth, (int) clip.getBounds().getHeight());
694 * white fill the region to be drawn (so incremental fast paint doesn't
695 * scribble over an existing image)
697 g.setColor(Color.white);
698 g.fillRect(0, ypos, (endx - startColumn + 1) * charWidth,
699 wrappedRepeatHeightPx);
701 drawPanel(g, startColumn, endx, 0, av.getAlignment().getHeight() - 1,
704 int cHeight = av.getAlignment().getHeight() * av.getCharHeight();
706 if (av.isShowAnnotation())
708 g.translate(0, cHeight + ypos + 3);
709 if (annotations == null)
711 annotations = new AnnotationPanel(av);
714 annotations.renderer.drawComponent(annotations, av, g, -1,
715 startColumn, endx + 1);
716 g.translate(0, -cHeight - ypos - 3);
719 g.translate(-xOffset, 0);
723 * Draws scales left, right and above (if shown), and any hidden column
724 * markers, on all widths of the wrapped alignment
729 protected void drawWrappedDecorators(Graphics g, final int startColumn)
731 int charWidth = av.getCharWidth();
733 g.setFont(av.getFont());
734 g.setColor(Color.black);
736 int ypos = wrappedSpaceAboveAlignment;
737 ViewportRanges ranges = av.getRanges();
738 int viewportWidth = ranges.getViewportWidth();
739 int maxWidth = ranges.getVisibleAlignmentWidth();
741 int startCol = startColumn;
743 while (widthsDrawn < wrappedVisibleWidths)
745 int endColumn = Math.min(maxWidth, startCol + viewportWidth - 1);
747 if (av.getScaleLeftWrapped())
749 drawVerticalScale(g, startCol, endColumn - 1, ypos, true);
752 if (av.getScaleRightWrapped())
754 int x = labelWidthWest + viewportWidth * charWidth;
756 drawVerticalScale(g, startCol, endColumn, ypos, false);
761 * white fill region of scale above and hidden column markers
762 * (to support incremental fast paint of image)
764 g.translate(labelWidthWest, 0);
765 g.setColor(Color.white);
766 g.fillRect(0, ypos - wrappedSpaceAboveAlignment, viewportWidth
767 * charWidth + labelWidthWest, wrappedSpaceAboveAlignment);
768 g.setColor(Color.black);
769 g.translate(-labelWidthWest, 0);
771 g.translate(labelWidthWest, 0);
773 if (av.getScaleAboveWrapped())
775 drawNorthScale(g, startCol, endColumn, ypos);
778 if (av.hasHiddenColumns() && av.getShowHiddenMarkers())
780 drawHiddenColumnMarkers(g, ypos, startCol, endColumn);
783 g.translate(-labelWidthWest, 0);
785 ypos += wrappedRepeatHeightPx;
786 startCol += viewportWidth;
792 * Draws markers (triangles) above hidden column positions between startColumn
800 protected void drawHiddenColumnMarkers(Graphics g, int ypos,
801 int startColumn, int endColumn)
803 int charHeight = av.getCharHeight();
804 int charWidth = av.getCharWidth();
806 g.setColor(Color.blue);
808 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
810 Iterator<Integer> it = hidden.getStartRegionIterator(startColumn,
814 res = it.next() - startColumn;
816 if (res < 0 || res > endColumn - startColumn + 1)
822 * draw a downward-pointing triangle at the hidden columns location
823 * (before the following visible column)
825 int xMiddle = res * charWidth;
826 int[] xPoints = new int[] { xMiddle - charHeight / 4,
827 xMiddle + charHeight / 4, xMiddle };
828 int yTop = ypos - (charHeight / 2);
829 int[] yPoints = new int[] { yTop, yTop, yTop + 8 };
830 g.fillPolygon(xPoints, yPoints, 3);
835 * Draw a selection group over a wrapped alignment
837 private void drawWrappedSelection(Graphics2D g, SequenceGroup group,
839 int canvasHeight, int startRes)
841 int charHeight = av.getCharHeight();
842 int charWidth = av.getCharWidth();
844 // height gap above each panel
845 int hgap = charHeight;
846 if (av.getScaleAboveWrapped())
851 int cWidth = (canvasWidth - labelWidthEast - labelWidthWest)
853 int cHeight = av.getAlignment().getHeight() * charHeight;
855 int startx = startRes;
857 int ypos = hgap; // vertical offset
858 int maxwidth = av.getAlignment().getWidth();
860 if (av.hasHiddenColumns())
862 maxwidth = av.getAlignment().getHiddenColumns()
863 .absoluteToVisibleColumn(maxwidth);
866 // chop the wrapped alignment extent up into panel-sized blocks and treat
867 // each block as if it were a block from an unwrapped alignment
868 g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
869 BasicStroke.JOIN_ROUND, 3f, new float[]
871 g.setColor(Color.RED);
872 while ((ypos <= canvasHeight) && (startx < maxwidth))
874 // set end value to be start + width, or maxwidth, whichever is smaller
875 endx = startx + cWidth - 1;
882 g.translate(labelWidthWest, 0);
884 drawUnwrappedSelection(g, group, startx, endx, 0,
885 av.getAlignment().getHeight() - 1,
888 g.translate(-labelWidthWest, 0);
890 // update vertical offset
891 ypos += cHeight + getAnnotationHeight() + hgap;
893 // update horizontal offset
896 g.setStroke(new BasicStroke());
899 int getAnnotationHeight()
901 if (!av.isShowAnnotation())
906 if (annotations == null)
908 annotations = new AnnotationPanel(av);
911 return annotations.adjustPanelHeight();
915 * Draws the visible region of the alignment on the graphics context. If there
916 * are hidden column markers in the visible region, then each sub-region
917 * between the markers is drawn separately, followed by the hidden column
921 * the graphics context, positioned at the first residue to be drawn
923 * offset of the first column to draw (0..)
925 * offset of the last column to draw (0..)
927 * offset of the first sequence to draw (0..)
929 * offset of the last sequence to draw (0..)
931 * vertical offset at which to draw (for wrapped alignments)
933 public void drawPanel(Graphics g1, final int startRes, final int endRes,
934 final int startSeq, final int endSeq, final int yOffset)
936 int charHeight = av.getCharHeight();
937 int charWidth = av.getCharWidth();
939 if (!av.hasHiddenColumns())
941 draw(g1, startRes, endRes, startSeq, endSeq, yOffset);
949 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
950 VisibleContigsIterator regions = hidden
951 .getVisContigsIterator(startRes, endRes + 1, true);
953 while (regions.hasNext())
955 int[] region = regions.next();
956 blockEnd = region[1];
957 blockStart = region[0];
960 * draw up to just before the next hidden region, or the end of
961 * the visible region, whichever comes first
963 g1.translate(screenY * charWidth, 0);
965 draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset);
968 * draw the downline of the hidden column marker (ScalePanel draws the
969 * triangle on top) if we reached it
971 if (av.getShowHiddenMarkers()
972 && (regions.hasNext() || regions.endsAtHidden()))
974 g1.setColor(Color.blue);
976 g1.drawLine((blockEnd - blockStart + 1) * charWidth - 1,
977 0 + yOffset, (blockEnd - blockStart + 1) * charWidth - 1,
978 (endSeq - startSeq + 1) * charHeight + yOffset);
981 g1.translate(-screenY * charWidth, 0);
982 screenY += blockEnd - blockStart + 1;
989 * Draws a region of the visible alignment
993 * offset of the first column in the visible region (0..)
995 * offset of the last column in the visible region (0..)
997 * offset of the first sequence in the visible region (0..)
999 * offset of the last sequence in the visible region (0..)
1001 * vertical offset at which to draw (for wrapped alignments)
1003 private void draw(Graphics g, int startRes, int endRes, int startSeq,
1004 int endSeq, int offset)
1006 int charHeight = av.getCharHeight();
1007 int charWidth = av.getCharWidth();
1009 g.setFont(av.getFont());
1010 seqRdr.prepare(g, av.isRenderGaps());
1014 // / First draw the sequences
1015 // ///////////////////////////
1016 for (int i = startSeq; i <= endSeq; i++)
1018 nextSeq = av.getAlignment().getSequenceAt(i);
1019 if (nextSeq == null)
1021 // occasionally, a race condition occurs such that the alignment row is
1025 seqRdr.drawSequence(nextSeq, av.getAlignment().findAllGroups(nextSeq),
1026 startRes, endRes, offset + ((i - startSeq) * charHeight));
1028 if (av.isShowSequenceFeatures())
1030 fr.drawSequence(g, nextSeq, startRes, endRes,
1031 offset + ((i - startSeq) * charHeight), false);
1035 * highlight search Results once sequence has been drawn
1037 if (av.hasSearchResults())
1039 SearchResultsI searchResults = av.getSearchResults();
1040 int[] visibleResults = searchResults.getResults(nextSeq, startRes,
1042 if (visibleResults != null)
1044 for (int r = 0; r < visibleResults.length; r += 2)
1046 seqRdr.drawHighlightedText(nextSeq, visibleResults[r],
1047 visibleResults[r + 1],
1048 (visibleResults[r] - startRes) * charWidth,
1049 offset + ((i - startSeq) * charHeight));
1055 if (av.getSelectionGroup() != null
1056 || av.getAlignment().getGroups().size() > 0)
1058 drawGroupsBoundaries(g, startRes, endRes, startSeq, endSeq, offset);
1064 * Draws the outlines of any groups defined on the alignment (excluding the
1065 * current selection group, if any)
1074 void drawGroupsBoundaries(Graphics g1, int startRes, int endRes,
1075 int startSeq, int endSeq, int offset)
1077 Graphics2D g = (Graphics2D) g1;
1079 SequenceGroup group = null;
1080 int groupIndex = -1;
1082 if (av.getAlignment().getGroups().size() > 0)
1084 group = av.getAlignment().getGroups().get(0);
1092 g.setColor(group.getOutlineColour());
1094 drawPartialGroupOutline(g, group, startRes, endRes, startSeq,
1099 if (groupIndex >= av.getAlignment().getGroups().size())
1104 group = av.getAlignment().getGroups().get(groupIndex);
1106 } while (groupIndex < av.getAlignment().getGroups().size());
1113 * Draws the outline of the current selection group (if any)
1121 private void drawSelectionGroup(Graphics2D g, int startRes, int endRes,
1122 int startSeq, int endSeq)
1124 SequenceGroup group = av.getSelectionGroup();
1130 g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
1131 BasicStroke.JOIN_ROUND, 3f, new float[]
1133 g.setColor(Color.RED);
1134 if (!av.getWrapAlignment())
1136 drawUnwrappedSelection(g, group, startRes, endRes, startSeq, endSeq,
1141 drawWrappedSelection(g, group, getWidth(), getHeight(),
1142 av.getRanges().getStartRes());
1144 g.setStroke(new BasicStroke());
1148 * Draw the cursor as a separate image and overlay
1151 * start residue of area to draw cursor in
1153 * end residue of area to draw cursor in
1155 * start sequence of area to draw cursor in
1157 * end sequence of are to draw cursor in
1158 * @return a transparent image of the same size as the sequence canvas, with
1159 * the cursor drawn on it, if any
1161 private void drawCursor(Graphics g, int startRes, int endRes,
1165 // convert the cursorY into a position on the visible alignment
1166 int cursor_ypos = cursorY;
1168 // don't do work unless we have to
1169 if (cursor_ypos >= startSeq && cursor_ypos <= endSeq)
1173 int startx = startRes;
1176 // convert the cursorX into a position on the visible alignment
1177 int cursor_xpos = av.getAlignment().getHiddenColumns()
1178 .absoluteToVisibleColumn(cursorX);
1180 if (av.getAlignment().getHiddenColumns().isVisible(cursorX))
1183 if (av.getWrapAlignment())
1185 // work out the correct offsets for the cursor
1186 int charHeight = av.getCharHeight();
1187 int charWidth = av.getCharWidth();
1188 int canvasWidth = getWidth();
1189 int canvasHeight = getHeight();
1191 // height gap above each panel
1192 int hgap = charHeight;
1193 if (av.getScaleAboveWrapped())
1198 int cWidth = (canvasWidth - labelWidthEast - labelWidthWest)
1200 int cHeight = av.getAlignment().getHeight() * charHeight;
1202 endx = startx + cWidth - 1;
1203 int ypos = hgap; // vertical offset
1205 // iterate down the wrapped panels
1206 while ((ypos <= canvasHeight) && (endx < cursor_xpos))
1208 // update vertical offset
1209 ypos += cHeight + getAnnotationHeight() + hgap;
1211 // update horizontal offset
1213 endx = startx + cWidth - 1;
1216 xoffset = labelWidthWest;
1219 // now check if cursor is within range for x values
1220 if (cursor_xpos >= startx && cursor_xpos <= endx)
1222 // get the character the cursor is drawn at
1223 SequenceI seq = av.getAlignment().getSequenceAt(cursorY);
1224 char s = seq.getCharAt(cursorX);
1226 seqRdr.drawCursor(g, s,
1227 xoffset + (cursor_xpos - startx) * av.getCharWidth(),
1228 yoffset + (cursor_ypos - startSeq) * av.getCharHeight());
1236 * Draw a selection group over an unwrapped alignment
1239 * graphics object to draw with
1243 * start residue of area to draw
1245 * end residue of area to draw
1247 * start sequence of area to draw
1249 * end sequence of area to draw
1251 * vertical offset (used when called from wrapped alignment code)
1253 private void drawUnwrappedSelection(Graphics2D g, SequenceGroup group,
1254 int startRes, int endRes, int startSeq, int endSeq, int offset)
1256 int charWidth = av.getCharWidth();
1258 if (!av.hasHiddenColumns())
1260 drawPartialGroupOutline(g, group, startRes, endRes, startSeq, endSeq,
1265 // package into blocks of visible columns
1270 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
1271 VisibleContigsIterator regions = hidden
1272 .getVisContigsIterator(startRes, endRes + 1, true);
1273 while (regions.hasNext())
1275 int[] region = regions.next();
1276 blockEnd = region[1];
1277 blockStart = region[0];
1279 g.translate(screenY * charWidth, 0);
1280 drawPartialGroupOutline(g, group,
1281 blockStart, blockEnd, startSeq, endSeq, offset);
1283 g.translate(-screenY * charWidth, 0);
1284 screenY += blockEnd - blockStart + 1;
1290 * Draws part of a selection group outline
1298 * @param verticalOffset
1300 private void drawPartialGroupOutline(Graphics2D g, SequenceGroup group,
1301 int startRes, int endRes, int startSeq, int endSeq,
1304 int charHeight = av.getCharHeight();
1305 int charWidth = av.getCharWidth();
1306 int visWidth = (endRes - startRes + 1) * charWidth;
1310 boolean inGroup = false;
1315 List<SequenceI> seqs = group.getSequences(null);
1317 // position of start residue of group relative to startRes, in pixels
1318 int sx = (group.getStartRes() - startRes) * charWidth;
1320 // width of group in pixels
1321 int xwidth = (((group.getEndRes() + 1) - group.getStartRes())
1324 if (!(sx + xwidth < 0 || sx > visWidth))
1326 for (i = startSeq; i <= endSeq; i++)
1328 sy = verticalOffset + (i - startSeq) * charHeight;
1330 if ((sx <= (endRes - startRes) * charWidth)
1331 && seqs.contains(av.getAlignment().getSequenceAt(i)))
1334 && !seqs.contains(av.getAlignment().getSequenceAt(i + 1)))
1336 bottom = sy + charHeight;
1341 if (((top == -1) && (i == 0)) || !seqs
1342 .contains(av.getAlignment().getSequenceAt(i - 1)))
1353 drawVerticals(g, sx, xwidth, visWidth, oldY, sy);
1354 drawHorizontals(g, sx, xwidth, visWidth, top, bottom);
1356 // reset top and bottom
1364 sy = verticalOffset + ((i - startSeq) * charHeight);
1365 drawVerticals(g, sx, xwidth, visWidth, oldY, sy);
1366 drawHorizontals(g, sx, xwidth, visWidth, top, bottom);
1372 * Draw horizontal selection group boundaries at top and bottom positions
1375 * graphics object to draw on
1381 * visWidth maximum available width
1383 * position to draw top of group at
1385 * position to draw bottom of group at
1387 private void drawHorizontals(Graphics2D g, int sx, int xwidth,
1388 int visWidth, int top, int bottom)
1398 // don't let width extend beyond current block, or group extent
1400 if (startx + width >= visWidth)
1402 width = visWidth - startx;
1407 g.drawLine(startx, top, startx + width, top);
1412 g.drawLine(startx, bottom - 1, startx + width, bottom - 1);
1417 * Draw vertical lines at sx and sx+xwidth providing they lie within
1421 * graphics object to draw on
1427 * visWidth maximum available width
1433 private void drawVerticals(Graphics2D g, int sx, int xwidth, int visWidth,
1436 // if start position is visible, draw vertical line to left of
1438 if (sx >= 0 && sx < visWidth)
1440 g.drawLine(sx, oldY, sx, sy);
1443 // if end position is visible, draw vertical line to right of
1445 if (sx + xwidth < visWidth)
1447 g.drawLine(sx + xwidth, oldY, sx + xwidth, sy);
1452 * Highlights search results in the visible region by rendering as white text
1453 * on a black background. Any previous highlighting is removed. Answers true
1454 * if any highlight was left on the visible alignment (so status bar should be
1455 * set to match), else false.
1457 * Currently fastPaint is not implemented for wrapped alignments. If a wrapped
1458 * alignment had to be scrolled to show the highlighted region, then it should
1459 * be fully redrawn, otherwise a fast paint can be performed. This argument
1460 * could be removed if fast paint of scrolled wrapped alignment is coded in
1461 * future (JAL-2609).
1464 * @param noFastPaint
1467 public boolean highlightSearchResults(SearchResultsI results,
1468 boolean noFastPaint)
1474 boolean wrapped = av.getWrapAlignment();
1477 fastPaint = !noFastPaint;
1478 fastpainting = fastPaint;
1481 * to avoid redrawing the whole visible region, we instead
1482 * redraw just the minimal regions to remove previous highlights
1485 SearchResultsI previous = av.getSearchResults();
1486 av.setSearchResults(results);
1487 boolean redrawn = false;
1488 boolean drawn = false;
1491 redrawn = drawMappedPositionsWrapped(previous);
1492 drawn = drawMappedPositionsWrapped(results);
1497 redrawn = drawMappedPositions(previous);
1498 drawn = drawMappedPositions(results);
1503 * if highlights were either removed or added, repaint
1511 * return true only if highlights were added
1517 fastpainting = false;
1522 * Redraws the minimal rectangle in the visible region (if any) that includes
1523 * mapped positions of the given search results. Whether or not positions are
1524 * highlighted depends on the SearchResults set on the Viewport. This allows
1525 * this method to be called to either clear or set highlighting. Answers true
1526 * if any positions were drawn (in which case a repaint is still required),
1532 protected boolean drawMappedPositions(SearchResultsI results)
1534 if ((results == null) || (gg == null)) // JAL-2784 check gg is not null
1540 * calculate the minimal rectangle to redraw that
1541 * includes both new and existing search results
1543 int firstSeq = Integer.MAX_VALUE;
1545 int firstCol = Integer.MAX_VALUE;
1547 boolean matchFound = false;
1549 ViewportRanges ranges = av.getRanges();
1550 int firstVisibleColumn = ranges.getStartRes();
1551 int lastVisibleColumn = ranges.getEndRes();
1552 AlignmentI alignment = av.getAlignment();
1553 if (av.hasHiddenColumns())
1555 firstVisibleColumn = alignment.getHiddenColumns()
1556 .visibleToAbsoluteColumn(firstVisibleColumn);
1557 lastVisibleColumn = alignment.getHiddenColumns()
1558 .visibleToAbsoluteColumn(lastVisibleColumn);
1561 for (int seqNo = ranges.getStartSeq(); seqNo <= ranges
1562 .getEndSeq(); seqNo++)
1564 SequenceI seq = alignment.getSequenceAt(seqNo);
1566 int[] visibleResults = results.getResults(seq, firstVisibleColumn,
1568 if (visibleResults != null)
1570 for (int i = 0; i < visibleResults.length - 1; i += 2)
1572 int firstMatchedColumn = visibleResults[i];
1573 int lastMatchedColumn = visibleResults[i + 1];
1574 if (firstMatchedColumn <= lastVisibleColumn
1575 && lastMatchedColumn >= firstVisibleColumn)
1578 * found a search results match in the visible region -
1579 * remember the first and last sequence matched, and the first
1580 * and last visible columns in the matched positions
1583 firstSeq = Math.min(firstSeq, seqNo);
1584 lastSeq = Math.max(lastSeq, seqNo);
1585 firstMatchedColumn = Math.max(firstMatchedColumn,
1586 firstVisibleColumn);
1587 lastMatchedColumn = Math.min(lastMatchedColumn,
1589 firstCol = Math.min(firstCol, firstMatchedColumn);
1590 lastCol = Math.max(lastCol, lastMatchedColumn);
1598 if (av.hasHiddenColumns())
1600 firstCol = alignment.getHiddenColumns()
1601 .absoluteToVisibleColumn(firstCol);
1602 lastCol = alignment.getHiddenColumns().absoluteToVisibleColumn(lastCol);
1604 int transX = (firstCol - ranges.getStartRes()) * av.getCharWidth();
1605 int transY = (firstSeq - ranges.getStartSeq()) * av.getCharHeight();
1606 gg.translate(transX, transY);
1607 drawPanel(gg, firstCol, lastCol, firstSeq, lastSeq, 0);
1608 gg.translate(-transX, -transY);
1615 public void propertyChange(PropertyChangeEvent evt)
1617 String eventName = evt.getPropertyName();
1619 if (eventName.equals(SequenceGroup.SEQ_GROUP_CHANGED))
1625 else if (eventName.equals(ViewportRanges.MOVE_VIEWPORT))
1633 if (eventName.equals(ViewportRanges.STARTRES)
1634 || eventName.equals(ViewportRanges.STARTRESANDSEQ))
1636 // Make sure we're not trying to draw a panel
1637 // larger than the visible window
1638 if (eventName.equals(ViewportRanges.STARTRES))
1640 scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
1644 scrollX = ((int[]) evt.getNewValue())[0]
1645 - ((int[]) evt.getOldValue())[0];
1647 ViewportRanges vpRanges = av.getRanges();
1649 int range = vpRanges.getEndRes() - vpRanges.getStartRes();
1650 if (scrollX > range)
1654 else if (scrollX < -range)
1659 // Both scrolling and resizing change viewport ranges: scrolling changes
1660 // both start and end points, but resize only changes end values.
1661 // Here we only want to fastpaint on a scroll, with resize using a normal
1662 // paint, so scroll events are identified as changes to the horizontal or
1663 // vertical start value.
1664 if (eventName.equals(ViewportRanges.STARTRES))
1666 if (av.getWrapAlignment())
1668 fastPaintWrapped(scrollX);
1672 fastPaint(scrollX, 0);
1675 else if (eventName.equals(ViewportRanges.STARTSEQ))
1678 fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
1680 else if (eventName.equals(ViewportRanges.STARTRESANDSEQ))
1682 if (av.getWrapAlignment())
1684 fastPaintWrapped(scrollX);
1688 fastPaint(scrollX, 0);
1691 else if (eventName.equals(ViewportRanges.STARTSEQ))
1694 fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
1696 else if (eventName.equals(ViewportRanges.STARTRESANDSEQ))
1698 if (av.getWrapAlignment())
1700 fastPaintWrapped(scrollX);
1706 * Does a minimal update of the image for a scroll movement. This method
1707 * handles scroll movements of up to one width of the wrapped alignment (one
1708 * click in the vertical scrollbar). Larger movements (for example after a
1709 * scroll to highlight a mapped position) trigger a full redraw instead.
1712 * number of positions scrolled (right if positive, left if negative)
1714 protected void fastPaintWrapped(int scrollX)
1716 ViewportRanges ranges = av.getRanges();
1718 if (Math.abs(scrollX) > ranges.getViewportWidth())
1721 * shift of more than one view width is
1722 * overcomplicated to handle in this method
1729 if (fastpainting || gg == null)
1735 fastpainting = true;
1739 calculateWrappedGeometry(getWidth(), getHeight());
1742 * relocate the regions of the alignment that are still visible
1744 shiftWrappedAlignment(-scrollX);
1747 * add new columns (sequence, annotation)
1748 * - at top left if scrollX < 0
1749 * - at right of last two widths if scrollX > 0
1753 int startRes = ranges.getStartRes();
1754 drawWrappedWidth(gg, wrappedSpaceAboveAlignment, startRes, startRes
1755 - scrollX - 1, getHeight());
1759 fastPaintWrappedAddRight(scrollX);
1763 * draw all scales (if shown) and hidden column markers
1765 drawWrappedDecorators(gg, ranges.getStartRes());
1770 fastpainting = false;
1775 * Draws the specified number of columns at the 'end' (bottom right) of a
1776 * wrapped alignment view, including sequences and annotations if shown, but
1777 * not scales. Also draws the same number of columns at the right hand end of
1778 * the second last width shown, if the last width is not full height (so
1779 * cannot simply be copied from the graphics image).
1783 protected void fastPaintWrappedAddRight(int columns)
1790 ViewportRanges ranges = av.getRanges();
1791 int viewportWidth = ranges.getViewportWidth();
1792 int charWidth = av.getCharWidth();
1795 * draw full height alignment in the second last row, last columns, if the
1796 * last row was not full height
1798 int visibleWidths = wrappedVisibleWidths;
1799 int canvasHeight = getHeight();
1800 boolean lastWidthPartHeight = (wrappedVisibleWidths * wrappedRepeatHeightPx) > canvasHeight;
1802 if (lastWidthPartHeight)
1804 int widthsAbove = Math.max(0, visibleWidths - 2);
1805 int ypos = wrappedRepeatHeightPx * widthsAbove
1806 + wrappedSpaceAboveAlignment;
1807 int endRes = ranges.getEndRes();
1808 endRes += widthsAbove * viewportWidth;
1809 int startRes = endRes - columns;
1810 int xOffset = ((startRes - ranges.getStartRes()) % viewportWidth)
1814 * white fill first to erase annotations
1816 gg.translate(xOffset, 0);
1817 gg.setColor(Color.white);
1818 gg.fillRect(labelWidthWest, ypos,
1819 (endRes - startRes + 1) * charWidth, wrappedRepeatHeightPx);
1820 gg.translate(-xOffset, 0);
1822 drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight);
1826 * draw newly visible columns in last wrapped width (none if we
1827 * have reached the end of the alignment)
1828 * y-offset for drawing last width is height of widths above,
1831 int widthsAbove = visibleWidths - 1;
1832 int ypos = wrappedRepeatHeightPx * widthsAbove
1833 + wrappedSpaceAboveAlignment;
1834 int endRes = ranges.getEndRes();
1835 endRes += widthsAbove * viewportWidth;
1836 int startRes = endRes - columns + 1;
1839 * white fill first to erase annotations
1841 int xOffset = ((startRes - ranges.getStartRes()) % viewportWidth)
1843 gg.translate(xOffset, 0);
1844 gg.setColor(Color.white);
1845 int width = viewportWidth * charWidth - xOffset;
1846 gg.fillRect(labelWidthWest, ypos, width, wrappedRepeatHeightPx);
1847 gg.translate(-xOffset, 0);
1849 gg.setFont(av.getFont());
1850 gg.setColor(Color.black);
1852 if (startRes < ranges.getVisibleAlignmentWidth())
1854 drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight);
1858 * and finally, white fill any space below the visible alignment
1860 int heightBelow = canvasHeight - visibleWidths * wrappedRepeatHeightPx;
1861 if (heightBelow > 0)
1863 gg.setColor(Color.white);
1864 gg.fillRect(0, canvasHeight - heightBelow, getWidth(), heightBelow);
1869 * Shifts the visible alignment by the specified number of columns - left if
1870 * negative, right if positive. Copies and moves sequences and annotations (if
1871 * shown). Scales, hidden column markers and any newly visible columns must be
1876 protected void shiftWrappedAlignment(int positions)
1882 int charWidth = av.getCharWidth();
1884 int canvasHeight = getHeight();
1885 ViewportRanges ranges = av.getRanges();
1886 int viewportWidth = ranges.getViewportWidth();
1887 int widthToCopy = (ranges.getViewportWidth() - Math.abs(positions))
1889 int heightToCopy = wrappedRepeatHeightPx - wrappedSpaceAboveAlignment;
1890 int xMax = ranges.getVisibleAlignmentWidth();
1895 * shift right (after scroll left)
1896 * for each wrapped width (starting with the last), copy (width-positions)
1897 * columns from the left margin to the right margin, and copy positions
1898 * columns from the right margin of the row above (if any) to the
1899 * left margin of the current row
1903 * get y-offset of last wrapped width, first row of sequences
1905 int y = canvasHeight / wrappedRepeatHeightPx * wrappedRepeatHeightPx;
1906 y += wrappedSpaceAboveAlignment;
1907 int copyFromLeftStart = labelWidthWest;
1908 int copyFromRightStart = copyFromLeftStart + widthToCopy;
1912 gg.copyArea(copyFromLeftStart, y, widthToCopy, heightToCopy,
1913 positions * charWidth, 0);
1916 gg.copyArea(copyFromRightStart, y - wrappedRepeatHeightPx,
1917 positions * charWidth, heightToCopy, -widthToCopy,
1918 wrappedRepeatHeightPx);
1921 y -= wrappedRepeatHeightPx;
1927 * shift left (after scroll right)
1928 * for each wrapped width (starting with the first), copy (width-positions)
1929 * columns from the right margin to the left margin, and copy positions
1930 * columns from the left margin of the row below (if any) to the
1931 * right margin of the current row
1933 int xpos = av.getRanges().getStartRes();
1934 int y = wrappedSpaceAboveAlignment;
1935 int copyFromRightStart = labelWidthWest - positions * charWidth;
1937 while (y < canvasHeight)
1939 gg.copyArea(copyFromRightStart, y, widthToCopy, heightToCopy,
1940 positions * charWidth, 0);
1941 if (y + wrappedRepeatHeightPx < canvasHeight - wrappedRepeatHeightPx
1942 && (xpos + viewportWidth <= xMax))
1944 gg.copyArea(labelWidthWest, y + wrappedRepeatHeightPx, -positions
1945 * charWidth, heightToCopy, widthToCopy,
1946 -wrappedRepeatHeightPx);
1949 y += wrappedRepeatHeightPx;
1950 xpos += viewportWidth;
1957 * Redraws any positions in the search results in the visible region of a
1958 * wrapped alignment. Any highlights are drawn depending on the search results
1959 * set on the Viewport, not the <code>results</code> argument. This allows
1960 * this method to be called either to clear highlights (passing the previous
1961 * search results), or to draw new highlights.
1966 protected boolean drawMappedPositionsWrapped(SearchResultsI results)
1968 if ((results == null) || (gg == null)) // JAL-2784 check gg is not null
1972 int charHeight = av.getCharHeight();
1974 boolean matchFound = false;
1976 calculateWrappedGeometry(getWidth(), getHeight());
1977 int wrappedWidth = av.getWrappedWidth();
1978 int wrappedHeight = wrappedRepeatHeightPx;
1980 ViewportRanges ranges = av.getRanges();
1981 int canvasHeight = getHeight();
1982 int repeats = canvasHeight / wrappedHeight;
1983 if (canvasHeight / wrappedHeight > 0)
1988 int firstVisibleColumn = ranges.getStartRes();
1989 int lastVisibleColumn = ranges.getStartRes() + repeats
1990 * ranges.getViewportWidth() - 1;
1992 AlignmentI alignment = av.getAlignment();
1993 if (av.hasHiddenColumns())
1995 firstVisibleColumn = alignment.getHiddenColumns()
1996 .visibleToAbsoluteColumn(firstVisibleColumn);
1997 lastVisibleColumn = alignment.getHiddenColumns()
1998 .visibleToAbsoluteColumn(lastVisibleColumn);
2001 int gapHeight = charHeight * (av.getScaleAboveWrapped() ? 2 : 1);
2003 for (int seqNo = ranges.getStartSeq(); seqNo <= ranges
2004 .getEndSeq(); seqNo++)
2006 SequenceI seq = alignment.getSequenceAt(seqNo);
2008 int[] visibleResults = results.getResults(seq, firstVisibleColumn,
2010 if (visibleResults != null)
2012 for (int i = 0; i < visibleResults.length - 1; i += 2)
2014 int firstMatchedColumn = visibleResults[i];
2015 int lastMatchedColumn = visibleResults[i + 1];
2016 if (firstMatchedColumn <= lastVisibleColumn
2017 && lastMatchedColumn >= firstVisibleColumn)
2020 * found a search results match in the visible region
2022 firstMatchedColumn = Math.max(firstMatchedColumn,
2023 firstVisibleColumn);
2024 lastMatchedColumn = Math.min(lastMatchedColumn,
2028 * draw each mapped position separately (as contiguous positions may
2029 * wrap across lines)
2031 for (int mappedPos = firstMatchedColumn; mappedPos <= lastMatchedColumn; mappedPos++)
2033 int displayColumn = mappedPos;
2034 if (av.hasHiddenColumns())
2036 displayColumn = alignment.getHiddenColumns()
2037 .absoluteToVisibleColumn(displayColumn);
2041 * transX: offset from left edge of canvas to residue position
2043 int transX = labelWidthWest
2044 + ((displayColumn - ranges.getStartRes()) % wrappedWidth)
2045 * av.getCharWidth();
2048 * transY: offset from top edge of canvas to residue position
2050 int transY = gapHeight;
2051 transY += (displayColumn - ranges.getStartRes())
2052 / wrappedWidth * wrappedHeight;
2053 transY += (seqNo - ranges.getStartSeq()) * av.getCharHeight();
2056 * yOffset is from graphics origin to start of visible region
2058 int yOffset = 0;// (displayColumn / wrappedWidth) * wrappedHeight;
2059 if (transY < getHeight())
2062 gg.translate(transX, transY);
2063 drawPanel(gg, displayColumn, displayColumn, seqNo, seqNo,
2065 gg.translate(-transX, -transY);
2077 * Answers the width in pixels of the left scale labels (0 if not shown)
2081 int getLabelWidthWest()
2083 return labelWidthWest;