JAL-2374 JAL-2419 - TODO suspiciously redundant nested if clauses probably need a...
[jalview.git] / src / jalview / gui / SeqPanel.java
index 264ca8d..37b4852 100644 (file)
@@ -35,7 +35,7 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.io.SequenceAnnotationReport;
-import jalview.schemes.CollectionColourSchemeI;
+import jalview.renderer.ResidueShaderI;
 import jalview.schemes.ResidueProperties;
 import jalview.structure.SelectionListener;
 import jalview.structure.SelectionSource;
@@ -1587,42 +1587,15 @@ public class SeqPanel extends JPanel implements MouseListener,
 
     stretchGroup = av.getSelectionGroup();
 
-    if (stretchGroup == null)
+    if (stretchGroup == null || !stretchGroup.contains(sequence, res))
     {
-      stretchGroup = av.getAlignment().findGroup(sequence);
-
-      if ((stretchGroup != null) && (res > stretchGroup.getStartRes())
-              && (res < stretchGroup.getEndRes()))
+      stretchGroup = av.getAlignment().findGroup(sequence, res);
+      if (stretchGroup != null)
       {
+        // only update the current selection if the popup menu has a group to
+        // focus on
         av.setSelectionGroup(stretchGroup);
       }
-      else
-      {
-        stretchGroup = null;
-      }
-    }
-    else if (!stretchGroup.getSequences(null).contains(sequence)
-            || (stretchGroup.getStartRes() > res)
-            || (stretchGroup.getEndRes() < res))
-    {
-      stretchGroup = null;
-
-      SequenceGroup[] allGroups = av.getAlignment().findAllGroups(sequence);
-
-      if (allGroups != null)
-      {
-        for (int i = 0; i < allGroups.length; i++)
-        {
-          if ((allGroups[i].getStartRes() <= res)
-                  && (allGroups[i].getEndRes() >= res))
-          {
-            stretchGroup = allGroups[i];
-            break;
-          }
-        }
-      }
-
-      av.setSelectionGroup(stretchGroup);
     }
 
     if (evt.isPopupTrigger()) // Mac: mousePressed
@@ -1663,15 +1636,16 @@ public class SeqPanel extends JPanel implements MouseListener,
 
       if (av.getConservationSelected())
       {
-        SliderPanel.setConservationSlider(ap, av.getViewportColourScheme(),
-                "Background");
+        SliderPanel.setConservationSlider(ap, av.getResidueShading(),
+                ap.getViewName());
       }
 
       if (av.getAbovePIDThreshold())
       {
-        SliderPanel.setPIDSliderSource(ap, av.getViewportColourScheme(),
-                "Background");
+        SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
+                ap.getViewName());
       }
+      // TODO: stretchGroup will always be not null. Is this a merge error ?
       if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
       {
         // Edit end res position of selected group
@@ -1741,13 +1715,13 @@ public class SeqPanel extends JPanel implements MouseListener,
       stretchGroup.cs.alignmentChanged(stretchGroup,
               av.getHiddenRepSequences());
 
-      CollectionColourSchemeI groupColourScheme = stretchGroup.getGroupColourScheme();
+      ResidueShaderI groupColourScheme = stretchGroup.getGroupColourScheme();
       String name = stretchGroup.getName();
       if (stretchGroup.cs.conservationApplied())
       {
         SliderPanel.setConservationSlider(ap, groupColourScheme, name);
       }
-      else
+      if (stretchGroup.cs.getThreshold() > 0)
       {
         SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
       }