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.renderer.ScaleRenderer;
29 import jalview.renderer.ScaleRenderer.ScaleMark;
30 import jalview.util.Comparison;
31 import jalview.viewmodel.ViewportListenerI;
32 import jalview.viewmodel.ViewportRanges;
34 import java.awt.AlphaComposite;
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.List;
47 import javax.swing.JComponent;
50 * The Swing component on which the alignment sequences, and annotations (if
51 * shown), are drawn. This includes scales above, left and right (if shown) in
52 * Wrapped mode, but not the scale above in Unwrapped mode.
55 public class SeqCanvas extends JComponent implements ViewportListenerI
57 private static final String ZEROS = "0000000000";
59 final FeatureRenderer fr;
69 private final SequenceRenderer seqRdr;
71 private boolean fastPaint = false;
73 private boolean fastpainting = false;
75 private AnnotationPanel annotations;
78 * measurements for drawing a wrapped alignment
80 private int labelWidthEast; // label right width in pixels if shown
82 private int labelWidthWest; // label left width in pixels if shown
84 private int wrappedSpaceAboveAlignment; // gap between widths
86 private int wrappedRepeatHeightPx; // height in pixels of wrapped width
88 private int wrappedVisibleWidths; // number of wrapped widths displayed
90 private Graphics2D gg;
93 * Creates a new SeqCanvas object.
97 public SeqCanvas(AlignmentPanel ap)
100 fr = new FeatureRenderer(ap);
101 seqRdr = new SequenceRenderer(av);
102 setLayout(new BorderLayout());
103 PaintRefresher.Register(this, av.getSequenceSetId());
104 setBackground(Color.white);
106 av.getRanges().addPropertyChangeListener(this);
109 public SequenceRenderer getSequenceRenderer()
114 public FeatureRenderer getFeatureRenderer()
120 * Draws the scale above a region of a wrapped alignment, consisting of a
121 * column number every major interval (10 columns).
124 * the graphics context to draw on, positioned at the start (bottom
125 * left) of the line on which to draw any scale marks
127 * start alignment column (0..)
129 * end alignment column (0..)
131 * y offset to draw at
133 private void drawNorthScale(Graphics g, int startx, int endx, int ypos)
135 int charHeight = av.getCharHeight();
136 int charWidth = av.getCharWidth();
139 * white fill the scale space (for the fastPaint case)
141 g.setColor(Color.white);
142 g.fillRect(0, ypos - charHeight - charHeight / 2, getWidth(),
143 charHeight * 3 / 2 + 2);
144 g.setColor(Color.black);
146 List<ScaleMark> marks = new ScaleRenderer().calculateMarks(av, startx,
148 for (ScaleMark mark : marks)
150 int mpos = mark.column; // (i - startx - 1)
155 String mstring = mark.text;
161 g.drawString(mstring, mpos * charWidth, ypos - (charHeight / 2));
165 * draw a tick mark below the column number, centred on the column;
166 * height of tick mark is 4 pixels less than half a character
168 int xpos = (mpos * charWidth) + (charWidth / 2);
169 g.drawLine(xpos, (ypos + 2) - (charHeight / 2), xpos, ypos - 2);
175 * Draw the scale to the left or right of a wrapped alignment
178 * graphics context, positioned at the start of the scale to be drawn
180 * first column of wrapped width (0.. excluding any hidden columns)
182 * last column of wrapped width (0.. excluding any hidden columns)
184 * vertical offset at which to begin the scale
186 * if true, scale is left of residues, if false, scale is right
188 void drawVerticalScale(Graphics g, final int startx, final int endx,
189 final int ypos, final boolean left)
191 int charHeight = av.getCharHeight();
192 int charWidth = av.getCharWidth();
194 int yPos = ypos + charHeight;
198 if (av.hasHiddenColumns())
200 HiddenColumns hiddenColumns = av.getAlignment().getHiddenColumns();
201 startX = hiddenColumns.adjustForHiddenColumns(startx);
202 endX = hiddenColumns.adjustForHiddenColumns(endx);
204 FontMetrics fm = getFontMetrics(av.getFont());
206 for (int i = 0; i < av.getAlignment().getHeight(); i++)
208 SequenceI seq = av.getAlignment().getSequenceAt(i);
211 * find sequence position of first non-gapped position -
212 * to the right if scale left, to the left if scale right
214 int index = left ? startX : endX;
216 while (index >= startX && index <= endX)
218 if (!Comparison.isGap(seq.getCharAt(index)))
220 value = seq.findPosition(index);
234 * white fill the space for the scale
236 g.setColor(Color.white);
237 int y = (yPos + (i * charHeight)) - (charHeight / 5);
238 // fillRect origin is top left of rectangle
239 g.fillRect(0, y - charHeight, left ? labelWidthWest : labelWidthEast,
245 * draw scale value, right justified within its width less half a
246 * character width padding on the right
248 int labelSpace = left ? labelWidthWest : labelWidthEast;
249 labelSpace -= charWidth / 2; // leave space to the right
250 String valueAsString = String.valueOf(value);
251 int labelLength = fm.stringWidth(valueAsString);
252 int xOffset = labelSpace - labelLength;
253 g.setColor(Color.black);
254 g.drawString(valueAsString, xOffset, y);
260 * Does a fast paint of an alignment in response to a scroll. Most of the
261 * visible region is simply copied and shifted, and then any newly visible
262 * columns or rows are drawn. The scroll may be horizontal or vertical, but
263 * not both at once. Scrolling may be the result of
265 * <li>dragging a scroll bar</li>
266 * <li>clicking in the scroll bar</li>
267 * <li>scrolling by trackpad, middle mouse button, or other device</li>
268 * <li>by moving the box in the Overview window</li>
269 * <li>programmatically to make a highlighted position visible</li>
273 * columns to shift right (positive) or left (negative)
275 * rows to shift down (positive) or up (negative)
277 public void fastPaint(int horizontal, int vertical)
279 if (fastpainting || gg == null || img == null)
288 int charHeight = av.getCharHeight();
289 int charWidth = av.getCharWidth();
291 ViewportRanges ranges = av.getRanges();
292 int startRes = ranges.getStartRes();
293 int endRes = ranges.getEndRes();
294 int startSeq = ranges.getStartSeq();
295 int endSeq = ranges.getEndSeq();
299 gg.copyArea(horizontal * charWidth, vertical * charHeight,
300 img.getWidth(), img.getHeight(), -horizontal * charWidth,
301 -vertical * charHeight);
303 if (horizontal > 0) // scrollbar pulled right, image to the left
305 transX = (endRes - startRes - horizontal) * charWidth;
306 startRes = endRes - horizontal;
308 else if (horizontal < 0)
310 endRes = startRes - horizontal;
312 else if (vertical > 0) // scroll down
314 startSeq = endSeq - vertical;
316 if (startSeq < ranges.getStartSeq())
317 { // ie scrolling too fast, more than a page at a time
318 startSeq = ranges.getStartSeq();
322 transY = img.getHeight() - ((vertical + 1) * charHeight);
325 else if (vertical < 0)
327 endSeq = startSeq - vertical;
329 if (endSeq > ranges.getEndSeq())
331 endSeq = ranges.getEndSeq();
335 gg.translate(transX, transY);
336 drawPanel(gg, startRes, endRes, startSeq, endSeq, 0);
337 gg.translate(-transX, -transY);
342 fastpainting = false;
347 public void paintComponent(Graphics g)
349 super.paintComponent(g);
351 int charHeight = av.getCharHeight();
352 int charWidth = av.getCharWidth();
354 ViewportRanges ranges = av.getRanges();
356 int width = getWidth();
357 int height = getHeight();
359 width -= (width % charWidth);
360 height -= (height % charHeight);
362 // selectImage is the selection group outline image
363 BufferedImage selectImage = drawSelectionGroup(
364 ranges.getStartRes(), ranges.getEndRes(),
365 ranges.getStartSeq(), ranges.getEndSeq());
367 if ((img != null) && (fastPaint
368 || (getVisibleRect().width != g.getClipBounds().width)
369 || (getVisibleRect().height != g.getClipBounds().height)))
371 BufferedImage lcimg = buildLocalImage(selectImage);
372 g.drawImage(lcimg, 0, 0, this);
375 else if ((width > 0) && (height > 0))
377 // img is a cached version of the last view we drew, if any
378 // if we have no img or the size has changed, make a new one
379 if (img == null || width != img.getWidth()
380 || height != img.getHeight())
387 gg = (Graphics2D) img.getGraphics();
388 gg.setFont(av.getFont());
393 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
394 RenderingHints.VALUE_ANTIALIAS_ON);
397 gg.setColor(Color.white);
398 gg.fillRect(0, 0, img.getWidth(), img.getHeight());
400 if (av.getWrapAlignment())
402 drawWrappedPanel(gg, getWidth(), getHeight(), ranges.getStartRes());
406 drawPanel(gg, ranges.getStartRes(), ranges.getEndRes(),
407 ranges.getStartSeq(), ranges.getEndSeq(), 0);
410 // lcimg is a local *copy* of img which we'll draw selectImage on top of
411 BufferedImage lcimg = buildLocalImage(selectImage);
412 g.drawImage(lcimg, 0, 0, this);
417 * Draw an alignment panel for printing
420 * Graphics object to draw with
422 * start residue of print area
424 * end residue of print area
426 * start sequence of print area
428 * end sequence of print area
430 public void drawPanelForPrinting(Graphics g1, int startRes, int endRes,
431 int startSeq, int endSeq)
433 drawPanel(g1, startRes, endRes, startSeq, endSeq, 0);
435 BufferedImage selectImage = drawSelectionGroup(startRes, endRes,
437 if (selectImage != null)
439 ((Graphics2D) g1).setComposite(AlphaComposite
440 .getInstance(AlphaComposite.SRC_OVER));
441 g1.drawImage(selectImage, 0, 0, this);
446 * Draw a wrapped alignment panel for printing
449 * Graphics object to draw with
451 * width of drawing area
452 * @param canvasHeight
453 * height of drawing area
455 * start residue of print area
457 public void drawWrappedPanelForPrinting(Graphics g, int canvasWidth,
458 int canvasHeight, int startRes)
460 SequenceGroup group = av.getSelectionGroup();
462 drawWrappedPanel(g, canvasWidth, canvasHeight, startRes);
466 BufferedImage selectImage = null;
469 selectImage = new BufferedImage(canvasWidth, canvasHeight,
470 BufferedImage.TYPE_INT_ARGB); // ARGB so alpha compositing works
471 } catch (OutOfMemoryError er)
474 System.err.println("Print image OutOfMemory Error.\n" + er);
475 new OOMWarning("Creating wrapped alignment image for printing", er);
477 if (selectImage != null)
479 Graphics2D g2 = selectImage.createGraphics();
480 setupSelectionGroup(g2, selectImage);
481 drawWrappedSelection(g2, group, canvasWidth, canvasHeight,
485 AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
486 g.drawImage(selectImage, 0, 0, this);
493 * Make a local image by combining the cached image img
496 private BufferedImage buildLocalImage(BufferedImage selectImage)
498 // clone the cached image
499 BufferedImage lcimg = new BufferedImage(img.getWidth(), img.getHeight(),
501 Graphics2D g2d = lcimg.createGraphics();
502 g2d.drawImage(img, 0, 0, null);
504 // overlay selection group on lcimg
505 if (selectImage != null)
508 AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
509 g2d.drawImage(selectImage, 0, 0, this);
517 * Set up a buffered image of the correct height and size for the sequence canvas
519 private BufferedImage setupImage()
521 BufferedImage lcimg = null;
523 int charWidth = av.getCharWidth();
524 int charHeight = av.getCharHeight();
526 int width = getWidth();
527 int height = getHeight();
529 width -= (width % charWidth);
530 height -= (height % charHeight);
532 if ((width < 1) || (height < 1))
539 lcimg = new BufferedImage(width, height,
540 BufferedImage.TYPE_INT_ARGB); // ARGB so alpha compositing works
541 } catch (OutOfMemoryError er)
545 "Group image OutOfMemory Redraw Error.\n" + er);
546 new OOMWarning("Creating alignment image for display", er);
555 * Returns the visible width of the canvas in residues, after allowing for
556 * East or West scales (if shown)
559 * the width in pixels (possibly including scales)
563 public int getWrappedCanvasWidth(int canvasWidth)
565 int charWidth = av.getCharWidth();
567 FontMetrics fm = getFontMetrics(av.getFont());
571 if (av.getScaleRightWrapped() || av.getScaleLeftWrapped())
573 labelWidth = getLabelWidth(fm);
576 labelWidthEast = av.getScaleRightWrapped() ? labelWidth : 0;
578 labelWidthWest = av.getScaleLeftWrapped() ? labelWidth : 0;
580 return (canvasWidth - labelWidthEast - labelWidthWest) / charWidth;
584 * Returns a pixel width sufficient to show the largest sequence coordinate
585 * (end position) in the alignment, calculated as the FontMetrics width of
586 * zeroes "0000000" limited to the number of decimal digits to be shown (3 for
587 * 1-10, 4 for 11-99 etc). One character width is added to this, to allow for
588 * half a character width space on either side.
593 protected int getLabelWidth(FontMetrics fm)
596 * find the biggest sequence end position we need to show
597 * (note this is not necessarily the sequence length)
600 AlignmentI alignment = av.getAlignment();
601 for (int i = 0; i < alignment.getHeight(); i++)
603 maxWidth = Math.max(maxWidth, alignment.getSequenceAt(i).getEnd());
607 for (int i = maxWidth; i > 0; i /= 10)
612 return fm.stringWidth(ZEROS.substring(0, length)) + av.getCharWidth();
616 * Draws as many widths of a wrapped alignment as can fit in the visible
621 * available width in pixels
622 * @param canvasHeight
623 * available height in pixels
625 * the first column (0...) of the alignment to draw
627 public void drawWrappedPanel(Graphics g, int canvasWidth,
628 int canvasHeight, final int startColumn)
630 int wrappedWidthInResidues = calculateWrappedGeometry(canvasWidth,
633 av.setWrappedWidth(wrappedWidthInResidues);
635 ViewportRanges ranges = av.getRanges();
636 ranges.setViewportStartAndWidth(startColumn, wrappedWidthInResidues);
639 * draw one width at a time (including any scales or annotation shown),
640 * until we have run out of either alignment or vertical space available
642 int ypos = wrappedSpaceAboveAlignment;
643 int maxWidth = ranges.getVisibleAlignmentWidth();
645 int start = startColumn;
646 int currentWidth = 0;
647 while ((currentWidth < wrappedVisibleWidths) && (start < maxWidth))
650 .min(maxWidth, start + wrappedWidthInResidues - 1);
651 drawWrappedWidth(g, ypos, start, endColumn, canvasHeight);
652 ypos += wrappedRepeatHeightPx;
653 start += wrappedWidthInResidues;
657 drawWrappedDecorators(g, startColumn);
661 * Calculates and saves values needed when rendering a wrapped alignment.
662 * These depend on many factors, including
664 * <li>canvas width and height</li>
665 * <li>number of visible sequences, and height of annotations if shown</li>
666 * <li>font and character width</li>
667 * <li>whether scales are shown left, right or above the alignment</li>
671 * @param canvasHeight
672 * @return the number of residue columns in each width
674 protected int calculateWrappedGeometry(int canvasWidth, int canvasHeight)
676 int charHeight = av.getCharHeight();
679 * vertical space in pixels between wrapped widths of alignment
680 * - one character height, or two if scale above is drawn
682 wrappedSpaceAboveAlignment = charHeight
683 * (av.getScaleAboveWrapped() ? 2 : 1);
686 * height in pixels of the wrapped widths
688 wrappedRepeatHeightPx = wrappedSpaceAboveAlignment;
690 wrappedRepeatHeightPx += av.getRanges().getViewportHeight()
692 // add annotations panel height if shown
693 wrappedRepeatHeightPx += getAnnotationHeight();
696 * number of visible widths (the last one may be part height),
697 * ensuring a part height includes at least one sequence
699 ViewportRanges ranges = av.getRanges();
700 wrappedVisibleWidths = canvasHeight / wrappedRepeatHeightPx;
701 int remainder = canvasHeight % wrappedRepeatHeightPx;
702 if (remainder >= (wrappedSpaceAboveAlignment + charHeight))
704 wrappedVisibleWidths++;
708 * compute width in residues; this also sets East and West label widths
710 int wrappedWidthInResidues = getWrappedCanvasWidth(canvasWidth);
713 * limit visibleWidths to not exceed width of alignment
715 int xMax = ranges.getVisibleAlignmentWidth();
716 int startToEnd = xMax - ranges.getStartRes();
717 int maxWidths = startToEnd / wrappedWidthInResidues;
718 if (startToEnd % wrappedWidthInResidues > 0)
722 wrappedVisibleWidths = Math.min(wrappedVisibleWidths, maxWidths);
724 return wrappedWidthInResidues;
728 * Draws one width of a wrapped alignment, including sequences and
729 * annnotations, if shown, but not scales or hidden column markers
735 * @param canvasHeight
737 protected void drawWrappedWidth(Graphics g, int ypos, int startColumn,
738 int endColumn, int canvasHeight)
740 ViewportRanges ranges = av.getRanges();
741 int viewportWidth = ranges.getViewportWidth();
743 int endx = Math.min(startColumn + viewportWidth - 1, endColumn);
746 * move right before drawing by the width of the scale left (if any)
747 * plus column offset from left margin (usually zero, but may be non-zero
748 * when fast painting is drawing just a few columns)
750 int charWidth = av.getCharWidth();
751 int xOffset = labelWidthWest
752 + ((startColumn - ranges.getStartRes()) % viewportWidth)
754 g.translate(xOffset, 0);
756 // When printing we have an extra clipped region,
757 // the Printable page which we need to account for here
758 Shape clip = g.getClip();
762 g.setClip(0, 0, viewportWidth * charWidth, canvasHeight);
766 g.setClip(0, (int) clip.getBounds().getY(),
767 viewportWidth * charWidth, (int) clip.getBounds().getHeight());
771 * white fill the region to be drawn (so incremental fast paint doesn't
772 * scribble over an existing image)
774 gg.setColor(Color.white);
775 gg.fillRect(0, ypos, (endx - startColumn + 1) * charWidth,
776 wrappedRepeatHeightPx);
778 drawPanel(g, startColumn, endx, 0, av.getAlignment().getHeight() - 1,
781 int cHeight = av.getAlignment().getHeight() * av.getCharHeight();
783 if (av.isShowAnnotation())
785 g.translate(0, cHeight + ypos + 3);
786 if (annotations == null)
788 annotations = new AnnotationPanel(av);
791 annotations.renderer.drawComponent(annotations, av, g, -1,
792 startColumn, endx + 1);
793 g.translate(0, -cHeight - ypos - 3);
796 g.translate(-xOffset, 0);
800 * Draws scales left, right and above (if shown), and any hidden column
801 * markers, on all widths of the wrapped alignment
806 protected void drawWrappedDecorators(Graphics g, final int startColumn)
808 int charWidth = av.getCharWidth();
810 g.setFont(av.getFont());
811 g.setColor(Color.black);
813 int ypos = wrappedSpaceAboveAlignment;
814 ViewportRanges ranges = av.getRanges();
815 int viewportWidth = ranges.getViewportWidth();
816 int maxWidth = ranges.getVisibleAlignmentWidth();
818 int startCol = startColumn;
820 while (widthsDrawn < wrappedVisibleWidths)
822 int endColumn = Math.min(maxWidth, startCol + viewportWidth - 1);
824 if (av.getScaleLeftWrapped())
826 drawVerticalScale(g, startCol, endColumn - 1, ypos, true);
829 if (av.getScaleRightWrapped())
831 int x = labelWidthWest + viewportWidth * charWidth;
833 drawVerticalScale(g, startCol, endColumn, ypos, false);
838 * white fill region of scale above and hidden column markers
839 * (to support incremental fast paint of image)
841 g.setColor(Color.white);
842 g.fillRect(0, ypos - wrappedSpaceAboveAlignment, viewportWidth
843 * charWidth + labelWidthWest, wrappedSpaceAboveAlignment);
844 g.setColor(Color.black);
846 g.translate(labelWidthWest, 0);
848 if (av.getScaleAboveWrapped())
850 drawNorthScale(g, startCol, endColumn, ypos);
853 if (av.hasHiddenColumns() && av.getShowHiddenMarkers())
855 drawHiddenColumnMarkers(g, ypos, startCol, endColumn);
858 g.translate(-labelWidthWest, 0);
860 ypos += wrappedRepeatHeightPx;
861 startCol += viewportWidth;
867 * Draws markers (triangles) above hidden column positions between startColumn
875 protected void drawHiddenColumnMarkers(Graphics g, int ypos,
876 int startColumn, int endColumn)
878 int charHeight = av.getCharHeight();
879 int charWidth = av.getCharWidth();
881 g.setColor(Color.blue);
882 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
883 List<Integer> positions = hidden.findHiddenRegionPositions();
884 for (int pos : positions)
886 int res = pos - startColumn;
888 if (res < 0 || res > endColumn - startColumn + 1)
894 * draw a downward-pointing triangle at the hidden columns location
895 * (before the following visible column)
897 int xMiddle = res * charWidth;
898 int[] xPoints = new int[] { xMiddle - charHeight / 4,
899 xMiddle + charHeight / 4, xMiddle };
900 int yTop = ypos - (charHeight / 2);
901 int[] yPoints = new int[] { yTop, yTop, yTop + 8 };
902 g.fillPolygon(xPoints, yPoints, 3);
907 * Draw a selection group over a wrapped alignment
909 private void drawWrappedSelection(Graphics2D g, SequenceGroup group,
911 int canvasHeight, int startRes)
913 int charHeight = av.getCharHeight();
914 int charWidth = av.getCharWidth();
916 // height gap above each panel
917 int hgap = charHeight;
918 if (av.getScaleAboveWrapped())
923 int cWidth = (canvasWidth - labelWidthEast - labelWidthWest)
925 int cHeight = av.getAlignment().getHeight() * charHeight;
927 int startx = startRes;
929 int ypos = hgap; // vertical offset
930 int maxwidth = av.getAlignment().getWidth();
932 if (av.hasHiddenColumns())
934 maxwidth = av.getAlignment().getHiddenColumns()
935 .findColumnPosition(maxwidth);
938 // chop the wrapped alignment extent up into panel-sized blocks and treat
939 // each block as if it were a block from an unwrapped alignment
940 while ((ypos <= canvasHeight) && (startx < maxwidth))
942 // set end value to be start + width, or maxwidth, whichever is smaller
943 endx = startx + cWidth - 1;
950 g.translate(labelWidthWest, 0);
952 drawUnwrappedSelection(g, group, startx, endx, 0,
953 av.getAlignment().getHeight() - 1,
956 g.translate(-labelWidthWest, 0);
958 // update vertical offset
959 ypos += cHeight + getAnnotationHeight() + hgap;
961 // update horizontal offset
966 int getAnnotationHeight()
968 if (!av.isShowAnnotation())
973 if (annotations == null)
975 annotations = new AnnotationPanel(av);
978 return annotations.adjustPanelHeight();
982 * Draws the visible region of the alignment on the graphics context. If there
983 * are hidden column markers in the visible region, then each sub-region
984 * between the markers is drawn separately, followed by the hidden column
988 * the graphics context, positioned at the first residue to be drawn
990 * offset of the first column to draw (0..)
992 * offset of the last column to draw (0..)
994 * offset of the first sequence to draw (0..)
996 * offset of the last sequence to draw (0..)
998 * vertical offset at which to draw (for wrapped alignments)
1000 public void drawPanel(Graphics g1, final int startRes, final int endRes,
1001 final int startSeq, final int endSeq, final int yOffset)
1003 int charHeight = av.getCharHeight();
1004 int charWidth = av.getCharWidth();
1006 if (!av.hasHiddenColumns())
1008 draw(g1, startRes, endRes, startSeq, endSeq, yOffset);
1013 final int screenYMax = endRes - startRes;
1014 int blockStart = startRes;
1015 int blockEnd = endRes;
1017 for (int[] region : av.getAlignment().getHiddenColumns()
1018 .getHiddenColumnsCopy())
1020 int hideStart = region[0];
1021 int hideEnd = region[1];
1023 if (hideStart <= blockStart)
1025 blockStart += (hideEnd - hideStart) + 1;
1030 * draw up to just before the next hidden region, or the end of
1031 * the visible region, whichever comes first
1033 blockEnd = Math.min(hideStart - 1, blockStart + screenYMax
1036 g1.translate(screenY * charWidth, 0);
1038 draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset);
1041 * draw the downline of the hidden column marker (ScalePanel draws the
1042 * triangle on top) if we reached it
1044 if (av.getShowHiddenMarkers() && blockEnd == hideStart - 1)
1046 g1.setColor(Color.blue);
1048 g1.drawLine((blockEnd - blockStart + 1) * charWidth - 1,
1049 0 + yOffset, (blockEnd - blockStart + 1) * charWidth - 1,
1050 (endSeq - startSeq + 1) * charHeight + yOffset);
1053 g1.translate(-screenY * charWidth, 0);
1054 screenY += blockEnd - blockStart + 1;
1055 blockStart = hideEnd + 1;
1057 if (screenY > screenYMax)
1059 // already rendered last block
1064 if (screenY <= screenYMax)
1066 // remaining visible region to render
1067 blockEnd = blockStart + screenYMax - screenY;
1068 g1.translate(screenY * charWidth, 0);
1069 draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset);
1071 g1.translate(-screenY * charWidth, 0);
1078 * Draws a region of the visible alignment
1082 * offset of the first column in the visible region (0..)
1084 * offset of the last column in the visible region (0..)
1086 * offset of the first sequence in the visible region (0..)
1088 * offset of the last sequence in the visible region (0..)
1090 * vertical offset at which to draw (for wrapped alignments)
1092 private void draw(Graphics g, int startRes, int endRes, int startSeq,
1093 int endSeq, int offset)
1095 int charHeight = av.getCharHeight();
1096 int charWidth = av.getCharWidth();
1098 g.setFont(av.getFont());
1099 seqRdr.prepare(g, av.isRenderGaps());
1103 // / First draw the sequences
1104 // ///////////////////////////
1105 for (int i = startSeq; i <= endSeq; i++)
1107 nextSeq = av.getAlignment().getSequenceAt(i);
1108 if (nextSeq == null)
1110 // occasionally, a race condition occurs such that the alignment row is
1114 seqRdr.drawSequence(nextSeq, av.getAlignment().findAllGroups(nextSeq),
1115 startRes, endRes, offset + ((i - startSeq) * charHeight));
1117 if (av.isShowSequenceFeatures())
1119 fr.drawSequence(g, nextSeq, startRes, endRes,
1120 offset + ((i - startSeq) * charHeight), false);
1124 * highlight search Results once sequence has been drawn
1126 if (av.hasSearchResults())
1128 SearchResultsI searchResults = av.getSearchResults();
1129 int[] visibleResults = searchResults.getResults(nextSeq,
1131 if (visibleResults != null)
1133 for (int r = 0; r < visibleResults.length; r += 2)
1135 seqRdr.drawHighlightedText(nextSeq, visibleResults[r],
1136 visibleResults[r + 1], (visibleResults[r] - startRes)
1138 + ((i - startSeq) * charHeight));
1143 if (av.cursorMode && cursorY == i && cursorX >= startRes
1144 && cursorX <= endRes)
1146 seqRdr.drawCursor(nextSeq, cursorX, (cursorX - startRes) * charWidth,
1147 offset + ((i - startSeq) * charHeight));
1151 if (av.getSelectionGroup() != null
1152 || av.getAlignment().getGroups().size() > 0)
1154 drawGroupsBoundaries(g, startRes, endRes, startSeq, endSeq, offset);
1159 void drawGroupsBoundaries(Graphics g1, int startRes, int endRes,
1160 int startSeq, int endSeq, int offset)
1162 Graphics2D g = (Graphics2D) g1;
1164 // ///////////////////////////////////
1165 // Now outline any areas if necessary
1166 // ///////////////////////////////////
1168 SequenceGroup group = null;
1169 int groupIndex = -1;
1171 if (av.getAlignment().getGroups().size() > 0)
1173 group = av.getAlignment().getGroups().get(0);
1179 g.setStroke(new BasicStroke());
1180 g.setColor(group.getOutlineColour());
1184 drawPartialGroupOutline(g, group, startRes, endRes, startSeq,
1189 g.setStroke(new BasicStroke());
1191 if (groupIndex >= av.getAlignment().getGroups().size())
1196 group = av.getAlignment().getGroups().get(groupIndex);
1198 } while (groupIndex < av.getAlignment().getGroups().size());
1206 * Draw the selection group as a separate image and overlay
1208 private BufferedImage drawSelectionGroup(int startRes, int endRes,
1209 int startSeq, int endSeq)
1211 // get a new image of the correct size
1212 BufferedImage selectionImage = setupImage();
1214 if (selectionImage == null)
1219 SequenceGroup group = av.getSelectionGroup();
1226 // set up drawing colour
1227 Graphics2D g = (Graphics2D) selectionImage.getGraphics();
1229 setupSelectionGroup(g, selectionImage);
1231 if (!av.getWrapAlignment())
1233 drawUnwrappedSelection(g, group, startRes, endRes, startSeq, endSeq,
1238 drawWrappedSelection(g, group, getWidth(), getHeight(),
1239 av.getRanges().getStartRes());
1243 return selectionImage;
1247 * Set up graphics for selection group
1249 private void setupSelectionGroup(Graphics2D g,
1250 BufferedImage selectionImage)
1252 // set background to transparent
1253 g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
1254 g.fillRect(0, 0, selectionImage.getWidth(), selectionImage.getHeight());
1256 // set up foreground to draw red dashed line
1257 g.setComposite(AlphaComposite.Src);
1258 g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
1259 BasicStroke.JOIN_ROUND, 3f, new float[]
1261 g.setColor(Color.RED);
1265 * Draw a selection group over an unwrapped alignment
1266 * @param g graphics object to draw with
1267 * @param group selection group
1268 * @param startRes start residue of area to draw
1269 * @param endRes end residue of area to draw
1270 * @param startSeq start sequence of area to draw
1271 * @param endSeq end sequence of area to draw
1272 * @param offset vertical offset (used when called from wrapped alignment code)
1274 private void drawUnwrappedSelection(Graphics2D g, SequenceGroup group,
1275 int startRes, int endRes, int startSeq, int endSeq, int offset)
1277 int charWidth = av.getCharWidth();
1279 if (!av.hasHiddenColumns())
1281 drawPartialGroupOutline(g, group, startRes, endRes, startSeq, endSeq,
1286 // package into blocks of visible columns
1288 int blockStart = startRes;
1289 int blockEnd = endRes;
1291 for (int[] region : av.getAlignment().getHiddenColumns()
1292 .getHiddenColumnsCopy())
1294 int hideStart = region[0];
1295 int hideEnd = region[1];
1297 if (hideStart <= blockStart)
1299 blockStart += (hideEnd - hideStart) + 1;
1303 blockEnd = hideStart - 1;
1305 g.translate(screenY * charWidth, 0);
1306 drawPartialGroupOutline(g, group,
1307 blockStart, blockEnd, startSeq, endSeq, offset);
1309 g.translate(-screenY * charWidth, 0);
1310 screenY += blockEnd - blockStart + 1;
1311 blockStart = hideEnd + 1;
1313 if (screenY > (endRes - startRes))
1315 // already rendered last block
1320 if (screenY <= (endRes - startRes))
1322 // remaining visible region to render
1323 blockEnd = blockStart + (endRes - startRes) - screenY;
1324 g.translate(screenY * charWidth, 0);
1325 drawPartialGroupOutline(g, group,
1326 blockStart, blockEnd, startSeq, endSeq, offset);
1328 g.translate(-screenY * charWidth, 0);
1334 * Draw the selection group as a separate image and overlay
1336 private void drawPartialGroupOutline(Graphics2D g, SequenceGroup group,
1337 int startRes, int endRes, int startSeq, int endSeq,
1340 int charHeight = av.getCharHeight();
1341 int charWidth = av.getCharWidth();
1343 int visWidth = (endRes - startRes + 1) * charWidth;
1347 boolean inGroup = false;
1355 for (i = startSeq; i <= endSeq; i++)
1357 // position of start residue of group relative to startRes, in pixels
1358 sx = (group.getStartRes() - startRes) * charWidth;
1360 // width of group in pixels
1361 xwidth = (((group.getEndRes() + 1) - group.getStartRes()) * charWidth)
1364 sy = verticalOffset + (i - startSeq) * charHeight;
1366 if (sx + xwidth < 0 || sx > visWidth)
1371 if ((sx <= (endRes - startRes) * charWidth)
1372 && group.getSequences(null)
1373 .contains(av.getAlignment().getSequenceAt(i)))
1375 if ((bottom == -1) && !group.getSequences(null)
1376 .contains(av.getAlignment().getSequenceAt(i + 1)))
1378 bottom = sy + charHeight;
1383 if (((top == -1) && (i == 0)) || !group.getSequences(null)
1384 .contains(av.getAlignment().getSequenceAt(i - 1)))
1397 // if start position is visible, draw vertical line to left of
1399 if (sx >= 0 && sx < visWidth)
1401 g.drawLine(sx, oldY, sx, sy);
1404 // if end position is visible, draw vertical line to right of
1406 if (sx + xwidth < visWidth)
1408 g.drawLine(sx + xwidth, oldY, sx + xwidth, sy);
1417 // don't let width extend beyond current block, or group extent
1419 if (sx + xwidth >= (endRes - startRes + 1) * charWidth)
1421 xwidth = (endRes - startRes + 1) * charWidth - sx;
1424 // draw horizontal line at top of group
1427 g.drawLine(sx, top, sx + xwidth, top);
1431 // draw horizontal line at bottom of group
1434 g.drawLine(sx, bottom, sx + xwidth, bottom);
1445 sy = verticalOffset + ((i - startSeq) * charHeight);
1446 if (sx >= 0 && sx < visWidth)
1448 g.drawLine(sx, oldY, sx, sy);
1451 if (sx + xwidth < visWidth)
1453 g.drawLine(sx + xwidth, oldY, sx + xwidth, sy);
1462 if (sx + xwidth > visWidth)
1466 else if (sx + xwidth >= (endRes - startRes + 1) * charWidth)
1468 xwidth = (endRes - startRes + 1) * charWidth;
1473 g.drawLine(sx, top, sx + xwidth, top);
1479 g.drawLine(sx, bottom - 1, sx + xwidth, bottom - 1);
1488 * Highlights search results in the visible region by rendering as white text
1489 * on a black background. Any previous highlighting is removed. Answers true
1490 * if any highlight was left on the visible alignment (so status bar should be
1491 * set to match), else false.
1493 * Currently fastPaint is not implemented for wrapped alignments. If a wrapped
1494 * alignment had to be scrolled to show the highlighted region, then it should
1495 * be fully redrawn, otherwise a fast paint can be performed. This argument
1496 * could be removed if fast paint of scrolled wrapped alignment is coded in
1497 * future (JAL-2609).
1500 * @param noFastPaint
1503 public boolean highlightSearchResults(SearchResultsI results,
1504 boolean noFastPaint)
1510 boolean wrapped = av.getWrapAlignment();
1513 fastPaint = !noFastPaint;
1514 fastpainting = fastPaint;
1517 * to avoid redrawing the whole visible region, we instead
1518 * redraw just the minimal regions to remove previous highlights
1521 SearchResultsI previous = av.getSearchResults();
1522 av.setSearchResults(results);
1523 boolean redrawn = false;
1524 boolean drawn = false;
1527 redrawn = drawMappedPositionsWrapped(previous);
1528 drawn = drawMappedPositionsWrapped(results);
1533 redrawn = drawMappedPositions(previous);
1534 drawn = drawMappedPositions(results);
1539 * if highlights were either removed or added, repaint
1547 * return true only if highlights were added
1553 fastpainting = false;
1558 * Redraws the minimal rectangle in the visible region (if any) that includes
1559 * mapped positions of the given search results. Whether or not positions are
1560 * highlighted depends on the SearchResults set on the Viewport. This allows
1561 * this method to be called to either clear or set highlighting. Answers true
1562 * if any positions were drawn (in which case a repaint is still required),
1568 protected boolean drawMappedPositions(SearchResultsI results)
1570 if (results == null)
1576 * calculate the minimal rectangle to redraw that
1577 * includes both new and existing search results
1579 int firstSeq = Integer.MAX_VALUE;
1581 int firstCol = Integer.MAX_VALUE;
1583 boolean matchFound = false;
1585 ViewportRanges ranges = av.getRanges();
1586 int firstVisibleColumn = ranges.getStartRes();
1587 int lastVisibleColumn = ranges.getEndRes();
1588 AlignmentI alignment = av.getAlignment();
1589 if (av.hasHiddenColumns())
1591 firstVisibleColumn = alignment.getHiddenColumns()
1592 .adjustForHiddenColumns(firstVisibleColumn);
1593 lastVisibleColumn = alignment.getHiddenColumns()
1594 .adjustForHiddenColumns(lastVisibleColumn);
1597 for (int seqNo = ranges.getStartSeq(); seqNo <= ranges
1598 .getEndSeq(); seqNo++)
1600 SequenceI seq = alignment.getSequenceAt(seqNo);
1602 int[] visibleResults = results.getResults(seq, firstVisibleColumn,
1604 if (visibleResults != null)
1606 for (int i = 0; i < visibleResults.length - 1; i += 2)
1608 int firstMatchedColumn = visibleResults[i];
1609 int lastMatchedColumn = visibleResults[i + 1];
1610 if (firstMatchedColumn <= lastVisibleColumn
1611 && lastMatchedColumn >= firstVisibleColumn)
1614 * found a search results match in the visible region -
1615 * remember the first and last sequence matched, and the first
1616 * and last visible columns in the matched positions
1619 firstSeq = Math.min(firstSeq, seqNo);
1620 lastSeq = Math.max(lastSeq, seqNo);
1621 firstMatchedColumn = Math.max(firstMatchedColumn,
1622 firstVisibleColumn);
1623 lastMatchedColumn = Math.min(lastMatchedColumn,
1625 firstCol = Math.min(firstCol, firstMatchedColumn);
1626 lastCol = Math.max(lastCol, lastMatchedColumn);
1634 if (av.hasHiddenColumns())
1636 firstCol = alignment.getHiddenColumns()
1637 .findColumnPosition(firstCol);
1638 lastCol = alignment.getHiddenColumns().findColumnPosition(lastCol);
1640 int transX = (firstCol - ranges.getStartRes()) * av.getCharWidth();
1641 int transY = (firstSeq - ranges.getStartSeq()) * av.getCharHeight();
1642 gg.translate(transX, transY);
1643 drawPanel(gg, firstCol, lastCol, firstSeq, lastSeq, 0);
1644 gg.translate(-transX, -transY);
1651 public void propertyChange(PropertyChangeEvent evt)
1653 String eventName = evt.getPropertyName();
1655 if (eventName.equals(SequenceGroup.SEQ_GROUP_CHANGED))
1660 else if (eventName.equals(ViewportRanges.STARTRES))
1663 if (eventName.equals(ViewportRanges.STARTRES))
1665 // Make sure we're not trying to draw a panel
1666 // larger than the visible window
1667 ViewportRanges vpRanges = av.getRanges();
1668 scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
1669 int range = vpRanges.getEndRes() - vpRanges.getStartRes() + 1;
1670 if (scrollX > range)
1674 else if (scrollX < -range)
1679 // Both scrolling and resizing change viewport ranges: scrolling changes
1680 // both start and end points, but resize only changes end values.
1681 // Here we only want to fastpaint on a scroll, with resize using a normal
1682 // paint, so scroll events are identified as changes to the horizontal or
1683 // vertical start value.
1685 // scroll - startres and endres both change
1686 if (av.getWrapAlignment())
1688 fastPaintWrapped(scrollX);
1692 fastPaint(scrollX, 0);
1695 else if (eventName.equals(ViewportRanges.STARTSEQ))
1698 fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
1704 * Does a minimal update of the image for a scroll movement. This method
1705 * handles scroll movements of up to one width of the wrapped alignment (one
1706 * click in the vertical scrollbar). Larger movements (for example after a
1707 * scroll to highlight a mapped position) trigger a full redraw instead.
1710 * number of positions scrolled (right if positive, left if negative)
1712 protected void fastPaintWrapped(int scrollX)
1714 ViewportRanges ranges = av.getRanges();
1716 if (Math.abs(scrollX) > ranges.getViewportWidth())
1719 * shift of more than one view width is
1720 * overcomplicated to handle in this method
1727 if (fastpainting || gg == null)
1733 fastpainting = true;
1737 calculateWrappedGeometry(getWidth(), getHeight());
1740 * relocate the regions of the alignment that are still visible
1742 shiftWrappedAlignment(-scrollX);
1745 * add new columns (sequence, annotation)
1746 * - at top left if scrollX < 0
1747 * - at right of last two widths if scrollX > 0
1751 int startRes = ranges.getStartRes();
1752 drawWrappedWidth(gg, wrappedSpaceAboveAlignment, startRes, startRes
1753 - scrollX - 1, getHeight());
1757 fastPaintWrappedAddRight(scrollX);
1761 * draw all scales (if shown) and hidden column markers
1763 drawWrappedDecorators(gg, ranges.getStartRes());
1768 fastpainting = false;
1773 * Draws the specified number of columns at the 'end' (bottom right) of a
1774 * wrapped alignment view, including sequences and annotations if shown, but
1775 * not scales. Also draws the same number of columns at the right hand end of
1776 * the second last width shown, if the last width is not full height (so
1777 * cannot simply be copied from the graphics image).
1781 protected void fastPaintWrappedAddRight(int columns)
1788 ViewportRanges ranges = av.getRanges();
1789 int viewportWidth = ranges.getViewportWidth();
1790 int charWidth = av.getCharWidth();
1793 * draw full height alignment in the second last row, last columns, if the
1794 * last row was not full height
1796 int visibleWidths = wrappedVisibleWidths;
1797 int canvasHeight = getHeight();
1798 boolean lastWidthPartHeight = (wrappedVisibleWidths * wrappedRepeatHeightPx) > canvasHeight;
1800 if (lastWidthPartHeight)
1802 int widthsAbove = Math.max(0, visibleWidths - 2);
1803 int ypos = wrappedRepeatHeightPx * widthsAbove
1804 + wrappedSpaceAboveAlignment;
1805 int endRes = ranges.getEndRes();
1806 endRes += widthsAbove * viewportWidth;
1807 int startRes = endRes - columns;
1808 int xOffset = ((startRes - ranges.getStartRes()) % viewportWidth)
1812 * white fill first to erase annotations
1814 gg.translate(xOffset, 0);
1815 gg.setColor(Color.white);
1816 gg.fillRect(labelWidthWest, ypos,
1817 (endRes - startRes + 1) * charWidth, wrappedRepeatHeightPx);
1818 gg.translate(-xOffset, 0);
1820 drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight);
1824 * draw newly visible columns in last wrapped width (none if we
1825 * have reached the end of the alignment)
1826 * y-offset for drawing last width is height of widths above,
1829 int widthsAbove = visibleWidths - 1;
1830 int ypos = wrappedRepeatHeightPx * widthsAbove
1831 + wrappedSpaceAboveAlignment;
1832 int endRes = ranges.getEndRes();
1833 endRes += widthsAbove * viewportWidth;
1834 int startRes = endRes - columns + 1;
1837 * white fill first to erase annotations
1839 int xOffset = ((startRes - ranges.getStartRes()) % viewportWidth)
1841 gg.translate(xOffset, 0);
1842 gg.setColor(Color.white);
1843 int width = viewportWidth * charWidth - xOffset;
1844 gg.fillRect(labelWidthWest, ypos, width, wrappedRepeatHeightPx);
1845 gg.translate(-xOffset, 0);
1847 gg.setFont(av.getFont());
1848 gg.setColor(Color.black);
1850 if (startRes < ranges.getVisibleAlignmentWidth())
1852 drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight);
1856 * and finally, white fill any space below the visible alignment
1858 int heightBelow = canvasHeight - visibleWidths * wrappedRepeatHeightPx;
1859 if (heightBelow > 0)
1861 gg.setColor(Color.white);
1862 gg.fillRect(0, canvasHeight - heightBelow, getWidth(), heightBelow);
1867 * Shifts the visible alignment by the specified number of columns - left if
1868 * negative, right if positive. Copies and moves sequences and annotations (if
1869 * shown). Scales, hidden column markers and any newly visible columns must be
1874 protected void shiftWrappedAlignment(int positions)
1880 int charWidth = av.getCharWidth();
1882 int canvasHeight = getHeight();
1883 ViewportRanges ranges = av.getRanges();
1884 int viewportWidth = ranges.getViewportWidth();
1885 int widthToCopy = (ranges.getViewportWidth() - Math.abs(positions))
1887 int heightToCopy = wrappedRepeatHeightPx - wrappedSpaceAboveAlignment;
1888 int xMax = ranges.getVisibleAlignmentWidth();
1893 * shift right (after scroll left)
1894 * for each wrapped width (starting with the last), copy (width-positions)
1895 * columns from the left margin to the right margin, and copy positions
1896 * columns from the right margin of the row above (if any) to the
1897 * left margin of the current row
1901 * get y-offset of last wrapped width, first row of sequences
1903 int y = canvasHeight / wrappedRepeatHeightPx * wrappedRepeatHeightPx;
1904 y += wrappedSpaceAboveAlignment;
1905 int copyFromLeftStart = labelWidthWest;
1906 int copyFromRightStart = copyFromLeftStart + widthToCopy;
1910 gg.copyArea(copyFromLeftStart, y, widthToCopy, heightToCopy,
1911 positions * charWidth, 0);
1914 gg.copyArea(copyFromRightStart, y - wrappedRepeatHeightPx,
1915 positions * charWidth, heightToCopy, -widthToCopy,
1916 wrappedRepeatHeightPx);
1919 y -= wrappedRepeatHeightPx;
1925 * shift left (after scroll right)
1926 * for each wrapped width (starting with the first), copy (width-positions)
1927 * columns from the right margin to the left margin, and copy positions
1928 * columns from the left margin of the row below (if any) to the
1929 * right margin of the current row
1931 int xpos = av.getRanges().getStartRes();
1932 int y = wrappedSpaceAboveAlignment;
1933 int copyFromRightStart = labelWidthWest - positions * charWidth;
1935 while (y < canvasHeight)
1937 gg.copyArea(copyFromRightStart, y, widthToCopy, heightToCopy,
1938 positions * charWidth, 0);
1939 if (y + wrappedRepeatHeightPx < canvasHeight - wrappedRepeatHeightPx
1940 && (xpos + viewportWidth <= xMax))
1942 gg.copyArea(labelWidthWest, y + wrappedRepeatHeightPx, -positions
1943 * charWidth, heightToCopy, widthToCopy,
1944 -wrappedRepeatHeightPx);
1947 y += wrappedRepeatHeightPx;
1948 xpos += viewportWidth;
1955 * Redraws any positions in the search results in the visible region of a
1956 * wrapped alignment. Any highlights are drawn depending on the search results
1957 * set on the Viewport, not the <code>results</code> argument. This allows
1958 * this method to be called either to clear highlights (passing the previous
1959 * search results), or to draw new highlights.
1964 protected boolean drawMappedPositionsWrapped(SearchResultsI results)
1966 if (results == null)
1970 int charHeight = av.getCharHeight();
1972 boolean matchFound = false;
1974 calculateWrappedGeometry(getWidth(), getHeight());
1975 int wrappedWidth = av.getWrappedWidth();
1976 int wrappedHeight = wrappedRepeatHeightPx;
1978 ViewportRanges ranges = av.getRanges();
1979 int canvasHeight = getHeight();
1980 int repeats = canvasHeight / wrappedHeight;
1981 if (canvasHeight / wrappedHeight > 0)
1986 int firstVisibleColumn = ranges.getStartRes();
1987 int lastVisibleColumn = ranges.getStartRes() + repeats
1988 * ranges.getViewportWidth() - 1;
1990 AlignmentI alignment = av.getAlignment();
1991 if (av.hasHiddenColumns())
1993 firstVisibleColumn = alignment.getHiddenColumns()
1994 .adjustForHiddenColumns(firstVisibleColumn);
1995 lastVisibleColumn = alignment.getHiddenColumns()
1996 .adjustForHiddenColumns(lastVisibleColumn);
1999 int gapHeight = charHeight * (av.getScaleAboveWrapped() ? 2 : 1);
2001 for (int seqNo = ranges.getStartSeq(); seqNo <= ranges
2002 .getEndSeq(); seqNo++)
2004 SequenceI seq = alignment.getSequenceAt(seqNo);
2006 int[] visibleResults = results.getResults(seq, firstVisibleColumn,
2008 if (visibleResults != null)
2010 for (int i = 0; i < visibleResults.length - 1; i += 2)
2012 int firstMatchedColumn = visibleResults[i];
2013 int lastMatchedColumn = visibleResults[i + 1];
2014 if (firstMatchedColumn <= lastVisibleColumn
2015 && lastMatchedColumn >= firstVisibleColumn)
2018 * found a search results match in the visible region
2020 firstMatchedColumn = Math.max(firstMatchedColumn,
2021 firstVisibleColumn);
2022 lastMatchedColumn = Math.min(lastMatchedColumn,
2026 * draw each mapped position separately (as contiguous positions may
2027 * wrap across lines)
2029 for (int mappedPos = firstMatchedColumn; mappedPos <= lastMatchedColumn; mappedPos++)
2031 int displayColumn = mappedPos;
2032 if (av.hasHiddenColumns())
2034 displayColumn = alignment.getHiddenColumns()
2035 .findColumnPosition(displayColumn);
2039 * transX: offset from left edge of canvas to residue position
2041 int transX = labelWidthWest
2042 + ((displayColumn - ranges.getStartRes()) % wrappedWidth)
2043 * av.getCharWidth();
2046 * transY: offset from top edge of canvas to residue position
2048 int transY = gapHeight;
2049 transY += (displayColumn - ranges.getStartRes())
2050 / wrappedWidth * wrappedHeight;
2051 transY += (seqNo - ranges.getStartSeq()) * av.getCharHeight();
2054 * yOffset is from graphics origin to start of visible region
2056 int yOffset = 0;// (displayColumn / wrappedWidth) * wrappedHeight;
2057 if (transY < getHeight())
2060 gg.translate(transX, transY);
2061 drawPanel(gg, displayColumn, displayColumn, seqNo, seqNo,
2063 gg.translate(-transX, -transY);
2075 * Answers the width in pixels of the left scale labels (0 if not shown)
2079 int getLabelWidthWest()
2081 return labelWidthWest;