JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / gui / 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.gui;
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.datamodel.VisibleContigsIterator;
29 import jalview.renderer.ScaleRenderer;
30 import jalview.renderer.ScaleRenderer.ScaleMark;
31 import jalview.util.Comparison;
32 import jalview.viewmodel.ViewportListenerI;
33 import jalview.viewmodel.ViewportRanges;
34
35 import java.awt.BasicStroke;
36 import java.awt.BorderLayout;
37 import java.awt.Color;
38 import java.awt.FontMetrics;
39 import java.awt.Graphics;
40 import java.awt.Graphics2D;
41 import java.awt.Rectangle;
42 import java.awt.RenderingHints;
43 import java.awt.image.BufferedImage;
44 import java.beans.PropertyChangeEvent;
45 import java.util.Iterator;
46 import java.util.List;
47
48 import javax.swing.JPanel;
49
50 /**
51  * The Swing component on which the alignment sequences, and annotations (if
52  * shown), are drawn. This includes scales above, left and right (if shown) in
53  * Wrapped mode, but not the scale above in Unwrapped mode.
54  * 
55  */
56 @SuppressWarnings("serial")
57 public class SeqCanvas extends JPanel implements ViewportListenerI
58 {
59   /*
60    * pixels gap between sequences and annotations when in wrapped mode
61    */
62   static final int SEQS_ANNOTATION_GAP = 3;
63
64   private static final String ZEROS = "0000000000";
65
66   final FeatureRenderer fr;
67
68   BufferedImage img;
69
70   AlignViewport av;
71
72   int cursorX = 0;
73
74   int cursorY = 0;
75
76   private final SequenceRenderer seqRdr;
77
78   boolean fastPaint = false;
79
80   private boolean fastpainting = false;
81
82   private AnnotationPanel annotations;
83
84   /*
85    * measurements for drawing a wrapped alignment
86    */
87   private int labelWidthEast; // label right width in pixels if shown
88
89   private int labelWidthWest; // label left width in pixels if shown
90
91   int wrappedSpaceAboveAlignment; // gap between widths
92
93   int wrappedRepeatHeightPx; // height in pixels of wrapped width
94
95   private int wrappedVisibleWidths; // number of wrapped widths displayed
96
97   // Don't do this! Graphics handles are supposed to be transient
98   //private Graphics2D gg;
99
100   /**
101    * Creates a new SeqCanvas object.
102    * 
103    * @param ap
104    */
105   public SeqCanvas(AlignmentPanel ap)
106   {
107     this.av = ap.av;
108     fr = new FeatureRenderer(ap);
109     seqRdr = new SequenceRenderer(av);
110     setLayout(new BorderLayout());
111     PaintRefresher.Register(this, av.getSequenceSetId());
112     setBackground(Color.white);
113
114     av.getRanges().addPropertyChangeListener(this);
115   }
116
117   public SequenceRenderer getSequenceRenderer()
118   {
119     return seqRdr; 
120   }
121
122   public FeatureRenderer getFeatureRenderer()
123   {
124     return fr;
125   }
126
127   /**
128    * Draws the scale above a region of a wrapped alignment, consisting of a
129    * column number every major interval (10 columns).
130    * 
131    * @param g
132    *          the graphics context to draw on, positioned at the start (bottom
133    *          left) of the line on which to draw any scale marks
134    * @param startx
135    *          start alignment column (0..)
136    * @param endx
137    *          end alignment column (0..)
138    * @param ypos
139    *          y offset to draw at
140    */
141   private void drawNorthScale(Graphics g, int startx, int endx, int ypos)
142   {
143     int charHeight = av.getCharHeight();
144     int charWidth = av.getCharWidth();
145
146     /*
147      * white fill the scale space (for the fastPaint case)
148      */
149     g.setColor(Color.white);
150     g.fillRect(0, ypos - charHeight - charHeight / 2, getWidth(),
151             charHeight * 3 / 2 + 2);
152     g.setColor(Color.black);
153
154     List<ScaleMark> marks = new ScaleRenderer().calculateMarks(av, startx,
155             endx);
156     for (ScaleMark mark : marks)
157     {
158       int mpos = mark.column; // (i - startx - 1)
159       if (mpos < 0)
160       {
161         continue;
162       }
163       String mstring = mark.text;
164
165       if (mark.major)
166       {
167         if (mstring != null)
168         {
169           g.drawString(mstring, mpos * charWidth, ypos - (charHeight / 2));
170         }
171
172         /*
173          * draw a tick mark below the column number, centred on the column;
174          * height of tick mark is 4 pixels less than half a character
175          */
176         int xpos = (mpos * charWidth) + (charWidth / 2);
177         g.drawLine(xpos, (ypos + 2) - (charHeight / 2), xpos, ypos - 2);
178       }
179     }
180   }
181
182   /**
183    * Draw the scale to the left or right of a wrapped alignment
184    * 
185    * @param g
186    *          graphics context, positioned at the start of the scale to be drawn
187    * @param startx
188    *          first column of wrapped width (0.. excluding any hidden columns)
189    * @param endx
190    *          last column of wrapped width (0.. excluding any hidden columns)
191    * @param ypos
192    *          vertical offset at which to begin the scale
193    * @param left
194    *          if true, scale is left of residues, if false, scale is right
195    */
196   void drawVerticalScale(Graphics g, final int startx, final int endx,
197           final int ypos, final boolean left)
198   {
199     int charHeight = av.getCharHeight();
200     int charWidth = av.getCharWidth();
201
202     int yPos = ypos + charHeight;
203     int startX = startx;
204     int endX = endx;
205     
206     if (av.hasHiddenColumns())
207     {
208       HiddenColumns hiddenColumns = av.getAlignment().getHiddenColumns();
209       startX = hiddenColumns.visibleToAbsoluteColumn(startx);
210       endX = hiddenColumns.visibleToAbsoluteColumn(endx);
211     }
212     FontMetrics fm = getFontMetrics(av.getFont());
213
214     for (int i = 0; i < av.getAlignment().getHeight(); i++)
215     {
216       SequenceI seq = av.getAlignment().getSequenceAt(i);
217
218       /*
219        * find sequence position of first non-gapped position -
220        * to the right if scale left, to the left if scale right
221        */
222       int index = left ? startX : endX;
223       int value = -1;
224       while (index >= startX && index <= endX)
225       {
226         if (!Comparison.isGap(seq.getCharAt(index)))
227         {
228           value = seq.findPosition(index);
229           break;
230         }
231         if (left)
232         {
233           index++;
234         }
235         else
236         {
237           index--;
238         }
239       }
240
241       
242       /*
243        * white fill the space for the scale
244        */
245       g.setColor(Color.white);
246       int y = (yPos + (i * charHeight)) - (charHeight / 5);
247       // fillRect origin is top left of rectangle
248       g.fillRect(0, y - charHeight, left ? labelWidthWest : labelWidthEast,
249               charHeight + 1);
250
251       if (value != -1)
252       {
253         /*
254          * draw scale value, right justified within its width less half a
255          * character width padding on the right
256          */
257         int labelSpace = left ? labelWidthWest : labelWidthEast;
258         labelSpace -= charWidth / 2; // leave space to the right
259         String valueAsString = String.valueOf(value);
260         int labelLength = fm.stringWidth(valueAsString);
261         int xOffset = labelSpace - labelLength;
262         g.setColor(Color.black);
263         g.drawString(valueAsString, xOffset, y);
264       }
265     }
266
267   }
268
269   /**
270    * Does a fast paint of an alignment in response to a scroll. Most of the
271    * visible region is simply copied and shifted, and then any newly visible
272    * columns or rows are drawn. The scroll may be horizontal or vertical, but
273    * not both at once. Scrolling may be the result of
274    * <ul>
275    * <li>dragging a scroll bar</li>
276    * <li>clicking in the scroll bar</li>
277    * <li>scrolling by trackpad, middle mouse button, or other device</li>
278    * <li>by moving the box in the Overview window</li>
279    * <li>programmatically to make a highlighted position visible</li>
280    * <li>pasting a block of sequences</li>
281    * </ul>
282    * 
283    * @param horizontal
284    *          columns to shift right (positive) or left (negative)
285    * @param vertical
286    *          rows to shift down (positive) or up (negative)
287    */
288   public void fastPaint(int horizontal, int vertical)
289   {
290
291     // effectively:
292     // if (horizontal != 0 && vertical != 0)
293     // throw new InvalidArgumentException();
294     if (fastpainting || img == null)
295     {
296       return;
297     }
298     fastpainting = true;
299     fastPaint = true;
300     try
301     {
302       int charHeight = av.getCharHeight();
303       int charWidth = av.getCharWidth();
304
305       ViewportRanges ranges = av.getRanges();
306       int startRes = ranges.getStartRes();
307       int endRes = ranges.getEndRes();
308       int startSeq = ranges.getStartSeq();
309       int endSeq = ranges.getEndSeq();
310       int transX = 0;
311       int transY = 0;
312
313       if (horizontal > 0) // scrollbar pulled right, image to the left
314       {
315         transX = (endRes - startRes - horizontal) * charWidth;
316         startRes = endRes - horizontal;
317       }
318       else if (horizontal < 0)
319       {
320         endRes = startRes - horizontal;
321       }
322
323       if (vertical > 0) // scroll down
324       {
325         startSeq = endSeq - vertical;
326
327         if (startSeq < ranges.getStartSeq())
328         { // ie scrolling too fast, more than a page at a time
329           startSeq = ranges.getStartSeq();
330         }
331         else
332         {
333           transY = img.getHeight() - ((vertical + 1) * charHeight);
334         }
335       }
336       else if (vertical < 0)
337       {
338         endSeq = startSeq - vertical;
339
340         if (endSeq > ranges.getEndSeq())
341         {
342           endSeq = ranges.getEndSeq();
343         }
344       }
345
346
347       // System.err.println(">>> FastPaint to " + transX + " " + transY + " "
348       // + horizontal + " " + vertical + " " + startRes + " " + endRes
349       // + " " + startSeq + " " + endSeq);
350
351       Graphics gg = img.getGraphics();
352       gg.copyArea(horizontal * charWidth, vertical * charHeight,
353               img.getWidth(), img.getHeight(), -horizontal * charWidth,
354               -vertical * charHeight);
355       gg.translate(transX, transY);
356       drawPanel(gg, startRes, endRes, startSeq, endSeq, 0);
357       gg.translate(-transX, -transY);
358       gg.dispose();
359
360       // Call repaint on alignment panel so that repaints from other alignment
361       // panel components can be aggregated. Otherwise performance of the
362       // overview window and others may be adversely affected.
363       // System.out.println("SeqCanvas fastPaint() repaint() request...");
364       av.getAlignPanel().repaint();
365     } finally
366     {
367       fastpainting = false;
368     }
369   }
370
371   @Override
372   public void paintComponent(Graphics g)
373   {
374
375     if (av.getAlignPanel().getHoldRepaint())
376     {
377       return;
378     }
379     int charHeight = av.getCharHeight();
380     int charWidth = av.getCharWidth();
381
382     int availWidth = getWidth();
383     int availHeight = getHeight();
384
385     availWidth -= (availWidth % charWidth);
386     availHeight -= (availHeight % charHeight);
387
388     // BH 2019 can't possibly fastPaint if either width or height is 0
389
390     if (availWidth == 0 || availHeight == 0)
391     {
392       return;
393     }
394
395     ViewportRanges ranges = av.getRanges();
396     int startRes = ranges.getStartRes();
397     int startSeq = ranges.getStartSeq();
398     int endRes = ranges.getEndRes();
399     int endSeq = ranges.getEndSeq();
400
401     // [JAL-3226] problem that JavaScript (or Java) may consolidate multiple
402     // repaint() requests in unpredictable ways. In this case, the issue was
403     // that in response to a CTRL-C/CTRL-V paste request, in Java a fast
404     // repaint request preceded two full requests, thus resulting
405     // in a full request for paint. In constrast, in JavaScript, the three
406     // requests were bundled together into one, so the fastPaint flag was
407     // still present for the second and third request.
408     //
409     // This resulted in incomplete painting.
410     //
411     // The solution was to set seqCanvas.fastPaint and idCanvas.fastPaint false
412     // in PaintRefresher when the target to be painted is one of those two
413     // components.
414     //
415     // BH 2019.04.22
416     //
417     // An initial idea; can be removed once we determine this issue is closed:
418     // if (av.isFastPaintDisabled())
419     // {
420     // fastPaint = false;
421     // }
422
423     Rectangle vis, clip;
424     if (img != null
425             && (fastPaint
426                     || (vis = getVisibleRect()).width != (clip = g
427                             .getClipBounds()).width
428                     || vis.height != clip.height))
429     {
430       g.drawImage(img, 0, 0, this);
431       drawSelectionGroup((Graphics2D) g, startRes, endRes, startSeq,
432               endSeq);
433       fastPaint = false;
434     }
435     else
436     {
437       // img is a cached version of the last view we drew.
438       // If we have no img or the size has changed, make a new one.
439       //
440       if (img == null || availWidth != img.getWidth()
441               || availHeight != img.getHeight())
442       {
443         img = new BufferedImage(availWidth, availHeight,
444                 BufferedImage.TYPE_INT_RGB);
445       }
446
447       Graphics2D gg = (Graphics2D) img.getGraphics();
448       gg.setFont(av.getFont());
449
450       if (av.antiAlias)
451       {
452         gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
453                 RenderingHints.VALUE_ANTIALIAS_ON);
454       }
455
456       gg.setColor(Color.white);
457       gg.fillRect(0, 0, availWidth, availHeight);
458
459       if (av.getWrapAlignment())
460       {
461         drawWrappedPanel(gg, availWidth, availHeight, ranges.getStartRes());
462       }
463       else
464       {
465         drawPanel(gg, startRes, endRes, startSeq, endSeq, 0);
466       }
467
468       drawSelectionGroup(gg, startRes, endRes, startSeq, endSeq);
469
470       g.drawImage(img, 0, 0, this);
471       gg.dispose();
472     }
473
474     if (av.cursorMode)
475     {
476       drawCursor(g, startRes, endRes, startSeq, endSeq);
477     }
478   }
479   
480   /**
481    * Draw an alignment panel for printing
482    * 
483    * @param g1
484    *          Graphics object to draw with
485    * @param startRes
486    *          start residue of print area
487    * @param endRes
488    *          end residue of print area
489    * @param startSeq
490    *          start sequence of print area
491    * @param endSeq
492    *          end sequence of print area
493    */
494   public void drawPanelForPrinting(Graphics g1, int startRes, int endRes,
495           int startSeq, int endSeq)
496   {
497     drawPanel(g1, startRes, endRes, startSeq, endSeq, 0);
498
499     drawSelectionGroup((Graphics2D) g1, startRes, endRes,
500             startSeq, endSeq);
501   }
502
503   /**
504    * Draw a wrapped alignment panel for printing
505    * 
506    * @param g
507    *          Graphics object to draw with
508    * @param canvasWidth
509    *          width of drawing area
510    * @param canvasHeight
511    *          height of drawing area
512    * @param startRes
513    *          start residue of print area
514    */
515   public void drawWrappedPanelForPrinting(Graphics g, int canvasWidth,
516           int canvasHeight, int startRes)
517   {
518     drawWrappedPanel(g, canvasWidth, canvasHeight, startRes);
519
520     SequenceGroup group = av.getSelectionGroup();
521     if (group != null)
522     {
523       drawWrappedSelection((Graphics2D) g, group, canvasWidth, canvasHeight,
524                 startRes);
525     }
526   }
527
528   /**
529    * Using the current font, determine fields labelWidthEast and labelWidthWest,
530    * and return the number of residues that can fill the remaining width.
531    * 
532    * @param width
533    *          the width in pixels (possibly including scales)
534    * 
535    * @return the visible width in residues, after allowing for East or West
536    *         scales (if shown)
537    * 
538    */
539   public int getWrappedCanvasWidth(int width)
540   {
541     int charWidth = av.getCharWidth();
542
543     FontMetrics fm = getFontMetrics(av.getFont());
544
545     int labelWidth = (av.getScaleRightWrapped() || av.getScaleLeftWrapped()
546             ? getLabelWidth(fm)
547             : 0);
548
549     labelWidthEast = av.getScaleRightWrapped() ? labelWidth : 0;
550
551     labelWidthWest = av.getScaleLeftWrapped() ? labelWidth : 0;
552
553     return (width - labelWidthEast - labelWidthWest) / charWidth;
554   }
555
556   /**
557    * Returns a pixel width sufficient to show the largest sequence coordinate
558    * (end position) in the alignment, calculated as the FontMetrics width of
559    * zeroes "0000000" limited to the number of decimal digits to be shown (3 for
560    * 1-10, 4 for 11-99 etc). One character width is added to this, to allow for
561    * half a character width space on either side.
562    * 
563    * @param fm
564    * @return
565    */
566   protected int getLabelWidth(FontMetrics fm)
567   {
568     /*
569      * find the biggest sequence end position we need to show
570      * (note this is not necessarily the sequence length)
571      */
572     int maxWidth = 0;
573     AlignmentI alignment = av.getAlignment();
574     for (int i = 0; i < alignment.getHeight(); i++)
575     {
576       maxWidth = Math.max(maxWidth, alignment.getSequenceAt(i).getEnd());
577     }
578
579     // quick int log10
580     int length = 0;
581     for (int i = maxWidth; i > 0; i /= 10)
582     {
583       length++;
584     }
585
586     return fm.stringWidth(ZEROS.substring(0, length)) + av.getCharWidth();
587   }
588
589   /**
590    * Draws as many widths of a wrapped alignment as can fit in the visible
591    * window
592    * 
593    * @param g
594    * @param availWidth
595    *          available width in pixels
596    * @param availHeight
597    *          available height in pixels
598    * @param startColumn
599    *          the first column (0...) of the alignment to draw
600    */
601   public void drawWrappedPanel(Graphics g, int availWidth, int availHeight,
602           final int startColumn)
603   {
604     int wrappedWidthInResidues = calculateWrappedGeometry(availWidth,
605             availHeight);
606
607     av.setWrappedWidth(wrappedWidthInResidues);
608
609     ViewportRanges ranges = av.getRanges();
610     ranges.setViewportStartAndWidth(startColumn, wrappedWidthInResidues);
611
612     // we need to call this again to make sure the startColumn +
613     // wrappedWidthInResidues values are used to calculate wrappedVisibleWidths
614     // correctly.
615     calculateWrappedGeometry(availWidth, availHeight);
616
617     /*
618      * draw one width at a time (excluding any scales shown),
619      * until we have run out of either alignment or vertical space available
620      */
621     int ypos = wrappedSpaceAboveAlignment;
622     int maxWidth = ranges.getVisibleAlignmentWidth();
623
624     int start = startColumn;
625     int currentWidth = 0;
626     while ((currentWidth < wrappedVisibleWidths) && (start < maxWidth))
627     {
628       int endColumn = Math
629               .min(maxWidth, start + wrappedWidthInResidues - 1);
630       drawWrappedWidth(g, ypos, start, endColumn, availHeight);
631       ypos += wrappedRepeatHeightPx;
632       start += wrappedWidthInResidues;
633       currentWidth++;
634     }
635
636     drawWrappedDecorators(g, startColumn);
637   }
638
639   /**
640    * Calculates and saves values needed when rendering a wrapped alignment.
641    * These depend on many factors, including
642    * <ul>
643    * <li>canvas width and height</li>
644    * <li>number of visible sequences, and height of annotations if shown</li>
645    * <li>font and character width</li>
646    * <li>whether scales are shown left, right or above the alignment</li>
647    * </ul>
648    * 
649    * @param availWidth
650    * @param availHeight
651    * @return the number of residue columns in each width
652    */
653   protected int calculateWrappedGeometry(int availWidth, int availHeight)
654   {
655     int charHeight = av.getCharHeight();
656
657     /*
658      * vertical space in pixels between wrapped widths of alignment
659      * - one character height, or two if scale above is drawn
660      */
661     wrappedSpaceAboveAlignment = charHeight
662             * (av.getScaleAboveWrapped() ? 2 : 1);
663
664     /*
665      * compute height in pixels of the wrapped widths
666      * - start with space above plus sequences
667      */
668     wrappedRepeatHeightPx = wrappedSpaceAboveAlignment;
669     wrappedRepeatHeightPx += av.getAlignment().getHeight()
670             * charHeight;
671
672     /*
673      * add annotations panel height if shown
674      * also gap between sequences and annotations
675      */
676     if (av.isShowAnnotation())
677     {
678       wrappedRepeatHeightPx += getAnnotationHeight();
679       wrappedRepeatHeightPx += SEQS_ANNOTATION_GAP; // 3px
680     }
681
682     /*
683      * number of visible widths (the last one may be part height),
684      * ensuring a part height includes at least one sequence
685      */
686     ViewportRanges ranges = av.getRanges();
687     wrappedVisibleWidths = availHeight / wrappedRepeatHeightPx;
688     int remainder = availHeight % wrappedRepeatHeightPx;
689     if (remainder >= (wrappedSpaceAboveAlignment + charHeight))
690     {
691       wrappedVisibleWidths++;
692     }
693
694     /*
695      * compute width in residues; this also sets East and West label widths
696      */
697     int wrappedWidthInResidues = getWrappedCanvasWidth(availWidth);
698
699     /*
700      *  limit visibleWidths to not exceed width of alignment
701      */
702     int xMax = ranges.getVisibleAlignmentWidth();
703     int startToEnd = xMax - ranges.getStartRes();
704     int maxWidths = startToEnd / wrappedWidthInResidues;
705     if (startToEnd % wrappedWidthInResidues > 0)
706     {
707       maxWidths++;
708     }
709     wrappedVisibleWidths = Math.min(wrappedVisibleWidths, maxWidths);
710
711     return wrappedWidthInResidues;
712   }
713
714   /**
715    * Draws one width of a wrapped alignment, including sequences and
716    * annnotations, if shown, but not scales or hidden column markers
717    * 
718    * @param g
719    * @param ypos
720    * @param startColumn
721    * @param endColumn
722    * @param canvasHeight
723    */
724   protected void drawWrappedWidth(Graphics g, final int ypos,
725           final int startColumn, final int endColumn,
726           final int canvasHeight)
727   {
728     ViewportRanges ranges = av.getRanges();
729     int viewportWidth = ranges.getViewportWidth();
730
731     int endx = Math.min(startColumn + viewportWidth - 1, endColumn);
732
733     /*
734      * move right before drawing by the width of the scale left (if any)
735      * plus column offset from left margin (usually zero, but may be non-zero
736      * when fast painting is drawing just a few columns)
737      */
738     int charWidth = av.getCharWidth();
739     int xOffset = labelWidthWest
740             + ((startColumn - ranges.getStartRes()) % viewportWidth)
741             * charWidth;
742
743     g.translate(xOffset, 0);
744
745     /*
746      * white fill the region to be drawn (so incremental fast paint doesn't
747      * scribble over an existing image)
748      */
749     g.setColor(Color.white);
750     g.fillRect(0, ypos, (endx - startColumn + 1) * charWidth,
751             wrappedRepeatHeightPx);
752
753     drawPanel(g, startColumn, endx, 0, av.getAlignment().getHeight() - 1,
754             ypos);
755
756     int cHeight = av.getAlignment().getHeight() * av.getCharHeight();
757
758     if (av.isShowAnnotation())
759     {
760       final int yShift = cHeight + ypos + SEQS_ANNOTATION_GAP;
761       g.translate(0, yShift);
762       if (annotations == null)
763       {
764         annotations = new AnnotationPanel(av);
765       }
766
767       annotations.renderer.drawComponent(annotations, av, g, -1,
768               startColumn, endx + 1);
769       g.translate(0, -yShift);
770     }
771     g.translate(-xOffset, 0);
772   }
773
774   /**
775    * Draws scales left, right and above (if shown), and any hidden column
776    * markers, on all widths of the wrapped alignment
777    * 
778    * @param g
779    * @param startColumn
780    */
781   protected void drawWrappedDecorators(Graphics g, final int startColumn)
782   {
783     int charWidth = av.getCharWidth();
784
785     g.setFont(av.getFont());
786
787     g.setColor(Color.black);
788
789     int ypos = wrappedSpaceAboveAlignment;
790     ViewportRanges ranges = av.getRanges();
791     int viewportWidth = ranges.getViewportWidth();
792     int maxWidth = ranges.getVisibleAlignmentWidth();
793     int widthsDrawn = 0;
794     int startCol = startColumn;
795
796     while (widthsDrawn < wrappedVisibleWidths)
797     {
798       int endColumn = Math.min(maxWidth, startCol + viewportWidth - 1);
799
800       if (av.getScaleLeftWrapped())
801       {
802         drawVerticalScale(g, startCol, endColumn - 1, ypos, true);
803       }
804
805       if (av.getScaleRightWrapped())
806       {
807         int x = labelWidthWest + viewportWidth * charWidth;
808         
809         g.translate(x, 0);
810         drawVerticalScale(g, startCol, endColumn, ypos, false);
811         g.translate(-x, 0);
812       }
813
814       /*
815        * white fill region of scale above and hidden column markers
816        * (to support incremental fast paint of image)
817        */
818       g.translate(labelWidthWest, 0);
819       g.setColor(Color.white);
820       g.fillRect(0, ypos - wrappedSpaceAboveAlignment, viewportWidth
821               * charWidth + labelWidthWest, wrappedSpaceAboveAlignment);
822       g.setColor(Color.black);
823       g.translate(-labelWidthWest, 0);
824
825       g.translate(labelWidthWest, 0);
826
827       if (av.getScaleAboveWrapped())
828       {
829         drawNorthScale(g, startCol, endColumn, ypos);
830       }
831
832       if (av.hasHiddenColumns() && av.getShowHiddenMarkers())
833       {
834         drawHiddenColumnMarkers(g, ypos, startCol, endColumn);
835       }
836
837       g.translate(-labelWidthWest, 0);
838
839       ypos += wrappedRepeatHeightPx;
840       startCol += viewportWidth;
841       widthsDrawn++;
842     }
843   }
844
845   /**
846    * Draws markers (triangles) above hidden column positions between startColumn
847    * and endColumn.
848    * 
849    * @param g
850    * @param ypos
851    * @param startColumn
852    * @param endColumn
853    */
854   protected void drawHiddenColumnMarkers(Graphics g, int ypos,
855           int startColumn, int endColumn)
856   {
857     int charHeight = av.getCharHeight();
858     int charWidth = av.getCharWidth();
859
860     g.setColor(Color.blue);
861     int res;
862     HiddenColumns hidden = av.getAlignment().getHiddenColumns();
863
864     Iterator<Integer> it = hidden.getStartRegionIterator(startColumn,
865             endColumn);
866     while (it.hasNext())
867     {
868       res = it.next() - startColumn;
869
870       if (res < 0 || res > endColumn - startColumn + 1)
871       {
872         continue;
873       }
874
875       /*
876        * draw a downward-pointing triangle at the hidden columns location
877        * (before the following visible column)
878        */
879       int xMiddle = res * charWidth;
880       int[] xPoints = new int[] { xMiddle - charHeight / 4,
881           xMiddle + charHeight / 4, xMiddle };
882       int yTop = ypos - (charHeight / 2);
883       int[] yPoints = new int[] { yTop, yTop, yTop + 8 };
884       g.fillPolygon(xPoints, yPoints, 3);
885     }
886   }
887
888   /*
889    * Draw a selection group over a wrapped alignment
890    */
891   private void drawWrappedSelection(Graphics2D g, SequenceGroup group,
892           int canvasWidth,
893           int canvasHeight, int startRes)
894   {
895     int charHeight = av.getCharHeight();
896     int charWidth = av.getCharWidth();
897       
898     // height gap above each panel
899     int hgap = charHeight;
900     if (av.getScaleAboveWrapped())
901     {
902       hgap += charHeight;
903     }
904
905     int cWidth = (canvasWidth - labelWidthEast - labelWidthWest)
906             / charWidth;
907     int cHeight = av.getAlignment().getHeight() * charHeight;
908
909     int startx = startRes;
910     int endx;
911     int ypos = hgap; // vertical offset
912     int maxwidth = av.getAlignment().getVisibleWidth();
913
914     // chop the wrapped alignment extent up into panel-sized blocks and treat
915     // each block as if it were a block from an unwrapped alignment
916     g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
917             BasicStroke.JOIN_ROUND, 3f, new float[]
918             { 5f, 3f }, 0f));
919     g.setColor(Color.RED);
920     while ((ypos <= canvasHeight) && (startx < maxwidth))
921     {
922       // set end value to be start + width, or maxwidth, whichever is smaller
923       endx = startx + cWidth - 1;
924
925       if (endx > maxwidth)
926       {
927         endx = maxwidth;
928       }
929
930       g.translate(labelWidthWest, 0);
931
932       drawUnwrappedSelection(g, group, startx, endx, 0,
933               av.getAlignment().getHeight() - 1,
934               ypos);
935
936       g.translate(-labelWidthWest, 0);
937
938       // update vertical offset
939       ypos += cHeight + getAnnotationHeight() + hgap;
940
941       // update horizontal offset
942       startx += cWidth;
943     }
944     g.setStroke(new BasicStroke());
945   }
946
947   int getAnnotationHeight()
948   {
949     if (!av.isShowAnnotation())
950     {
951       return 0;
952     }
953
954     if (annotations == null)
955     {
956       annotations = new AnnotationPanel(av);
957     }
958
959     return annotations.adjustPanelHeight();
960   }
961
962   /**
963    * Draws the visible region of the alignment on the graphics context. If there
964    * are hidden column markers in the visible region, then each sub-region
965    * between the markers is drawn separately, followed by the hidden column
966    * marker.
967    * 
968    * @param g1
969    *          the graphics context, positioned at the first residue to be drawn
970    * @param startRes
971    *          offset of the first column to draw (0..)
972    * @param endRes
973    *          offset of the last column to draw (0..)
974    * @param startSeq
975    *          offset of the first sequence to draw (0..)
976    * @param endSeq
977    *          offset of the last sequence to draw (0..)
978    * @param yOffset
979    *          vertical offset at which to draw (for wrapped alignments)
980    */
981   public void drawPanel(Graphics g1, final int startRes, final int endRes,
982           final int startSeq, final int endSeq, final int yOffset)
983   {
984     int charHeight = av.getCharHeight();
985     int charWidth = av.getCharWidth();
986
987     if (!av.hasHiddenColumns())
988     {
989       draw(g1, startRes, endRes, startSeq, endSeq, yOffset);
990     }
991     else
992     {
993       int screenY = 0;
994       int blockStart;
995       int blockEnd;
996
997       HiddenColumns hidden = av.getAlignment().getHiddenColumns();
998       VisibleContigsIterator regions = hidden
999               .getVisContigsIterator(startRes, endRes + 1, true);
1000
1001       while (regions.hasNext())
1002       {
1003         int[] region = regions.next();
1004         blockEnd = region[1];
1005         blockStart = region[0];
1006
1007         /*
1008          * draw up to just before the next hidden region, or the end of
1009          * the visible region, whichever comes first
1010          */
1011         g1.translate(screenY * charWidth, 0);
1012
1013         draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset);
1014
1015         /*
1016          * draw the downline of the hidden column marker (ScalePanel draws the
1017          * triangle on top) if we reached it
1018          */
1019         if (av.getShowHiddenMarkers()
1020                 && (regions.hasNext() || regions.endsAtHidden()))
1021         {
1022           g1.setColor(Color.blue);
1023
1024           g1.drawLine((blockEnd - blockStart + 1) * charWidth - 1,
1025                   0 + yOffset, (blockEnd - blockStart + 1) * charWidth - 1,
1026                   (endSeq - startSeq + 1) * charHeight + yOffset);
1027         }
1028
1029         g1.translate(-screenY * charWidth, 0);
1030         screenY += blockEnd - blockStart + 1;
1031       }
1032     }
1033
1034   }
1035
1036   /**
1037    * Draws a region of the visible alignment
1038    * 
1039    * @param g1
1040    * @param startRes
1041    *          offset of the first column in the visible region (0..)
1042    * @param endRes
1043    *          offset of the last column in the visible region (0..)
1044    * @param startSeq
1045    *          offset of the first sequence in the visible region (0..)
1046    * @param endSeq
1047    *          offset of the last sequence in the visible region (0..)
1048    * @param yOffset
1049    *          vertical offset at which to draw (for wrapped alignments)
1050    */
1051   private void draw(Graphics g, int startRes, int endRes, int startSeq,
1052           int endSeq, int offset)
1053   {
1054     int charHeight = av.getCharHeight();
1055     int charWidth = av.getCharWidth();
1056
1057     g.setFont(av.getFont());
1058     seqRdr.prepare(g, av.isRenderGaps());
1059
1060     SequenceI nextSeq;
1061
1062     // / First draw the sequences
1063     // ///////////////////////////
1064     for (int i = startSeq; i <= endSeq; i++)
1065     {
1066       nextSeq = av.getAlignment().getSequenceAt(i);
1067       if (nextSeq == null)
1068       {
1069         // occasionally, a race condition occurs such that the alignment row is
1070         // empty
1071         continue;
1072       }
1073       seqRdr.drawSequence(nextSeq, av.getAlignment().findAllGroups(nextSeq),
1074               startRes, endRes, offset + ((i - startSeq) * charHeight));
1075
1076       if (av.isShowSequenceFeatures())
1077       {
1078         fr.drawSequence(g, nextSeq, startRes, endRes,
1079                 offset + ((i - startSeq) * charHeight), false);
1080       }
1081
1082       /*
1083        * highlight search Results once sequence has been drawn
1084        */
1085       if (av.hasSearchResults())
1086       {
1087         SearchResultsI searchResults = av.getSearchResults();
1088         int[] visibleResults = searchResults.getResults(nextSeq, startRes,
1089                 endRes);
1090         if (visibleResults != null)
1091         {
1092           for (int r = 0; r < visibleResults.length; r += 2)
1093           {
1094             seqRdr.drawHighlightedText(nextSeq, visibleResults[r],
1095                     visibleResults[r + 1],
1096                     (visibleResults[r] - startRes) * charWidth,
1097                     offset + ((i - startSeq) * charHeight));
1098           }
1099         }
1100       }
1101     }
1102
1103     if (av.getSelectionGroup() != null
1104             || av.getAlignment().getGroups().size() > 0)
1105     {
1106       drawGroupsBoundaries(g, startRes, endRes, startSeq, endSeq, offset);
1107     }
1108
1109   }
1110
1111   /**
1112    * Draws the outlines of any groups defined on the alignment (excluding the
1113    * current selection group, if any)
1114    * 
1115    * @param g1
1116    * @param startRes
1117    * @param endRes
1118    * @param startSeq
1119    * @param endSeq
1120    * @param offset
1121    */
1122   void drawGroupsBoundaries(Graphics g1, int startRes, int endRes,
1123           int startSeq, int endSeq, int offset)
1124   {
1125     Graphics2D g = (Graphics2D) g1;
1126
1127     SequenceGroup group = null;
1128     int groupIndex = -1;
1129
1130     if (av.getAlignment().getGroups().size() > 0)
1131     {
1132       group = av.getAlignment().getGroups().get(0);
1133       groupIndex = 0;
1134     }
1135
1136     if (group != null)
1137     {
1138       do
1139       {
1140         g.setColor(group.getOutlineColour());
1141         drawPartialGroupOutline(g, group, startRes, endRes, startSeq,
1142                 endSeq, offset);
1143
1144         groupIndex++;
1145         if (groupIndex >= av.getAlignment().getGroups().size())
1146         {
1147           break;
1148         }
1149         group = av.getAlignment().getGroups().get(groupIndex);
1150       } while (groupIndex < av.getAlignment().getGroups().size());
1151     }
1152   }
1153
1154   /**
1155    * Draws the outline of the current selection group (if any)
1156    * 
1157    * @param g
1158    * @param startRes
1159    * @param endRes
1160    * @param startSeq
1161    * @param endSeq
1162    */
1163   private void drawSelectionGroup(Graphics2D g, int startRes, int endRes,
1164           int startSeq, int endSeq)
1165   {
1166     SequenceGroup group = av.getSelectionGroup();
1167     if (group == null)
1168     {
1169       return;
1170     }
1171
1172     g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
1173             BasicStroke.JOIN_ROUND, 3f, new float[]
1174             { 5f, 3f }, 0f));
1175     g.setColor(Color.RED);
1176     if (!av.getWrapAlignment())
1177     {
1178       drawUnwrappedSelection(g, group, startRes, endRes, startSeq, endSeq,
1179               0);
1180     }
1181     else
1182     {
1183       drawWrappedSelection(g, group, getWidth(), getHeight(),
1184               av.getRanges().getStartRes());
1185     }
1186     g.setStroke(new BasicStroke());
1187   }
1188
1189   /**
1190    * Draw the cursor as a separate image and overlay
1191    * 
1192    * @param startRes
1193    *          start residue of area to draw cursor in
1194    * @param endRes
1195    *          end residue of area to draw cursor in
1196    * @param startSeq
1197    *          start sequence of area to draw cursor in
1198    * @param endSeq
1199    *          end sequence of are to draw cursor in
1200    * @return a transparent image of the same size as the sequence canvas, with
1201    *         the cursor drawn on it, if any
1202    */
1203   private void drawCursor(Graphics g, int startRes, int endRes,
1204           int startSeq,
1205           int endSeq)
1206   {
1207     // convert the cursorY into a position on the visible alignment
1208     int cursor_ypos = cursorY;
1209
1210     // don't do work unless we have to
1211     if (cursor_ypos >= startSeq && cursor_ypos <= endSeq)
1212     {
1213       int yoffset = 0;
1214       int xoffset = 0;
1215       int startx = startRes;
1216       int endx = endRes;
1217
1218       // convert the cursorX into a position on the visible alignment
1219       int cursor_xpos = av.getAlignment().getHiddenColumns()
1220               .absoluteToVisibleColumn(cursorX);
1221
1222       if (av.getAlignment().getHiddenColumns().isVisible(cursorX))
1223       {
1224
1225         if (av.getWrapAlignment())
1226         {
1227           // work out the correct offsets for the cursor
1228           int charHeight = av.getCharHeight();
1229           int charWidth = av.getCharWidth();
1230           int canvasWidth = getWidth();
1231           int canvasHeight = getHeight();
1232
1233           // height gap above each panel
1234           int hgap = charHeight;
1235           if (av.getScaleAboveWrapped())
1236           {
1237             hgap += charHeight;
1238           }
1239
1240           int cWidth = (canvasWidth - labelWidthEast - labelWidthWest)
1241                   / charWidth;
1242           int cHeight = av.getAlignment().getHeight() * charHeight;
1243
1244           endx = startx + cWidth - 1;
1245           int ypos = hgap; // vertical offset
1246
1247           // iterate down the wrapped panels
1248           while ((ypos <= canvasHeight) && (endx < cursor_xpos))
1249           {
1250             // update vertical offset
1251             ypos += cHeight + getAnnotationHeight() + hgap;
1252
1253             // update horizontal offset
1254             startx += cWidth;
1255             endx = startx + cWidth - 1;
1256           }
1257           yoffset = ypos;
1258           xoffset = labelWidthWest;
1259         }
1260
1261         // now check if cursor is within range for x values
1262         if (cursor_xpos >= startx && cursor_xpos <= endx)
1263         {
1264           // get the character the cursor is drawn at
1265           SequenceI seq = av.getAlignment().getSequenceAt(cursorY);
1266           char s = seq.getCharAt(cursorX);
1267
1268           seqRdr.drawCursor(g, s,
1269                   xoffset + (cursor_xpos - startx) * av.getCharWidth(),
1270                   yoffset + (cursor_ypos - startSeq) * av.getCharHeight());
1271         }
1272       }
1273     }
1274   }
1275
1276
1277   /**
1278    * Draw a selection group over an unwrapped alignment
1279    * 
1280    * @param g
1281    *          graphics object to draw with
1282    * @param group
1283    *          selection group
1284    * @param startRes
1285    *          start residue of area to draw
1286    * @param endRes
1287    *          end residue of area to draw
1288    * @param startSeq
1289    *          start sequence of area to draw
1290    * @param endSeq
1291    *          end sequence of area to draw
1292    * @param offset
1293    *          vertical offset (used when called from wrapped alignment code)
1294    */
1295   private void drawUnwrappedSelection(Graphics2D g, SequenceGroup group,
1296           int startRes, int endRes, int startSeq, int endSeq, int offset)
1297   {
1298     int charWidth = av.getCharWidth();
1299           
1300     if (!av.hasHiddenColumns())
1301     {
1302       drawPartialGroupOutline(g, group, startRes, endRes, startSeq, endSeq,
1303               offset);
1304     }
1305     else
1306     {
1307       // package into blocks of visible columns
1308       int screenY = 0;
1309       int blockStart;
1310       int blockEnd;
1311
1312       HiddenColumns hidden = av.getAlignment().getHiddenColumns();
1313       VisibleContigsIterator regions = hidden
1314               .getVisContigsIterator(startRes, endRes + 1, true);
1315       while (regions.hasNext())
1316       {
1317         int[] region = regions.next();
1318         blockEnd = region[1];
1319         blockStart = region[0];
1320
1321         g.translate(screenY * charWidth, 0);
1322         drawPartialGroupOutline(g, group,
1323                 blockStart, blockEnd, startSeq, endSeq, offset);
1324
1325         g.translate(-screenY * charWidth, 0);
1326         screenY += blockEnd - blockStart + 1;
1327       }
1328     }
1329   }
1330
1331   /**
1332    * Draws part of a selection group outline
1333    * 
1334    * @param g
1335    * @param group
1336    * @param startRes
1337    * @param endRes
1338    * @param startSeq
1339    * @param endSeq
1340    * @param verticalOffset
1341    */
1342   private void drawPartialGroupOutline(Graphics2D g, SequenceGroup group,
1343           int startRes, int endRes, int startSeq, int endSeq,
1344           int verticalOffset)
1345   {
1346     int charHeight = av.getCharHeight();
1347     int charWidth = av.getCharWidth();
1348     int visWidth = (endRes - startRes + 1) * charWidth;
1349
1350     int oldY = -1;
1351     int i = 0;
1352     boolean inGroup = false;
1353     int top = -1;
1354     int bottom = -1;
1355     int sy = -1;
1356
1357     List<SequenceI> seqs = group.getSequences(null);
1358
1359     // position of start residue of group relative to startRes, in pixels
1360     int sx = (group.getStartRes() - startRes) * charWidth;
1361
1362     // width of group in pixels
1363     int xwidth = (((group.getEndRes() + 1) - group.getStartRes())
1364             * charWidth) - 1;
1365
1366     if (!(sx + xwidth < 0 || sx > visWidth))
1367     {
1368       for (i = startSeq; i <= endSeq; i++)
1369       {
1370         sy = verticalOffset + (i - startSeq) * charHeight;
1371
1372         if ((sx <= (endRes - startRes) * charWidth)
1373                 && seqs.contains(av.getAlignment().getSequenceAt(i)))
1374         {
1375           if ((bottom == -1)
1376                   && !seqs.contains(av.getAlignment().getSequenceAt(i + 1)))
1377           {
1378             bottom = sy + charHeight;
1379           }
1380
1381           if (!inGroup)
1382           {
1383             if (((top == -1) && (i == 0)) || !seqs
1384                     .contains(av.getAlignment().getSequenceAt(i - 1)))
1385             {
1386               top = sy;
1387             }
1388
1389             oldY = sy;
1390             inGroup = true;
1391           }
1392         }
1393         else if (inGroup)
1394         {
1395           drawVerticals(g, sx, xwidth, visWidth, oldY, sy);
1396           drawHorizontals(g, sx, xwidth, visWidth, top, bottom);
1397
1398           // reset top and bottom
1399           top = -1;
1400           bottom = -1;
1401           inGroup = false;
1402         }
1403       }
1404       if (inGroup)
1405       {
1406         sy = verticalOffset + ((i - startSeq) * charHeight);
1407         drawVerticals(g, sx, xwidth, visWidth, oldY, sy);
1408         drawHorizontals(g, sx, xwidth, visWidth, top, bottom);
1409       }
1410     }
1411   }
1412
1413   /**
1414    * Draw horizontal selection group boundaries at top and bottom positions
1415    * 
1416    * @param g
1417    *          graphics object to draw on
1418    * @param sx
1419    *          start x position
1420    * @param xwidth
1421    *          width of gap
1422    * @param visWidth
1423    *          visWidth maximum available width
1424    * @param top
1425    *          position to draw top of group at
1426    * @param bottom
1427    *          position to draw bottom of group at
1428    */
1429   private void drawHorizontals(Graphics2D g, int sx, int xwidth,
1430           int visWidth, int top, int bottom)
1431   {
1432     int width = xwidth;
1433     int startx = sx;
1434     if (startx < 0)
1435     {
1436       width += startx;
1437       startx = 0;
1438     }
1439
1440     // don't let width extend beyond current block, or group extent
1441     // fixes JAL-2672
1442     if (startx + width >= visWidth)
1443     {
1444       width = visWidth - startx;
1445     }
1446
1447     if (top != -1)
1448     {
1449       g.drawLine(startx, top, startx + width, top);
1450     }
1451
1452     if (bottom != -1)
1453     {
1454       g.drawLine(startx, bottom - 1, startx + width, bottom - 1);
1455     }
1456   }
1457
1458   /**
1459    * Draw vertical lines at sx and sx+xwidth providing they lie within
1460    * [0,visWidth)
1461    * 
1462    * @param g
1463    *          graphics object to draw on
1464    * @param sx
1465    *          start x position
1466    * @param xwidth
1467    *          width of gap
1468    * @param visWidth
1469    *          visWidth maximum available width
1470    * @param oldY
1471    *          top y value
1472    * @param sy
1473    *          bottom y value
1474    */
1475   private void drawVerticals(Graphics2D g, int sx, int xwidth, int visWidth,
1476           int oldY, int sy)
1477   {
1478     // if start position is visible, draw vertical line to left of
1479     // group
1480     if (sx >= 0 && sx < visWidth)
1481     {
1482       g.drawLine(sx, oldY, sx, sy);
1483     }
1484
1485     // if end position is visible, draw vertical line to right of
1486     // group
1487     if (sx + xwidth < visWidth)
1488     {
1489       g.drawLine(sx + xwidth, oldY, sx + xwidth, sy);
1490     }
1491   }
1492   
1493   /**
1494    * Highlights search results in the visible region by rendering as white text
1495    * on a black background. Any previous highlighting is removed. Answers true
1496    * if any highlight was left on the visible alignment (so status bar should be
1497    * set to match), else false. This method does _not_ set the 'fastPaint' flag,
1498    * so allows the next repaint to update the whole display.
1499    * 
1500    * @param results
1501    * @return
1502    */
1503   public boolean highlightSearchResults(SearchResultsI results)
1504   {
1505     return highlightSearchResults(results, false);
1506
1507   }
1508   
1509   /**
1510    * Highlights search results in the visible region by rendering as white text
1511    * on a black background. Any previous highlighting is removed. Answers true
1512    * if any highlight was left on the visible alignment (so status bar should be
1513    * set to match), else false.
1514    * <p>
1515    * Optionally, set the 'fastPaint' flag for a faster redraw if only the
1516    * highlighted regions are modified. This speeds up highlighting across linked
1517    * alignments.
1518    * <p>
1519    * Currently fastPaint is not implemented for scrolled wrapped alignments. If
1520    * a wrapped alignment had to be scrolled to show the highlighted region, then
1521    * it should be fully redrawn, otherwise a fast paint can be performed. This
1522    * argument could be removed if fast paint of scrolled wrapped alignment is
1523    * coded in future (JAL-2609).
1524    * 
1525    * @param results
1526    * @param doFastPaint
1527    *          if true, sets a flag so the next repaint only redraws the modified
1528    *          image
1529    * @return
1530    */
1531   public boolean highlightSearchResults(SearchResultsI results,
1532           boolean doFastPaint)
1533   {
1534     if (fastpainting)
1535     {
1536       return false;
1537     }
1538     boolean wrapped = av.getWrapAlignment();
1539     try
1540     {
1541       fastPaint = doFastPaint;
1542       fastpainting = fastPaint;
1543
1544       /*
1545        * to avoid redrawing the whole visible region, we instead
1546        * redraw just the minimal regions to remove previous highlights
1547        * and add new ones
1548        */
1549       SearchResultsI previous = av.getSearchResults();
1550       av.setSearchResults(results);
1551       boolean redrawn = false;
1552       boolean drawn = false;
1553       if (wrapped)
1554       {
1555         redrawn = drawMappedPositionsWrapped(previous);
1556         drawn = drawMappedPositionsWrapped(results);
1557         redrawn |= drawn;
1558       }
1559       else
1560       {
1561         redrawn = drawMappedPositions(previous);
1562         drawn = drawMappedPositions(results);
1563         redrawn |= drawn;
1564       }
1565
1566       /*
1567        * if highlights were either removed or added, repaint
1568        */
1569       if (redrawn)
1570       {
1571         repaint();
1572       }
1573
1574       /*
1575        * return true only if highlights were added
1576        */
1577       return drawn;
1578
1579     } finally
1580     {
1581       fastpainting = false;
1582     }
1583   }
1584
1585   /**
1586    * Redraws the minimal rectangle in the visible region (if any) that includes
1587    * mapped positions of the given search results. Whether or not positions are
1588    * highlighted depends on the SearchResults set on the Viewport. This allows
1589    * this method to be called to either clear or set highlighting. Answers true
1590    * if any positions were drawn (in which case a repaint is still required),
1591    * else false.
1592    * 
1593    * @param results
1594    * @return
1595    */
1596   protected boolean drawMappedPositions(SearchResultsI results)
1597   {
1598     if ((results == null) || (img == null)) // JAL-2784 check gg is not null
1599     {
1600       return false;
1601     }
1602
1603     /*
1604      * calculate the minimal rectangle to redraw that 
1605      * includes both new and existing search results
1606      */
1607     int firstSeq = Integer.MAX_VALUE;
1608     int lastSeq = -1;
1609     int firstCol = Integer.MAX_VALUE;
1610     int lastCol = -1;
1611     boolean matchFound = false;
1612
1613     ViewportRanges ranges = av.getRanges();
1614     int firstVisibleColumn = ranges.getStartRes();
1615     int lastVisibleColumn = ranges.getEndRes();
1616     AlignmentI alignment = av.getAlignment();
1617     if (av.hasHiddenColumns())
1618     {
1619       firstVisibleColumn = alignment.getHiddenColumns()
1620               .visibleToAbsoluteColumn(firstVisibleColumn);
1621       lastVisibleColumn = alignment.getHiddenColumns()
1622               .visibleToAbsoluteColumn(lastVisibleColumn);
1623     }
1624
1625     for (int seqNo = ranges.getStartSeq(); seqNo <= ranges
1626             .getEndSeq(); seqNo++)
1627     {
1628       SequenceI seq = alignment.getSequenceAt(seqNo);
1629
1630       int[] visibleResults = results.getResults(seq, firstVisibleColumn,
1631               lastVisibleColumn);
1632       if (visibleResults != null)
1633       {
1634         for (int i = 0; i < visibleResults.length - 1; i += 2)
1635         {
1636           int firstMatchedColumn = visibleResults[i];
1637           int lastMatchedColumn = visibleResults[i + 1];
1638           if (firstMatchedColumn <= lastVisibleColumn
1639                   && lastMatchedColumn >= firstVisibleColumn)
1640           {
1641             /*
1642              * found a search results match in the visible region - 
1643              * remember the first and last sequence matched, and the first
1644              * and last visible columns in the matched positions
1645              */
1646             matchFound = true;
1647             firstSeq = Math.min(firstSeq, seqNo);
1648             lastSeq = Math.max(lastSeq, seqNo);
1649             firstMatchedColumn = Math.max(firstMatchedColumn,
1650                     firstVisibleColumn);
1651             lastMatchedColumn = Math.min(lastMatchedColumn,
1652                     lastVisibleColumn);
1653             firstCol = Math.min(firstCol, firstMatchedColumn);
1654             lastCol = Math.max(lastCol, lastMatchedColumn);
1655           }
1656         }
1657       }
1658     }
1659
1660     if (matchFound)
1661     {
1662       if (av.hasHiddenColumns())
1663       {
1664         firstCol = alignment.getHiddenColumns()
1665                 .absoluteToVisibleColumn(firstCol);
1666         lastCol = alignment.getHiddenColumns().absoluteToVisibleColumn(lastCol);
1667       }
1668       int transX = (firstCol - ranges.getStartRes()) * av.getCharWidth();
1669       int transY = (firstSeq - ranges.getStartSeq()) * av.getCharHeight();
1670       Graphics gg = img.getGraphics();
1671       gg.translate(transX, transY);
1672       drawPanel(gg, firstCol, lastCol, firstSeq, lastSeq, 0);
1673       gg.translate(-transX, -transY);
1674       gg.dispose();
1675     }
1676
1677     return matchFound;
1678   }
1679
1680   @Override
1681   public void propertyChange(PropertyChangeEvent evt)
1682   {
1683     String eventName = evt.getPropertyName();
1684
1685     // BH 2019.07.27 removes dead code introduced in aad3650 and simplifies
1686     // logic, emphasizing no check for ENDRES or ENDSEQ
1687
1688     // Both scrolling and resizing change viewport ranges: scrolling changes
1689     // both start and end points, but resize only changes end values.
1690     // Here we only want to fastpaint on a scroll, with resize using a normal
1691     // paint, so scroll events are identified as changes to the horizontal or
1692     // vertical start value.
1693
1694     // Make sure we're not trying to draw a panel
1695     // larger than the visible window
1696     int scrollX = 0;
1697     int scrollY = 0;
1698     switch (eventName)
1699     {
1700     case SequenceGroup.SEQ_GROUP_CHANGED:
1701       fastPaint = true;
1702       repaint();
1703       return;
1704     case ViewportRanges.MOVE_VIEWPORT:
1705       fastPaint = false;
1706       repaint();
1707       return;
1708     case ViewportRanges.STARTSEQ:
1709       // meaning STARTOREND
1710       // typically scroll, but possibly just the end changed
1711       fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
1712       return;
1713     case ViewportRanges.ENDRES:
1714     case ViewportRanges.ENDSEQ:
1715       // meaning second event along with "START" -- ENDONLY,NOTSTART
1716       // TODO: ignore??
1717       return;
1718     case ViewportRanges.STARTRES:
1719       // meaning STARTOREND
1720       scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
1721       break;
1722     case ViewportRanges.STARTRESANDSEQ:
1723       scrollX = ((int[]) evt.getNewValue())[0]
1724               - ((int[]) evt.getOldValue())[0];
1725       scrollY = ((int[]) evt.getNewValue())[1]
1726               - ((int[]) evt.getOldValue())[1];
1727
1728       // System.out.println("SC dx dy " + scrollX + " " + scrollY);
1729
1730       if (scrollX != 0 && scrollY != 0)
1731       {
1732         // all sorts of problems in JavaScript if this is commented out.
1733         repaint();
1734         return;
1735
1736       }
1737       break;
1738     }
1739
1740     ViewportRanges vpRanges = av.getRanges();
1741     int range = vpRanges.getEndRes() - vpRanges.getStartRes() + 1;
1742     scrollX = Math.max(Math.min(scrollX, range), -range);
1743     // only STARTRES or STARTRESANDSEQ:
1744     if (av.getWrapAlignment())
1745     {
1746       fastPaintWrapped(scrollX);
1747     }
1748     else
1749     {
1750       fastPaint(scrollX, scrollY);
1751     }
1752
1753     // BH 2019.07.27 was:
1754     // if (eventName.equals(SequenceGroup.SEQ_GROUP_CHANGED))
1755     // {
1756     // fastPaint = true;
1757     // repaint();
1758     // return;
1759     // }
1760     // else if (eventName.equals(ViewportRanges.MOVE_VIEWPORT))
1761     // {
1762     // fastPaint = false;
1763     // // System.err.println("!!!! fastPaint false from MOVE_VIEWPORT");
1764     // repaint();
1765     // return;
1766     // }
1767     //
1768     // if (eventName.equals(ViewportRanges.STARTRES)
1769     // || eventName.equals(ViewportRanges.STARTRESANDSEQ))
1770     // {
1771     // // Make sure we're not trying to draw a panel
1772     // // larger than the visible window
1773     // if (eventName.equals(ViewportRanges.STARTRES))
1774     // {
1775     // scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
1776     // }
1777     // else
1778     // {
1779     // scrollX = ((int[]) evt.getNewValue())[0]
1780     // - ((int[]) evt.getOldValue())[0];
1781     // }
1782     // ViewportRanges vpRanges = av.getRanges();
1783     //
1784     // int range = vpRanges.getEndRes() - vpRanges.getStartRes() + 1;
1785     // if (scrollX > range)
1786     // {
1787     // scrollX = range;
1788     // }
1789     // else if (scrollX < -range)
1790     // {
1791     // scrollX = -range;
1792     // }
1793     // }
1794     // Both scrolling and resizing change viewport ranges: scrolling changes
1795     // both start and end points, but resize only changes end values.
1796     // Here we only want to fastpaint on a scroll, with resize using a normal
1797     // paint, so scroll events are identified as changes to the horizontal or
1798     // vertical start value.
1799     // BH 2019.07.27 was:
1800     // if (eventName.equals(ViewportRanges.STARTRES))
1801     // {
1802     // if (av.getWrapAlignment())
1803     // {
1804     // fastPaintWrapped(scrollX);
1805     // }
1806     // else
1807     // {
1808     // fastPaint(scrollX, 0);
1809     // }
1810     // }
1811     // else if (eventName.equals(ViewportRanges.STARTSEQ))
1812     // {
1813     // // scroll
1814     // fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
1815     // }
1816     // else if (eventName.equals(ViewportRanges.STARTRESANDSEQ))
1817     // {
1818     // if (av.getWrapAlignment())
1819     // {
1820     // fastPaintWrapped(scrollX);
1821     // }
1822     // else
1823     // {
1824     // fastPaint(scrollX, 0);
1825     // }
1826     // }
1827     //
1828     // BH oops!
1829     //
1830     // else if (eventName.equals(ViewportRanges.STARTSEQ))
1831     // {
1832     // // scroll
1833     // fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
1834     // }
1835     // else if (eventName.equals(ViewportRanges.STARTRESANDSEQ))
1836     // {
1837     // if (av.getWrapAlignment())
1838     // {
1839     // fastPaintWrapped(scrollX);
1840     // }
1841     // }
1842   }
1843
1844   /**
1845    * Does a minimal update of the image for a scroll movement. This method
1846    * handles scroll movements of up to one width of the wrapped alignment (one
1847    * click in the vertical scrollbar). Larger movements (for example after a
1848    * scroll to highlight a mapped position) trigger a full redraw instead.
1849    * 
1850    * @param scrollX
1851    *          number of positions scrolled (right if positive, left if negative)
1852    */
1853   protected void fastPaintWrapped(int scrollX)
1854   {
1855     ViewportRanges ranges = av.getRanges();
1856
1857     if (Math.abs(scrollX) >= ranges.getViewportWidth())
1858     {
1859       /*
1860        * shift of one view width or more is 
1861        * overcomplicated to handle in this method
1862        */
1863       fastPaint = false;
1864       repaint();
1865       return;
1866     }
1867
1868     if (fastpainting || img == null)
1869     {
1870       return;
1871     }
1872
1873     fastPaint = true;
1874     fastpainting = true;
1875
1876     try
1877     {
1878       
1879       Graphics gg = img.getGraphics();
1880       
1881       calculateWrappedGeometry(getWidth(), getHeight());
1882
1883       /*
1884        * relocate the regions of the alignment that are still visible
1885        */
1886       shiftWrappedAlignment(-scrollX);
1887
1888       /*
1889        * add new columns (sequence, annotation)
1890        * - at top left if scrollX < 0 
1891        * - at right of last two widths if scrollX > 0
1892        */
1893       if (scrollX < 0)
1894       {
1895         int startRes = ranges.getStartRes();
1896         drawWrappedWidth(gg, wrappedSpaceAboveAlignment, startRes, startRes
1897                 - scrollX - 1, getHeight());
1898       }
1899       else
1900       {
1901         fastPaintWrappedAddRight(scrollX);
1902       }
1903
1904       /*
1905        * draw all scales (if  shown) and hidden column markers
1906        */
1907       drawWrappedDecorators(gg, ranges.getStartRes());
1908
1909       gg.dispose();
1910       
1911       repaint();
1912     } finally
1913     {
1914       fastpainting = false;
1915     }
1916   }
1917
1918   /**
1919    * Draws the specified number of columns at the 'end' (bottom right) of a
1920    * wrapped alignment view, including sequences and annotations if shown, but
1921    * not scales. Also draws the same number of columns at the right hand end of
1922    * the second last width shown, if the last width is not full height (so
1923    * cannot simply be copied from the graphics image).
1924    * 
1925    * @param columns
1926    */
1927   protected void fastPaintWrappedAddRight(int columns)
1928   {
1929     if (columns == 0)
1930     {
1931       return;
1932     }
1933
1934     Graphics gg = img.getGraphics();
1935     
1936     ViewportRanges ranges = av.getRanges();
1937     int viewportWidth = ranges.getViewportWidth();
1938     int charWidth = av.getCharWidth();
1939
1940     /**
1941      * draw full height alignment in the second last row, last columns, if the
1942      * last row was not full height
1943      */
1944     int visibleWidths = wrappedVisibleWidths;
1945     int canvasHeight = getHeight();
1946     boolean lastWidthPartHeight = (wrappedVisibleWidths * wrappedRepeatHeightPx) > canvasHeight;
1947
1948     if (lastWidthPartHeight)
1949     {
1950       int widthsAbove = Math.max(0, visibleWidths - 2);
1951       int ypos = wrappedRepeatHeightPx * widthsAbove
1952               + wrappedSpaceAboveAlignment;
1953       int endRes = ranges.getEndRes();
1954       endRes += widthsAbove * viewportWidth;
1955       int startRes = endRes - columns;
1956       int xOffset = ((startRes - ranges.getStartRes()) % viewportWidth)
1957               * charWidth;
1958
1959       /*
1960        * white fill first to erase annotations
1961        */
1962       
1963       
1964       gg.translate(xOffset, 0);
1965       gg.setColor(Color.white);
1966       gg.fillRect(labelWidthWest, ypos,
1967               (endRes - startRes + 1) * charWidth, wrappedRepeatHeightPx);
1968       gg.translate(-xOffset, 0);
1969
1970       drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight);
1971       
1972     }
1973
1974     /*
1975      * draw newly visible columns in last wrapped width (none if we
1976      * have reached the end of the alignment)
1977      * y-offset for drawing last width is height of widths above,
1978      * plus one gap row
1979      */
1980     int widthsAbove = visibleWidths - 1;
1981     int ypos = wrappedRepeatHeightPx * widthsAbove
1982             + wrappedSpaceAboveAlignment;
1983     int endRes = ranges.getEndRes();
1984     endRes += widthsAbove * viewportWidth;
1985     int startRes = endRes - columns + 1;
1986
1987     /*
1988      * white fill first to erase annotations
1989      */
1990     int xOffset = ((startRes - ranges.getStartRes()) % viewportWidth)
1991             * charWidth;
1992     gg.translate(xOffset, 0);
1993     gg.setColor(Color.white);
1994     int width = viewportWidth * charWidth - xOffset;
1995     gg.fillRect(labelWidthWest, ypos, width, wrappedRepeatHeightPx);
1996     gg.translate(-xOffset, 0);
1997
1998     gg.setFont(av.getFont());
1999     gg.setColor(Color.black);
2000
2001     if (startRes < ranges.getVisibleAlignmentWidth())
2002     {
2003       drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight);
2004     }
2005
2006     /*
2007      * and finally, white fill any space below the visible alignment
2008      */
2009     int heightBelow = canvasHeight - visibleWidths * wrappedRepeatHeightPx;
2010     if (heightBelow > 0)
2011     {
2012       gg.setColor(Color.white);
2013       gg.fillRect(0, canvasHeight - heightBelow, getWidth(), heightBelow);
2014     }
2015     gg.dispose();
2016  }
2017
2018   /**
2019    * Shifts the visible alignment by the specified number of columns - left if
2020    * negative, right if positive. Copies and moves sequences and annotations (if
2021    * shown). Scales, hidden column markers and any newly visible columns must be
2022    * drawn separately.
2023    * 
2024    * @param positions
2025    */
2026   protected void shiftWrappedAlignment(int positions)
2027   {
2028     if (positions == 0)
2029     {
2030       return;
2031     }
2032
2033     Graphics gg = img.getGraphics();
2034
2035     int charWidth = av.getCharWidth();
2036
2037     int canvasHeight = getHeight();
2038     ViewportRanges ranges = av.getRanges();
2039     int viewportWidth = ranges.getViewportWidth();
2040     int widthToCopy = (ranges.getViewportWidth() - Math.abs(positions))
2041             * charWidth;
2042     int heightToCopy = wrappedRepeatHeightPx - wrappedSpaceAboveAlignment;
2043     int xMax = ranges.getVisibleAlignmentWidth();
2044
2045     if (positions > 0)
2046     {
2047       /*
2048        * shift right (after scroll left)
2049        * for each wrapped width (starting with the last), copy (width-positions) 
2050        * columns from the left margin to the right margin, and copy positions 
2051        * columns from the right margin of the row above (if any) to the 
2052        * left margin of the current row
2053        */
2054
2055       /*
2056        * get y-offset of last wrapped width, first row of sequences
2057        */
2058       int y = canvasHeight / wrappedRepeatHeightPx * wrappedRepeatHeightPx;
2059       y += wrappedSpaceAboveAlignment;
2060       int copyFromLeftStart = labelWidthWest;
2061       int copyFromRightStart = copyFromLeftStart + widthToCopy;
2062
2063       while (y >= 0)
2064       {
2065         /*
2066          * shift 'widthToCopy' residues by 'positions' places to the right
2067          */
2068         gg.copyArea(copyFromLeftStart, y, widthToCopy, heightToCopy,
2069                 positions * charWidth, 0);
2070         if (y > 0)
2071         {
2072           /*
2073            * copy 'positions' residue from the row above (right hand end)
2074            * to this row's left hand end
2075            */
2076           gg.copyArea(copyFromRightStart, y - wrappedRepeatHeightPx,
2077                   positions * charWidth, heightToCopy, -widthToCopy,
2078                   wrappedRepeatHeightPx);
2079         }
2080
2081         y -= wrappedRepeatHeightPx;
2082       }
2083     }
2084     else
2085     {
2086       /*
2087        * shift left (after scroll right)
2088        * for each wrapped width (starting with the first), copy (width-positions) 
2089        * columns from the right margin to the left margin, and copy positions 
2090        * columns from the left margin of the row below (if any) to the 
2091        * right margin of the current row
2092        */
2093       int xpos = av.getRanges().getStartRes();
2094       int y = wrappedSpaceAboveAlignment;
2095       int copyFromRightStart = labelWidthWest - positions * charWidth;
2096
2097       while (y < canvasHeight)
2098       {
2099         gg.copyArea(copyFromRightStart, y, widthToCopy, heightToCopy,
2100                 positions * charWidth, 0);
2101         if (y + wrappedRepeatHeightPx < canvasHeight - wrappedRepeatHeightPx
2102                 && (xpos + viewportWidth <= xMax))
2103         {
2104           gg.copyArea(labelWidthWest, y + wrappedRepeatHeightPx, -positions
2105                   * charWidth, heightToCopy, widthToCopy,
2106                   -wrappedRepeatHeightPx);
2107         }
2108         y += wrappedRepeatHeightPx;
2109         xpos += viewportWidth;
2110       }
2111     }
2112     gg.dispose();
2113   }
2114
2115   
2116   /**
2117    * Redraws any positions in the search results in the visible region of a
2118    * wrapped alignment. Any highlights are drawn depending on the search results
2119    * set on the Viewport, not the <code>results</code> argument. This allows
2120    * this method to be called either to clear highlights (passing the previous
2121    * search results), or to draw new highlights.
2122    * 
2123    * @param results
2124    * @return
2125    */
2126   protected boolean drawMappedPositionsWrapped(SearchResultsI results)
2127   {
2128     if ((results == null) || (img == null)) // JAL-2784 check gg is not null
2129     {
2130       return false;
2131     }
2132     int charHeight = av.getCharHeight();
2133
2134     boolean matchFound = false;
2135
2136     calculateWrappedGeometry(getWidth(), getHeight());
2137     int wrappedWidth = av.getWrappedWidth();
2138     int wrappedHeight = wrappedRepeatHeightPx;
2139
2140     ViewportRanges ranges = av.getRanges();
2141     int canvasHeight = getHeight();
2142     int repeats = canvasHeight / wrappedHeight;
2143     if (canvasHeight / wrappedHeight > 0)
2144     {
2145       repeats++;
2146     }
2147
2148     int firstVisibleColumn = ranges.getStartRes();
2149     int lastVisibleColumn = ranges.getStartRes() + repeats
2150             * ranges.getViewportWidth() - 1;
2151
2152     AlignmentI alignment = av.getAlignment();
2153     if (av.hasHiddenColumns())
2154     {
2155       firstVisibleColumn = alignment.getHiddenColumns()
2156               .visibleToAbsoluteColumn(firstVisibleColumn);
2157       lastVisibleColumn = alignment.getHiddenColumns()
2158               .visibleToAbsoluteColumn(lastVisibleColumn);
2159     }
2160
2161     int gapHeight = charHeight * (av.getScaleAboveWrapped() ? 2 : 1);
2162
2163     
2164     Graphics gg = img.getGraphics();
2165
2166     for (int seqNo = ranges.getStartSeq(); seqNo <= ranges
2167             .getEndSeq(); seqNo++)
2168     {
2169       SequenceI seq = alignment.getSequenceAt(seqNo);
2170
2171       int[] visibleResults = results.getResults(seq, firstVisibleColumn,
2172               lastVisibleColumn);
2173       if (visibleResults != null)
2174       {
2175         for (int i = 0; i < visibleResults.length - 1; i += 2)
2176         {
2177           int firstMatchedColumn = visibleResults[i];
2178           int lastMatchedColumn = visibleResults[i + 1];
2179           if (firstMatchedColumn <= lastVisibleColumn
2180                   && lastMatchedColumn >= firstVisibleColumn)
2181           {
2182             /*
2183              * found a search results match in the visible region
2184              */
2185             firstMatchedColumn = Math.max(firstMatchedColumn,
2186                     firstVisibleColumn);
2187             lastMatchedColumn = Math.min(lastMatchedColumn,
2188                     lastVisibleColumn);
2189
2190             /*
2191              * draw each mapped position separately (as contiguous positions may
2192              * wrap across lines)
2193              */
2194             for (int mappedPos = firstMatchedColumn; mappedPos <= lastMatchedColumn; mappedPos++)
2195             {
2196               int displayColumn = mappedPos;
2197               if (av.hasHiddenColumns())
2198               {
2199                 displayColumn = alignment.getHiddenColumns()
2200                         .absoluteToVisibleColumn(displayColumn);
2201               }
2202
2203               /*
2204                * transX: offset from left edge of canvas to residue position
2205                */
2206               int transX = labelWidthWest
2207                       + ((displayColumn - ranges.getStartRes()) % wrappedWidth)
2208                       * av.getCharWidth();
2209
2210               /*
2211                * transY: offset from top edge of canvas to residue position
2212                */
2213               int transY = gapHeight;
2214               transY += (displayColumn - ranges.getStartRes())
2215                       / wrappedWidth * wrappedHeight;
2216               transY += (seqNo - ranges.getStartSeq()) * av.getCharHeight();
2217
2218               /*
2219                * yOffset is from graphics origin to start of visible region
2220                */
2221               int yOffset = 0;// (displayColumn / wrappedWidth) * wrappedHeight;
2222               if (transY < getHeight())
2223               {
2224                 matchFound = true;
2225                 gg.translate(transX, transY);
2226                 drawPanel(gg, displayColumn, displayColumn, seqNo, seqNo,
2227                         yOffset);
2228                 gg.translate(-transX, -transY);
2229               }
2230             }
2231           }
2232         }
2233       }
2234     }
2235   
2236     gg.dispose();
2237
2238     return matchFound;
2239   }
2240
2241   /**
2242    * Answers the width in pixels of the left scale labels (0 if not shown)
2243    * 
2244    * @return
2245    */
2246   int getLabelWidthWest()
2247   {
2248     return labelWidthWest;
2249   }
2250
2251 }