Merge branch 'develop' into features/JAL-4134_use_annotation_row_for_colours_and_groups
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index f1a8af7..9970702 100755 (executable)
@@ -656,7 +656,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       fr = Math.min(cXci.cStart, cXci.cEnd);
       to = Math.max(cXci.cStart, cXci.cEnd);
 
-      if (evt.isControlDown())
+      // double click selects the whole group
+      if (evt.getClickCount() == 2)
       {
         ContactMatrixI matrix = av.getContactMatrix(clicked);
 
@@ -667,6 +668,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
           {
             SequenceI rseq = clicked.sequenceRef;
             BitSet grp = matrix.getGroupsFor(currentX);
+            // TODO: cXci needs to be mapped to real groups
             for (int c = fr; c <= to; c++)
             {
               BitSet additionalGrp = matrix.getGroupsFor(c);
@@ -697,16 +699,18 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       {
         // select corresponding range in segment under mouse
         {
-          for (int c = fr; c <= to; c++)
+          int[] rng = forCurrentX.getMappedPositionsFor(fr, to);
+          if (rng != null)
           {
-            av.getColumnSelection().addElement(c);
+            av.getColumnSelection().addRangeOfElements(rng, true);
           }
           av.getColumnSelection().addElement(currentX);
         }
         // PAE SPECIFIC
         // and also select everything lower than the max range adjacent
         // (kind of works)
-        if (PAEContactMatrix.PAEMATRIX.equals(clicked.getCalcId()))
+        if (evt.isControlDown()
+                && PAEContactMatrix.PAEMATRIX.equals(clicked.getCalcId()))
         {
           int c = fr - 1;
           ContactRange cr = forCurrentX.getRangeFor(fr, to);
@@ -724,12 +728,17 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
             if (// cr.getMin() <= cval &&
             cval <= thresh)
             {
-              av.getColumnSelection().addElement(c--);
-            }
-            else
-            {
-              break;
+              int[] cols = forCurrentX.getMappedPositionsFor(c, c);
+              if (cols != null)
+              {
+                av.getColumnSelection().addRangeOfElements(cols, true);
+              }
+              else
+              {
+                break;
+              }
             }
+            c--;
           }
           c = to;
           while (c < forCurrentX.getContactHeight())
@@ -738,12 +747,18 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
             if (// cr.getMin() <= cval &&
             cval <= thresh)
             {
-              av.getColumnSelection().addElement(c++);
+              int[] cols = forCurrentX.getMappedPositionsFor(c, c);
+              if (cols != null)
+              {
+                av.getColumnSelection().addRangeOfElements(cols, true);
+              }
             }
             else
             {
               break;
             }
+            c++;
+
           }
         }
       }
@@ -1052,32 +1067,51 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       int fr, to;
       fr = Math.min(lastXci.cStart, lastXci.cEnd);
       to = Math.max(lastXci.cStart, lastXci.cEnd);
-      jalview.bin.Console.trace("Marking " + fr + " to " + to);
-      for (int c = fr; c <= to; c++)
+      int[] mappedPos = forFromX.getMappedPositionsFor(fr, to);
+      if (mappedPos != null)
       {
-        if (cma.sequenceRef != null)
+        jalview.bin.Console.trace("Marking " + fr + " to " + to
+                + " mapping to sequence positions " + mappedPos[0] + " to "
+                + mappedPos[1]);
+        for (int pair = 0; pair < mappedPos.length; pair += 2)
         {
-          int col = cma.sequenceRef.findIndex(c);
-          av.getColumnSelection().addElement(col);
-        }
-        else
-        {
-          av.getColumnSelection().addElement(c);
+          for (int c = mappedPos[pair]; c <= mappedPos[pair + 1]; c++)
+          // {
+          // if (cma.sequenceRef != null)
+          // {
+          // int col = cma.sequenceRef.findIndex(cma.sequenceRef.getStart()+c);
+          // av.getColumnSelection().addElement(col);
+          // }
+          // else
+          {
+            av.getColumnSelection().addElement(c);
+          }
         }
       }
+      // and again for most recent corner of drag
       fr = Math.min(cXci.cStart, cXci.cEnd);
       to = Math.max(cXci.cStart, cXci.cEnd);
-      jalview.bin.Console.trace("Marking " + fr + " to " + to);
-      for (int c = fr; c <= to; c++)
+      mappedPos = forFromX.getMappedPositionsFor(fr, to);
+      if (mappedPos != null)
       {
-        if (cma.sequenceRef != null)
+        for (int pair = 0; pair < mappedPos.length; pair += 2)
         {
-          int col = cma.sequenceRef.findIndex(c);
-          av.getColumnSelection().addElement(col);
-        }
-        else
-        {
-          av.getColumnSelection().addElement(c);
+          jalview.bin.Console.trace("Marking " + fr + " to " + to
+                  + " mapping to sequence positions " + mappedPos[pair]
+                  + " to " + mappedPos[pair + 1]);
+          for (int c = mappedPos[pair]; c <= mappedPos[pair + 1]; c++)
+          {
+            // if (cma.sequenceRef != null)
+            // {
+            // int col =
+            // cma.sequenceRef.findIndex(cma.sequenceRef.getStart()+c);
+            // av.getColumnSelection().addElement(col);
+            // }
+            // else
+            {
+              av.getColumnSelection().addElement(c);
+            }
+          }
         }
       }
       fr = Math.min(lastX, currentX);
@@ -1250,12 +1284,28 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
         ContactRange cr = clist.getRangeFor(ci.cStart, ci.cEnd);
         tooltip = "Contact from " + clist.getPosition() + ", [" + ci.cStart
                 + " - " + ci.cEnd + "]" + "<br/>Mean:" + cr.getMean();
+
         int col = ann.sequenceRef.findPosition(column);
+        int[][] highlightPos;
+        int[] mappedPos = clist.getMappedPositionsFor(ci.cStart, ci.cEnd);
+        if (mappedPos != null)
+        {
+          highlightPos = new int[1 + mappedPos.length][2];
+          highlightPos[0] = new int[] { col, col };
+          for (int p = 0, h = 0; p < mappedPos.length; h++, p += 2)
+          {
+            highlightPos[h][0] = ann.sequenceRef
+                    .findPosition(mappedPos[p] - 1);
+            highlightPos[h][1] = ann.sequenceRef
+                    .findPosition(mappedPos[p + 1] - 1);
+          }
+        }
+        else
+        {
+          highlightPos = new int[][] { new int[] { col, col } };
+        }
         ap.getStructureSelectionManager()
-                .highlightPositionsOn(ann.sequenceRef, new int[][]
-                { new int[] { col, col },
-                    new int[]
-                    { ci.cStart, ci.cEnd } }, null);
+                .highlightPositionsOn(ann.sequenceRef, highlightPos, null);
       }
     }
     return tooltip;