From: Ben Soares Date: Fri, 10 Nov 2023 22:27:09 +0000 (+0000) Subject: JAL-4240 Remove unnecessary whitespace, being rendered in JalviewJS. Split on both... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=133dc2c227a23c5d06d05720400cdd77b8386591;p=jalview.git JAL-4240 Remove unnecessary whitespace, being rendered in JalviewJS. Split on both

. Should make consistent at source, mea culpa. --- diff --git a/src/jalview/gui/JvSwingUtils.java b/src/jalview/gui/JvSwingUtils.java index e7f992d..c00be98 100644 --- a/src/jalview/gui/JvSwingUtils.java +++ b/src/jalview/gui/JvSwingUtils.java @@ -73,20 +73,36 @@ public final class JvSwingUtils ttext = ttext.trim(); boolean maxLengthExceeded = false; - if (ttext.contains("
")) + boolean hasBr = false; + for (String br : new String[] { "
", "
" }) { - String[] htmllines = ttext.split("
"); - for (String line : htmllines) + hasBr = true; + if (ttext.contains(br)) { - maxLengthExceeded = line.length() > 60; - if (maxLengthExceeded) + String[] htmllines = ttext.split(br); + StringBuilder sb = new StringBuilder(); + for (String line : htmllines) { - break; + line = line.replaceAll("\\s+", " "); + line = line.trim(); + if (line.length() == 0 || line.equals(" ")) + { + continue; + } + maxLengthExceeded = line.length() > 60; + if (sb.length() > 0) + { + sb.append(br); + } + sb.append(line); } + ttext = sb.toString(); } } - else + if (!hasBr) { + ttext = ttext.replaceAll("\\s+", " "); + ttext = ttext.trim(); maxLengthExceeded = ttext.length() > 60; } @@ -101,7 +117,7 @@ public final class JvSwingUtils // + "

" - + ttext + " " + + ttext + "" // + "

" + ((enclose ? "" : "")); }