/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
+ * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
import jalview.datamodel.*;
import jalview.io.*;
import jalview.schemes.*;
+import jalview.util.GroupUrlLink;
import jalview.util.UrlLink;
/**
// JMenuItem annotationMenuItem = new JMenuItem();
+ JMenu groupLinksMenu;
+
/**
* Creates a new PopupMenu object.
*
* @param seq
* DOCUMENT ME!
*/
- public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
+ public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
+ {
+ this(ap, seq, links, null);
+ }
+ /**
+ *
+ * @param ap
+ * @param seq
+ * @param links
+ * @param groupLinks
+ */
+ public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links, Vector groupLinks)
{
// /////////////////////////////////////////////////////////
// If this is activated from the sequence panel, the user may want to
showText.setSelected(sg.getDisplayText());
showColourText.setSelected(sg.getColourText());
showBoxes.setSelected(sg.getDisplayBoxes());
+ // add any groupURLs to the groupURL submenu and make it visible
+ if (groupLinks!=null && groupLinks.size()>0) {
+ buildGroupURLMenu(sg, groupLinks);
+ }
}
else
{
if (links != null && links.size() > 0)
{
+
JMenu linkMenu = new JMenu("Link");
Vector linkset = new Vector();
for (int i = 0; i < links.size(); i++)
}
}
}
+
+ private void buildGroupURLMenu(SequenceGroup sg, Vector 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("Group Link");
+ JMenu[] linkMenus = new JMenu[] { null, new JMenu("IDS"), new JMenu("Sequences"), new JMenu("IDS and Sequences")}; // three types of url that might be created.
+ SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
+ String[][] idandseqs = GroupUrlLink.formStrings(seqs);
+ Hashtable commonDbrefs = new Hashtable();
+ 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.getDBRef();
+ 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 = (Object[]) 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 (int i = 0; i < groupLinks.size(); i++) {
+ String link = groupLinks.elementAt(i).toString();
+ GroupUrlLink urlLink = null;
+ try
+ {
+ urlLink = new GroupUrlLink(link);
+ } catch (Exception foo)
+ {
+ jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
+ + "'", foo);
+ continue;
+ }
+ ;
+ if (!urlLink.isValid())
+ {
+ jalview.bin.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 = (Object[]) 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];
+ }
+ }
+ } else {
+ // just use the id/seq set
+ seqstr = idandseqs[1];
+ ids = idandseqs[0];
+ usingNames=true;
+ }
+ // and try and make the groupURL!
+
+ Object[] urlset = urlLink.makeUrlStubs(ids,seqstr, "FromJalview"+System.currentTimeMillis(),false);
+ if (urlset!=null)
+ {
+ int type = urlLink.getGroupURLType() & 3;
+ //System.out.println(urlLink.getGroupURLType() +" "+((String[])urlset[3])[0]);
+ // first two bits ofurlLink type bitfield are sequenceids and sequences
+ // TODO: FUTURE: ensure the groupURL menu structure can be generalised
+ addshowLink(linkMenus[type], label + (((type & 1)==1) ? ("("+(usingNames ? "Names" : ltarget)+")") : ""), urlLink, urlset);
+ addMenu = true;
+ }
+ }
+ if (addMenu)
+ {
+ groupLinksMenu = new JMenu("Group Links");
+ for (int m=0;m<linkMenus.length; m++)
+ {
+ if (linkMenus[m]!=null && linkMenus[m].getMenuComponentCount()>0)
+ {
+ groupLinksMenu.add(linkMenus[m]);
+ }
+ }
+
+ groupMenu.add(groupLinksMenu);
+ }
+ }
/**
* add a show URL menu item to the given linkMenu
linkMenu.add(item);
}
+ /**
+ * add a late bound groupURL item to the given linkMenu
+ *
+ * @param linkMenu
+ * @param label -
+ * menu label string
+ * @param urlgenerator GroupURLLink used to generate URL
+ * @param urlstub Object array returned from the makeUrlStubs function.
+ */
+ private void addshowLink(JMenu linkMenu, String label, final GroupUrlLink urlgenerator, final Object[] urlstub)
+ {
+ JMenuItem item = new JMenuItem(label);
+ item.setToolTipText("open URL ("+urlgenerator.getUrl_prefix()+"..) ("+urlgenerator.getNumberInvolved(urlstub)+" seqs)"); // TODO: put in info about what is being sent.
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ new Thread(new Runnable()
+ {
+
+ public void run()
+ {
+ showLink(urlgenerator.constructFrom(urlstub));
+ }
+ }).start();
+ }
+ });
+
+ linkMenu.add(item);
+ }
/**
* DOCUMENT ME!
*
*/
void refresh()
{
+ ap.updateAnnotation();
ap.paintAlignment(true);
PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
sg.setName(dialog.getName());
sg.setDescription(dialog.getDescription());
+ refresh();
}
/**
- * DOCUMENT ME!
+ * Get selection group - adding it to the alignment if necessary.
*
- * @return DOCUMENT ME!
+ * @return sequence group to operate on
*/
SequenceGroup getGroup()
{
}
ap.av.hideSequence(hseqs);
+ // refresh(); TODO: ? needed ?
ap.av.sendSelection();
}
return;
}
- int gSize = sg.getSize();
- SequenceI[] seqs = new SequenceI[gSize];
- SequenceFeature[] features = new SequenceFeature[gSize];
-
+ int rsize=0,gSize = sg.getSize();
+ SequenceI[] rseqs,seqs = new SequenceI[gSize];
+ SequenceFeature[] tfeatures,features = new SequenceFeature[gSize];
+
for (int i = 0; i < gSize; i++)
{
- seqs[i] = sg.getSequenceAt(i).getDatasetSequence();
int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
int end = sg.findEndRes(sg.getSequenceAt(i));
- features[i] = new SequenceFeature(null, null, null, start, end,
+ if (start<=end)
+ {
+ seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
+ features[rsize] = new SequenceFeature(null, null, null, start, end,
"Jalview");
+ rsize++;
+ }
}
-
+ rseqs = new SequenceI[rsize];
+ tfeatures = new SequenceFeature[rsize];
+ System.arraycopy(seqs,0,rseqs, 0, rsize);
+ System.arraycopy(features, 0, tfeatures, 0, rsize);
+ features = tfeatures;
+ seqs = rseqs;
if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
features, true, ap))
{