JAL-1858 fast paint wrapped highlights unless view was scrolled
[jalview.git] / src / jalview / gui / SeqCanvas.java
index 6099897..47ef7cf 100755 (executable)
@@ -1000,18 +1000,33 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
    * on a black background. Any previous highlighting is removed. Answers true
    * if any highlight was left on the visible alignment (so status bar should be
    * set to match), else false.
+   * <p>
+   * Currently fastPaint is not implemented for wrapped alignments. If a wrapped
+   * alignment had to be scrolled to show the highlighted region, then it should
+   * be fully redrawn, otherwise a fast paint can be performed. This argument
+   * could be removed if fast paint of scrolled wrapped alignment is coded in
+   * future (JAL-2609).
    * 
    * @param results
+   * @param noFastPaint
    * @return
    */
-  public boolean highlightSearchResults(SearchResultsI results)
+  public boolean highlightSearchResults(SearchResultsI results,
+          boolean noFastPaint)
   {
-    updateViewport();
-
+    if (fastpainting)
+    {
+      return false;
+    }
     boolean wrapped = av.getWrapAlignment();
 
     try
     {
+      fastPaint = !noFastPaint;
+      fastpainting = fastPaint;
+
+      updateViewport();
+
       /*
        * to avoid redrawing the whole visible region, we instead
        * redraw just the minimal regions to remove previous highlights
@@ -1051,7 +1066,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
     {
       fastpainting = false;
     }
-
   }
 
   /**
@@ -1214,8 +1228,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
 
     ViewportRanges ranges = av.getRanges();
     int canvasHeight = getHeight();
-    int repeats = wrappedHeight / canvasHeight;
-    if (wrappedHeight % canvasHeight > 0)
+    int repeats = canvasHeight / wrappedHeight;
+    if (canvasHeight / wrappedHeight > 0)
     {
       repeats++;
     }
@@ -1283,7 +1297,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
                * transY: offset from top edge of canvas to residue position
                */
               int transY = gapHeight;
-              transY += (displayColumn / wrappedWidth) * wrappedHeight;
+              transY += (displayColumn - ranges.getStartRes())
+                      / wrappedWidth * wrappedHeight;
               transY += (seqNo - ranges.getStartSeq()) * av.getCharHeight();
 
               /*