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;
/**
* 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
{
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
*/
public class SequenceAnnotationReport
{
+ private static final int MAX_DESCRIPTION_LENGTH = 40;
+
private static final String COMMA = ",";
private static final String ELLIPSIS = "...";
* Comparator to order DBRefEntry by Source + accession id (case-insensitive),
* with 'Primary' sources placed before others, and 'chromosome' first of all
*/
- private static Comparator<DBRefEntry> comparator = new Comparator<DBRefEntry>()
+ private static Comparator<DBRefEntry> comparator = new Comparator<>()
{
@Override
if (description != null && !description.equals(feature.getType()))
{
description = StringUtils.stripHtmlTags(description);
+
+ /*
+ * truncate overlong descriptions unless they contain an href
+ * (as truncation could leave corrupted html)
+ */
+ boolean hasLink = description.indexOf("a href") > -1;
+ if (description.length() > MAX_DESCRIPTION_LENGTH && !hasLink)
+ {
+ description = description.substring(0, MAX_DESCRIPTION_LENGTH)
+ + ELLIPSIS;
+ }
sb.append("; ").append(description);
}
if (sequence.getDescription() != null)
{
tmp = sequence.getDescription();
- sb.append("<br>").append(tmp);
+ sb.append(tmp);
maxWidth = Math.max(maxWidth, tmp.length());
}
SequenceI ds = sequence;