JAL-147 improved wrapped scrolling (including Overview) with
[jalview.git] / src / jalview / appletgui / AlignmentPanel.java
index c3458f9..6826c4c 100644 (file)
@@ -407,7 +407,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
       {
         int offset = (vpRanges.getEndRes() - vpRanges.getStartRes() + 1) / 2 - 1;
         start = Math.max(start - offset, 0);
-        end = Math.min(end + offset, seq.getEnd() - 1);
+        end = end + offset - 1;
+        // end = Math.min(end + offset, seq.getEnd() - 1);
       }
 
       if (start < 0)
@@ -436,11 +437,12 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
     int start = -1;
     if (av.hasHiddenColumns())
     {
-      start = av.getColumnSelection().findColumnPosition(ostart);
-      end = av.getColumnSelection().findColumnPosition(end);
+      AlignmentI al = av.getAlignment();
+      start = al.getHiddenColumns().findColumnPosition(ostart);
+      end = al.getHiddenColumns().findColumnPosition(end);
       if (start == end)
       {
-        if (!scrollToNearest && !av.getColumnSelection().isVisible(ostart))
+        if (!scrollToNearest && !al.getHiddenColumns().isVisible(ostart))
         {
           // don't scroll - position isn't visible
           return false;
@@ -673,21 +675,24 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
 
   int vextent = 0;
 
-  public void setScrollValues(int x, int y)
+  public void setScrollValues(int xpos, int ypos)
   {
+    int x = xpos;
+    int y = ypos;
+
     if (av.getWrapAlignment())
     {
       setScrollingForWrappedPanel(x);
     }
     else
     {
-
       int width = av.getAlignment().getWidth();
       int height = av.getAlignment().getHeight();
 
       if (av.hasHiddenColumns())
       {
-        width = av.getColumnSelection().findColumnPosition(width);
+        width = av.getAlignment().getHiddenColumns()
+                .findColumnPosition(width);
       }
       if (x < 0)
       {
@@ -742,9 +747,20 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
     }
   }
 
+  /**
+   * Respond to adjustment event when horizontal or vertical scrollbar is
+   * changed
+   * 
+   * @param evt
+   *          adjustment event encoding whether apvscroll, hscroll or vscroll
+   *          changed
+   */
   @Override
   public void adjustmentValueChanged(AdjustmentEvent evt)
   {
+    // Note that this event is NOT fired by the AWT scrollbar when setValues is
+    // called. Instead manually call adjustHorizontal and adjustVertical
+    // directly.
     if (evt == null || evt.getSource() == apvscroll)
     {
       annotationPanel.setScrollOffset(apvscroll.getValue(), false);
@@ -801,13 +817,17 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
       // if we're scrolling to the position we're already at, stop
       // this prevents infinite recursion of events when the scroll/viewport
       // ranges values are the same
-      if ((offy * rowSize == oldX) && (oldwidth == rowSize))
+      int newX = offy * rowSize;
+      newX += oldX % rowSize; // horizontal scroll offset if any
+      if ((newX == oldX) && (oldwidth == rowSize))
       {
         return;
       }
       else if (offy > -1)
       {
-        vpRanges.setViewportStartAndWidth(offy * rowSize, rowSize);
+        // limit page up/down to one width's worth of positions
+        newX = newX > oldX ? oldX + rowSize : oldX - rowSize;
+        vpRanges.setViewportStartAndWidth(newX, rowSize);
       }
     }
     else
@@ -896,8 +916,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
      * Scroll to position but centring the target residue. Also set a state flag
      * to prevent adjustmentValueChanged performing this recursively.
      */
-    // setFollowingComplementScroll(true);
-    // this should be scrollToPosition(sr,verticalOffset,
     scrollToPosition(sr, seqOffset, true, true);
   }
 
@@ -979,7 +997,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
     int maxwidth = av.getAlignment().getWidth();
     if (av.hasHiddenColumns())
     {
-      maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
+      maxwidth = av.getAlignment().getHiddenColumns()
+              .findColumnPosition(maxwidth) - 1;
     }
 
     // get the width of the canvas in residues
@@ -1138,6 +1157,11 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
     this.scrollComplementaryPanel = b;
   }
 
+  /**
+   * Get whether to scroll complement panel
+   * 
+   * @return true if cDNA/protein complement panels should be scrolled
+   */
   protected boolean isSetToScrollComplementPanel()
   {
     return this.scrollComplementaryPanel;