X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fproject%2FJalview2xmlTests.java;h=783dd1cb90587a133b14488ea73bc03e3ea988dc;hb=5d49f772d8dd53aba8907f37a244b00ed8f86a87;hp=42d68a9dfc5d71339e798d8e7c84eb38cbd13872;hpb=7b32d373b60d0af55481cfd6d377b2cc1ec035c0;p=jalview.git diff --git a/test/jalview/project/Jalview2xmlTests.java b/test/jalview/project/Jalview2xmlTests.java index 42d68a9..783dd1c 100644 --- a/test/jalview/project/Jalview2xmlTests.java +++ b/test/jalview/project/Jalview2xmlTests.java @@ -23,11 +23,13 @@ package jalview.project; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNotSame; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; import java.awt.Color; +import java.awt.Rectangle; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -48,6 +50,7 @@ import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureColourI; import jalview.api.ViewStyleI; +import jalview.bin.Cache; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; @@ -69,8 +72,10 @@ import jalview.gui.AlignViewport; import jalview.gui.AlignmentPanel; import jalview.gui.Desktop; import jalview.gui.JvOptionPane; +import jalview.gui.OverviewPanel; import jalview.gui.PCAPanel; import jalview.gui.PopupMenu; +import jalview.gui.Preferences; import jalview.gui.SliderPanel; import jalview.io.DataSourceType; import jalview.io.FileFormat; @@ -160,8 +165,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase assertNotNull( ColourSchemeProperty.getColourScheme(viewport, viewport.getAlignment(), - viewport.getGlobalColourScheme() - .getSchemeName()), + viewport.getGlobalColourScheme().getSchemeName()), "Recognise T-Coffee score from string"); af.saveAlignment(tfile, FileFormat.Jalview); @@ -450,9 +454,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase Assert.assertEquals(Desktop.getAlignFrames().length, Desktop.getAlignmentPanels( af.getViewport().getSequenceSetId()).length); - Assert.assertEquals( - Desktop.getAlignmentPanels( - af.getViewport().getSequenceSetId()).length, + Assert.assertEquals(Desktop + .getAlignmentPanels(af.getViewport().getSequenceSetId()).length, oldviews); } @@ -1207,7 +1210,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqData, DataSourceType.PASTE); assertNotNull(af, "Didn't read in the example file correctly."); - + AlignmentViewPanel ap = Desktop.getAlignmentPanels(null)[0]; SequenceI pep = ap.getAlignment().getSequenceAt(0); SequenceI cds = ap.getAlignment().getSequenceAt(1); @@ -1239,7 +1242,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase Assert.fail("Didn't save the state", e); } Desktop.instance.closeAll_actionPerformed(null); - + new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), DataSourceType.FILE); AlignmentViewPanel rap = Desktop.getAlignmentPanels(null)[0]; @@ -1272,4 +1275,117 @@ public class Jalview2xmlTests extends Jalview2xmlBase assertTrue(dbRef instanceof GeneLocus); assertEquals(dbRef, dbref3); } + + /** + * test store and recovery of Overview windows + * + * @throws Exception + */ + @Test(groups = { "Functional" }, enabled = true) + public void testStoreAndRecoverOverview() throws Exception + { + Desktop.instance.closeAll_actionPerformed(null); + + Cache.setProperty("SHOW_OVERVIEW", "false"); + Cache.setProperty(Preferences.USE_LEGACY_GAP, "false"); + Cache.setColourProperty(Preferences.GAP_COLOUR, Color.green); + Cache.setColourProperty(Preferences.HIDDEN_COLOUR, Color.yellow); + Cache.setProperty(Preferences.SHOW_OV_HIDDEN_AT_START, "true"); + + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( + "examples/uniref50.fa", DataSourceType.FILE); + + /* + * open and resize / reposition overview + */ + af.overviewMenuItem_actionPerformed(null); + OverviewPanel ov1 = af.alignPanel.getOverviewPanel(); + assertNotNull(ov1); + ov1.setFrameBounds(20, 30, 200, 400); + assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa"); + assertTrue(ov1.isShowHiddenRegions()); + + /* + * open a New View and its Overview and reposition it + */ + af.newView_actionPerformed(null); + af.overviewMenuItem_actionPerformed(null); + OverviewPanel ov2 = af.alignPanel.getOverviewPanel(); + assertNotNull(ov2); + assertNotSame(ov1, ov2); + ov2.setFrameBounds(25, 35, 205, 405); + assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa Original"); + assertEquals(ov2.getTitle(), "Overview examples/uniref50.fa View 1"); + + File tfile = File.createTempFile("testStoreAndRecoverOverview", ".jvp"); + new Jalview2XML(false).saveState(tfile); + Desktop.instance.closeAll_actionPerformed(null); + + /* + * change preferences (should _not_ affect reloaded Overviews) + */ + Cache.setProperty("SHOW_OVERVIEW", "true"); + Cache.setProperty(Preferences.USE_LEGACY_GAP, "true"); + Cache.setColourProperty(Preferences.GAP_COLOUR, Color.blue); + Cache.setColourProperty(Preferences.HIDDEN_COLOUR, Color.orange); + Cache.setProperty(Preferences.SHOW_OV_HIDDEN_AT_START, "false"); + + af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), + DataSourceType.FILE); + + /* + * workaround: explicitly select View 1 (not in focus after restore) + */ + af.tabSelectionChanged(1); + + /* + * verify restored overview for View 1 + */ + ov2 = af.alignPanel.getOverviewPanel(); + assertEquals(ov2.getCanvas().getGapColour(), Color.green); + // 'non-legacy' colouring uses white for non-gapped residues + assertEquals(ov2.getCanvas().getResidueColour(), Color.white); + assertEquals(ov2.getCanvas().getHiddenColour(), Color.yellow); + assertEquals(ov2.getTitle(), "Overview examples/uniref50.fa View 1"); + assertEquals(ov2.getFrameBounds(), new Rectangle(25, 35, 205, 405)); + assertTrue(ov2.isShowHiddenRegions()); + + /* + * verify restored overview for Original view + */ + af.tabSelectionChanged(0); + ov1 = af.alignPanel.getOverviewPanel(); + assertEquals(ov1.getCanvas().getGapColour(), Color.green); + // 'non-legacy' colouring uses white for non-gapped residues + assertEquals(ov1.getCanvas().getResidueColour(), Color.white); + assertEquals(ov1.getCanvas().getHiddenColour(), Color.yellow); + assertEquals(ov1.getTitle(), "Overview examples/uniref50.fa Original"); + assertEquals(ov1.getFrameBounds(), new Rectangle(20, 30, 200, 400)); + assertTrue(ov1.isShowHiddenRegions()); + } + + /** + * Test that a view with no Overview is restored with no Overview, even if + * 'Open Overview' is selected in Preferences + * + * @throws Exception + */ + @Test(groups = { "Functional" }, enabled = true) + public void testStoreAndRecoverNoOverview() throws Exception + { + Cache.setProperty("SHOW_OVERVIEW", "false"); + Desktop.instance.closeAll_actionPerformed(null); + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( + ">seq1\nMATRSQFLVNF\n", DataSourceType.PASTE); + + File tfile = File.createTempFile("testStoreAndRecoverOverview", ".jvp"); + new Jalview2XML(false).saveState(tfile); + Desktop.instance.closeAll_actionPerformed(null); + + Cache.setProperty("SHOW_OVERVIEW", "true"); + af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), + DataSourceType.FILE); + + assertNull(af.alignPanel.getOverviewPanel()); + } }