JAL-2374 fix popup out by one and multiple groups bugs
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 5 Jan 2017 16:00:23 +0000 (16:00 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 5 Jan 2017 16:00:23 +0000 (16:00 +0000)
src/jalview/appletgui/SeqPanel.java
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentI.java
src/jalview/gui/SeqPanel.java

index 8d6e683..4278744 100644 (file)
@@ -1425,19 +1425,12 @@ public class SeqPanel extends Panel implements MouseMotionListener,
 
     if (stretchGroup == null)
     {
-      stretchGroup = av.getAlignment().findGroup(sequence);
-      if (stretchGroup != null && res > stretchGroup.getStartRes()
-              && res < stretchGroup.getEndRes())
-      {
-        av.setSelectionGroup(stretchGroup);
-      }
-      else
-      {
-        stretchGroup = null;
-      }
+      stretchGroup = av.getAlignment().findGroup(sequence, res);
+      av.setSelectionGroup(stretchGroup);
     }
 
-    else if (!stretchGroup.getSequences(null).contains(sequence)
+    if (stretchGroup == null
+            || !stretchGroup.getSequences(null).contains(sequence)
             || stretchGroup.getStartRes() > res
             || stretchGroup.getEndRes() < res)
     {
index d651c1d..90bdcae 100755 (executable)
@@ -366,17 +366,18 @@ public class Alignment implements AlignmentI
    * @see jalview.datamodel.AlignmentI#findGroup(jalview.datamodel.SequenceI)
    */
   @Override
-  public SequenceGroup findGroup(SequenceI s)
+  public SequenceGroup findGroup(SequenceI seq, int position)
   {
     synchronized (groups)
     {
-      for (int i = 0; i < this.groups.size(); i++)
+      for (SequenceGroup sg : groups)
       {
-        SequenceGroup sg = groups.get(i);
-
-        if (sg.getSequences(null).contains(s))
+        if (sg.getSequences(null).contains(seq))
         {
-          return sg;
+          if (position >= sg.getStartRes() && position <= sg.getEndRes())
+          {
+            return sg;
+          }
         }
       }
     }
index 7274e5f..2df099a 100755 (executable)
@@ -156,15 +156,16 @@ public interface AlignmentI extends AnnotatedCollectionI
   int findIndex(SequenceI s);
 
   /**
-   * Finds group that given sequence is part of.
+   * Returns the first group (in the order in which groups were added) that
+   * includes the given sequence and aligned position (base 0), or null if none
+   * found
    * 
-   * @param s
-   *          Sequence in alignment.
+   * @param seq
+   * @param position
    * 
-   * @return First group found for sequence. WARNING : Sequences may be members
-   *         of several groups. This method is incomplete.
+   * @return
    */
-  SequenceGroup findGroup(SequenceI s);
+  SequenceGroup findGroup(SequenceI seq, int position);
 
   /**
    * Finds all groups that a given sequence is part of.
index 8726c4a..5b87445 100644 (file)
@@ -60,7 +60,6 @@ import java.awt.event.MouseWheelListener;
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.SwingUtilities;
 import javax.swing.ToolTipManager;
@@ -1589,19 +1588,11 @@ public class SeqPanel extends JPanel implements MouseListener,
 
     if (stretchGroup == null)
     {
-      stretchGroup = av.getAlignment().findGroup(sequence);
-
-      if ((stretchGroup != null) && (res > stretchGroup.getStartRes())
-              && (res < stretchGroup.getEndRes()))
-      {
-        av.setSelectionGroup(stretchGroup);
-      }
-      else
-      {
-        stretchGroup = null;
-      }
+      stretchGroup = av.getAlignment().findGroup(sequence, res);
+      av.setSelectionGroup(stretchGroup);
     }
-    else if (!stretchGroup.getSequences(null).contains(sequence)
+    if (stretchGroup == null
+            || !stretchGroup.getSequences(null).contains(sequence)
             || (stretchGroup.getStartRes() > res)
             || (stretchGroup.getEndRes() < res))
     {