+ if (!forIdPanel)
+ {
+ sequenceMenu.setVisible(false);
+ chooseStructure.setVisible(false);
+ rnaStructureMenu.setVisible(false);
+ }
+
+ addLinksAndFeatures(seq, column);
+ }
+
+ /**
+ * Adds
+ * <ul>
+ * <li>configured sequence database links (ID panel popup menu)</li>
+ * <li>non-positional feature links (ID panel popup menu)</li>
+ * <li>positional feature links (alignment panel popup menu)</li>
+ * <li>feature details links (alignment panel popup menu)</li>
+ * </ul>
+ * If this panel is also showed complementary (CDS/protein) features, then links
+ * to their feature details are also added.
+ *
+ * @param seq
+ * @param column
+ */
+ void addLinksAndFeatures(final SequenceI seq, final int column)
+ {
+ List<SequenceFeature> features = null;
+ if (forIdPanel)
+ {
+ features = sequence.getFeatures().getNonPositionalFeatures();
+ }
+ else
+ {
+ features = ap.getFeatureRenderer().findFeaturesAtColumn(sequence,
+ column + 1);
+ }
+
+ addLinks(seq, features);
+
+ if (!forIdPanel)
+ {
+ addFeatureDetails(features, seq, column);
+ }
+ }
+
+ /**
+ * Add a link to show feature details for each sequence feature
+ *
+ * @param features
+ * @param column
+ * @param seq
+ */
+ protected void addFeatureDetails(List<SequenceFeature> features,
+ SequenceI seq, int column)
+ {
+ /*
+ * add features in CDS/protein complement at the corresponding
+ * position if configured to do so
+ */
+ MappedFeatures mf = null;
+ if (ap.av.isShowComplementFeatures())
+ {
+ if (!Comparison.isGap(sequence.getCharAt(column)))
+ {
+ AlignViewportI complement = ap.getAlignViewport()
+ .getCodingComplement();
+ AlignFrame af = Desktop.getAlignFrameFor(complement);
+ FeatureRendererModel fr2 = af.getFeatureRenderer();
+ int seqPos = sequence.findPosition(column);
+ mf = fr2.findComplementFeaturesAtResidue(sequence, seqPos);
+ }
+ }
+
+ if (features.isEmpty() && mf == null)
+ {
+ /*
+ * no features to show at this position
+ */
+ return;
+ }
+
+ JMenu details = new JMenu(
+ MessageManager.getString("label.feature_details"));
+ add(details);
+
+ String name = seq.getName();
+ for (final SequenceFeature sf : features)
+ {
+ addFeatureDetailsMenuItem(details, name, sf);
+ }
+
+ if (mf != null)
+ {
+ name = mf.fromSeq == seq ? mf.mapping.getTo().getName()
+ : mf.fromSeq.getName();
+ for (final SequenceFeature sf : mf.features)
+ {
+ addFeatureDetailsMenuItem(details, name, sf);
+ }
+ }
+ }
+
+ /**
+ * A helper method to add one menu item whose action is to show details for one
+ * feature
+ *
+ * @param details
+ * @param seqName
+ * @param sf
+ */
+ void addFeatureDetailsMenuItem(JMenu details, final String seqName,
+ final SequenceFeature sf)
+ {
+ int start = sf.getBegin();
+ int end = sf.getEnd();
+ String desc = null;
+ if (start == end)
+ {
+ desc = String.format("%s %d", sf.getType(), start);
+ }
+ else
+ {
+ desc = String.format("%s %d-%d", sf.getType(), start, end);
+ }
+ String tooltip = desc;
+ String description = sf.getDescription();
+ if (description != null)
+ {
+ description = StringUtils.stripHtmlTags(description);
+ if (description.length() > 12)
+ {
+ desc = desc + " " + description.substring(0, 12) + "..";
+ }
+ else
+ {
+ desc = desc + " " + description;
+ }
+ tooltip = tooltip + " " + description;
+ }
+ if (sf.getFeatureGroup() != null)
+ {
+ tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
+ }
+ JMenuItem item = new JMenuItem(desc);
+ item.setToolTipText(tooltip);
+ 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));