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.viewmodel.ViewportListenerI;
31 import jalview.viewmodel.ViewportRanges;
33 import java.awt.AlphaComposite;
34 import java.awt.BasicStroke;
35 import java.awt.BorderLayout;
36 import java.awt.Color;
37 import java.awt.FontMetrics;
38 import java.awt.Graphics;
39 import java.awt.Graphics2D;
40 import java.awt.RenderingHints;
41 import java.awt.Shape;
42 import java.awt.image.BufferedImage;
43 import java.beans.PropertyChangeEvent;
44 import java.util.List;
46 import javax.swing.JComponent;
54 public class SeqCanvas extends JComponent implements ViewportListenerI
56 final FeatureRenderer fr;
58 final SequenceRenderer sr;
66 boolean fastPaint = false;
77 * Creates a new SeqCanvas object.
82 public SeqCanvas(AlignmentPanel ap)
86 fr = new FeatureRenderer(ap);
87 sr = new SequenceRenderer(av);
88 setLayout(new BorderLayout());
89 PaintRefresher.Register(this, av.getSequenceSetId());
90 setBackground(Color.white);
92 av.getRanges().addPropertyChangeListener(this);
95 public SequenceRenderer getSequenceRenderer()
100 public FeatureRenderer getFeatureRenderer()
105 int charHeight = 0, charWidth = 0;
107 private void updateViewport()
109 charHeight = av.getCharHeight();
110 charWidth = av.getCharWidth();
125 private void drawNorthScale(Graphics g, int startx, int endx, int ypos)
128 for (ScaleMark mark : new ScaleRenderer().calculateMarks(av, startx,
131 int mpos = mark.column; // (i - startx - 1)
136 String mstring = mark.text;
142 g.drawString(mstring, mpos * charWidth, ypos - (charHeight / 2));
144 g.drawLine((mpos * charWidth) + (charWidth / 2), (ypos + 2)
145 - (charHeight / 2), (mpos * charWidth) + (charWidth / 2),
163 void drawWestScale(Graphics g, int startx, int endx, int ypos)
165 FontMetrics fm = getFontMetrics(av.getFont());
168 if (av.hasHiddenColumns())
170 startx = av.getAlignment().getHiddenColumns()
171 .adjustForHiddenColumns(startx);
172 endx = av.getAlignment().getHiddenColumns()
173 .adjustForHiddenColumns(endx);
176 int maxwidth = av.getAlignment().getWidth();
177 if (av.hasHiddenColumns())
179 maxwidth = av.getAlignment().getHiddenColumns()
180 .findColumnPosition(maxwidth) - 1;
184 for (int i = 0; i < av.getAlignment().getHeight(); i++)
186 SequenceI seq = av.getAlignment().getSequenceAt(i);
192 if (jalview.util.Comparison.isGap(seq.getCharAt(index)))
199 value = av.getAlignment().getSequenceAt(i).findPosition(index);
206 int x = LABEL_WEST - fm.stringWidth(String.valueOf(value))
208 g.drawString(value + "", x, (ypos + (i * charHeight))
226 void drawEastScale(Graphics g, int startx, int endx, int ypos)
230 if (av.hasHiddenColumns())
232 endx = av.getAlignment().getHiddenColumns()
233 .adjustForHiddenColumns(endx);
238 for (int i = 0; i < av.getAlignment().getHeight(); i++)
240 seq = av.getAlignment().getSequenceAt(i);
244 while (index > startx)
246 if (jalview.util.Comparison.isGap(seq.getCharAt(index)))
253 value = seq.findPosition(index);
260 g.drawString(String.valueOf(value), 0, (ypos + (i * charHeight))
266 boolean fastpainting = false;
269 * need to make this thread safe move alignment rendering in response to
275 * shift up or down in repaint
277 public void fastPaint(int horizontal, int vertical)
279 if (fastpainting || gg == null)
287 ViewportRanges ranges = av.getRanges();
288 int sr = ranges.getStartRes();
289 int er = ranges.getEndRes();
290 int ss = ranges.getStartSeq();
291 int es = ranges.getEndSeq();
295 gg.copyArea(horizontal * charWidth, vertical * charHeight,
296 img.getWidth(), img.getHeight(), -horizontal * charWidth,
297 -vertical * charHeight);
299 if (horizontal > 0) // scrollbar pulled right, image to the left
301 transX = (er - sr - horizontal) * charWidth;
302 sr = er - horizontal;
304 else if (horizontal < 0)
306 er = sr - horizontal;
308 else if (vertical > 0) // scroll down
312 if (ss < ranges.getStartSeq())
313 { // ie scrolling too fast, more than a page at a time
314 ss = ranges.getStartSeq();
318 transY = img.getHeight() - ((vertical + 1) * charHeight);
321 else if (vertical < 0)
325 if (es > ranges.getEndSeq())
327 es = ranges.getEndSeq();
331 gg.translate(transX, transY);
332 drawPanel(gg, sr, er, ss, es, 0);
333 gg.translate(-transX, -transY);
336 fastpainting = false;
340 * Definitions of startx and endx (hopefully): SMJS This is what I'm working
341 * towards! startx is the first residue (starting at 0) to display. endx is
342 * the last residue to display (starting at 0). starty is the first sequence
343 * to display (starting at 0). endy is the last sequence to display (starting
344 * at 0). NOTE 1: The av limits are set in setFont in this class and in the
345 * adjustment listener in SeqPanel when the scrollbars move.
348 // Set this to false to force a full panel paint
350 public void paintComponent(Graphics g)
352 super.paintComponent(g);
356 // img is a cached version of the last view we drew
357 // selectImage will hold any selection we have
358 // lcimg is a local *copy* of img which we'll draw selectImage on top of
360 ViewportRanges ranges = av.getRanges();
361 BufferedImage selectImage = drawSelectionGroup(
362 av.getRanges().getStartRes(), av.getRanges().getEndRes(),
363 ranges.getStartSeq(), ranges.getEndSeq());
365 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
366 || (getVisibleRect().height != g.getClipBounds().height))
368 BufferedImage lcimg = buildLocalImage(selectImage);
369 g.drawImage(lcimg, 0, 0, this);
375 int width = getWidth();
376 int height = getHeight();
378 width -= (width % charWidth);
379 height -= (height % charHeight);
381 if ((width < 1) || (height < 1))
386 if (img == null || width != img.getWidth() || height != img.getHeight())
389 gg = (Graphics2D) img.getGraphics();
390 gg.setFont(av.getFont());
400 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
401 RenderingHints.VALUE_ANTIALIAS_ON);
404 gg.setColor(Color.white);
405 gg.fillRect(0, 0, img.getWidth(), img.getHeight());
407 if (av.getWrapAlignment())
409 drawWrappedPanel(gg, getWidth(), getHeight(), ranges.getStartRes());
413 drawPanel(gg, ranges.getStartRes(), ranges.getEndRes(),
414 ranges.getStartSeq(), ranges.getEndSeq(), 0);
417 BufferedImage lcimg = buildLocalImage(selectImage);
418 g.drawImage(lcimg, 0, 0, this);
422 * Make a local image by combining the cached image img
425 private BufferedImage buildLocalImage(BufferedImage selectImage)
427 // clone the cached image
428 BufferedImage lcimg = new BufferedImage(img.getWidth(), img.getHeight(),
430 Graphics2D g2d = lcimg.createGraphics();
431 g2d.drawImage(img, 0, 0, null);
433 // overlay selection group on lcimg
434 if (selectImage != null)
437 AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
438 g2d.drawImage(selectImage, 0, 0, this);
445 private void paintSeqGroup()
451 private BufferedImage setupImage()
453 BufferedImage lcimg = null;
455 int width = getWidth();
456 int height = getHeight();
458 width -= (width % charWidth);
459 height -= (height % charHeight);
461 if ((width < 1) || (height < 1))
468 lcimg = new BufferedImage(width, height,
469 BufferedImage.TYPE_INT_ARGB); // ARGB so alpha compositing works
470 } catch (OutOfMemoryError er)
474 "Selection Group image OutOfMemory Redraw Error.\n" + er);
475 new OOMWarning("Creating alignment image for display", er);
489 * @return DOCUMENT ME!
491 public int getWrappedCanvasWidth(int cwidth)
493 FontMetrics fm = getFontMetrics(av.getFont());
498 if (av.getScaleRightWrapped())
500 LABEL_EAST = fm.stringWidth(getMask());
503 if (av.getScaleLeftWrapped())
505 LABEL_WEST = fm.stringWidth(getMask());
508 return (cwidth - LABEL_EAST - LABEL_WEST) / charWidth;
512 * Generates a string of zeroes.
521 for (int i = 0; i < av.getAlignment().getHeight(); i++)
523 tmp = av.getAlignment().getSequenceAt(i).getEnd();
530 for (int i = maxWidth; i > 0; i /= 10)
544 * @param canvasHeight
549 public void drawWrappedPanel(Graphics g, int canvasWidth,
550 int canvasHeight, int startRes)
553 AlignmentI al = av.getAlignment();
555 FontMetrics fm = getFontMetrics(av.getFont());
560 if (av.getScaleRightWrapped())
562 LABEL_EAST = fm.stringWidth(getMask());
565 if (av.getScaleLeftWrapped())
567 LABEL_WEST = fm.stringWidth(getMask());
570 int hgap = charHeight;
571 if (av.getScaleAboveWrapped())
576 int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / charWidth;
577 int cHeight = av.getAlignment().getHeight() * charHeight;
579 av.setWrappedWidth(cWidth);
581 av.getRanges().setViewportStartAndWidth(startRes, cWidth);
585 int maxwidth = av.getAlignment().getWidth();
587 if (av.hasHiddenColumns())
589 maxwidth = av.getAlignment().getHiddenColumns()
590 .findColumnPosition(maxwidth);
593 while ((ypos <= canvasHeight) && (startRes < maxwidth))
595 endx = startRes + cWidth - 1;
602 g.setFont(av.getFont());
603 g.setColor(Color.black);
605 if (av.getScaleLeftWrapped())
607 drawWestScale(g, startRes, endx, ypos);
610 if (av.getScaleRightWrapped())
612 g.translate(canvasWidth - LABEL_EAST, 0);
613 drawEastScale(g, startRes, endx, ypos);
614 g.translate(-(canvasWidth - LABEL_EAST), 0);
617 g.translate(LABEL_WEST, 0);
619 if (av.getScaleAboveWrapped())
621 drawNorthScale(g, startRes, endx, ypos);
624 if (av.hasHiddenColumns() && av.getShowHiddenMarkers())
626 g.setColor(Color.blue);
628 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
629 List<Integer> positions = hidden.findHiddenRegionPositions();
630 for (int pos : positions)
632 res = pos - startRes;
634 if (res < 0 || res > endx - startRes)
640 new int[] { res * charWidth - charHeight / 4,
641 res * charWidth + charHeight / 4, res * charWidth },
642 new int[] { ypos - (charHeight / 2),
643 ypos - (charHeight / 2), ypos - (charHeight / 2) + 8 },
649 // When printing we have an extra clipped region,
650 // the Printable page which we need to account for here
651 Shape clip = g.getClip();
655 g.setClip(0, 0, cWidth * charWidth, canvasHeight);
659 g.setClip(0, (int) clip.getBounds().getY(), cWidth * charWidth,
660 (int) clip.getBounds().getHeight());
663 drawPanel(g, startRes, endx, 0, al.getHeight() - 1, ypos);
665 if (av.isShowAnnotation())
667 g.translate(0, cHeight + ypos + 3);
668 if (annotations == null)
670 annotations = new AnnotationPanel(av);
673 annotations.renderer.drawComponent(annotations, av, g, -1,
675 g.translate(0, -cHeight - ypos - 3);
678 g.translate(-LABEL_WEST, 0);
680 ypos += cHeight + getAnnotationHeight() + hgap;
686 public void drawWrappedSelection(Graphics2D g, SequenceGroup group,
688 int canvasHeight, int startRes)
690 int hgap = charHeight;
691 if (av.getScaleAboveWrapped())
696 int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / charWidth;
697 int cHeight = av.getAlignment().getHeight() * charHeight;
701 int maxwidth = av.getAlignment().getWidth();
703 if (av.hasHiddenColumns())
705 maxwidth = av.getAlignment().getHiddenColumns()
706 .findColumnPosition(maxwidth);
709 while ((ypos <= canvasHeight) && (startRes < maxwidth))
711 endx = startRes + cWidth - 1;
718 g.translate(LABEL_WEST, 0);
720 drawUnwrappedSelection(g, group, startRes, endx, 0,
721 av.getAlignment().getHeight() - 1,
724 g.translate(-LABEL_WEST, 0);
726 ypos += cHeight + getAnnotationHeight() + hgap;
732 AnnotationPanel annotations;
734 int getAnnotationHeight()
736 if (!av.isShowAnnotation())
741 if (annotations == null)
743 annotations = new AnnotationPanel(av);
746 return annotations.adjustPanelHeight();
765 public void drawPanel(Graphics g1, int startRes, int endRes,
766 int startSeq, int endSeq, int offset)
769 if (!av.hasHiddenColumns())
771 draw(g1, startRes, endRes, startSeq, endSeq, offset);
776 int blockStart = startRes;
777 int blockEnd = endRes;
779 for (int[] region : av.getAlignment().getHiddenColumns()
780 .getHiddenColumnsCopy())
782 int hideStart = region[0];
783 int hideEnd = region[1];
785 if (hideStart <= blockStart)
787 blockStart += (hideEnd - hideStart) + 1;
791 blockEnd = hideStart - 1;
793 g1.translate(screenY * charWidth, 0);
795 draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
797 if (av.getShowHiddenMarkers())
799 g1.setColor(Color.blue);
801 g1.drawLine((blockEnd - blockStart + 1) * charWidth - 1,
802 0 + offset, (blockEnd - blockStart + 1) * charWidth - 1,
803 (endSeq - startSeq + 1) * charHeight + offset);
806 g1.translate(-screenY * charWidth, 0);
807 screenY += blockEnd - blockStart + 1;
808 blockStart = hideEnd + 1;
810 if (screenY > (endRes - startRes))
812 // already rendered last block
817 if (screenY <= (endRes - startRes))
819 // remaining visible region to render
820 blockEnd = blockStart + (endRes - startRes) - screenY;
821 g1.translate(screenY * charWidth, 0);
822 draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
824 g1.translate(-screenY * charWidth, 0);
830 // int startRes, int endRes, int startSeq, int endSeq, int x, int y,
831 // int x1, int x2, int y1, int y2, int startx, int starty,
832 private void draw(Graphics g, int startRes, int endRes, int startSeq,
833 int endSeq, int offset)
835 g.setFont(av.getFont());
836 sr.prepare(g, av.isRenderGaps());
840 // / First draw the sequences
841 // ///////////////////////////
842 for (int i = startSeq; i <= endSeq; i++)
844 nextSeq = av.getAlignment().getSequenceAt(i);
847 // occasionally, a race condition occurs such that the alignment row is
851 sr.drawSequence(nextSeq, av.getAlignment().findAllGroups(nextSeq),
852 startRes, endRes, offset + ((i - startSeq) * charHeight));
854 if (av.isShowSequenceFeatures())
856 fr.drawSequence(g, nextSeq, startRes, endRes, offset
857 + ((i - startSeq) * charHeight), false);
860 // / Highlight search Results once all sequences have been drawn
861 // ////////////////////////////////////////////////////////
862 if (av.hasSearchResults())
864 int[] visibleResults = av.getSearchResults().getResults(nextSeq,
866 if (visibleResults != null)
868 for (int r = 0; r < visibleResults.length; r += 2)
870 sr.drawHighlightedText(nextSeq, visibleResults[r],
871 visibleResults[r + 1], (visibleResults[r] - startRes)
873 + ((i - startSeq) * charHeight));
878 if (av.cursorMode && cursorY == i && cursorX >= startRes
879 && cursorX <= endRes)
881 sr.drawCursor(nextSeq, cursorX, (cursorX - startRes) * charWidth,
882 offset + ((i - startSeq) * charHeight));
886 if (av.getSelectionGroup() != null
887 || av.getAlignment().getGroups().size() > 0)
889 drawGroupsBoundaries(g, startRes, endRes, startSeq, endSeq, offset);
894 void drawGroupsBoundaries(Graphics g1, int startRes, int endRes,
895 int startSeq, int endSeq, int offset)
897 Graphics2D g = (Graphics2D) g1;
899 // ///////////////////////////////////
900 // Now outline any areas if necessary
901 // ///////////////////////////////////
903 SequenceGroup group = null;
909 int visWidth = (endRes - startRes + 1) * charWidth;
911 if (av.getAlignment().getGroups().size() > 0)
913 group = av.getAlignment().getGroups().get(0);
923 boolean inGroup = false;
927 for (i = startSeq; i <= endSeq; i++)
929 // position of start residue of group relative to startRes, in pixels
930 sx = (group.getStartRes() - startRes) * charWidth;
931 sy = offset + ((i - startSeq) * charHeight);
932 // width of group in pixels
933 ex = (((group.getEndRes() + 1) - group.getStartRes()) * charWidth) - 1;
935 if (sx + ex < 0 || sx > visWidth)
940 if ((sx <= (endRes - startRes) * charWidth)
941 && group.getSequences(null).contains(
942 av.getAlignment().getSequenceAt(i)))
945 && !group.getSequences(null).contains(
946 av.getAlignment().getSequenceAt(i + 1)))
948 bottom = sy + charHeight;
953 if (((top == -1) && (i == 0))
954 || !group.getSequences(null).contains(
955 av.getAlignment().getSequenceAt(i - 1)))
963 g.setStroke(new BasicStroke());
964 g.setColor(group.getOutlineColour());
971 // if start position is visible, draw vertical line to left of
973 if (sx >= 0 && sx < visWidth)
975 g.drawLine(sx, oldY, sx, sy);
978 // if end position is visible, draw vertical line to right of
980 if (sx + ex < visWidth)
982 g.drawLine(sx + ex, oldY, sx + ex, sy);
991 if (sx + ex > visWidth)
996 else if (sx + ex >= (endRes - startRes + 1) * charWidth)
998 ex = (endRes - startRes + 1) * charWidth;
1001 // draw horizontal line at top of group
1004 g.drawLine(sx, top, sx + ex, top);
1008 // draw horizontal line at bottom of group
1011 g.drawLine(sx, bottom, sx + ex, bottom);
1022 sy = offset + ((i - startSeq) * charHeight);
1023 if (sx >= 0 && sx < visWidth)
1025 g.drawLine(sx, oldY, sx, sy);
1028 if (sx + ex < visWidth)
1030 g.drawLine(sx + ex, oldY, sx + ex, sy);
1039 if (sx + ex > visWidth)
1043 else if (sx + ex >= (endRes - startRes + 1) * charWidth)
1045 ex = (endRes - startRes + 1) * charWidth;
1050 g.drawLine(sx, top, sx + ex, top);
1056 g.drawLine(sx, bottom - 1, sx + ex, bottom - 1);
1065 g.setStroke(new BasicStroke());
1067 if (groupIndex >= av.getAlignment().getGroups().size())
1072 group = av.getAlignment().getGroups().get(groupIndex);
1074 } while (groupIndex < av.getAlignment().getGroups().size());
1082 * Draw the selection group as a separate image and overlay
1084 private BufferedImage drawSelectionGroup(int startRes, int endRes,
1085 int startSeq, int endSeq)
1087 // get a new image of the correct size
1088 BufferedImage selectionImage = setupImage();
1090 if (selectionImage == null)
1095 SequenceGroup group = av.getSelectionGroup();
1102 /*if (!av.getWrapAlignment())
1108 // set up drawing colour
1109 Graphics2D g = (Graphics2D) selectionImage.getGraphics();
1110 // g.translate(LABEL_WEST, 0);
1111 // set background to transparent
1112 g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
1113 g.fillRect(0, 0, selectionImage.getWidth(), selectionImage.getHeight());
1115 g.setComposite(AlphaComposite.Src);
1116 g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
1117 BasicStroke.JOIN_ROUND, 3f, new float[]
1119 g.setColor(Color.RED);
1121 if (!av.getWrapAlignment())
1123 drawUnwrappedSelection(g, group, startRes, endRes, startSeq, endSeq,
1128 drawWrappedSelection(g, group, getWidth(), getHeight(),
1129 av.getRanges().getStartRes());
1133 return selectionImage;
1136 private void drawUnwrappedSelection(Graphics2D g, SequenceGroup group,
1137 int startRes, int endRes, int startSeq, int endSeq, int offset)
1139 if (!av.hasHiddenColumns())
1141 drawSelectionGroupPart(g, group, startRes, endRes, startSeq, endSeq,
1146 // package into blocks of visible columns
1148 int blockStart = startRes;
1149 int blockEnd = endRes;
1151 for (int[] region : av.getAlignment().getHiddenColumns()
1152 .getHiddenColumnsCopy())
1154 int hideStart = region[0];
1155 int hideEnd = region[1];
1157 if (hideStart <= blockStart)
1159 blockStart += (hideEnd - hideStart) + 1;
1163 blockEnd = hideStart - 1;
1165 g.translate(screenY * charWidth, 0);
1167 drawSelectionGroupPart(g, group,
1168 blockStart, blockEnd, startSeq, endSeq, offset);
1170 g.translate(-screenY * charWidth, 0);
1171 screenY += blockEnd - blockStart + 1;
1172 blockStart = hideEnd + 1;
1174 if (screenY > (endRes - startRes))
1176 // already rendered last block
1181 if (screenY <= (endRes - startRes))
1183 // remaining visible region to render
1184 blockEnd = blockStart + (endRes - startRes) - screenY;
1185 g.translate(screenY * charWidth, 0);
1186 drawSelectionGroupPart(g, group,
1187 blockStart, blockEnd, startSeq, endSeq, offset);
1189 g.translate(-screenY * charWidth, 0);
1192 // g.translate(-LABEL_WEST, 0);
1196 * Draw the selection group as a separate image and overlay
1198 private void drawSelectionGroupPart(Graphics2D g, SequenceGroup group,
1199 int startRes, int endRes, int startSeq, int endSeq,
1202 // set up values in case the alignment is wrapped
1203 /*int verticalOffset = 0;
1204 int horizontalOffset = 0;
1205 if (av.getWrapAlignment())
1207 int hgap = charHeight;
1208 if (av.getScaleAboveWrapped())
1213 // get the start res of the group and work out the offsets for it in the wrapped alignment
1214 int groupstart = group.getStartRes();
1215 int cWidth = (getWidth() - LABEL_EAST - LABEL_WEST) / charWidth;
1217 // group is in which slice of alignment? res position / width in residues
1218 int slice = groupstart / cWidth;
1219 // vertical offset is increased by slice number * number of sequences * height of each sequence
1220 verticalOffset = slice * (av.getAlignment().getHeight() * charHeight
1221 + getAnnotationHeight() + hgap) + hgap;
1223 // horizontal offset is number of residues to subtract from group residue
1225 horizontalOffset = (slice * cWidth);
1228 int visWidth = (endRes - startRes + 1) * charWidth;
1232 boolean inGroup = false;
1240 // position of start residue of group relative to startRes, in pixels
1241 sx = (group.getStartRes() - startRes) * charWidth;
1243 // width of group in pixels
1244 ex = (((group.getEndRes() + 1) - group.getStartRes())
1247 for (i = startSeq; i <= endSeq; i++)
1249 sy = verticalOffset + (i - startSeq) * charHeight;
1251 if (sx + ex < 0 || sx > visWidth)
1256 if ((sx <= (endRes - startRes) * charWidth)
1257 && group.getSequences(null)
1258 .contains(av.getAlignment().getSequenceAt(i)))
1260 if ((bottom == -1) && !group.getSequences(null)
1261 .contains(av.getAlignment().getSequenceAt(i + 1)))
1263 bottom = sy + charHeight;
1268 if (((top == -1) && (i == 0)) || !group.getSequences(null)
1269 .contains(av.getAlignment().getSequenceAt(i - 1)))
1282 // if start position is visible, draw vertical line to left of
1284 if (sx >= 0 && sx < visWidth)
1286 g.drawLine(sx, oldY, sx, sy);
1289 // if end position is visible, draw vertical line to right of
1291 if (sx + ex < visWidth)
1293 g.drawLine(sx + ex, oldY, sx + ex, sy);
1302 if (sx + ex > visWidth)
1307 else if (sx + ex >= (endRes - startRes + 1) * charWidth)
1309 ex = (endRes - startRes + 1) * charWidth;
1312 // draw horizontal line at top of group
1315 g.drawLine(sx, top, sx + ex, top);
1319 // draw horizontal line at bottom of group
1322 g.drawLine(sx, bottom, sx + ex, bottom);
1333 sy = verticalOffset + ((i - startSeq) * charHeight);
1334 if (sx >= 0 && sx < visWidth)
1336 g.drawLine(sx, oldY, sx, sy);
1339 if (sx + ex < visWidth)
1341 g.drawLine(sx + ex, oldY, sx + ex, sy);
1350 if (sx + ex > visWidth)
1354 else if (sx + ex >= (endRes - startRes + 1) * charWidth)
1356 ex = (endRes - startRes + 1) * charWidth;
1361 g.drawLine(sx, top, sx + ex, top);
1367 g.drawLine(sx, bottom - 1, sx + ex, bottom - 1);
1381 public void highlightSearchResults(SearchResultsI results)
1385 av.setSearchResults(results);
1391 public void propertyChange(PropertyChangeEvent evt)
1393 String eventName = evt.getPropertyName();
1395 if (eventName.equals(SequenceGroup.SEQ_GROUP_CHANGED))
1399 else if (av.getWrapAlignment())
1401 if (eventName.equals(ViewportRanges.STARTRES))
1409 if (eventName.equals(ViewportRanges.STARTRES))
1411 // Make sure we're not trying to draw a panel
1412 // larger than the visible window
1413 ViewportRanges vpRanges = av.getRanges();
1414 scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
1415 int range = vpRanges.getEndRes() - vpRanges.getStartRes();
1416 if (scrollX > range)
1420 else if (scrollX < -range)
1426 // Both scrolling and resizing change viewport ranges: scrolling changes
1427 // both start and end points, but resize only changes end values.
1428 // Here we only want to fastpaint on a scroll, with resize using a normal
1429 // paint, so scroll events are identified as changes to the horizontal or
1430 // vertical start value.
1431 if (eventName.equals(ViewportRanges.STARTRES))
1433 // scroll - startres and endres both change
1434 fastPaint(scrollX, 0);
1436 else if (eventName.equals(ViewportRanges.STARTSEQ))
1439 fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());