JAL-3468 truncate feature description to 40 chars in tooltip/menu item
[jalview.git] / src / jalview / io / SequenceAnnotationReport.java
index 5a55b5b..df28ea3 100644 (file)
@@ -46,6 +46,8 @@ import java.util.Map;
  */
 public class SequenceAnnotationReport
 {
+  private static final int MAX_DESCRIPTION_LENGTH = 40;
+
   private static final String COMMA = ",";
 
   private static final String ELLIPSIS = "...";
@@ -64,7 +66,7 @@ public class SequenceAnnotationReport
    * Comparator to order DBRefEntry by Source + accession id (case-insensitive),
    * with 'Primary' sources placed before others, and 'chromosome' first of all
    */
-  private static Comparator<DBRefEntry> comparator = new Comparator<DBRefEntry>()
+  private static Comparator<DBRefEntry> comparator = new Comparator<>()
   {
 
     @Override
@@ -206,6 +208,17 @@ public class SequenceAnnotationReport
       if (description != null && !description.equals(feature.getType()))
       {
         description = StringUtils.stripHtmlTags(description);
+
+        /*
+         * truncate overlong descriptions unless they contain an href
+         * (as truncation could leave corrupted html)
+         */
+        boolean hasLink = description.indexOf("a href") > -1;
+        if (description.length() > MAX_DESCRIPTION_LENGTH && !hasLink)
+        {
+          description = description.substring(0, MAX_DESCRIPTION_LENGTH)
+                  + ELLIPSIS;
+        }
         sb.append("; ").append(description);
       }
 
@@ -376,7 +389,7 @@ public class SequenceAnnotationReport
     if (sequence.getDescription() != null)
     {
       tmp = sequence.getDescription();
-      sb.append("<br>").append(tmp);
+      sb.append(tmp);
       maxWidth = Math.max(maxWidth, tmp.length());
     }
     SequenceI ds = sequence;