/*
* 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 static org.testng.Assert.assertNotEquals;
import jalview.bin.Cache;
import jalview.bin.Jalview;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.io.DataSourceType;
import jalview.io.FileLoader;
import jalview.viewmodel.ViewportRanges;
import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities;
import org.testng.annotations.BeforeMethod;
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");
AlignFrame af;
@BeforeMethod(alwaysRun = true)
public void setUp() throws InvocationTargetException, InterruptedException
{
Jalview.main(new String[] { "-nonews", "-props",
"test/jalview/testProps.jvprops" });
Cache.setPropertyNoSave("SHOW_IDENTITY",
Boolean.TRUE.toString());
af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
DataSourceType.FILE);
/*
* ensure the panel has been repainted and so ViewportRanges set
*/
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
af.repaint();
}});
/*
* wait for Consensus thread to complete
*/
synchronized (this)
{
while (af.getViewport().getConsensusSeq() == null)
{
try
{
wait(50);
} catch (InterruptedException e)
{
}
}
}
}
/**
* Test side effect that end residue is set correctly by setScrollValues, with
* or without hidden columns
*/
@Test(groups = "Functional")
public void TestSetScrollValues()
{
ViewportRanges ranges = af.getViewport().getRanges();
af.alignPanel.setScrollValues(0, 0);
int oldres = ranges.getEndRes();
af.alignPanel.setScrollValues(-1, 5);
// setting -ve x value does not change residue
assertEquals(ranges.getEndRes(), oldres);
af.alignPanel.setScrollValues(0, 5);
// setting 0 as x value does not change residue
assertEquals(ranges.getEndRes(), oldres);
af.alignPanel.setScrollValues(5, 5);
// setting x value to 5 extends endRes by 5 residues
assertEquals(ranges.getEndRes(), oldres + 5);
// scroll to position after hidden columns sets endres to oldres (width) +
// position
int scrollpos = 60;
af.getViewport().hideColumns(30, 50);
af.alignPanel.setScrollValues(scrollpos, 5);
assertEquals(ranges.getEndRes(), oldres + scrollpos);
// scroll to position within hidden columns, still sets endres to oldres +
// position
// not sure if this is actually correct behaviour but this is what Jalview
// currently does
scrollpos = 40;
af.getViewport().showAllHiddenColumns();
af.getViewport().hideColumns(30, 50);
af.alignPanel.setScrollValues(scrollpos, 5);
assertEquals(ranges.getEndRes(), oldres + scrollpos);
// scroll to position within distance of the end of the alignment
// endRes should be set to width of alignment - 1
scrollpos = 130;
af.getViewport().showAllHiddenColumns();
af.alignPanel.setScrollValues(scrollpos, 5);
assertEquals(ranges.getEndRes(), af.getViewport()
.getAlignment().getWidth() - 1);
// now hide some columns, and scroll to position within
// distance of the end of the alignment
// endRes should be set to width of alignment - 1 - the number of hidden
// columns
af.getViewport().hideColumns(30, 50);
af.alignPanel.setScrollValues(scrollpos, 5);
assertEquals(ranges.getEndRes(), af.getViewport()
.getAlignment().getWidth() - 1 - 21); // 21 is the number of hidden
// columns
}
/**
* Test that update layout reverts to original (unwrapped) values for endRes
* when switching from wrapped back to unwrapped mode (JAL-2739)
*/
@Test(groups = "Functional")
public void TestUpdateLayout_endRes()
{
// get details of original alignment dimensions
ViewportRanges ranges = af.getViewport().getRanges();
int endres = ranges.getEndRes();
// wrap
af.alignPanel.getAlignViewport().setWrapAlignment(true);
af.alignPanel.updateLayout();
// endRes has changed
assertNotEquals(ranges.getEndRes(), endres);
// unwrap
af.alignPanel.getAlignViewport().setWrapAlignment(false);
af.alignPanel.updateLayout();
// endRes back to original value
assertEquals(ranges.getEndRes(), endres);
}
}