* Calculate wrapped start residue from visible start residue
*
* @param res
- * absolute start residue
+ * visible start residue
* @return left column of panel res will be located in
*/
private int calcWrappedStartResidue(int res)
int oldStartRes = startRes;
int width = getViewportWidth();
- /*if (res >= oldStartRes && res < oldStartRes + width)
- {
- return false;
- }*/
-
boolean up = res < oldStartRes;
int widthsToScroll = Math.abs((res - oldStartRes) / width);
if (up)
* Set the viewport location so that a position is visible
*
* @param x
- * column to be visible
+ * column to be visible: absolute position in alignment
* @param y
- * row to be visible
+ * row to be visible: absolute position in alignment
*/
public boolean setViewportLocation(int x, int y)
{
boolean changedLocation = false;
- // convert the x,y location to absolute values
+ // convert the x,y location to visible coordinates
int visX = al.getHiddenColumns().findColumnPosition(x);
int visY = al.getHiddenSequences().findIndexWithoutHiddenSeqs(y);
else
{
// set the viewport x location to contain vis_x
+ int newstartres = visX;
int width = getViewportWidth();
- updateStartEndRes(visX, visX + width - 1);
+ if (newstartres + width - 1 > getVisibleAlignmentWidth() - 1)
+ {
+ newstartres = getVisibleAlignmentWidth() - width;
+ }
+ updateStartEndRes(newstartres, newstartres + width - 1);
// set the viewport y location to contain vis_y
- int startseq = visY;
+ int newstartseq = visY;
int height = getViewportHeight();
- if (startseq + height - 1 > getVisibleAlignmentHeight() - 1)
+ if (newstartseq + height - 1 > getVisibleAlignmentHeight() - 1)
{
- startseq = getVisibleAlignmentHeight() - height;
+ newstartseq = getVisibleAlignmentHeight() - height;
}
- updateStartEndSeq(startseq,
- startseq + height - 1);
+ updateStartEndSeq(newstartseq, newstartseq + height - 1);
newresseq = new int[] { startRes, startSeq };
}
assertEquals(vr.getEndRes(), 52);
}
- // leave until JAL-2388 is merged and we can do without viewport
- /*@Test(groups = { "Functional" })
+ @Test(groups = { "Functional" })
public void testScrollToVisible()
{
ViewportRanges vr = new ViewportRanges(al);
vr.setViewportStartAndWidth(12,5);
vr.setViewportStartAndHeight(10,6);
- vr.scrollToVisible(13,14)
+ vr.scrollToVisible(13, 14);
// no change
assertEquals(vr.getStartRes(), 12);
assertEquals(vr.getStartSeq(), 6);
// test for hidden columns too
- }*/
+ al.getHiddenColumns().hideColumns(1, 3);
+ vr.scrollToVisible(13, 3);
+ assertEquals(vr.getStartRes(), 6);
+ assertEquals(vr.getStartSeq(), 3);
+
+ vr.scrollToVisible(2, 9);
+ assertEquals(vr.getStartRes(), 0);
+ assertEquals(vr.getStartSeq(), 4);
+ }
@Test(groups = { "Functional" })
public void testEventFiring()
assertEquals(vr.getStartSeq(), 1);
assertEquals(vr.getStartRes(), 43);
}
+
+ @Test(groups = { "Functional" })
+ public void testSetViewportLocation()
+ {
+ AlignmentI al2 = gen.generate(60, 80, 1, 0, 0);
+
+ ViewportRanges vr = new ViewportRanges(al2);
+
+ // start with viewport on 5-14
+ vr.setViewportStartAndWidth(5, 10);
+ assertEquals(vr.getStartRes(), 5);
+ assertEquals(vr.getEndRes(), 14);
+
+ vr.setViewportStartAndHeight(3, 13);
+ assertEquals(vr.getStartSeq(), 3);
+ assertEquals(vr.getEndSeq(), 15);
+
+ // set location to (8,5) - no change
+ vr.setViewportLocation(8, 5);
+ assertEquals(vr.getStartRes(), 5);
+ assertEquals(vr.getEndRes(), 14);
+ assertEquals(vr.getStartSeq(), 3);
+ assertEquals(vr.getEndSeq(), 15);
+
+ // set location to (40,50) - change to top left (40,50)
+ vr.setViewportLocation(40, 50);
+ assertEquals(vr.getStartRes(), 40);
+ assertEquals(vr.getEndRes(), 49);
+ assertEquals(vr.getStartSeq(), 50);
+ assertEquals(vr.getEndSeq(), 62);
+
+ // set location past end of alignment - resets to leftmost pos
+ vr.setViewportLocation(63, 85);
+ assertEquals(vr.getStartRes(), 50);
+ assertEquals(vr.getEndRes(), 59);
+ assertEquals(vr.getStartSeq(), 67);
+ assertEquals(vr.getEndSeq(), 79);
+
+ // hide some columns
+ al2.getHiddenColumns().hideColumns(20, 50);
+ vr.setViewportLocation(55, 4);
+ assertEquals(vr.getStartRes(), 19);
+ assertEquals(vr.getEndRes(), 28);
+ assertEquals(vr.getStartSeq(), 4);
+ assertEquals(vr.getEndSeq(), 16);
+
+ // hide some sequences
+ al2.getHiddenSequences().hideSequence(al2.getSequenceAt(3));
+ al2.getHiddenSequences().hideSequence(al2.getSequenceAt(4));
+ vr.setViewportLocation(17, 5);
+ assertEquals(vr.getStartRes(), 17);
+ assertEquals(vr.getEndRes(), 26);
+ assertEquals(vr.getStartSeq(), 3);
+ assertEquals(vr.getEndSeq(), 15);
+
+ // set wrapped mode
+ vr.setWrappedMode(true);
+ vr.setViewportLocation(1, 8);
+ assertEquals(vr.getStartRes(), 0);
+ assertEquals(vr.getEndRes(), 9);
+ assertEquals(vr.getStartSeq(), 3);
+ assertEquals(vr.getEndSeq(), 15);
+
+ // try further down the alignment
+ vr.setViewportLocation(57, 5);
+ assertEquals(vr.getStartRes(), 20);
+ assertEquals(vr.getEndRes(), 29);
+ assertEquals(vr.getStartSeq(), 3);
+ assertEquals(vr.getEndSeq(), 15);
+ }
}
// mock listener for property change events