JAL-2349 JAL-3855 highlight residues associated with elements under mouse - Jmol...
authorJim Procter <j.procter@dundee.ac.uk>
Sat, 22 Oct 2022 11:40:35 +0000 (12:40 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Sat, 22 Oct 2022 11:40:35 +0000 (12:40 +0100)
src/jalview/gui/AnnotationPanel.java
src/jalview/renderer/ContactGeometry.java
src/jalview/structure/StructureSelectionManager.java

index e12cc3f..d31e52d 100755 (executable)
@@ -1097,14 +1097,16 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
       if (clist != null)
       {
         ContactGeometry cgeom = new ContactGeometry(clist, ann.graphHeight);
-        ContactGeometry.contactInterval ci = cgeom.mapFor(rowAndOffset,
-                rowAndOffset);
+        ContactGeometry.contactInterval ci = cgeom.mapFor(rowAndOffset);
         ContactRange cr = clist.getRangeFor(ci.cStart, ci.cEnd);
         tooltip = "Contact from " + clist.getPosition() + ", [" + ci.cStart
                 + " - " + ci.cEnd + "]" + "<br/>Mean:" + cr.getMean();
-
-        // ap.getStructureSelectionManager().mouseOverSequence(ann.sequenceRef,
-        // new int[] {column, ci.cStart,ci.cEnd}, -1, null)
+        int col = ann.sequenceRef.findPosition(column);
+        ap.getStructureSelectionManager()
+                .highlightPositionsOn(ann.sequenceRef, new int[][]
+                { new int[] { col, col },
+                    new int[]
+                    { ci.cStart, ci.cEnd } }, null);
       }
     }
     return tooltip;
index 52581fb..4aef1d8 100644 (file)
@@ -12,8 +12,11 @@ public class ContactGeometry
 
   final int contact_height;
 
+  final int graphHeight;
+
   public ContactGeometry(ContactListI contacts, int graphHeight)
   {
+    this.graphHeight = graphHeight;
     contact_height = contacts.getContactHeight();
     // fractional number of contacts covering each pixel
     contacts_per_pixel = (graphHeight < 1) ? contact_height
@@ -71,6 +74,25 @@ public class ContactGeometry
     return ci;
   }
 
+  /**
+   * return the cell containing given pixel
+   * 
+   * @param pCentre
+   * @return range for pCEntre
+   */
+  public contactInterval mapFor(int pCentre)
+  {
+    int pStart = Math.max(pCentre - pixels_step, 0);
+    int pEnd = Math.min(pStart + pixels_step, graphHeight);
+    int cStart = (int) Math.floor(pStart * contacts_per_pixel);
+    contactInterval ci = new contactInterval(cStart,
+            (int) Math.min(contact_height,
+                    Math.ceil(cStart + (pixels_step) * contacts_per_pixel)),
+            pStart, pEnd);
+
+    return ci;
+  }
+
   public Iterator<contactInterval> iterateOverContactIntervals(
           int graphHeight)
   {
index c8a846c..ba3ef71 100644 (file)
@@ -874,6 +874,52 @@ public class StructureSelectionManager
   }
 
   /**
+   * hack to highlight a range of positions at once on any structure views
+   * 
+   * @param sequenceRef
+   * @param is
+   *          - series of int start-end ranges as positions on sequenceRef
+   * @param i
+   * @param object
+   */
+  public void highlightPositionsOn(SequenceI sequenceRef, int[][] is,
+          Object source)
+  {
+    boolean hasSequenceListeners = handlingVamsasMo
+            || !seqmappings.isEmpty();
+    SearchResultsI results = null;
+    ArrayList<Integer> listOfPositions = new ArrayList<Integer>();
+    for (int[] s_e : is)
+    {
+      for (int p = s_e[0]; p <= s_e[1]; listOfPositions.add(p++))
+        ;
+    }
+    int seqpos[] = new int[listOfPositions.size()];
+    int i = 0;
+    for (Integer p : listOfPositions)
+    {
+      seqpos[i++] = p;
+    }
+
+    for (i = 0; i < listeners.size(); i++)
+    {
+      Object listener = listeners.elementAt(i);
+      if (listener == source)
+      {
+        // TODO listener (e.g. SeqPanel) is never == source (AlignViewport)
+        // Temporary fudge with SequenceListener.getVamsasSource()
+        continue;
+      }
+      if (listener instanceof StructureListener)
+      {
+        highlightStructure((StructureListener) listener, sequenceRef,
+                seqpos);
+      }
+
+    }
+  }
+
+  /**
    * Propagate mouseover of a single position in a structure
    * 
    * @param pdbResNum