From: kiramt Date: Tue, 14 Nov 2017 19:36:53 +0000 (+0000) Subject: JAL-2831 tidies and tests X-Git-Tag: Release_2_10_3b1~28^2~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8e820dadfebf0ced59476338df0fa391590f5401;p=jalview.git JAL-2831 tidies and tests --- diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index e463cc3..0cc8d7c 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -563,7 +563,7 @@ public class ViewportRanges extends ViewportProperties * Calculate wrapped start residue from visible start residue * * @param res - * absolute start residue + * visible start residue * @return left column of panel res will be located in */ private int calcWrappedStartResidue(int res) @@ -571,11 +571,6 @@ public class ViewportRanges extends ViewportProperties int oldStartRes = startRes; int width = getViewportWidth(); - /*if (res >= oldStartRes && res < oldStartRes + width) - { - return false; - }*/ - boolean up = res < oldStartRes; int widthsToScroll = Math.abs((res - oldStartRes) / width); if (up) @@ -633,15 +628,15 @@ public class ViewportRanges extends ViewportProperties * Set the viewport location so that a position is visible * * @param x - * column to be visible + * column to be visible: absolute position in alignment * @param y - * row to be visible + * row to be visible: absolute position in alignment */ public boolean setViewportLocation(int x, int y) { boolean changedLocation = false; - // convert the x,y location to absolute values + // convert the x,y location to visible coordinates int visX = al.getHiddenColumns().findColumnPosition(x); int visY = al.getHiddenSequences().findIndexWithoutHiddenSeqs(y); @@ -660,18 +655,22 @@ public class ViewportRanges extends ViewportProperties else { // set the viewport x location to contain vis_x + int newstartres = visX; int width = getViewportWidth(); - updateStartEndRes(visX, visX + width - 1); + if (newstartres + width - 1 > getVisibleAlignmentWidth() - 1) + { + newstartres = getVisibleAlignmentWidth() - width; + } + updateStartEndRes(newstartres, newstartres + width - 1); // set the viewport y location to contain vis_y - int startseq = visY; + int newstartseq = visY; int height = getViewportHeight(); - if (startseq + height - 1 > getVisibleAlignmentHeight() - 1) + if (newstartseq + height - 1 > getVisibleAlignmentHeight() - 1) { - startseq = getVisibleAlignmentHeight() - height; + newstartseq = getVisibleAlignmentHeight() - height; } - updateStartEndSeq(startseq, - startseq + height - 1); + updateStartEndSeq(newstartseq, newstartseq + height - 1); newresseq = new int[] { startRes, startSeq }; } diff --git a/test/jalview/viewmodel/ViewportRangesTest.java b/test/jalview/viewmodel/ViewportRangesTest.java index af2424d..41a313f 100644 --- a/test/jalview/viewmodel/ViewportRangesTest.java +++ b/test/jalview/viewmodel/ViewportRangesTest.java @@ -402,14 +402,13 @@ public class ViewportRangesTest { assertEquals(vr.getEndRes(), 52); } - // leave until JAL-2388 is merged and we can do without viewport - /*@Test(groups = { "Functional" }) + @Test(groups = { "Functional" }) public void testScrollToVisible() { ViewportRanges vr = new ViewportRanges(al); vr.setViewportStartAndWidth(12,5); vr.setViewportStartAndHeight(10,6); - vr.scrollToVisible(13,14) + vr.scrollToVisible(13, 14); // no change assertEquals(vr.getStartRes(), 12); @@ -420,7 +419,15 @@ public class ViewportRangesTest { assertEquals(vr.getStartSeq(), 6); // test for hidden columns too - }*/ + al.getHiddenColumns().hideColumns(1, 3); + vr.scrollToVisible(13, 3); + assertEquals(vr.getStartRes(), 6); + assertEquals(vr.getStartSeq(), 3); + + vr.scrollToVisible(2, 9); + assertEquals(vr.getStartRes(), 0); + assertEquals(vr.getStartSeq(), 4); + } @Test(groups = { "Functional" }) public void testEventFiring() @@ -853,6 +860,76 @@ public class ViewportRangesTest { assertEquals(vr.getStartSeq(), 1); assertEquals(vr.getStartRes(), 43); } + + @Test(groups = { "Functional" }) + public void testSetViewportLocation() + { + AlignmentI al2 = gen.generate(60, 80, 1, 0, 0); + + ViewportRanges vr = new ViewportRanges(al2); + + // start with viewport on 5-14 + vr.setViewportStartAndWidth(5, 10); + assertEquals(vr.getStartRes(), 5); + assertEquals(vr.getEndRes(), 14); + + vr.setViewportStartAndHeight(3, 13); + assertEquals(vr.getStartSeq(), 3); + assertEquals(vr.getEndSeq(), 15); + + // set location to (8,5) - no change + vr.setViewportLocation(8, 5); + assertEquals(vr.getStartRes(), 5); + assertEquals(vr.getEndRes(), 14); + assertEquals(vr.getStartSeq(), 3); + assertEquals(vr.getEndSeq(), 15); + + // set location to (40,50) - change to top left (40,50) + vr.setViewportLocation(40, 50); + assertEquals(vr.getStartRes(), 40); + assertEquals(vr.getEndRes(), 49); + assertEquals(vr.getStartSeq(), 50); + assertEquals(vr.getEndSeq(), 62); + + // set location past end of alignment - resets to leftmost pos + vr.setViewportLocation(63, 85); + assertEquals(vr.getStartRes(), 50); + assertEquals(vr.getEndRes(), 59); + assertEquals(vr.getStartSeq(), 67); + assertEquals(vr.getEndSeq(), 79); + + // hide some columns + al2.getHiddenColumns().hideColumns(20, 50); + vr.setViewportLocation(55, 4); + assertEquals(vr.getStartRes(), 19); + assertEquals(vr.getEndRes(), 28); + assertEquals(vr.getStartSeq(), 4); + assertEquals(vr.getEndSeq(), 16); + + // hide some sequences + al2.getHiddenSequences().hideSequence(al2.getSequenceAt(3)); + al2.getHiddenSequences().hideSequence(al2.getSequenceAt(4)); + vr.setViewportLocation(17, 5); + assertEquals(vr.getStartRes(), 17); + assertEquals(vr.getEndRes(), 26); + assertEquals(vr.getStartSeq(), 3); + assertEquals(vr.getEndSeq(), 15); + + // set wrapped mode + vr.setWrappedMode(true); + vr.setViewportLocation(1, 8); + assertEquals(vr.getStartRes(), 0); + assertEquals(vr.getEndRes(), 9); + assertEquals(vr.getStartSeq(), 3); + assertEquals(vr.getEndSeq(), 15); + + // try further down the alignment + vr.setViewportLocation(57, 5); + assertEquals(vr.getStartRes(), 20); + assertEquals(vr.getEndRes(), 29); + assertEquals(vr.getStartSeq(), 3); + assertEquals(vr.getEndSeq(), 15); + } } // mock listener for property change events