JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / gui / SeqPanel.java
index 2df55ad..134e284 100644 (file)
@@ -74,7 +74,8 @@ import javax.swing.Timer;
 import javax.swing.ToolTipManager;
 
 /**
- * DOCUMENT ME!
+ * The main scrollable region containing the alignment and just to the right of
+ * the IDPanel.
  * 
  * @author $author$
  * @version $Revision: 1.130 $
@@ -134,7 +135,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;
     }
 
@@ -224,7 +224,7 @@ public class SeqPanel extends JPanel
   SearchResultsI lastSearchResults;
 
   /**
-   * Creates a new SeqPanel object
+   * Create a new SeqPanel.
    * 
    * @param viewport
    * @param alignPanel
@@ -1504,7 +1504,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))
       {
@@ -1944,12 +1943,21 @@ public class SeqPanel extends JPanel
   {
     lastMousePosition = null;
     ap.alignFrame.setStatus(" ");
+
     if (av.getWrapAlignment())
     {
       return;
     }
 
-    if (mouseDragging && scrollThread == null)
+    /*
+     * start scrolling if mouse dragging, whether the drag started
+     * in the scale panel or this panel
+     */
+    if (ap.getScalePanel().isMouseDragging())
+    {
+      ap.getScalePanel().mouseExited(e);
+    }
+    else if (mouseDragging && scrollThread == null)
     {
       startScrolling(e.getPoint());
     }
@@ -2424,29 +2432,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)
             {
               // SeqPanel.stopScrolling called
-              t.stop();
+              ((Timer) e.getSource()).stop();
             }
           }
         });
         t.start();
       }
-    }
-    else
-    {
-      /*
-       * Java - run in a new thread
-       */
-      scrollThread.start();
+      else
+      {
+        /*
+         * Java - run in a new thread
+         */
+        scrollThread.start();
+      }
     }
   }
 
@@ -2770,4 +2771,45 @@ public class SeqPanel extends JPanel
   {
     return lastSearchResults;
   }
+
+  /**
+   * scroll to the given row/column - or nearest visible location
+   * 
+   * @param row
+   * @param column
+   */
+  public void scrollTo(int row, int column)
+  {
+
+    row = row < 0 ? ap.av.getRanges().getStartSeq() : row;
+    column = column < 0 ? ap.av.getRanges().getStartRes() : column;
+    ap.scrollTo(column, column, row, true, true);
+  }
+
+  /**
+   * scroll to the given row - or nearest visible location
+   * 
+   * @param row
+   */
+  public void scrollToRow(int row)
+  {
+
+    row = row < 0 ? ap.av.getRanges().getStartSeq() : row;
+    ap.scrollTo(ap.av.getRanges().getStartRes(),
+            ap.av.getRanges().getStartRes(), row, true, true);
+  }
+
+  /**
+   * scroll to the given column - or nearest visible location
+   * 
+   * @param column
+   */
+  public void scrollToColumn(int column)
+  {
+
+    column = column < 0 ? ap.av.getRanges().getStartRes() : column;
+    ap.scrollTo(column, column, ap.av.getRanges().getStartSeq(), true,
+            true);
+  }
+
 }