import jalview.schemes.TurnColourScheme;
import jalview.schemes.UserColourScheme;
import jalview.schemes.ZappoColourScheme;
-import jalview.util.DBRefUtils;
import jalview.util.GroupUrlLink;
import jalview.util.GroupUrlLink.UrlStringTooLongException;
import jalview.util.MessageManager;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.LinkedHashMap;
void addFeatureLinks(final SequenceI seq, List<String> links)
{
JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
- List<String> linkset = new ArrayList<String>();
+ Map<String, String[]> linkset = new LinkedHashMap<String, String[]>();
+
for (String link : links)
{
UrlLink urlLink = null;
Cache.log.error("Exception for URLLink '" + link + "'", foo);
continue;
}
- ;
+
if (!urlLink.isValid())
{
Cache.log.error(urlLink.getInvalidMessage());
continue;
}
- final String label = urlLink.getLabel();
-
- // collect id string too
- String id = seq.getName();
- String descr = seq.getDescription();
- if (descr != null && descr.length() < 1)
- {
- descr = null;
- }
-
- if (seq != null && urlLink.usesSeqId()) // link is ID
- {
- // collect matching db-refs
- DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(),
- new String[] { urlLink.getTarget() });
-
- // if there are any dbrefs which match up with the link
- if (dbr != null)
- {
- for (int r = 0; r < dbr.length; r++)
- {
- if (id != null && dbr[r].getAccessionId().equals(id))
- {
- // suppress duplicate link creation for the bare sequence ID
- // string with this link
- id = null;
- }
- // create Bare ID link for this URL
- createBareURLLink(urlLink, dbr[r].getAccessionId(), linkset,
- linkMenu, label, true);
- }
- }
- // Create urls from description but only for URL links which are regex
- // links
- if (descr != null && urlLink.getRegexReplace() != null)
- {
- // create link for this URL from description where regex matches
- createBareURLLink(urlLink, descr, linkset, linkMenu, label, false);
- }
+ urlLink.createLinksFromSeq(seq, linkset);
+ }
- }
- else if (seq != null && !urlLink.usesSeqId()) // link is name
- {
- if (id != null)
- {
- // create Bare ID link for this URL
- createBareURLLink(urlLink, id, linkset, linkMenu, label, false);
- }
- // Create urls from description but only for URL links which are regex
- // links
- if (descr != null && urlLink.getRegexReplace() != null)
- {
- // create link for this URL from description where regex matches
- createBareURLLink(urlLink, descr, linkset, linkMenu, label, false);
- }
- }
- else
- {
- if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
- {
- linkset.add(label + "|" + urlLink.getUrl_prefix());
- // Add a non-dynamic link
- addshowLink(linkMenu, label, urlLink.getUrl_prefix());
- }
- }
+ addshowLinks(linkMenu, linkset.values());
- }
if (sequence != null)
{
sequenceMenu.add(linkMenu);
}
}
- /*
- * Create a bare URL Link
- */
- private void createBareURLLink(UrlLink urlLink, String id,
- List<String> linkset, JMenu linkMenu, String label,
- Boolean addSepToLabel)
- {
- String[] urls = urlLink.makeUrls(id, true);
- if (urls != null)
- {
- for (int u = 0; u < urls.length; u += 2)
- {
- if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
- {
- linkset.add(urls[u] + "|" + urls[u + 1]);
- if (addSepToLabel)
- {
- addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
- }
- else
- {
- addshowLink(linkMenu, label, urls[u + 1]);
- }
- }
- }
- }
- }
+
/**
* Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
}
}
+ private void addshowLinks(JMenu linkMenu, Collection<String[]> linkset)
+ {
+ for (String[] linkstrset : linkset)
+ {
+ // split linkstr into label and url
+ addshowLink(linkMenu, linkstrset[1], linkstrset[3]);
+ }
+ }
+
/**
* add a show URL menu item to the given linkMenu
*
import static jalview.util.UrlConstants.SEQUENCE_ID;
import static jalview.util.UrlConstants.SEQUENCE_NAME;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.SequenceI;
+
+import java.util.Map;
import java.util.Vector;
public class UrlLink
}
}
+ /**
+ *
+ * @param urlLink
+ * @param seq
+ * @param linkset
+ */
+ public void createLinksFromSeq(final SequenceI seq,
+ Map<String, String[]> linkset)
+ {
+ if (seq != null && dynamic)
+ {
+ createDynamicLinks(seq, linkset);
+ }
+ else
+ {
+ createStaticLink(linkset);
+ }
+ }
+
+ /**
+ * Create a static URL link
+ *
+ * @param linkset
+ */
+ public void createStaticLink(Map<String, String[]> linkset)
+ {
+ if (!linkset.containsKey(label + "|" + getUrl_prefix()))
+ {
+ // Add a non-dynamic link
+ linkset.put(label + "|" + getUrl_prefix(), new String[] { "", label,
+ "", getUrl_prefix() });
+ }
+ }
+
+ /**
+ * Create a dynamic URL link
+ *
+ * @param seq
+ * @param linkset
+ */
+ public void createDynamicLinks(final SequenceI seq,
+ Map<String, String[]> linkset)
+ {
+ // collect id string too
+ String id = seq.getName();
+ String descr = seq.getDescription();
+ if (descr != null && descr.length() < 1)
+ {
+ descr = null;
+ }
+
+ if (usesSeqId()) // link is ID
+ {
+ // collect matching db-refs
+ DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(),
+ new String[] { target });
+
+ // if there are any dbrefs which match up with the link
+ if (dbr != null)
+ {
+ for (int r = 0; r < dbr.length; r++)
+ {
+ // create Bare ID link for this URL
+ createBareURLLink(dbr[r].getAccessionId(), linkset, true);
+ }
+ }
+ }
+ else if (!usesSeqId() && id != null) // link is name
+ {
+ // create Bare ID link for this URL
+ createBareURLLink(id, linkset, false);
+ }
+
+ // Create urls from description but only for URL links which are regex
+ // links
+ if (descr != null && getRegexReplace() != null)
+ {
+ // create link for this URL from description where regex matches
+ createBareURLLink(descr, linkset, false);
+ }
+ }
+
+ /*
+ * Create a bare URL Link
+ */
+ protected void createBareURLLink(String id,
+ Map<String, String[]> linkset, Boolean combineLabel)
+ {
+ String[] urls = makeUrls(id, true);
+ if (urls != null)
+ {
+ for (int u = 0; u < urls.length; u += 2)
+ {
+ if (!linkset.containsKey(urls[u] + "|" + urls[u + 1]))
+ {
+ String thisLabel = label;
+ if (combineLabel)
+ {
+ thisLabel = label + "|" + urls[u];
+ }
+
+ linkset.put(urls[u] + "|" + urls[u + 1], new String[] { target,
+ thisLabel, urls[u], urls[u + 1] });
+ }
+ }
+ }
+ }
+
private static void testUrls(UrlLink ul, String idstring, String[] urls)
{
public boolean isDynamic()
{
- // TODO Auto-generated method stub
return dynamic;
}