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.FileFormatI;
43 import jalview.io.FormatAdapter;
44 import jalview.io.SequenceAnnotationReport;
45 import jalview.schemes.AnnotationColourGradient;
46 import jalview.schemes.Blosum62ColourScheme;
47 import jalview.schemes.BuriedColourScheme;
48 import jalview.schemes.ClustalxColourScheme;
49 import jalview.schemes.ColourSchemeI;
50 import jalview.schemes.HelixColourScheme;
51 import jalview.schemes.HydrophobicColourScheme;
52 import jalview.schemes.JalviewColourScheme;
53 import jalview.schemes.NucleotideColourScheme;
54 import jalview.schemes.PIDColourScheme;
55 import jalview.schemes.PurinePyrimidineColourScheme;
56 import jalview.schemes.StrandColourScheme;
57 import jalview.schemes.TCoffeeColourScheme;
58 import jalview.schemes.TaylorColourScheme;
59 import jalview.schemes.TurnColourScheme;
60 import jalview.schemes.UserColourScheme;
61 import jalview.schemes.ZappoColourScheme;
62 import jalview.util.GroupUrlLink;
63 import jalview.util.GroupUrlLink.UrlStringTooLongException;
64 import jalview.util.MessageManager;
65 import jalview.util.UrlLink;
67 import java.awt.Color;
68 import java.awt.Component;
69 import java.awt.event.ActionEvent;
70 import java.awt.event.ActionListener;
71 import java.util.Arrays;
72 import java.util.Collection;
73 import java.util.Collections;
74 import java.util.Hashtable;
75 import java.util.LinkedHashMap;
76 import java.util.List;
78 import java.util.SortedMap;
79 import java.util.TreeMap;
80 import java.util.Vector;
82 import javax.swing.ButtonGroup;
83 import javax.swing.JCheckBoxMenuItem;
84 import javax.swing.JColorChooser;
85 import javax.swing.JMenu;
86 import javax.swing.JMenuItem;
87 import javax.swing.JPopupMenu;
88 import javax.swing.JRadioButtonMenuItem;
94 * @version $Revision: 1.118 $
96 public class PopupMenu extends JPopupMenu
98 JMenu groupMenu = new JMenu();
100 JMenuItem groupName = new JMenuItem();
102 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
104 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
106 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
108 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
110 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
112 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
114 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
116 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
118 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
120 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
122 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
124 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
126 JRadioButtonMenuItem nucleotideColour = new JRadioButtonMenuItem();
128 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
130 protected JRadioButtonMenuItem tcoffeeColour = new JRadioButtonMenuItem();
132 // protected JRadioButtonMenuItem RNAInteractionColour;
134 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
136 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
140 JMenu sequenceMenu = new JMenu();
142 JMenuItem sequenceName = new JMenuItem();
144 JMenuItem sequenceDetails = new JMenuItem();
146 JMenuItem sequenceSelDetails = new JMenuItem();
148 JMenuItem makeReferenceSeq = new JMenuItem();
150 JMenuItem chooseAnnotations = new JMenuItem();
154 JMenuItem createGroupMenuItem = new JMenuItem();
156 JMenuItem unGroupMenuItem = new JMenuItem();
158 JMenuItem outline = new JMenuItem();
160 JMenu colourMenu = new JMenu();
162 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
164 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
166 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
168 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
170 JMenu editMenu = new JMenu();
172 JMenuItem cut = new JMenuItem();
174 JMenuItem copy = new JMenuItem();
176 JMenuItem upperCase = new JMenuItem();
178 JMenuItem lowerCase = new JMenuItem();
180 JMenuItem toggle = new JMenuItem();
182 JMenu pdbMenu = new JMenu();
184 JMenu outputMenu = new JMenu();
186 JMenu seqShowAnnotationsMenu = new JMenu();
188 JMenu seqHideAnnotationsMenu = new JMenu();
190 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
191 MessageManager.getString("label.add_reference_annotations"));
193 JMenu groupShowAnnotationsMenu = new JMenu();
195 JMenu groupHideAnnotationsMenu = new JMenu();
197 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
198 MessageManager.getString("label.add_reference_annotations"));
200 JMenuItem sequenceFeature = new JMenuItem();
202 JMenuItem textColour = new JMenuItem();
204 JMenu jMenu1 = new JMenu();
206 JMenuItem pdbStructureDialog = new JMenuItem();
208 JMenu rnaStructureMenu = new JMenu();
210 JMenuItem editSequence = new JMenuItem();
212 JMenu groupLinksMenu;
214 JMenuItem hideInsertions = new JMenuItem();
217 * Creates a new PopupMenu object.
224 public PopupMenu(final AlignmentPanel ap, Sequence seq, List<String> links)
226 this(ap, seq, links, null);
236 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
237 List<String> links, List<String> groupLinks)
239 // /////////////////////////////////////////////////////////
240 // If this is activated from the sequence panel, the user may want to
241 // edit or annotate a particular residue. Therefore display the residue menu
243 // If from the IDPanel, we must display the sequence menu
244 // ////////////////////////////////////////////////////////
248 for (String ff : FileFormat.getWritableFormats(true))
250 JMenuItem item = new JMenuItem(ff);
252 item.addActionListener(new ActionListener()
255 public void actionPerformed(ActionEvent e)
257 outputText_actionPerformed(e);
261 outputMenu.add(item);
265 * Build menus for annotation types that may be shown or hidden, and for
266 * 'reference annotations' that may be added to the alignment. First for the
267 * currently selected sequence (if there is one):
269 final List<SequenceI> selectedSequence = (seq == null ? Collections
270 .<SequenceI> emptyList() : Arrays.asList(seq));
271 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
272 seqHideAnnotationsMenu, selectedSequence);
273 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
277 * And repeat for the current selection group (if there is one):
279 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
280 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
282 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
283 groupHideAnnotationsMenu, selectedGroup);
284 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
290 } catch (Exception e)
298 sequenceMenu.setText(sequence.getName());
299 if (seq == ap.av.getAlignment().getSeqrep())
301 makeReferenceSeq.setText(MessageManager
302 .getString("action.unmark_as_reference"));
306 makeReferenceSeq.setText(MessageManager
307 .getString("action.set_as_reference"));
310 if (!ap.av.getAlignment().isNucleotide())
312 remove(rnaStructureMenu);
316 int origCount = rnaStructureMenu.getItemCount();
318 * add menu items to 2D-render any alignment or sequence secondary
319 * structure annotation
321 AlignmentAnnotation[] aas = ap.av.getAlignment()
322 .getAlignmentAnnotation();
325 for (final AlignmentAnnotation aa : aas)
327 if (aa.isValidStruc() && aa.sequenceRef == null)
330 * valid alignment RNA secondary structure annotation
332 menuItem = new JMenuItem();
333 menuItem.setText(MessageManager.formatMessage(
334 "label.2d_rna_structure_line",
335 new Object[] { aa.label }));
336 menuItem.addActionListener(new ActionListener()
339 public void actionPerformed(ActionEvent e)
341 new AppVarna(seq, aa, ap);
344 rnaStructureMenu.add(menuItem);
349 if (seq.getAnnotation() != null)
351 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
352 for (final AlignmentAnnotation aa : seqAnns)
354 if (aa.isValidStruc())
357 * valid sequence RNA secondary structure annotation
359 // TODO: make rnastrucF a bit more nice
360 menuItem = new JMenuItem();
361 menuItem.setText(MessageManager.formatMessage(
362 "label.2d_rna_sequence_name",
363 new Object[] { seq.getName() }));
364 menuItem.addActionListener(new ActionListener()
367 public void actionPerformed(ActionEvent e)
369 // TODO: VARNA does'nt print gaps in the sequence
370 new AppVarna(seq, aa, ap);
373 rnaStructureMenu.add(menuItem);
377 if (rnaStructureMenu.getItemCount() == origCount)
379 remove(rnaStructureMenu);
383 menuItem = new JMenuItem(
384 MessageManager.getString("action.hide_sequences"));
385 menuItem.addActionListener(new ActionListener()
388 public void actionPerformed(ActionEvent e)
390 hideSequences(false);
395 if (ap.av.getSelectionGroup() != null
396 && ap.av.getSelectionGroup().getSize() > 1)
398 menuItem = new JMenuItem(MessageManager.formatMessage(
399 "label.represent_group_with",
400 new Object[] { seq.getName() }));
401 menuItem.addActionListener(new ActionListener()
404 public void actionPerformed(ActionEvent e)
409 sequenceMenu.add(menuItem);
412 if (ap.av.hasHiddenRows())
414 final int index = ap.av.getAlignment().findIndex(seq);
416 if (ap.av.adjustForHiddenSeqs(index)
417 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
419 menuItem = new JMenuItem(
420 MessageManager.getString("action.reveal_sequences"));
421 menuItem.addActionListener(new ActionListener()
424 public void actionPerformed(ActionEvent e)
426 ap.av.showSequence(index);
427 if (ap.overviewPanel != null)
429 ap.overviewPanel.updateOverviewImage();
437 // for the case when no sequences are even visible
438 if (ap.av.hasHiddenRows())
441 menuItem = new JMenuItem(
442 MessageManager.getString("action.reveal_all"));
443 menuItem.addActionListener(new ActionListener()
446 public void actionPerformed(ActionEvent e)
448 ap.av.showAllHiddenSeqs();
449 if (ap.overviewPanel != null)
451 ap.overviewPanel.updateOverviewImage();
461 SequenceGroup sg = ap.av.getSelectionGroup();
462 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
463 .getGroups().contains(sg) : false;
465 if (sg != null && sg.getSize() > 0)
467 groupName.setText(MessageManager
468 .getString("label.edit_name_and_description_current_group"));
470 setColourSelected(sg.cs);
472 if (sg.cs != null && sg.cs.conservationApplied())
474 conservationMenuItem.setSelected(true);
476 displayNonconserved.setSelected(sg.getShowNonconserved());
477 showText.setSelected(sg.getDisplayText());
478 showColourText.setSelected(sg.getColourText());
479 showBoxes.setSelected(sg.getDisplayBoxes());
480 // add any groupURLs to the groupURL submenu and make it visible
481 if (groupLinks != null && groupLinks.size() > 0)
483 buildGroupURLMenu(sg, groupLinks);
485 // Add a 'show all structures' for the current selection
486 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
487 SequenceI sqass = null;
488 for (SequenceI sq : ap.av.getSequenceSelection())
490 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
491 if (pes != null && pes.size() > 0)
493 reppdb.put(pes.get(0).getId(), pes.get(0));
494 for (PDBEntry pe : pes)
496 pdbe.put(pe.getId(), pe);
506 final PDBEntry[] pe = pdbe.values().toArray(
507 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
508 new PDBEntry[reppdb.size()]);
509 final JMenuItem gpdbview, rpdbview;
514 groupMenu.setVisible(false);
515 editMenu.setVisible(false);
520 createGroupMenuItem.setVisible(true);
521 unGroupMenuItem.setVisible(false);
522 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
526 createGroupMenuItem.setVisible(false);
527 unGroupMenuItem.setVisible(true);
528 jMenu1.setText(MessageManager.getString("action.edit_group"));
533 sequenceMenu.setVisible(false);
534 pdbStructureDialog.setVisible(false);
535 rnaStructureMenu.setVisible(false);
538 if (links != null && links.size() > 0)
540 addFeatureLinks(seq, links);
545 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
550 void addFeatureLinks(final SequenceI seq, List<String> links)
552 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
553 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
555 for (String link : links)
557 UrlLink urlLink = null;
560 urlLink = new UrlLink(link);
561 } catch (Exception foo)
563 Cache.log.error("Exception for URLLink '" + link + "'", foo);
567 if (!urlLink.isValid())
569 Cache.log.error(urlLink.getInvalidMessage());
573 urlLink.createLinksFromSeq(seq, linkset);
576 addshowLinks(linkMenu, linkset.values());
578 // disable link menu if there are no valid entries
579 if (linkMenu.getItemCount() > 0)
581 linkMenu.setEnabled(true);
585 linkMenu.setEnabled(false);
588 if (sequence != null)
590 sequenceMenu.add(linkMenu);
602 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
603 * "All" is added first, followed by a separator. Then add any annotation
604 * types associated with the current selection. Separate menus are built for
605 * the selected sequence group (if any), and the selected sequence.
607 * Some annotation rows are always rendered together - these can be identified
608 * by a common graphGroup property > -1. Only one of each group will be marked
609 * as visible (to avoid duplication of the display). For such groups we add a
610 * composite type name, e.g.
612 * IUPredWS (Long), IUPredWS (Short)
616 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
617 List<SequenceI> forSequences)
619 showMenu.removeAll();
620 hideMenu.removeAll();
622 final List<String> all = Arrays.asList(new String[] { MessageManager
623 .getString("label.all") });
624 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
625 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
627 showMenu.addSeparator();
628 hideMenu.addSeparator();
630 final AlignmentAnnotation[] annotations = ap.getAlignment()
631 .getAlignmentAnnotation();
634 * Find shown/hidden annotations types, distinguished by source (calcId),
635 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
636 * the insertion order, which is the order of the annotations on the
639 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
640 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
641 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
642 AlignmentAnnotationUtils.asList(annotations), forSequences);
644 for (String calcId : hiddenTypes.keySet())
646 for (List<String> type : hiddenTypes.get(calcId))
648 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
652 // grey out 'show annotations' if none are hidden
653 showMenu.setEnabled(!hiddenTypes.isEmpty());
655 for (String calcId : shownTypes.keySet())
657 for (List<String> type : shownTypes.get(calcId))
659 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
663 // grey out 'hide annotations' if none are shown
664 hideMenu.setEnabled(!shownTypes.isEmpty());
668 * Returns a list of sequences - either the current selection group (if there
669 * is one), else the specified single sequence.
674 protected List<SequenceI> getSequenceScope(SequenceI seq)
676 List<SequenceI> forSequences = null;
677 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
678 if (selectionGroup != null && selectionGroup.getSize() > 0)
680 forSequences = selectionGroup.getSequences();
684 forSequences = seq == null ? Collections.<SequenceI> emptyList()
685 : Arrays.asList(seq);
691 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
694 * @param showOrHideMenu
696 * @param forSequences
697 * the sequences whose annotations may be shown or hidden
702 * if true this is a special label meaning 'All'
703 * @param actionIsShow
704 * if true, the select menu item action is to show the annotation
707 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
708 final List<SequenceI> forSequences, String calcId,
709 final List<String> types, final boolean allTypes,
710 final boolean actionIsShow)
712 String label = types.toString(); // [a, b, c]
713 label = label.substring(1, label.length() - 1); // a, b, c
714 final JMenuItem item = new JMenuItem(label);
715 item.setToolTipText(calcId);
716 item.addActionListener(new ActionListener()
719 public void actionPerformed(ActionEvent e)
721 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
722 types, forSequences, allTypes, actionIsShow);
726 showOrHideMenu.add(item);
729 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
732 // TODO: usability: thread off the generation of group url content so root
734 // sequence only URLs
735 // ID/regex match URLs
736 groupLinksMenu = new JMenu(
737 MessageManager.getString("action.group_link"));
738 // three types of url that might be created.
739 JMenu[] linkMenus = new JMenu[] { null,
740 new JMenu(MessageManager.getString("action.ids")),
741 new JMenu(MessageManager.getString("action.sequences")),
742 new JMenu(MessageManager.getString("action.ids_sequences")) };
744 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
745 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
746 Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
747 for (int sq = 0; sq < seqs.length; sq++)
750 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
751 .findPosition(sg.getEndRes());
752 // just collect ids from dataset sequence
753 // TODO: check if IDs collected from selecton group intersects with the
754 // current selection, too
755 SequenceI sqi = seqs[sq];
756 while (sqi.getDatasetSequence() != null)
758 sqi = sqi.getDatasetSequence();
760 DBRefEntry[] dbr = sqi.getDBRefs();
761 if (dbr != null && dbr.length > 0)
763 for (int d = 0; d < dbr.length; d++)
765 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
766 Object[] sarray = commonDbrefs.get(src);
769 sarray = new Object[2];
770 sarray[0] = new int[] { 0 };
771 sarray[1] = new String[seqs.length];
773 commonDbrefs.put(src, sarray);
776 if (((String[]) sarray[1])[sq] == null)
779 || (dbr[d].getMap().locateMappedRange(start, end) != null))
781 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
782 ((int[]) sarray[0])[0]++;
788 // now create group links for all distinct ID/sequence sets.
789 boolean addMenu = false; // indicates if there are any group links to give
791 for (String link : groupLinks)
793 GroupUrlLink urlLink = null;
796 urlLink = new GroupUrlLink(link);
797 } catch (Exception foo)
799 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
803 if (!urlLink.isValid())
805 Cache.log.error(urlLink.getInvalidMessage());
808 final String label = urlLink.getLabel();
809 boolean usingNames = false;
810 // Now see which parts of the group apply for this URL
811 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
812 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
813 String[] seqstr, ids; // input to makeUrl
816 int numinput = ((int[]) idset[0])[0];
817 String[] allids = ((String[]) idset[1]);
818 seqstr = new String[numinput];
819 ids = new String[numinput];
820 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
822 if (allids[sq] != null)
824 ids[idcount] = allids[sq];
825 seqstr[idcount++] = idandseqs[1][sq];
831 // just use the id/seq set
832 seqstr = idandseqs[1];
836 // and try and make the groupURL!
838 Object[] urlset = null;
841 urlset = urlLink.makeUrlStubs(ids, seqstr,
842 "FromJalview" + System.currentTimeMillis(), false);
843 } catch (UrlStringTooLongException e)
848 int type = urlLink.getGroupURLType() & 3;
849 // first two bits ofurlLink type bitfield are sequenceids and sequences
850 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
851 addshowLink(linkMenus[type], label
852 + (((type & 1) == 1) ? ("("
853 + (usingNames ? "Names" : ltarget) + ")") : ""),
860 groupLinksMenu = new JMenu(
861 MessageManager.getString("action.group_link"));
862 for (int m = 0; m < linkMenus.length; m++)
864 if (linkMenus[m] != null
865 && linkMenus[m].getMenuComponentCount() > 0)
867 groupLinksMenu.add(linkMenus[m]);
871 groupMenu.add(groupLinksMenu);
875 private void addshowLinks(JMenu linkMenu, Collection<List<String>> linkset)
877 for (List<String> linkstrset : linkset)
879 // split linkstr into label and url
880 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
885 * add a show URL menu item to the given linkMenu
889 * - menu label string
893 private void addshowLink(JMenu linkMenu, String label, final String url)
895 JMenuItem item = new JMenuItem(label);
896 item.setToolTipText(MessageManager.formatMessage(
897 "label.open_url_param", new Object[] { url }));
898 item.addActionListener(new ActionListener()
901 public void actionPerformed(ActionEvent e)
903 new Thread(new Runnable()
920 * add a late bound groupURL item to the given linkMenu
924 * - menu label string
925 * @param urlgenerator
926 * GroupURLLink used to generate URL
928 * Object array returned from the makeUrlStubs function.
930 private void addshowLink(JMenu linkMenu, String label,
931 final GroupUrlLink urlgenerator, final Object[] urlstub)
933 JMenuItem item = new JMenuItem(label);
934 item.setToolTipText(MessageManager.formatMessage(
935 "label.open_url_seqs_param",
936 new Object[] { urlgenerator.getUrl_prefix(),
937 urlgenerator.getNumberInvolved(urlstub) }));
938 // TODO: put in info about what is being sent.
939 item.addActionListener(new ActionListener()
942 public void actionPerformed(ActionEvent e)
944 new Thread(new Runnable()
952 showLink(urlgenerator.constructFrom(urlstub));
953 } catch (UrlStringTooLongException e2)
971 private void jbInit() throws Exception
973 groupMenu.setText(MessageManager.getString("label.selection"));
974 groupName.setText(MessageManager.getString("label.name"));
975 groupName.addActionListener(new ActionListener()
978 public void actionPerformed(ActionEvent e)
980 groupName_actionPerformed();
983 sequenceMenu.setText(MessageManager.getString("label.sequence"));
984 sequenceName.setText(MessageManager
985 .getString("label.edit_name_description"));
986 sequenceName.addActionListener(new ActionListener()
989 public void actionPerformed(ActionEvent e)
991 sequenceName_actionPerformed();
994 chooseAnnotations.setText(MessageManager
995 .getString("action.choose_annotations"));
996 chooseAnnotations.addActionListener(new ActionListener()
999 public void actionPerformed(ActionEvent e)
1001 chooseAnnotations_actionPerformed(e);
1004 sequenceDetails.setText(MessageManager
1005 .getString("label.sequence_details"));
1006 sequenceDetails.addActionListener(new ActionListener()
1009 public void actionPerformed(ActionEvent e)
1011 sequenceDetails_actionPerformed();
1014 sequenceSelDetails.setText(MessageManager
1015 .getString("label.sequence_details"));
1017 .addActionListener(new ActionListener()
1020 public void actionPerformed(ActionEvent e)
1022 sequenceSelectionDetails_actionPerformed();
1025 PIDColour.setFocusPainted(false);
1027 .setText(MessageManager.getString("action.remove_group"));
1028 unGroupMenuItem.addActionListener(new ActionListener()
1031 public void actionPerformed(ActionEvent e)
1033 unGroupMenuItem_actionPerformed();
1036 createGroupMenuItem.setText(MessageManager
1037 .getString("action.create_group"));
1039 .addActionListener(new ActionListener()
1042 public void actionPerformed(ActionEvent e)
1044 createGroupMenuItem_actionPerformed();
1048 outline.setText(MessageManager.getString("action.border_colour"));
1049 outline.addActionListener(new ActionListener()
1052 public void actionPerformed(ActionEvent e)
1054 outline_actionPerformed();
1057 showBoxes.setText(MessageManager.getString("action.boxes"));
1058 showBoxes.setState(true);
1059 showBoxes.addActionListener(new ActionListener()
1062 public void actionPerformed(ActionEvent e)
1064 showBoxes_actionPerformed();
1067 showText.setText(MessageManager.getString("action.text"));
1068 showText.setState(true);
1069 showText.addActionListener(new ActionListener()
1072 public void actionPerformed(ActionEvent e)
1074 showText_actionPerformed();
1077 showColourText.setText(MessageManager.getString("label.colour_text"));
1078 showColourText.addActionListener(new ActionListener()
1081 public void actionPerformed(ActionEvent e)
1083 showColourText_actionPerformed();
1086 displayNonconserved.setText(MessageManager
1087 .getString("label.show_non_conserved"));
1088 displayNonconserved.setState(true);
1089 displayNonconserved.addActionListener(new ActionListener()
1092 public void actionPerformed(ActionEvent e)
1094 showNonconserved_actionPerformed();
1097 editMenu.setText(MessageManager.getString("action.edit"));
1098 cut.setText(MessageManager.getString("action.cut"));
1099 cut.addActionListener(new ActionListener()
1102 public void actionPerformed(ActionEvent e)
1104 cut_actionPerformed();
1107 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1108 upperCase.addActionListener(new ActionListener()
1111 public void actionPerformed(ActionEvent e)
1116 copy.setText(MessageManager.getString("action.copy"));
1117 copy.addActionListener(new ActionListener()
1120 public void actionPerformed(ActionEvent e)
1122 copy_actionPerformed();
1125 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1126 lowerCase.addActionListener(new ActionListener()
1129 public void actionPerformed(ActionEvent e)
1134 toggle.setText(MessageManager.getString("label.toggle_case"));
1135 toggle.addActionListener(new ActionListener()
1138 public void actionPerformed(ActionEvent e)
1143 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1145 seqShowAnnotationsMenu.setText(MessageManager
1146 .getString("label.show_annotations"));
1147 seqHideAnnotationsMenu.setText(MessageManager
1148 .getString("label.hide_annotations"));
1149 groupShowAnnotationsMenu.setText(MessageManager
1150 .getString("label.show_annotations"));
1151 groupHideAnnotationsMenu.setText(MessageManager
1152 .getString("label.hide_annotations"));
1153 sequenceFeature.setText(MessageManager
1154 .getString("label.create_sequence_feature"));
1155 sequenceFeature.addActionListener(new ActionListener()
1158 public void actionPerformed(ActionEvent e)
1160 sequenceFeature_actionPerformed();
1163 jMenu1.setText(MessageManager.getString("label.group"));
1164 pdbStructureDialog.setText(MessageManager
1165 .getString("label.show_pdbstruct_dialog"));
1166 pdbStructureDialog.addActionListener(new ActionListener()
1169 public void actionPerformed(ActionEvent actionEvent)
1171 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1172 if (ap.av.getSelectionGroup() != null)
1174 selectedSeqs = ap.av.getSequenceSelection();
1176 new StructureChooser(selectedSeqs, sequence, ap);
1180 rnaStructureMenu.setText(MessageManager
1181 .getString("label.view_rna_structure"));
1183 // colStructureMenu.setText("Colour By Structure");
1184 editSequence.setText(MessageManager.getString("label.edit_sequence")
1186 editSequence.addActionListener(new ActionListener()
1189 public void actionPerformed(ActionEvent actionEvent)
1191 editSequence_actionPerformed(actionEvent);
1194 makeReferenceSeq.setText(MessageManager
1195 .getString("label.mark_as_representative"));
1196 makeReferenceSeq.addActionListener(new ActionListener()
1200 public void actionPerformed(ActionEvent actionEvent)
1202 makeReferenceSeq_actionPerformed(actionEvent);
1206 hideInsertions.setText(MessageManager
1207 .getString("label.hide_insertions"));
1208 hideInsertions.addActionListener(new ActionListener()
1212 public void actionPerformed(ActionEvent e)
1214 hideInsertions_actionPerformed(e);
1218 * annotationMenuItem.setText("By Annotation");
1219 * annotationMenuItem.addActionListener(new ActionListener() { public void
1220 * actionPerformed(ActionEvent actionEvent) {
1221 * annotationMenuItem_actionPerformed(actionEvent); } });
1223 groupMenu.add(sequenceSelDetails);
1226 add(rnaStructureMenu);
1227 add(pdbStructureDialog);
1228 if (sequence != null)
1230 add(hideInsertions);
1232 // annotations configuration panel suppressed for now
1233 // groupMenu.add(chooseAnnotations);
1236 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1237 * (if a selection group is in force).
1239 sequenceMenu.add(seqShowAnnotationsMenu);
1240 sequenceMenu.add(seqHideAnnotationsMenu);
1241 sequenceMenu.add(seqAddReferenceAnnotations);
1242 groupMenu.add(groupShowAnnotationsMenu);
1243 groupMenu.add(groupHideAnnotationsMenu);
1244 groupMenu.add(groupAddReferenceAnnotations);
1245 groupMenu.add(editMenu);
1246 groupMenu.add(outputMenu);
1247 groupMenu.add(sequenceFeature);
1248 groupMenu.add(createGroupMenuItem);
1249 groupMenu.add(unGroupMenuItem);
1250 groupMenu.add(jMenu1);
1251 sequenceMenu.add(sequenceName);
1252 sequenceMenu.add(sequenceDetails);
1253 sequenceMenu.add(makeReferenceSeq);
1259 editMenu.add(editSequence);
1260 editMenu.add(upperCase);
1261 editMenu.add(lowerCase);
1262 editMenu.add(toggle);
1263 // JBPNote: These shouldn't be added here - should appear in a generic
1264 // 'apply web service to this sequence menu'
1265 // pdbMenu.add(RNAFold);
1266 // pdbMenu.add(ContraFold);
1267 jMenu1.add(groupName);
1268 jMenu1.add(colourMenu);
1269 jMenu1.add(showBoxes);
1270 jMenu1.add(showText);
1271 jMenu1.add(showColourText);
1272 jMenu1.add(outline);
1273 jMenu1.add(displayNonconserved);
1279 * Constructs the entries for the colour menu
1281 protected void initColourMenu()
1283 colourMenu.setText(MessageManager.getString("label.group_colour"));
1284 textColour.setText(MessageManager.getString("label.text_colour"));
1285 textColour.addActionListener(new ActionListener()
1288 public void actionPerformed(ActionEvent e)
1290 textColour_actionPerformed();
1293 noColourmenuItem.setText(MessageManager.getString("label.none"));
1294 noColourmenuItem.addActionListener(new ActionListener()
1297 public void actionPerformed(ActionEvent e)
1299 noColourmenuItem_actionPerformed();
1303 clustalColour.setText(MessageManager.getString("label.clustalx"));
1304 clustalColour.setName(JalviewColourScheme.Clustal.toString());
1305 clustalColour.addActionListener(new ActionListener()
1308 public void actionPerformed(ActionEvent e)
1310 clustalColour_actionPerformed();
1313 zappoColour.setText(MessageManager.getString("label.zappo"));
1314 zappoColour.setName(JalviewColourScheme.Zappo.toString());
1315 zappoColour.addActionListener(new ActionListener()
1318 public void actionPerformed(ActionEvent e)
1320 zappoColour_actionPerformed();
1323 taylorColour.setText(MessageManager.getString("label.taylor"));
1324 taylorColour.setName(JalviewColourScheme.Taylor.toString());
1325 taylorColour.addActionListener(new ActionListener()
1328 public void actionPerformed(ActionEvent e)
1330 taylorColour_actionPerformed();
1333 hydrophobicityColour.setText(MessageManager
1334 .getString("label.hydrophobicity"));
1335 hydrophobicityColour
1336 .setName(JalviewColourScheme.Hydrophobic.toString());
1337 hydrophobicityColour.addActionListener(new ActionListener()
1340 public void actionPerformed(ActionEvent e)
1342 hydrophobicityColour_actionPerformed();
1345 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1346 helixColour.setName(JalviewColourScheme.Helix.toString());
1347 helixColour.addActionListener(new ActionListener()
1350 public void actionPerformed(ActionEvent e)
1352 helixColour_actionPerformed();
1355 strandColour.setText(MessageManager
1356 .getString("label.strand_propensity"));
1357 strandColour.setName(JalviewColourScheme.Strand.toString());
1358 strandColour.addActionListener(new ActionListener()
1361 public void actionPerformed(ActionEvent e)
1363 strandColour_actionPerformed();
1366 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1367 turnColour.setName(JalviewColourScheme.Turn.toString());
1368 turnColour.addActionListener(new ActionListener()
1371 public void actionPerformed(ActionEvent e)
1373 turnColour_actionPerformed();
1376 buriedColour.setText(MessageManager.getString("label.buried_index"));
1377 buriedColour.setName(JalviewColourScheme.Buried.toString());
1378 buriedColour.addActionListener(new ActionListener()
1381 public void actionPerformed(ActionEvent e)
1383 buriedColour_actionPerformed();
1386 abovePIDColour.setText(MessageManager
1387 .getString("label.above_identity_threshold"));
1388 abovePIDColour.addActionListener(new ActionListener()
1391 public void actionPerformed(ActionEvent e)
1393 abovePIDColour_actionPerformed();
1396 userDefinedColour.setText(MessageManager
1397 .getString("action.user_defined"));
1398 userDefinedColour.setName(JalviewColourScheme.UserDefined.toString());
1399 userDefinedColour.addActionListener(new ActionListener()
1402 public void actionPerformed(ActionEvent e)
1404 userDefinedColour_actionPerformed(e);
1408 .setText(MessageManager.getString("label.percentage_identity"));
1409 PIDColour.setName(JalviewColourScheme.PID.toString());
1410 PIDColour.addActionListener(new ActionListener()
1413 public void actionPerformed(ActionEvent e)
1415 PIDColour_actionPerformed();
1419 .setText(MessageManager.getString("label.blosum62_score"));
1420 BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1421 BLOSUM62Colour.addActionListener(new ActionListener()
1424 public void actionPerformed(ActionEvent e)
1426 BLOSUM62Colour_actionPerformed();
1429 nucleotideColour.setText(MessageManager.getString("label.nucleotide"));
1430 nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1431 nucleotideColour.addActionListener(new ActionListener()
1434 public void actionPerformed(ActionEvent e)
1436 nucleotideMenuItem_actionPerformed();
1439 purinePyrimidineColour.setText(MessageManager
1440 .getString("label.purine_pyrimidine"));
1441 purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
1443 purinePyrimidineColour.addActionListener(new ActionListener()
1446 public void actionPerformed(ActionEvent e)
1448 purinePyrimidineColour_actionPerformed();
1452 tcoffeeColour.setText(MessageManager.getString("label.tcoffee_scores"));
1453 tcoffeeColour.setName(JalviewColourScheme.TCoffee.toString());
1454 tcoffeeColour.addActionListener(new ActionListener()
1457 public void actionPerformed(ActionEvent e)
1459 tcoffeeColorScheme_actionPerformed();
1464 * covariationColour.addActionListener(new ActionListener() {
1465 * public void actionPerformed(ActionEvent e) {
1466 * covariationColour_actionPerformed(); } });
1469 conservationMenuItem.setText(MessageManager
1470 .getString("action.by_conservation"));
1471 conservationMenuItem.addActionListener(new ActionListener()
1474 public void actionPerformed(ActionEvent e)
1476 conservationMenuItem_actionPerformed();
1482 * Builds the group colour sub-menu, including any user-defined colours which
1483 * were loaded at startup or during the Jalview session
1485 protected void buildColourMenu()
1487 SequenceGroup sg = getGroup();
1488 colourMenu.removeAll();
1489 colourMenu.add(textColour);
1490 colourMenu.addSeparator();
1491 colourMenu.add(noColourmenuItem);
1492 colourMenu.add(clustalColour);
1493 // in Java 8, isApplicableTo can be a static method on the interface
1494 clustalColour.setEnabled(new ClustalxColourScheme(sg, null)
1495 .isApplicableTo(sg));
1496 colourMenu.add(BLOSUM62Colour);
1498 .setEnabled(new Blosum62ColourScheme().isApplicableTo(sg));
1499 colourMenu.add(PIDColour);
1500 PIDColour.setEnabled(new PIDColourScheme().isApplicableTo(sg));
1501 colourMenu.add(zappoColour);
1502 zappoColour.setEnabled(new ZappoColourScheme().isApplicableTo(sg));
1503 colourMenu.add(taylorColour);
1504 taylorColour.setEnabled(new TaylorColourScheme().isApplicableTo(sg));
1505 colourMenu.add(hydrophobicityColour);
1506 hydrophobicityColour.setEnabled(new HydrophobicColourScheme()
1507 .isApplicableTo(sg));
1508 colourMenu.add(helixColour);
1509 helixColour.setEnabled(new HelixColourScheme().isApplicableTo(sg));
1510 colourMenu.add(strandColour);
1511 strandColour.setEnabled(new StrandColourScheme().isApplicableTo(sg));
1512 colourMenu.add(turnColour);
1513 turnColour.setEnabled(new TurnColourScheme().isApplicableTo(sg));
1514 colourMenu.add(buriedColour);
1515 buriedColour.setEnabled(new BuriedColourScheme().isApplicableTo(sg));
1516 colourMenu.add(nucleotideColour);
1517 nucleotideColour.setEnabled(new NucleotideColourScheme()
1518 .isApplicableTo(sg));
1519 colourMenu.add(purinePyrimidineColour);
1520 purinePyrimidineColour.setEnabled(new PurinePyrimidineColourScheme()
1521 .isApplicableTo(sg));
1522 colourMenu.add(tcoffeeColour);
1524 .setEnabled(new TCoffeeColourScheme(sg).isApplicableTo(sg));
1527 * add some of these items to a ButtonGroup so their
1528 * selection is mutually exclusive
1530 ButtonGroup colours = new ButtonGroup();
1533 * add any user-defined colours loaded on startup or
1534 * during the application session
1536 SortedMap<String, UserColourScheme> userColourSchemes = UserDefinedColours
1537 .getUserColourSchemes();
1538 if (userColourSchemes != null)
1540 for (String userColour : userColourSchemes.keySet())
1542 JRadioButtonMenuItem item = new JRadioButtonMenuItem(userColour);
1543 item.setName(userColour); // button name identifies selected colour
1544 item.addActionListener(new ActionListener()
1547 public void actionPerformed(ActionEvent evt)
1549 userDefinedColour_actionPerformed(evt);
1552 colourMenu.add(item);
1556 colourMenu.add(userDefinedColour);
1558 colourMenu.addSeparator();
1559 colourMenu.add(conservationMenuItem);
1560 colourMenu.add(abovePIDColour);
1562 colours.add(noColourmenuItem);
1563 colours.add(clustalColour);
1564 colours.add(BLOSUM62Colour);
1565 colours.add(PIDColour);
1566 colours.add(zappoColour);
1567 colours.add(taylorColour);
1568 colours.add(hydrophobicityColour);
1569 colours.add(helixColour);
1570 colours.add(strandColour);
1571 colours.add(turnColour);
1572 colours.add(buriedColour);
1573 colours.add(purinePyrimidineColour);
1574 colours.add(tcoffeeColour);
1575 colours.add(nucleotideColour);
1576 colours.add(userDefinedColour);
1577 colours.add(abovePIDColour);
1578 // colours.add(RNAInteractionColour);
1583 * Check for any annotations on the underlying dataset sequences (for the
1584 * current selection group) which are not 'on the alignment'.If any are found,
1585 * enable the option to add them to the alignment. The criteria for 'on the
1586 * alignment' is finding an alignment annotation on the alignment, matched on
1587 * calcId, label and sequenceRef.
1589 * A tooltip is also constructed that displays the source (calcId) and type
1590 * (label) of the annotations that can be added.
1593 * @param forSequences
1595 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1596 List<SequenceI> forSequences)
1598 menuItem.setEnabled(false);
1601 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1602 * Using TreeMap means calcIds are shown in alphabetical order.
1604 SortedMap<String, String> tipEntries = new TreeMap<String, String>();
1605 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1606 AlignmentI al = this.ap.av.getAlignment();
1607 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1608 tipEntries, candidates, al);
1609 if (!candidates.isEmpty())
1611 StringBuilder tooltip = new StringBuilder(64);
1612 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1615 * Found annotations that could be added. Enable the menu item, and
1616 * configure its tooltip and action.
1618 menuItem.setEnabled(true);
1619 for (String calcId : tipEntries.keySet())
1621 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1623 String tooltipText = JvSwingUtils.wrapTooltip(true,
1624 tooltip.toString());
1625 menuItem.setToolTipText(tooltipText);
1627 menuItem.addActionListener(new ActionListener()
1630 public void actionPerformed(ActionEvent e)
1632 addReferenceAnnotations_actionPerformed(candidates);
1639 * Add annotations to the sequences and to the alignment.
1642 * a map whose keys are sequences on the alignment, and values a list
1643 * of annotations to add to each sequence
1645 protected void addReferenceAnnotations_actionPerformed(
1646 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1648 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1649 final AlignmentI alignment = this.ap.getAlignment();
1650 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1655 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1657 if (!ap.av.getAlignment().hasSeqrep())
1659 // initialise the display flags so the user sees something happen
1660 ap.av.setDisplayReferenceSeq(true);
1661 ap.av.setColourByReferenceSeq(true);
1662 ap.av.getAlignment().setSeqrep(sequence);
1666 if (ap.av.getAlignment().getSeqrep() == sequence)
1668 ap.av.getAlignment().setSeqrep(null);
1672 ap.av.getAlignment().setSeqrep(sequence);
1678 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1680 if (sequence != null)
1682 ColumnSelection cs = ap.av.getColumnSelection();
1685 cs = new ColumnSelection();
1687 cs.hideInsertionsFor(sequence);
1688 ap.av.setColumnSelection(cs);
1693 protected void sequenceSelectionDetails_actionPerformed()
1695 createSequenceDetailsReport(ap.av.getSequenceSelection());
1698 protected void sequenceDetails_actionPerformed()
1700 createSequenceDetailsReport(new SequenceI[] { sequence });
1703 public void createSequenceDetailsReport(SequenceI[] sequences)
1705 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1706 StringBuilder contents = new StringBuilder(128);
1707 for (SequenceI seq : sequences)
1709 contents.append("<p><h2>"
1712 "label.create_sequence_details_report_annotation_for",
1713 new Object[] { seq.getDisplayId(true) })
1715 new SequenceAnnotationReport(null)
1716 .createSequenceAnnotationReport(
1721 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1722 .getSeqPanel().seqCanvas.fr.getMinMax()
1724 contents.append("</p>");
1726 cap.setText("<html>" + contents.toString() + "</html>");
1728 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1729 "label.sequence_details_for",
1730 (sequences.length == 1 ? new Object[] { sequences[0]
1731 .getDisplayId(true) } : new Object[] { MessageManager
1732 .getString("label.selection") })), 500, 400);
1736 protected void showNonconserved_actionPerformed()
1738 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1743 * call to refresh view after settings change
1747 ap.updateAnnotation();
1748 ap.paintAlignment(true);
1750 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1759 protected void clustalColour_actionPerformed()
1761 SequenceGroup sg = getGroup();
1762 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1772 protected void zappoColour_actionPerformed()
1774 getGroup().cs = new ZappoColourScheme();
1784 protected void taylorColour_actionPerformed()
1786 getGroup().cs = new TaylorColourScheme();
1796 protected void hydrophobicityColour_actionPerformed()
1798 getGroup().cs = new HydrophobicColourScheme();
1808 protected void helixColour_actionPerformed()
1810 getGroup().cs = new HelixColourScheme();
1820 protected void strandColour_actionPerformed()
1822 getGroup().cs = new StrandColourScheme();
1832 protected void turnColour_actionPerformed()
1834 getGroup().cs = new TurnColourScheme();
1844 protected void buriedColour_actionPerformed()
1846 getGroup().cs = new BuriedColourScheme();
1856 public void nucleotideMenuItem_actionPerformed()
1858 getGroup().cs = new NucleotideColourScheme();
1862 protected void purinePyrimidineColour_actionPerformed()
1864 getGroup().cs = new PurinePyrimidineColourScheme();
1868 protected void tcoffeeColorScheme_actionPerformed()
1870 getGroup().cs = new TCoffeeColourScheme(getGroup());
1875 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1876 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1884 protected void abovePIDColour_actionPerformed()
1886 SequenceGroup sg = getGroup();
1892 if (abovePIDColour.isSelected())
1894 sg.cs.setConsensus(AAFrequency.calculate(
1895 sg.getSequences(ap.av.getHiddenRepSequences()),
1896 sg.getStartRes(), sg.getEndRes() + 1));
1898 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1901 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1903 SliderPanel.showPIDSlider();
1906 // remove PIDColouring
1908 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1920 protected void userDefinedColour_actionPerformed(ActionEvent e)
1922 SequenceGroup sg = getGroup();
1924 if (e.getSource().equals(userDefinedColour))
1926 new UserDefinedColours(ap, sg);
1930 UserColourScheme udc = UserDefinedColours
1931 .getUserColourSchemes().get(e.getActionCommand());
1939 * Open a panel where the user can choose which types of sequence annotation
1944 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1946 // todo correct way to guard against opening a duplicate panel?
1947 new AnnotationChooser(ap);
1956 protected void PIDColour_actionPerformed()
1958 SequenceGroup sg = getGroup();
1959 sg.cs = new PIDColourScheme();
1960 sg.cs.setConsensus(AAFrequency.calculate(
1961 sg.getSequences(ap.av.getHiddenRepSequences()),
1962 sg.getStartRes(), sg.getEndRes() + 1));
1972 protected void BLOSUM62Colour_actionPerformed()
1974 SequenceGroup sg = getGroup();
1976 sg.cs = new Blosum62ColourScheme();
1978 sg.cs.setConsensus(AAFrequency.calculate(
1979 sg.getSequences(ap.av.getHiddenRepSequences()),
1980 sg.getStartRes(), sg.getEndRes() + 1));
1991 protected void noColourmenuItem_actionPerformed()
1993 getGroup().cs = null;
2003 protected void conservationMenuItem_actionPerformed()
2005 SequenceGroup sg = getGroup();
2011 if (conservationMenuItem.isSelected())
2013 // JBPNote: Conservation name shouldn't be i18n translated
2014 Conservation c = new Conservation("Group", sg.getSequences(ap.av
2015 .getHiddenRepSequences()), sg.getStartRes(),
2016 sg.getEndRes() + 1);
2019 c.verdict(false, ap.av.getConsPercGaps());
2021 sg.cs.setConservation(c);
2023 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2024 SliderPanel.showConservationSlider();
2027 // remove ConservationColouring
2029 sg.cs.setConservation(null);
2035 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2037 SequenceGroup sg = getGroup();
2043 AnnotationColourGradient acg = new AnnotationColourGradient(
2044 sequence.getAnnotation()[0], null,
2045 AnnotationColourGradient.NO_THRESHOLD);
2047 acg.setPredefinedColours(true);
2059 protected void groupName_actionPerformed()
2062 SequenceGroup sg = getGroup();
2063 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2064 sg.getDescription(), " "
2065 + MessageManager.getString("label.group_name") + " ",
2066 MessageManager.getString("label.group_description") + " ",
2067 MessageManager.getString("label.edit_group_name_description"),
2075 sg.setName(dialog.getName());
2076 sg.setDescription(dialog.getDescription());
2081 * Get selection group - adding it to the alignment if necessary.
2083 * @return sequence group to operate on
2085 SequenceGroup getGroup()
2087 SequenceGroup sg = ap.av.getSelectionGroup();
2088 // this method won't add a new group if it already exists
2091 ap.av.getAlignment().addGroup(sg);
2103 void sequenceName_actionPerformed()
2105 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2106 sequence.getDescription(),
2107 " " + MessageManager.getString("label.sequence_name")
2109 MessageManager.getString("label.sequence_description") + " ",
2111 .getString("label.edit_sequence_name_description"),
2119 if (dialog.getName() != null)
2121 if (dialog.getName().indexOf(" ") > -1)
2127 .getString("label.spaces_converted_to_backslashes"),
2129 .getString("label.no_spaces_allowed_sequence_name"),
2130 JvOptionPane.WARNING_MESSAGE);
2133 sequence.setName(dialog.getName().replace(' ', '_'));
2134 ap.paintAlignment(false);
2137 sequence.setDescription(dialog.getDescription());
2139 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2150 void unGroupMenuItem_actionPerformed()
2152 SequenceGroup sg = ap.av.getSelectionGroup();
2153 ap.av.getAlignment().deleteGroup(sg);
2154 ap.av.setSelectionGroup(null);
2158 void createGroupMenuItem_actionPerformed()
2160 getGroup(); // implicitly creates group - note - should apply defaults / use
2161 // standard alignment window logic for this
2171 protected void outline_actionPerformed()
2173 SequenceGroup sg = getGroup();
2174 Color col = JColorChooser.showDialog(this,
2175 MessageManager.getString("label.select_outline_colour"),
2180 sg.setOutlineColour(col);
2192 public void showBoxes_actionPerformed()
2194 getGroup().setDisplayBoxes(showBoxes.isSelected());
2204 public void showText_actionPerformed()
2206 getGroup().setDisplayText(showText.isSelected());
2216 public void showColourText_actionPerformed()
2218 getGroup().setColourText(showColourText.isSelected());
2222 public void showLink(String url)
2226 jalview.util.BrowserLauncher.openURL(url);
2227 } catch (Exception ex)
2229 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
2230 MessageManager.getString("label.web_browser_not_found_unix"),
2231 MessageManager.getString("label.web_browser_not_found"),
2232 JvOptionPane.WARNING_MESSAGE);
2234 ex.printStackTrace();
2238 void hideSequences(boolean representGroup)
2240 ap.av.hideSequences(sequence, representGroup);
2243 public void copy_actionPerformed()
2245 ap.alignFrame.copy_actionPerformed(null);
2248 public void cut_actionPerformed()
2250 ap.alignFrame.cut_actionPerformed(null);
2253 void changeCase(ActionEvent e)
2255 Object source = e.getSource();
2256 SequenceGroup sg = ap.av.getSelectionGroup();
2260 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2261 sg.getStartRes(), sg.getEndRes() + 1);
2266 if (source == toggle)
2268 description = MessageManager.getString("label.toggle_case");
2269 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2271 else if (source == upperCase)
2273 description = MessageManager.getString("label.to_upper_case");
2274 caseChange = ChangeCaseCommand.TO_UPPER;
2278 description = MessageManager.getString("label.to_lower_case");
2279 caseChange = ChangeCaseCommand.TO_LOWER;
2282 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2283 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2284 startEnd, caseChange);
2286 ap.alignFrame.addHistoryItem(caseCommand);
2288 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2294 public void outputText_actionPerformed(ActionEvent e)
2296 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2297 cap.setForInput(null);
2298 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2299 "label.alignment_output_command",
2300 new Object[] { e.getActionCommand() }), 600, 500);
2302 String[] omitHidden = null;
2304 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2305 // or we simply trust the user wants
2306 // wysiwig behaviour
2308 FileFormatI fileFormat = FileFormat.forName(e.getActionCommand());
2309 cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2312 public void sequenceFeature_actionPerformed()
2314 SequenceGroup sg = ap.av.getSelectionGroup();
2320 int rsize = 0, gSize = sg.getSize();
2321 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2322 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2324 for (int i = 0; i < gSize; i++)
2326 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2327 int end = sg.findEndRes(sg.getSequenceAt(i));
2330 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2331 features[rsize] = new SequenceFeature(null, null, null, start, end,
2336 rseqs = new SequenceI[rsize];
2337 tfeatures = new SequenceFeature[rsize];
2338 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2339 System.arraycopy(features, 0, tfeatures, 0, rsize);
2340 features = tfeatures;
2342 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2343 features, true, ap))
2345 ap.alignFrame.setShowSeqFeatures(true);
2346 ap.highlightSearchResults(null);
2350 public void textColour_actionPerformed()
2352 SequenceGroup sg = getGroup();
2355 new TextColourChooser().chooseColour(ap, sg);
2359 public void colourByStructure(String pdbid)
2361 Annotation[] anots = ap.av.getStructureSelectionManager()
2362 .colourSequenceFromStructure(sequence, pdbid);
2364 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2365 "Coloured by " + pdbid, anots);
2367 ap.av.getAlignment().addAnnotation(an);
2368 an.createSequenceMapping(sequence, 0, true);
2369 // an.adjustForAlignment();
2370 ap.av.getAlignment().setAnnotationIndex(an, 0);
2372 ap.adjustAnnotationHeight();
2374 sequence.addAlignmentAnnotation(an);
2378 public void editSequence_actionPerformed(ActionEvent actionEvent)
2380 SequenceGroup sg = ap.av.getSelectionGroup();
2384 if (sequence == null)
2386 sequence = sg.getSequenceAt(0);
2389 EditNameDialog dialog = new EditNameDialog(
2390 sequence.getSequenceAsString(sg.getStartRes(),
2391 sg.getEndRes() + 1), null,
2392 MessageManager.getString("label.edit_sequence"), null,
2393 MessageManager.getString("label.edit_sequence"),
2398 EditCommand editCommand = new EditCommand(
2399 MessageManager.getString("label.edit_sequences"),
2400 Action.REPLACE, dialog.getName().replace(' ',
2401 ap.av.getGapCharacter()),
2402 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2403 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2405 ap.alignFrame.addHistoryItem(editCommand);
2407 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2414 * Marks as selected the colour menu item matching the given name, or the
2415 * first item ('None') if no match is found
2419 protected void setColourSelected(ColourSchemeI cs)
2421 noColourmenuItem.setSelected(true);
2427 String schemeName = cs.getSchemeName();
2429 * look for a radio button with a name that matches the colour name
2430 * (note the button text may not as it may be internationalised)
2432 for (Component menuItem : colourMenu.getMenuComponents())
2434 if (menuItem instanceof JRadioButtonMenuItem)
2436 if (schemeName.equals(((JRadioButtonMenuItem) menuItem).getName()))
2438 ((JRadioButtonMenuItem) menuItem).setSelected(true);