JAL-4380 Added information to annotation tooltips when description is not present
authorBen Soares <b.soares@dundee.ac.uk>
Tue, 20 Feb 2024 15:35:22 +0000 (15:35 +0000)
committerJames Procter <j.procter@dundee.ac.uk>
Mon, 28 Oct 2024 16:23:29 +0000 (16:23 +0000)
src/jalview/gui/AnnotationPanel.java

index 747eac3..24cd8bc 100755 (executable)
@@ -1275,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)
@@ -1290,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)
@@ -1337,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
    * 
@@ -1357,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);