JAL-4240 Remove unnecessary whitespace, being rendered in JalviewJS. Split on both...
authorBen Soares <b.soares@dundee.ac.uk>
Fri, 10 Nov 2023 22:27:09 +0000 (22:27 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Fri, 10 Nov 2023 22:27:09 +0000 (22:27 +0000)
src/jalview/gui/JvSwingUtils.java

index e7f992d..c00be98 100644 (file)
@@ -73,20 +73,36 @@ public final class JvSwingUtils
     ttext = ttext.trim();
     boolean maxLengthExceeded = false;
 
-    if (ttext.contains("<br>"))
+    boolean hasBr = false;
+    for (String br : new String[] { "<br>", "<br/>" })
     {
-      String[] htmllines = ttext.split("<br>");
-      for (String line : htmllines)
+      hasBr = true;
+      if (ttext.contains(br))
       {
-        maxLengthExceeded = line.length() > 60;
-        if (maxLengthExceeded)
+        String[] htmllines = ttext.split(br);
+        StringBuilder sb = new StringBuilder();
+        for (String line : htmllines)
         {
-          break;
+          line = line.replaceAll("\\s+", " ");
+          line = line.trim();
+          if (line.length() == 0 || line.equals(" "))
+          {
+            continue;
+          }
+          maxLengthExceeded = line.length() > 60;
+          if (sb.length() > 0)
+          {
+            sb.append(br);
+          }
+          sb.append(line);
         }
+        ttext = sb.toString();
       }
     }
-    else
+    if (!hasBr)
     {
+      ttext = ttext.replaceAll("\\s+", " ");
+      ttext = ttext.trim();
       maxLengthExceeded = ttext.length() > 60;
     }
 
@@ -101,7 +117,7 @@ public final class JvSwingUtils
             // + "<style> p.ttip {width:350px;margin:-14px 0px -14px
             // 0px;padding:2px;overflow-wrap:break-word;}"
             // + "</style><p class=\"ttip\">"
-            + ttext + " </div>"
+            + ttext + "</div>"
             // + "</p>"
             + ((enclose ? "</html>" : ""));
   }