From 2b2c9e1a88930585de0b5c205e4ae6f0174440d2 Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 30 May 2017 10:36:34 +0100 Subject: [PATCH] JAL-2571 Corrected alignment width/height checks to visible only --- src/jalview/datamodel/HiddenSequences.java | 10 ++- src/jalview/gui/SeqPanel.java | 3 +- src/jalview/viewmodel/ViewportRanges.java | 38 ++++++------ test/jalview/viewmodel/ViewportRangesTest.java | 78 +++++++++++++++++++++--- 4 files changed, 95 insertions(+), 34 deletions(-) diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index 1daaf43..a98b10e 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -170,7 +170,13 @@ public class HiddenSequences public List showAll( Map hiddenRepSequences) { - List revealedSeqs = new ArrayList(); + List revealedSeqs = new ArrayList<>(); + + if (hiddenSequences == null) + { + return revealedSeqs; + } + for (int i = 0; i < hiddenSequences.length; i++) { if (hiddenSequences[i] != null) @@ -199,7 +205,7 @@ public class HiddenSequences public List showSequence(int alignmentIndex, Map hiddenRepSequences) { - List revealedSeqs = new ArrayList(); + List revealedSeqs = new ArrayList<>(); SequenceI repSequence = alignment.getSequenceAt(alignmentIndex); if (repSequence != null && hiddenRepSequences != null && hiddenRepSequences.containsKey(repSequence)) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 0878cbb..012ac94 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -393,8 +393,7 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - av.getRanges().scrollToVisible(seqCanvas.cursorX, seqCanvas.cursorY, - av); + av.getRanges().scrollToVisible(seqCanvas.cursorX, seqCanvas.cursorY); } setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY), seqCanvas.cursorX, seqCanvas.cursorY); diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index da39e36..56c1d39 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -20,7 +20,6 @@ */ package jalview.viewmodel; -import jalview.api.AlignViewportI; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; @@ -122,9 +121,9 @@ public class ViewportRanges extends ViewportProperties 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) { @@ -164,9 +163,9 @@ public class ViewportRanges extends ViewportProperties { 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); } @@ -183,9 +182,9 @@ public class ViewportRanges extends ViewportProperties { 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); } @@ -203,9 +202,9 @@ public class ViewportRanges extends ViewportProperties 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) { @@ -217,9 +216,9 @@ public class ViewportRanges extends ViewportProperties } int oldendseq = this.endSeq; - if (end >= al.getHeight()) + if (end >= getVisibleAlignmentHeight()) { - endSeq = al.getHeight() - 1; + endSeq = getVisibleAlignmentHeight() - 1; } else if (end < 0) { @@ -327,9 +326,9 @@ public class ViewportRanges extends ViewportProperties { 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); } @@ -351,9 +350,9 @@ public class ViewportRanges extends ViewportProperties { 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); } @@ -399,7 +398,7 @@ public class ViewportRanges extends ViewportProperties } else { - if (endSeq >= al.getHeight() - 1) + if (endSeq >= getVisibleAlignmentHeight() - 1) { return false; } @@ -430,7 +429,7 @@ public class ViewportRanges extends ViewportProperties } else { - if (endRes > al.getWidth() - 1) + if (endRes > getVisibleAlignmentWidth() - 1) { return false; } @@ -463,11 +462,8 @@ public class ViewportRanges extends ViewportProperties * 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) { diff --git a/test/jalview/viewmodel/ViewportRangesTest.java b/test/jalview/viewmodel/ViewportRangesTest.java index 3cd2096..9c0d41b 100644 --- a/test/jalview/viewmodel/ViewportRangesTest.java +++ b/test/jalview/viewmodel/ViewportRangesTest.java @@ -5,12 +5,16 @@ import static org.testng.Assert.assertTrue; 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 { @@ -19,6 +23,14 @@ 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() { @@ -213,7 +225,7 @@ public class ViewportRangesTest { 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); } @@ -228,6 +240,30 @@ public class ViewportRangesTest { 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); @@ -256,6 +292,31 @@ public class ViewportRangesTest { } @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); @@ -296,7 +357,7 @@ public class ViewportRangesTest { { ViewportRanges vr = new ViewportRanges(al); MockPropChangeListener l = new MockPropChangeListener(vr); - List emptylist = new ArrayList(); + List emptylist = new ArrayList<>(); vr.setViewportWidth(5); vr.setViewportHeight(5); @@ -425,11 +486,10 @@ public class ViewportRangesTest { 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"))); @@ -442,9 +502,9 @@ class MockPropChangeListener implements ViewportListenerI { private int firecount = 0; - private List events = new ArrayList(); + private List events = new ArrayList<>(); - private List newvalues = new ArrayList(); + private List newvalues = new ArrayList<>(); public MockPropChangeListener(ViewportRanges vr) { -- 1.7.10.2