JAL-147 ViewportRanges calculate wrapped vertical scroll position
[jalview.git] / src / jalview / viewmodel / ViewportRanges.java
index f290ae7..36e598f 100644 (file)
@@ -577,4 +577,35 @@ public class ViewportRanges extends ViewportProperties
   {
     wrappedMode = wrapped;
   }
+
+  /**
+   * Answers the vertical scroll position (0..) to set, given the visible column
+   * that is at top left. Note that if called with the total visible width of
+   * the alignment, this gives the maximum cursor scroll value.
+   * 
+   * <pre>
+   * Example:
+   *    viewport width 40 columns (0-39, 40-79, 80-119...)
+   *    column 0 returns scroll position 0
+   *    columns 0-40 return scroll position 1
+   *    columns 41-80 return scroll position 2
+   *    etc
+   * </pre>
+   * 
+   * @param topLeftColumn
+   *          (0..)
+   * @return
+   */
+  public int getWrappedScrollPosition(final int topLeftColumn)
+  {
+    int w = getViewportWidth();
+
+    /*
+     * visible whole widths
+     */
+    int scroll = topLeftColumn / w;
+    scroll += topLeftColumn % w > 0 ? 1 : 0;
+
+    return scroll;
+  }
 }