From 133dc2c227a23c5d06d05720400cdd77b8386591 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Fri, 10 Nov 2023 22:27:09 +0000 Subject: [PATCH] JAL-4240 Remove unnecessary whitespace, being rendered in JalviewJS. Split on both

. Should make consistent at source, mea culpa. --- src/jalview/gui/JvSwingUtils.java | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) 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 ? "" : "")); } -- 1.7.10.2