+ }
+ }
+
+ /**
+ * 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
+ */
+ void addFeatureDetailsMenuItem(JMenu details, final String seqName,
+ final SequenceFeature sf)
+ {
+ int start = sf.getBegin();
+ int end = sf.getEnd();
+ StringBuilder desc = new StringBuilder();
+ desc.append(sf.getType()).append(" ").append(String.valueOf(start));
+ if (start != end)
+ {
+ desc.append("-").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(seqName, sf);
+ }
+ });
+ details.add(item);
+ }
+
+ /**
+ * Opens a panel showing a text report of feature dteails
+ *
+ * @param seqName
+ *
+ * @param sf
+ */
+ protected void showFeatureDetails(String seqName, SequenceFeature sf)
+ {
+ CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
+ // it appears Java's CSS does not support border-collapse :-(
+ cap.addStylesheetRule("table { border-collapse: collapse;}");
+ cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
+ cap.setText(sf.getDetailsReport(seqName));
+
+ Desktop.addInternalFrame(cap,
+ MessageManager.getString("label.feature_details"), 500, 500);
+ }
+
+ /**
+ * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
+ * When seq is not null, these are links for the sequence id, which may be to
+ * external web sites for the sequence accession, and/or links embedded in
+ * non-positional features. When seq is null, only links embedded in the
+ * provided features are added. If no links are found, the menu is not added.
+ *
+ * @param seq
+ * @param features
+ */
+ void addLinks(final SequenceI seq, List<SequenceFeature> features)
+ {
+ JMenu linkMenu = buildLinkMenu(forIdPanel ? seq : null, features);
+
+ // only add link menu if it has entries
+ if (linkMenu.getItemCount() > 0)
+ {
+ if (forIdPanel)
+ {
+ sequenceMenu.add(linkMenu);
+ }
+ else
+ {
+ add(linkMenu);
+ }
+ }
+ }
+
+ /**
+ * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
+ * "All" is added first, followed by a separator. Then add any annotation
+ * types associated with the current selection. Separate menus are built for
+ * the selected sequence group (if any), and the selected sequence.
+ * <p>
+ * Some annotation rows are always rendered together - these can be identified
+ * by a common graphGroup property > -1. Only one of each group will be marked
+ * as visible (to avoid duplication of the display). For such groups we add a
+ * composite type name, e.g.
+ * <p>
+ * IUPredWS (Long), IUPredWS (Short)
+ *
+ * @param seq
+ */
+ protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
+ List<SequenceI> forSequences)
+ {
+ showMenu.removeAll();
+ hideMenu.removeAll();
+
+ final List<String> all = Arrays
+ .asList(new String[]
+ { MessageManager.getString("label.all") });
+ addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
+ true);
+ addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
+ false);
+ showMenu.addSeparator();
+ hideMenu.addSeparator();
+
+ final AlignmentAnnotation[] annotations = ap.getAlignment()
+ .getAlignmentAnnotation();
+
+ /*
+ * Find shown/hidden annotations types, distinguished by source (calcId),
+ * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
+ * the insertion order, which is the order of the annotations on the
+ * alignment.
+ */
+ Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
+ Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
+ AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
+ AlignmentAnnotationUtils.asList(annotations), forSequences);
+
+ for (String calcId : hiddenTypes.keySet())
+ {
+ for (List<String> type : hiddenTypes.get(calcId))