minor changes
[jalview.git] / src / jalview / gui / JvSwingUtils.java
index b25b2c8..fb487d8 100644 (file)
@@ -56,7 +56,7 @@ import javax.swing.border.TitledBorder;
  */
 public final class JvSwingUtils
 {
-  public static final String HTML_PREFIX = "<html><div style=\"width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;\">";
+  static final String HTML_PREFIX = "<html><div style=\"width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;\">";
 
   /**
    * wrap a bare html safe string to around 60 characters per line using a CSS
@@ -73,10 +73,21 @@ public final class JvSwingUtils
   {
     Objects.requireNonNull(ttext,
             "Tootip text to format must not be null!");
-    ttext = ttext.trim();
+    ttext = ttext.trim().replaceAll("<br/>", "<br>");
     boolean maxLengthExceeded = false;
-
-    if (ttext.contains("<br>"))
+    boolean isHTML = ttext.startsWith("<html>");
+    if (isHTML)
+    {
+      ttext = ttext.substring(6);
+    }
+    if (ttext.endsWith("</html>"))
+    {
+      isHTML = true;
+      ttext = ttext.substring(0, ttext.length() - 7);
+    }
+    boolean hasBR = ttext.contains("<br>");
+    enclose |= isHTML || hasBR;
+    if (hasBR)
     {
       String[] htmllines = ttext.split("<br>");
       for (String line : htmllines)
@@ -98,11 +109,7 @@ public final class JvSwingUtils
       return enclose ? "<html>" + ttext + "</html>" : ttext;
     }
     // BH 2018,2019
-    return (enclose
-            ? HTML_PREFIX
-            + ttext
-                    + "</div></html>"
-            : ttext);
+    return (enclose ? HTML_PREFIX + ttext + "</div></html>" : ttext);
 
   }
 
@@ -346,6 +353,7 @@ public final class JvSwingUtils
           combo.setToolTipText(tooltips.get(j));
         }
       }
+
       @Override
       public void mouseExited(MouseEvent e)
       {