+ addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
+ false, false);
+ }
+ }
+ // grey out 'hide annotations' if none are shown
+ hideMenu.setEnabled(!shownTypes.isEmpty());
+ }
+
+ /**
+ * Returns a list of sequences - either the current selection group (if there
+ * is one), else the specified single sequence.
+ *
+ * @param seq
+ * @return
+ */
+ protected List<SequenceI> getSequenceScope(SequenceI seq)
+ {
+ List<SequenceI> forSequences = null;
+ final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
+ if (selectionGroup != null && selectionGroup.getSize() > 0)
+ {
+ forSequences = selectionGroup.getSequences();
+ }
+ else
+ {
+ forSequences = seq == null ? Collections.<SequenceI> emptyList()
+ : Arrays.asList(seq);
+ }
+ return forSequences;
+ }
+
+ /**
+ * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
+ * menus.
+ *
+ * @param showOrHideMenu
+ * the menu to add to
+ * @param forSequences
+ * the sequences whose annotations may be shown or hidden
+ * @param calcId
+ * @param types
+ * the label to add
+ * @param allTypes
+ * if true this is a special label meaning 'All'
+ * @param actionIsShow
+ * if true, the select menu item action is to show the annotation
+ * type, else hide
+ */
+ protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
+ final List<SequenceI> forSequences, String calcId,
+ final List<String> types, final boolean allTypes,
+ final boolean actionIsShow)
+ {
+ String label = types.toString(); // [a, b, c]
+ label = label.substring(1, label.length() - 1); // a, b, c
+ final JMenuItem item = new JMenuItem(label);
+ item.setToolTipText(calcId);
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
+ types, forSequences, allTypes, actionIsShow);
+ refresh();
+ }
+ });
+ showOrHideMenu.add(item);
+ }
+
+ private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
+ {
+
+ // TODO: usability: thread off the generation of group url content so root
+ // menu appears asap
+ // sequence only URLs
+ // ID/regex match URLs
+ groupLinksMenu = new JMenu(
+ MessageManager.getString("action.group_link"));
+ // three types of url that might be created.
+ JMenu[] linkMenus = new JMenu[] { null,
+ new JMenu(MessageManager.getString("action.ids")),
+ new JMenu(MessageManager.getString("action.sequences")),
+ new JMenu(MessageManager.getString("action.ids_sequences")) };
+
+ SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
+ String[][] idandseqs = GroupUrlLink.formStrings(seqs);
+ Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
+ for (int sq = 0; sq < seqs.length; sq++)
+ {
+
+ int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
+ .findPosition(sg.getEndRes());
+ // just collect ids from dataset sequence
+ // TODO: check if IDs collected from selecton group intersects with the
+ // current selection, too
+ SequenceI sqi = seqs[sq];
+ while (sqi.getDatasetSequence() != null)
+ {
+ sqi = sqi.getDatasetSequence();
+ }
+ DBRefEntry[] dbr = sqi.getDBRefs();
+ if (dbr != null && dbr.length > 0)
+ {
+ for (int d = 0; d < dbr.length; d++)
+ {
+ String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
+ Object[] sarray = commonDbrefs.get(src);
+ if (sarray == null)
+ {
+ sarray = new Object[2];
+ sarray[0] = new int[] { 0 };
+ sarray[1] = new String[seqs.length];
+
+ commonDbrefs.put(src, sarray);
+ }
+
+ if (((String[]) sarray[1])[sq] == null)
+ {
+ if (!dbr[d].hasMap()
+ || (dbr[d].getMap().locateMappedRange(start, end) != null))
+ {
+ ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
+ ((int[]) sarray[0])[0]++;
+ }
+ }
+ }
+ }
+ }
+ // now create group links for all distinct ID/sequence sets.
+ boolean addMenu = false; // indicates if there are any group links to give
+ // to user
+ for (String link : groupLinks)
+ {
+ GroupUrlLink urlLink = null;
+ try
+ {
+ urlLink = new GroupUrlLink(link);
+ } catch (Exception foo)
+ {
+ Cache.log.error("Exception for GroupURLLink '" + link
+ + "'", foo);
+ continue;
+ }
+ ;
+ if (!urlLink.isValid())
+ {
+ Cache.log.error(urlLink.getInvalidMessage());
+ continue;
+ }
+ final String label = urlLink.getLabel();
+ boolean usingNames = false;
+ // Now see which parts of the group apply for this URL
+ String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
+ Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
+ String[] seqstr, ids; // input to makeUrl
+ if (idset != null)
+ {
+ int numinput = ((int[]) idset[0])[0];
+ String[] allids = ((String[]) idset[1]);
+ seqstr = new String[numinput];
+ ids = new String[numinput];
+ for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
+ {
+ if (allids[sq] != null)
+ {
+ ids[idcount] = allids[sq];
+ seqstr[idcount++] = idandseqs[1][sq];
+ }
+ }