From: kiramt Date: Fri, 2 Jun 2017 13:00:13 +0000 (+0100) Subject: JAL-2577 Don't allow viewport ranges below 0. Unit tests updated. X-Git-Tag: Release_2_10_2~3^2~42^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fbug%2FJAL-2577;p=jalview.git JAL-2577 Don't allow viewport ranges below 0. Unit tests updated. --- diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index 743d212..4eb8c95 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -123,7 +123,7 @@ public class ViewportRanges extends ViewportProperties int oldstartres = this.startRes; if (start > getVisibleAlignmentWidth() - 1) { - startRes = getVisibleAlignmentWidth() - 1; + startRes = Math.max(getVisibleAlignmentWidth() - 1, 0); } else if (start < 0) { @@ -141,7 +141,7 @@ public class ViewportRanges extends ViewportProperties } else if (end > getVisibleAlignmentWidth() - 1) { - endRes = getVisibleAlignmentWidth() - 1; + endRes = Math.max(getVisibleAlignmentWidth() - 1, 0); } else { @@ -208,7 +208,7 @@ public class ViewportRanges extends ViewportProperties int oldstartseq = this.startSeq; if (start > getVisibleAlignmentHeight() - 1) { - startSeq = getVisibleAlignmentHeight() - 1; + startSeq = Math.max(getVisibleAlignmentHeight() - 1, 0); } else if (start < 0) { @@ -222,7 +222,7 @@ public class ViewportRanges extends ViewportProperties int oldendseq = this.endSeq; if (end >= getVisibleAlignmentHeight()) { - endSeq = getVisibleAlignmentHeight() - 1; + endSeq = Math.max(getVisibleAlignmentHeight() - 1, 0); } else if (end < 0) { diff --git a/test/jalview/viewmodel/ViewportRangesTest.java b/test/jalview/viewmodel/ViewportRangesTest.java index 80bd4db..3ed02d7 100644 --- a/test/jalview/viewmodel/ViewportRangesTest.java +++ b/test/jalview/viewmodel/ViewportRangesTest.java @@ -31,6 +31,8 @@ public class ViewportRangesTest { ColumnSelection sel = new ColumnSelection(); al.getHiddenColumns().revealAllHiddenColumns(sel); al.getHiddenSequences().showAll(null); + smallAl.getHiddenColumns().revealAllHiddenColumns(sel); + smallAl.getHiddenSequences().showAll(null); } @Test(groups = { "Functional" }) @@ -133,6 +135,12 @@ public class ViewportRangesTest { ViewportRanges vrsmall = new ViewportRanges(smallAl); vrsmall.setStartEndRes(al.getWidth(), al.getWidth()); assertEquals(vrsmall.getEndRes(), 6); + + // make visible alignment width = 0 + smallAl.getHiddenColumns().hideColumns(0, 6); + vrsmall.setStartEndRes(0, 4); + assertEquals(vrsmall.getStartRes(), 0); + assertEquals(vrsmall.getEndRes(), 0); } @Test(groups = { "Functional" }) @@ -149,6 +157,14 @@ public class ViewportRangesTest { vr.setStartEndSeq(al.getHeight(), al.getHeight()); assertEquals(vr.getEndSeq(), al.getHeight() - 1); + + // make visible alignment height = 0 + smallAl.getHiddenSequences().hideSequence(smallAl.getSequenceAt(0)); + smallAl.getHiddenSequences().hideSequence(smallAl.getSequenceAt(0)); + ViewportRanges vrsmall = new ViewportRanges(smallAl); + vrsmall.setStartEndSeq(0, 3); + assertEquals(vrsmall.getStartSeq(), 0); + assertEquals(vrsmall.getEndSeq(), 0); } @Test(groups = { "Functional" })