X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fviewmodel%2FOverviewDimensionsTest.java;h=1ea07ea0f8f0f6b89d46008e15036946789e3c17;hb=7f4da0a2b0c10f158a03dbfce8878e67e90c4a68;hp=cc808d653c5cb568de54e4b80729c70262586ac6;hpb=571d15a897c11bdc2dda76ce03686604596f220d;p=jalview.git diff --git a/test/jalview/viewmodel/OverviewDimensionsTest.java b/test/jalview/viewmodel/OverviewDimensionsTest.java index cc808d6..1ea07ea 100644 --- a/test/jalview/viewmodel/OverviewDimensionsTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsTest.java @@ -22,202 +22,93 @@ package jalview.viewmodel; import static org.testng.Assert.assertEquals; -import jalview.bin.Cache; -import jalview.bin.Jalview; +import jalview.analysis.AlignmentGenerator; import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.ColumnSelection; import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; -import jalview.gui.AlignFrame; -import jalview.gui.AlignViewport; -import jalview.gui.Desktop; -import jalview.gui.JvOptionPane; -import jalview.io.DataSourceType; -import jalview.io.FileLoader; -import java.util.List; +import java.util.Hashtable; -import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @Test(singleThreaded = true) -public class OverviewDimensionsTest { - - boolean showConservationSetting; - - SequenceI seq1 = new Sequence( - "Seq1", - "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); - - SequenceI seq2 = new Sequence( - "Seq2", - "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); - - SequenceI seq3 = new Sequence( - "Seq3", - "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); - - SequenceI seq4 = new Sequence( - "Seq4", - "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); - - SequenceI seq5 = new Sequence( - "Seq5", - "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); - - AlignFrame af; - AlignViewport av; +public class OverviewDimensionsTest +{ + AlignmentI al; OverviewDimensions od; - float scalew; - float scaleh; + // cached widths and heights int boxWidth; int boxHeight; - int viewHeight; - int viewWidth; - int alheight; - int alwidth; + ViewportPositionProps posProps; + + Hashtable hiddenRepSequences = new Hashtable(); + + ColumnSelection hiddenCols = new ColumnSelection(); + @BeforeClass(alwaysRun = true) public void setUpJvOptionPane() { - JvOptionPane.setInteractiveMode(false); - JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + // create random alignment + AlignmentGenerator gen = new AlignmentGenerator(false); + al = gen.generate(157, 525, 123, 5, 5); } @BeforeMethod(alwaysRun = true) public void setUp() { - Jalview.main(new String[] { "-nonews", "-props", - "test/jalview/testProps.jvprops" }); - - Cache.applicationProperties.setProperty("SHOW_IDENTITY", - Boolean.TRUE.toString()); - af = new FileLoader().LoadFileWaitTillLoaded( - "examples/testdata/bigal.fa", - DataSourceType.FILE); - - /* - * Wait for viewport to initialise - */ - synchronized (this) + if (!hiddenRepSequences.isEmpty()) { - while (af.getViewport().getEndRes() == 0) - { - try - { - wait(50); - } catch (InterruptedException e) - { - } - } + al.getHiddenSequences().showAll(hiddenRepSequences); } - - /* - * wait for Consensus thread to complete - */ - synchronized (this) - { - while (af.getViewport().getConsensusSeq() == null) - { - try - { - wait(50); - } catch (InterruptedException e) - { - } - } - } - - // get cached setting for showConservation - // reset it in AfterClass! - showConservationSetting = Cache.getDefault("SHOW_CONSERVATION", true); + hiddenCols.revealAllHiddenColumns(); - av = af.getViewport(); - - od = new OverviewDimensions(av); + posProps = new ViewportPositionProps(al); + posProps.setStartRes(0); + posProps.setEndRes(62); + posProps.setStartSeq(0); + posProps.setEndSeq(17); - while (av.isCalcInProgress()) - { - try - { - Thread.sleep(50); - } catch (InterruptedException e) - { + viewHeight = posProps.getEndSeq() - posProps.getStartSeq() + 1; + viewWidth = posProps.getEndRes() - posProps.getStartRes() + 1; - } - } + ColumnSelection hiddenCols = new ColumnSelection(); + od = new OverviewDimensions(posProps, true); // Initial box sizing - default path through code - od.setBoxPosition(); - - init(); - } - - private void init() - { - av.showAllHiddenColumns(); - av.showAllHiddenSeqs(); - av.setSelectionGroup(null); - // o/w hidden seqs retain selection group, causes problems later when hiding - // sequences - - // wait for conservation calc to complete - while (av.isCalcInProgress()) - { - try - { - Thread.sleep(50); - } catch (InterruptedException e) - { - - } - } + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); mouseClick(od, 0, 0); moveViewport(0, 0); - viewHeight = av.getEndSeq() - av.getStartSeq(); - viewWidth = av.getEndRes() - av.getStartRes(); - - // wait for gui to get set up - while (viewHeight != 17 || viewWidth != 59) - { - try - { - Thread.sleep(50); - viewHeight = av.getEndSeq() - av.getStartSeq(); - viewWidth = av.getEndRes() - av.getStartRes(); - } catch (InterruptedException e) - { - - } - } - // calculate before hidden columns so we get absolute values - alheight = av.getAlignment().getHeight(); - alwidth = av.getAlignment().getWidth(); - - boxWidth = Math.round((float) (av.getEndRes() - av.getStartRes() + 1) - / alwidth * od.getWidth()); - boxHeight = Math.round((float) (av.getEndSeq() - av.getStartSeq()) - / alheight * od.getHeight()); - System.out.println(boxHeight); - + alheight = posProps.getAbsoluteAlignmentHeight(); + alwidth = posProps.getAbsoluteAlignmentWidth(); + + boxWidth = Math.round((float) (posProps.getEndRes() + - posProps.getStartRes() + 1) + * od.getWidth() / alwidth); + boxHeight = Math.round((float) (posProps.getEndSeq() + - posProps.getStartSeq() + 1) + * od.getSequencesHeight() / alheight); } - @AfterMethod(alwaysRun = true) - public void tearDown() + @AfterClass(alwaysRun = true) + public void cleanUp() { - Cache.applicationProperties.setProperty("SHOW_CONSERVATION", - Boolean.toString(showConservationSetting)); - Desktop.instance.closeAll_actionPerformed(null); + al = null; } /** @@ -240,17 +131,13 @@ public class OverviewDimensionsTest { int maxSeqHeight = 300; int minSeqHeight = 40; - Cache.applicationProperties.setProperty("SHOW_CONSERVATION", - Boolean.toString(true)); - // test for alignment with width > height SequenceI[] seqs1 = new SequenceI[] { seqa, seqb }; Alignment al1 = new Alignment(seqs1); - al1.setDataset(null); - AlignViewport av1 = new AlignViewport(al1); + ViewportPositionProps props = new ViewportPositionProps(al1); - OverviewDimensions od = new OverviewDimensions(av1); - int scaledHeight = 266; + OverviewDimensions od = new OverviewDimensions(props, true); + int scaledHeight = 267; assertEquals(od.getGraphHeight(), defaultGraphHeight); assertEquals(od.getSequencesHeight(), scaledHeight); assertEquals(od.getWidth(), maxWidth); @@ -259,10 +146,9 @@ public class OverviewDimensionsTest { // test for alignment with width < height SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd }; Alignment al2 = new Alignment(seqs2); - al2.setDataset(null); - AlignViewport av2 = new AlignViewport(al2); + props = new ViewportPositionProps(al2); - od = new OverviewDimensions(av2); + od = new OverviewDimensions(props, true); int scaledWidth = 300; assertEquals(od.getGraphHeight(), defaultGraphHeight); assertEquals(od.getSequencesHeight(), maxSeqHeight); @@ -273,10 +159,9 @@ public class OverviewDimensionsTest { // min value SequenceI[] seqs3 = new SequenceI[] { seqe }; Alignment al3 = new Alignment(seqs3); - al3.setDataset(null); - AlignViewport av3 = new AlignViewport(al3); + props = new ViewportPositionProps(al3); - od = new OverviewDimensions(av3); + od = new OverviewDimensions(props, true); assertEquals(od.getGraphHeight(), defaultGraphHeight); assertEquals(od.getSequencesHeight(), minSeqHeight); assertEquals(od.getWidth(), maxWidth); @@ -286,24 +171,18 @@ 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); - al4.setDataset(null); - AlignViewport av4 = new AlignViewport(al4); + props = new ViewportPositionProps(al4); - od = new OverviewDimensions(av4); + od = new OverviewDimensions(props, true); assertEquals(od.getGraphHeight(), defaultGraphHeight); assertEquals(od.getSequencesHeight(), maxSeqHeight); assertEquals(od.getWidth(), minWidth); assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight); - // test for alignment where no conservation annotation is shown - Cache.applicationProperties.setProperty("SHOW_CONSERVATION", - Boolean.toString(false)); - Alignment al5 = new Alignment(seqs4); - al5.setDataset(null); - AlignViewport av5 = new AlignViewport(al5); + props = new ViewportPositionProps(al5); - od = new OverviewDimensions(av5); + od = new OverviewDimensions(props, false); assertEquals(od.getGraphHeight(), 0); assertEquals(od.getSequencesHeight(), maxSeqHeight); assertEquals(od.getWidth(), minWidth); @@ -314,16 +193,12 @@ public class OverviewDimensionsTest { * Test that validation after mouse adjustments to boxX and boxY sets box * dimensions and scroll values correctly, when there are no hidden rows or * columns. - * - * The current implementation uses multiple transformations between coordinate - * systems which often involve casting to int, which causes values to be - * truncated. As a result we can lose accuracy. The tests below use - * approximate test values where appropriate. */ @Test(groups = { "Functional" }) public void testSetBoxFromMouseClick() { - od.setBoxPositionByMouse(0, 0); + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, + posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -368,9 +243,13 @@ 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); @@ -417,7 +296,8 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenColsAtStart() { - od.setBoxPositionByMouse(0, 0); + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, + posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -427,9 +307,9 @@ public class OverviewDimensionsTest { // hide cols at start and check updated box position is correct // changes boxX but not boxwidth int lastHiddenCol = 30; - hideColumns(0, lastHiddenCol); + hiddenCols.hideColumns(0, lastHiddenCol); - od.setBoxPosition(); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); assertEquals(od.getBoxX(), Math.round((float) (lastHiddenCol + 1) * od.getWidth() / alwidth)); @@ -437,18 +317,18 @@ 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(od.getBoxX(), - Math.round ((lastHiddenCol + 1) * od.getWidth() / alwidth)); - assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), - Math.round (xpos * alwidth / od.getWidth())); - */ + int xpos = 10; + mouseClick(od, xpos, 0); + 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); + // click to right of hidden columns, box moves to click point testBoxIsAtClickPoint(40, 0); assertEquals(od.getScrollRow(), 0); @@ -460,7 +340,7 @@ public class OverviewDimensionsTest { // of alignment // box position is adjusted away from the edge // overly large boxX value reset to width-boxWidth - int xpos = 100; + xpos = 100; mouseClick(od, xpos, 5); assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxY(), 5); @@ -481,19 +361,20 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenColsInMiddle() { - od.setBoxPositionByMouse(0, 0); + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, + posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getScrollCol(), 0); assertEquals(od.getScrollRow(), 0); - // hide columns 60-68, no change to box position or dimensions - int firstHidden = 60; - int lastHidden = 68; - hideColumns(firstHidden, lastHidden); + // hide columns 63-73, no change to box position or dimensions + int firstHidden = 63; + int lastHidden = 73; + hiddenCols.hideColumns(firstHidden, lastHidden); - od.setBoxPosition(); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -502,8 +383,8 @@ public class OverviewDimensionsTest { // move box so that it overlaps with hidden cols on one side // box width changes, boxX and scrollCol as for unhidden case - int xpos = 50 - boxWidth; // 50 is position in overview halfway between cols - // 60 and 70 + int xpos = 55 - boxWidth; // 55 is position in overview approx halfway + // between cols 60 and 70 mouseClick(od, xpos, 0); assertEquals(od.getBoxX(), xpos); assertEquals(od.getBoxY(), 0); @@ -518,7 +399,7 @@ public class OverviewDimensionsTest { // move box so that it completely covers hidden cols // box width changes, boxX and scrollCol as for hidden case - xpos = 30; + xpos = 33; mouseClick(od, xpos, 0); assertEquals(od.getBoxX(), xpos); assertEquals(od.getBoxY(), 0); @@ -528,39 +409,35 @@ public class OverviewDimensionsTest { * od.getWidth() / alwidth)); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), - Math.round(xpos * alwidth / od.getWidth())); + Math.round((float) xpos * alwidth / od.getWidth())); assertEquals(od.getScrollRow(), 0); // move box so boxX is in hidden cols, box overhangs at right - // box width back to normal, boxX and scrollCol move to right of hidden area - // TODO currently this test fails in the Jalview GUI, there is a gap between - // the rhs of the hidden area and the box - /* xpos = 50; - mouseClick(od, xpos, 0); - assertEquals(od.getBoxX(), - (lastHidden + 1) * scalew * av.getCharWidth()); - assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), - Math.round(xpos * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0);*/ + // 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); // 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 - // TODO currently this test fails in the Jalview GUI because boxX is - // calculated - // based on the current boxWidth, which includes hidden columns, thereby - // pushing - // the box off the end of the alignment. So boxX is adjusted backwards - // unnecessarily. - /* xpos = 72; - testBoxIsAtClickPoint(xpos, 0); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), - Math.round(xpos * alwidth / od.getWidth()) - - lastHidden);*/ + xpos = 75; + testBoxIsAtClickPoint(xpos, 0); + assertEquals(od.getScrollRow(), 0); + assertEquals(od.getScrollCol(), + Math.round(xpos * alwidth / od.getWidth()) + - (lastHidden - firstHidden + 1)); // move box so it goes beyond full width of alignment // boxX, scrollCol adjusted back, box width normal @@ -586,18 +463,19 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenColsAtEnd() { - od.setBoxPositionByMouse(0, 0); + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, + posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getScrollCol(), 0); assertEquals(od.getScrollRow(), 0); - // hide columns 140-157, no change to box position or dimensions + // hide columns 140-164, no change to box position or dimensions int firstHidden = 140; - int lastHidden = 157; - hideColumns(firstHidden, lastHidden); - od.setBoxPosition(); + int lastHidden = 164; + hiddenCols.hideColumns(firstHidden, lastHidden); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -614,50 +492,43 @@ public class OverviewDimensionsTest { // click to left of hidden cols, with overlap // boxX and scrollCol adjusted for hidden cols, width normal - // TODO this fails because setBoxPosition screws up the hidden cols calc - // only works in GUI because of AlignmentPanel::setScrollValues - /*xpos = 115 - boxWidth; + xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth; mouseClick(od, xpos, 0); - assertEquals( - od.getBoxX(), - Math.round((firstHidden - 1) * scalew * av.getCharWidth()) - - od.getBoxWidth()); + 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 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); } /** @@ -710,7 +581,7 @@ public class OverviewDimensionsTest { { int firstHidden = 0; int lastHidden = 20; - hideColumns(firstHidden, lastHidden); + hiddenCols.hideColumns(firstHidden, lastHidden); // move viewport to start of alignment moveViewport(0, 0); @@ -737,9 +608,9 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testSetBoxFromViewportHiddenColsInMiddle() { - int firstHidden = 65; - int lastHidden = 75; - hideColumns(firstHidden, lastHidden); + int firstHidden = 68; + int lastHidden = 78; + hiddenCols.hideColumns(firstHidden, lastHidden); // move viewport before hidden columns moveViewport(3, 0); @@ -765,9 +636,9 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxHeight(), boxHeight); // move viewport to straddle hidden columns - moveViewport(60, 0); + moveViewport(63, 0); assertEquals(od.getBoxX(), - Math.round((float) 60 * od.getWidth() / alwidth)); + Math.round((float) 63 * od.getWidth() / alwidth)); assertEquals(od.getBoxY(), 0); assertEquals( od.getBoxWidth(), @@ -793,9 +664,9 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testSetBoxFromViewportHiddenColsAtEnd() { - int firstHidden = 145; - int lastHidden = 157; - hideColumns(firstHidden, lastHidden); + int firstHidden = 152; + int lastHidden = 164; + hiddenCols.hideColumns(firstHidden, lastHidden); // move viewport before hidden columns moveViewport(3, 0); @@ -806,14 +677,11 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxHeight(), boxHeight); // move viewport to hidden columns - // TODO boxwidth includes hidden in overview panel (why?) - moveViewport(98, 0); + moveViewport(102, 0); assertEquals(od.getBoxX(), - Math.round((float) 98 * od.getWidth() / alwidth)); + Math.round((float) 102 * od.getWidth() / alwidth)); assertEquals(od.getBoxY(), 0); - assertEquals( - od.getBoxWidth(), - boxWidth + assertEquals(od.getBoxWidth(), boxWidth + Math.round((float) (lastHidden - firstHidden + 1) * od.getWidth() / alwidth)); assertEquals(od.getBoxHeight(), boxHeight); @@ -828,7 +696,7 @@ public class OverviewDimensionsTest { { int firstHidden = 0; int lastHidden = 20; - hideSequences(firstHidden, lastHidden + 1, lastHidden + 1); + hideSequences(firstHidden, lastHidden); // move viewport to start of alignment: // box moves to below hidden rows, height remains same @@ -840,22 +708,15 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - // move viewport to end of alignment, need to account for hidden rows - // because of how alignment panel/overview panel are implemented - - // AlignViewport adjusts endSeq using Alignment height which excludes hidden - // rows if we happen to be at the bottom of the alignment - // od.setBoxPosition adjusts endSeq to include hidden rows - // od.checkValid adjusts scroll position to exclude hidden rows - // TODO this test fails because of the above! - - /* moveViewport(0, 525 - viewHeight - lastHidden - 1); - assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), - (525 - viewHeight) * scaleh - * av.getCharHeight()); - 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.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); } /** @@ -867,27 +728,26 @@ public class OverviewDimensionsTest { { int firstHidden = 200; int lastHidden = 210; - hideSequences(firstHidden, lastHidden + 1, lastHidden + 1); + hideSequences(firstHidden, lastHidden); // move viewport to start of alignment: // box, height etc as in non-hidden case - // TODO fails with boxy=12 because that's what setBoxPosition sets it to! - /*moveViewport(0, 0); + moveViewport(0, 0); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight);*/ + assertEquals(od.getBoxHeight(), boxHeight); // move viewport to straddle hidden rows - // TODO also fails with boxY out by 12 - /*moveViewport(0, 198); + moveViewport(0, 198); assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), Math.round (198 * scaleh * av.getCharHeight()), - 1.5); + assertEquals(od.getBoxY(), Math.round ((float)198 * od.getSequencesHeight() + / alheight)); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight - + ((lastHidden - firstHidden) * scaleh * av.getCharHeight()), - 1.5);*/ + assertEquals( + od.getBoxHeight(), + Math.round((float) (viewHeight + lastHidden - firstHidden + 1) + * od.getSequencesHeight() / alheight)); } /** @@ -899,7 +759,7 @@ public class OverviewDimensionsTest { { int firstHidden = 500; int lastHidden = 524; - hideSequences(firstHidden - 1, lastHidden, firstHidden - 1); + hideSequences(firstHidden, lastHidden); // move viewport to start of alignment: // box, height etc as in non-hidden case @@ -910,18 +770,15 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxHeight(), boxHeight); // move viewport to end of alignment - // TODO fails with wrong boxHeight who knows why - /*moveViewport(0, firstHidden - viewHeight - 1); - assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), - Math.round ((firstHidden - viewHeight - 1) - * scaleh * av.getCharHeight())); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals( - od.getBoxHeight(), - boxHeight - + Math.round ((lastHidden - firstHidden + 1) * scaleh * av - .getCharHeight()));*/ + // viewport sits above hidden rows and does not include them + moveViewport(0, firstHidden - viewHeight - 1); + assertEquals(od.getBoxX(), 0); + assertEquals( + od.getBoxY(), + Math.round((float) (firstHidden - viewHeight - 1) + * od.getSequencesHeight() / alheight)); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); } @@ -932,7 +789,8 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenRowsAtStart() { - od.setBoxPositionByMouse(0, 0); + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, + posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxHeight(), boxHeight); @@ -943,9 +801,9 @@ public class OverviewDimensionsTest { // hide rows at start and check updated box position is correct // changes boxY but not boxheight int lastHiddenRow = 30; - hideSequences(0, lastHiddenRow + 1, lastHiddenRow + 1); + hideSequences(0, lastHiddenRow); - od.setBoxPosition(); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1) @@ -953,15 +811,15 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - // click in hidden rows - // TODO fails because boxHeight is 27 not 25 (possible rounding issue) - /* mouseClick(od, 0, 0); - assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight - + Math.round ((lastHiddenRow + 1) * scaleh * av.getCharHeight()), - 1.5);*/ + // 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.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); // click below hidden rows mouseClick(od, 0, 150); @@ -978,7 +836,8 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenRowsInMiddle() { - od.setBoxPositionByMouse(0, 0); + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, + posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); @@ -990,10 +849,10 @@ public class OverviewDimensionsTest { // hide rows in middle and check updated box position is correct // no changes int firstHiddenRow = 50; - int lastHiddenRow = 60; - hideSequences(firstHiddenRow, lastHiddenRow + 1, lastHiddenRow + 1); + int lastHiddenRow = 54; + hideSequences(firstHiddenRow, lastHiddenRow); - od.setBoxPosition(); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); @@ -1001,34 +860,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)); } /** @@ -1038,7 +895,8 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenRowsAtEnd() { - od.setBoxPositionByMouse(0, 0); + od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols, + posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -1050,9 +908,9 @@ public class OverviewDimensionsTest { // no changes int firstHidden = 500; int lastHidden = 524; - hideSequences(firstHidden - 1, lastHidden, firstHidden - 1); + hideSequences(firstHidden, lastHidden); - od.setBoxPosition(); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -1070,29 +928,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); } /* @@ -1100,9 +957,9 @@ public class OverviewDimensionsTest { */ private void moveViewportH(int startRes) { - av.setStartRes(startRes); - av.setEndRes(startRes + viewWidth); - od.setBoxPosition(); + posProps.setStartRes(startRes); + posProps.setEndRes(startRes + viewWidth - 1); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); } /* @@ -1110,9 +967,9 @@ public class OverviewDimensionsTest { */ private void moveViewportV(int startSeq) { - av.setStartSeq(startSeq); - av.setEndSeq(startSeq + viewHeight); - od.setBoxPosition(); + posProps.setStartSeq(startSeq); + posProps.setEndSeq(startSeq + viewHeight - 1); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); } /* @@ -1120,11 +977,11 @@ public class OverviewDimensionsTest { */ private void moveViewport(int startRes, int startSeq) { - av.setStartRes(startRes); - av.setEndRes(startRes + viewWidth); - av.setStartSeq(startSeq); - av.setEndSeq(startSeq + viewHeight); - od.setBoxPosition(); + posProps.setStartRes(startRes); + posProps.setEndRes(startRes + viewWidth - 1); + posProps.setStartSeq(startSeq); + posProps.setEndSeq(startSeq + viewHeight - 1); + od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps); } /* @@ -1132,19 +989,24 @@ public class OverviewDimensionsTest { */ private void mouseClick(OverviewDimensions od, int x, int y) { - od.setBoxPositionByMouse(x, y); + od.updateViewportFromMouse(x, y, al.getHiddenSequences(), hiddenCols, + posProps); + // updates require an OverviewPanel to exist which it doesn't here // so call setBoxPosition() as it would be called by the AlignmentPanel // normally - // int width = av.getEndRes() - av.getStartRes(); - // int height = av.getEndSeq() - av.getStartSeq(); - av.setStartRes(od.getScrollCol()); - av.setEndRes(od.getScrollCol() + viewWidth); - av.setStartSeq(od.getScrollRow()); - av.setEndSeq(od.getScrollRow() + viewHeight); - od.setBoxPosition(); + + 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); } + /* + * Test that the box is positioned with the top left corner at xpos, ypos + * and with the original width and height + */ private void testBoxIsAtClickPoint(int xpos, int ypos) { mouseClick(od, xpos, ypos); @@ -1156,49 +1018,19 @@ public class OverviewDimensionsTest { } /* - * Hide sequences between start and end, using hideseq to do the hiding - * (start <= hideseq <= end. Sequence hideseq is not hidden but the others are + * Hide sequences between start and end */ - private void hideSequences(int start, int end, int hideseq) + private void hideSequences(int start, int end) { - SequenceGroup sg = new SequenceGroup(); - List allseqs = av.getAlignment().getSequences(); - for (int i = start; i <= end; ++i) - { - sg.addSequence(allseqs.get(i), false); - } - av.setSelectionGroup(sg); - - /* - * hide group - */ - av.hideSequences(allseqs.get(hideseq), true); - - while (av.isCalcInProgress()) + SequenceI[] allseqs = al.getSequencesArray(); + SequenceGroup theseSeqs = new SequenceGroup(); + + for (int i = start; i <= end; i++) { - try - { - Thread.sleep(50); - } catch (InterruptedException e) - { - System.out.println("Hiding seqs interruption"); - } + theseSeqs.addSequence(allseqs[i], false); + al.getHiddenSequences().hideSequence(allseqs[i]); } - } - private void hideColumns(int firstHidden, int lastHidden) - { - av.hideColumns(firstHidden, lastHidden); - - while (av.isCalcInProgress()) - { - try - { - Thread.sleep(50); - } catch (InterruptedException e) - { - System.out.println("Hiding cols interruption"); - } - } + hiddenRepSequences.put(allseqs[start], theseSeqs); } }