import static org.testng.Assert.assertEquals;
+import jalview.analysis.AlignmentGenerator;
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 java.util.List;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
@Test(singleThreaded = true)
public class OverviewDimensionsTest {
- boolean showConservationSetting;
-
SequenceI seq1 = new Sequence(
"Seq1",
"ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
AlignFrame af;
AlignViewport av;
+
+ AlignmentI al;
OverviewDimensions od;
- float scalew;
- float scaleh;
int boxWidth;
int boxHeight;
-
int viewHeight;
-
int viewWidth;
-
int alheight;
-
int alwidth;
@BeforeClass(alwaysRun = true)
{
JvOptionPane.setInteractiveMode(false);
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+
+ // create random alignment
+ AlignmentGenerator gen = new AlignmentGenerator(false);
+ al = gen.generate(157, 525, 123, 5, 5);
}
@BeforeMethod(alwaysRun = true)
Cache.applicationProperties.setProperty("SHOW_IDENTITY",
Boolean.TRUE.toString());
- af = new FileLoader().LoadFileWaitTillLoaded(
- "examples/testdata/bigal.fa",
- DataSourceType.FILE);
-
- /*
- * Wait for viewport to initialise
- */
- synchronized (this)
- {
- while (af.getViewport().getEndRes() == 0)
- {
- try
- {
- wait(50);
- } catch (InterruptedException e)
- {
- }
- }
- }
+ af = new FileLoader().LoadFileWaitTillLoaded(al.toString(),
+ DataSourceType.PASTE);
/*
* wait for Consensus thread to complete
}
}
}
-
- // get cached setting for showConservation
- // reset it in AfterClass!
- showConservationSetting = Cache.getDefault("SHOW_CONSERVATION", true);
av = af.getViewport();
- od = new OverviewDimensions(av);
+ od = new OverviewDimensions(av, true);
while (av.isCalcInProgress())
{
// o/w hidden seqs retain selection group, causes problems later when hiding
// sequences
- // wait for conservation calc to complete
+ // wait for conservation calc to complete again
while (av.isCalcInProgress())
{
try
viewWidth = av.getEndRes() - av.getStartRes();
// wait for gui to get set up
- while (viewHeight != 17 || viewWidth != 59)
+ while (viewHeight != 17 || viewWidth != 62)
{
try
{
@AfterMethod(alwaysRun = true)
public void tearDown()
{
- Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
- Boolean.toString(showConservationSetting));
+ af = null;
+ av = null;
Desktop.instance.closeAll_actionPerformed(null);
}
+ @AfterClass(alwaysRun = true)
+ public void cleanUp()
+ {
+ al = null;
+ }
+
/**
* Test that the OverviewDimensions constructor sets width and height
* correctly
int maxSeqHeight = 300;
int minSeqHeight = 40;
- Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
- Boolean.toString(true));
-
// test for alignment with width > height
SequenceI[] seqs1 = new SequenceI[] { seqa, seqb };
Alignment al1 = new Alignment(seqs1);
al1.setDataset(null);
AlignViewport av1 = new AlignViewport(al1);
- OverviewDimensions od = new OverviewDimensions(av1);
+ OverviewDimensions od = new OverviewDimensions(av1, true);
int scaledHeight = 266;
assertEquals(od.getGraphHeight(), defaultGraphHeight);
assertEquals(od.getSequencesHeight(), scaledHeight);
al2.setDataset(null);
AlignViewport av2 = new AlignViewport(al2);
- od = new OverviewDimensions(av2);
+ od = new OverviewDimensions(av2, true);
int scaledWidth = 300;
assertEquals(od.getGraphHeight(), defaultGraphHeight);
assertEquals(od.getSequencesHeight(), maxSeqHeight);
al3.setDataset(null);
AlignViewport av3 = new AlignViewport(al3);
- od = new OverviewDimensions(av3);
+ od = new OverviewDimensions(av3, true);
assertEquals(od.getGraphHeight(), defaultGraphHeight);
assertEquals(od.getSequencesHeight(), minSeqHeight);
assertEquals(od.getWidth(), maxWidth);
al4.setDataset(null);
AlignViewport av4 = new AlignViewport(al4);
- od = new OverviewDimensions(av4);
+ od = new OverviewDimensions(av4, true);
assertEquals(od.getGraphHeight(), defaultGraphHeight);
assertEquals(od.getSequencesHeight(), maxSeqHeight);
assertEquals(od.getWidth(), minWidth);
assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight);
- // test for alignment where no conservation annotation is shown
- Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
- Boolean.toString(false));
-
Alignment al5 = new Alignment(seqs4);
al5.setDataset(null);
AlignViewport av5 = new AlignViewport(al5);
- od = new OverviewDimensions(av5);
+ od = new OverviewDimensions(av5, false);
assertEquals(od.getGraphHeight(), 0);
assertEquals(od.getSequencesHeight(), maxSeqHeight);
assertEquals(od.getWidth(), minWidth);
@Test(groups = { "Functional" })
public void testSetBoxFromMouseClick()
{
- od.setBoxPositionByMouse(0, 0);
+ od.updateViewportFromMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenColsAtStart()
{
- od.setBoxPositionByMouse(0, 0);
+ od.updateViewportFromMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenColsInMiddle()
{
- od.setBoxPositionByMouse(0, 0);
+ od.updateViewportFromMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getScrollRow(), 0);
// hide columns 60-68, no change to box position or dimensions
- int firstHidden = 60;
- int lastHidden = 68;
+ int firstHidden = 63;
+ int lastHidden = 73;
hideColumns(firstHidden, lastHidden);
od.setBoxPosition();
// move box so that it overlaps with hidden cols on one side
// box width changes, boxX and scrollCol as for unhidden case
- int xpos = 50 - boxWidth; // 50 is position in overview halfway between cols
- // 60 and 70
+ int xpos = 55 - boxWidth; // 55 is position in overview approx halfway
+ // between cols 60 and 70
mouseClick(od, xpos, 0);
assertEquals(od.getBoxX(), xpos);
assertEquals(od.getBoxY(), 0);
// move box so that it completely covers hidden cols
// box width changes, boxX and scrollCol as for hidden case
- xpos = 30;
+ xpos = 33;
mouseClick(od, xpos, 0);
assertEquals(od.getBoxX(), xpos);
assertEquals(od.getBoxY(), 0);
* od.getWidth() / alwidth));
assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(od.getScrollCol(),
- Math.round(xpos * alwidth / od.getWidth()));
+ Math.round((float) xpos * alwidth / od.getWidth()));
assertEquals(od.getScrollRow(), 0);
// move box so boxX is in hidden cols, box overhangs at right
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenColsAtEnd()
{
- od.setBoxPositionByMouse(0, 0);
+ od.updateViewportFromMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
@Test(groups = { "Functional" })
public void testSetBoxFromViewportHiddenColsInMiddle()
{
- int firstHidden = 65;
- int lastHidden = 75;
+ int firstHidden = 68;
+ int lastHidden = 78;
hideColumns(firstHidden, lastHidden);
// move viewport before hidden columns
assertEquals(od.getBoxHeight(), boxHeight);
// move viewport to straddle hidden columns
- moveViewport(60, 0);
+ moveViewport(63, 0);
assertEquals(od.getBoxX(),
- Math.round((float) 60 * od.getWidth() / alwidth));
+ Math.round((float) 63 * od.getWidth() / alwidth));
assertEquals(od.getBoxY(), 0);
assertEquals(
od.getBoxWidth(),
@Test(groups = { "Functional" })
public void testSetBoxFromViewportHiddenColsAtEnd()
{
- int firstHidden = 145;
- int lastHidden = 157;
+ int firstHidden = 152;
+ int lastHidden = 164;
hideColumns(firstHidden, lastHidden);
// move viewport before hidden columns
// move viewport to hidden columns
// TODO boxwidth includes hidden in overview panel (why?)
- moveViewport(98, 0);
+ moveViewport(102, 0);
assertEquals(od.getBoxX(),
- Math.round((float) 98 * od.getWidth() / alwidth));
+ Math.round((float) 102 * od.getWidth() / alwidth));
assertEquals(od.getBoxY(), 0);
- assertEquals(
- od.getBoxWidth(),
- boxWidth
- + Math.round((float) (lastHidden - firstHidden + 1)
+ assertEquals(od.getBoxWidth(), boxWidth
+ + Math.round((float) (lastHidden - firstHidden)
* od.getWidth() / alwidth));
assertEquals(od.getBoxHeight(), boxHeight);
}
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenRowsAtStart()
{
- od.setBoxPositionByMouse(0, 0);
+ od.updateViewportFromMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxHeight(), boxHeight);
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenRowsInMiddle()
{
- od.setBoxPositionByMouse(0, 0);
+ od.updateViewportFromMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenRowsAtEnd()
{
- od.setBoxPositionByMouse(0, 0);
+ od.updateViewportFromMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
*/
private void mouseClick(OverviewDimensions od, int x, int y)
{
- od.setBoxPositionByMouse(x, y);
+ od.updateViewportFromMouse(x, y);
// updates require an OverviewPanel to exist which it doesn't here
// so call setBoxPosition() as it would be called by the AlignmentPanel
// normally