+ * Select the menu item (if any) matching the current colour scheme. This
+ * works by matching the menu item name (not display text) to the canonical
+ * name of the colour scheme.
+ *
+ * @param cs
+ */
+ protected void setSelectedColour(CollectionColourSchemeI cs)
+ {
+ if (cs == null || cs.getColourScheme() == null)
+ {
+ noColour.setState(true);
+ }
+ else
+ {
+ String name = cs.getColourScheme().getSchemeName();
+ for (int i = 0; i < colourMenu.getItemCount(); i++)
+ {
+ MenuItem item = colourMenu.getItem(i);
+ if (item instanceof CheckboxMenuItem)
+ {
+ if (name.equals(item.getName()))
+ {
+ ((CheckboxMenuItem) item).setState(true);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
+ *
+ * @param seq
+ * @param links
+ */
+ void addFeatureLinks(final SequenceI seq, List<String> links)
+ {
+ Menu linkMenu = new Menu(MessageManager.getString("action.link"));
+ Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
+
+ for (String link : links)
+ {
+ UrlLink urlLink = null;
+ try
+ {
+ urlLink = new UrlLink(link);
+ } catch (Exception foo)
+ {
+ System.err.println("Exception for URLLink '" + link + "': "
+ + foo.getMessage());
+ continue;
+ }
+
+ if (!urlLink.isValid())
+ {
+ System.err.println(urlLink.getInvalidMessage());
+ continue;
+ }
+
+ urlLink.createLinksFromSeq(seq, linkset);
+ }
+
+ addshowLinks(linkMenu, linkset.values());
+
+ // disable link menu if there are no valid entries
+ if (linkMenu.getItemCount() > 0)
+ {
+ linkMenu.setEnabled(true);
+ }
+ else
+ {
+ linkMenu.setEnabled(false);
+ }
+
+ if (seq != null)
+ {
+ seqMenu.add(linkMenu);
+ }
+ else
+ {
+ add(linkMenu);
+ }
+
+ }
+
+ private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
+ {
+ for (List<String> linkstrset : linkset)
+ {
+ // split linkstr into label and url
+ addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
+ }
+ }
+
+ /**
+ * Build menus for annotation types that may be shown or hidden, and for
+ * 'reference annotations' that may be added to the alignment.
+ */
+ private void buildAnnotationSubmenus()
+ {
+ /*
+ * First for the currently selected sequence (if there is one):
+ */
+ final List<SequenceI> selectedSequence = (seq == null ? Collections
+ .<SequenceI> emptyList() : Arrays.asList(seq));
+ buildAnnotationTypesMenus(seqShowAnnotationsMenu,
+ seqHideAnnotationsMenu, selectedSequence);
+ configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
+ selectedSequence);
+
+ /*
+ * and repeat for the current selection group (if there is one):
+ */
+ final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
+ .<SequenceI> emptyList() : ap.av.getSelectionGroup()
+ .getSequences());
+ buildAnnotationTypesMenus(groupShowAnnotationsMenu,
+ groupHideAnnotationsMenu, selectedGroup);
+ configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
+ selectedGroup);
+ }
+
+ /**
+ * Determine whether or not to enable 'add reference annotations' menu item.
+ * It is enable if there are any annotations, on any of the selected
+ * sequences, which are not yet on the alignment (visible or not).
+ *
+ * @param menu
+ * @param forSequences
+ */
+ private void configureReferenceAnnotationsMenu(MenuItem menuItem,
+ List<SequenceI> forSequences)
+ {
+ menuItem.setEnabled(false);
+
+ /*
+ * Temporary store to hold distinct calcId / type pairs for the tooltip.
+ * Using TreeMap means calcIds are shown in alphabetical order.
+ */
+ SortedMap<String, String> tipEntries = new TreeMap<String, String>();
+ final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
+ AlignmentI al = this.ap.av.getAlignment();
+ AlignmentUtils.findAddableReferenceAnnotations(forSequences,
+ tipEntries, candidates, al);
+ if (!candidates.isEmpty())
+ {
+ StringBuilder tooltip = new StringBuilder(64);
+ tooltip.append(MessageManager.getString("label.add_annotations_for"));
+
+ /*
+ * Found annotations that could be added. Enable the menu item, and
+ * configure its action.
+ */
+ menuItem.setEnabled(true);
+
+ menuItem.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ addReferenceAnnotations_actionPerformed(candidates);
+ }
+ });
+ }
+ }
+
+ /**
+ * Add annotations to the sequences and to the alignment.
+ *
+ * @param candidates
+ * a map whose keys are sequences on the alignment, and values a list
+ * of annotations to add to each sequence
+ */
+ protected void addReferenceAnnotations_actionPerformed(
+ Map<SequenceI, List<AlignmentAnnotation>> candidates)
+ {
+ final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
+ final AlignmentI alignment = this.ap.getAlignment();
+ AlignmentUtils.addReferenceAnnotations(candidates, alignment,
+ selectionGroup);
+ refresh();
+ }
+
+ /**