From: BobHanson Date: Wed, 10 Jun 2020 05:22:18 +0000 (-0500) Subject: JAL-3446 tests - Popup/HTML changes in Applet X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8e7a86b0a37be21335e594bebca887b669478c03;p=jalview.git JAL-3446 tests - Popup/HTML changes in Applet -
indicates no additional line breaks. - removal of unrealistic tests ("false" tests of jws2Discoverer HTML messages) - accepts either
or
(as does JLabel) --- diff --git a/src/jalview/gui/JvSwingUtils.java b/src/jalview/gui/JvSwingUtils.java index e399236..f89b4e4 100644 --- a/src/jalview/gui/JvSwingUtils.java +++ b/src/jalview/gui/JvSwingUtils.java @@ -56,12 +56,15 @@ import jalview.util.MessageManager; */ public final class JvSwingUtils { + static final String HTML_PREFIX = "
"; + /** * wrap a bare html safe string to around 60 characters per line using a CSS * style class specifying word-wrap and break-word * * @param enclose - * if true, add <html> wrapper tags + * if true, add <html> wrapper tags (currently false for only + * two references -- both in Jws2Discoverer -- * @param ttext * * @return @@ -70,12 +73,26 @@ public final class JvSwingUtils { Objects.requireNonNull(ttext, "Tootip text to format must not be null!"); - ttext = ttext.trim(); - boolean maxLengthExceeded = false; + ttext = ttext.trim().replaceAll("
", "
"); - if (ttext.contains("
")) + boolean maxLengthExceeded = false; + boolean isHTML = ttext.startsWith(""); + if (isHTML) + { + ttext = ttext.substring(6); + } + if (ttext.endsWith("")) + { + isHTML = true; + ttext = ttext.substring(0, ttext.length() - 7); + } + boolean hasBR = ttext.contains("
"); + enclose |= isHTML || hasBR; + if (hasBR) { - maxLengthExceeded = false; + +// Too complex in HTML5 to mix
with word wrapping. +// // String[] htmllines = ttext.split("
"); // for (String line : htmllines) // { @@ -95,16 +112,8 @@ public final class JvSwingUtils { return enclose ? "" + ttext + "" : ttext; } - - return (enclose ? "" : "") - // BH 2018 - + "
" -// + "

" - + ttext - + "

" -// + "

" - + ((enclose ? "" : "")); + // BH 2018,2019 + return (enclose ? HTML_PREFIX + ttext + "
" : ttext); } public static JButton makeButton(String label, String tooltip, diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index dc7fea3..4469b43 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -1699,7 +1699,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener menuItem.setEnabled(true); for (String calcId : tipEntries.keySet()) { - tooltip.append("
" + calcId + "/" + tipEntries.get(calcId)); + tooltip.append("
" + calcId + "/" + tipEntries.get(calcId)); } String tooltipText = JvSwingUtils.wrapTooltip(true, tooltip.toString()); diff --git a/test/jalview/gui/JvSwingUtilsTest.java b/test/jalview/gui/JvSwingUtilsTest.java index 61c5c9b..214a3ad 100644 --- a/test/jalview/gui/JvSwingUtilsTest.java +++ b/test/jalview/gui/JvSwingUtilsTest.java @@ -86,7 +86,12 @@ public class JvSwingUtilsTest JvSwingUtils.wrapTooltip(true, tip)); tip = "0123456789012345678901234567890123456789012345678901234567890"; // 61 - assertFalse(tip.equals(JvSwingUtils.wrapTooltip(false, tip))); + + // n/a -- message is too long for "false" +// +// assertFalse(tip.equals(JvSwingUtils.wrapTooltip(false, tip))); +// + assertFalse(("" + tip + "").equals(JvSwingUtils .wrapTooltip(true, tip))); } @@ -100,9 +105,21 @@ public class JvSwingUtilsTest public void testWrapTooltip_multilineShortText() { String tip = "Now is the winter of our discontent
Made glorious summer by this sun of York"; - assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip)); - assertEquals("" + tip + "", - JvSwingUtils.wrapTooltip(true, tip)); + String tip2 = "Now is the winter of our discontent
Made glorious summer by this sun of York"; + +// BH not applicable in Jalview; "false" is only for when no
and only for short j2s2Discover messages +// +// String s = JvSwingUtils.wrapTooltip(false, tip); +// System.out.println("" + tip + ""); +// assertEquals(tip, s); + + String s; + s = JvSwingUtils.wrapTooltip(true, tip); + System.out.println(s); + assertEquals("" + tip + "", s); + s = JvSwingUtils.wrapTooltip(true, tip2); + System.out.println(s); + assertEquals("" + tip + "", s); } /** @@ -112,11 +129,13 @@ public class JvSwingUtilsTest @Test(groups = { "Functional" }) public void testWrapTooltip_longText() { + // BH should work in Java and JavaScript String tip = "Now is the winter of our discontent made glorious summer by this sun of York"; - String expected = "" - + "
" + tip + "
"; - assertEquals("" + expected + "", - JvSwingUtils.wrapTooltip(true, tip)); - assertEquals(expected, JvSwingUtils.wrapTooltip(false, tip)); + String expected = JvSwingUtils.HTML_PREFIX + tip + ""; + String s = JvSwingUtils.wrapTooltip(true, tip); + assertEquals(expected, s); + // BH not applicable in Jalview; "false" is only for when no
and only for short j2s2Discover messages +// s = JvSwingUtils.wrapTooltip(false, tip); +// assertEquals(expected, s); } } diff --git a/test/jalview/gui/PopupMenuTest.java b/test/jalview/gui/PopupMenuTest.java index cc13fb9..4a5c248 100644 --- a/test/jalview/gui/PopupMenuTest.java +++ b/test/jalview/gui/PopupMenuTest.java @@ -201,9 +201,10 @@ public class PopupMenuTest testee.configureReferenceAnnotationsMenu(menu, seqs); assertTrue(menu.isEnabled()); String s = MessageManager.getString("label.add_annotations_for"); - String expected = "" - + "
" + s - + "
Jmol/secondary structure
PDB/Temp
"; +// String expected = "" +// + "
" + s +// + "
Jmol/secondary structure
PDB/Temp
"; + String expected = "" + s + "
Jmol/secondary structure
PDB/Temp"; assertEquals(expected, menu.getToolTipText()); } @@ -225,10 +226,13 @@ public class PopupMenuTest testee.configureReferenceAnnotationsMenu(menu, seqs); assertTrue(menu.isEnabled()); String s = MessageManager.getString("label.add_annotations_for"); - String expected = "" - + "
" + s - + "
Jmol/secondary structure
PDB/Temp
"; - assertEquals(expected, menu.getToolTipText()); +// String expected = "" +// + "
" + s +// + "
Jmol/secondary structure
PDB/Temp"; + String expected = "" + s + + "
Jmol/secondary structure
PDB/Temp"; + s = menu.getToolTipText(); + assertEquals(expected, s); } /**