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;
// cached widths and heights
int boxWidth;
+
int boxHeight;
+
int viewHeight;
+
int viewWidth;
+
int alheight;
+
int alwidth;
ViewportRanges vpranges;
- Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
+ Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<>();
HiddenColumns hiddenCols = new HiddenColumns();
}
ColumnSelection colsel = new ColumnSelection();
hiddenCols.revealAllHiddenColumns(colsel);
-
+
vpranges = new ViewportRanges(al);
- vpranges.setStartRes(0);
- vpranges.setEndRes(62);
- vpranges.setStartSeq(0);
- vpranges.setEndSeq(17);
+ vpranges.setViewportStartAndHeight(0, 18);
+ vpranges.setViewportStartAndWidth(0, 63);
viewHeight = vpranges.getEndSeq() - vpranges.getStartSeq() + 1;
viewWidth = vpranges.getEndRes() - vpranges.getStartRes() + 1;
alheight = vpranges.getVisibleAlignmentHeight();
alwidth = vpranges.getVisibleAlignmentWidth();
- boxWidth = Math.round((float) (vpranges.getEndRes()
- - vpranges.getStartRes() + 1)
- * od.getWidth() / alwidth);
- boxHeight = Math.round((float) (vpranges.getEndSeq()
- - vpranges.getStartSeq() + 1)
- * od.getSequencesHeight() / alheight);
+ boxWidth = Math.round(
+ (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+ * od.getWidth() / alwidth);
+ boxHeight = Math.round(
+ (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+ * od.getSequencesHeight() / alheight);
}
@AfterClass(alwaysRun = true)
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
- assertEquals(od.getScrollCol(), 0);
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartRes(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
// negative boxX value reset to 0
mouseClick(od, -5, 10);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(od.getScrollRow(),
+ assertEquals(vpranges.getStartSeq() + vpranges.getViewportHeight() / 2,
Math.round((float) 10 * alheight / od.getSequencesHeight()));
- assertEquals(od.getScrollCol(), 0);
+ assertEquals(vpranges.getStartRes(), 0);
// negative boxY value reset to 0
mouseClick(od, 6, -2);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(od.getScrollCol(),
- Math.round((float) 6 * alwidth / od.getWidth()));
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartRes(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
// overly large boxX value reset to width-boxWidth
- mouseClick(od, 100, 6);
+ mouseClick(od, 101, 6);
assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
- assertEquals(od.getBoxY(), 6);
+ assertEquals(od.getBoxY(), 1);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(od.getScrollCol(),
+ assertEquals(vpranges.getStartRes(),
Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
- assertEquals(od.getScrollRow(),
- Math.round((float) od.getBoxY() * alheight
- / od.getSequencesHeight()));
+ assertEquals(vpranges.getStartSeq(), Math.round(
+ (float) od.getBoxY() * alheight / od.getSequencesHeight()));
// overly large boxY value reset to sequenceHeight - boxHeight
mouseClick(od, 10, 520);
- assertEquals(od.getBoxX(), 10);
+ assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(od.getScrollCol(),
+ assertEquals(vpranges.getStartRes(),
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()) - 1);
+ assertEquals(vpranges.getStartSeq(), Math.round(
+ (float) od.getBoxY() * alheight / od.getSequencesHeight()) - 1);
// click past end of alignment, as above
mouseClick(od, 3000, 5);
assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(od.getScrollCol(),
+ assertEquals(vpranges.getStartRes(),
Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
- assertEquals(od.getScrollRow(),
- Math.round((float) od.getBoxY() * alheight
- / od.getSequencesHeight()));
+ assertEquals(vpranges.getStartSeq(), Math.round(
+ (float) od.getBoxY() * alheight / od.getSequencesHeight()));
// move viewport so startRes non-zero and then mouseclick
- moveViewportH(50);
+ moveViewportH(20);
// 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);
+ mouseClick(od, od.getBoxX() + od.getBoxWidth() / 2 + 6,
+ od.getBoxY() + od.getBoxHeight() / 2 + 3);
+ assertEquals(od.getBoxX(), oldboxx + 6);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(od.getScrollCol(),
+ assertEquals(vpranges.getStartRes(),
Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
- assertEquals(od.getBoxY(), oldboxy + 2);
- assertEquals(od.getScrollRow(),
- Math.round((float) od.getBoxY() * alheight
- / od.getSequencesHeight()));
+ assertEquals(od.getBoxY(), oldboxy + 3);
+ assertEquals(vpranges.getStartSeq(), Math.round(
+ (float) od.getBoxY() * alheight / od.getSequencesHeight()));
// click at top corner
mouseClick(od, 0, 0);
assertEquals(od.getBoxX(), 0);
- assertEquals(od.getScrollCol(), 0);
+ assertEquals(vpranges.getStartRes(), 0);
assertEquals(od.getBoxY(), 0);
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
}
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
- assertEquals(od.getScrollCol(), 0);
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartRes(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
// hide cols at start and check updated box position is correct
int lastHiddenCol = 30;
hiddenCols.hideColumns(0, lastHiddenCol);
- testBoxIsAtClickPoint(0, 0);
+ testBoxIsAtClickPoint(boxWidth / 2, boxHeight / 2);
// click to right of hidden columns, box moves to click point
- testBoxIsAtClickPoint(40, 0);
- assertEquals(od.getScrollRow(), 0);
- assertEquals(od.getScrollCol(),
- Math.round((float) 40 * alwidth / od.getWidth()));
+ testBoxIsAtClickPoint(41 + boxWidth / 2, boxHeight / 2);
+ assertEquals(vpranges.getStartSeq(), 0);
+ assertEquals(vpranges.getStartRes(),
+ Math.round((float) 41 * alwidth / od.getWidth()));
// 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, 0);
+ int xpos = 100 + boxWidth / 2;
+ mouseClick(od, xpos, boxHeight / 2);
assertEquals(od.getBoxX(), Math.round(od.getWidth()) - boxWidth);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(od.getScrollCol(),
+ assertEquals(vpranges.getStartRes(),
Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
}
/**
public void testFromMouseWithHiddenColsInMiddle()
{
od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
- testBoxIsAtClickPoint(0, 0);
+ testBoxIsAtClickPoint(boxWidth / 2, boxHeight / 2);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
- assertEquals(od.getScrollCol(), 0);
- assertEquals(od.getScrollRow(), 0);
-
+ assertEquals(vpranges.getStartRes(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
+
// hide columns 63-73, no change to box position or dimensions
int firstHidden = 63;
int lastHidden = 73;
hiddenCols.hideColumns(firstHidden, lastHidden);
od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
- testBoxIsAtClickPoint(0, 0);
+ testBoxIsAtClickPoint(boxWidth / 2, boxHeight / 2);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
- assertEquals(od.getScrollCol(), 0);
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartRes(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
// move box so that it overlaps with hidden cols on one side
// box width, boxX and scrollCol as for unhidden case
- int xpos = 55 - boxWidth; // 55 is position in overview approx halfway
- // between cols 60 and 70
- mouseClick(od, xpos, 0);
- testBoxIsAtClickPoint(xpos, 0);
- assertEquals(od.getScrollCol(),
- Math.round(xpos * alwidth / od.getWidth()));
- assertEquals(od.getScrollRow(), 0);
+ int xpos = 54 - boxWidth / 2; // 54 is position in overview approx halfway
+ // between cols 60 and 70
+ mouseClick(od, xpos, boxHeight / 2);
+ testBoxIsAtClickPoint(xpos, boxHeight / 2);
+ assertEquals(vpranges.getStartRes(), 1 + // rounding
+ Math.round((xpos - boxWidth / 2) * alwidth / od.getWidth()));
+ assertEquals(vpranges.getStartSeq(), 0);
// move box so that it completely covers hidden cols
// box width, boxX and scrollCol as for unhidden case
xpos = 33;
- mouseClick(od, xpos, 0);
- testBoxIsAtClickPoint(xpos, 0);
- assertEquals(od.getScrollCol(),
- Math.round((float) xpos * alwidth / od.getWidth()));
- assertEquals(od.getScrollRow(), 0);
+ mouseClick(od, xpos, boxHeight / 2);
+ testBoxIsAtClickPoint(xpos, boxHeight / 2);
+ assertEquals(vpranges.getStartRes(), Math.round(
+ (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
+ assertEquals(vpranges.getStartSeq(), 0);
// move box so boxX is in hidden cols, box overhangs at right
// boxX and scrollCol at left of hidden area, box width unchanged
- xpos = 50;
- mouseClick(od, xpos, 0);
- testBoxIsAtClickPoint(xpos, 0);
- assertEquals(od.getScrollCol(),
- Math.round((float) xpos * alwidth / od.getWidth()));
- assertEquals(od.getScrollRow(), 0);
+ xpos = Math.round((float) 50 * od.getWidth() / alwidth) + boxWidth / 2;
+ mouseClick(od, xpos, boxHeight / 2);
+ assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(vpranges.getStartRes(), 50);
+ assertEquals(vpranges.getStartSeq(), 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
- xpos = 75;
- testBoxIsAtClickPoint(xpos, 0);
- assertEquals(od.getScrollRow(), 0);
- assertEquals(od.getScrollCol(),
- Math.round(xpos * alwidth / od.getWidth()));
-
+ xpos = Math.round((float) 75 * od.getWidth() / alwidth) + boxWidth / 2;
+ mouseClick(od, xpos, boxHeight / 2);
+ assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(vpranges.getStartSeq(), 0);
+ assertEquals(vpranges.getStartRes(), 75);
+
// move box so it goes beyond full width of alignment
// boxX, scrollCol adjusted back, box width normal
xpos = 3000;
- mouseClick(od, xpos, 0);
+ mouseClick(od, xpos, boxHeight / 2);
assertEquals(od.getBoxX(), Math.round(od.getWidth()) - boxWidth);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(od.getScrollCol(),
+ assertEquals(vpranges.getStartRes(),
Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
}
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
- assertEquals(od.getScrollCol(), 0);
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartRes(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
// hide columns 140-164, no change to box position or dimensions
int firstHidden = 140;
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
- assertEquals(od.getScrollCol(), 0);
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartRes(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
// 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((float) xpos * alwidth / od.getWidth()));
+ int xpos = 30;
+ int ypos = 6;
+ testBoxIsAtClickPoint(xpos, ypos);
+ assertEquals(vpranges.getStartSeq(), Math.round(
+ (float) (ypos - boxHeight / 2) * alheight / od.getHeight()));
+ assertEquals(vpranges.getStartRes(), Math.round(
+ (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
// click to left of hidden cols, with overlap
// boxX and scrollCol adjusted for hidden cols, width normal
- xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
- mouseClick(od, xpos, 0);
- testBoxIsAtClickPoint(xpos, 0);
- assertEquals(od.getScrollCol(),
- Math.round((float) xpos * alwidth / od.getWidth()));
- assertEquals(od.getScrollRow(), 0);
+ xpos = Math.round((float) 144 * od.getWidth() / alwidth) - boxWidth;
+ mouseClick(od, xpos, boxHeight / 2);
+ testBoxIsAtClickPoint(xpos, boxHeight / 2);
+ assertEquals(vpranges.getStartRes(), Math.round(
+ (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
+ assertEquals(vpranges.getStartSeq(), 0);
// click off end of alignment
// boxX and scrollCol adjusted backwards, width normal
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(od.getScrollCol(),
+ assertEquals(vpranges.getStartRes(),
Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
}
/**
// 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((float) (98 - lastHidden - 1) * od.getWidth()
- / alwidth));
+ assertEquals(od.getBoxX(), Math.round(
+ (float) (98 - lastHidden - 1) * od.getWidth() / alwidth));
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
// viewport can't actually extend into hidden cols,
// so move to the far right edge of the viewport
moveViewport(firstHidden - viewWidth, 0);
- assertEquals(od.getBoxX(),
- Math.round((float) (firstHidden - viewWidth)
- * od.getWidth() / alwidth));
+ assertEquals(od.getBoxX(), Math.round(
+ (float) (firstHidden - viewWidth) * od.getWidth() / alwidth));
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
alheight = vpranges.getVisibleAlignmentHeight();
alwidth = vpranges.getVisibleAlignmentWidth();
- boxWidth = Math.round((float) (vpranges.getEndRes()
- - vpranges.getStartRes() + 1)
- * od.getWidth() / alwidth);
- boxHeight = Math.round((float) (vpranges.getEndSeq()
- - vpranges.getStartSeq() + 1)
- * od.getSequencesHeight() / alheight);
+ boxWidth = Math.round(
+ (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+ * od.getWidth() / alwidth);
+ boxHeight = Math.round(
+ (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+ * od.getSequencesHeight() / alheight);
// move viewport to start of alignment:
// box moves to below hidden rows, height remains same
// move viewport to end of alignment
moveViewport(0, 525 - viewHeight - lastHidden - 1);
assertEquals(od.getBoxX(), 0);
- assertEquals(
- od.getBoxY(),
+ assertEquals(od.getBoxY(),
Math.round((float) (525 - viewHeight - lastHidden - 1)
- * od.getSequencesHeight()
- / alheight));
+ * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
}
alheight = vpranges.getVisibleAlignmentHeight();
alwidth = vpranges.getVisibleAlignmentWidth();
- boxWidth = Math.round((float) (vpranges.getEndRes()
- - vpranges.getStartRes() + 1)
- * od.getWidth() / alwidth);
- boxHeight = Math.round((float) (vpranges.getEndSeq()
- - vpranges.getStartSeq() + 1)
- * od.getSequencesHeight() / alheight);
+ boxWidth = Math.round(
+ (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+ * od.getWidth() / alwidth);
+ boxHeight = Math.round(
+ (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+ * od.getSequencesHeight() / alheight);
// move viewport to start of alignment:
// box, height etc as in non-hidden case
// move viewport to straddle hidden rows
moveViewport(0, 198);
assertEquals(od.getBoxX(), 0);
- assertEquals(od.getBoxY(), Math.round ((float)198 * od.getSequencesHeight()
- / alheight));
+ assertEquals(od.getBoxY(),
+ Math.round((float) 198 * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
}
alheight = vpranges.getVisibleAlignmentHeight();
alwidth = vpranges.getVisibleAlignmentWidth();
- boxWidth = Math.round((float) (vpranges.getEndRes()
- - vpranges.getStartRes() + 1)
- * od.getWidth() / alwidth);
- boxHeight = Math.round((float) (vpranges.getEndSeq()
- - vpranges.getStartSeq() + 1)
- * od.getSequencesHeight() / alheight);
+ boxWidth = Math.round(
+ (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+ * od.getWidth() / alwidth);
+ boxHeight = Math.round(
+ (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+ * od.getSequencesHeight() / alheight);
// move viewport to start of alignment:
// box, height etc as in non-hidden case
// viewport sits above hidden rows and does not include them
moveViewport(0, firstHidden - viewHeight - 1);
assertEquals(od.getBoxX(), 0);
- assertEquals(
- od.getBoxY(),
+ assertEquals(od.getBoxY(),
Math.round((float) (firstHidden - viewHeight - 1)
* od.getSequencesHeight() / alheight));
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(od.getBoxWidth(), boxWidth);
- assertEquals(od.getScrollCol(), 0);
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartRes(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
// hide rows at start and check updated box position is correct
int lastHiddenRow = 30;
alheight = vpranges.getVisibleAlignmentHeight();
alwidth = vpranges.getVisibleAlignmentWidth();
- boxWidth = Math.round((float) (vpranges.getEndRes()
- - vpranges.getStartRes() + 1)
- * od.getWidth() / alwidth);
- boxHeight = Math.round((float) (vpranges.getEndSeq()
- - vpranges.getStartSeq() + 1)
- * od.getSequencesHeight() / alheight);
+ boxWidth = Math.round(
+ (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+ * od.getWidth() / alwidth);
+ boxHeight = Math.round(
+ (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+ * od.getSequencesHeight() / alheight);
od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxHeight(), boxHeight);
// click below hidden rows
- mouseClick(od, 0, 150);
+ mouseClick(od, 0, 151 + boxHeight / 2);
assertEquals(od.getBoxX(), 0);
- assertEquals(od.getBoxY(), 150);
+ assertEquals(od.getBoxY(), 151);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
}
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(od.getScrollCol(), 0);
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartRes(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
// hide rows in middle and check updated box position is correct
// no changes
alheight = vpranges.getVisibleAlignmentHeight();
alwidth = vpranges.getVisibleAlignmentWidth();
- boxWidth = Math.round((float) (vpranges.getEndRes()
- - vpranges.getStartRes() + 1)
- * od.getWidth() / alwidth);
- boxHeight = Math.round((float) (vpranges.getEndSeq()
- - vpranges.getStartSeq() + 1)
- * od.getSequencesHeight() / alheight);
+ boxWidth = Math.round(
+ (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+ * od.getWidth() / alwidth);
+ boxHeight = Math.round(
+ (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+ * od.getSequencesHeight() / alheight);
od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
assertEquals(od.getBoxHeight(), boxHeight);
// click above hidden rows, so that box overlaps
- int ypos = 35; // column value in residues
+ int ypos = 35 + viewHeight / 2; // row 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));
+ Math.round((float) 35 * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
// click so that box straddles hidden rows
- ypos = 44; // column value in residues
+ ypos = 45 + viewHeight / 2; // row 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));
+ Math.round((float) 45 * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
}
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(od.getScrollCol(), 0);
- assertEquals(od.getScrollRow(), 0);
+ assertEquals(vpranges.getStartRes(), 0);
+ assertEquals(vpranges.getStartSeq(), 0);
// hide rows at end and check updated box position is correct
// no changes
alheight = vpranges.getVisibleAlignmentHeight();
alwidth = vpranges.getVisibleAlignmentWidth();
- boxWidth = Math.round((float) (vpranges.getEndRes()
- - vpranges.getStartRes() + 1)
- * od.getWidth() / alwidth);
- boxHeight = Math.round((float) (vpranges.getEndSeq()
- - vpranges.getStartSeq() + 1)
- * od.getSequencesHeight() / alheight);
+ boxWidth = Math.round(
+ (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+ * od.getWidth() / alwidth);
+ boxHeight = Math.round(
+ (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+ * od.getSequencesHeight() / alheight);
od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxHeight(), boxHeight);
// click above hidden rows
- int ypos = 40; // row 40
+ int ypos = 41 + viewHeight / 2; // row 41
mouseClick(od, 0,
Math.round((float) ypos * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(),
- Math.round((float) ypos * od.getSequencesHeight() / alheight));
+ Math.round((float) 41 * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
// click above hidden rows so box overlaps
// boxY, boxHeight remains same
- ypos = 497; // row 497
+ ypos = 497 + viewHeight / 2; // row 497
mouseClick(od, 0,
Math.round((float) ypos * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxX(), 0);
- assertEquals(
- od.getBoxY(),
- Math.round((float) firstHidden * od.getSequencesHeight()
- / alheight)
- - boxHeight);
+ assertEquals(od.getBoxY(), Math
+ .round((float) firstHidden * od.getSequencesHeight() / alheight)
+ - boxHeight);
assertEquals(od.getBoxWidth(), boxWidth);
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));
+
+ // hide columns in the box area
+ // makes absolutely no difference
+ 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));
+
+ // hide sequences in box area
+ // makes absolutely no difference
+ hideSequences(1, 3);
+ 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));
+ }
+
+ /**
+ * 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 - 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) right and 6 (22-16) up
+ assertEquals(od.getBoxX(), 16);
+ 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) right and 6 (22-16) up
+ assertEquals(od.getBoxX(), 16);
+ assertEquals(od.getBoxY(), 6);
+ }
+
/*
* Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
*/
private void moveViewportH(int startRes)
{
- vpranges.setStartRes(startRes);
- vpranges.setEndRes(startRes + viewWidth - 1);
+ vpranges.setViewportStartAndWidth(startRes, viewWidth);
od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
}
*/
private void moveViewportV(int startSeq)
{
- vpranges.setStartSeq(startSeq);
- vpranges.setEndSeq(startSeq + viewHeight - 1);
+ vpranges.setViewportStartAndHeight(startSeq, viewHeight);
od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
}
*/
private void moveViewport(int startRes, int startSeq)
{
- vpranges.setStartRes(startRes);
- vpranges.setEndRes(startRes + viewWidth - 1);
- vpranges.setStartSeq(startSeq);
- vpranges.setEndSeq(startSeq + viewHeight - 1);
+ vpranges.setViewportStartAndWidth(startRes, viewWidth);
+ vpranges.setViewportStartAndHeight(startSeq, viewHeight);
od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
}
/*
* Mouse click as position x,y in overview window
*/
- private void mouseClick(OverviewDimensionsHideHidden od, int x, int y)
+ private void mouseClick(OverviewDimensions od, int x, int y)
{
od.updateViewportFromMouse(x, y, 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
-
- vpranges.setStartRes(od.getScrollCol());
- vpranges.setEndRes(od.getScrollCol() + viewWidth - 1);
- vpranges.setStartSeq(od.getScrollRow());
- vpranges.setEndSeq(od.getScrollRow() + viewHeight - 1);
od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
}
-
+
/*
* 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);
- assertEquals(od.getBoxX(), xpos);
- assertEquals(od.getBoxY(), ypos);
+ assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
+ assertEquals(od.getBoxY() + od.getBoxHeight() / 2, ypos);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
{
SequenceI[] allseqs = al.getSequencesArray();
SequenceGroup theseSeqs = new SequenceGroup();
-
+
for (int i = start; i <= end; i++)
{
theseSeqs.addSequence(allseqs[i], false);