X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPopupMenu.java;h=187090ba03b63ef3fa23af4b068dd5896a0d346d;hb=586b87fca07c53c935ffe67827e498eb80fad4bf;hp=415054ec38313c1a7c525ecdbe6e17f88c2d5b1b;hpb=74f21ca6ca8fa17d53708e457d191e15904f8310;p=jalview.git diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 415054e..187090b 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -88,6 +88,11 @@ import javax.swing.JRadioButtonMenuItem; public class PopupMenu extends JPopupMenu implements ColourChangeListener { /* + * maximum length of feature description to include in popup menu item text + */ + private static final int FEATURE_DESC_MAX = 40; + + /* * true for ID Panel menu, false for alignment panel menu */ private final boolean forIdPanel; @@ -808,7 +813,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener /** * A helper method to add one menu item whose action is to show details for one - * feature + * feature. The menu text includes feature description, but this may be + * truncated. * * @param details * @param seqName @@ -819,36 +825,36 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { int start = sf.getBegin(); int end = sf.getEnd(); - String desc = null; - if (start == end) - { - desc = String.format("%s %d", sf.getType(), start); - } - else + StringBuilder desc = new StringBuilder(); + desc.append(sf.getType()).append(" ").append(String.valueOf(start)); + if (start != end) { - desc = String.format("%s %d-%d", sf.getType(), start, end); + desc.append("-").append(String.valueOf(end)); } - String tooltip = desc; String description = sf.getDescription(); if (description != null) { + desc.append(" "); description = StringUtils.stripHtmlTags(description); - if (description.length() > 12) - { - desc = desc + " " + description.substring(0, 12) + ".."; - } - else + + /* + * truncate overlong descriptions unless they contain an href + * (as truncation could leave corrupted html) + */ + boolean hasLink = description.indexOf("a href") > -1; + if (description.length() > FEATURE_DESC_MAX && !hasLink) { - desc = desc + " " + description; + description = description.substring(0, FEATURE_DESC_MAX) + "..."; } - tooltip = tooltip + " " + description; + desc.append(description); } - if (sf.getFeatureGroup() != null) + String featureGroup = sf.getFeatureGroup(); + if (featureGroup != null) { - tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")"); + desc.append(" (").append(featureGroup).append(")"); } - JMenuItem item = new JMenuItem(desc); - item.setToolTipText(tooltip); + String htmlText = JvSwingUtils.wrapTooltip(true, desc.toString()); + JMenuItem item = new JMenuItem(htmlText); item.addActionListener(new ActionListener() { @Override