- if (dbr != null)
- {
- for (int r = 0; r < dbr.length; r++)
- {
- if (id != null && dbr[r].getAccessionId().equals(id))
- {
- // suppress duplicate link creation for the bare sequence ID
- // string with this link
- id = null;
- }
- // create Bare ID link for this RUL
- String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
- true);
- if (urls != null)
- {
- for (int u = 0; u < urls.length; u += 2)
- {
- if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
- {
- linkset.addElement(urls[u] + "|" + urls[u + 1]);
- addshowLink(linkMenu, label + "|" + urls[u],
- urls[u + 1]);
- }
- }
- }
- }
- }
- if (id != null)
- {
- // create Bare ID link for this RUL
- String[] urls = urlLink.makeUrls(id, true);
- if (urls != null)
- {
- for (int u = 0; u < urls.length; u += 2)
- {
- if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
- {
- linkset.addElement(urls[u] + "|" + urls[u + 1]);
- addshowLink(linkMenu, label, urls[u + 1]);
- }
- }
- }
- }
- // Create urls from description but only for URL links which are regex
- // links
- if (descr != null && urlLink.getRegexReplace() != null)
- {
- // create link for this URL from description where regex matches
- String[] urls = urlLink.makeUrls(descr, true);
- if (urls != null)
- {
- for (int u = 0; u < urls.length; u += 2)
- {
- if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
- {
- linkset.addElement(urls[u] + "|" + urls[u + 1]);
- addshowLink(linkMenu, label, urls[u + 1]);
- }
- }
- }
- }
- }
- else
- {
- if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
- {
- linkset.addElement(label + "|" + urlLink.getUrl_prefix());
- // Add a non-dynamic link
- addshowLink(linkMenu, label, urlLink.getUrl_prefix());
- }
- }
+ JMenu details = new JMenu(
+ MessageManager.getString("label.feature_details"));
+ add(details);
+
+ String name = seq.getName();
+ for (final SequenceFeature sf : features)
+ {
+ addFeatureDetailsMenuItem(details, name, sf, null);
+ }
+
+ if (mf != null)
+ {
+ for (final SequenceFeature sf : mf.features)
+ {
+ addFeatureDetailsMenuItem(details, name, sf, mf);
+ }
+ }
+ }
+
+ /**
+ * A helper method to add one menu item whose action is to show details for
+ * one feature. The menu text includes feature description, but this may be
+ * truncated.
+ *
+ * @param details
+ * @param seqName
+ * @param sf
+ * @param mf
+ */
+ void addFeatureDetailsMenuItem(JMenu details, final String seqName,
+ final SequenceFeature sf, MappedFeatures mf)
+ {
+ int start = sf.getBegin();
+ int end = sf.getEnd();
+ if (mf != null)
+ {
+ /*
+ * show local rather than linked feature coordinates
+ */
+ int[] localRange = mf.getMappedPositions(start, end);
+ if (localRange == null)
+ {
+ // e.g. variant extending to stop codon so not mappable
+ return;
+ }
+ start = localRange[0];
+ end = localRange[localRange.length - 1];
+ }
+ StringBuilder desc = new StringBuilder();
+ desc.append(sf.getType()).append(" ").append(String.valueOf(start));
+ if (start != end)
+ {
+ desc.append(sf.isContactFeature() ? ":" : "-");
+ desc.append(String.valueOf(end));
+ }
+ String description = sf.getDescription();
+ if (description != null)
+ {
+ desc.append(" ");
+ 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() > FEATURE_DESC_MAX && !hasLink)
+ {
+ description = description.substring(0, FEATURE_DESC_MAX) + "...";
+ }
+ desc.append(description);
+ }
+ String featureGroup = sf.getFeatureGroup();
+ if (featureGroup != null)
+ {
+ desc.append(" (").append(featureGroup).append(")");
+ }
+ String htmlText = JvSwingUtils.wrapTooltip(true, desc.toString());
+ JMenuItem item = new JMenuItem(htmlText);
+ item.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ showFeatureDetails(sf, seqName, mf);