From 64741412a510f134a0e08fc87d1e84d938022dbb Mon Sep 17 00:00:00 2001 From: BobHanson Date: Wed, 10 Jun 2020 10:52:59 -0500 Subject: [PATCH] JAL-3446 from applet, JAL-3584 tooltip fixes
and allows different html style coding for Java and JavaScript --- src/jalview/gui/JvSwingUtils.java | 39 ++++++++++----------- src/jalview/io/SequenceAnnotationReport.java | 18 +++++----- src/jalview/jbgui/GAlignFrame.java | 4 +-- test/jalview/io/SequenceAnnotationReportTest.java | 28 +++++++-------- 4 files changed, 44 insertions(+), 45 deletions(-) diff --git a/src/jalview/gui/JvSwingUtils.java b/src/jalview/gui/JvSwingUtils.java index f89b4e4..f23dcf8 100644 --- a/src/jalview/gui/JvSwingUtils.java +++ b/src/jalview/gui/JvSwingUtils.java @@ -47,6 +47,7 @@ import javax.swing.border.Border; import javax.swing.border.TitledBorder; import jalview.util.MessageManager; +import jalview.util.Platform; /** * useful functions for building Swing GUIs @@ -56,7 +57,10 @@ import jalview.util.MessageManager; */ public final class JvSwingUtils { - static final String HTML_PREFIX = "
"; + static final String HTML_PREFIX = (Platform.isJS() ? + "
" + : "
" + ); /** * wrap a bare html safe string to around 60 characters per line using a CSS @@ -89,31 +93,24 @@ public final class JvSwingUtils boolean hasBR = ttext.contains("
"); enclose |= isHTML || hasBR; if (hasBR) - { - -// Too complex in HTML5 to mix
with word wrapping. -// -// String[] htmllines = ttext.split("
"); -// for (String line : htmllines) -// { -// maxLengthExceeded = line.length() > 60; -// if (maxLengthExceeded) -// { -// break; -// } -// } + { + int pt = -1, ptlast = -4; + while ((pt = ttext.indexOf("
", pt + 1)) >= 0) { + if (pt - ptlast - 4 > 60) { + maxLengthExceeded = true; + break; + } + } } - else + else { maxLengthExceeded = ttext.length() > 60; } - if (!maxLengthExceeded) - { - return enclose ? "" + ttext + "" : ttext; - } - // BH 2018,2019 - return (enclose ? HTML_PREFIX + ttext + "
" : ttext); + String ret = (!enclose ? ttext : maxLengthExceeded ? HTML_PREFIX + ttext + "
" : + "" + ttext + ""); + //System.out.println("JvSwUtil " + enclose + " " + maxLengthExceeded + " " + ret); + return ret; } public static JButton makeButton(String label, String tooltip, diff --git a/src/jalview/io/SequenceAnnotationReport.java b/src/jalview/io/SequenceAnnotationReport.java index 8e4e783..4d0bec7 100644 --- a/src/jalview/io/SequenceAnnotationReport.java +++ b/src/jalview/io/SequenceAnnotationReport.java @@ -237,7 +237,7 @@ public class SequenceAnnotationReport { if (sb0.length() > 6) { - sb.append("
"); + sb.append("
"); } sb.append(feature.getType()).append(" ").append(begin).append(":") .append(end); @@ -247,7 +247,7 @@ public class SequenceAnnotationReport if (sb0.length() > 6) { - sb.append("
"); + sb.append("
"); } // TODO: remove this hack to display link only features boolean linkOnly = feature.getValue("linkonly") != null; @@ -276,7 +276,9 @@ public class SequenceAnnotationReport int linkindex = description.toLowerCase().indexOf(" -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; @@ -395,7 +397,7 @@ public class SequenceAnnotationReport { for (List urllink : createLinksFrom(null, urlstring)) { - sb.append("

"); + + "

"); } } catch (Exception x) { @@ -561,7 +563,7 @@ public class SequenceAnnotationReport countForSource++; if (countForSource == 1 || !summary) { - sb.append("
"); + sb.append("
"); } if (countForSource <= MAX_REFS_PER_SOURCE || !summary) { @@ -587,11 +589,11 @@ public class SequenceAnnotationReport } if (moreSources) { - sb.append("
").append(source).append(COMMA).append(ELLIPSIS); + sb.append("
").append(source).append(COMMA).append(ELLIPSIS); } if (ellipsis) { - sb.append("
("); + sb.append("
("); sb.append(MessageManager.getString("label.output_seq_details")); sb.append(")"); } diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index b6c5280..c67da2b 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -1736,8 +1736,8 @@ public class GAlignFrame extends JInternalFrame }); JMenuItem selectHighlighted = new JMenuItem( MessageManager.getString("action.select_highlighted_columns")); - selectHighlighted.setToolTipText( - MessageManager.getString("tooltip.select_highlighted_columns")); + selectHighlighted.setToolTipText(JvSwingUtils.wrapTooltip(true, + MessageManager.getString("tooltip.select_highlighted_columns"))); al = new ActionListener() { @Override diff --git a/test/jalview/io/SequenceAnnotationReportTest.java b/test/jalview/io/SequenceAnnotationReportTest.java index 772ed2b..f3a7586 100644 --- a/test/jalview/io/SequenceAnnotationReportTest.java +++ b/test/jalview/io/SequenceAnnotationReportTest.java @@ -69,15 +69,15 @@ public class SequenceAnnotationReportTest sar.appendFeature(sb, 2, null, sf, null, 0); assertEquals("123456", sb.toString()); - // residuePos == 1 matches start of feature, text appended (but no
) + // residuePos == 1 matches start of feature, text appended (but no
) // 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 - //
is prefixed once sb.length() > 6 + //
is prefixed once sb.length() > 6 sar.appendFeature(sb, 3, null, sf, null, 0); - assertEquals("123456disulfide bond 1:3
disulfide bond 1:3", + assertEquals("123456disulfide bond 1:3
disulfide bond 1:3", sb.toString()); } @@ -147,8 +147,8 @@ public class SequenceAnnotationReportTest */ minmax.put("METAL", new float[][] { { 0f, 1f }, null }); sar.appendFeature(sb, 1, fr, sf, null, 0); - //
is appended to a buffer > 6 in length - assertEquals("METAL 1 3; Fe2-S
METAL 1 3; Fe2-S Score=1.3", + //
is appended to a buffer > 6 in length + assertEquals("METAL 1 3; Fe2-S
METAL 1 3; Fe2-S Score=1.3", sb.toString()); /* @@ -299,7 +299,7 @@ public class SequenceAnnotationReportTest null)); sb.setLength(0); sar.createSequenceAnnotationReport(sb, seq, true, true, null); - String expected = "SeqDesc
Type1 ; Nonpos Score=1.0
"; + String expected = "SeqDesc
Type1 ; Nonpos Score=1.0
"; assertEquals(expected, sb.toString()); /* @@ -324,7 +324,7 @@ public class SequenceAnnotationReportTest sb.setLength(0); sar.createSequenceAnnotationReport(sb, seq, true, true, fr); - expected = "SeqDesc
Metal ; Desc
Type1 ; Nonpos
"; + expected = "SeqDesc
Metal ; Desc
Type1 ; Nonpos
"; assertEquals(expected, sb.toString()); /* @@ -349,7 +349,7 @@ public class SequenceAnnotationReportTest seq.addSequenceFeature(sf2); sb.setLength(0); sar.createSequenceAnnotationReport(sb, seq, true, true, fr); - expected = "SeqDesc
Metal ; Desc
Type1 ; Nonpos
Variant ; Havana
"; + expected = "SeqDesc
Metal ; Desc
Type1 ; Nonpos
Variant ; Havana
"; assertEquals(expected, sb.toString()); /* @@ -370,13 +370,13 @@ public class SequenceAnnotationReportTest fc.setAttributeName("clinical_significance"); fr.setColour("Variant", fc); sar.createSequenceAnnotationReport(sb, seq, true, true, fr); - expected = "SeqDesc
UNIPROT P30419
PDB 3iu1
Metal ; Desc
" - + "Type1 ; Nonpos
Variant ; Havana; clinical_significance=benign
"; + expected = "SeqDesc
UNIPROT P30419
PDB 3iu1
Metal ; Desc
" + + "Type1 ; Nonpos
Variant ; Havana; clinical_significance=benign
"; assertEquals(expected, sb.toString()); // with showNonPositionalFeatures = false sb.setLength(0); sar.createSequenceAnnotationReport(sb, seq, true, false, fr); - expected = "SeqDesc
UNIPROT P30419
PDB 3iu1
"; + expected = "SeqDesc
UNIPROT P30419
PDB 3iu1
"; assertEquals(expected, sb.toString()); /* @@ -386,7 +386,7 @@ public class SequenceAnnotationReportTest sf2.setDescription( "This is a very long description which should be truncated"); sar.createSequenceAnnotationReport(sb, seq, false, true, fr); - expected = "SeqDesc
Metal ; Desc
Type1 ; Nonpos
Variant ; This is a very long description which sh...; clinical_significance=benign
"; + expected = "SeqDesc
Metal ; Desc
Type1 ; Nonpos
Variant ; This is a very long description which sh...; clinical_significance=benign
"; assertEquals(expected, sb.toString()); // see other tests for treatment of status and html @@ -421,10 +421,10 @@ public class SequenceAnnotationReportTest String report = sb.toString(); assertTrue(report .startsWith( - "
UNIPROT P30410, P30411, P30412, P30413,...
PDB0 3iu1")); + "
UNIPROT P30410, P30411, P30412, P30413,...
PDB0 3iu1")); assertTrue(report .endsWith( - "
PDB7 3iu1
PDB8,...
(Output Sequence Details to list all database references)
")); + "
PDB7 3iu1
PDB8,...
(Output Sequence Details to list all database references)
")); } /** -- 1.7.10.2