import javax.swing.border.TitledBorder;
import jalview.util.MessageManager;
+import jalview.util.Platform;
/**
* useful functions for building Swing GUIs
*/
public final class JvSwingUtils
{
- 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 = (Platform.isJS() ?
+ "<html><div style=\"max-width:350px;overflow-wrap:break-word;display:inline-block\">"
+ : "<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
boolean hasBR = ttext.contains("<br>");
enclose |= isHTML || hasBR;
if (hasBR)
- {
-
-// Too complex in HTML5 to mix <br> with word wrapping.
-//
-// String[] htmllines = ttext.split("<br>");
-// for (String line : htmllines)
-// {
-// maxLengthExceeded = line.length() > 60;
-// if (maxLengthExceeded)
-// {
-// break;
-// }
-// }
+ {
+ 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;
- }
- // BH 2018,2019
- return (enclose ? HTML_PREFIX + ttext + "</div></html>" : ttext);
+ 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,