X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FViewportRanges.java;h=24ff57f46861e3ffed3004250946f89b97892260;hb=0ebfeaf22a68a4c2760ef6980d68ede56ad40eb3;hp=10cf583d032a71f4aff9f29c44c44d56d3e8136d;hpb=e54df488cd82761bfb0e9372aeae2acc5a1324d7;p=jalview.git diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index 10cf583..24ff57f 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -402,23 +402,39 @@ public class ViewportRanges extends ViewportProperties */ public boolean scrollUp(boolean up) { + /* + * if in unwrapped mode, scroll up or down one sequence row; + * if in wrapped mode, scroll by one visible width of columns + */ if (up) { - if (startSeq < 1) + if (wrappedMode) { - return false; + pageUp(); + } + else + { + if (startSeq < 1) + { + return false; + } + setStartSeq(startSeq - 1); } - - setStartSeq(startSeq - 1); } else { - if (endSeq >= getVisibleAlignmentHeight() - 1) + if (wrappedMode) { - return false; + pageDown(); + } + else + { + if (endSeq >= getVisibleAlignmentHeight() - 1) + { + return false; + } + setStartSeq(startSeq + 1); } - - setStartSeq(startSeq + 1); } return true; } @@ -456,18 +472,42 @@ public class ViewportRanges extends ViewportProperties } /** - * Scroll a wrapped alignment so that the specified residue is visible. Fires - * a property change event. + * Scroll a wrapped alignment so that the specified residue is in the first + * repeat of the wrapped view. Fires a property change event. Answers true if + * the startRes changed, else false. * * @param res * residue position to scroll to + * @return */ - public void scrollToWrappedVisible(int res) + public boolean scrollToWrappedVisible(int res) { - // get the start residue of the wrapped row which res is in - // and set that as our start residue + int oldStartRes = startRes; int width = getViewportWidth(); - setStartRes((res / width) * width); + + if (res >= oldStartRes && res < oldStartRes + width) + { + return false; + } + + boolean up = res < oldStartRes; + int widthsToScroll = Math.abs((res - oldStartRes) / width); + if (up) + { + widthsToScroll++; + } + + int residuesToScroll = width * widthsToScroll; + int newStartRes = up ? oldStartRes - residuesToScroll : oldStartRes + + residuesToScroll; + if (newStartRes < 0) + { + newStartRes = 0; + } + + setStartRes(newStartRes); + + return true; } /** @@ -505,7 +545,7 @@ public class ViewportRanges extends ViewportProperties } } } - + /** * Adjust sequence position for page up. Fires a property change event. */ @@ -521,7 +561,7 @@ public class ViewportRanges extends ViewportProperties getViewportHeight()); } } - + /** * Adjust sequence position for page down. Fires a property change event. */