JAL-4380 Added information to annotation tooltips when description is not present
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index e1193c9..c97ee53 100755 (executable)
@@ -192,21 +192,27 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     renderer = new AnnotationRenderer();
   }
 
+  /**
+   * Responds to a mouse wheel movement by scrolling the annotations up or down.
+   * Annotation labels are scrolled via method adjustmentValueChanged when the
+   * vertical scrollbar is adjusted.
+   * <p>
+   * If shift is pressed, then scrolling is left or right instead, and is
+   * delegated to AlignmentPanel, so that both sequences and annotations are
+   * scrolled together.
+   * <p>
+   * This object is a MouseWheelListener to AnnotationLabels, so mouse wheel
+   * events over the labels are delegated to this method.
+   * <p>
+   * Note that this method may also be fired by scrolling with a gesture on a
+   * trackpad.
+   */
   @Override
   public void mouseWheelMoved(MouseWheelEvent e)
   {
     if (e.isShiftDown())
     {
-      e.consume();
-      double wheelRotation = e.getPreciseWheelRotation();
-      if (wheelRotation > 0)
-      {
-        av.getRanges().scrollRight(true);
-      }
-      else if (wheelRotation < 0)
-      {
-        av.getRanges().scrollRight(false);
-      }
+      ap.getSeqPanel().mouseWheelMoved(e);
     }
     else
     {
@@ -677,7 +683,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
             {
               SequenceI rseq = clicked.sequenceRef;
               BitSet grp = new BitSet();
-              grp.or(matrix.getGroupsFor(currentX));
+              grp.or(matrix.getGroupsFor(forCurrentX.getPosition()));
               // TODO: cXci needs to be mapped to real groups
               for (int c = fr; c <= to; c++)
               {
@@ -1269,8 +1275,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
           if (!first)
           {
             tip.append("<br>");
+            first = false;
           }
-          first = false;
           tip.append(anns[i].label);
           String description = anns[i].annotations[column].description;
           if (description != null && description.length() > 0)
@@ -1284,7 +1290,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     else if (column < ann.annotations.length
             && ann.annotations[column] != null)
     {
-      tooltip = ann.annotations[column].description;
+      tooltip = getAnnotationBriefSummary(ann.annotations[column]);
     }
     // TODO abstract tooltip generator so different implementations can be built
     if (ann.graph == AlignmentAnnotation.CONTACT_MAP)
@@ -1331,6 +1337,31 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     return tooltip;
   }
 
+  private static String getAnnotationBriefSummary(Annotation a)
+  {
+    String tt = a.description;
+    if (tt == null || tt.trim().length() == 0)
+    {
+      tt = String.valueOf(a.displayCharacter);
+    }
+    if ((tt == null || tt.length() == 0) && !Float.isNaN(a.value))
+    {
+      if (a.value == Math.floor(a.value)) // likely integer value
+      {
+        tt = String.format("%.0f", a.value);
+      }
+      else // display as is
+      {
+        tt = String.valueOf(a.value);
+      }
+    }
+    if (tt == null || tt.trim().length() == 0)
+    {
+      tt = String.valueOf(a.secondaryStructure);
+    }
+    return tt;
+  }
+
   /**
    * Constructs and returns the status bar message
    * 
@@ -1351,7 +1382,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
 
     if (column < ann.annotations.length && ann.annotations[column] != null)
     {
-      String description = ann.annotations[column].description;
+      String description = getAnnotationBriefSummary(
+              ann.annotations[column]);
       if (description != null && description.trim().length() > 0)
       {
         text.append("  ").append(description);