Merge branch 'develop' into features/JAL-2446NCList
[jalview.git] / src / jalview / gui / SeqCanvas.java
index 6099897..d4b3e73 100755 (executable)
@@ -146,9 +146,9 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
         {
           g.drawString(mstring, mpos * charWidth, ypos - (charHeight / 2));
         }
-        g.drawLine((mpos * charWidth) + (charWidth / 2), (ypos + 2)
-                - (charHeight / 2), (mpos * charWidth) + (charWidth / 2),
-                ypos - 2);
+        g.drawLine((mpos * charWidth) + (charWidth / 2),
+                (ypos + 2) - (charHeight / 2),
+                (mpos * charWidth) + (charWidth / 2), ypos - 2);
       }
     }
   }
@@ -210,8 +210,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
       {
         int x = labelWidthWest - fm.stringWidth(String.valueOf(value))
                 - charWidth / 2;
-        g.drawString(value + "", x, (ypos + (i * charHeight))
-                - (charHeight / 5));
+        g.drawString(value + "", x,
+                (ypos + (i * charHeight)) - (charHeight / 5));
       }
     }
   }
@@ -262,8 +262,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
 
       if (value != -1)
       {
-        g.drawString(String.valueOf(value), 0, (ypos + (i * charHeight))
-                - (charHeight / 5));
+        g.drawString(String.valueOf(value), 0,
+                (ypos + (i * charHeight)) - (charHeight / 5));
       }
     }
   }
@@ -348,10 +348,9 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
     // img and call later.
     super.paintComponent(g);
 
-    if (lcimg != null
-            && (fastPaint
-                    || (getVisibleRect().width != g.getClipBounds().width) || (getVisibleRect().height != g
-                    .getClipBounds().height)))
+    if (lcimg != null && (fastPaint
+            || (getVisibleRect().width != g.getClipBounds().width)
+            || (getVisibleRect().height != g.getClipBounds().height)))
     {
       g.drawImage(lcimg, 0, 0, this);
       fastPaint = false;
@@ -512,16 +511,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();
@@ -573,10 +572,12 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
           }
 
           gg.fillPolygon(
-                  new int[] { res * charWidth - charHeight / 4,
+                  new int[]
+                  { res * charWidth - charHeight / 4,
                       res * charWidth + charHeight / 4, res * charWidth },
-                  new int[] { ypos - (charHeight / 2),
-                      ypos - (charHeight / 2), ypos - (charHeight / 2) + 8 },
+                  new int[]
+                  { ypos - (charHeight / 2), ypos - (charHeight / 2),
+                      ypos - (charHeight / 2) + 8 },
                   3);
 
         }
@@ -606,8 +607,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
           annotations = new AnnotationPanel(av);
         }
 
-        annotations.renderer.drawComponent(annotations, av, g, -1,
-                startRes, endx + 1);
+        annotations.renderer.drawComponent(annotations, av, g, -1, startRes,
+                endx + 1);
         g.translate(0, -cHeight - ypos - 3);
       }
       g.setClip(clip);
@@ -768,8 +769,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
 
       if (av.isShowSequenceFeatures())
       {
-        fr.drawSequence(g, nextSeq, startRes, endRes, offset
-                + ((i - startSeq) * charHeight), false);
+        fr.drawSequence(g, nextSeq, startRes, endRes,
+                offset + ((i - startSeq) * charHeight), false);
       }
 
       /*
@@ -785,9 +786,9 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
           for (int r = 0; r < visibleResults.length; r += 2)
           {
             sr.drawHighlightedText(nextSeq, visibleResults[r],
-                    visibleResults[r + 1], (visibleResults[r] - startRes)
-                            * charWidth, offset
-                            + ((i - startSeq) * charHeight));
+                    visibleResults[r + 1],
+                    (visibleResults[r] - startRes) * charWidth,
+                    offset + ((i - startSeq) * charHeight));
           }
         }
       }
@@ -844,7 +845,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
         {
           sx = (group.getStartRes() - startRes) * charWidth;
           sy = offset + ((i - startSeq) * charHeight);
-          ex = (((group.getEndRes() + 1) - group.getStartRes()) * charWidth) - 1;
+          ex = (((group.getEndRes() + 1) - group.getStartRes()) * charWidth)
+                  - 1;
 
           if (sx + ex < 0 || sx > visWidth)
           {
@@ -852,21 +854,19 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
           }
 
           if ((sx <= (endRes - startRes) * charWidth)
-                  && group.getSequences(null).contains(
-                          av.getAlignment().getSequenceAt(i)))
+                  && group.getSequences(null)
+                          .contains(av.getAlignment().getSequenceAt(i)))
           {
-            if ((bottom == -1)
-                    && !group.getSequences(null).contains(
-                            av.getAlignment().getSequenceAt(i + 1)))
+            if ((bottom == -1) && !group.getSequences(null)
+                    .contains(av.getAlignment().getSequenceAt(i + 1)))
             {
               bottom = sy + charHeight;
             }
 
             if (!inGroup)
             {
-              if (((top == -1) && (i == 0))
-                      || !group.getSequences(null).contains(
-                              av.getAlignment().getSequenceAt(i - 1)))
+              if (((top == -1) && (i == 0)) || !group.getSequences(null)
+                      .contains(av.getAlignment().getSequenceAt(i - 1)))
               {
                 top = sy;
               }
@@ -877,8 +877,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
               if (group == av.getSelectionGroup())
               {
                 g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
-                        BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f },
-                        0f));
+                        BasicStroke.JOIN_ROUND, 3f, new float[]
+                        { 5f, 3f }, 0f));
                 g.setColor(Color.RED);
               }
               else
@@ -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();
 
               /*