From 8a491d35239e20cd026fbdbef092783f759ddbc7 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 Conflicts: src/jalview/gui/JvSwingUtils.java --- src/jalview/gui/JvSwingUtils.java | 49 +++++++++++++-------- src/jalview/io/SequenceAnnotationReport.java | 18 ++++---- src/jalview/jbgui/GAlignFrame.java | 4 +- test/jalview/io/SequenceAnnotationReportTest.java | 28 ++++++------ 4 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/jalview/gui/JvSwingUtils.java b/src/jalview/gui/JvSwingUtils.java index 7a5dde6..c561457 100644 --- a/src/jalview/gui/JvSwingUtils.java +++ b/src/jalview/gui/JvSwingUtils.java @@ -48,6 +48,9 @@ import javax.swing.SwingConstants; 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,6 +59,12 @@ import javax.swing.border.TitledBorder; */ public final class JvSwingUtils { + // JBPMerge note: Old Non-JS prefix + // static final String HTML_PREFIX = "
"; + + 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 @@ -72,33 +81,37 @@ public final class JvSwingUtils "Tootip text to format must not be null!"); ttext = ttext.trim(); boolean maxLengthExceeded = false; - - if (ttext.contains("
")) + boolean isHTML = ttext.startsWith(""); + if (isHTML) { - String[] htmllines = ttext.split("
"); - for (String line : htmllines) - { - maxLengthExceeded = line.length() > 60; - if (maxLengthExceeded) - { + 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) + { + 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; - } - - return (enclose ? "" : "") - + "

" - + ttext + "

" + ((enclose ? "" : "")); - + 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 27c1652..ecb5a98 100644 --- a/src/jalview/io/SequenceAnnotationReport.java +++ b/src/jalview/io/SequenceAnnotationReport.java @@ -240,7 +240,7 @@ public class SequenceAnnotationReport { if (sb0.length() > 6) { - sb.append("
"); + sb.append("
"); } sb.append(feature.getType()).append(" ").append(begin).append(":") .append(end); @@ -250,7 +250,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; @@ -279,7 +279,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; @@ -398,7 +400,7 @@ public class SequenceAnnotationReport { for (List urllink : createLinksFrom(null, urlstring)) { - sb.append("

"); + + "

"); } } catch (Exception x) { @@ -564,7 +566,7 @@ public class SequenceAnnotationReport countForSource++; if (countForSource == 1 || !summary) { - sb.append("
"); + sb.append("
"); } if (countForSource <= MAX_REFS_PER_SOURCE || !summary) { @@ -590,11 +592,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 075b490..8c945f0 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -1696,8 +1696,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