Merge branch 'develop' into features/JAL-2446NCList
[jalview.git] / src / jalview / gui / SeqCanvas.java
index 6099897..0e31246 100755 (executable)
@@ -512,16 +512,16 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
 
     av.setWrappedWidth(cWidth);
 
-    av.getRanges().setEndRes(av.getRanges().getStartRes() + cWidth - 1);
+    av.getRanges().setViewportStartAndWidth(startRes, cWidth);
 
     int endx;
     int ypos = hgap;
-    int maxwidth = av.getAlignment().getWidth() - 1;
+    int maxwidth = av.getAlignment().getWidth();
 
     if (av.hasHiddenColumns())
     {
       maxwidth = av.getAlignment().getHiddenColumns()
-              .findColumnPosition(maxwidth) - 1;
+              .findColumnPosition(maxwidth);
     }
 
     int annotationHeight = getAnnotationHeight();
@@ -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;
     }
-
   }
 
   /**
@@ -1152,7 +1166,14 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
   {
     String eventName = evt.getPropertyName();
 
-    if (!av.getWrapAlignment())
+    if (av.getWrapAlignment())
+    {
+      if (eventName.equals(ViewportRanges.STARTRES))
+      {
+        repaint();
+      }
+    }
+    else
     {
       int scrollX = 0;
       if (eventName.equals(ViewportRanges.STARTRES))
@@ -1214,8 +1235,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 +1304,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();
 
               /*