import static org.testng.Assert.assertEquals;
-import jalview.datamodel.Alignment;
+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 java.awt.Dimension;
-
-import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class AlignmentPanelTest
"Seq23",
"ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
- @BeforeClass(alwaysRun = true)
+ AlignFrame af;
+
+ @BeforeMethod(alwaysRun = true)
public void setUp()
{
- JvOptionPane.setInteractiveMode(false);
- JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ Jalview.main(new String[] { "-nonews", "-props",
+ "test/jalview/testProps.jvprops" });
+
+ Cache.applicationProperties.setProperty("SHOW_IDENTITY",
+ Boolean.TRUE.toString());
+ af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
+ DataSourceType.FILE);
+
+ /*
+ * 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()
{
- 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);
-
- AlignFrame alignFrame = new AlignFrame(al, 500, 700);
-
- alignFrame.alignPanel.getSeqPanel().seqCanvas
- .setPreferredSize(new Dimension(300, 300));
-
- int oldres = alignFrame.getViewport().getEndRes();
- alignFrame.alignPanel.setScrollValues(-1, 5);
+ int oldres = af.getViewport().getEndRes();
+ af.alignPanel.setScrollValues(-1, 5);
// setting -ve x value does not change residue
- assertEquals(alignFrame.getViewport().getEndRes(), oldres);
+ assertEquals(af.getViewport().getEndRes(), oldres);
- alignFrame.alignPanel.setScrollValues(0, 5);
+ af.alignPanel.setScrollValues(0, 5);
// setting 0 as x value does not change residue
- assertEquals(alignFrame.getViewport().getEndRes(), oldres);
-
- alignFrame.alignPanel.setScrollValues(5, 5);
- // setting x value to 20 extends endRes by 20px converted to residues
- assertEquals(alignFrame.getViewport().getEndRes(), oldres + 5);
-
-
+ assertEquals(af.getViewport().getEndRes(), oldres);
+
+ af.alignPanel.setScrollValues(5, 5);
+ // setting x value to 5 extends endRes by 5 residues
+ assertEquals(af.getViewport().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(af.getViewport().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(af.getViewport().getEndRes(), oldres + scrollpos);
+
+ // scroll to position within <width> 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(af.getViewport().getEndRes(), af.getViewport()
+ .getAlignment().getWidth() - 1);
+
+ // now hide some columns, and scroll to position within <width>
+ // 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(af.getViewport().getEndRes(), af.getViewport()
+ .getAlignment().getWidth() - 1 - 21); // 21 is the number of hidden
+ // columns
}
}