Merge branch 'JAL-3878_ws-overhaul-3' into with_ws_overhaul-3
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index 9dfad08..93af6ec 100755 (executable)
@@ -637,6 +637,10 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     mouseDragLastX = -1;
     mouseDragLastY = -1;
     mouseDragging = false;
+    if (dragMode == DragMode.Resize)
+    {
+      ap.adjustAnnotationHeight();
+    }
     dragMode = DragMode.Undefined;
     ap.getScalePanel().mouseReleased(evt);
 
@@ -677,16 +681,25 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   }
 
   /**
-   * DOCUMENT ME!
+   * Action on starting or continuing a mouse drag. There are two possible
+   * actions:
+   * <ul>
+   * <li>drag up or down on a graphed annotation increases or decreases the
+   * height of the graph</li>
+   * <li>dragging left or right selects the columns dragged across</li>
+   * </ul>
+   * A drag on a graph annotation is treated as column selection if it starts
+   * with more horizontal than vertical movement, and as resize if it starts
+   * with more vertical than horizontal movement. Once started, the drag does
+   * not change mode.
    * 
    * @param evt
-   *          DOCUMENT ME!
    */
   @Override
   public void mouseDragged(MouseEvent evt)
   {
     /*
-     * todo: if dragMode is Undefined:
+     * if dragMode is Undefined:
      * - set to Select if dx > dy
      * - set to Resize if dy > dx
      * - do nothing if dx == dy
@@ -721,6 +734,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
        */
         return;
       }
+
     try
     {
       if (dragMode == DragMode.Resize)
@@ -993,7 +1007,6 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   }
 
   private volatile boolean imageFresh = false;
-
   private Rectangle visibleRect = new Rectangle(),
           clipBounds = new Rectangle();
 
@@ -1006,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
@@ -1014,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);
 
@@ -1028,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;
@@ -1084,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);
@@ -1117,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);
@@ -1140,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
@@ -1259,7 +1272,6 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   private int[] bounds = new int[2];
 
   private boolean allowFastPaint;
-
   @Override
   public int[] getVisibleVRange()
   {
@@ -1375,5 +1387,4 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
   {
     allowFastPaint = false;
   }
-
 }