private void setScrollingForWrappedPanel(int topLeftColumn)
{
int scrollPosition = vpRanges.getWrappedScrollPosition(topLeftColumn);
- int maxScroll = vpRanges.getWrappedScrollPosition(vpRanges
- .getVisibleAlignmentWidth() - 1);
+ int maxScroll = vpRanges.getWrappedMaxScroll(topLeftColumn);
+ /*
+ * a scrollbar's value can be set to at most (maximum-extent)
+ * so we add extent (1) to the maxScroll value
+ */
vscroll.setUnitIncrement(1);
- vscroll.setValues(scrollPosition, 1, 0, maxScroll);
+ vscroll.setValues(scrollPosition, 1, 0, maxScroll + 1);
}
protected Panel sequenceHolderPanel = new Panel();
private void setScrollingForWrappedPanel(int topLeftColumn)
{
int scrollPosition = vpRanges.getWrappedScrollPosition(topLeftColumn);
- int maxScroll = vpRanges.getWrappedScrollPosition(vpRanges
- .getVisibleAlignmentWidth() - 1);
+ int maxScroll = vpRanges.getWrappedMaxScroll(topLeftColumn);
+ /*
+ * a scrollbar's value can be set to at most (maximum-extent)
+ * so we add extent (1) to the maxScroll value
+ */
vscroll.setUnitIncrement(1);
- vscroll.setValues(scrollPosition, 1, 0, maxScroll);
+ vscroll.setValues(scrollPosition, 1, 0, maxScroll + 1);
}
/**
/**
* Answers the vertical scroll position (0..) to set, given the visible column
- * that is at top left. Note that if called with the total visible width of
- * the alignment, this gives the maximum cursor scroll value.
+ * that is at top left.
*
* <pre>
* Example:
* viewport width 40 columns (0-39, 40-79, 80-119...)
* column 0 returns scroll position 0
- * columns 0-40 return scroll position 1
+ * columns 1-40 return scroll position 1
* columns 41-80 return scroll position 2
* etc
* </pre>
* visible whole widths
*/
int scroll = topLeftColumn / w;
+
+ /*
+ * add 1 for a part width if there is one
+ */
scroll += topLeftColumn % w > 0 ? 1 : 0;
return scroll;
}
+
+ /**
+ * Answers the maximum wrapped vertical scroll value, given the column
+ * position (0..) to show at top left of the visible region.
+ *
+ * @param topLeftColumn
+ * @return
+ */
+ public int getWrappedMaxScroll(int topLeftColumn)
+ {
+ int scrollPosition = getWrappedScrollPosition(topLeftColumn);
+
+ /*
+ * how many more widths could be drawn after this one?
+ */
+ int columnsRemaining = getVisibleAlignmentWidth() - topLeftColumn;
+ int width = getViewportWidth();
+ int widthsRemaining = columnsRemaining / width
+ + (columnsRemaining % width > 0 ? 1 : 0) - 1;
+ int maxScroll = scrollPosition + widthsRemaining;
+
+ return maxScroll;
+ }
}
assertEquals(vrsmall.getViewportWidth(), 7);
assertEquals(vrsmall.getStartRes(), 0);
}
+
+ @Test(groups = { "Functional" })
+ public void testGetWrappedMaxScroll()
+ {
+ // generate an ungapped alignment of width 140
+ int alignmentWidth = 140;
+ AlignmentI al2 = gen.generate(alignmentWidth, 15, 1, 0, 5);
+ ViewportRanges vr = new ViewportRanges(al2);
+ vr.setStartEndRes(0, 39);
+ int width = vr.getViewportWidth(); // 40
+ int partWidth = alignmentWidth % width; // 20
+
+ /*
+ * there are 3 * 40 remainder 20 residues
+ * number of widths depends on offset (scroll right)
+ * 4 widths (maxScroll = 3) if offset by 0 or more than 19 columns
+ * 5 widths (maxScroll = 4) if 1 <= offset <= 19
+ */
+ for (int col = 0; col < alignmentWidth; col++)
+ {
+ int offset = col % width;
+ if (offset > 0 && offset < partWidth)
+ {
+ assertEquals(vr.getWrappedMaxScroll(col), 4, "col " + col);
+ }
+ else
+ {
+ assertEquals(vr.getWrappedMaxScroll(col), 3, "col " + col);
+ }
+ }
+ }
}
// mock listener for property change events