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