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,
{
if (sb0.length() > 6)
{
- sb.append("<br/>");
+ sb.append("<br>");
}
sb.append(feature.getType()).append(" ").append(begin).append(":")
.append(end);
if (sb0.length() > 6)
{
- sb.append("<br/>");
+ sb.append("<br>");
}
// TODO: remove this hack to display link only features
boolean linkOnly = feature.getValue("linkonly") != null;
int linkindex = description.toLowerCase().indexOf("<a ");
boolean hasLink = linkindex > -1
&& linkindex < MAX_DESCRIPTION_LENGTH;
- if (description.length() > MAX_DESCRIPTION_LENGTH && !hasLink)
+ if (
+ // BH suggestion maxlength == 0 &&
+ description.length() > MAX_DESCRIPTION_LENGTH && !hasLink)
{
description = description.substring(0, MAX_DESCRIPTION_LENGTH)
+ ELLIPSIS;
{
for (List<String> urllink : createLinksFrom(null, urlstring))
{
- sb.append("<br/> <a href=\""
+ sb.append("<br> <a href=\""
+ urllink.get(3)
+ "\" target=\""
+ urllink.get(0)
.equals(urllink.get(1).toLowerCase()) ? urllink
.get(0) : (urllink.get(0) + ":" + urllink
.get(1)))
- + "</a><br/>");
+ + "</a><br>");
}
} catch (Exception x)
{
countForSource++;
if (countForSource == 1 || !summary)
{
- sb.append("<br/>");
+ sb.append("<br>");
}
if (countForSource <= MAX_REFS_PER_SOURCE || !summary)
{
}
if (moreSources)
{
- sb.append("<br/>").append(source).append(COMMA).append(ELLIPSIS);
+ sb.append("<br>").append(source).append(COMMA).append(ELLIPSIS);
}
if (ellipsis)
{
- sb.append("<br/>(");
+ sb.append("<br>(");
sb.append(MessageManager.getString("label.output_seq_details"));
sb.append(")");
}
sar.appendFeature(sb, 2, null, sf, null, 0);
assertEquals("123456", sb.toString());
- // residuePos == 1 matches start of feature, text appended (but no <br/>)
+ // residuePos == 1 matches start of feature, text appended (but no <br>)
// feature score is not included
sar.appendFeature(sb, 1, null, sf, null, 0);
assertEquals("123456disulfide bond 1:3", sb.toString());
// residuePos == 3 matches end of feature, text appended
- // <br/> is prefixed once sb.length() > 6
+ // <br> is prefixed once sb.length() > 6
sar.appendFeature(sb, 3, null, sf, null, 0);
- assertEquals("123456disulfide bond 1:3<br/>disulfide bond 1:3",
+ assertEquals("123456disulfide bond 1:3<br>disulfide bond 1:3",
sb.toString());
}
*/
minmax.put("METAL", new float[][] { { 0f, 1f }, null });
sar.appendFeature(sb, 1, fr, sf, null, 0);
- // <br/> is appended to a buffer > 6 in length
- assertEquals("METAL 1 3; Fe2-S<br/>METAL 1 3; Fe2-S Score=1.3",
+ // <br> is appended to a buffer > 6 in length
+ assertEquals("METAL 1 3; Fe2-S<br>METAL 1 3; Fe2-S Score=1.3",
sb.toString());
/*
null));
sb.setLength(0);
sar.createSequenceAnnotationReport(sb, seq, true, true, null);
- String expected = "<i>SeqDesc<br/>Type1 ; Nonpos Score=1.0</i>";
+ String expected = "<i>SeqDesc<br>Type1 ; Nonpos Score=1.0</i>";
assertEquals(expected, sb.toString());
/*
sb.setLength(0);
sar.createSequenceAnnotationReport(sb, seq, true, true, fr);
- expected = "<i>SeqDesc<br/>Metal ; Desc<br/>Type1 ; Nonpos</i>";
+ expected = "<i>SeqDesc<br>Metal ; Desc<br>Type1 ; Nonpos</i>";
assertEquals(expected, sb.toString());
/*
seq.addSequenceFeature(sf2);
sb.setLength(0);
sar.createSequenceAnnotationReport(sb, seq, true, true, fr);
- expected = "<i>SeqDesc<br/>Metal ; Desc<br/>Type1 ; Nonpos<br/>Variant ; Havana</i>";
+ expected = "<i>SeqDesc<br>Metal ; Desc<br>Type1 ; Nonpos<br>Variant ; Havana</i>";
assertEquals(expected, sb.toString());
/*
fc.setAttributeName("clinical_significance");
fr.setColour("Variant", fc);
sar.createSequenceAnnotationReport(sb, seq, true, true, fr);
- expected = "<i>SeqDesc<br/>UNIPROT P30419<br/>PDB 3iu1<br/>Metal ; Desc<br/>"
- + "Type1 ; Nonpos<br/>Variant ; Havana; clinical_significance=benign</i>";
+ expected = "<i>SeqDesc<br>UNIPROT P30419<br>PDB 3iu1<br>Metal ; Desc<br>"
+ + "Type1 ; Nonpos<br>Variant ; Havana; clinical_significance=benign</i>";
assertEquals(expected, sb.toString());
// with showNonPositionalFeatures = false
sb.setLength(0);
sar.createSequenceAnnotationReport(sb, seq, true, false, fr);
- expected = "<i>SeqDesc<br/>UNIPROT P30419<br/>PDB 3iu1</i>";
+ expected = "<i>SeqDesc<br>UNIPROT P30419<br>PDB 3iu1</i>";
assertEquals(expected, sb.toString());
/*
sf2.setDescription(
"This is a very long description which should be truncated");
sar.createSequenceAnnotationReport(sb, seq, false, true, fr);
- expected = "<i>SeqDesc<br/>Metal ; Desc<br/>Type1 ; Nonpos<br/>Variant ; This is a very long description which sh...; clinical_significance=benign</i>";
+ expected = "<i>SeqDesc<br>Metal ; Desc<br>Type1 ; Nonpos<br>Variant ; This is a very long description which sh...; clinical_significance=benign</i>";
assertEquals(expected, sb.toString());
// see other tests for treatment of status and html
String report = sb.toString();
assertTrue(report
.startsWith(
- "<i><br/>UNIPROT P30410, P30411, P30412, P30413,...<br/>PDB0 3iu1"));
+ "<i><br>UNIPROT P30410, P30411, P30412, P30413,...<br>PDB0 3iu1"));
assertTrue(report
.endsWith(
- "<br/>PDB7 3iu1<br/>PDB8,...<br/>(Output Sequence Details to list all database references)</i>"));
+ "<br>PDB7 3iu1<br>PDB8,...<br>(Output Sequence Details to list all database references)</i>"));
}
/**