import jalview.bin.Jalview;
import jalview.datamodel.Alignment;
import jalview.datamodel.Sequence;
+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 org.testng.annotations.AfterClass;
+import java.util.List;
+
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+@Test(singleThreaded = true)
public class OverviewDimensionsTest {
boolean showConservationSetting;
"Seq5",
"ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
- SequenceI seq6 = new Sequence(
- "Seq6",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ AlignFrame af;
+ AlignViewport av;
+ OverviewDimensions od;
- SequenceI seq7 = new Sequence(
- "Seq7",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ float scalew;
+ float scaleh;
+ int boxWidth;
+ int boxHeight;
- SequenceI seq8 = new Sequence(
- "Seq8",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ int viewHeight;
- SequenceI seq9 = new Sequence(
- "Seq9",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq10 = new Sequence(
- "Seq10",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq11 = new Sequence(
- "Seq11",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq12 = new Sequence(
- "Seq12",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq13 = new Sequence(
- "Seq13",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
- SequenceI seq14 = new Sequence(
- "Seq14",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ @BeforeMethod(alwaysRun = true)
+ public void setUp()
+ {
+ Jalview.main(new String[] { "-nonews", "-props",
+ "test/jalview/testProps.jvprops" });
- SequenceI seq15 = new Sequence(
- "Seq15",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ 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)
+ {
+ while (af.getViewport().getEndRes() == 0)
+ {
+ try
+ {
+ wait(50);
+ } catch (InterruptedException e)
+ {
+ }
+ }
+ }
+
+ /*
+ * wait for Consensus thread to complete
+ */
+ synchronized (this)
+ {
+ while (af.getViewport().getConsensusSeq() == null)
+ {
+ try
+ {
+ wait(50);
+ } catch (InterruptedException e)
+ {
+ }
+ }
+ }
- SequenceI seq16 = new Sequence(
- "Seq16",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ // get cached setting for showConservation
+ // reset it in AfterClass!
+ showConservationSetting = Cache.getDefault("SHOW_CONSERVATION", true);
+
+ av = af.getViewport();
- SequenceI seq17 = new Sequence(
- "Seq17",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ if (av.isCalcInProgress())
+ {
- SequenceI seq18 = new Sequence(
- "Seq18",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ }
- SequenceI seq19 = new Sequence(
- "Seq19",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ od = new OverviewDimensions(av);
- SequenceI seq20 = new Sequence(
- "Seq20",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ while (av.isCalcInProgress())
+ {
+ try
+ {
+ Thread.sleep(50);
+ } catch (InterruptedException e)
+ {
+ System.out.println("Hiding cols interruption");
+ }
+ }
- SequenceI seq21 = new Sequence(
- "Seq21",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ // Initial box sizing - default path through code
+ od.setBoxPosition();
- SequenceI seq22 = new Sequence(
- "Seq22",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"
- + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"
- + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ scalew = (float) od.getWidth()
+ / (av.getAlignment().getWidth() * av.getCharWidth());
+ scaleh = (float) od.getSequencesHeight()
+ / (av.getAlignment().getHeight() * av.getCharHeight());
+ boxWidth = Math.round((av.getEndRes() - av.getStartRes() + 1)
+ * av.getCharWidth() * scalew);
+ boxHeight = Math.round((av.getEndSeq() - av.getStartSeq())
+ * av.getCharHeight() * scaleh);
- SequenceI seq23 = new Sequence(
- "Seq23",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
+ viewHeight = av.getEndSeq() - av.getStartSeq();
+ init();
+ }
- @BeforeClass(alwaysRun = true)
- public void setUp()
+ private void init()
{
- JvOptionPane.setInteractiveMode(false);
- JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ 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)
+ {
- Jalview.main(new String[] { "-nonews", "-props",
- "test/jalview/testProps.jvprops" });
+ }
+ }
- // get cached setting for showConservation
- // reset it in AfterClass!
- showConservationSetting = Cache.getDefault("SHOW_CONSERVATION", true);
+ mouseClick(od, 0, 0);
+ moveViewport(0, 0);
}
- @AfterClass(alwaysRun = true)
+ @AfterMethod(alwaysRun = true)
public void tearDown()
{
Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
Boolean.toString(showConservationSetting));
+ Desktop.instance.closeAll_actionPerformed(null);
}
/**
* correctly
*/
@Test(groups = { "Functional" })
- public void testConstructor()
- {
- SequenceI seqa = new Sequence("Seq1", "ABC");
- SequenceI seqb = new Sequence("Seq2", "ABC");
- SequenceI seqc = new Sequence("Seq3", "ABC");
- SequenceI seqd = new Sequence("Seq4", "ABC");
- SequenceI seqe = new Sequence("Seq5",
- "ABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- 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);
-
- OverviewDimensions od = new OverviewDimensions(av1);
- assertEquals(od.getGraphHeight(), 20);
- assertEquals(od.getSequencesHeight(), 266);
- assertEquals(od.getWidth(), 400);
- assertEquals(od.getHeight(), 286);
-
- // 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);
-
- od = new OverviewDimensions(av2);
- assertEquals(od.getGraphHeight(), 20);
- assertEquals(od.getSequencesHeight(), 300);
- assertEquals(od.getWidth(), 300);
- assertEquals(od.getHeight(), 320);
-
- // test for alignment with width > height and sequence height scaled below
- // min value
- SequenceI[] seqs3 = new SequenceI[] { seqe };
- Alignment al3 = new Alignment(seqs3);
- al3.setDataset(null);
- AlignViewport av3 = new AlignViewport(al3);
-
- od = new OverviewDimensions(av3);
- assertEquals(od.getGraphHeight(), 20);
- assertEquals(od.getSequencesHeight(), 40);
- assertEquals(od.getWidth(), 400);
- assertEquals(od.getHeight(), 60);
-
- // test for alignment with width < height and width scaled below min value
- 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);
-
- od = new OverviewDimensions(av4);
- assertEquals(od.getGraphHeight(), 20);
- assertEquals(od.getSequencesHeight(), 300);
- assertEquals(od.getWidth(), 120);
- assertEquals(od.getHeight(), 320);
-
- // 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);
-
- od = new OverviewDimensions(av5);
- assertEquals(od.getGraphHeight(), 0);
- assertEquals(od.getSequencesHeight(), 300);
- assertEquals(od.getWidth(), 120);
- assertEquals(od.getHeight(), 300);
- }
+ public void testConstructor()
+ {
+ SequenceI seqa = new Sequence("Seq1", "ABC");
+ SequenceI seqb = new Sequence("Seq2", "ABC");
+ SequenceI seqc = new Sequence("Seq3", "ABC");
+ SequenceI seqd = new Sequence("Seq4", "ABC");
+ SequenceI seqe = new Sequence("Seq5",
+ "ABCABCABCABCABCABCABCABCBACBACBACBAC");
+
+ int defaultGraphHeight = 20;
+ int maxWidth = 400;
+ int minWidth = 120;
+ 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);
+
+ OverviewDimensions od = new OverviewDimensions(av1);
+ int scaledHeight = 266;
+ assertEquals(od.getGraphHeight(), defaultGraphHeight);
+ assertEquals(od.getSequencesHeight(), scaledHeight);
+ assertEquals(od.getWidth(), maxWidth);
+ assertEquals(od.getHeight(), scaledHeight + defaultGraphHeight);
+
+ // 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);
+
+ od = new OverviewDimensions(av2);
+ int scaledWidth = 300;
+ assertEquals(od.getGraphHeight(), defaultGraphHeight);
+ assertEquals(od.getSequencesHeight(), maxSeqHeight);
+ assertEquals(od.getWidth(), scaledWidth);
+ assertEquals(od.getHeight(), scaledWidth + defaultGraphHeight);
+
+ // test for alignment with width > height and sequence height scaled below
+ // min value
+ SequenceI[] seqs3 = new SequenceI[] { seqe };
+ Alignment al3 = new Alignment(seqs3);
+ al3.setDataset(null);
+ AlignViewport av3 = new AlignViewport(al3);
+
+ od = new OverviewDimensions(av3);
+ assertEquals(od.getGraphHeight(), defaultGraphHeight);
+ assertEquals(od.getSequencesHeight(), minSeqHeight);
+ assertEquals(od.getWidth(), maxWidth);
+ assertEquals(od.getHeight(), minSeqHeight + defaultGraphHeight);
+
+ // test for alignment with width < height and width scaled below min value
+ 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);
+
+ od = new OverviewDimensions(av4);
+ 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);
+
+ od = new OverviewDimensions(av5);
+ assertEquals(od.getGraphHeight(), 0);
+ assertEquals(od.getSequencesHeight(), maxSeqHeight);
+ assertEquals(od.getWidth(), minWidth);
+ assertEquals(od.getHeight(), maxSeqHeight);
+ }
/**
* 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
+ * 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 checkValidNoHidden()
+ public void testSetBoxFromMouseClick()
{
- seq23.setStart(386);
- SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5,
- seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15,
- seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 };
- Alignment al = new Alignment(seqs);
- al.setDataset(null);
- AlignViewport av = new AlignViewport(al);
-
- // Initial box sizing - default path through code
- OverviewDimensions od = new OverviewDimensions(av);
- od.setBoxPosition();
- od.checkValid();
+ od.setBoxPositionByMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
- assertEquals(od.getBoxWidth(), 399);
+ assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getScrollCol(), 0);
assertEquals(od.getScrollRow(), 0);
// negative boxX value reset to 0
- od.setBoxX(-5);
- od.checkValid();
+ mouseClick(od, -5, 10);
assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollRow(),
+ Math.round(10 / scaleh / av.getCharHeight()));
+ assertEquals(od.getScrollCol(), 0);
// negative boxY value reset to 0
- od.setBoxY(-2);
- od.checkValid();
+ mouseClick(od, 6, -2);
assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(),
+ Math.round(6 / scalew / av.getCharWidth()));
+ assertEquals(od.getScrollRow(), 0);
// overly large boxX value reset to width-boxWidth
- od.setBoxX(100);
- od.checkValid();
- assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
-
- // startRes non-zero
- av.setStartRes(50);
- OverviewDimensions od2 = new OverviewDimensions(av);
- od2.setBoxPosition();
- od2.checkValid();
- assertEquals(od2.getBoxX(), 61);
- assertEquals(od2.getScrollCol(), 49);
+ mouseClick(od, 100, 6);
+ assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth(), 1.5);
+ assertEquals(od.getBoxY(), 6, 1.5);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(),
+ (od.getBoxX() / scalew / av.getCharWidth()), 1.5);
+ assertEquals(od.getScrollRow(),
+ (od.getBoxY() / scaleh / av.getCharHeight()), 1.5);
+
+ // overly large boxY value reset to sequenceHeight - boxHeight
+ mouseClick(od, 10, 520);
+ assertEquals(od.getBoxX(), 10, 1.5);
+ assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight(),
+ 1.5);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight, 1.5);
+ assertEquals(od.getScrollCol(),
+ (od.getBoxX() / scalew / av.getCharWidth()), 1.5);
+ assertEquals(od.getScrollRow(),
+ (od.getBoxY() / scaleh / av.getCharHeight()), 1.5);
+
+ // click past end of alignment, as above
+ mouseClick(od, 3000, 5);
+ assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth(), 1.5);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight, 1.5);
+ assertEquals(od.getScrollCol(),
+ (od.getBoxX() / scalew / av.getCharWidth()), 1.5);
+ assertEquals(od.getScrollRow(),
+ (od.getBoxY() / scaleh / av.getCharHeight()), 1.5);
+
+ // move viewport so startRes non-zero and then mouseclick
+ moveViewportH(50);
+
+ // 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, 1.5);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight, 1.5);
+ assertEquals(od.getScrollCol(),
+ (od.getBoxX() / scalew / av.getCharWidth()), 1.5);
+ assertEquals(od.getBoxY(), oldboxy + 2, 1.5);
+ assertEquals(od.getScrollRow(),
+ (od.getBoxY() / scaleh / av.getCharHeight()), 1.5);
+
+ // click at top corner
+ mouseClick(od, 0, 0);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getScrollCol(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getScrollRow(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight, 1.5);
}
/**
* of the alignment
*/
@Test(groups = { "Functional" })
- public void testSetBoxPosWithHiddenColsAtStart()
+ public void testFromMouseWithHiddenColsAtStart()
{
- seq23.setStart(386);
- SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5,
- seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15,
- seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 };
- Alignment al = new Alignment(seqs);
- al.setDataset(null);
- AlignViewport av = new AlignViewport(al);
+ od.setBoxPositionByMouse(0, 0);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getScrollCol(), 0);
+ assertEquals(od.getScrollRow(), 0);
- av.setStartRes(50);
- OverviewDimensions od = new OverviewDimensions(av);
+ // hide cols at start and check updated box position is correct
+ // changes boxX but not boxwidth
+ int lastHiddenCol = 30;
+ hideColumns(0, lastHiddenCol);
- // hiding columns before current position: changes boxX but not scrollCol or
- // boxwidth
+ od.setBoxPosition();
+ assertEquals(od.getBoxX(),
+ Math.round((lastHiddenCol + 1) * scalew * av.getCharWidth()));
+ assertEquals(od.getBoxWidth(), boxWidth);
+ 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) * scalew * av.getCharWidth()));
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollRow(), 0);
+ assertEquals(od.getScrollCol(),
+ Math.round (xpos / scalew / av.getCharWidth()));
+ */
+ // click to right of hidden columns, box moves to click point
+ testBoxIsAtClickPoint(40, 0);
+ assertEquals(od.getScrollRow(), 0);
+ assertEquals(od.getScrollCol(),
+ Math.round(40 / scalew / av.getCharWidth())
+ - lastHiddenCol,
+ 1.5);
+
+ // click to right of hidden columns such that box runs over right hand side
+ // of alignment
+ // box position is adjusted away from the edge
+ // overly large boxX value reset to width-boxWidth
+ int xpos = 100;
+ mouseClick(od, xpos, 5);
+ assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth(), 1.5);
+ assertEquals(od.getBoxY(), 5);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(),
+ Math.round(od.getBoxX() / scalew / av.getCharWidth())
+ - lastHiddenCol, 1.5);
+ assertEquals(od.getScrollRow(),
+ Math.round(od.getBoxY() / scaleh / av.getCharHeight()));
+
+ }
+
+ /**
+ * Test setting of the box position, when there are hidden cols in the middle
+ * of the alignment
+ */
+ @Test(groups = { "Functional" })
+ public void testFromMouseWithHiddenColsInMiddle()
+ {
+ od.setBoxPositionByMouse(0, 0);
+ 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);
- // do a reset
- av.showAllHiddenColumns();
od.setBoxPosition();
- od.checkValid();
- int prevWidth = od.getBoxWidth();
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getScrollCol(), 0);
+ assertEquals(od.getScrollRow(), 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 = 50 - boxWidth; // 50 is position in overview halfway between cols
+ // 60 and 70
+ mouseClick(od, xpos, 0);
+ assertEquals(od.getBoxX(), xpos);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(
+ od.getBoxWidth(),
+ Math.round(boxWidth + (lastHidden - firstHidden + 1) * scalew
+ * av.getCharWidth()));
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(),
+ Math.round(xpos / scalew / av.getCharWidth()));
+ assertEquals(od.getScrollRow(), 0);
- // hide cols at start and check updated box position is correct
- // changes boxX but not scrollCol or boxwidth
- int lastHiddenCol = 50;
- av.hideColumns(0, 50);
+ // move box so that it completely covers hidden cols
+ // box width changes, boxX and scrollCol as for hidden case
+ xpos = 30;
+ mouseClick(od, xpos, 0);
+ assertEquals(od.getBoxX(), xpos);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(
+ od.getBoxWidth(),
+ Math.round(boxWidth + (lastHidden - firstHidden + 1) * scalew
+ * av.getCharWidth()));
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(),
+ Math.round(xpos / scalew / av.getCharWidth()), 1.5);
+ 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(), 1.5);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(),
+ Math.round(xpos / scalew / av.getCharWidth()), 1.5);
+ 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 / scalew / av.getCharWidth())
+ - lastHidden, 1.5);*/
+
+ // 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(), 1.5);
+ assertEquals(od.getBoxY(), 5);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(),
+ Math.round((od.getBoxX() / scalew / av.getCharWidth())
+ - (lastHidden - firstHidden + 1)));
+ assertEquals(od.getScrollRow(),
+ Math.round(od.getBoxY() / scaleh / av.getCharHeight()));
+
+ }
+
+ /**
+ * Test setting of the box position, when there are hidden cols at the end of
+ * the alignment
+ */
+ @Test(groups = { "Functional" })
+ public void testFromMouseWithHiddenColsAtEnd()
+ {
+ od.setBoxPositionByMouse(0, 0);
+ 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
+ int firstHidden = 140;
+ int lastHidden = 157;
+ hideColumns(firstHidden, lastHidden);
od.setBoxPosition();
- assertEquals(od.getBoxX(), 124);
- assertEquals(od.getScrollCol(), lastHiddenCol - 1);
- assertEquals(od.getBoxWidth(), prevWidth);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getScrollCol(), 0);
+ assertEquals(od.getScrollRow(), 0);
- // set the box position by moving viewport & check it goes to the right
- // place
+ // 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(xpos / scalew / av.getCharWidth()), 1.5);
+
+ // 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;
+ mouseClick(od, xpos, 0);
+ assertEquals(
+ od.getBoxX(),
+ Math.round((firstHidden - 1) * scalew * av.getCharWidth())
+ - od.getBoxWidth(), 1.5);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(),
+ Math.round(od.getBoxX() / scalew / av.getCharWidth()), 1.5);
+ 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(), 1.5);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(),
+ Math.round(od.getBoxX() / scalew / av.getCharWidth()), 1.5);
+ 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(), 1.5);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(),
+ Math.round(od.getBoxX() / scalew / av.getCharWidth()), 1.5);
+ assertEquals(od.getScrollRow(), 0);*/
+ }
+
+ /**
+ * Test that the box position is set correctly when set from the viewport,
+ * with no hidden rows or columns
+ */
+ @Test(groups = { "Functional" })
+ public void testSetBoxFromViewport()
+ {
+ // move viewport to start of alignment
+ moveViewport(0, 0);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
- // update the box position via mouse and check it goes to the right place
+ // move viewport to right
+ moveViewportH(70);
+ assertEquals(od.getBoxX(), Math.round(70 * scalew * av.getCharWidth()));
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+
+ // move viewport down
+ moveViewportV(100);
+ assertEquals(od.getBoxX(), Math.round(70 * scalew * av.getCharWidth()));
+ assertEquals(od.getBoxY(),
+ Math.round(100 * scaleh * av.getCharHeight()));
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+
+ // move viewport to bottom right
+ moveViewport(98, 508);
+ assertEquals(od.getBoxX(), Math.round(98 * scalew * av.getCharWidth()));
+ assertEquals(od.getBoxY(),
+ Math.round(508 * scaleh * av.getCharHeight()));
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight);
}
+ /**
+ * Test that the box position is set correctly when there are hidden columns
+ * at the start
+ */
@Test(groups = { "Functional" })
- public void testSetBoxPosWithHiddenColsAtEnd()
+ public void testSetBoxFromViewportHiddenColsAtStart()
{
+ int firstHidden = 0;
+ int lastHidden = 20;
+ hideColumns(firstHidden, lastHidden);
+
+ // move viewport to start of alignment
+ moveViewport(0, 0);
+ assertEquals(od.getBoxX(),
+ Math.round((lastHidden + 1) * scalew * av.getCharWidth()));
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ // move viewport to end of alignment - need to make startRes by removing
+ // hidden cols because of how viewport/overview are implemented
+ moveViewport(98 - lastHidden - 1, 0);
+ assertEquals(od.getBoxX(), Math.round(98 * scalew * av.getCharWidth()));
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
}
+ /**
+ * Test that the box position is set correctly when there are hidden columns
+ * in the middle
+ */
@Test(groups = { "Functional" })
- public void testSetBoxPosWithHiddenColsMiddle()
+ public void testSetBoxFromViewportHiddenColsInMiddle()
{
- seq23.setStart(386);
- SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5,
- seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15,
- seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 };
- Alignment al = new Alignment(seqs);
- al.setDataset(null);
- AlignViewport av = new AlignViewport(al);
-
- av.setStartRes(50);
- OverviewDimensions od = new OverviewDimensions(av);
-
- // hiding columns after current position: changes end position but not start
- // so scrollCol and boxX do not change but boxWidth does
- float scalew = od.getWidth() / al.getWidth();
- int prevWidth = od.getBoxWidth();
- int prevX = od.getBoxX();
- av.hideColumns(108, 110);
- od.setBoxPosition();
- assertEquals(od.getBoxX(), prevX);
- assertEquals(od.getScrollCol(), 49);
- // assertEquals(od2.getBoxWidth(), prevWidth + ((int) 2 * av.getCharWidth()
- // / scalew));
+ int firstHidden = 65;
+ int lastHidden = 75;
+ hideColumns(firstHidden, lastHidden);
+
+ // move viewport before hidden columns
+ moveViewport(3, 0);
+
+ assertEquals(od.getBoxX(), Math.round(3 * scalew * av.getCharWidth()));
+ assertEquals(od.getBoxY(), 0);
+ System.out.println(od.getBoxWidth());
+ assertEquals(od.getBoxWidth(), boxWidth);
+ System.out.println(od.getBoxWidth());
+ assertEquals(od.getBoxHeight(), boxHeight);
+
+ // move viewport to left of hidden columns with overlap
+ moveViewport(10, 0);
+ assertEquals(od.getBoxX(), Math.round(10 * scalew * av.getCharWidth()));
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(
+ od.getBoxWidth(),
+ boxWidth
+ + Math.round((lastHidden - firstHidden + 1) * scalew
+ * av.getCharWidth()));
+ assertEquals(od.getBoxHeight(), boxHeight);
+
+ // move viewport to straddle hidden columns
+ moveViewport(60, 0);
+ assertEquals(od.getBoxX(), Math.round(60 * scalew * av.getCharWidth()));
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(
+ od.getBoxWidth(),
+ boxWidth
+ + Math.round((lastHidden - firstHidden + 1) * scalew
+ * av
+.getCharWidth()));
+ assertEquals(od.getBoxHeight(), boxHeight);
+
+ // move viewport to right of hidden columns, no overlap
+ moveViewport(80 - (lastHidden - firstHidden + 1), 0);
+ assertEquals(od.getBoxX(), Math.round(80 * scalew * av.getCharWidth()));
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+
}
+ /**
+ * Test that the box position is set correctly when there are hidden columns
+ * at the end
+ */
@Test(groups = { "Functional" })
- public void testSetBoxPosWithHiddenRowsAtStart()
+ public void testSetBoxFromViewportHiddenColsAtEnd()
{
- seq23.setStart(386);
- SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5,
- seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15,
- seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 };
- Alignment al = new Alignment(seqs);
- al.setDataset(null);
- AlignViewport av = new AlignViewport(al);
-
- av.setStartRes(50);
- OverviewDimensions od = new OverviewDimensions(av);
-
- // account for hidden rows
- SequenceI[] hidden = { seq2, seq3, seq4, seq5, seq6, seq7 };
- av.showAllHiddenColumns();
- av.hideSequence(hidden);
- od.checkValid();
+ int firstHidden = 145;
+ int lastHidden = 157;
+ hideColumns(firstHidden, lastHidden);
+
+ // move viewport before hidden columns
+ moveViewport(3, 0);
+ assertEquals(od.getBoxX(), Math.round(3 * scalew * av.getCharWidth()),
+ 1.5);
assertEquals(od.getBoxY(), 0);
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+
+ // move viewport to hidden columns
+ // TODO boxwidth includes hidden in overview panel (why?)
+ moveViewport(98, 0);
+ assertEquals(od.getBoxX(), Math.round(98 * scalew * av.getCharWidth()),
+ 1.5);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(
+ od.getBoxWidth(),
+ boxWidth
+ + Math.round((lastHidden - firstHidden + 1) * scalew
+ * av.getCharWidth()), 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight);
}
- /**
- * Test that the box position is set correctly
- */
+ /**
+ * Test that the box position is set correctly when there are hidden rows at
+ * the start
+ */
@Test(groups = { "Functional" })
- public void setBoxPosition()
- {
+ public void testSetBoxFromViewportHiddenRowsAtStart()
+ {
+ int firstHidden = 0;
+ int lastHidden = 20;
+ hideSequences(firstHidden, lastHidden + 1, lastHidden + 1);
+
+ // move viewport to start of alignment:
+ // box moves to below hidden rows, height remains same
+ moveViewport(0, 0);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(),
+ Math.round((lastHidden + 1) * scaleh * av.getCharHeight()));
+ 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(), 1.5);
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight, 1.5);*/
+ }
+
+ /**
+ * Test that the box position is set correctly when there are hidden rows in
+ * the middle
+ */
+ @Test(groups = { "Functional" })
+ public void testSetBoxFromViewportHiddenRowsInMiddle()
+ {
+ int firstHidden = 200;
+ int lastHidden = 210;
+ hideSequences(firstHidden, lastHidden + 1, lastHidden + 1);
+
+ // 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);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight, 1.5);*/
+
+ // move viewport to straddle hidden rows
+ // TODO also fails with boxY out by 12
+ /*moveViewport(0, 198);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), Math.round (198 * scaleh * av.getCharHeight()),
+ 1.5);
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight
+ + ((lastHidden - firstHidden) * scaleh * av.getCharHeight()),
+ 1.5);*/
+ }
+
+ /**
+ * Test that the box position is set correctly when there are hidden rows at
+ * the bottom
+ */
+ @Test(groups = { "Functional" })
+ public void testSetBoxFromViewportHiddenRowsAtEnd()
+ {
+ int firstHidden = 500;
+ int lastHidden = 524;
+ hideSequences(firstHidden - 1, lastHidden, firstHidden - 1);
+
+ // move viewport to start of alignment:
+ // box, height etc as in non-hidden case
+ moveViewport(0, 0);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ 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()), 1.5);
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(
+ od.getBoxHeight(),
+ boxHeight
+ + Math.round ((lastHidden - firstHidden + 1) * scaleh * av
+ .getCharHeight()), 1.5);*/
- SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5,
- seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15,
- seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 };
- Alignment al = new Alignment(seqs);
- al.setDataset(null);
- AlignViewport av = new AlignViewport(al);
+ }
- // Test box is in expected location when there are no hidden rows or columns
+ /**
+ * Test setting of the box position, when there are hidden rows at the start
+ * of the alignment
+ */
+ @Test(groups = { "Functional" })
+ public void testFromMouseWithHiddenRowsAtStart()
+ {
+ od.setBoxPositionByMouse(0, 0);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getScrollCol(), 0);
+ assertEquals(od.getScrollRow(), 0);
- OverviewDimensions od = new OverviewDimensions(av);
- od.setBoxPosition();
+ // 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);
- assertEquals(od.getBoxHeight(), 81);
- assertEquals(od.getBoxWidth(), 400);
+ od.setBoxPosition();
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(),
+ Math.round((lastHiddenRow + 1) * scaleh * av.getCharHeight()));
+ 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, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight
+ + Math.round ((lastHiddenRow + 1) * scaleh * av.getCharHeight()),
+ 1.5);*/
- // Account for hidden rows
- SequenceI[] hidden = { seq2, seq3, seq4 };
- av.hideSequence(hidden);
+ // click below hidden rows
+ mouseClick(od, 0, 150);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 150, 1.5);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ }
- OverviewDimensions od1 = new OverviewDimensions(av);
- od1.setBoxPosition();
+ /**
+ * Test setting of the box position, when there are hidden rows at the middle
+ * of the alignment
+ */
+ @Test(groups = { "Functional" })
+ public void testFromMouseWithHiddenRowsInMiddle()
+ {
+ assertEquals(od.getBoxHeight(), 10);
+
+ od.setBoxPositionByMouse(0, 0);
+
+ assertEquals(od.getBoxHeight(), 10);
+
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(), 0);
+ assertEquals(od.getScrollRow(), 0);
- assertEquals(od1.getBoxHeight(), 80);
- assertEquals(od1.getBoxWidth(), 400);
- assertEquals(od1.getBoxX(), 0);
- assertEquals(od1.getBoxY(), 0);
+ // hide rows in middle and check updated box position is correct
+ // no changes
+ int firstHiddenRow = 50;
+ int lastHiddenRow = 60;
+ assertEquals(od.getBoxHeight(), 10);
+ hideSequences(firstHiddenRow, lastHiddenRow + 1, lastHiddenRow + 1);
+ assertEquals(od.getBoxHeight(), 10);
+
+ od.setBoxPosition();
+ assertEquals(od.getBoxHeight(), 10);
+
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ 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 / scaleh / av.getCharHeight()));
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), Math.round (ypos / scaleh / av.getCharHeight()),
+ 1.5);
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(
+ od.getBoxHeight(),
+ boxHeight
+ + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
+ .getCharHeight()), 1.5);
+ */
+ // 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 / scaleh / av.getCharHeight()));
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), Math.round (ypos / scaleh / av.getCharHeight()),
+ 1.5);
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(
+ od.getBoxHeight(),
+ boxHeight
+ + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
+ .getCharHeight()), 1.5);*/
+ }
- // Account for hidden columns
- av.hideColumns(10, 15);
- av.showAllHiddenSeqs();
+ /**
+ * Test setting of the box position, when there are hidden rows at the end of
+ * the alignment
+ */
+ @Test(groups = { "Functional" })
+ public void testFromMouseWithHiddenRowsAtEnd()
+ {
+ od.setBoxPositionByMouse(0, 0);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getScrollCol(), 0);
+ assertEquals(od.getScrollRow(), 0);
- OverviewDimensions od2 = new OverviewDimensions(av);
- od2.setBoxPosition();
+ // hide rows at end and check updated box position is correct
+ // no changes
+ int firstHidden = 500;
+ int lastHidden = 524;
+ hideSequences(firstHidden - 1, lastHidden, firstHidden - 1);
- assertEquals(od2.getBoxHeight(), 81);
- assertEquals(od2.getBoxWidth(), 422);
- assertEquals(od2.getBoxX(), 0);
- assertEquals(od2.getBoxY(), 0);
+ od.setBoxPosition();
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
- // Account for hidden rows and cols
- av.hideSequence(hidden);
- OverviewDimensions od3 = new OverviewDimensions(av);
- od3.setBoxPosition();
+ // click above hidden rows
+ int ypos = 40; // row 40
+ mouseClick(od, 0, Math.round(ypos * scaleh * av.getCharHeight()));
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(),
+ Math.round(ypos * scaleh * av.getCharHeight()));
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+
+ // 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, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight, 1.5);*/
+
+ // click within hidden rows
+ ypos = 505;
+ // TODO: fails with wrong boxHeight - correction done by setScrollValues(?)
+ /*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, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight, 1.5);*/
+ }
- assertEquals(od3.getBoxHeight(), 80);
- assertEquals(od3.getBoxWidth(), 422);
- assertEquals(od3.getBoxX(), 0);
- assertEquals(od3.getBoxY(), 0);
+ /*
+ * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
+ */
+ private void moveViewportH(int startRes)
+ {
+ int width = av.getEndRes() - av.getStartRes();
+ av.setStartRes(startRes);
+ av.setEndRes(startRes + width);
+ od.setBoxPosition();
+ }
+
+ /*
+ * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
+ */
+ private void moveViewportV(int startSeq)
+ {
+ av.setStartSeq(startSeq);
+ av.setEndSeq(startSeq + viewHeight);
+ od.setBoxPosition();
+ }
+
+ /*
+ * Move viewport horizontally and vertically.
+ */
+ private void moveViewport(int startRes, int startSeq)
+ {
+ int width = av.getEndRes() - av.getStartRes();
+
+ av.setStartRes(startRes);
+ av.setEndRes(startRes + width);
+ av.setStartSeq(startSeq);
+ av.setEndSeq(startSeq + viewHeight);
+ od.setBoxPosition();
+ }
+
+ /*
+ * Mouse click as position x,y in overview window
+ */
+ private void mouseClick(OverviewDimensions od, int x, int y)
+ {
+ od.setBoxPositionByMouse(x, y);
+ // 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() + width);
+ av.setStartSeq(od.getScrollRow());
+ av.setEndSeq(od.getScrollRow() + height);
+ od.setBoxPosition();
+ }
+
+ private void testBoxIsAtClickPoint(int xpos, int ypos)
+ {
+ mouseClick(od, xpos, ypos);
+ assertEquals(od.getBoxX(), xpos, 1.5);
+ assertEquals(od.getBoxY(), ypos, 1.5);
+ assertEquals(od.getBoxWidth(), boxWidth, 1.5);
+ assertEquals(od.getBoxHeight(), boxHeight, 1.5);
+
+ }
+
+ /*
+ * Hide sequences between start and end, using hideseq to do the hiding
+ * (start <= hideseq <= end. Sequence hideseq is not hidden but the others are
+ */
+ private void hideSequences(int start, int end, int hideseq)
+ {
+ SequenceGroup sg = new SequenceGroup();
+ List<SequenceI> 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())
+ {
+ try
+ {
+ Thread.sleep(50);
+ } catch (InterruptedException e)
+ {
+ System.out.println("Hiding seqs interruption");
+ }
+ }
+ }
+
+ 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");
+ }
+ }
}
}