JAL-3345 JAL3253 Smoother ScalePanel-based scrolling
[jalview.git] / src / jalview / gui / SeqPanel.java
index 546838d..26ec081 100644 (file)
@@ -134,7 +134,6 @@ public class SeqPanel extends JPanel
       MousePos o = (MousePos) obj;
       boolean b = (column == o.column && seqIndex == o.seqIndex
               && annotationIndex == o.annotationIndex);
-      // System.out.println(obj + (b ? "= " : "!= ") + this);
       return b;
     }
 
@@ -321,8 +320,10 @@ public class SeqPanel extends JPanel
     }
     else
     {
-      seqIndex = Math.min((y / charHeight) + av.getRanges().getStartSeq(),
+      ViewportRanges ranges = av.getRanges();
+      seqIndex = Math.min((y / charHeight) + ranges.getStartSeq(),
               alignmentHeight - 1);
+      seqIndex = Math.min(seqIndex, ranges.getEndSeq());
     }
 
     return new MousePos(col, seqIndex, annIndex);
@@ -1502,7 +1503,6 @@ public class SeqPanel extends JPanel
         return;
       }
 
-      // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
       // Selection spans a hidden region
       if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
       {
@@ -1940,12 +1940,17 @@ public class SeqPanel extends JPanel
   @Override
   public void mouseExited(MouseEvent e)
   {
+    if (ap.getScalePanel().isMouseDragging())
+    {
+      ap.getScalePanel().mouseExited(e);
+      return;
+    }
+    lastMousePosition = null;
     ap.alignFrame.setStatus(" ");
     if (av.getWrapAlignment())
     {
       return;
     }
-
     if (mouseDragging && scrollThread == null)
     {
       startScrolling(e.getPoint());
@@ -2405,33 +2410,12 @@ public class SeqPanel extends JPanel
     {
       scrollThread = new ScrollThread();
       scrollThread.setMousePosition(mousePos);
-      if (!Platform.isJS())
-      {
-        /*
-         * Java - run in a new thread
-         */
-        scrollThread.start();
-      }
-      else
+      if (Platform.isJS())
       {
         /*
          * Javascript - run every 20ms until scrolling stopped
          * or reaches the limit of scrollable alignment
          */
-        // java.util.Timer version:
-        // Timer t = new Timer("ScrollThreadTimer", true);
-        // TimerTask task = new TimerTask()
-        // {
-        // @Override
-        // public void run()
-        // {
-        // if (!scrollThread.scrollOnce())
-        // {
-        // cancel();
-        // }
-        // }
-        // };
-        // t.schedule(task, 20, 20);
         Timer t = new Timer(20, new ActionListener()
         {
           @Override
@@ -2442,22 +2426,22 @@ public class SeqPanel extends JPanel
               // if (!scrollOnce() {t.stop();}) gives compiler error :-(
               scrollThread.scrollOnce();
             }
-          }
-        });
-        t.addActionListener(new ActionListener()
-        {
-          @Override
-          public void actionPerformed(ActionEvent e)
-          {
             if (scrollThread == null)
             {
-              // finished and nulled itself
-              t.stop();
+              // SeqPanel.stopScrolling called
+              ((Timer) e.getSource()).stop();
             }
           }
         });
         t.start();
       }
+      else
+      {
+        /*
+         * Java - run in a new thread
+         */
+        scrollThread.start();
+      }
     }
   }