JAL-1713 restore project with no Overview, regardless of Preferences
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Sat, 19 Dec 2020 07:22:07 +0000 (07:22 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Sat, 19 Dec 2020 07:22:07 +0000 (07:22 +0000)
src/jalview/project/Jalview2XML.java
test/jalview/project/Jalview2xmlTests.java

index 4bcdc81..5a8eac9 100644 (file)
@@ -4084,14 +4084,16 @@ public class Jalview2XML
    */
   protected void loadOverview(Viewport view, AlignFrame af)
   {
+    /*
+     * first close any Overview that was opened automatically
+     * (if so configured in Preferences) so that the view is
+     * restored in the same state as saved
+     */
+    af.alignPanel.closeOverviewPanel();
+
     Overview overview = view.getOverview();
     if (overview != null)
     {
-      /*
-       * first close any Overview that was opened automatically
-       * (if so configured in Preferences)
-       */
-      af.alignPanel.closeOverviewPanel();
       OverviewPanel overviewPanel = af
               .openOverviewPanel(overview.isShowHidden());
       overviewPanel.setTitle(overview.getTitle());
index 4350a14..351cedf 100644 (file)
@@ -164,8 +164,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);
@@ -454,9 +453,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);
   }
 
@@ -1210,7 +1208,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);
@@ -1242,7 +1240,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];
@@ -1285,26 +1283,26 @@ public class Jalview2xmlTests extends Jalview2xmlBase
   public void testStoreAndRecoverOverview() throws Exception
   {
     Desktop.instance.closeAll_actionPerformed(null);
-    
-    Cache.setProperty("SHOW_OVERVIEW",  "false");
+
+    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);
+    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
      */
@@ -1313,32 +1311,31 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     OverviewPanel ov2 = af.alignPanel.getOverviewPanel();
     assertNotNull(ov2);
     assertNotSame(ov1, ov2);
-    ov2.setFrameBounds(25,  35,  205,  405);
+    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("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
      */
@@ -1348,9 +1345,9 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     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));
+    assertEquals(ov2.getFrameBounds(), new Rectangle(25, 35, 205, 405));
     assertTrue(ov2.isShowHiddenRegions());
-    
+
     /*
      * verify restored overview for Original view
      */
@@ -1361,7 +1358,32 @@ public class Jalview2xmlTests extends Jalview2xmlBase
     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));
+    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());
+  }
 }