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 jalview.structure.StructureImportSettings;
import jalview.util.matcher.Condition;
import jalview.viewmodel.AlignmentViewport;
+import jalview.viewmodel.AlignmentViewport.AutoAnnotation;
import java.awt.Color;
import java.io.File;
}
/**
- * Test that annotation ordering is faithfully restored
+ * Tests that annotation ordering is faithfully restored, on project reload or
+ * New View, even if preference settings have changed
*
* @throws Exception
*/
newPanel.closePanel();
/*
- * reload the project with Preferences set to not create Occupancy;
- * this should still appear, as it is in the saved project
+ * reload the project with Preferences set to not create Occupancy, but to
+ * create Quality; annotations should still appear as saved in the project;
+ * preferences should be left unchanged (after temporary override)
*/
Desktop.instance.closeAll_actionPerformed(null);
Cache.setProperty("SHOW_OCCUPANCY", "false");
+ Cache.removeProperty("SHOW_QUALITY"); // will default to true
+ Map<String, String> originalPreferences = Cache.getProperties(
+ AutoAnnotation.OCCUPANCY.preferenceKey,
+ AutoAnnotation.CONSERVATION.preferenceKey,
+ AutoAnnotation.QUALITY.preferenceKey,
+ AutoAnnotation.CONSENSUS.preferenceKey);
af = new FileLoader().LoadFileWaitTillLoaded(
projectFile.getAbsolutePath(), DataSourceType.FILE);
- anns = af.getViewport().getAlignment().getAlignmentAnnotation();
+ alignment = af.getViewport().getAlignment();
+ anns = alignment.getAlignmentAnnotation();
assertEquals(anns.length, 4);
assertEquals(anns[0].label, "Occupancy");
assertEquals(anns[1].label, "hello");
assertEquals(anns[2].label, "Conservation");
assertEquals(anns[3].label, "world");
+ Map<String, String> newPreferences = Cache.getProperties(
+ AutoAnnotation.OCCUPANCY.preferenceKey,
+ AutoAnnotation.CONSERVATION.preferenceKey,
+ AutoAnnotation.QUALITY.preferenceKey,
+ AutoAnnotation.CONSENSUS.preferenceKey);
+ assertEquals(originalPreferences, newPreferences);
+ assertNull(Cache.getProperty(AutoAnnotation.QUALITY.preferenceKey));
+
+ /*
+ * make a new view, reorder its annotations, and delete and hide
+ * a different annotation in each of the two views
+ */
+ newPanel = af.newView("new", true);
+ af.getViewport().setViewName("Original");
+
+ /*
+ * just for interest - new view has the same manual annotation objects,
+ * but new auto-calculated annotations
+ */
+ AlignmentI newAlignment = newPanel.getAlignment();
+ newAnns = newAlignment.getAlignmentAnnotation();
+ assertNotSame(anns[0], newAnns[0]);
+ assertSame(anns[1], newAnns[1]);
+ assertNotSame(anns[2], newAnns[2]);
+ assertSame(anns[3], newAnns[3]);
+
+ alignment.deleteAnnotation(anns[2]); // delete Conservation view 1
+ anns[1].visible = false; // hide 'hello' view 1
+
+ tmp = newAnns[0];
+ newAnns[0] = newAnns[3]; // 'world' moved to top of new view
+ newAnns[3] = tmp; // then hello, Conservation, Occupancy
+ newAnns[0].visible = false; // hide 'world' in new view
+ newAnns[3].graphHeight = 99; // set height of Occupancy
+ newAlignment.deleteAnnotation(newAnns[1]); // delete 'hello' in new view
/*
- * reload the project with Preferences set to create Quality annotation;
- * this should not appear, as it is not in the saved project
+ * save, reload and verify annotations in both views
*/
+ ((AlignViewport) newPanel.getAlignViewport()).setViewName("New View");
+ projectFile = File.createTempFile("jvTest", ".jvp");
+ new Jalview2XML(false).saveState(projectFile);
Desktop.instance.closeAll_actionPerformed(null);
- Cache.setProperty("SHOW_OCCUPANCY", "false");
- Cache.setProperty("SHOW_QUALITY", "true");
af = new FileLoader().LoadFileWaitTillLoaded(
projectFile.getAbsolutePath(), DataSourceType.FILE);
- anns = af.getViewport().getAlignment().getAlignmentAnnotation();
- assertEquals(anns.length, 4);
+ assertEquals(af.getAlignPanels().size(), 2);
+
+ /*
+ * check first view
+ */
+ AlignViewportI firstViewport = af.getAlignPanels().get(0)
+ .getAlignViewport();
+ assertEquals(((AlignViewport) firstViewport).getViewName(), "Original");
+ alignment = firstViewport.getAlignment();
+ anns = alignment.getAlignmentAnnotation();
+ assertEquals(anns.length, 3);
assertEquals(anns[0].label, "Occupancy");
assertEquals(anns[1].label, "hello");
- assertEquals(anns[2].label, "Conservation");
- assertEquals(anns[3].label, "world");
+ assertEquals(anns[2].label, "world");
+ assertFalse(anns[0].visible);
+ assertFalse(anns[1].visible);
+ assertFalse(anns[2].visible);
+
+ /*
+ * check second view
+ */
+ AlignViewportI secondViewport = af.getAlignPanels().get(1)
+ .getAlignViewport();
+ assertEquals(((AlignViewport) secondViewport).getViewName(),
+ "New View");
+ alignment = secondViewport.getAlignment();
+ anns = alignment.getAlignmentAnnotation();
+ assertEquals(anns.length, 3);
+ assertEquals(anns[0].label, "world");
+ assertEquals(anns[1].label, "Conservation");
+ assertEquals(anns[2].label, "Occupancy");
+ assertFalse(anns[0].visible);
+ assertTrue(anns[1].visible);
+ assertFalse(anns[2].visible);
+ assertEquals(anns[2].graphHeight, 99);
}
}