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