JAL-2600 updates following review
[jalview.git] / src / jalview / gui / SeqCanvas.java
index 1625c52..d8b3f2a 100755 (executable)
@@ -286,8 +286,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
     fastpainting = true;
     fastPaint = true;
     updateViewport();
-    gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth,
-            imgHeight, -horizontal * charWidth, -vertical * charHeight);
 
     ViewportRanges ranges = av.getRanges();
     int sr = ranges.getStartRes();
@@ -297,6 +295,9 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
     int transX = 0;
     int transY = 0;
 
+    gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth,
+            imgHeight, -horizontal * charWidth, -vertical * charHeight);
+
     if (horizontal > 0) // scrollbar pulled right, image to the left
     {
       transX = (er - sr - horizontal) * charWidth;
@@ -987,15 +988,17 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
   @Override
   public void propertyChange(PropertyChangeEvent evt)
   {
+    String eventName = evt.getPropertyName();
+
     if (!av.getWrapAlignment())
     {
-      if (evt.getPropertyName().equals("startres")
-              || evt.getPropertyName().equals("endres"))
+      int scrollX = 0;
+      if (eventName.equals(ViewportRanges.STARTRES))
       {
         // Make sure we're not trying to draw a panel
         // larger than the visible window
         ViewportRanges vpRanges = av.getRanges();
-        int scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
+        scrollX = (int) evt.getNewValue() - (int) evt.getOldValue();
         if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes())
         {
           scrollX = vpRanges.getEndRes() - vpRanges.getStartRes();
@@ -1004,11 +1007,21 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
         {
           scrollX = vpRanges.getStartRes() - vpRanges.getEndRes();
         }
+      }
+
+      // Both scrolling and resizing change viewport ranges: scrolling changes
+      // both start and end points, but resize only changes end values.
+      // Here we only want to fastpaint on a scroll, with resize using a normal
+      // paint, so scroll events are identified as changes to the horizontal or
+      // vertical start value.
+      if (eventName.equals(ViewportRanges.STARTRES))
+      {
+        // scroll - startres and endres both change
         fastPaint(scrollX, 0);
       }
-      else if (evt.getPropertyName().equals("startseq")
-              || evt.getPropertyName().equals("endseq"))
+      else if (eventName.equals(ViewportRanges.STARTSEQ))
       {
+        // scroll
         fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
       }
     }