import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+
/**
* useful functions for building Swing GUIs
*
*/
public final class JvSwingUtils
{
+ // JBPMerge note: Old Non-JS prefix
+ // static final String HTML_PREFIX = "<html><div
+ // style=\"width:350px;white-space:pre-wrap;margin:2px;overflow-wrap:break-word;\">";
+
+ static final String HTML_PREFIX = "<html><div style=\"width:350; text-align: justify; word-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
"Tootip text to format must not be null!");
ttext = ttext.trim();
boolean maxLengthExceeded = false;
-
- if (ttext.contains("<br>"))
+ boolean isHTML = ttext.startsWith("<html>");
+ if (isHTML)
{
- String[] htmllines = ttext.split("<br>");
- for (String line : htmllines)
- {
- maxLengthExceeded = line.length() > 60;
- if (maxLengthExceeded)
- {
+ 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)
+ {
+ int pt = -1, ptlast = -4;
+ while ((pt = ttext.indexOf("<br>", pt + 1)) >= 0) {
+ if (pt - ptlast - 4 > 60) {
+ maxLengthExceeded = true;
break;
}
}
}
- else
+ else
{
maxLengthExceeded = ttext.length() > 60;
}
- if (!maxLengthExceeded)
- {
- return enclose ? "<html>" + ttext + "</html>" : ttext;
- }
-
- return (enclose ? "<html>" : "")
- + "<style> p.ttip {width: 350; text-align: left; word-wrap: break-word;}</style><p class=\"ttip\">"
- + ttext + "</p>" + ((enclose ? "</html>" : ""));
-
+ String ret = (!enclose ? ttext : maxLengthExceeded ? HTML_PREFIX + ttext + "</div></html>" :
+ "<html>" + ttext + "</html>");
+ //System.out.println("JvSwUtil " + enclose + " " + maxLengthExceeded + " " + ret);
+ return ret;
}
public static JButton makeButton(String label, String tooltip,