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