minor changes
[jalview.git] / src / jalview / gui / JvSwingUtils.java
index 79e0cef..fb487d8 100644 (file)
@@ -56,12 +56,15 @@ import javax.swing.border.TitledBorder;
  */
 public final class JvSwingUtils
 {
+  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
    * style class specifying word-wrap and break-word
    * 
    * @param enclose
-   *          if true, add &lt;html&gt; wrapper tags
+   *          if true, add &lt;html&gt; wrapper tags (currently false for only
+   *          two references -- both in Jws2Discoverer --
    * @param ttext
    * 
    * @return
@@ -70,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)
@@ -94,10 +108,8 @@ public final class JvSwingUtils
     {
       return enclose ? "<html>" + ttext + "</html>" : ttext;
     }
-
-    return (enclose ? "<html>" : "")
-            + "<style> p.ttip {width: 350; text-align: justify; word-wrap: break-word;}</style><p class=\"ttip\">"
-            + ttext + "</p>" + ((enclose ? "</html>" : ""));
+    // BH 2018,2019
+    return (enclose ? HTML_PREFIX + ttext + "</div></html>" : ttext);
 
   }
 
@@ -341,6 +353,7 @@ public final class JvSwingUtils
           combo.setToolTipText(tooltips.get(j));
         }
       }
+
       @Override
       public void mouseExited(MouseEvent e)
       {
@@ -356,12 +369,13 @@ public final class JvSwingUtils
 
   /**
    * Adds a titled border to the component in the default font and position (top
-   * left)
+   * left), optionally witht italic text
    * 
    * @param comp
    * @param title
+   * @param italic
    */
-  public static void createItalicTitledBorder(JComponent comp,
+  public static TitledBorder createTitledBorder(JComponent comp,
           String title, boolean italic)
   {
     Font font = comp.getFont();
@@ -374,6 +388,8 @@ public final class JvSwingUtils
             title, TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION,
             font);
     comp.setBorder(titledBorder);
+
+    return titledBorder;
   }
 
 }