From 607cd66d3ccb056b773d9c32271ebf08e06a451c Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 30 May 2017 19:28:42 +0100 Subject: [PATCH] JAL-2573 Fixes for alignment < viewport width, and similarly height --- src/jalview/gui/AlignmentPanel.java | 3 ++- src/jalview/viewmodel/ViewportRanges.java | 18 ++++++++++---- test/jalview/viewmodel/ViewportRangesTest.java | 30 +++++++++++++++++------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index ce9e989..395f6b3 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -416,7 +416,8 @@ public class AlignmentPanel extends GAlignmentPanel implements */ if (centre) { - int offset = (vpRanges.getEndRes() - vpRanges.getStartRes() + 1) / 2 - 1; + int offset = (vpRanges.getEndRes() - vpRanges.getStartRes() + 1) / 2 + - 1; start = Math.max(start - offset, 0); end = end + offset - 1; } diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index 56c1d39..743d212 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -139,6 +139,10 @@ public class ViewportRanges extends ViewportProperties { endRes = 0; } + else if (end > getVisibleAlignmentWidth() - 1) + { + endRes = getVisibleAlignmentWidth() - 1; + } else { endRes = end; @@ -326,9 +330,12 @@ public class ViewportRanges extends ViewportProperties { vpstart = 0; } - else if (vpstart + w - 1 > getVisibleAlignmentWidth() - 1) + else if ((w <= getVisibleAlignmentWidth()) + && (vpstart + w - 1 > getVisibleAlignmentWidth() - 1)) + // viewport width is less than the full alignment and we are running off the + // RHS edge { - vpstart = getVisibleAlignmentWidth() - 1; + vpstart = getVisibleAlignmentWidth() - w; } setStartEndRes(vpstart, vpstart + w - 1); } @@ -350,7 +357,10 @@ public class ViewportRanges extends ViewportProperties { vpstart = 0; } - else if (vpstart + h - 1 > getVisibleAlignmentHeight() - 1) + else if ((h <= getVisibleAlignmentHeight()) + && (vpstart + h - 1 > getVisibleAlignmentHeight() - 1)) + // viewport height is less than the full alignment and we are running off + // the bottom { vpstart = getVisibleAlignmentHeight() - h; } @@ -429,7 +439,7 @@ public class ViewportRanges extends ViewportProperties } else { - if (endRes > getVisibleAlignmentWidth() - 1) + if (endRes >= getVisibleAlignmentWidth() - 1) { return false; } diff --git a/test/jalview/viewmodel/ViewportRangesTest.java b/test/jalview/viewmodel/ViewportRangesTest.java index 9c0d41b..80bd4db 100644 --- a/test/jalview/viewmodel/ViewportRangesTest.java +++ b/test/jalview/viewmodel/ViewportRangesTest.java @@ -23,6 +23,8 @@ public class ViewportRangesTest { AlignmentI al = gen.generate(20, 30, 1, 5, 5); + AlignmentI smallAl = gen.generate(7, 2, 2, 5, 5); + @BeforeMethod public void cleanUp() { @@ -126,7 +128,11 @@ public class ViewportRangesTest { assertEquals(vr.getEndRes(), 19); vr.setStartEndRes(al.getWidth(), al.getWidth()); - assertEquals(vr.getEndRes(), al.getWidth()); + assertEquals(vr.getEndRes(), al.getWidth() - 1); + + ViewportRanges vrsmall = new ViewportRanges(smallAl); + vrsmall.setStartEndRes(al.getWidth(), al.getWidth()); + assertEquals(vrsmall.getEndRes(), 6); } @Test(groups = { "Functional" }) @@ -196,7 +202,13 @@ public class ViewportRangesTest { // reset out of bounds start values to within bounds vr.setViewportStartAndWidth(35, 5); assertEquals(vr.getViewportWidth(), 5); - assertEquals(vr.getStartRes(), 20); + assertEquals(vr.getStartRes(), 16); + + // small alignment doesn't get bounds reset + ViewportRanges vrsmall = new ViewportRanges(smallAl); + vrsmall.setViewportStartAndWidth(0, 63); + assertEquals(vrsmall.getViewportWidth(), 7); + assertEquals(vrsmall.getStartRes(), 0); } @Test(groups = { "Functional" }) @@ -283,12 +295,12 @@ public class ViewportRangesTest { vr.scrollRight(false); assertEquals(vr.getStartRes(), 0); - vr.setViewportStartAndWidth(19, 5); + vr.setViewportStartAndWidth(15, 5); vr.scrollRight(true); - assertEquals(vr.getStartRes(), 20); + assertEquals(vr.getStartRes(), 16); // can't scroll right past end vr.scrollRight(true); - assertEquals(vr.getStartRes(), 20); + assertEquals(vr.getStartRes(), 16); } @Test(groups = { "Functional" }) @@ -298,7 +310,7 @@ public class ViewportRangesTest { // hide last 2 columns HiddenColumns cols = new HiddenColumns(); - cols.hideColumns(18, 19); + cols.hideColumns(19, 20); al.setHiddenColumns(cols); vr.setViewportStartAndWidth(1, 5); @@ -308,12 +320,12 @@ public class ViewportRangesTest { vr.scrollRight(false); assertEquals(vr.getStartRes(), 0); - vr.setViewportStartAndWidth(19, 5); + vr.setViewportStartAndWidth(13, 5); vr.scrollRight(true); - assertEquals(vr.getStartRes(), 18); + assertEquals(vr.getStartRes(), 14); // can't scroll right past last visible col vr.scrollRight(true); - assertEquals(vr.getStartRes(), 18); + assertEquals(vr.getStartRes(), 14); } @Test(groups = { "Functional" }) -- 1.7.10.2