JAL-4380 Added information to annotation tooltips when description is not present improvement/JAL-4381_dynamic_value_colouring_of_annotations
authorBen Soares <b.soares@dundee.ac.uk>
Tue, 20 Feb 2024 15:35:22 +0000 (15:35 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Tue, 20 Feb 2024 15:35:22 +0000 (15:35 +0000)
src/jalview/gui/AnnotationPanel.java

index ea32684..c97ee53 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);