X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fviewmodel%2FOverviewDimensionsShowHiddenTest.java;h=b890e48352f8c640d9439d3a46d74270a51177b2;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;hp=8297159e2f6bf770872f9f736cc4b21a95967812;hpb=460c037bef9ec113c2a46010c443d85e73347592;p=jalview.git diff --git a/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java b/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java index 8297159..b890e48 100644 --- a/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java @@ -21,6 +21,8 @@ package jalview.viewmodel; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; import jalview.analysis.AlignmentGenerator; import jalview.datamodel.Alignment; @@ -43,19 +45,25 @@ import org.testng.annotations.Test; public class OverviewDimensionsShowHiddenTest { AlignmentI al; + OverviewDimensionsShowHidden od; // cached widths and heights int boxWidth; + int boxHeight; + int viewHeight; + int viewWidth; + int alheight; + int alwidth; ViewportRanges vpranges; - Hashtable hiddenRepSequences = new Hashtable(); + Hashtable hiddenRepSequences = new Hashtable<>(); HiddenColumns hiddenCols = new HiddenColumns(); @@ -76,12 +84,10 @@ public class OverviewDimensionsShowHiddenTest } ColumnSelection colsel = new ColumnSelection(); hiddenCols.revealAllHiddenColumns(colsel); - + vpranges = new ViewportRanges(al); - vpranges.setStartRes(0); - vpranges.setEndRes(62); - vpranges.setStartSeq(0); - vpranges.setEndSeq(17); + vpranges.setViewportStartAndHeight(0, 18); + vpranges.setViewportStartAndWidth(0, 63); viewHeight = vpranges.getEndSeq() - vpranges.getStartSeq() + 1; viewWidth = vpranges.getEndRes() - vpranges.getStartRes() + 1; @@ -99,12 +105,12 @@ public class OverviewDimensionsShowHiddenTest alheight = vpranges.getAbsoluteAlignmentHeight(); alwidth = vpranges.getAbsoluteAlignmentWidth(); - boxWidth = Math.round((float) (vpranges.getEndRes() - - vpranges.getStartRes() + 1) - * od.getWidth() / alwidth); - boxHeight = Math.round((float) (vpranges.getEndSeq() - - vpranges.getStartSeq() + 1) - * od.getSequencesHeight() / alheight); + boxWidth = Math.round( + (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1) + * od.getWidth() / alwidth); + boxHeight = Math.round( + (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1) + * od.getSequencesHeight() / alheight); } @AfterClass(alwaysRun = true) @@ -203,89 +209,85 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // negative boxX value reset to 0 mouseClick(od, -5, 10); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollRow(), + assertEquals(vpranges.getStartSeq() + vpranges.getViewportHeight() / 2, Math.round((float) 10 * alheight / od.getSequencesHeight())); - assertEquals(od.getScrollCol(), 0); + assertEquals(vpranges.getStartRes(), 0); // negative boxY value reset to 0 mouseClick(od, 6, -2); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), - Math.round((float) 6 * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // overly large boxX value reset to width-boxWidth - mouseClick(od, 100, 6); + mouseClick(od, 101, 6); assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); - assertEquals(od.getBoxY(), 6); + assertEquals(od.getBoxY(), 1); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), - Math.round((float) od.getBoxY() * alheight - / od.getSequencesHeight())); + assertEquals(vpranges.getStartSeq(), Math.round( + (float) od.getBoxY() * alheight / od.getSequencesHeight())); // overly large boxY value reset to sequenceHeight - boxHeight mouseClick(od, 10, 520); - assertEquals(od.getBoxX(), 10); + assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight()); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(0, Math.round((float) od.getBoxX() * alwidth / od.getWidth())); // here (float) od.getBoxY() * alheight / od.getSequencesHeight() = 507.5 // and round rounds to 508; however we get 507 working with row values // hence the subtraction of 1 - assertEquals(od.getScrollRow(), - Math.round((float) od.getBoxY() * alheight - / od.getSequencesHeight()) - 1); + assertEquals(vpranges.getStartSeq(), Math.round( + (float) od.getBoxY() * alheight / od.getSequencesHeight()) - 1); // click past end of alignment, as above mouseClick(od, 3000, 5); assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), - Math.round((float) od.getBoxY() * alheight - / od.getSequencesHeight())); + assertEquals(vpranges.getStartSeq(), Math.round( + (float) od.getBoxY() * alheight / od.getSequencesHeight())); // move viewport so startRes non-zero and then mouseclick - moveViewportH(50); + moveViewportH(20); // click at viewport position int oldboxx = od.getBoxX(); int oldboxy = od.getBoxY(); - mouseClick(od, od.getBoxX() + 5, od.getBoxY() + 2); - assertEquals(od.getBoxX(), oldboxx + 5); + mouseClick(od, od.getBoxX() + od.getBoxWidth() / 2 + 6, + od.getBoxY() + od.getBoxHeight() / 2 + 3); + assertEquals(od.getBoxX(), oldboxx + 6); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getBoxY(), oldboxy + 2); - assertEquals(od.getScrollRow(), - Math.round((float) od.getBoxY() * alheight - / od.getSequencesHeight())); + assertEquals(od.getBoxY(), oldboxy + 3); + assertEquals(vpranges.getStartSeq(), Math.round( + (float) od.getBoxY() * alheight / od.getSequencesHeight())); // click at top corner mouseClick(od, 0, 0); assertEquals(od.getBoxX(), 0); - assertEquals(od.getScrollCol(), 0); + assertEquals(vpranges.getStartRes(), 0); assertEquals(od.getBoxY(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartSeq(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); } @@ -301,8 +303,8 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // hide cols at start and check updated box position is correct // changes boxX but not boxwidth @@ -310,30 +312,31 @@ public class OverviewDimensionsShowHiddenTest hiddenCols.hideColumns(0, lastHiddenCol); od.setBoxPosition(al.getHiddenSequences(), hiddenCols); - assertEquals(od.getBoxX(), - Math.round((float) (lastHiddenCol + 1) * od.getWidth() - / alwidth)); + assertEquals(od.getBoxX(), Math + .round((float) (lastHiddenCol + 1) * od.getWidth() / alwidth)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); // try to click in hidden cols, check box does not move int xpos = 10; mouseClick(od, xpos, 0); - assertEquals( - od.getBoxX(), - Math.round((float) (lastHiddenCol + 1) * od.getWidth() - / alwidth)); + assertEquals(od.getBoxX(), Math + .round((float) (lastHiddenCol + 1) * od.getWidth() / alwidth)); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), 0); + assertEquals(vpranges.getStartSeq(), 0); + assertEquals(vpranges.getStartRes(), 0); // click to right of hidden columns, box moves to click point - testBoxIsAtClickPoint(40, 0); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), - Math.round((float) 40 * alwidth / od.getWidth()) + mouseClick(od, 60 + boxWidth / 2, boxHeight / 2); + assertEquals(od.getBoxX(), 60); + assertEquals(od.getBoxY(), 0); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); + assertEquals(vpranges.getStartSeq(), 0); + assertEquals(vpranges.getStartRes(), + Math.round((float) 60 * alwidth / od.getWidth()) - (lastHiddenCol + 1)); // click to right of hidden columns such that box runs over right hand side @@ -341,17 +344,16 @@ public class OverviewDimensionsShowHiddenTest // box position is adjusted away from the edge // overly large boxX value reset to width-boxWidth xpos = 100; - mouseClick(od, xpos, 5); + mouseClick(od, xpos + boxWidth / 2, 5 + boxHeight / 2); assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxY(), 5); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth()) - (lastHiddenCol + 1)); - assertEquals(od.getScrollRow(), - Math.round((float) od.getBoxY() * alheight - / od.getSequencesHeight())); + assertEquals(vpranges.getStartSeq(), Math.round( + (float) od.getBoxY() * alheight / od.getSequencesHeight())); } /** @@ -365,9 +367,9 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); - + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); + // hide columns 63-73, no change to box position or dimensions int firstHidden = 63; int lastHidden = 73; @@ -377,81 +379,65 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // move box so that it overlaps with hidden cols on one side // box width changes, boxX and scrollCol as for unhidden case - int xpos = 55 - boxWidth; // 55 is position in overview approx halfway - // between cols 60 and 70 - mouseClick(od, xpos, 0); - assertEquals(od.getBoxX(), xpos); + int xpos = 54 - boxWidth / 2; // 54 is position in overview approx halfway + // between cols 60 and 70 + mouseClick(od, xpos, boxHeight / 2); + assertEquals(od.getBoxX(), xpos - boxWidth / 2); assertEquals(od.getBoxY(), 0); - assertEquals( - od.getBoxWidth(), + assertEquals(od.getBoxWidth(), Math.round(boxWidth + (float) (lastHidden - firstHidden + 1) * od.getWidth() / alwidth)); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), - Math.round(xpos * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), + Math.round((xpos - boxWidth / 2) * alwidth / od.getWidth()) + + 1); // +1 for rounding + assertEquals(vpranges.getStartSeq(), 0); // move box so that it completely covers hidden cols // box width changes, boxX and scrollCol as for hidden case - xpos = 33; + xpos = 24 + boxWidth / 2; mouseClick(od, xpos, 0); - assertEquals(od.getBoxX(), xpos); + assertEquals(od.getBoxX(), 24); assertEquals(od.getBoxY(), 0); - assertEquals( - od.getBoxWidth(), + assertEquals(od.getBoxWidth(), Math.round(boxWidth + (float) (lastHidden - firstHidden + 1) * od.getWidth() / alwidth)); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), - Math.round((float) xpos * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); - - // move box so boxX is in hidden cols, box overhangs at right - // boxX and scrollCol at left of hidden area, box width extends across - // hidden region - xpos = 50; - mouseClick(od, xpos, 0); - assertEquals(od.getBoxX(), - Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)); - assertEquals(od.getBoxY(), 0); - assertEquals( - od.getBoxWidth(), - boxWidth - + Math.round((float) (lastHidden - firstHidden + 1) - * od.getWidth() / alwidth)); - assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), firstHidden - 1); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), + Math.round((float) 24 * alwidth / od.getWidth())); + assertEquals(vpranges.getStartSeq(), 0); // move box so boxX is to right of hidden cols, but does not go beyond full // width of alignment // box width, boxX and scrollCol all as for non-hidden case - xpos = 75; - testBoxIsAtClickPoint(xpos, 0); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), - Math.round(xpos * alwidth / od.getWidth()) - - (lastHidden - firstHidden + 1)); - + xpos = Math.round((float) 75 * od.getWidth() / alwidth) + boxWidth / 2; + mouseClick(od, xpos, boxHeight / 2); + assertEquals(od.getBoxX(), xpos - boxWidth / 2); + assertEquals(od.getBoxY(), 0); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); + assertEquals(vpranges.getStartSeq(), 0); + assertEquals(vpranges.getStartRes(), + 75 - (lastHidden - firstHidden + 1)); + // move box so it goes beyond full width of alignment // boxX, scrollCol adjusted back, box width normal xpos = 3000; mouseClick(od, xpos, 5); assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); - assertEquals(od.getBoxY(), 5); + assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round(((float) od.getBoxX() * alwidth / od.getWidth()) - (lastHidden - firstHidden + 1))); - assertEquals(od.getScrollRow(), - Math.round((float) od.getBoxY() * alheight - / od.getSequencesHeight())); + assertEquals(vpranges.getStartSeq(), Math.round( + (float) od.getBoxY() * alheight / od.getSequencesHeight())); } @@ -466,8 +452,8 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // hide columns 140-164, no change to box position or dimensions int firstHidden = 140; @@ -477,30 +463,32 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // click to left of hidden cols, without overlapping // boxX, scrollCol and width as normal - int xpos = 5; - testBoxIsAtClickPoint(xpos, 0); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), - Math.round((float) xpos * alwidth / od.getWidth())); + int xpos = 30; + int ypos = 6; + testBoxIsAtClickPoint(xpos, ypos); + assertEquals(vpranges.getStartSeq(), Math.round( + (float) (ypos - boxHeight / 2) * alheight / od.getHeight())); + assertEquals(vpranges.getStartRes(), Math.round( + (float) (xpos - boxWidth / 2) * alwidth / od.getWidth())); // click to left of hidden cols, with overlap // boxX and scrollCol adjusted for hidden cols, width normal xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth; - mouseClick(od, xpos, 0); + mouseClick(od, xpos + boxWidth / 2, boxHeight / 2); assertEquals(od.getBoxX(), Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth) - boxWidth + 1); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), - Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), + Math.round((float) (od.getBoxX()) * alwidth / od.getWidth())); + assertEquals(vpranges.getStartSeq(), 0); // click in hidden cols // boxX and scrollCol adjusted for hidden cols, width normal @@ -511,9 +499,9 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartSeq(), 0); // click off end of alignment // boxX and scrollCol adjusted for hidden cols, width normal @@ -524,9 +512,9 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartSeq(), 0); } /** @@ -624,11 +612,9 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), Math.round((float) 10 * od.getWidth() / alwidth)); assertEquals(od.getBoxY(), 0); - assertEquals( - od.getBoxWidth(), - boxWidth - + Math.round((float) (lastHidden - firstHidden + 1) - * od.getWidth() / alwidth)); + assertEquals(od.getBoxWidth(), + boxWidth + Math.round((float) (lastHidden - firstHidden + 1) + * od.getWidth() / alwidth)); assertEquals(od.getBoxHeight(), boxHeight); // move viewport to straddle hidden columns @@ -636,11 +622,8 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), Math.round((float) 63 * od.getWidth() / alwidth)); assertEquals(od.getBoxY(), 0); - assertEquals( - od.getBoxWidth(), - boxWidth - + Math.round((lastHidden - firstHidden + 1) - * od.getWidth() / alwidth)); + assertEquals(od.getBoxWidth(), boxWidth + Math.round( + (lastHidden - firstHidden + 1) * od.getWidth() / alwidth)); assertEquals(od.getBoxHeight(), boxHeight); // move viewport to right of hidden columns, no overlap @@ -676,9 +659,8 @@ public class OverviewDimensionsShowHiddenTest // viewport can't actually extend into hidden cols, // so move to the far right edge of the viewport moveViewport(firstHidden - viewWidth, 0); - assertEquals(od.getBoxX(), - Math.round((float) (firstHidden - viewWidth) - * od.getWidth() / alwidth)); + assertEquals(od.getBoxX(), Math.round( + (float) (firstHidden - viewWidth) * od.getWidth() / alwidth)); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); @@ -699,19 +681,16 @@ public class OverviewDimensionsShowHiddenTest // box moves to below hidden rows, height remains same moveViewport(0, 0); assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), - Math.round((float) (lastHidden + 1) * od.getSequencesHeight() - / alheight)); + assertEquals(od.getBoxY(), Math.round( + (float) (lastHidden + 1) * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); // move viewport to end of alignment moveViewport(0, 525 - viewHeight - lastHidden - 1); assertEquals(od.getBoxX(), 0); - assertEquals( - od.getBoxY(), - Math.round((float) (525 - viewHeight) * od.getSequencesHeight() - / alheight)); + assertEquals(od.getBoxY(), Math.round((float) (525 - viewHeight) + * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); } @@ -738,11 +717,10 @@ public class OverviewDimensionsShowHiddenTest // move viewport to straddle hidden rows moveViewport(0, 198); assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), Math.round ((float)198 * od.getSequencesHeight() - / alheight)); + assertEquals(od.getBoxY(), + Math.round((float) 198 * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals( - od.getBoxHeight(), + assertEquals(od.getBoxHeight(), Math.round((float) (viewHeight + lastHidden - firstHidden + 1) * od.getSequencesHeight() / alheight)); } @@ -770,8 +748,7 @@ public class OverviewDimensionsShowHiddenTest // viewport sits above hidden rows and does not include them moveViewport(0, firstHidden - viewHeight - 1); assertEquals(od.getBoxX(), 0); - assertEquals( - od.getBoxY(), + assertEquals(od.getBoxY(), Math.round((float) (firstHidden - viewHeight - 1) * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); @@ -791,8 +768,8 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // hide rows at start and check updated box position is correct // changes boxY but not boxheight @@ -801,24 +778,21 @@ public class OverviewDimensionsShowHiddenTest od.setBoxPosition(al.getHiddenSequences(), hiddenCols); assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), - Math.round((float) (lastHiddenRow + 1) - * od.getSequencesHeight() / alheight)); + assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1) + * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); // click in hidden rows - same result mouseClick(od, 0, 0); assertEquals(od.getBoxX(), 0); - assertEquals( - od.getBoxY(), - Math.round((float) (lastHiddenRow + 1) - * od.getSequencesHeight() / alheight)); + assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1) + * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); // click below hidden rows - mouseClick(od, 0, 150); + mouseClick(od, 0, 150 + boxHeight / 2); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 150); assertEquals(od.getBoxWidth(), boxWidth); @@ -838,8 +812,8 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // hide rows in middle and check updated box position is correct // no changes @@ -855,31 +829,17 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxHeight(), boxHeight); // click above hidden rows, so that box overlaps - int ypos = 35; // column value in residues - mouseClick(od, 0, - Math.round((float) ypos * od.getSequencesHeight() / alheight)); - assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), - Math.round((float) ypos * od.getSequencesHeight() / alheight)); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals( - od.getBoxHeight(), - boxHeight - + Math.round((float) (lastHiddenRow - firstHiddenRow + 1) - * od.getSequencesHeight() / alheight)); - - // click so that box straddles hidden rows - ypos = 44; // column value in residues - mouseClick(od, 0, - Math.round((float) ypos * od.getSequencesHeight() / alheight)); + int rowpos = 35; // row value in residues + int centrepos = 43; // centre row + mouseClick(od, 0, Math + .round((float) centrepos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), - Math.round((float) ypos * od.getSequencesHeight() / alheight)); + assertEquals(od.getBoxY(), Math + .round((float) rowpos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals( - od.getBoxHeight(), - boxHeight - + Math.round((float) (lastHiddenRow - firstHiddenRow + 1) + assertEquals(od.getBoxHeight(), + boxHeight + Math + .round((float) (lastHiddenRow - firstHiddenRow + 1) * od.getSequencesHeight() / alheight)); } @@ -895,8 +855,8 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // hide rows at end and check updated box position is correct // no changes @@ -910,49 +870,143 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - // click above hidden rows - int ypos = 40; // row 40 + // click above hidden rows, no overlap + int ypos = 40 + viewHeight / 2; // top is row 40 mouseClick(od, 0, Math.round((float) ypos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), - Math.round((float) ypos * od.getSequencesHeight() / alheight)); + Math.round((float) 40 * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); // click above hidden rows so box overlaps // boxY moved upwards, boxHeight remains same - ypos = 497; // row 497 + ypos = 497 + viewHeight / 2; // row 497 mouseClick(od, 0, Math.round((float) ypos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxX(), 0); - assertEquals( - od.getBoxY(), - Math.round((float) (firstHidden - viewHeight) - * od.getSequencesHeight() / alheight)); + assertEquals(od.getBoxY(), Math.round((float) (firstHidden - viewHeight) + * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); // click within hidden rows - ypos = 505; + ypos = 505 + boxHeight / 2; mouseClick(od, 0, Math.round((float) ypos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxX(), 0); - assertEquals( - od.getBoxY(), - Math.round((firstHidden - viewHeight) * od.getSequencesHeight() - / alheight)); + assertEquals(od.getBoxY(), Math.round((firstHidden - viewHeight) + * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); } + /** + * Test the function to determine if a point is in the overview's box or not + */ + @Test(groups = { "Functional" }) + public void testPositionInBox() + { + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols); + + assertFalse(od.isPositionInBox(0, 0)); + assertTrue(od.isPositionInBox(10, 9)); + assertFalse(od.isPositionInBox(0, 9)); + assertFalse(od.isPositionInBox(9, 0)); + assertFalse(od.isPositionInBox(75, 20)); + + assertTrue(od.isPositionInBox(47, 6)); + assertFalse(od.isPositionInBox(48, 6)); + assertTrue(od.isPositionInBox(47, 9)); + assertFalse(od.isPositionInBox(47, 10)); + + // hide columns in the box area + // extends area where a point is considered to be in the box + hiddenCols.hideColumns(1, 4); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols); + assertFalse(od.isPositionInBox(0, 0)); + assertTrue(od.isPositionInBox(10, 9)); + assertFalse(od.isPositionInBox(0, 9)); + assertFalse(od.isPositionInBox(9, 0)); + assertFalse(od.isPositionInBox(75, 20)); + + assertTrue(od.isPositionInBox(47, 6)); + assertTrue(od.isPositionInBox(48, 6)); + assertTrue(od.isPositionInBox(47, 9)); + assertFalse(od.isPositionInBox(47, 10)); + + // hide sequences in box area + // extends area where a point is considered to be in the box + hideSequences(1, 3); + ColumnSelection cs = new ColumnSelection(); + hiddenCols.revealAllHiddenColumns(cs); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols); + assertFalse(od.isPositionInBox(0, 0)); + assertTrue(od.isPositionInBox(10, 9)); + assertFalse(od.isPositionInBox(0, 9)); + assertFalse(od.isPositionInBox(9, 0)); + assertFalse(od.isPositionInBox(75, 20)); + + assertTrue(od.isPositionInBox(47, 6)); + assertFalse(od.isPositionInBox(48, 6)); + assertTrue(od.isPositionInBox(47, 9)); + assertTrue(od.isPositionInBox(47, 10)); + } + + /** + * Test the dragging functionality + */ + @Test(groups = { "Functional" }) + public void testDragging() + { + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols); + od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols); + od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols); + + // updates require an OverviewPanel to exist which it doesn't here + // so call setBoxPosition() as it would be called by the AlignmentPanel + // normally + od.setBoxPosition(al.getHiddenSequences(), hiddenCols); + + // corner moves 16 (20-4) right and 6 (22-16) up + assertEquals(od.getBoxX(), 16); + assertEquals(od.getBoxY(), 6); + + // hide columns - box moves drag distance + hidden cols, vertically makes no + // difference + hiddenCols.hideColumns(1, 4); + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols); + od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols); + od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols); + + // corner moves 16 (20-4) + hiddenCols right and 6 (22-16) down + assertEquals(od.getBoxX(), + 16 + Math.round((float) 4 * od.getWidth() / alwidth)); + assertEquals(od.getBoxY(), 6); + + // hide sequences in box area + // makes absolutely no difference + hideSequences(1, 3); + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols); + od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols); + od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols); + + // corner moves 16 (20-4) + hiddenCols right and 6 (22-16) + hiddenRows down + assertEquals(od.getBoxX(), + 16 + Math.round((float) 4 * od.getWidth() / alwidth)); + assertEquals(od.getBoxY(), + 6 + Math.round((float) 3 * od.getHeight() / alheight)); + } + /* * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same. */ private void moveViewportH(int startRes) { - vpranges.setStartRes(startRes); - vpranges.setEndRes(startRes + viewWidth - 1); + vpranges.setViewportStartAndWidth(startRes, viewWidth); od.setBoxPosition(al.getHiddenSequences(), hiddenCols); } @@ -961,8 +1015,7 @@ public class OverviewDimensionsShowHiddenTest */ private void moveViewportV(int startSeq) { - vpranges.setStartSeq(startSeq); - vpranges.setEndSeq(startSeq + viewHeight - 1); + vpranges.setViewportStartAndHeight(startSeq, viewHeight); od.setBoxPosition(al.getHiddenSequences(), hiddenCols); } @@ -971,40 +1024,33 @@ public class OverviewDimensionsShowHiddenTest */ private void moveViewport(int startRes, int startSeq) { - vpranges.setStartRes(startRes); - vpranges.setEndRes(startRes + viewWidth - 1); - vpranges.setStartSeq(startSeq); - vpranges.setEndSeq(startSeq + viewHeight - 1); + vpranges.setViewportStartAndWidth(startRes, viewWidth); + vpranges.setViewportStartAndHeight(startSeq, viewHeight); od.setBoxPosition(al.getHiddenSequences(), hiddenCols); } /* * Mouse click as position x,y in overview window */ - private void mouseClick(OverviewDimensionsShowHidden od, int x, int y) + private void mouseClick(OverviewDimensions od, int x, int y) { od.updateViewportFromMouse(x, y, al.getHiddenSequences(), hiddenCols); // updates require an OverviewPanel to exist which it doesn't here // so call setBoxPosition() as it would be called by the AlignmentPanel // normally - - vpranges.setStartRes(od.getScrollCol()); - vpranges.setEndRes(od.getScrollCol() + viewWidth - 1); - vpranges.setStartSeq(od.getScrollRow()); - vpranges.setEndSeq(od.getScrollRow() + viewHeight - 1); od.setBoxPosition(al.getHiddenSequences(), hiddenCols); } - + /* - * Test that the box is positioned with the top left corner at xpos, ypos + * Test that the box is positioned with the centre at xpos, ypos * and with the original width and height */ private void testBoxIsAtClickPoint(int xpos, int ypos) { mouseClick(od, xpos, ypos); - assertEquals(od.getBoxX(), xpos); - assertEquals(od.getBoxY(), ypos); + assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos); + assertEquals(od.getBoxY() + od.getBoxHeight() / 2, ypos); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); @@ -1017,7 +1063,7 @@ public class OverviewDimensionsShowHiddenTest { SequenceI[] allseqs = al.getSequencesArray(); SequenceGroup theseSeqs = new SequenceGroup(); - + for (int i = start; i <= end; i++) { theseSeqs.addSequence(allseqs[i], false); @@ -1026,4 +1072,50 @@ public class OverviewDimensionsShowHiddenTest hiddenRepSequences.put(allseqs[start], theseSeqs); } + + /** + * Test setting of the box position, when there are hidden rows at the start + * of the alignment + */ + @Test(groups = { "Functional" }) + public void testFromMouseWithHiddenRowsAtStartWrapped() + { + vpranges.setWrappedMode(true); + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols); + assertEquals(od.getBoxX(), 0); + assertEquals(od.getBoxY(), 0); + assertEquals(od.getBoxHeight(), boxHeight); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); + + // hide rows at start and check updated box position is correct + // changes boxY but not boxheight + int lastHiddenRow = 30; + hideSequences(0, lastHiddenRow); + + od.setBoxPosition(al.getHiddenSequences(), hiddenCols); + assertEquals(od.getBoxX(), 0); + assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1) + * od.getSequencesHeight() / alheight)); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); + + // click in hidden rows - same result + mouseClick(od, 0, 0); + assertEquals(od.getBoxX(), 0); + int boxY = od.getBoxY(); + assertEquals(boxY, Math.round((float) (lastHiddenRow + 1) + * od.getSequencesHeight() / alheight)); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); + + // click below hidden rows + // vertical move of overview box is suppressed in wrapped mode + mouseClick(od, 0, 150); + assertEquals(od.getBoxX(), 0); + assertEquals(od.getBoxY(), boxY); // unchanged + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); + } }