JAL-3451 JalviewJS embedded mode not resizing
[jalview.git] / src / jalview / gui / SeqCanvas.java
index 2d83e9e..5165aea 100755 (executable)
@@ -75,7 +75,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
 
   private final SequenceRenderer seqRdr;
 
-  boolean fastPaint = false;
+  private boolean fastPaint = false;
 
   private boolean fastpainting = false;
 
@@ -371,7 +371,10 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
   @Override
   public void paintComponent(Graphics g)
   {
-
+    if (av.getAlignPanel().getHoldRepaint())
+    {
+      return;
+    }
     int charHeight = av.getCharHeight();
     int charWidth = av.getCharWidth();
 
@@ -381,8 +384,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     availWidth -= (availWidth % charWidth);
     availHeight -= (availHeight % charHeight);
 
-    // BH 2019 can't possibly fastPaint if either width or height is 0
-
     if (availWidth == 0 || availHeight == 0)
     {
       return;
@@ -394,28 +395,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     int endRes = ranges.getEndRes();
     int endSeq = ranges.getEndSeq();
 
-    // [JAL-3226] problem that JavaScript (or Java) may consolidate multiple
-    // repaint() requests in unpredictable ways. In this case, the issue was
-    // that in response to a CTRL-C/CTRL-V paste request, in Java a fast
-    // repaint request preceded two full requests, thus resulting
-    // in a full request for paint. In constrast, in JavaScript, the three
-    // requests were bundled together into one, so the fastPaint flag was
-    // still present for the second and third request.
-    //
-    // This resulted in incomplete painting.
-    //
-    // The solution was to set seqCanvas.fastPaint and idCanvas.fastPaint false
-    // in PaintRefresher when the target to be painted is one of those two
-    // components.
-    //
-    // BH 2019.04.22
-    //
-    // An initial idea; can be removed once we determine this issue is closed:
-    // if (av.isFastPaintDisabled())
-    // {
-    // fastPaint = false;
-    // }
-
     Rectangle vis, clip;
     if (img != null
             && (fastPaint
@@ -523,16 +502,16 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
 
   /**
    * Using the current font, determine fields labelWidthEast and labelWidthWest,
-   * and return the number of residues that can fill the remaining width.
+   * and return the number of residues that can fill the remaining width
    * 
-   * @param width
+   * @param w
    *          the width in pixels (possibly including scales)
    * 
    * @return the visible width in residues, after allowing for East or West
    *         scales (if shown)
    * 
    */
-  public int getWrappedCanvasWidth(int width)
+  public int getWrappedCanvasWidth(int w)
   {
     int charWidth = av.getCharWidth();
 
@@ -546,7 +525,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
 
     labelWidthWest = av.getScaleLeftWrapped() ? labelWidth : 0;
 
-    return (width - labelWidthEast - labelWidthWest) / charWidth;
+    return (w - labelWidthEast - labelWidthWest) / charWidth;
   }
 
   /**
@@ -1690,6 +1669,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     // Make sure we're not trying to draw a panel
     // larger than the visible window
     int scrollX = 0;
+    int scrollY = 0;
     switch (eventName)
     {
     case SequenceGroup.SEQ_GROUP_CHANGED:
@@ -1705,11 +1685,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
       // typically scroll, but possibly just the end changed
       fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
       return;
-    case ViewportRanges.ENDRES:
-    case ViewportRanges.ENDSEQ:
-      // meaning second event along with "START" -- ENDONLY,NOTSTART
-      // TODO: ignore??
-      return;
     case ViewportRanges.STARTRES:
       // meaning STARTOREND
       scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
@@ -1717,8 +1692,23 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     case ViewportRanges.STARTRESANDSEQ:
       scrollX = ((int[]) evt.getNewValue())[0]
               - ((int[]) evt.getOldValue())[0];
+      scrollY = ((int[]) evt.getNewValue())[1]
+              - ((int[]) evt.getOldValue())[1];
+
+      // System.out.println("SC dx dy " + scrollX + " " + scrollY);
+
+      if (scrollX != 0 && scrollY != 0)
+      {
+        // all sorts of problems in JavaScript if this is commented out.
+        repaint();
+        return;
+
+      }
       break;
+    default:
+      return;
     }
+
     ViewportRanges vpRanges = av.getRanges();
     int range = vpRanges.getEndRes() - vpRanges.getStartRes() + 1;
     scrollX = Math.max(Math.min(scrollX, range), -range);
@@ -1729,7 +1719,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     }
     else
     {
-      fastPaint(scrollX, 0);
+      fastPaint(scrollX, scrollY);
     }
 
     // BH 2019.07.27 was:
@@ -2230,4 +2220,13 @@ public class SeqCanvas extends JPanel implements ViewportListenerI
     return labelWidthWest;
   }
 
+  /**
+   * Clears the flag that allows a 'fast paint' on the next repaint, so
+   * requiring a full repaint
+   */
+  public void setNoFastPaint()
+  {
+    fastPaint = false;
+  }
+
 }