2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.bin.Cache;
28 import jalview.commands.ChangeCaseCommand;
29 import jalview.commands.EditCommand;
30 import jalview.commands.EditCommand.Action;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.Annotation;
34 import jalview.datamodel.ColumnSelection;
35 import jalview.datamodel.DBRefEntry;
36 import jalview.datamodel.PDBEntry;
37 import jalview.datamodel.Sequence;
38 import jalview.datamodel.SequenceFeature;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.io.FileFormat;
42 import jalview.io.FormatAdapter;
43 import jalview.io.SequenceAnnotationReport;
44 import jalview.schemes.AnnotationColourGradient;
45 import jalview.schemes.Blosum62ColourScheme;
46 import jalview.schemes.BuriedColourScheme;
47 import jalview.schemes.ClustalxColourScheme;
48 import jalview.schemes.HelixColourScheme;
49 import jalview.schemes.HydrophobicColourScheme;
50 import jalview.schemes.NucleotideColourScheme;
51 import jalview.schemes.PIDColourScheme;
52 import jalview.schemes.PurinePyrimidineColourScheme;
53 import jalview.schemes.ResidueProperties;
54 import jalview.schemes.StrandColourScheme;
55 import jalview.schemes.TaylorColourScheme;
56 import jalview.schemes.TurnColourScheme;
57 import jalview.schemes.UserColourScheme;
58 import jalview.schemes.ZappoColourScheme;
59 import jalview.util.DBRefUtils;
60 import jalview.util.GroupUrlLink;
61 import jalview.util.GroupUrlLink.UrlStringTooLongException;
62 import jalview.util.MessageManager;
63 import jalview.util.UrlLink;
65 import java.awt.Color;
66 import java.awt.event.ActionEvent;
67 import java.awt.event.ActionListener;
68 import java.util.ArrayList;
69 import java.util.Arrays;
70 import java.util.Collections;
71 import java.util.Hashtable;
72 import java.util.LinkedHashMap;
73 import java.util.List;
75 import java.util.TreeMap;
76 import java.util.Vector;
78 import javax.swing.ButtonGroup;
79 import javax.swing.JCheckBoxMenuItem;
80 import javax.swing.JColorChooser;
81 import javax.swing.JMenu;
82 import javax.swing.JMenuItem;
83 import javax.swing.JOptionPane;
84 import javax.swing.JPopupMenu;
85 import javax.swing.JRadioButtonMenuItem;
91 * @version $Revision: 1.118 $
93 public class PopupMenu extends JPopupMenu
95 private static final String ALL_ANNOTATIONS = "All";
97 JMenu groupMenu = new JMenu();
99 JMenuItem groupName = new JMenuItem();
101 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
103 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
105 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
107 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
109 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
111 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
113 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
115 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
117 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
119 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
121 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
123 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
125 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
127 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
129 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
131 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
135 JMenu sequenceMenu = new JMenu();
137 JMenuItem sequenceName = new JMenuItem();
139 JMenuItem sequenceDetails = new JMenuItem();
141 JMenuItem sequenceSelDetails = new JMenuItem();
143 JMenuItem makeReferenceSeq = new JMenuItem();
145 JMenuItem chooseAnnotations = new JMenuItem();
149 JMenuItem createGroupMenuItem = new JMenuItem();
151 JMenuItem unGroupMenuItem = new JMenuItem();
153 JMenuItem outline = new JMenuItem();
155 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
157 JMenu colourMenu = new JMenu();
159 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
161 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
163 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
165 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
167 JMenu editMenu = new JMenu();
169 JMenuItem cut = new JMenuItem();
171 JMenuItem copy = new JMenuItem();
173 JMenuItem upperCase = new JMenuItem();
175 JMenuItem lowerCase = new JMenuItem();
177 JMenuItem toggle = new JMenuItem();
179 JMenu pdbMenu = new JMenu();
181 JMenu outputMenu = new JMenu();
183 JMenu seqShowAnnotationsMenu = new JMenu();
185 JMenu seqHideAnnotationsMenu = new JMenu();
187 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
188 MessageManager.getString("label.add_reference_annotations"));
190 JMenu groupShowAnnotationsMenu = new JMenu();
192 JMenu groupHideAnnotationsMenu = new JMenu();
194 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
195 MessageManager.getString("label.add_reference_annotations"));
197 JMenuItem sequenceFeature = new JMenuItem();
199 JMenuItem textColour = new JMenuItem();
201 JMenu jMenu1 = new JMenu();
203 JMenuItem pdbStructureDialog = new JMenuItem();
205 JMenu rnaStructureMenu = new JMenu();
207 JMenuItem editSequence = new JMenuItem();
209 JMenu groupLinksMenu;
211 JMenuItem hideInsertions = new JMenuItem();
214 * Creates a new PopupMenu object.
221 public PopupMenu(final AlignmentPanel ap, Sequence seq, List<String> links)
223 this(ap, seq, links, null);
233 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
234 List<String> links, List<String> groupLinks)
236 // /////////////////////////////////////////////////////////
237 // If this is activated from the sequence panel, the user may want to
238 // edit or annotate a particular residue. Therefore display the residue menu
240 // If from the IDPanel, we must display the sequence menu
241 // ////////////////////////////////////////////////////////
245 ButtonGroup colours = new ButtonGroup();
246 colours.add(noColourmenuItem);
247 colours.add(clustalColour);
248 colours.add(zappoColour);
249 colours.add(taylorColour);
250 colours.add(hydrophobicityColour);
251 colours.add(helixColour);
252 colours.add(strandColour);
253 colours.add(turnColour);
254 colours.add(buriedColour);
255 colours.add(abovePIDColour);
256 colours.add(userDefinedColour);
257 colours.add(PIDColour);
258 colours.add(BLOSUM62Colour);
259 colours.add(purinePyrimidineColour);
260 colours.add(RNAInteractionColour);
262 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
264 JMenuItem item = new JMenuItem(
265 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
267 item.addActionListener(new java.awt.event.ActionListener()
270 public void actionPerformed(ActionEvent e)
272 outputText_actionPerformed(e);
276 outputMenu.add(item);
280 * Build menus for annotation types that may be shown or hidden, and for
281 * 'reference annotations' that may be added to the alignment. First for the
282 * currently selected sequence (if there is one):
284 final List<SequenceI> selectedSequence = (seq == null ? Collections
285 .<SequenceI> emptyList() : Arrays.asList(seq));
286 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
287 seqHideAnnotationsMenu, selectedSequence);
288 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
292 * And repeat for the current selection group (if there is one):
294 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
295 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
297 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
298 groupHideAnnotationsMenu, selectedGroup);
299 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
305 } catch (Exception e)
313 sequenceMenu.setText(sequence.getName());
314 if (seq == ap.av.getAlignment().getSeqrep())
316 makeReferenceSeq.setText(MessageManager
317 .getString("action.unmark_as_reference"));
321 makeReferenceSeq.setText(MessageManager
322 .getString("action.set_as_reference"));
325 if (!ap.av.getAlignment().isNucleotide())
327 remove(rnaStructureMenu);
331 int origCount = rnaStructureMenu.getItemCount();
333 * add menu items to 2D-render any alignment or sequence secondary
334 * structure annotation
336 AlignmentAnnotation[] aas = ap.av.getAlignment()
337 .getAlignmentAnnotation();
340 for (final AlignmentAnnotation aa : aas)
342 if (aa.isValidStruc() && aa.sequenceRef == null)
345 * valid alignment RNA secondary structure annotation
347 menuItem = new JMenuItem();
348 menuItem.setText(MessageManager.formatMessage(
349 "label.2d_rna_structure_line",
350 new Object[] { aa.label }));
351 menuItem.addActionListener(new java.awt.event.ActionListener()
354 public void actionPerformed(ActionEvent e)
356 new AppVarna(seq, aa, ap);
359 rnaStructureMenu.add(menuItem);
364 if (seq.getAnnotation() != null)
366 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
367 for (final AlignmentAnnotation aa : seqAnns)
369 if (aa.isValidStruc())
372 * valid sequence RNA secondary structure annotation
374 // TODO: make rnastrucF a bit more nice
375 menuItem = new JMenuItem();
376 menuItem.setText(MessageManager.formatMessage(
377 "label.2d_rna_sequence_name",
378 new Object[] { seq.getName() }));
379 menuItem.addActionListener(new java.awt.event.ActionListener()
382 public void actionPerformed(ActionEvent e)
384 // TODO: VARNA does'nt print gaps in the sequence
385 new AppVarna(seq, aa, ap);
388 rnaStructureMenu.add(menuItem);
392 if (rnaStructureMenu.getItemCount() == origCount)
394 remove(rnaStructureMenu);
398 menuItem = new JMenuItem(
399 MessageManager.getString("action.hide_sequences"));
400 menuItem.addActionListener(new java.awt.event.ActionListener()
403 public void actionPerformed(ActionEvent e)
405 hideSequences(false);
410 if (ap.av.getSelectionGroup() != null
411 && ap.av.getSelectionGroup().getSize() > 1)
413 menuItem = new JMenuItem(MessageManager.formatMessage(
414 "label.represent_group_with",
415 new Object[] { seq.getName() }));
416 menuItem.addActionListener(new java.awt.event.ActionListener()
419 public void actionPerformed(ActionEvent e)
424 sequenceMenu.add(menuItem);
427 if (ap.av.hasHiddenRows())
429 final int index = ap.av.getAlignment().findIndex(seq);
431 if (ap.av.adjustForHiddenSeqs(index)
432 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
434 menuItem = new JMenuItem(
435 MessageManager.getString("action.reveal_sequences"));
436 menuItem.addActionListener(new ActionListener()
439 public void actionPerformed(ActionEvent e)
441 ap.av.showSequence(index);
442 if (ap.overviewPanel != null)
444 ap.overviewPanel.updateOverviewImage();
452 // for the case when no sequences are even visible
453 if (ap.av.hasHiddenRows())
456 menuItem = new JMenuItem(
457 MessageManager.getString("action.reveal_all"));
458 menuItem.addActionListener(new ActionListener()
461 public void actionPerformed(ActionEvent e)
463 ap.av.showAllHiddenSeqs();
464 if (ap.overviewPanel != null)
466 ap.overviewPanel.updateOverviewImage();
476 SequenceGroup sg = ap.av.getSelectionGroup();
477 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
478 .getGroups().contains(sg) : false;
480 if (sg != null && sg.getSize() > 0)
482 groupName.setText(MessageManager.formatMessage("label.name_param",
483 new Object[] { sg.getName() }));
484 groupName.setText(MessageManager
485 .getString("label.edit_name_and_description_current_group"));
487 if (sg.cs instanceof ZappoColourScheme)
489 zappoColour.setSelected(true);
491 else if (sg.cs instanceof TaylorColourScheme)
493 taylorColour.setSelected(true);
495 else if (sg.cs instanceof PIDColourScheme)
497 PIDColour.setSelected(true);
499 else if (sg.cs instanceof Blosum62ColourScheme)
501 BLOSUM62Colour.setSelected(true);
503 else if (sg.cs instanceof UserColourScheme)
505 userDefinedColour.setSelected(true);
507 else if (sg.cs instanceof HydrophobicColourScheme)
509 hydrophobicityColour.setSelected(true);
511 else if (sg.cs instanceof HelixColourScheme)
513 helixColour.setSelected(true);
515 else if (sg.cs instanceof StrandColourScheme)
517 strandColour.setSelected(true);
519 else if (sg.cs instanceof TurnColourScheme)
521 turnColour.setSelected(true);
523 else if (sg.cs instanceof BuriedColourScheme)
525 buriedColour.setSelected(true);
527 else if (sg.cs instanceof ClustalxColourScheme)
529 clustalColour.setSelected(true);
531 else if (sg.cs instanceof PurinePyrimidineColourScheme)
533 purinePyrimidineColour.setSelected(true);
537 * else if (sg.cs instanceof CovariationColourScheme) {
538 * covariationColour.setSelected(true); }
542 noColourmenuItem.setSelected(true);
545 if (sg.cs != null && sg.cs.conservationApplied())
547 conservationMenuItem.setSelected(true);
549 displayNonconserved.setSelected(sg.getShowNonconserved());
550 showText.setSelected(sg.getDisplayText());
551 showColourText.setSelected(sg.getColourText());
552 showBoxes.setSelected(sg.getDisplayBoxes());
553 // add any groupURLs to the groupURL submenu and make it visible
554 if (groupLinks != null && groupLinks.size() > 0)
556 buildGroupURLMenu(sg, groupLinks);
558 // Add a 'show all structures' for the current selection
559 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
560 SequenceI sqass = null;
561 for (SequenceI sq : ap.av.getSequenceSelection())
563 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
564 if (pes != null && pes.size() > 0)
566 reppdb.put(pes.get(0).getId(), pes.get(0));
567 for (PDBEntry pe : pes)
569 pdbe.put(pe.getId(), pe);
579 final PDBEntry[] pe = pdbe.values().toArray(
580 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
581 new PDBEntry[reppdb.size()]);
582 final JMenuItem gpdbview, rpdbview;
587 groupMenu.setVisible(false);
588 editMenu.setVisible(false);
593 createGroupMenuItem.setVisible(true);
594 unGroupMenuItem.setVisible(false);
595 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
599 createGroupMenuItem.setVisible(false);
600 unGroupMenuItem.setVisible(true);
601 jMenu1.setText(MessageManager.getString("action.edit_group"));
606 sequenceMenu.setVisible(false);
607 pdbStructureDialog.setVisible(false);
608 rnaStructureMenu.setVisible(false);
611 if (links != null && links.size() > 0)
613 addFeatureLinks(seq, links);
618 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
623 void addFeatureLinks(final SequenceI seq, List<String> links)
625 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
626 List<String> linkset = new ArrayList<String>();
627 for (String link : links)
629 UrlLink urlLink = null;
632 urlLink = new UrlLink(link);
633 } catch (Exception foo)
635 Cache.log.error("Exception for URLLink '" + link + "'", foo);
639 if (!urlLink.isValid())
641 Cache.log.error(urlLink.getInvalidMessage());
644 final String label = urlLink.getLabel();
645 if (seq != null && urlLink.isDynamic())
648 // collect matching db-refs
649 DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(),
650 new String[] { urlLink.getTarget() });
651 // collect id string too
652 String id = seq.getName();
653 String descr = seq.getDescription();
654 if (descr != null && descr.length() < 1)
661 for (int r = 0; r < dbr.length; r++)
663 if (id != null && dbr[r].getAccessionId().equals(id))
665 // suppress duplicate link creation for the bare sequence ID
666 // string with this link
669 // create Bare ID link for this URL
670 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true);
673 for (int u = 0; u < urls.length; u += 2)
675 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
677 linkset.add(urls[u] + "|" + urls[u + 1]);
678 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
686 // create Bare ID link for this URL
687 String[] urls = urlLink.makeUrls(id, true);
690 for (int u = 0; u < urls.length; u += 2)
692 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
694 linkset.add(urls[u] + "|" + urls[u + 1]);
695 addshowLink(linkMenu, label, urls[u + 1]);
700 // Create urls from description but only for URL links which are regex
702 if (descr != null && urlLink.getRegexReplace() != null)
704 // create link for this URL from description where regex matches
705 String[] urls = urlLink.makeUrls(descr, true);
708 for (int u = 0; u < urls.length; u += 2)
710 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
712 linkset.add(urls[u] + "|" + urls[u + 1]);
713 addshowLink(linkMenu, label, urls[u + 1]);
721 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
723 linkset.add(label + "|" + urlLink.getUrl_prefix());
724 // Add a non-dynamic link
725 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
729 if (sequence != null)
731 sequenceMenu.add(linkMenu);
740 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
741 * "All" is added first, followed by a separator. Then add any annotation
742 * types associated with the current selection. Separate menus are built for
743 * the selected sequence group (if any), and the selected sequence.
745 * Some annotation rows are always rendered together - these can be identified
746 * by a common graphGroup property > -1. Only one of each group will be marked
747 * as visible (to avoid duplication of the display). For such groups we add a
748 * composite type name, e.g.
750 * IUPredWS (Long), IUPredWS (Short)
754 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
755 List<SequenceI> forSequences)
757 showMenu.removeAll();
758 hideMenu.removeAll();
760 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
761 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
762 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
764 showMenu.addSeparator();
765 hideMenu.addSeparator();
767 final AlignmentAnnotation[] annotations = ap.getAlignment()
768 .getAlignmentAnnotation();
771 * Find shown/hidden annotations types, distinguished by source (calcId),
772 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
773 * the insertion order, which is the order of the annotations on the
776 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
777 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
778 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
779 AlignmentAnnotationUtils.asList(annotations), forSequences);
781 for (String calcId : hiddenTypes.keySet())
783 for (List<String> type : hiddenTypes.get(calcId))
785 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
789 // grey out 'show annotations' if none are hidden
790 showMenu.setEnabled(!hiddenTypes.isEmpty());
792 for (String calcId : shownTypes.keySet())
794 for (List<String> type : shownTypes.get(calcId))
796 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
800 // grey out 'hide annotations' if none are shown
801 hideMenu.setEnabled(!shownTypes.isEmpty());
805 * Returns a list of sequences - either the current selection group (if there
806 * is one), else the specified single sequence.
811 protected List<SequenceI> getSequenceScope(SequenceI seq)
813 List<SequenceI> forSequences = null;
814 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
815 if (selectionGroup != null && selectionGroup.getSize() > 0)
817 forSequences = selectionGroup.getSequences();
821 forSequences = seq == null ? Collections.<SequenceI> emptyList()
822 : Arrays.asList(seq);
828 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
831 * @param showOrHideMenu
833 * @param forSequences
834 * the sequences whose annotations may be shown or hidden
839 * if true this is a special label meaning 'All'
840 * @param actionIsShow
841 * if true, the select menu item action is to show the annotation
844 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
845 final List<SequenceI> forSequences, String calcId,
846 final List<String> types, final boolean allTypes,
847 final boolean actionIsShow)
849 String label = types.toString(); // [a, b, c]
850 label = label.substring(1, label.length() - 1); // a, b, c
851 final JMenuItem item = new JMenuItem(label);
852 item.setToolTipText(calcId);
853 item.addActionListener(new java.awt.event.ActionListener()
856 public void actionPerformed(ActionEvent e)
858 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
859 types, forSequences, allTypes, actionIsShow);
863 showOrHideMenu.add(item);
866 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
869 // TODO: usability: thread off the generation of group url content so root
871 // sequence only URLs
872 // ID/regex match URLs
873 groupLinksMenu = new JMenu(
874 MessageManager.getString("action.group_link"));
875 // three types of url that might be created.
876 JMenu[] linkMenus = new JMenu[] { null,
877 new JMenu(MessageManager.getString("action.ids")),
878 new JMenu(MessageManager.getString("action.sequences")),
879 new JMenu(MessageManager.getString("action.ids_sequences")) };
881 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
882 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
883 Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
884 for (int sq = 0; sq < seqs.length; sq++)
887 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
888 .findPosition(sg.getEndRes());
889 // just collect ids from dataset sequence
890 // TODO: check if IDs collected from selecton group intersects with the
891 // current selection, too
892 SequenceI sqi = seqs[sq];
893 while (sqi.getDatasetSequence() != null)
895 sqi = sqi.getDatasetSequence();
897 DBRefEntry[] dbr = sqi.getDBRefs();
898 if (dbr != null && dbr.length > 0)
900 for (int d = 0; d < dbr.length; d++)
902 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
903 Object[] sarray = commonDbrefs.get(src);
906 sarray = new Object[2];
907 sarray[0] = new int[] { 0 };
908 sarray[1] = new String[seqs.length];
910 commonDbrefs.put(src, sarray);
913 if (((String[]) sarray[1])[sq] == null)
916 || (dbr[d].getMap().locateMappedRange(start, end) != null))
918 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
919 ((int[]) sarray[0])[0]++;
925 // now create group links for all distinct ID/sequence sets.
926 boolean addMenu = false; // indicates if there are any group links to give
928 for (String link : groupLinks)
930 GroupUrlLink urlLink = null;
933 urlLink = new GroupUrlLink(link);
934 } catch (Exception foo)
936 Cache.log.error("Exception for GroupURLLink '" + link
941 if (!urlLink.isValid())
943 Cache.log.error(urlLink.getInvalidMessage());
946 final String label = urlLink.getLabel();
947 boolean usingNames = false;
948 // Now see which parts of the group apply for this URL
949 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
950 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
951 String[] seqstr, ids; // input to makeUrl
954 int numinput = ((int[]) idset[0])[0];
955 String[] allids = ((String[]) idset[1]);
956 seqstr = new String[numinput];
957 ids = new String[numinput];
958 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
960 if (allids[sq] != null)
962 ids[idcount] = allids[sq];
963 seqstr[idcount++] = idandseqs[1][sq];
969 // just use the id/seq set
970 seqstr = idandseqs[1];
974 // and try and make the groupURL!
976 Object[] urlset = null;
979 urlset = urlLink.makeUrlStubs(ids, seqstr,
980 "FromJalview" + System.currentTimeMillis(), false);
981 } catch (UrlStringTooLongException e)
986 int type = urlLink.getGroupURLType() & 3;
987 // first two bits ofurlLink type bitfield are sequenceids and sequences
988 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
989 addshowLink(linkMenus[type], label
990 + (((type & 1) == 1) ? ("("
991 + (usingNames ? "Names" : ltarget) + ")") : ""),
998 groupLinksMenu = new JMenu(
999 MessageManager.getString("action.group_link"));
1000 for (int m = 0; m < linkMenus.length; m++)
1002 if (linkMenus[m] != null
1003 && linkMenus[m].getMenuComponentCount() > 0)
1005 groupLinksMenu.add(linkMenus[m]);
1009 groupMenu.add(groupLinksMenu);
1014 * add a show URL menu item to the given linkMenu
1018 * - menu label string
1022 private void addshowLink(JMenu linkMenu, String label, final String url)
1024 JMenuItem item = new JMenuItem(label);
1025 item.setToolTipText(MessageManager.formatMessage(
1026 "label.open_url_param", new Object[] { url }));
1027 item.addActionListener(new java.awt.event.ActionListener()
1030 public void actionPerformed(ActionEvent e)
1032 new Thread(new Runnable()
1049 * add a late bound groupURL item to the given linkMenu
1053 * - menu label string
1054 * @param urlgenerator
1055 * GroupURLLink used to generate URL
1057 * Object array returned from the makeUrlStubs function.
1059 private void addshowLink(JMenu linkMenu, String label,
1060 final GroupUrlLink urlgenerator, final Object[] urlstub)
1062 JMenuItem item = new JMenuItem(label);
1063 item.setToolTipText(MessageManager.formatMessage(
1064 "label.open_url_seqs_param",
1065 new Object[] { urlgenerator.getUrl_prefix(),
1066 urlgenerator.getNumberInvolved(urlstub) }));
1067 // TODO: put in info about what is being sent.
1068 item.addActionListener(new ActionListener()
1071 public void actionPerformed(ActionEvent e)
1073 new Thread(new Runnable()
1081 showLink(urlgenerator.constructFrom(urlstub));
1082 } catch (UrlStringTooLongException e2)
1100 private void jbInit() throws Exception
1102 groupMenu.setText(MessageManager.getString("label.group"));
1103 groupMenu.setText(MessageManager.getString("label.selection"));
1104 groupName.setText(MessageManager.getString("label.name"));
1105 groupName.addActionListener(new java.awt.event.ActionListener()
1108 public void actionPerformed(ActionEvent e)
1110 groupName_actionPerformed();
1113 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1114 sequenceName.setText(MessageManager
1115 .getString("label.edit_name_description"));
1116 sequenceName.addActionListener(new java.awt.event.ActionListener()
1119 public void actionPerformed(ActionEvent e)
1121 sequenceName_actionPerformed();
1124 chooseAnnotations.setText(MessageManager
1125 .getString("action.choose_annotations"));
1126 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1129 public void actionPerformed(ActionEvent e)
1131 chooseAnnotations_actionPerformed(e);
1134 sequenceDetails.setText(MessageManager
1135 .getString("label.sequence_details"));
1136 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1139 public void actionPerformed(ActionEvent e)
1141 sequenceDetails_actionPerformed();
1144 sequenceSelDetails.setText(MessageManager
1145 .getString("label.sequence_details"));
1147 .addActionListener(new java.awt.event.ActionListener()
1150 public void actionPerformed(ActionEvent e)
1152 sequenceSelectionDetails_actionPerformed();
1155 PIDColour.setFocusPainted(false);
1157 .setText(MessageManager.getString("action.remove_group"));
1158 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1161 public void actionPerformed(ActionEvent e)
1163 unGroupMenuItem_actionPerformed();
1166 createGroupMenuItem.setText(MessageManager
1167 .getString("action.create_group"));
1169 .addActionListener(new java.awt.event.ActionListener()
1172 public void actionPerformed(ActionEvent e)
1174 createGroupMenuItem_actionPerformed();
1178 outline.setText(MessageManager.getString("action.border_colour"));
1179 outline.addActionListener(new java.awt.event.ActionListener()
1182 public void actionPerformed(ActionEvent e)
1184 outline_actionPerformed();
1188 .setText(MessageManager.getString("label.nucleotide"));
1189 nucleotideMenuItem.addActionListener(new ActionListener()
1192 public void actionPerformed(ActionEvent e)
1194 nucleotideMenuItem_actionPerformed();
1197 colourMenu.setText(MessageManager.getString("label.group_colour"));
1198 showBoxes.setText(MessageManager.getString("action.boxes"));
1199 showBoxes.setState(true);
1200 showBoxes.addActionListener(new ActionListener()
1203 public void actionPerformed(ActionEvent e)
1205 showBoxes_actionPerformed();
1208 showText.setText(MessageManager.getString("action.text"));
1209 showText.setState(true);
1210 showText.addActionListener(new ActionListener()
1213 public void actionPerformed(ActionEvent e)
1215 showText_actionPerformed();
1218 showColourText.setText(MessageManager.getString("label.colour_text"));
1219 showColourText.addActionListener(new ActionListener()
1222 public void actionPerformed(ActionEvent e)
1224 showColourText_actionPerformed();
1227 displayNonconserved.setText(MessageManager
1228 .getString("label.show_non_conversed"));
1229 displayNonconserved.setState(true);
1230 displayNonconserved.addActionListener(new ActionListener()
1233 public void actionPerformed(ActionEvent e)
1235 showNonconserved_actionPerformed();
1238 editMenu.setText(MessageManager.getString("action.edit"));
1239 cut.setText(MessageManager.getString("action.cut"));
1240 cut.addActionListener(new ActionListener()
1243 public void actionPerformed(ActionEvent e)
1245 cut_actionPerformed();
1248 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1249 upperCase.addActionListener(new ActionListener()
1252 public void actionPerformed(ActionEvent e)
1257 copy.setText(MessageManager.getString("action.copy"));
1258 copy.addActionListener(new ActionListener()
1261 public void actionPerformed(ActionEvent e)
1263 copy_actionPerformed();
1266 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1267 lowerCase.addActionListener(new ActionListener()
1270 public void actionPerformed(ActionEvent e)
1275 toggle.setText(MessageManager.getString("label.toggle_case"));
1276 toggle.addActionListener(new ActionListener()
1279 public void actionPerformed(ActionEvent e)
1284 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1286 seqShowAnnotationsMenu.setText(MessageManager
1287 .getString("label.show_annotations"));
1288 seqHideAnnotationsMenu.setText(MessageManager
1289 .getString("label.hide_annotations"));
1290 groupShowAnnotationsMenu.setText(MessageManager
1291 .getString("label.show_annotations"));
1292 groupHideAnnotationsMenu.setText(MessageManager
1293 .getString("label.hide_annotations"));
1294 sequenceFeature.setText(MessageManager
1295 .getString("label.create_sequence_feature"));
1296 sequenceFeature.addActionListener(new ActionListener()
1299 public void actionPerformed(ActionEvent e)
1301 sequenceFeature_actionPerformed();
1304 textColour.setText(MessageManager.getString("label.text_colour"));
1305 textColour.addActionListener(new ActionListener()
1308 public void actionPerformed(ActionEvent e)
1310 textColour_actionPerformed();
1313 jMenu1.setText(MessageManager.getString("label.group"));
1314 pdbStructureDialog.setText(MessageManager
1315 .getString("label.show_pdbstruct_dialog"));
1316 pdbStructureDialog.addActionListener(new ActionListener()
1319 public void actionPerformed(ActionEvent actionEvent)
1321 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1322 if (ap.av.getSelectionGroup() != null)
1324 selectedSeqs = ap.av.getSequenceSelection();
1326 new StructureChooser(selectedSeqs, sequence, ap);
1330 rnaStructureMenu.setText(MessageManager
1331 .getString("label.view_rna_structure"));
1333 // colStructureMenu.setText("Colour By Structure");
1334 editSequence.setText(MessageManager.getString("label.edit_sequence")
1336 editSequence.addActionListener(new ActionListener()
1339 public void actionPerformed(ActionEvent actionEvent)
1341 editSequence_actionPerformed(actionEvent);
1344 makeReferenceSeq.setText(MessageManager
1345 .getString("label.mark_as_representative"));
1346 makeReferenceSeq.addActionListener(new ActionListener()
1350 public void actionPerformed(ActionEvent actionEvent)
1352 makeReferenceSeq_actionPerformed(actionEvent);
1356 hideInsertions.setText(MessageManager
1357 .getString("label.hide_insertions"));
1358 hideInsertions.addActionListener(new ActionListener()
1362 public void actionPerformed(ActionEvent e)
1364 hideInsertions_actionPerformed(e);
1368 * annotationMenuItem.setText("By Annotation");
1369 * annotationMenuItem.addActionListener(new ActionListener() { public void
1370 * actionPerformed(ActionEvent actionEvent) {
1371 * annotationMenuItem_actionPerformed(actionEvent); } });
1373 groupMenu.add(sequenceSelDetails);
1376 add(rnaStructureMenu);
1377 add(pdbStructureDialog);
1378 if (sequence != null)
1380 add(hideInsertions);
1382 // annotations configuration panel suppressed for now
1383 // groupMenu.add(chooseAnnotations);
1386 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1387 * (if a selection group is in force).
1389 sequenceMenu.add(seqShowAnnotationsMenu);
1390 sequenceMenu.add(seqHideAnnotationsMenu);
1391 sequenceMenu.add(seqAddReferenceAnnotations);
1392 groupMenu.add(groupShowAnnotationsMenu);
1393 groupMenu.add(groupHideAnnotationsMenu);
1394 groupMenu.add(groupAddReferenceAnnotations);
1395 groupMenu.add(editMenu);
1396 groupMenu.add(outputMenu);
1397 groupMenu.add(sequenceFeature);
1398 groupMenu.add(createGroupMenuItem);
1399 groupMenu.add(unGroupMenuItem);
1400 groupMenu.add(jMenu1);
1401 sequenceMenu.add(sequenceName);
1402 sequenceMenu.add(sequenceDetails);
1403 sequenceMenu.add(makeReferenceSeq);
1404 colourMenu.add(textColour);
1405 colourMenu.add(noColourmenuItem);
1406 colourMenu.add(clustalColour);
1407 colourMenu.add(BLOSUM62Colour);
1408 colourMenu.add(PIDColour);
1409 colourMenu.add(zappoColour);
1410 colourMenu.add(taylorColour);
1411 colourMenu.add(hydrophobicityColour);
1412 colourMenu.add(helixColour);
1413 colourMenu.add(strandColour);
1414 colourMenu.add(turnColour);
1415 colourMenu.add(buriedColour);
1416 colourMenu.add(nucleotideMenuItem);
1417 if (ap.getAlignment().isNucleotide())
1419 // JBPNote - commented since the colourscheme isn't functional
1420 colourMenu.add(purinePyrimidineColour);
1422 colourMenu.add(userDefinedColour);
1424 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1426 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1427 .getUserColourSchemes().keys();
1429 while (userColours.hasMoreElements())
1431 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1432 item.addActionListener(new ActionListener()
1435 public void actionPerformed(ActionEvent evt)
1437 userDefinedColour_actionPerformed(evt);
1440 colourMenu.add(item);
1444 colourMenu.addSeparator();
1445 colourMenu.add(abovePIDColour);
1446 colourMenu.add(conservationMenuItem);
1449 editMenu.add(editSequence);
1450 editMenu.add(upperCase);
1451 editMenu.add(lowerCase);
1452 editMenu.add(toggle);
1453 // JBPNote: These shouldn't be added here - should appear in a generic
1454 // 'apply web service to this sequence menu'
1455 // pdbMenu.add(RNAFold);
1456 // pdbMenu.add(ContraFold);
1457 jMenu1.add(groupName);
1458 jMenu1.add(colourMenu);
1459 jMenu1.add(showBoxes);
1460 jMenu1.add(showText);
1461 jMenu1.add(showColourText);
1462 jMenu1.add(outline);
1463 jMenu1.add(displayNonconserved);
1464 noColourmenuItem.setText(MessageManager.getString("label.none"));
1465 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1468 public void actionPerformed(ActionEvent e)
1470 noColourmenuItem_actionPerformed();
1474 clustalColour.setText(MessageManager
1475 .getString("label.clustalx_colours"));
1476 clustalColour.addActionListener(new java.awt.event.ActionListener()
1479 public void actionPerformed(ActionEvent e)
1481 clustalColour_actionPerformed();
1484 zappoColour.setText(MessageManager.getString("label.zappo"));
1485 zappoColour.addActionListener(new java.awt.event.ActionListener()
1488 public void actionPerformed(ActionEvent e)
1490 zappoColour_actionPerformed();
1493 taylorColour.setText(MessageManager.getString("label.taylor"));
1494 taylorColour.addActionListener(new java.awt.event.ActionListener()
1497 public void actionPerformed(ActionEvent e)
1499 taylorColour_actionPerformed();
1502 hydrophobicityColour.setText(MessageManager
1503 .getString("label.hydrophobicity"));
1504 hydrophobicityColour
1505 .addActionListener(new java.awt.event.ActionListener()
1508 public void actionPerformed(ActionEvent e)
1510 hydrophobicityColour_actionPerformed();
1513 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1514 helixColour.addActionListener(new java.awt.event.ActionListener()
1517 public void actionPerformed(ActionEvent e)
1519 helixColour_actionPerformed();
1522 strandColour.setText(MessageManager
1523 .getString("label.strand_propensity"));
1524 strandColour.addActionListener(new java.awt.event.ActionListener()
1527 public void actionPerformed(ActionEvent e)
1529 strandColour_actionPerformed();
1532 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1533 turnColour.addActionListener(new java.awt.event.ActionListener()
1536 public void actionPerformed(ActionEvent e)
1538 turnColour_actionPerformed();
1541 buriedColour.setText(MessageManager.getString("label.buried_index"));
1542 buriedColour.addActionListener(new java.awt.event.ActionListener()
1545 public void actionPerformed(ActionEvent e)
1547 buriedColour_actionPerformed();
1550 abovePIDColour.setText(MessageManager
1551 .getString("label.above_identity_percentage"));
1552 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1555 public void actionPerformed(ActionEvent e)
1557 abovePIDColour_actionPerformed();
1560 userDefinedColour.setText(MessageManager
1561 .getString("action.user_defined"));
1562 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1565 public void actionPerformed(ActionEvent e)
1567 userDefinedColour_actionPerformed(e);
1571 .setText(MessageManager.getString("label.percentage_identity"));
1572 PIDColour.addActionListener(new java.awt.event.ActionListener()
1575 public void actionPerformed(ActionEvent e)
1577 PIDColour_actionPerformed();
1580 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1581 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1584 public void actionPerformed(ActionEvent e)
1586 BLOSUM62Colour_actionPerformed();
1589 purinePyrimidineColour.setText(MessageManager
1590 .getString("label.purine_pyrimidine"));
1591 purinePyrimidineColour
1592 .addActionListener(new java.awt.event.ActionListener()
1595 public void actionPerformed(ActionEvent e)
1597 purinePyrimidineColour_actionPerformed();
1602 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1603 * public void actionPerformed(ActionEvent e) {
1604 * covariationColour_actionPerformed(); } });
1607 conservationMenuItem.setText(MessageManager
1608 .getString("label.conservation"));
1609 conservationMenuItem
1610 .addActionListener(new java.awt.event.ActionListener()
1613 public void actionPerformed(ActionEvent e)
1615 conservationMenuItem_actionPerformed();
1621 * Check for any annotations on the underlying dataset sequences (for the
1622 * current selection group) which are not 'on the alignment'.If any are found,
1623 * enable the option to add them to the alignment. The criteria for 'on the
1624 * alignment' is finding an alignment annotation on the alignment, matched on
1625 * calcId, label and sequenceRef.
1627 * A tooltip is also constructed that displays the source (calcId) and type
1628 * (label) of the annotations that can be added.
1631 * @param forSequences
1633 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1634 List<SequenceI> forSequences)
1636 menuItem.setEnabled(false);
1639 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1640 * Using TreeMap means calcIds are shown in alphabetical order.
1642 Map<String, String> tipEntries = new TreeMap<String, String>();
1643 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1644 AlignmentI al = this.ap.av.getAlignment();
1645 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1646 tipEntries, candidates, al);
1647 if (!candidates.isEmpty())
1649 StringBuilder tooltip = new StringBuilder(64);
1650 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1653 * Found annotations that could be added. Enable the menu item, and
1654 * configure its tooltip and action.
1656 menuItem.setEnabled(true);
1657 for (String calcId : tipEntries.keySet())
1659 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1661 String tooltipText = JvSwingUtils.wrapTooltip(true,
1662 tooltip.toString());
1663 menuItem.setToolTipText(tooltipText);
1665 menuItem.addActionListener(new ActionListener()
1668 public void actionPerformed(ActionEvent e)
1670 addReferenceAnnotations_actionPerformed(candidates);
1677 * Add annotations to the sequences and to the alignment.
1680 * a map whose keys are sequences on the alignment, and values a list
1681 * of annotations to add to each sequence
1683 protected void addReferenceAnnotations_actionPerformed(
1684 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1686 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1687 final AlignmentI alignment = this.ap.getAlignment();
1688 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1693 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1695 if (!ap.av.getAlignment().hasSeqrep())
1697 // initialise the display flags so the user sees something happen
1698 ap.av.setDisplayReferenceSeq(true);
1699 ap.av.setColourByReferenceSeq(true);
1700 ap.av.getAlignment().setSeqrep(sequence);
1704 if (ap.av.getAlignment().getSeqrep() == sequence)
1706 ap.av.getAlignment().setSeqrep(null);
1710 ap.av.getAlignment().setSeqrep(sequence);
1716 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1718 if (sequence != null)
1720 ColumnSelection cs = ap.av.getColumnSelection();
1723 cs = new ColumnSelection();
1725 cs.hideInsertionsFor(sequence);
1726 ap.av.setColumnSelection(cs);
1731 protected void sequenceSelectionDetails_actionPerformed()
1733 createSequenceDetailsReport(ap.av.getSequenceSelection());
1736 protected void sequenceDetails_actionPerformed()
1738 createSequenceDetailsReport(new SequenceI[] { sequence });
1741 public void createSequenceDetailsReport(SequenceI[] sequences)
1743 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1744 StringBuffer contents = new StringBuffer();
1745 for (SequenceI seq : sequences)
1747 contents.append("<p><h2>"
1750 "label.create_sequence_details_report_annotation_for",
1751 new Object[] { seq.getDisplayId(true) })
1753 new SequenceAnnotationReport(null)
1754 .createSequenceAnnotationReport(
1760 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1761 .getSeqPanel().seqCanvas.fr.getMinMax()
1763 contents.append("</p>");
1765 cap.setText("<html>" + contents.toString() + "</html>");
1767 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1768 "label.sequence_details_for",
1769 (sequences.length == 1 ? new Object[] { sequences[0]
1770 .getDisplayId(true) } : new Object[] { MessageManager
1771 .getString("label.selection") })), 500, 400);
1775 protected void showNonconserved_actionPerformed()
1777 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1782 * call to refresh view after settings change
1786 ap.updateAnnotation();
1787 ap.paintAlignment(true);
1789 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1798 protected void clustalColour_actionPerformed()
1800 SequenceGroup sg = getGroup();
1801 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1811 protected void zappoColour_actionPerformed()
1813 getGroup().cs = new ZappoColourScheme();
1823 protected void taylorColour_actionPerformed()
1825 getGroup().cs = new TaylorColourScheme();
1835 protected void hydrophobicityColour_actionPerformed()
1837 getGroup().cs = new HydrophobicColourScheme();
1847 protected void helixColour_actionPerformed()
1849 getGroup().cs = new HelixColourScheme();
1859 protected void strandColour_actionPerformed()
1861 getGroup().cs = new StrandColourScheme();
1871 protected void turnColour_actionPerformed()
1873 getGroup().cs = new TurnColourScheme();
1883 protected void buriedColour_actionPerformed()
1885 getGroup().cs = new BuriedColourScheme();
1895 public void nucleotideMenuItem_actionPerformed()
1897 getGroup().cs = new NucleotideColourScheme();
1901 protected void purinePyrimidineColour_actionPerformed()
1903 getGroup().cs = new PurinePyrimidineColourScheme();
1908 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1909 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1917 protected void abovePIDColour_actionPerformed()
1919 SequenceGroup sg = getGroup();
1925 if (abovePIDColour.isSelected())
1927 sg.cs.setConsensus(AAFrequency.calculate(
1928 sg.getSequences(ap.av.getHiddenRepSequences()),
1929 sg.getStartRes(), sg.getEndRes() + 1));
1931 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1934 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1936 SliderPanel.showPIDSlider();
1939 // remove PIDColouring
1941 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1953 protected void userDefinedColour_actionPerformed(ActionEvent e)
1955 SequenceGroup sg = getGroup();
1957 if (e.getSource().equals(userDefinedColour))
1959 new UserDefinedColours(ap, sg);
1963 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1964 .getUserColourSchemes().get(e.getActionCommand());
1972 * Open a panel where the user can choose which types of sequence annotation
1977 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1979 // todo correct way to guard against opening a duplicate panel?
1980 new AnnotationChooser(ap);
1989 protected void PIDColour_actionPerformed()
1991 SequenceGroup sg = getGroup();
1992 sg.cs = new PIDColourScheme();
1993 sg.cs.setConsensus(AAFrequency.calculate(
1994 sg.getSequences(ap.av.getHiddenRepSequences()),
1995 sg.getStartRes(), sg.getEndRes() + 1));
2005 protected void BLOSUM62Colour_actionPerformed()
2007 SequenceGroup sg = getGroup();
2009 sg.cs = new Blosum62ColourScheme();
2011 sg.cs.setConsensus(AAFrequency.calculate(
2012 sg.getSequences(ap.av.getHiddenRepSequences()),
2013 sg.getStartRes(), sg.getEndRes() + 1));
2024 protected void noColourmenuItem_actionPerformed()
2026 getGroup().cs = null;
2036 protected void conservationMenuItem_actionPerformed()
2038 SequenceGroup sg = getGroup();
2044 if (conservationMenuItem.isSelected())
2046 // JBPNote: Conservation name shouldn't be i18n translated
2047 Conservation c = new Conservation("Group",
2048 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2049 .getHiddenRepSequences()), sg.getStartRes(),
2050 sg.getEndRes() + 1);
2053 c.verdict(false, ap.av.getConsPercGaps());
2055 sg.cs.setConservation(c);
2057 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2058 SliderPanel.showConservationSlider();
2061 // remove ConservationColouring
2063 sg.cs.setConservation(null);
2069 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2071 SequenceGroup sg = getGroup();
2077 AnnotationColourGradient acg = new AnnotationColourGradient(
2078 sequence.getAnnotation()[0], null,
2079 AnnotationColourGradient.NO_THRESHOLD);
2081 acg.setPredefinedColours(true);
2093 protected void groupName_actionPerformed()
2096 SequenceGroup sg = getGroup();
2097 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2098 sg.getDescription(), " "
2099 + MessageManager.getString("label.group_name") + " ",
2100 MessageManager.getString("label.group_description") + " ",
2101 MessageManager.getString("label.edit_group_name_description"),
2109 sg.setName(dialog.getName());
2110 sg.setDescription(dialog.getDescription());
2115 * Get selection group - adding it to the alignment if necessary.
2117 * @return sequence group to operate on
2119 SequenceGroup getGroup()
2121 SequenceGroup sg = ap.av.getSelectionGroup();
2122 // this method won't add a new group if it already exists
2125 ap.av.getAlignment().addGroup(sg);
2137 void sequenceName_actionPerformed()
2139 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2140 sequence.getDescription(),
2141 " " + MessageManager.getString("label.sequence_name")
2143 MessageManager.getString("label.sequence_description") + " ",
2145 .getString("label.edit_sequence_name_description"),
2153 if (dialog.getName() != null)
2155 if (dialog.getName().indexOf(" ") > -1)
2161 .getString("label.spaces_converted_to_backslashes"),
2163 .getString("label.no_spaces_allowed_sequence_name"),
2164 JOptionPane.WARNING_MESSAGE);
2167 sequence.setName(dialog.getName().replace(' ', '_'));
2168 ap.paintAlignment(false);
2171 sequence.setDescription(dialog.getDescription());
2173 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2184 void unGroupMenuItem_actionPerformed()
2186 SequenceGroup sg = ap.av.getSelectionGroup();
2187 ap.av.getAlignment().deleteGroup(sg);
2188 ap.av.setSelectionGroup(null);
2192 void createGroupMenuItem_actionPerformed()
2194 getGroup(); // implicitly creates group - note - should apply defaults / use
2195 // standard alignment window logic for this
2205 protected void outline_actionPerformed()
2207 SequenceGroup sg = getGroup();
2208 Color col = JColorChooser.showDialog(this,
2209 MessageManager.getString("label.select_outline_colour"),
2214 sg.setOutlineColour(col);
2226 public void showBoxes_actionPerformed()
2228 getGroup().setDisplayBoxes(showBoxes.isSelected());
2238 public void showText_actionPerformed()
2240 getGroup().setDisplayText(showText.isSelected());
2250 public void showColourText_actionPerformed()
2252 getGroup().setColourText(showColourText.isSelected());
2256 public void showLink(String url)
2260 jalview.util.BrowserLauncher.openURL(url);
2261 } catch (Exception ex)
2263 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2264 MessageManager.getString("label.web_browser_not_found_unix"),
2265 MessageManager.getString("label.web_browser_not_found"),
2266 JOptionPane.WARNING_MESSAGE);
2268 ex.printStackTrace();
2272 void hideSequences(boolean representGroup)
2274 ap.av.hideSequences(sequence, representGroup);
2277 public void copy_actionPerformed()
2279 ap.alignFrame.copy_actionPerformed(null);
2282 public void cut_actionPerformed()
2284 ap.alignFrame.cut_actionPerformed(null);
2287 void changeCase(ActionEvent e)
2289 Object source = e.getSource();
2290 SequenceGroup sg = ap.av.getSelectionGroup();
2294 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2295 sg.getStartRes(), sg.getEndRes() + 1);
2300 if (source == toggle)
2302 description = MessageManager.getString("label.toggle_case");
2303 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2305 else if (source == upperCase)
2307 description = MessageManager.getString("label.to_upper_case");
2308 caseChange = ChangeCaseCommand.TO_UPPER;
2312 description = MessageManager.getString("label.to_lower_case");
2313 caseChange = ChangeCaseCommand.TO_LOWER;
2316 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2317 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2318 startEnd, caseChange);
2320 ap.alignFrame.addHistoryItem(caseCommand);
2322 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2328 public void outputText_actionPerformed(ActionEvent e)
2330 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2331 cap.setForInput(null);
2332 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2333 "label.alignment_output_command",
2334 new Object[] { e.getActionCommand() }), 600, 500);
2336 String[] omitHidden = null;
2338 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2339 // or we simply trust the user wants
2340 // wysiwig behaviour
2342 FileFormat fileFormat = FileFormat.forName(e.getActionCommand());
2343 cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2346 public void sequenceFeature_actionPerformed()
2348 SequenceGroup sg = ap.av.getSelectionGroup();
2354 int rsize = 0, gSize = sg.getSize();
2355 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2356 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2358 for (int i = 0; i < gSize; i++)
2360 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2361 int end = sg.findEndRes(sg.getSequenceAt(i));
2364 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2365 features[rsize] = new SequenceFeature(null, null, null, start, end,
2370 rseqs = new SequenceI[rsize];
2371 tfeatures = new SequenceFeature[rsize];
2372 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2373 System.arraycopy(features, 0, tfeatures, 0, rsize);
2374 features = tfeatures;
2376 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2377 features, true, ap))
2379 ap.alignFrame.setShowSeqFeatures(true);
2380 ap.highlightSearchResults(null);
2384 public void textColour_actionPerformed()
2386 SequenceGroup sg = getGroup();
2389 new TextColourChooser().chooseColour(ap, sg);
2393 public void colourByStructure(String pdbid)
2395 Annotation[] anots = ap.av.getStructureSelectionManager()
2396 .colourSequenceFromStructure(sequence, pdbid);
2398 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2399 "Coloured by " + pdbid, anots);
2401 ap.av.getAlignment().addAnnotation(an);
2402 an.createSequenceMapping(sequence, 0, true);
2403 // an.adjustForAlignment();
2404 ap.av.getAlignment().setAnnotationIndex(an, 0);
2406 ap.adjustAnnotationHeight();
2408 sequence.addAlignmentAnnotation(an);
2412 public void editSequence_actionPerformed(ActionEvent actionEvent)
2414 SequenceGroup sg = ap.av.getSelectionGroup();
2418 if (sequence == null)
2420 sequence = sg.getSequenceAt(0);
2423 EditNameDialog dialog = new EditNameDialog(
2424 sequence.getSequenceAsString(sg.getStartRes(),
2425 sg.getEndRes() + 1), null,
2426 MessageManager.getString("label.edit_sequence"), null,
2427 MessageManager.getString("label.edit_sequence"),
2432 EditCommand editCommand = new EditCommand(
2433 MessageManager.getString("label.edit_sequences"),
2434 Action.REPLACE, dialog.getName().replace(' ',
2435 ap.av.getGapCharacter()),
2436 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2437 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2439 ap.alignFrame.addHistoryItem(editCommand);
2441 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()