JAL-3201 group colour schemes distinct instances
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 26 Feb 2019 10:41:05 +0000 (10:41 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 26 Feb 2019 10:41:05 +0000 (10:41 +0000)
src/jalview/gui/SeqPanel.java
src/jalview/viewmodel/AlignmentViewport.java
test/jalview/gui/AlignViewportTest.java

index a4d4807..ec02bb1 100644 (file)
@@ -1872,8 +1872,11 @@ public class SeqPanel extends JPanel
             && afterDrag;
     if (stretchGroup.cs != null)
     {
-      stretchGroup.cs.alignmentChanged(stretchGroup,
-              av.getHiddenRepSequences());
+      if (afterDrag)
+      {
+        stretchGroup.cs.alignmentChanged(stretchGroup,
+                av.getHiddenRepSequences());
+      }
 
       ResidueShaderI groupColourScheme = stretchGroup
               .getGroupColourScheme();
index 1366ada..ca32ee7 100644 (file)
@@ -662,7 +662,7 @@ public abstract class AlignmentViewport
          * retain any colour thresholds per group while
          * changing choice of colour scheme (JAL-2386)
          */
-        sg.setColourScheme(cs);
+        sg.setColourScheme(cs.getInstance(sg, hiddenRepSequences));
         if (cs != null)
         {
           sg.getGroupColourScheme().alignmentChanged(sg,
index 7801250..959abb0 100644 (file)
@@ -23,6 +23,7 @@ package jalview.gui;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNotSame;
 import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 
@@ -33,8 +34,6 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
-import jalview.datamodel.PDBEntry;
-import jalview.datamodel.PDBEntry.Type;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.Sequence;
@@ -42,6 +41,7 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
+import jalview.schemes.ClustalxColourScheme;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.PIDColourScheme;
 import jalview.structure.StructureSelectionManager;
@@ -333,9 +333,34 @@ public class AlignViewportTest
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/uniref50.fa", DataSourceType.FILE);
     ColourSchemeI cs = new PIDColourScheme();
-    af.getViewport().setGlobalColourScheme(cs);
-    assertFalse(af.getViewport().getResidueShading()
+    AlignViewport viewport = af.getViewport();
+    viewport.setGlobalColourScheme(cs);
+    assertFalse(viewport.getResidueShading()
             .conservationApplied());
+
+    /*
+     * JAL-3201 groups have their own ColourSchemeI instances
+     */
+    AlignmentI aln = viewport.getAlignment();
+    SequenceGroup sg1 = new SequenceGroup();
+    sg1.addSequence(aln.getSequenceAt(0), false);
+    sg1.addSequence(aln.getSequenceAt(2), false);
+    SequenceGroup sg2 = new SequenceGroup();
+    sg2.addSequence(aln.getSequenceAt(1), false);
+    sg2.addSequence(aln.getSequenceAt(3), false);
+    aln.addGroup(sg1);
+    aln.addGroup(sg2);
+    viewport.setColourAppliesToAllGroups(true);
+    viewport.setGlobalColourScheme(new ClustalxColourScheme());
+    ColourSchemeI cs0 = viewport.getGlobalColourScheme();
+    ColourSchemeI cs1 = sg1.getColourScheme();
+    ColourSchemeI cs2 = sg2.getColourScheme();
+    assertTrue(cs0 instanceof ClustalxColourScheme);
+    assertTrue(cs1 instanceof ClustalxColourScheme);
+    assertTrue(cs2 instanceof ClustalxColourScheme);
+    assertNotSame(cs0, cs1);
+    assertNotSame(cs0, cs2);
+    assertNotSame(cs1, cs2);
   }
 
   @Test(groups = { "Functional" })