*/
package jalview.viewmodel;
-import jalview.api.AlignViewportI;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.HiddenColumns;
public void setStartEndRes(int start, int end)
{
int oldstartres = this.startRes;
- if (start > al.getWidth() - 1)
+ if (start > getVisibleAlignmentWidth() - 1)
{
- startRes = al.getWidth() - 1;
+ startRes = getVisibleAlignmentWidth() - 1;
}
else if (start < 0)
{
{
int startres = res;
int width = getViewportWidth();
- if (startres + width - 1 > al.getWidth() - 1)
+ if (startres + width - 1 > getVisibleAlignmentWidth() - 1)
{
- startres = al.getWidth() - width;
+ startres = getVisibleAlignmentWidth() - width;
}
setStartEndRes(startres - width + 1, startres);
}
{
int startseq = seq;
int height = getViewportHeight();
- if (startseq + height - 1 > al.getHeight() - 1)
+ if (startseq + height - 1 > getVisibleAlignmentHeight() - 1)
{
- startseq = al.getHeight() - height;
+ startseq = getVisibleAlignmentHeight() - height;
}
setStartEndSeq(startseq, startseq + height - 1);
}
public void setStartEndSeq(int start, int end)
{
int oldstartseq = this.startSeq;
- if (start > al.getHeight() - 1)
+ if (start > getVisibleAlignmentHeight() - 1)
{
- startSeq = al.getHeight() - 1;
+ startSeq = getVisibleAlignmentHeight() - 1;
}
else if (start < 0)
{
}
int oldendseq = this.endSeq;
- if (end >= al.getHeight())
+ if (end >= getVisibleAlignmentHeight())
{
- endSeq = al.getHeight() - 1;
+ endSeq = getVisibleAlignmentHeight() - 1;
}
else if (end < 0)
{
{
vpstart = 0;
}
- else if (vpstart + w - 1 > al.getWidth() - 1)
+ else if (vpstart + w - 1 > getVisibleAlignmentWidth() - 1)
{
- vpstart = al.getWidth() - 1;
+ vpstart = getVisibleAlignmentWidth() - 1;
}
setStartEndRes(vpstart, vpstart + w - 1);
}
{
vpstart = 0;
}
- else if (vpstart + h - 1 > al.getHeight() - 1)
+ else if (vpstart + h - 1 > getVisibleAlignmentHeight() - 1)
{
- vpstart = al.getHeight() - h;
+ vpstart = getVisibleAlignmentHeight() - h;
}
setStartEndSeq(vpstart, vpstart + h - 1);
}
}
else
{
- if (endSeq >= al.getHeight() - 1)
+ if (endSeq >= getVisibleAlignmentHeight() - 1)
{
return false;
}
}
else
{
- if (endRes > al.getWidth() - 1)
+ if (endRes > getVisibleAlignmentWidth() - 1)
{
return false;
}
* x position in alignment
* @param y
* y position in alignment
- * @param av
- * viewport to be visible in. Here until hidden columns JAL-2388
- * merged, then use alignment to get hidden cols
*/
- public void scrollToVisible(int x, int y, AlignViewportI av)
+ public void scrollToVisible(int x, int y)
{
while (y < startSeq)
{
import jalview.analysis.AlignmentGenerator;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.HiddenSequences;
import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class ViewportRangesTest {
AlignmentI al = gen.generate(20, 30, 1, 5, 5);
+ @BeforeMethod
+ public void cleanUp()
+ {
+ ColumnSelection sel = new ColumnSelection();
+ al.getHiddenColumns().revealAllHiddenColumns(sel);
+ al.getHiddenSequences().showAll(null);
+ }
+
@Test(groups = { "Functional" })
public void testViewportRanges()
{
vr.pageDown();
// pagedown to bottom does not go beyond end, and height stays same
- assertEquals(vr.getStartSeq(), 23);
+ assertEquals(vr.getStartSeq(), 24);
assertEquals(vr.getViewportHeight(), 6);
}
vr.scrollUp(true);
assertEquals(vr.getStartSeq(), 0);
+ vr.setViewportStartAndHeight(24, 5);
+ vr.scrollUp(false);
+ assertEquals(vr.getStartSeq(), 25);
+ // can't scroll beyond bottom
+ vr.scrollUp(false);
+ assertEquals(vr.getStartSeq(), 25);
+ }
+
+ @Test(groups = { "Functional" })
+ public void testScrollUpWithHidden()
+ {
+ ViewportRanges vr = new ViewportRanges(al);
+
+ // hide last sequence
+ HiddenSequences hidden = new HiddenSequences(al);
+ hidden.hideSequence(al.getSequenceAt(29));
+
+ vr.setViewportStartAndHeight(1, 5);
+ vr.scrollUp(true);
+ assertEquals(vr.getStartSeq(), 0);
+ // can't scroll above top
+ vr.scrollUp(true);
+ assertEquals(vr.getStartSeq(), 0);
+
vr.setViewportStartAndHeight(23, 5);
vr.scrollUp(false);
assertEquals(vr.getStartSeq(), 24);
}
@Test(groups = { "Functional" })
+ public void testScrollRightWithHidden()
+ {
+ ViewportRanges vr = new ViewportRanges(al);
+
+ // hide last 2 columns
+ HiddenColumns cols = new HiddenColumns();
+ cols.hideColumns(18, 19);
+ al.setHiddenColumns(cols);
+
+ vr.setViewportStartAndWidth(1, 5);
+ vr.scrollRight(false);
+ assertEquals(vr.getStartRes(), 0);
+ // can't scroll left past start
+ vr.scrollRight(false);
+ assertEquals(vr.getStartRes(), 0);
+
+ vr.setViewportStartAndWidth(19, 5);
+ vr.scrollRight(true);
+ assertEquals(vr.getStartRes(), 18);
+ // can't scroll right past last visible col
+ vr.scrollRight(true);
+ assertEquals(vr.getStartRes(), 18);
+ }
+
+ @Test(groups = { "Functional" })
public void testScrollToWrappedVisible()
{
ViewportRanges vr = new ViewportRanges(al);
{
ViewportRanges vr = new ViewportRanges(al);
MockPropChangeListener l = new MockPropChangeListener(vr);
- List<String> emptylist = new ArrayList<String>();
+ List<String> emptylist = new ArrayList<>();
vr.setViewportWidth(5);
vr.setViewportHeight(5);
assertTrue(l.verify(1, Arrays.asList("startres")));
l.reset();
- // TODO test scrollToVisibble once hidden columns JAL-2388 merged in
- // to avoid somersaults with align viewport
- /*vr.scrollToVisible(10, 10);
- assertTrue(l.verify(1, Arrays.asList("startres")));
- l.reset();*/
+ vr.scrollToVisible(10, 10);
+ assertTrue(l.verify(4,
+ Arrays.asList("startseq", "startseq", "startseq", "startseq")));
+ l.reset();
vr.scrollToWrappedVisible(5);
assertTrue(l.verify(1, Arrays.asList("startres")));
{
private int firecount = 0;
- private List<String> events = new ArrayList<String>();
+ private List<String> events = new ArrayList<>();
- private List<Integer> newvalues = new ArrayList<Integer>();
+ private List<Integer> newvalues = new ArrayList<>();
public MockPropChangeListener(ViewportRanges vr)
{