From: kiramt Date: Fri, 17 Feb 2017 07:46:07 +0000 (+0000) Subject: JAL-2421 Fix to alignment panel scroll values, and start of unit test. X-Git-Tag: Release_2_10_3b1~339^2~1^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c722265264903c67877587cc422bb2088a16166a;p=jalview.git JAL-2421 Fix to alignment panel scroll values, and start of unit test. --- diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index e61b042..3d64798 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -91,9 +91,9 @@ public class AlignmentPanel extends GAlignmentPanel implements // this value is set false when selection area being dragged boolean fastPaint = true; - int hextent = 0; + private int hextent = 0; - int vextent = 0; + private int vextent = 0; /* * Flag set while scrolling to follow complementary cDNA/protein scroll. When @@ -701,9 +701,6 @@ public class AlignmentPanel extends GAlignmentPanel implements width = av.getColumnSelection().findColumnPosition(width); } - av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av - .getCharWidth())) - 1); - hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(); @@ -737,6 +734,10 @@ public class AlignmentPanel extends GAlignmentPanel implements x = 0; } + // update endRes after x has (possibly) been adjusted + av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av + .getCharWidth())) - 1); + /* * each scroll adjustment triggers adjustmentValueChanged, which resets the * 'do not scroll complement' flag; ensure it is the same for both diff --git a/test/jalview/gui/AlignmentPanelTest.java b/test/jalview/gui/AlignmentPanelTest.java new file mode 100644 index 0000000..5c5890e --- /dev/null +++ b/test/jalview/gui/AlignmentPanelTest.java @@ -0,0 +1,178 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.gui; + +import static org.testng.Assert.assertEquals; + +import jalview.bin.Jalview; +import jalview.datamodel.Alignment; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; + +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AlignmentPanelTest +{ + SequenceI seq1 = new Sequence( + "Seq1", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq2 = new Sequence( + "Seq2", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq3 = new Sequence( + "Seq3", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq4 = new Sequence( + "Seq4", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq5 = new Sequence( + "Seq5", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq6 = new Sequence( + "Seq6", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq7 = new Sequence( + "Seq7", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq8 = new Sequence( + "Seq8", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq9 = new Sequence( + "Seq9", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq10 = new Sequence( + "Seq10", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq11 = new Sequence( + "Seq11", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq12 = new Sequence( + "Seq12", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq13 = new Sequence( + "Seq13", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq14 = new Sequence( + "Seq14", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq15 = new Sequence( + "Seq15", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq16 = new Sequence( + "Seq16", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq17 = new Sequence( + "Seq17", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq18 = new Sequence( + "Seq18", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq19 = new Sequence( + "Seq19", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq20 = new Sequence( + "Seq20", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq21 = new Sequence( + "Seq21", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq22 = new Sequence( + "Seq22", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq23 = new Sequence( + "Seq23", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + @BeforeClass(alwaysRun = true) + public void setUp() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + + Jalview.main(new String[] { "-nonews", "-props", + "test/jalview/testProps.jvprops" }); + } + + @AfterMethod(alwaysRun = true) + public void tearDown() + { + Desktop.instance.closeAll_actionPerformed(null); + } + + /** + * Test side effect that end residue is set correctly by setScrollValues, with + * or without hidden columns + */ + @Test(groups = "Functional") + public void TestSetScrollValues() + { + SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5, + seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15, + seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 }; + Alignment al = new Alignment(seqs); + al.setDataset(null); + AlignViewport av = new AlignViewport(al); + + AlignFrame alignFrame = new AlignFrame(al, 700, 500); + AlignmentPanel ap = new AlignmentPanel(alignFrame, av); + + int oldres = av.getEndRes(); + ap.setScrollValues(-1, 5); + + // setting -ve x value does not change residue + assertEquals(av.getEndRes(), oldres); + + ap.setScrollValues(0, 5); + + // setting 0 as x value does not change residue + assertEquals(av.getEndRes(), oldres); + + ap.setScrollValues(5, 5); + // setting x value to 20 extends endRes by 20px converted to residues + assertEquals(av.getEndRes(), oldres + 5); + + + } +}