From 999f2dccf898ff34d180a3fef7fae8b80e8d2fcf Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 20 Mar 2019 12:25:31 +0000 Subject: [PATCH] JAL-3212 unit test and fix for Scale Panel bug --- src/jalview/gui/ScalePanel.java | 5 +-- test/jalview/gui/ScalePanelTest.java | 66 +++++++++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index b95c569..b392c8f 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -279,14 +279,15 @@ public class ScalePanel extends JPanel ap.getSeqPanel().stopScrolling(); int xCords = Math.max(0, evt.getX()); // prevent negative X coordinates + ViewportRanges ranges = av.getRanges(); int res = (xCords / av.getCharWidth()) - + av.getRanges().getStartRes(); + + ranges.getStartRes(); + res = Math.min(res, ranges.getEndRes()); if (av.hasHiddenColumns()) { res = av.getAlignment().getHiddenColumns() .visibleToAbsoluteColumn(res); } - res = Math.min(res, av.getRanges().getEndRes()); res = Math.max(0, res); if (!stretchingGroup) diff --git a/test/jalview/gui/ScalePanelTest.java b/test/jalview/gui/ScalePanelTest.java index 91b541c..0ec1c1f 100644 --- a/test/jalview/gui/ScalePanelTest.java +++ b/test/jalview/gui/ScalePanelTest.java @@ -1,12 +1,18 @@ package jalview.gui; +import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import jalview.bin.Cache; +import jalview.bin.Jalview; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; +import jalview.io.FileLoader; +import jalview.viewmodel.ViewportRanges; import java.awt.event.MouseEvent; @@ -28,16 +34,12 @@ public class ScalePanelTest SequenceI seq1 = new Sequence("Seq1", "MATRESS"); SequenceI seq2 = new Sequence("Seq2", "MADNESS"); AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 }); - + AlignFrame alignFrame = new AlignFrame(al, al.getWidth(), al.getHeight()); - ScalePanel scalePanel = new ScalePanel( - alignFrame.getViewport(), alignFrame.alignPanel - ); - - MouseEvent mouse = new MouseEvent( - scalePanel, 0, 1, 0, 4, 0, 1, false - ); + ScalePanel scalePanel = alignFrame.alignPanel.getScalePanel(); + + MouseEvent mouse = new MouseEvent(scalePanel, 0, 1, 0, 4, 0, 1, false); scalePanel.mousePressed(mouse); scalePanel.mouseDragged(mouse); @@ -51,8 +53,56 @@ public class ScalePanelTest int startCol = sg.getStartRes(); assertTrue(startCol >= 0); + } + /** + * Test for JAL-3212 + */ + @Test(groups = "Functional") + public void testSelectColumns_withHidden() + { + String seq1 = ">Seq1\nANTOFAGASTAVALPARAISOMONTEVIDEOANTANANARIVO"; + AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(seq1, + DataSourceType.PASTE); + ScalePanel scalePanel = alignFrame.alignPanel.getScalePanel(); + /* + * hide columns 1-20 (of 43); then 'drag' to select columns 30-31; + * 31 is 51 in absolute columns but bug JAL-3212 reduces it to + * endRes which is 22 + */ + AlignViewport viewport = alignFrame.getViewport(); + ViewportRanges ranges = viewport.getRanges(); + assertEquals(ranges.getStartRes(), 0); + assertEquals(ranges.getEndRes(), 42); + viewport.hideColumns(0, 19); + alignFrame.alignPanel.updateLayout(); + assertEquals(ranges.getStartRes(), 0); + assertEquals(ranges.getEndRes(), 22); + + int cw = viewport.getCharWidth(); + int xPos = 9 * cw + 2; + MouseEvent mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, + false); + scalePanel.mousePressed(mouse); + scalePanel.mouseDragged(mouse); + xPos += cw; + mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false); + scalePanel.mouseReleased(mouse); + + SequenceGroup sg = scalePanel.av.getSelectionGroup(); + assertEquals(sg.getStartRes(), 29); + assertEquals(sg.getEndRes(), 30); + } + + @BeforeClass(alwaysRun = true) + public static void setUpBeforeClass() throws Exception + { + /* + * use read-only test properties file + */ + Cache.loadProperties("test/jalview/io/testProps.jvprops"); + Jalview.main(new String[] { "-nonews" }); } } -- 1.7.10.2