X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAPopupMenu.java;h=015734f139ab25abefed4f09ef0bc53f5ea53781;hb=7d67fb613ec026dc9a265e351e7fab542e3f1d61;hp=2037ca08160160c1ec35549b6ce0987e0340b0a1;hpb=7fadc8dc33be5781fac68507b08a9e387ddb5761;p=jalview.git diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index 2037ca0..015734f 100644 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -24,17 +24,19 @@ import jalview.analysis.AAFrequency; import jalview.analysis.AlignmentAnnotationUtils; import jalview.analysis.AlignmentUtils; import jalview.analysis.Conservation; +import jalview.bin.JalviewLite; import jalview.commands.ChangeCaseCommand; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; -import jalview.datamodel.DBRefEntry; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; import jalview.io.SequenceAnnotationReport; import jalview.schemes.Blosum62ColourScheme; import jalview.schemes.BuriedColourScheme; @@ -59,6 +61,7 @@ import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; @@ -213,10 +216,9 @@ public class APopupMenu extends java.awt.PopupMenu implements e.printStackTrace(); } - for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++) + for (String ff : FileFormat.getWritableFormats(true)) { - MenuItem item = new MenuItem( - jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]); + MenuItem item = new MenuItem(ff); item.addActionListener(this); outputmenu.add(item); @@ -253,122 +255,9 @@ public class APopupMenu extends java.awt.PopupMenu implements if (links != null && links.size() > 0) { - Menu linkMenu = new Menu(MessageManager.getString("action.link")); - for (int i = 0; i < links.size(); i++) - { - String link = links.elementAt(i); - UrlLink urlLink = new UrlLink(link); - if (!urlLink.isValid()) - { - System.err.println(urlLink.getInvalidMessage()); - continue; - } - final String target = urlLink.getTarget(); // link.substring(0, - // link.indexOf("|")); - final String label = urlLink.getLabel(); - if (seq != null && urlLink.isDynamic()) - { - - // collect matching db-refs - DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs( - seq.getDBRefs(), new String[] { target }); - // collect id string too - String id = seq.getName(); - String descr = seq.getDescription(); - if (descr != null && descr.length() < 1) - { - descr = null; - } - 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 RUL - String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), - true); - if (urls != null) - { - for (int u = 0; u < urls.length; u += 2) - { - addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]); - } - } - } - } - if (id != null) - { - // create Bare ID link for this RUL - String[] urls = urlLink.makeUrls(id, true); - if (urls != null) - { - for (int u = 0; u < urls.length; u += 2) - { - addshowLink(linkMenu, label, urls[u + 1]); - } - } - // addshowLink(linkMenu, target, url_pref + id + url_suff); - } - // Now construct URLs from description but only try to do it for regex - // URL links - if (descr != null && urlLink.getRegexReplace() != null) - { - // create link for this URL from description only if regex matches - String[] urls = urlLink.makeUrls(descr, true); - if (urls != null) - { - for (int u = 0; u < urls.length; u += 2) - { - addshowLink(linkMenu, label, urls[u + 1]); - } - } - } - } - else - { - addshowLink(linkMenu, target, urlLink.getUrl_prefix()); // link.substring(link.lastIndexOf("|")+1)); - } - /* - * final String url; - * - * if (link.indexOf("$SEQUENCE_ID$") > -1) { // Substitute SEQUENCE_ID - * string and any matching database reference accessions String url_pref - * = link.substring(link.indexOf("|") + 1, - * link.indexOf("$SEQUENCE_ID$")); - * - * String url_suff = link.substring(link.indexOf("$SEQUENCE_ID$") + 13); - * // collect matching db-refs DBRefEntry[] dbr = - * jalview.util.DBRefUtils.selectRefs(seq.getDBRef(), new - * String[]{target}); // collect id string too String id = - * seq.getName(); if (id.indexOf("|") > -1) { id = - * id.substring(id.lastIndexOf("|") + 1); } if (dbr!=null) { for (int - * r=0;r 0) - { - if (seq != null) - { - seqMenu.add(linkMenu); - } - else - { - add(linkMenu); - } - } + addFeatureLinks(seq, links); } + // TODO: add group link menu entry here if (seq != null) { @@ -414,6 +303,71 @@ public class APopupMenu extends java.awt.PopupMenu implements } /** + * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided. + * + * @param seq + * @param links + */ + void addFeatureLinks(final SequenceI seq, List links) + { + Menu linkMenu = new Menu(MessageManager.getString("action.link")); + Map> linkset = new LinkedHashMap>(); + + 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> linkset) + { + for (List 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. */ @@ -823,15 +777,16 @@ public class APopupMenu extends java.awt.PopupMenu implements Frame frame = new Frame(); frame.add(cap); - jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage( + JalviewLite.addFrame(frame, MessageManager.formatMessage( "label.selection_output_command", new Object[] { e.getActionCommand() }), 600, 500); // JBPNote: getSelectionAsNewSequence behaviour has changed - this method // now returns a full copy of sequence data // TODO consider using getSequenceSelection instead here - cap.setText(new jalview.io.AppletFormatAdapter().formatSequences( - e.getActionCommand(), ap.av.getShowJVSuffix(), ap, true)); + FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand()); + cap.setText(new AppletFormatAdapter().formatSequences(fileFormat, + ap.av.getShowJVSuffix(), ap, true)); } @@ -850,7 +805,7 @@ public class APopupMenu extends java.awt.PopupMenu implements CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame); - StringBuffer contents = new StringBuffer(); + StringBuilder contents = new StringBuilder(128); for (SequenceI seq : sequences) { contents.append(MessageManager.formatMessage( @@ -861,7 +816,6 @@ public class APopupMenu extends java.awt.PopupMenu implements seq, true, true, - false, (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr .getMinMax() : null); contents.append("

"); @@ -900,12 +854,12 @@ public class APopupMenu extends java.awt.PopupMenu implements if (ap.av.applet.jmolAvailable) { new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq }, - null, ap, AppletFormatAdapter.URL); + null, ap, DataSourceType.URL); } else { new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null, - ap, AppletFormatAdapter.URL); + ap, DataSourceType.URL); } } @@ -1207,11 +1161,10 @@ public class APopupMenu extends java.awt.PopupMenu implements if (conservationMenuItem.getState()) { - - sg.cs.setConservation(Conservation.calculateConservation("Group", 3, - sg.getSequences(ap.av.getHiddenRepSequences()), 0, ap.av - .getAlignment().getWidth(), false, ap.av - .getConsPercGaps(), false)); + sg.cs.setConservation(Conservation.calculateConservation("Group", sg + .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av + .getAlignment().getWidth(), false, ap.av.getConsPercGaps(), + false)); SliderPanel.setConservationSlider(ap, sg.cs, sg.getName()); SliderPanel.showConservationSlider(); }