X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fviewmodel%2FOverviewDimensionsTest.java;h=398fec302d0578a99b5edded73f9553a8698ee62;hb=527793abb7caec45b0362d349d5410a895573c7b;hp=8ceadbaa1656c03a5a26190396afb463b1251267;hpb=7e66b58086ec1368feaa6c32e6478d66734c152a;p=jalview.git diff --git a/test/jalview/viewmodel/OverviewDimensionsTest.java b/test/jalview/viewmodel/OverviewDimensionsTest.java index 8ceadba..398fec3 100644 --- a/test/jalview/viewmodel/OverviewDimensionsTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsTest.java @@ -52,7 +52,7 @@ public class OverviewDimensionsTest int alheight; int alwidth; - ViewportPositionProps posProps; + ViewportRanges vpranges; Hashtable hiddenRepSequences = new Hashtable(); @@ -75,33 +75,33 @@ public class OverviewDimensionsTest } hiddenCols.revealAllHiddenColumns(); - posProps = new ViewportPositionProps(al); - posProps.setStartRes(0); - posProps.setEndRes(62); - posProps.setStartSeq(0); - posProps.setEndSeq(17); + vpranges = new ViewportRanges(al); + vpranges.setStartRes(0); + vpranges.setEndRes(62); + vpranges.setStartSeq(0); + vpranges.setEndSeq(17); - viewHeight = posProps.getEndSeq() - posProps.getStartSeq() + 1; - viewWidth = posProps.getEndRes() - posProps.getStartRes() + 1; + viewHeight = vpranges.getEndSeq() - vpranges.getStartSeq() + 1; + viewWidth = vpranges.getEndRes() - vpranges.getStartRes() + 1; ColumnSelection hiddenCols = new ColumnSelection(); - od = new OverviewDimensions(posProps, true); + od = new OverviewDimensions(vpranges, true); // Initial box sizing - default path through code - od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); mouseClick(od, 0, 0); moveViewport(0, 0); // calculate before hidden columns so we get absolute values - alheight = posProps.getAbsoluteAlignmentHeight(); - alwidth = posProps.getAbsoluteAlignmentWidth(); + alheight = vpranges.getAbsoluteAlignmentHeight(); + alwidth = vpranges.getAbsoluteAlignmentWidth(); - boxWidth = Math.round((float) (posProps.getEndRes() - - posProps.getStartRes() + 1) + boxWidth = Math.round((float) (vpranges.getEndRes() + - vpranges.getStartRes() + 1) * od.getWidth() / alwidth); - boxHeight = Math.round((float) (posProps.getEndSeq() - - posProps.getStartSeq() + 1) + boxHeight = Math.round((float) (vpranges.getEndSeq() + - vpranges.getStartSeq() + 1) * od.getSequencesHeight() / alheight); } @@ -134,10 +134,10 @@ public class OverviewDimensionsTest // test for alignment with width > height SequenceI[] seqs1 = new SequenceI[] { seqa, seqb }; Alignment al1 = new Alignment(seqs1); - ViewportPositionProps props = new ViewportPositionProps(al1); + ViewportRanges props = new ViewportRanges(al1); OverviewDimensions od = new OverviewDimensions(props, true); - int scaledHeight = 266; + int scaledHeight = 267; assertEquals(od.getGraphHeight(), defaultGraphHeight); assertEquals(od.getSequencesHeight(), scaledHeight); assertEquals(od.getWidth(), maxWidth); @@ -146,7 +146,7 @@ public class OverviewDimensionsTest // test for alignment with width < height SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd }; Alignment al2 = new Alignment(seqs2); - props = new ViewportPositionProps(al2); + props = new ViewportRanges(al2); od = new OverviewDimensions(props, true); int scaledWidth = 300; @@ -159,7 +159,7 @@ public class OverviewDimensionsTest // min value SequenceI[] seqs3 = new SequenceI[] { seqe }; Alignment al3 = new Alignment(seqs3); - props = new ViewportPositionProps(al3); + props = new ViewportRanges(al3); od = new OverviewDimensions(props, true); assertEquals(od.getGraphHeight(), defaultGraphHeight); @@ -171,7 +171,7 @@ public class OverviewDimensionsTest SequenceI[] seqs4 = new SequenceI[] { seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd }; Alignment al4 = new Alignment(seqs4); - props = new ViewportPositionProps(al4); + props = new ViewportRanges(al4); od = new OverviewDimensions(props, true); assertEquals(od.getGraphHeight(), defaultGraphHeight); @@ -180,7 +180,7 @@ public class OverviewDimensionsTest assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight); Alignment al5 = new Alignment(seqs4); - props = new ViewportPositionProps(al5); + props = new ViewportRanges(al5); od = new OverviewDimensions(props, false); assertEquals(od.getGraphHeight(), 0); @@ -198,7 +198,7 @@ public class OverviewDimensionsTest public void testSetBoxFromMouseClick() { od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, - posProps); + vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -225,7 +225,7 @@ public class OverviewDimensionsTest // overly large boxX value reset to width-boxWidth mouseClick(od, 100, 6); - assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1); + assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxY(), 6); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); @@ -243,13 +243,17 @@ public class OverviewDimensionsTest assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), 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())); + / od.getSequencesHeight()) - 1); // click past end of alignment, as above mouseClick(od, 3000, 5); - assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1); + assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), @@ -293,7 +297,7 @@ public class OverviewDimensionsTest public void testFromMouseWithHiddenColsAtStart() { od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, - posProps); + vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -305,7 +309,7 @@ public class OverviewDimensionsTest int lastHiddenCol = 30; hiddenCols.hideColumns(0, lastHiddenCol); - od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); assertEquals(od.getBoxX(), Math.round((float) (lastHiddenCol + 1) * od.getWidth() / alwidth)); @@ -313,7 +317,6 @@ public class OverviewDimensionsTest assertEquals(od.getBoxHeight(), boxHeight); // try to click in hidden cols, check box does not move - // this test currently fails as the overview box does not behave like this! int xpos = 10; mouseClick(od, xpos, 0); assertEquals( @@ -339,7 +342,7 @@ public class OverviewDimensionsTest // overly large boxX value reset to width-boxWidth xpos = 100; mouseClick(od, xpos, 5); - assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1); + assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxY(), 5); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); @@ -359,7 +362,7 @@ public class OverviewDimensionsTest public void testFromMouseWithHiddenColsInMiddle() { od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, - posProps); + vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -371,7 +374,7 @@ public class OverviewDimensionsTest int lastHidden = 73; hiddenCols.hideColumns(firstHidden, lastHidden); - od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -440,7 +443,7 @@ public class OverviewDimensionsTest // boxX, scrollCol adjusted back, box width normal xpos = 3000; mouseClick(od, xpos, 5); - assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1); + assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxY(), 5); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); @@ -461,7 +464,7 @@ public class OverviewDimensionsTest public void testFromMouseWithHiddenColsAtEnd() { od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, - posProps); + vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -472,7 +475,7 @@ public class OverviewDimensionsTest int firstHidden = 140; int lastHidden = 164; hiddenCols.hideColumns(firstHidden, lastHidden); - od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -492,44 +495,40 @@ public class OverviewDimensionsTest xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth; mouseClick(od, xpos, 0); assertEquals(od.getBoxX(), - Math.round((firstHidden - 1) * od.getWidth() / alwidth) - - boxWidth); + 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(od.getBoxX() * alwidth / od.getWidth())); + Math.round((float) od.getBoxX() * alwidth / od.getWidth())); assertEquals(od.getScrollRow(), 0); // click in hidden cols // boxX and scrollCol adjusted for hidden cols, width normal - // TODO breaks as above test - /*xpos = 115; - assertEquals( - od.getBoxX(), - Math.round((firstHidden - 1) * scalew * av.getCharWidth()) - - od.getBoxWidth()); + xpos = 115; + 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(od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0);*/ + Math.round((float) od.getBoxX() * alwidth / od.getWidth())); + assertEquals(od.getScrollRow(), 0); // click off end of alignment // boxX and scrollCol adjusted for hidden cols, width normal - // TODO breaks as above test - /* xpos = 3000; - assertEquals( - od.getBoxX(), - Math.round((firstHidden - 1) * scalew * av.getCharWidth()) - - od.getBoxWidth()); - assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), - Math.round(od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0);*/ + xpos = 3000; + 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); } /** @@ -678,13 +677,14 @@ public class OverviewDimensionsTest assertEquals(od.getBoxHeight(), boxHeight); // move viewport to hidden columns - moveViewport(102, 0); + // 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) 102 * od.getWidth() / alwidth)); + Math.round((float) (firstHidden - viewWidth) + * od.getWidth() / alwidth)); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth - + Math.round((float) (lastHidden - firstHidden) - * od.getWidth() / alwidth)); + assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); } @@ -791,7 +791,7 @@ public class OverviewDimensionsTest public void testFromMouseWithHiddenRowsAtStart() { od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, - posProps); + vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxHeight(), boxHeight); @@ -804,7 +804,7 @@ public class OverviewDimensionsTest int lastHiddenRow = 30; hideSequences(0, lastHiddenRow); - od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1) @@ -838,7 +838,7 @@ public class OverviewDimensionsTest public void testFromMouseWithHiddenRowsInMiddle() { od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, - posProps); + vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); @@ -850,10 +850,10 @@ public class OverviewDimensionsTest // hide rows in middle and check updated box position is correct // no changes int firstHiddenRow = 50; - int lastHiddenRow = 60; + int lastHiddenRow = 54; hideSequences(firstHiddenRow, lastHiddenRow); - od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); @@ -861,34 +861,32 @@ public class OverviewDimensionsTest assertEquals(od.getBoxHeight(), boxHeight); // click above hidden rows, so that box overlaps - int ypos = 40; - // TODO test fails because box does not change height - dealt with by scroll - // values - /* mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight())); - assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()), - 1.5); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals( - od.getBoxHeight(), - boxHeight - + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av - .getCharHeight())); - */ + 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 = 48; - // TODO test fails because box does not change height - dealt with by scroll - // values - /*mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight())); + ypos = 44; // column value in residues + mouseClick(od, 0, + Math.round((float) ypos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()), - 1.5); + assertEquals(od.getBoxY(), + Math.round((float) ypos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals( od.getBoxHeight(), boxHeight - + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av - .getCharHeight()));*/ + + Math.round((float) (lastHiddenRow - firstHiddenRow + 1) + * od.getSequencesHeight() / alheight)); } /** @@ -899,7 +897,7 @@ public class OverviewDimensionsTest public void testFromMouseWithHiddenRowsAtEnd() { od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, - posProps); + vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -913,7 +911,7 @@ public class OverviewDimensionsTest int lastHidden = 524; hideSequences(firstHidden, lastHidden); - od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -931,29 +929,28 @@ public class OverviewDimensionsTest // click above hidden rows so box overlaps // boxY moved upwards, boxHeight remains same - // TODO fails with boxY located at row 497 - correction done by - // setScrollValues - /* ypos = 497; // row 497 - mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight())); - assertEquals(od.getBoxX(), 0); - assertEquals( - od.getBoxY(), - Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()), - 1.5); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight);*/ + ypos = 497; // 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.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); // click within hidden rows ypos = 505; - // TODO: fails with wrong boxHeight - correction done by setScrollValues(?) - /*mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight())); + mouseClick(od, 0, + Math.round((float) ypos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxX(), 0); assertEquals( od.getBoxY(), - Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()), - 1.5); + Math.round((firstHidden - viewHeight) * od.getSequencesHeight() + / alheight)); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight);*/ + assertEquals(od.getBoxHeight(), boxHeight); } /* @@ -961,9 +958,9 @@ public class OverviewDimensionsTest */ private void moveViewportH(int startRes) { - posProps.setStartRes(startRes); - posProps.setEndRes(startRes + viewWidth - 1); - od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); + vpranges.setStartRes(startRes); + vpranges.setEndRes(startRes + viewWidth - 1); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); } /* @@ -971,9 +968,9 @@ public class OverviewDimensionsTest */ private void moveViewportV(int startSeq) { - posProps.setStartSeq(startSeq); - posProps.setEndSeq(startSeq + viewHeight - 1); - od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); + vpranges.setStartSeq(startSeq); + vpranges.setEndSeq(startSeq + viewHeight - 1); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); } /* @@ -981,11 +978,11 @@ public class OverviewDimensionsTest */ private void moveViewport(int startRes, int startSeq) { - posProps.setStartRes(startRes); - posProps.setEndRes(startRes + viewWidth - 1); - posProps.setStartSeq(startSeq); - posProps.setEndSeq(startSeq + viewHeight - 1); - od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); + vpranges.setStartRes(startRes); + vpranges.setEndRes(startRes + viewWidth - 1); + vpranges.setStartSeq(startSeq); + vpranges.setEndSeq(startSeq + viewHeight - 1); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); } /* @@ -994,17 +991,17 @@ public class OverviewDimensionsTest private void mouseClick(OverviewDimensions od, int x, int y) { od.updateViewportFromMouse(x, y, al.getHiddenSequences(), hiddenCols, - posProps); + vpranges); // updates require an OverviewPanel to exist which it doesn't here // so call setBoxPosition() as it would be called by the AlignmentPanel // normally - posProps.setStartRes(od.getScrollCol()); - posProps.setEndRes(od.getScrollCol() + viewWidth - 1); - posProps.setStartSeq(od.getScrollRow()); - posProps.setEndSeq(od.getScrollRow() + viewHeight - 1); - od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); + 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, vpranges); } /*