update author list in license for (JAL-826)
[jalview.git] / src / jalview / gui / SeqCanvas.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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.drawLine((blockEnd - blockStart + 1) * av.charWidth - 1,
658                   0 + offset, (blockEnd - blockStart + 1) * av.charWidth
659                           - 1, (endSeq - startSeq) * av.charHeight + offset);
660         }
661
662         g1.translate(-screenY * av.charWidth, 0);
663         screenY += blockEnd - blockStart + 1;
664         blockStart = hideEnd + 1;
665       }
666
667       if (screenY <= (endRes - startRes))
668       {
669         blockEnd = blockStart + (endRes - startRes) - screenY;
670         g1.translate(screenY * av.charWidth, 0);
671         draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
672
673         g1.translate(-screenY * av.charWidth, 0);
674       }
675     }
676
677   }
678
679   // int startRes, int endRes, int startSeq, int endSeq, int x, int y,
680   // int x1, int x2, int y1, int y2, int startx, int starty,
681   void draw(Graphics g, int startRes, int endRes, int startSeq, int endSeq,
682           int offset)
683   {
684     g.setFont(av.getFont());
685     sr.prepare(g, av.renderGaps);
686
687     SequenceI nextSeq;
688
689     // / First draw the sequences
690     // ///////////////////////////
691     for (int i = startSeq; i < endSeq; i++)
692     {
693       nextSeq = av.alignment.getSequenceAt(i);
694       if (nextSeq == null)
695       {
696         // occasionally, a race condition occurs such that the alignment row is
697         // empty
698         continue;
699       }
700       sr.drawSequence(nextSeq, av.alignment.findAllGroups(nextSeq),
701               startRes, endRes, offset + ((i - startSeq) * av.charHeight));
702
703       if (av.showSequenceFeatures)
704       {
705         fr.drawSequence(g, nextSeq, startRes, endRes, offset
706                 + ((i - startSeq) * av.charHeight));
707       }
708
709       // / Highlight search Results once all sequences have been drawn
710       // ////////////////////////////////////////////////////////
711       if (searchResults != null)
712       {
713         int[] visibleResults = searchResults.getResults(nextSeq, startRes,
714                 endRes);
715         if (visibleResults != null)
716         {
717           for (int r = 0; r < visibleResults.length; r += 2)
718           {
719             sr.drawHighlightedText(nextSeq, visibleResults[r],
720                     visibleResults[r + 1], (visibleResults[r] - startRes)
721                             * av.charWidth, offset
722                             + ((i - startSeq) * av.charHeight));
723           }
724         }
725       }
726
727       if (av.cursorMode && cursorY == i && cursorX >= startRes
728               && cursorX <= endRes)
729       {
730         sr.drawCursor(nextSeq, cursorX,
731                 (cursorX - startRes) * av.charWidth, offset
732                         + ((i - startSeq) * av.charHeight));
733       }
734     }
735
736     if (av.getSelectionGroup() != null
737             || av.alignment.getGroups().size() > 0)
738     {
739       drawGroupsBoundaries(g, startRes, endRes, startSeq, endSeq, offset);
740     }
741
742   }
743
744   void drawGroupsBoundaries(Graphics g1, int startRes, int endRes,
745           int startSeq, int endSeq, int offset)
746   {
747     Graphics2D g = (Graphics2D) g1;
748     //
749     // ///////////////////////////////////
750     // Now outline any areas if necessary
751     // ///////////////////////////////////
752     SequenceGroup group = av.getSelectionGroup();
753
754     int sx = -1;
755     int sy = -1;
756     int ex = -1;
757     int groupIndex = -1;
758     int visWidth = (endRes - startRes + 1) * av.charWidth;
759
760     if ((group == null) && (av.alignment.getGroups().size() > 0))
761     {
762       group = (SequenceGroup) av.alignment.getGroups().elementAt(0);
763       groupIndex = 0;
764     }
765
766     if (group != null)
767     {
768       do
769       {
770         int oldY = -1;
771         int i = 0;
772         boolean inGroup = false;
773         int top = -1;
774         int bottom = -1;
775
776         for (i = startSeq; i < endSeq; i++)
777         {
778           sx = (group.getStartRes() - startRes) * av.charWidth;
779           sy = offset + ((i - startSeq) * av.charHeight);
780           ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) - 1;
781
782           if (sx + ex < 0 || sx > visWidth)
783           {
784             continue;
785           }
786
787           if ((sx <= (endRes - startRes) * av.charWidth)
788                   && group.getSequences(null).contains(
789                           av.alignment.getSequenceAt(i)))
790           {
791             if ((bottom == -1)
792                     && !group.getSequences(null).contains(
793                             av.alignment.getSequenceAt(i + 1)))
794             {
795               bottom = sy + av.charHeight;
796             }
797
798             if (!inGroup)
799             {
800               if (((top == -1) && (i == 0))
801                       || !group.getSequences(null).contains(
802                               av.alignment.getSequenceAt(i - 1)))
803               {
804                 top = sy;
805               }
806
807               oldY = sy;
808               inGroup = true;
809
810               if (group == av.getSelectionGroup())
811               {
812                 g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
813                         BasicStroke.JOIN_ROUND, 3f, new float[]
814                         { 5f, 3f }, 0f));
815                 g.setColor(Color.RED);
816               }
817               else
818               {
819                 g.setStroke(new BasicStroke());
820                 g.setColor(group.getOutlineColour());
821               }
822             }
823           }
824           else
825           {
826             if (inGroup)
827             {
828               if (sx >= 0 && sx < visWidth)
829               {
830                 g.drawLine(sx, oldY, sx, sy);
831               }
832
833               if (sx + ex < visWidth)
834               {
835                 g.drawLine(sx + ex, oldY, sx + ex, sy);
836               }
837
838               if (sx < 0)
839               {
840                 ex += sx;
841                 sx = 0;
842               }
843
844               if (sx + ex > visWidth)
845               {
846                 ex = visWidth;
847               }
848
849               else if (sx + ex >= (endRes - startRes + 1) * av.charWidth)
850               {
851                 ex = (endRes - startRes + 1) * av.charWidth;
852               }
853
854               if (top != -1)
855               {
856                 g.drawLine(sx, top, sx + ex, top);
857                 top = -1;
858               }
859
860               if (bottom != -1)
861               {
862                 g.drawLine(sx, bottom, sx + ex, bottom);
863                 bottom = -1;
864               }
865
866               inGroup = false;
867             }
868           }
869         }
870
871         if (inGroup)
872         {
873           sy = offset + ((i - startSeq) * av.charHeight);
874           if (sx >= 0 && sx < visWidth)
875           {
876             g.drawLine(sx, oldY, sx, sy);
877           }
878
879           if (sx + ex < visWidth)
880           {
881             g.drawLine(sx + ex, oldY, sx + ex, sy);
882           }
883
884           if (sx < 0)
885           {
886             ex += sx;
887             sx = 0;
888           }
889
890           if (sx + ex > visWidth)
891           {
892             ex = visWidth;
893           }
894           else if (sx + ex >= (endRes - startRes + 1) * av.charWidth)
895           {
896             ex = (endRes - startRes + 1) * av.charWidth;
897           }
898
899           if (top != -1)
900           {
901             g.drawLine(sx, top, sx + ex, top);
902             top = -1;
903           }
904
905           if (bottom != -1)
906           {
907             g.drawLine(sx, bottom - 1, sx + ex, bottom - 1);
908             bottom = -1;
909           }
910
911           inGroup = false;
912         }
913
914         groupIndex++;
915
916         g.setStroke(new BasicStroke());
917
918         if (groupIndex >= av.alignment.getGroups().size())
919         {
920           break;
921         }
922
923         group = (SequenceGroup) av.alignment.getGroups().elementAt(
924                 groupIndex);
925
926       } while (groupIndex < av.alignment.getGroups().size());
927
928     }
929
930   }
931
932   /**
933    * DOCUMENT ME!
934    * 
935    * @param results
936    *          DOCUMENT ME!
937    */
938   public void highlightSearchResults(SearchResults results)
939   {
940     img = null;
941
942     searchResults = results;
943
944     repaint();
945   }
946 }