From aaace4c8c53d4bb08a5bad0ea18ccfedbef90cd9 Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 18 Aug 2011 12:02:45 +0100 Subject: [PATCH] fix for JAL-701 - ensure '<' appears in tooltip in application and allow html tags (JAL-908) --- src/jalview/datamodel/AlignmentAnnotation.java | 6 ++++ src/jalview/gui/AnnotationLabels.java | 39 +++++++++++++++++++----- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 236e8ee..483c821 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -813,6 +813,12 @@ public class AlignmentAnnotation { if (seqname && this.sequenceRef != null) { + int i=description.toLowerCase().indexOf(""); + if (i>-1) + { + // move the html tag to before the sequence reference. + return ""+sequenceRef.getName()+" : "+description.substring(i+6); + } return sequenceRef.getName() + " : " + description; } return description; diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 6626016..7278901 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -18,6 +18,7 @@ package jalview.gui; import java.util.*; +import java.util.regex.Pattern; import java.awt.*; import java.awt.datatransfer.*; @@ -404,24 +405,46 @@ public class AnnotationLabels extends JPanel implements MouseListener, && ap.av.alignment.getAlignmentAnnotation().length > selectedRow) { AlignmentAnnotation aa = ap.av.alignment.getAlignmentAnnotation()[selectedRow]; - - StringBuffer desc = new StringBuffer(""); - + + StringBuffer desc = new StringBuffer(); if (aa.description != null && !aa.description.equals("New description")) { - desc.append(aa.getDescription(true)); - if (aa.hasScore) - desc.append("
"); + // TODO: we could refactor and merge this code with the code in jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature tooltips + desc.append(aa.getDescription(true).trim()); + // check to see if the description is an html fragment. + if (desc.length()<6 || (desc.substring(0,6).toLowerCase().indexOf("")<0)) + { + // clean the description ready for embedding in html + desc = new StringBuffer(Pattern.compile("<").matcher(desc).replaceAll("<")); + desc.insert(0, ""); + } else { + // remove terminating html if any + int i=desc.substring(desc.length()-7).toLowerCase().lastIndexOf(""); + if (i>-1) { + desc.setLength(desc.length()-7+i); + } + } + if (aa.hasScore()) + { + desc.append("
"); + } + + + } else { + // begin the tooltip's html fragment + desc.append(""); } if (aa.hasScore()) { - desc.append("Score: " + aa.score); + // TODO: limit precision of score to avoid noise from imprecise doubles (64.7 becomes 64.7+/some tiny value). + desc.append(" Score: " + aa.score); } - if (desc.length() != 6) + if (desc.length() > 6) { desc.append(""); + System.err.println(desc.toString()); this.setToolTipText(desc.toString()); } else -- 1.7.10.2