package jalview.viewmodel;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
import jalview.analysis.AlignmentGenerator;
import jalview.datamodel.Alignment;
assertEquals(od.getBoxHeight(), boxHeight);
}
+ /**
+ * Test the function to determine if a point is in the overview's box or not
+ */
+ @Test(groups = { "Functional" })
+ public void testPositionInBox()
+ {
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+
+ assertFalse(od.isPositionInBox(0, 0));
+ assertTrue(od.isPositionInBox(10, 9));
+ assertFalse(od.isPositionInBox(0, 9));
+ assertFalse(od.isPositionInBox(9, 0));
+ assertFalse(od.isPositionInBox(75, 20));
+
+ assertTrue(od.isPositionInBox(47, 6));
+ assertFalse(od.isPositionInBox(48, 6));
+ assertTrue(od.isPositionInBox(47, 9));
+ assertFalse(od.isPositionInBox(47, 10));
+
+ // hide columns in the box area
+ // extends area where a point is considered to be in the box
+ hiddenCols.hideColumns(1, 4);
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+ assertFalse(od.isPositionInBox(0, 0));
+ assertTrue(od.isPositionInBox(10, 9));
+ assertFalse(od.isPositionInBox(0, 9));
+ assertFalse(od.isPositionInBox(9, 0));
+ assertFalse(od.isPositionInBox(75, 20));
+
+ assertTrue(od.isPositionInBox(47, 6));
+ assertTrue(od.isPositionInBox(48, 6));
+ assertTrue(od.isPositionInBox(47, 9));
+ assertFalse(od.isPositionInBox(47, 10));
+
+ // hide sequences in box area
+ // extends area where a point is considered to be in the box
+ hideSequences(1, 3);
+ ColumnSelection cs = new ColumnSelection();
+ hiddenCols.revealAllHiddenColumns(cs);
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+ assertFalse(od.isPositionInBox(0, 0));
+ assertTrue(od.isPositionInBox(10, 9));
+ assertFalse(od.isPositionInBox(0, 9));
+ assertFalse(od.isPositionInBox(9, 0));
+ assertFalse(od.isPositionInBox(75, 20));
+
+ assertTrue(od.isPositionInBox(47, 6));
+ assertFalse(od.isPositionInBox(48, 6));
+ assertTrue(od.isPositionInBox(47, 9));
+ assertTrue(od.isPositionInBox(47, 10));
+ }
+
+ /**
+ * Test the dragging functionality
+ */
+ @Test(groups = { "Functional" })
+ public void testDragging()
+ {
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+ od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
+ od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
+
+ // updates require an OverviewPanel to exist which it doesn't here
+ // so call setBoxPosition() as it would be called by the AlignmentPanel
+ // normally
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+
+ // corner moves 16 (20-4) right and 6 (22-16) up
+ assertEquals(od.getBoxX(), 16);
+ assertEquals(od.getBoxY(), 6);
+
+ // hide columns - box moves drag distance + hidden cols, vertically makes no
+ // difference
+ hiddenCols.hideColumns(1, 4);
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+ od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
+ od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+
+ // corner moves 16 (20-4) + hiddenCols right and 6 (22-16) down
+ assertEquals(od.getBoxX(),
+ 16 + Math.round((float) 4 * od.getWidth() / alwidth));
+ assertEquals(od.getBoxY(), 6);
+
+ // hide sequences in box area
+ // makes absolutely no difference
+ hideSequences(1, 3);
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+ od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
+ od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+
+ // corner moves 16 (20-4) + hiddenCols right and 6 (22-16) + hiddenRows down
+ assertEquals(od.getBoxX(),
+ 16 + Math.round((float) 4 * od.getWidth() / alwidth));
+ assertEquals(od.getBoxY(),
+ 6 + Math.round((float) 3 * od.getHeight() / alheight));
+ }
+
/*
* Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
*/
hiddenRepSequences.put(allseqs[start], theseSeqs);
}
+
+ /**
+ * Test setting of the box position, when there are hidden rows at the start
+ * of the alignment
+ */
+ @Test(groups = { "Functional" })
+ public void testFromMouseWithHiddenRowsAtStartWrapped()
+ {
+ vpranges.setWrappedMode(true);
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(vpranges.getStartRes(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
+
+ // hide rows at start and check updated box position is correct
+ // changes boxY but not boxheight
+ int lastHiddenRow = 30;
+ hideSequences(0, lastHiddenRow);
+
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(),
+ Math.round((float) (lastHiddenRow + 1)
+ * od.getSequencesHeight() / alheight));
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+
+ // click in hidden rows - same result
+ mouseClick(od, 0, 0);
+ assertEquals(od.getBoxX(), 0);
+ int boxY = od.getBoxY();
+ assertEquals(
+ boxY,
+ Math.round((float) (lastHiddenRow + 1)
+ * od.getSequencesHeight() / alheight));
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+
+ // click below hidden rows
+ // vertical move of overview box is suppressed in wrapped mode
+ mouseClick(od, 0, 150);
+ assertEquals(od.getBoxX(), 0);
+ assertEquals(od.getBoxY(), boxY); // unchanged
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ }
}