Jalview 2.6 source licence
[jalview.git] / src / jalview / gui / SeqCanvas.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
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 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.gui;
19
20 import java.awt.*;
21 import java.awt.image.*;
22 import javax.swing.*;
23
24 import jalview.datamodel.*;
25
26 /**
27  * DOCUMENT ME!
28  * 
29  * @author $author$
30  * @version $Revision$
31  */
32 public class SeqCanvas extends JComponent
33 {
34   final FeatureRenderer fr;
35
36   final SequenceRenderer sr;
37
38   BufferedImage img;
39
40   Graphics2D gg;
41
42   int imgWidth;
43
44   int imgHeight;
45
46   AlignViewport av;
47
48   SearchResults searchResults = null;
49
50   boolean fastPaint = false;
51
52   int LABEL_WEST;
53
54   int LABEL_EAST;
55
56   int cursorX = 0;
57
58   int cursorY = 0;
59
60   /**
61    * Creates a new SeqCanvas object.
62    * 
63    * @param av
64    *          DOCUMENT ME!
65    */
66   public SeqCanvas(AlignmentPanel ap)
67   {
68     this.av = ap.av;
69     fr = new FeatureRenderer(ap);
70     sr = new SequenceRenderer(av);
71     setLayout(new BorderLayout());
72     PaintRefresher.Register(this, av.getSequenceSetId());
73     setBackground(Color.white);
74   }
75
76   public SequenceRenderer getSequenceRenderer()
77   {
78     return sr;
79   }
80
81   public FeatureRenderer getFeatureRenderer()
82   {
83     return fr;
84   }
85
86   /**
87    * DOCUMENT ME!
88    * 
89    * @param g
90    *          DOCUMENT ME!
91    * @param startx
92    *          DOCUMENT ME!
93    * @param endx
94    *          DOCUMENT ME!
95    * @param ypos
96    *          DOCUMENT ME!
97    */
98   void drawNorthScale(Graphics g, int startx, int endx, int ypos)
99   {
100     int scalestartx = startx - (startx % 10) + 10;
101
102     g.setColor(Color.black);
103
104     // NORTH SCALE
105     for (int i = scalestartx; i < endx; i += 10)
106     {
107       int value = i;
108       if (av.hasHiddenColumns)
109       {
110         value = av.getColumnSelection().adjustForHiddenColumns(value);
111       }
112
113       g.drawString(String.valueOf(value), (i - startx - 1) * av.charWidth,
114               ypos - (av.charHeight / 2));
115
116       g.drawLine(((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
117               (ypos + 2) - (av.charHeight / 2),
118               ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
119               ypos - 2);
120     }
121   }
122
123   /**
124    * DOCUMENT ME!
125    * 
126    * @param g
127    *          DOCUMENT ME!
128    * @param startx
129    *          DOCUMENT ME!
130    * @param endx
131    *          DOCUMENT ME!
132    * @param ypos
133    *          DOCUMENT ME!
134    */
135   void drawWestScale(Graphics g, int startx, int endx, int ypos)
136   {
137     FontMetrics fm = getFontMetrics(av.getFont());
138     ypos += av.charHeight;
139
140     if (av.hasHiddenColumns)
141     {
142       startx = av.getColumnSelection().adjustForHiddenColumns(startx);
143       endx = av.getColumnSelection().adjustForHiddenColumns(endx);
144     }
145
146     int maxwidth = av.alignment.getWidth();
147     if (av.hasHiddenColumns)
148     {
149       maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
150     }
151
152     // WEST SCALE
153     for (int i = 0; i < av.alignment.getHeight(); i++)
154     {
155       SequenceI seq = av.alignment.getSequenceAt(i);
156       int index = startx;
157       int value = -1;
158
159       while (index < endx)
160       {
161         if (jalview.util.Comparison.isGap(seq.getCharAt(index)))
162         {
163           index++;
164
165           continue;
166         }
167
168         value = av.alignment.getSequenceAt(i).findPosition(index);
169
170         break;
171       }
172
173       if (value != -1)
174       {
175         int x = LABEL_WEST - fm.stringWidth(String.valueOf(value))
176                 - av.charWidth / 2;
177         g.drawString(value + "", x, (ypos + (i * av.charHeight))
178                 - (av.charHeight / 5));
179       }
180     }
181   }
182
183   /**
184    * DOCUMENT ME!
185    * 
186    * @param g
187    *          DOCUMENT ME!
188    * @param startx
189    *          DOCUMENT ME!
190    * @param endx
191    *          DOCUMENT ME!
192    * @param ypos
193    *          DOCUMENT ME!
194    */
195   void drawEastScale(Graphics g, int startx, int endx, int ypos)
196   {
197     ypos += av.charHeight;
198
199     if (av.hasHiddenColumns)
200     {
201       endx = av.getColumnSelection().adjustForHiddenColumns(endx);
202     }
203
204     SequenceI seq;
205     // EAST SCALE
206     for (int i = 0; i < av.alignment.getHeight(); i++)
207     {
208       seq = av.alignment.getSequenceAt(i);
209       int index = endx;
210       int value = -1;
211
212       while (index > startx)
213       {
214         if (jalview.util.Comparison.isGap(seq.getCharAt(index)))
215         {
216           index--;
217
218           continue;
219         }
220
221         value = seq.findPosition(index);
222
223         break;
224       }
225
226       if (value != -1)
227       {
228         g.drawString(String.valueOf(value), 0, (ypos + (i * av.charHeight))
229                 - (av.charHeight / 5));
230       }
231     }
232   }
233
234   boolean fastpainting = false;
235
236   /**
237    * need to make this thread safe move alignment rendering in response to
238    * slider adjustment
239    * 
240    * @param horizontal
241    *          shift along
242    * @param vertical
243    *          shift up or down in repaint
244    */
245   public void fastPaint(int horizontal, int vertical)
246   {
247     if (fastpainting)
248     {
249       return;
250     }
251     fastpainting = true;
252     if (gg == null)
253     {
254       return;
255     }
256
257     fastPaint = true;
258
259     gg.copyArea(horizontal * av.charWidth, vertical * av.charHeight,
260             imgWidth, imgHeight, -horizontal * av.charWidth, -vertical
261                     * av.charHeight);
262
263     int sr = av.startRes;
264     int er = av.endRes;
265     int ss = av.startSeq;
266     int es = av.endSeq;
267     int transX = 0;
268     int transY = 0;
269
270     if (horizontal > 0) // scrollbar pulled right, image to the left
271     {
272       er++;
273       transX = (er - sr - horizontal) * av.charWidth;
274       sr = er - horizontal;
275     }
276     else if (horizontal < 0)
277     {
278       er = sr - horizontal - 1;
279     }
280     else if (vertical > 0) // scroll down
281     {
282       ss = es - vertical;
283
284       if (ss < av.startSeq)
285       { // ie scrolling too fast, more than a page at a time
286         ss = av.startSeq;
287       }
288       else
289       {
290         transY = imgHeight - (vertical * av.charHeight);
291       }
292     }
293     else if (vertical < 0)
294     {
295       es = ss - vertical;
296
297       if (es > av.endSeq)
298       {
299         es = av.endSeq;
300       }
301     }
302
303     gg.translate(transX, transY);
304     drawPanel(gg, sr, er, ss, es, 0);
305     gg.translate(-transX, -transY);
306
307     repaint();
308     fastpainting = false;
309   }
310
311   /**
312    * Definitions of startx and endx (hopefully): SMJS This is what I'm working
313    * towards! startx is the first residue (starting at 0) to display. endx is
314    * the last residue to display (starting at 0). starty is the first sequence
315    * to display (starting at 0). endy is the last sequence to display (starting
316    * at 0). NOTE 1: The av limits are set in setFont in this class and in the
317    * adjustment listener in SeqPanel when the scrollbars move.
318    */
319
320   // Set this to false to force a full panel paint
321   public void paintComponent(Graphics g)
322   {
323     BufferedImage lcimg = img; // take reference since other threads may null
324     // img and call later.
325     super.paintComponent(g);
326
327     if (lcimg != null
328             && (fastPaint
329                     || (getVisibleRect().width != g.getClipBounds().width) || (getVisibleRect().height != g
330                     .getClipBounds().height)))
331     {
332       g.drawImage(lcimg, 0, 0, this);
333       fastPaint = false;
334       return;
335     }
336
337     // this draws the whole of the alignment
338     imgWidth = getWidth();
339     imgHeight = getHeight();
340
341     imgWidth -= (imgWidth % av.charWidth);
342     imgHeight -= (imgHeight % av.charHeight);
343
344     if ((imgWidth < 1) || (imgHeight < 1))
345     {
346       return;
347     }
348
349     if (lcimg == null || imgWidth != lcimg.getWidth()
350             || imgHeight != lcimg.getHeight())
351     {
352       try
353       {
354         lcimg = img = new BufferedImage(imgWidth, imgHeight,
355                 BufferedImage.TYPE_INT_RGB);
356         gg = (Graphics2D) img.getGraphics();
357         gg.setFont(av.getFont());
358       } catch (OutOfMemoryError er)
359       {
360         System.gc();
361         System.err.println("SeqCanvas OutOfMemory Redraw Error.\n" + er);
362         new OOMWarning("Creating alignment image for display", er);
363
364         return;
365       }
366     }
367
368     if (av.antiAlias)
369     {
370       gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
371               RenderingHints.VALUE_ANTIALIAS_ON);
372     }
373
374     gg.setColor(Color.white);
375     gg.fillRect(0, 0, imgWidth, imgHeight);
376
377     if (av.getWrapAlignment())
378     {
379       drawWrappedPanel(gg, getWidth(), getHeight(), av.startRes);
380     }
381     else
382     {
383       drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq, 0);
384     }
385
386     g.drawImage(lcimg, 0, 0, this);
387
388   }
389
390   /**
391    * DOCUMENT ME!
392    * 
393    * @param cwidth
394    *          DOCUMENT ME!
395    * 
396    * @return DOCUMENT ME!
397    */
398   public int getWrappedCanvasWidth(int cwidth)
399   {
400     FontMetrics fm = getFontMetrics(av.getFont());
401
402     LABEL_EAST = 0;
403     LABEL_WEST = 0;
404
405     if (av.scaleRightWrapped)
406     {
407       LABEL_EAST = fm.stringWidth(getMask());
408     }
409
410     if (av.scaleLeftWrapped)
411     {
412       LABEL_WEST = fm.stringWidth(getMask());
413     }
414
415     return (cwidth - LABEL_EAST - LABEL_WEST) / av.charWidth;
416   }
417
418   /**
419    * Generates a string of zeroes.
420    * 
421    * @return String
422    */
423   String getMask()
424   {
425     String mask = "00";
426     int maxWidth = 0;
427     int tmp;
428     for (int i = 0; i < av.alignment.getHeight(); i++)
429     {
430       tmp = av.alignment.getSequenceAt(i).getEnd();
431       if (tmp > maxWidth)
432       {
433         maxWidth = tmp;
434       }
435     }
436
437     for (int i = maxWidth; i > 0; i /= 10)
438     {
439       mask += "0";
440     }
441     return mask;
442   }
443
444   /**
445    * DOCUMENT ME!
446    * 
447    * @param g
448    *          DOCUMENT ME!
449    * @param canvasWidth
450    *          DOCUMENT ME!
451    * @param canvasHeight
452    *          DOCUMENT ME!
453    * @param startRes
454    *          DOCUMENT ME!
455    */
456   public void drawWrappedPanel(Graphics g, int canvasWidth,
457           int canvasHeight, int startRes)
458   {
459     AlignmentI al = av.getAlignment();
460
461     FontMetrics fm = getFontMetrics(av.getFont());
462
463     if (av.scaleRightWrapped)
464     {
465       LABEL_EAST = fm.stringWidth(getMask());
466     }
467
468     if (av.scaleLeftWrapped)
469     {
470       LABEL_WEST = fm.stringWidth(getMask());
471     }
472
473     int hgap = av.charHeight;
474     if (av.scaleAboveWrapped)
475     {
476       hgap += av.charHeight;
477     }
478
479     int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / av.charWidth;
480     int cHeight = av.getAlignment().getHeight() * av.charHeight;
481
482     av.setWrappedWidth(cWidth);
483
484     av.endRes = av.startRes + cWidth;
485
486     int endx;
487     int ypos = hgap;
488     int maxwidth = av.alignment.getWidth() - 1;
489
490     if (av.hasHiddenColumns)
491     {
492       maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
493     }
494
495     while ((ypos <= canvasHeight) && (startRes < maxwidth))
496     {
497       endx = startRes + cWidth - 1;
498
499       if (endx > maxwidth)
500       {
501         endx = maxwidth;
502       }
503
504       g.setFont(av.getFont());
505       g.setColor(Color.black);
506
507       if (av.scaleLeftWrapped)
508       {
509         drawWestScale(g, startRes, endx, ypos);
510       }
511
512       if (av.scaleRightWrapped)
513       {
514         g.translate(canvasWidth - LABEL_EAST, 0);
515         drawEastScale(g, startRes, endx, ypos);
516         g.translate(-(canvasWidth - LABEL_EAST), 0);
517       }
518
519       g.translate(LABEL_WEST, 0);
520
521       if (av.scaleAboveWrapped)
522       {
523         drawNorthScale(g, startRes, endx, ypos);
524       }
525
526       if (av.hasHiddenColumns && av.showHiddenMarkers)
527       {
528         g.setColor(Color.blue);
529         int res;
530         for (int i = 0; i < av.getColumnSelection().getHiddenColumns()
531                 .size(); i++)
532         {
533           res = av.getColumnSelection().findHiddenRegionPosition(i)
534                   - startRes;
535
536           if (res < 0 || res > endx - startRes)
537           {
538             continue;
539           }
540
541           gg.fillPolygon(new int[]
542           { res * av.charWidth - av.charHeight / 4,
543               res * av.charWidth + av.charHeight / 4, res * av.charWidth },
544                   new int[]
545                   { ypos - (av.charHeight / 2), ypos - (av.charHeight / 2),
546                       ypos - (av.charHeight / 2) + 8 }, 3);
547
548         }
549       }
550
551       // When printing we have an extra clipped region,
552       // the Printable page which we need to account for here
553       Shape clip = g.getClip();
554
555       if (clip == null)
556       {
557         g.setClip(0, 0, cWidth * av.charWidth, canvasHeight);
558       }
559       else
560       {
561         g.setClip(0, (int) clip.getBounds().getY(), cWidth * av.charWidth,
562                 (int) clip.getBounds().getHeight());
563       }
564
565       drawPanel(g, startRes, endx, 0, al.getHeight(), ypos);
566
567       if (av.showAnnotation)
568       {
569         g.translate(0, cHeight + ypos + 3);
570         if (annotations == null)
571         {
572           annotations = new AnnotationPanel(av);
573         }
574
575         annotations.drawComponent((Graphics2D) g, startRes, endx + 1);
576         g.translate(0, -cHeight - ypos - 3);
577       }
578       g.setClip(clip);
579       g.translate(-LABEL_WEST, 0);
580
581       ypos += cHeight + getAnnotationHeight() + hgap;
582
583       startRes += cWidth;
584     }
585   }
586
587   AnnotationPanel annotations;
588
589   int getAnnotationHeight()
590   {
591     if (!av.showAnnotation)
592     {
593       return 0;
594     }
595
596     if (annotations == null)
597     {
598       annotations = new AnnotationPanel(av);
599     }
600
601     return annotations.adjustPanelHeight();
602   }
603
604   /**
605    * DOCUMENT ME!
606    * 
607    * @param g1
608    *          DOCUMENT ME!
609    * @param startRes
610    *          DOCUMENT ME!
611    * @param endRes
612    *          DOCUMENT ME!
613    * @param startSeq
614    *          DOCUMENT ME!
615    * @param endSeq
616    *          DOCUMENT ME!
617    * @param offset
618    *          DOCUMENT ME!
619    */
620   void drawPanel(Graphics g1, int startRes, int endRes, int startSeq,
621           int endSeq, int offset)
622   {
623     if (!av.hasHiddenColumns)
624     {
625       draw(g1, startRes, endRes, startSeq, endSeq, offset);
626     }
627     else
628     {
629       java.util.Vector regions = av.getColumnSelection().getHiddenColumns();
630
631       int screenY = 0;
632       int blockStart = startRes;
633       int blockEnd = endRes;
634
635       for (int i = 0; regions != null && i < regions.size(); i++)
636       {
637         int[] region = (int[]) regions.elementAt(i);
638         int hideStart = region[0];
639         int hideEnd = region[1];
640
641         if (hideStart <= blockStart)
642         {
643           blockStart += (hideEnd - hideStart) + 1;
644           continue;
645         }
646
647         blockEnd = hideStart - 1;
648
649         g1.translate(screenY * av.charWidth, 0);
650
651         draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
652
653         if (av.getShowHiddenMarkers())
654         {
655           g1.setColor(Color.blue);
656
657           g1
658                   .drawLine((blockEnd - blockStart + 1) * av.charWidth - 1,
659                           0 + offset, (blockEnd - blockStart + 1)
660                                   * av.charWidth - 1, (endSeq - startSeq)
661                                   * av.charHeight + offset);
662         }
663
664         g1.translate(-screenY * av.charWidth, 0);
665         screenY += blockEnd - blockStart + 1;
666         blockStart = hideEnd + 1;
667       }
668
669       if (screenY <= (endRes - startRes))
670       {
671         blockEnd = blockStart + (endRes - startRes) - screenY;
672         g1.translate(screenY * av.charWidth, 0);
673         draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
674
675         g1.translate(-screenY * av.charWidth, 0);
676       }
677     }
678
679   }
680
681   // int startRes, int endRes, int startSeq, int endSeq, int x, int y,
682   // int x1, int x2, int y1, int y2, int startx, int starty,
683   void draw(Graphics g, int startRes, int endRes, int startSeq, int endSeq,
684           int offset)
685   {
686     g.setFont(av.getFont());
687     sr.prepare(g, av.renderGaps);
688
689     SequenceI nextSeq;
690
691     // / First draw the sequences
692     // ///////////////////////////
693     for (int i = startSeq; i < endSeq; i++)
694     {
695       nextSeq = av.alignment.getSequenceAt(i);
696       if (nextSeq == null)
697       {
698         // occasionally, a race condition occurs such that the alignment row is
699         // empty
700         continue;
701       }
702       sr.drawSequence(nextSeq, av.alignment.findAllGroups(nextSeq),
703               startRes, endRes, offset + ((i - startSeq) * av.charHeight));
704
705       if (av.showSequenceFeatures)
706       {
707         fr.drawSequence(g, nextSeq, startRes, endRes, offset
708                 + ((i - startSeq) * av.charHeight));
709       }
710
711       // / Highlight search Results once all sequences have been drawn
712       // ////////////////////////////////////////////////////////
713       if (searchResults != null)
714       {
715         int[] visibleResults = searchResults.getResults(nextSeq, startRes,
716                 endRes);
717         if (visibleResults != null)
718         {
719           for (int r = 0; r < visibleResults.length; r += 2)
720           {
721             sr.drawHighlightedText(nextSeq, visibleResults[r],
722                     visibleResults[r + 1], (visibleResults[r] - startRes)
723                             * av.charWidth, offset
724                             + ((i - startSeq) * av.charHeight));
725           }
726         }
727       }
728
729       if (av.cursorMode && cursorY == i && cursorX >= startRes
730               && cursorX <= endRes)
731       {
732         sr.drawCursor(nextSeq, cursorX,
733                 (cursorX - startRes) * av.charWidth, offset
734                         + ((i - startSeq) * av.charHeight));
735       }
736     }
737
738     if (av.getSelectionGroup() != null
739             || av.alignment.getGroups().size() > 0)
740     {
741       drawGroupsBoundaries(g, startRes, endRes, startSeq, endSeq, offset);
742     }
743
744   }
745
746   void drawGroupsBoundaries(Graphics g1, int startRes, int endRes,
747           int startSeq, int endSeq, int offset)
748   {
749     Graphics2D g = (Graphics2D) g1;
750     //
751     // ///////////////////////////////////
752     // Now outline any areas if necessary
753     // ///////////////////////////////////
754     SequenceGroup group = av.getSelectionGroup();
755
756     int sx = -1;
757     int sy = -1;
758     int ex = -1;
759     int groupIndex = -1;
760     int visWidth = (endRes - startRes + 1) * av.charWidth;
761
762     if ((group == null) && (av.alignment.getGroups().size() > 0))
763     {
764       group = (SequenceGroup) av.alignment.getGroups().elementAt(0);
765       groupIndex = 0;
766     }
767
768     if (group != null)
769     {
770       do
771       {
772         int oldY = -1;
773         int i = 0;
774         boolean inGroup = false;
775         int top = -1;
776         int bottom = -1;
777
778         for (i = startSeq; i < endSeq; i++)
779         {
780           sx = (group.getStartRes() - startRes) * av.charWidth;
781           sy = offset + ((i - startSeq) * av.charHeight);
782           ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) - 1;
783
784           if (sx + ex < 0 || sx > visWidth)
785           {
786             continue;
787           }
788
789           if ((sx <= (endRes - startRes) * av.charWidth)
790                   && group.getSequences(null).contains(
791                           av.alignment.getSequenceAt(i)))
792           {
793             if ((bottom == -1)
794                     && !group.getSequences(null).contains(
795                             av.alignment.getSequenceAt(i + 1)))
796             {
797               bottom = sy + av.charHeight;
798             }
799
800             if (!inGroup)
801             {
802               if (((top == -1) && (i == 0))
803                       || !group.getSequences(null).contains(
804                               av.alignment.getSequenceAt(i - 1)))
805               {
806                 top = sy;
807               }
808
809               oldY = sy;
810               inGroup = true;
811
812               if (group == av.getSelectionGroup())
813               {
814                 g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
815                         BasicStroke.JOIN_ROUND, 3f, new float[]
816                         { 5f, 3f }, 0f));
817                 g.setColor(Color.RED);
818               }
819               else
820               {
821                 g.setStroke(new BasicStroke());
822                 g.setColor(group.getOutlineColour());
823               }
824             }
825           }
826           else
827           {
828             if (inGroup)
829             {
830               if (sx >= 0 && sx < visWidth)
831               {
832                 g.drawLine(sx, oldY, sx, sy);
833               }
834
835               if (sx + ex < visWidth)
836               {
837                 g.drawLine(sx + ex, oldY, sx + ex, sy);
838               }
839
840               if (sx < 0)
841               {
842                 ex += sx;
843                 sx = 0;
844               }
845
846               if (sx + ex > visWidth)
847               {
848                 ex = visWidth;
849               }
850
851               else if (sx + ex >= (endRes - startRes + 1) * av.charWidth)
852               {
853                 ex = (endRes - startRes + 1) * av.charWidth;
854               }
855
856               if (top != -1)
857               {
858                 g.drawLine(sx, top, sx + ex, top);
859                 top = -1;
860               }
861
862               if (bottom != -1)
863               {
864                 g.drawLine(sx, bottom, sx + ex, bottom);
865                 bottom = -1;
866               }
867
868               inGroup = false;
869             }
870           }
871         }
872
873         if (inGroup)
874         {
875           sy = offset + ((i - startSeq) * av.charHeight);
876           if (sx >= 0 && sx < visWidth)
877           {
878             g.drawLine(sx, oldY, sx, sy);
879           }
880
881           if (sx + ex < visWidth)
882           {
883             g.drawLine(sx + ex, oldY, sx + ex, sy);
884           }
885
886           if (sx < 0)
887           {
888             ex += sx;
889             sx = 0;
890           }
891
892           if (sx + ex > visWidth)
893           {
894             ex = visWidth;
895           }
896           else if (sx + ex >= (endRes - startRes + 1) * av.charWidth)
897           {
898             ex = (endRes - startRes + 1) * av.charWidth;
899           }
900
901           if (top != -1)
902           {
903             g.drawLine(sx, top, sx + ex, top);
904             top = -1;
905           }
906
907           if (bottom != -1)
908           {
909             g.drawLine(sx, bottom - 1, sx + ex, bottom - 1);
910             bottom = -1;
911           }
912
913           inGroup = false;
914         }
915
916         groupIndex++;
917
918         g.setStroke(new BasicStroke());
919
920         if (groupIndex >= av.alignment.getGroups().size())
921         {
922           break;
923         }
924
925         group = (SequenceGroup) av.alignment.getGroups().elementAt(
926                 groupIndex);
927
928       } while (groupIndex < av.alignment.getGroups().size());
929
930     }
931
932   }
933
934   /**
935    * DOCUMENT ME!
936    * 
937    * @param results
938    *          DOCUMENT ME!
939    */
940   public void highlightSearchResults(SearchResults results)
941   {
942     img = null;
943
944     searchResults = results;
945
946     repaint();
947   }
948 }