JAL-3074 don't scroll up/down on drag out of scale or annotation panel, performance...
[jalview.git] / src / jalview / gui / ScalePanel.java
index e6bba02..ea4b42b 100755 (executable)
@@ -35,6 +35,7 @@ import java.awt.Color;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
+import java.awt.Point;
 import java.awt.RenderingHints;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -275,6 +276,7 @@ public class ScalePanel extends JPanel
   public void mouseReleased(MouseEvent evt)
   {
     mouseDragging = false;
+    ap.getSeqPanel().stopScrolling();
 
     int res = (evt.getX() / av.getCharWidth())
             + av.getRanges().getStartRes();
@@ -285,10 +287,7 @@ public class ScalePanel extends JPanel
               .visibleToAbsoluteColumn(res);
     }
 
-    if (res >= av.getAlignment().getWidth())
-    {
-      res = av.getAlignment().getWidth() - 1;
-    }
+    res = Math.min(res, av.getAlignment().getWidth() - 1);
 
     if (!stretchingGroup)
     {
@@ -356,16 +355,22 @@ public class ScalePanel extends JPanel
   {
     if (mouseDragging)
     {
-      ap.getSeqPanel().scrollCanvas(null);
+      ap.getSeqPanel().stopScrolling();
     }
   }
 
+  /**
+   * Action on leaving the panel bounds with mouse drag in progress is to start
+   * scrolling the alignment in the direction of the mouse. To restrict
+   * scrolling to left-right (not up-down), the y-value of the mouse position is
+   * replaced with zero.
+   */
   @Override
   public void mouseExited(MouseEvent evt)
   {
     if (mouseDragging)
     {
-      ap.getSeqPanel().scrollCanvas(evt);
+      ap.getSeqPanel().startScrolling(new Point(evt.getX(), 0));
     }
   }