X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fviewmodel%2FViewportRanges.java;h=10cf583d032a71f4aff9f29c44c44d56d3e8136d;hb=ddbcb3e33e1a8d4c644472cfa3d28b193da97064;hp=abbc24ce54475f3dcb4a895f427372a58272ad67;hpb=0ad8259c1d61d8397e1722238f2295e5d4089875;p=jalview.git diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index abbc24c..10cf583 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -135,9 +135,10 @@ public class ViewportRanges extends ViewportProperties /* * if not wrapped, don't leave white space at the right margin */ - if (!wrappedMode && (start > getVisibleAlignmentWidth() - 1)) + int lastColumn = getVisibleAlignmentWidth() - 1; + if (!wrappedMode && (start > lastColumn)) { - startRes = Math.max(getVisibleAlignmentWidth() - 1, 0); + startRes = Math.max(lastColumn, 0); } else if (start < 0) { @@ -153,9 +154,9 @@ public class ViewportRanges extends ViewportProperties { endRes = 0; } - else if (!wrappedMode && (end > getVisibleAlignmentWidth() - 1)) + else if (!wrappedMode && (end > lastColumn)) { - endRes = Math.max(getVisibleAlignmentWidth() - 1, 0); + endRes = Math.max(lastColumn, 0); } else { @@ -172,30 +173,6 @@ public class ViewportRanges extends ViewportProperties } /** - * Set last residue visible in the viewport. Fires a property change event. - * - * @param res - * residue position - */ - public void setEndRes(int res) - { - int startres = res; - int width = getViewportWidth(); - - /* - * if not wrapped, don't leave white space at the right margin - */ - if (!wrappedMode) - { - if (startres + width - 1 > getVisibleAlignmentWidth() - 1) - { - startres = getVisibleAlignmentWidth() - width; - } - } - setStartEndRes(startres - width + 1, startres); - } - - /** * Set the first sequence visible in the viewport, maintaining the height. If * the viewport would extend past the last sequence, sets the viewport so it * sits at the bottom of the alignment. Fires a property change event. @@ -579,16 +556,20 @@ public class ViewportRanges extends ViewportProperties wrappedMode = wrapped; } + public boolean isWrappedMode() + { + return wrappedMode; + } + /** * 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. + * that is at top left. * *
    * 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 1-40 return scroll position 1
    *    columns 41-80 return scroll position 2
    *    etc
    * 
@@ -605,8 +586,35 @@ public class ViewportRanges extends ViewportProperties * visible whole widths */ int scroll = topLeftColumn / w; + + /* + * add 1 for a part width if there is one + */ scroll += topLeftColumn % w > 0 ? 1 : 0; return scroll; } + + /** + * Answers the maximum wrapped vertical scroll value, given the column + * position (0..) to show at top left of the visible region. + * + * @param topLeftColumn + * @return + */ + public int getWrappedMaxScroll(int topLeftColumn) + { + int scrollPosition = getWrappedScrollPosition(topLeftColumn); + + /* + * how many more widths could be drawn after this one? + */ + int columnsRemaining = getVisibleAlignmentWidth() - topLeftColumn; + int width = getViewportWidth(); + int widthsRemaining = columnsRemaining / width + + (columnsRemaining % width > 0 ? 1 : 0) - 1; + int maxScroll = scrollPosition + widthsRemaining; + + return maxScroll; + } }