Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index 15adafc..93af6ec 100755 (executable)
@@ -734,6 +734,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
        */
         return;
       }
+
     try
     {
       if (dragMode == DragMode.Resize)
@@ -1006,7 +1007,6 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   }
 
   private volatile boolean imageFresh = false;
-
   private Rectangle visibleRect = new Rectangle(),
           clipBounds = new Rectangle();
 
@@ -1019,7 +1019,6 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   @Override
   public void paintComponent(Graphics g)
   {
-
     // BH: note that this method is generally recommended to
     // call super.paintComponent(g). Otherwise, the children of this
     // component will not be rendered. That is not needed here
@@ -1027,7 +1026,6 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     // just a JPanel contained in a JViewPort.
 
     computeVisibleRect(visibleRect);
-
     g.setColor(Color.white);
     g.fillRect(0, 0, visibleRect.width, visibleRect.height);
 
@@ -1041,15 +1039,15 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
                       .getClipBounds(clipBounds)).width)
               || (visibleRect.height != clipBounds.height))
       {
-        g.drawImage(image, 0, 0, this);
+
+         
+         g.drawImage(image, 0, 0, this);
         fastPaint = false;
         return;
       }
     }
-
     imgWidth = (ranges.getEndRes() - ranges.getStartRes() + 1)
             * av.getCharWidth();
-
     if (imgWidth < 1)
     {
       fastPaint = false;
@@ -1097,8 +1095,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       gg = (Graphics2D) image.getGraphics();
 
     }
-
-    drawComponent(gg, ranges.getStartRes(), av.getRanges().getEndRes() + 1);
+    
+    drawComponent(gg, av.getRanges().getStartRes(),
+            av.getRanges().getEndRes() + 1);
     gg.dispose();
     imageFresh = false;
     g.drawImage(image, 0, 0, this);
@@ -1130,20 +1129,22 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       fastPaint = false;
       return;
     }
-
     Graphics2D gg = (Graphics2D) image.getGraphics();
 
-    gg.copyArea(0, 0, imgWidth, getHeight(),
-            -horizontal * av.getCharWidth(), 0);
-
-    if (horizontal > 0) // scrollbar pulled right, image to the left
-    {
-      transX = (er - sr - horizontal) * av.getCharWidth();
-      sr = er - horizontal;
-    }
-    else if (horizontal < 0)
-    {
-      er = sr - horizontal;
+    if (imgWidth>Math.abs(horizontal*av.getCharWidth())) {
+      //scroll is less than imgWidth away so can re-use buffered graphics
+      gg.copyArea(0, 0, imgWidth, getHeight(),
+              -horizontal * av.getCharWidth(), 0);
+      
+      if (horizontal > 0) // scrollbar pulled right, image to the left
+      {
+        transX = (er - sr - horizontal) * av.getCharWidth();
+        sr = er - horizontal;
+      }
+      else if (horizontal < 0)
+      {
+        er = sr - horizontal;
+      }
     }
 
     gg.translate(transX, 0);
@@ -1153,7 +1154,6 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     gg.translate(-transX, 0);
 
     gg.dispose();
-
     fastPaint = true;
 
     // Call repaint on alignment panel so that repaints from other alignment
@@ -1272,7 +1272,6 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   private int[] bounds = new int[2];
 
   private boolean allowFastPaint;
-
   @Override
   public int[] getVisibleVRange()
   {
@@ -1388,5 +1387,4 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   {
     allowFastPaint = false;
   }
-
 }