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
1304 .getString("label.colourScheme_clustal"));
1305 clustalColour.setName(JalviewColourScheme.Clustal.toString());
1306 clustalColour.addActionListener(new ActionListener()
1309 public void actionPerformed(ActionEvent e)
1311 clustalColour_actionPerformed();
1314 zappoColour.setText(MessageManager
1315 .getString("label.colourScheme_zappo"));
1316 zappoColour.setName(JalviewColourScheme.Zappo.toString());
1317 zappoColour.addActionListener(new ActionListener()
1320 public void actionPerformed(ActionEvent e)
1322 zappoColour_actionPerformed();
1325 taylorColour.setText(MessageManager
1326 .getString("label.colourScheme_taylor"));
1327 taylorColour.setName(JalviewColourScheme.Taylor.toString());
1328 taylorColour.addActionListener(new ActionListener()
1331 public void actionPerformed(ActionEvent e)
1333 taylorColour_actionPerformed();
1336 hydrophobicityColour.setText(MessageManager
1337 .getString("label.colourScheme_hydrophobic"));
1338 hydrophobicityColour
1339 .setName(JalviewColourScheme.Hydrophobic.toString());
1340 hydrophobicityColour.addActionListener(new ActionListener()
1343 public void actionPerformed(ActionEvent e)
1345 hydrophobicityColour_actionPerformed();
1348 helixColour.setText(MessageManager
1349 .getString("label.colourScheme_helix_propensity"));
1350 helixColour.setName(JalviewColourScheme.Helix.toString());
1351 helixColour.addActionListener(new ActionListener()
1354 public void actionPerformed(ActionEvent e)
1356 helixColour_actionPerformed();
1359 strandColour.setText(MessageManager
1360 .getString("label.colourScheme_strand_propensity"));
1361 strandColour.setName(JalviewColourScheme.Strand.toString());
1362 strandColour.addActionListener(new ActionListener()
1365 public void actionPerformed(ActionEvent e)
1367 strandColour_actionPerformed();
1370 turnColour.setText(MessageManager
1371 .getString("label.colourScheme_turn_propensity"));
1372 turnColour.setName(JalviewColourScheme.Turn.toString());
1373 turnColour.addActionListener(new ActionListener()
1376 public void actionPerformed(ActionEvent e)
1378 turnColour_actionPerformed();
1381 buriedColour.setText(MessageManager
1382 .getString("label.colourScheme_buried_index"));
1383 buriedColour.setName(JalviewColourScheme.Buried.toString());
1384 buriedColour.addActionListener(new ActionListener()
1387 public void actionPerformed(ActionEvent e)
1389 buriedColour_actionPerformed();
1392 abovePIDColour.setText(MessageManager
1393 .getString("label.above_identity_threshold"));
1394 abovePIDColour.addActionListener(new ActionListener()
1397 public void actionPerformed(ActionEvent e)
1399 abovePIDColour_actionPerformed();
1402 userDefinedColour.setText(MessageManager
1403 .getString("action.user_defined"));
1404 userDefinedColour.addActionListener(new ActionListener()
1407 public void actionPerformed(ActionEvent e)
1409 userDefinedColour_actionPerformed(e);
1413 .setText(MessageManager
1414 .getString("label.colourScheme_%_identity"));
1415 PIDColour.setName(JalviewColourScheme.PID.toString());
1416 PIDColour.addActionListener(new ActionListener()
1419 public void actionPerformed(ActionEvent e)
1421 PIDColour_actionPerformed();
1425 .setText(MessageManager
1426 .getString("label.colourScheme_blosum62"));
1427 BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1428 BLOSUM62Colour.addActionListener(new ActionListener()
1431 public void actionPerformed(ActionEvent e)
1433 BLOSUM62Colour_actionPerformed();
1436 nucleotideColour.setText(MessageManager
1437 .getString("label.colourScheme_nucleotide"));
1438 nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1439 nucleotideColour.addActionListener(new ActionListener()
1442 public void actionPerformed(ActionEvent e)
1444 nucleotideMenuItem_actionPerformed();
1447 purinePyrimidineColour.setText(MessageManager
1448 .getString("label.colourScheme_purine/pyrimidine"));
1449 purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
1451 purinePyrimidineColour.addActionListener(new ActionListener()
1454 public void actionPerformed(ActionEvent e)
1456 purinePyrimidineColour_actionPerformed();
1460 tcoffeeColour.setText(MessageManager
1461 .getString("label.colourScheme_t-coffee_scores"));
1462 tcoffeeColour.setName(JalviewColourScheme.TCoffee.toString());
1463 tcoffeeColour.addActionListener(new ActionListener()
1466 public void actionPerformed(ActionEvent e)
1468 tcoffeeColorScheme_actionPerformed();
1473 * covariationColour.addActionListener(new ActionListener() {
1474 * public void actionPerformed(ActionEvent e) {
1475 * covariationColour_actionPerformed(); } });
1478 conservationMenuItem.setText(MessageManager
1479 .getString("action.by_conservation"));
1480 conservationMenuItem.addActionListener(new ActionListener()
1483 public void actionPerformed(ActionEvent e)
1485 conservationMenuItem_actionPerformed();
1491 * Builds the group colour sub-menu, including any user-defined colours which
1492 * were loaded at startup or during the Jalview session
1494 protected void buildColourMenu()
1496 SequenceGroup sg = getGroup();
1497 colourMenu.removeAll();
1498 colourMenu.add(textColour);
1499 colourMenu.addSeparator();
1500 colourMenu.add(noColourmenuItem);
1501 colourMenu.add(clustalColour);
1502 // in Java 8, isApplicableTo can be a static method on the interface
1503 clustalColour.setEnabled(new ClustalxColourScheme(sg, null)
1504 .isApplicableTo(sg));
1505 colourMenu.add(BLOSUM62Colour);
1507 .setEnabled(new Blosum62ColourScheme().isApplicableTo(sg));
1508 colourMenu.add(PIDColour);
1509 PIDColour.setEnabled(new PIDColourScheme().isApplicableTo(sg));
1510 colourMenu.add(zappoColour);
1511 zappoColour.setEnabled(new ZappoColourScheme().isApplicableTo(sg));
1512 colourMenu.add(taylorColour);
1513 taylorColour.setEnabled(new TaylorColourScheme().isApplicableTo(sg));
1514 colourMenu.add(hydrophobicityColour);
1515 hydrophobicityColour.setEnabled(new HydrophobicColourScheme()
1516 .isApplicableTo(sg));
1517 colourMenu.add(helixColour);
1518 helixColour.setEnabled(new HelixColourScheme().isApplicableTo(sg));
1519 colourMenu.add(strandColour);
1520 strandColour.setEnabled(new StrandColourScheme().isApplicableTo(sg));
1521 colourMenu.add(turnColour);
1522 turnColour.setEnabled(new TurnColourScheme().isApplicableTo(sg));
1523 colourMenu.add(buriedColour);
1524 buriedColour.setEnabled(new BuriedColourScheme().isApplicableTo(sg));
1525 colourMenu.add(nucleotideColour);
1526 nucleotideColour.setEnabled(new NucleotideColourScheme()
1527 .isApplicableTo(sg));
1528 colourMenu.add(purinePyrimidineColour);
1529 purinePyrimidineColour.setEnabled(new PurinePyrimidineColourScheme()
1530 .isApplicableTo(sg));
1531 colourMenu.add(tcoffeeColour);
1533 .setEnabled(new TCoffeeColourScheme(sg).isApplicableTo(sg));
1536 * add some of these items to a ButtonGroup so their
1537 * selection is mutually exclusive
1539 ButtonGroup colours = new ButtonGroup();
1542 * add any user-defined colours loaded on startup or
1543 * during the application session
1545 SortedMap<String, UserColourScheme> userColourSchemes = UserDefinedColours
1546 .getUserColourSchemes();
1547 if (userColourSchemes != null)
1549 for (String userColour : userColourSchemes.keySet())
1551 JRadioButtonMenuItem item = new JRadioButtonMenuItem(userColour);
1552 item.setName(userColour); // button name identifies selected colour
1553 item.addActionListener(new ActionListener()
1556 public void actionPerformed(ActionEvent evt)
1558 userDefinedColour_actionPerformed(evt);
1561 colourMenu.add(item);
1565 colourMenu.add(userDefinedColour);
1567 colourMenu.addSeparator();
1568 colourMenu.add(conservationMenuItem);
1569 colourMenu.add(abovePIDColour);
1571 colours.add(noColourmenuItem);
1572 colours.add(clustalColour);
1573 colours.add(BLOSUM62Colour);
1574 colours.add(PIDColour);
1575 colours.add(zappoColour);
1576 colours.add(taylorColour);
1577 colours.add(hydrophobicityColour);
1578 colours.add(helixColour);
1579 colours.add(strandColour);
1580 colours.add(turnColour);
1581 colours.add(buriedColour);
1582 colours.add(purinePyrimidineColour);
1583 colours.add(tcoffeeColour);
1584 colours.add(nucleotideColour);
1585 colours.add(userDefinedColour);
1586 colours.add(abovePIDColour);
1587 // colours.add(RNAInteractionColour);
1592 * Check for any annotations on the underlying dataset sequences (for the
1593 * current selection group) which are not 'on the alignment'.If any are found,
1594 * enable the option to add them to the alignment. The criteria for 'on the
1595 * alignment' is finding an alignment annotation on the alignment, matched on
1596 * calcId, label and sequenceRef.
1598 * A tooltip is also constructed that displays the source (calcId) and type
1599 * (label) of the annotations that can be added.
1602 * @param forSequences
1604 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1605 List<SequenceI> forSequences)
1607 menuItem.setEnabled(false);
1610 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1611 * Using TreeMap means calcIds are shown in alphabetical order.
1613 SortedMap<String, String> tipEntries = new TreeMap<String, String>();
1614 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1615 AlignmentI al = this.ap.av.getAlignment();
1616 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1617 tipEntries, candidates, al);
1618 if (!candidates.isEmpty())
1620 StringBuilder tooltip = new StringBuilder(64);
1621 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1624 * Found annotations that could be added. Enable the menu item, and
1625 * configure its tooltip and action.
1627 menuItem.setEnabled(true);
1628 for (String calcId : tipEntries.keySet())
1630 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1632 String tooltipText = JvSwingUtils.wrapTooltip(true,
1633 tooltip.toString());
1634 menuItem.setToolTipText(tooltipText);
1636 menuItem.addActionListener(new ActionListener()
1639 public void actionPerformed(ActionEvent e)
1641 addReferenceAnnotations_actionPerformed(candidates);
1648 * Add annotations to the sequences and to the alignment.
1651 * a map whose keys are sequences on the alignment, and values a list
1652 * of annotations to add to each sequence
1654 protected void addReferenceAnnotations_actionPerformed(
1655 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1657 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1658 final AlignmentI alignment = this.ap.getAlignment();
1659 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1664 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1666 if (!ap.av.getAlignment().hasSeqrep())
1668 // initialise the display flags so the user sees something happen
1669 ap.av.setDisplayReferenceSeq(true);
1670 ap.av.setColourByReferenceSeq(true);
1671 ap.av.getAlignment().setSeqrep(sequence);
1675 if (ap.av.getAlignment().getSeqrep() == sequence)
1677 ap.av.getAlignment().setSeqrep(null);
1681 ap.av.getAlignment().setSeqrep(sequence);
1687 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1689 if (sequence != null)
1691 ColumnSelection cs = ap.av.getColumnSelection();
1694 cs = new ColumnSelection();
1696 cs.hideInsertionsFor(sequence);
1697 ap.av.setColumnSelection(cs);
1702 protected void sequenceSelectionDetails_actionPerformed()
1704 createSequenceDetailsReport(ap.av.getSequenceSelection());
1707 protected void sequenceDetails_actionPerformed()
1709 createSequenceDetailsReport(new SequenceI[] { sequence });
1712 public void createSequenceDetailsReport(SequenceI[] sequences)
1714 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1715 StringBuilder contents = new StringBuilder(128);
1716 for (SequenceI seq : sequences)
1718 contents.append("<p><h2>"
1721 "label.create_sequence_details_report_annotation_for",
1722 new Object[] { seq.getDisplayId(true) })
1724 new SequenceAnnotationReport(null)
1725 .createSequenceAnnotationReport(
1730 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1731 .getSeqPanel().seqCanvas.fr.getMinMax()
1733 contents.append("</p>");
1735 cap.setText("<html>" + contents.toString() + "</html>");
1737 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1738 "label.sequence_details_for",
1739 (sequences.length == 1 ? new Object[] { sequences[0]
1740 .getDisplayId(true) } : new Object[] { MessageManager
1741 .getString("label.selection") })), 500, 400);
1745 protected void showNonconserved_actionPerformed()
1747 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1752 * call to refresh view after settings change
1756 ap.updateAnnotation();
1757 ap.paintAlignment(true);
1759 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1768 protected void clustalColour_actionPerformed()
1770 SequenceGroup sg = getGroup();
1771 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1781 protected void zappoColour_actionPerformed()
1783 getGroup().cs = new ZappoColourScheme();
1793 protected void taylorColour_actionPerformed()
1795 getGroup().cs = new TaylorColourScheme();
1805 protected void hydrophobicityColour_actionPerformed()
1807 getGroup().cs = new HydrophobicColourScheme();
1817 protected void helixColour_actionPerformed()
1819 getGroup().cs = new HelixColourScheme();
1829 protected void strandColour_actionPerformed()
1831 getGroup().cs = new StrandColourScheme();
1841 protected void turnColour_actionPerformed()
1843 getGroup().cs = new TurnColourScheme();
1853 protected void buriedColour_actionPerformed()
1855 getGroup().cs = new BuriedColourScheme();
1865 public void nucleotideMenuItem_actionPerformed()
1867 getGroup().cs = new NucleotideColourScheme();
1871 protected void purinePyrimidineColour_actionPerformed()
1873 getGroup().cs = new PurinePyrimidineColourScheme();
1877 protected void tcoffeeColorScheme_actionPerformed()
1879 getGroup().cs = new TCoffeeColourScheme(getGroup());
1884 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1885 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1893 protected void abovePIDColour_actionPerformed()
1895 SequenceGroup sg = getGroup();
1901 if (abovePIDColour.isSelected())
1903 sg.cs.setConsensus(AAFrequency.calculate(
1904 sg.getSequences(ap.av.getHiddenRepSequences()),
1905 sg.getStartRes(), sg.getEndRes() + 1));
1907 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1910 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1912 SliderPanel.showPIDSlider();
1915 // remove PIDColouring
1917 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1929 protected void userDefinedColour_actionPerformed(ActionEvent e)
1931 SequenceGroup sg = getGroup();
1933 if (e.getSource().equals(userDefinedColour))
1935 new UserDefinedColours(ap, sg);
1939 UserColourScheme udc = UserDefinedColours
1940 .getUserColourSchemes().get(e.getActionCommand());
1948 * Open a panel where the user can choose which types of sequence annotation
1953 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1955 // todo correct way to guard against opening a duplicate panel?
1956 new AnnotationChooser(ap);
1965 protected void PIDColour_actionPerformed()
1967 SequenceGroup sg = getGroup();
1968 sg.cs = new PIDColourScheme();
1969 sg.cs.setConsensus(AAFrequency.calculate(
1970 sg.getSequences(ap.av.getHiddenRepSequences()),
1971 sg.getStartRes(), sg.getEndRes() + 1));
1981 protected void BLOSUM62Colour_actionPerformed()
1983 SequenceGroup sg = getGroup();
1985 sg.cs = new Blosum62ColourScheme();
1987 sg.cs.setConsensus(AAFrequency.calculate(
1988 sg.getSequences(ap.av.getHiddenRepSequences()),
1989 sg.getStartRes(), sg.getEndRes() + 1));
2000 protected void noColourmenuItem_actionPerformed()
2002 getGroup().cs = null;
2012 protected void conservationMenuItem_actionPerformed()
2014 SequenceGroup sg = getGroup();
2020 if (conservationMenuItem.isSelected())
2022 // JBPNote: Conservation name shouldn't be i18n translated
2023 Conservation c = new Conservation("Group", sg.getSequences(ap.av
2024 .getHiddenRepSequences()), sg.getStartRes(),
2025 sg.getEndRes() + 1);
2028 c.verdict(false, ap.av.getConsPercGaps());
2030 sg.cs.setConservation(c);
2032 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2033 SliderPanel.showConservationSlider();
2036 // remove ConservationColouring
2038 sg.cs.setConservation(null);
2044 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2046 SequenceGroup sg = getGroup();
2052 AnnotationColourGradient acg = new AnnotationColourGradient(
2053 sequence.getAnnotation()[0], null,
2054 AnnotationColourGradient.NO_THRESHOLD);
2056 acg.setPredefinedColours(true);
2068 protected void groupName_actionPerformed()
2071 SequenceGroup sg = getGroup();
2072 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2073 sg.getDescription(), " "
2074 + MessageManager.getString("label.group_name") + " ",
2075 MessageManager.getString("label.group_description") + " ",
2076 MessageManager.getString("label.edit_group_name_description"),
2084 sg.setName(dialog.getName());
2085 sg.setDescription(dialog.getDescription());
2090 * Get selection group - adding it to the alignment if necessary.
2092 * @return sequence group to operate on
2094 SequenceGroup getGroup()
2096 SequenceGroup sg = ap.av.getSelectionGroup();
2097 // this method won't add a new group if it already exists
2100 ap.av.getAlignment().addGroup(sg);
2112 void sequenceName_actionPerformed()
2114 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2115 sequence.getDescription(),
2116 " " + MessageManager.getString("label.sequence_name")
2118 MessageManager.getString("label.sequence_description") + " ",
2120 .getString("label.edit_sequence_name_description"),
2128 if (dialog.getName() != null)
2130 if (dialog.getName().indexOf(" ") > -1)
2136 .getString("label.spaces_converted_to_backslashes"),
2138 .getString("label.no_spaces_allowed_sequence_name"),
2139 JvOptionPane.WARNING_MESSAGE);
2142 sequence.setName(dialog.getName().replace(' ', '_'));
2143 ap.paintAlignment(false);
2146 sequence.setDescription(dialog.getDescription());
2148 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2159 void unGroupMenuItem_actionPerformed()
2161 SequenceGroup sg = ap.av.getSelectionGroup();
2162 ap.av.getAlignment().deleteGroup(sg);
2163 ap.av.setSelectionGroup(null);
2167 void createGroupMenuItem_actionPerformed()
2169 getGroup(); // implicitly creates group - note - should apply defaults / use
2170 // standard alignment window logic for this
2180 protected void outline_actionPerformed()
2182 SequenceGroup sg = getGroup();
2183 Color col = JColorChooser.showDialog(this,
2184 MessageManager.getString("label.select_outline_colour"),
2189 sg.setOutlineColour(col);
2201 public void showBoxes_actionPerformed()
2203 getGroup().setDisplayBoxes(showBoxes.isSelected());
2213 public void showText_actionPerformed()
2215 getGroup().setDisplayText(showText.isSelected());
2225 public void showColourText_actionPerformed()
2227 getGroup().setColourText(showColourText.isSelected());
2231 public void showLink(String url)
2235 jalview.util.BrowserLauncher.openURL(url);
2236 } catch (Exception ex)
2238 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
2239 MessageManager.getString("label.web_browser_not_found_unix"),
2240 MessageManager.getString("label.web_browser_not_found"),
2241 JvOptionPane.WARNING_MESSAGE);
2243 ex.printStackTrace();
2247 void hideSequences(boolean representGroup)
2249 ap.av.hideSequences(sequence, representGroup);
2252 public void copy_actionPerformed()
2254 ap.alignFrame.copy_actionPerformed(null);
2257 public void cut_actionPerformed()
2259 ap.alignFrame.cut_actionPerformed(null);
2262 void changeCase(ActionEvent e)
2264 Object source = e.getSource();
2265 SequenceGroup sg = ap.av.getSelectionGroup();
2269 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2270 sg.getStartRes(), sg.getEndRes() + 1);
2275 if (source == toggle)
2277 description = MessageManager.getString("label.toggle_case");
2278 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2280 else if (source == upperCase)
2282 description = MessageManager.getString("label.to_upper_case");
2283 caseChange = ChangeCaseCommand.TO_UPPER;
2287 description = MessageManager.getString("label.to_lower_case");
2288 caseChange = ChangeCaseCommand.TO_LOWER;
2291 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2292 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2293 startEnd, caseChange);
2295 ap.alignFrame.addHistoryItem(caseCommand);
2297 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2303 public void outputText_actionPerformed(ActionEvent e)
2305 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2306 cap.setForInput(null);
2307 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2308 "label.alignment_output_command",
2309 new Object[] { e.getActionCommand() }), 600, 500);
2311 String[] omitHidden = null;
2313 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2314 // or we simply trust the user wants
2315 // wysiwig behaviour
2317 FileFormatI fileFormat = FileFormat.forName(e.getActionCommand());
2318 cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2321 public void sequenceFeature_actionPerformed()
2323 SequenceGroup sg = ap.av.getSelectionGroup();
2329 int rsize = 0, gSize = sg.getSize();
2330 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2331 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2333 for (int i = 0; i < gSize; i++)
2335 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2336 int end = sg.findEndRes(sg.getSequenceAt(i));
2339 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2340 features[rsize] = new SequenceFeature(null, null, null, start, end,
2345 rseqs = new SequenceI[rsize];
2346 tfeatures = new SequenceFeature[rsize];
2347 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2348 System.arraycopy(features, 0, tfeatures, 0, rsize);
2349 features = tfeatures;
2351 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2352 features, true, ap))
2354 ap.alignFrame.setShowSeqFeatures(true);
2355 ap.highlightSearchResults(null);
2359 public void textColour_actionPerformed()
2361 SequenceGroup sg = getGroup();
2364 new TextColourChooser().chooseColour(ap, sg);
2368 public void colourByStructure(String pdbid)
2370 Annotation[] anots = ap.av.getStructureSelectionManager()
2371 .colourSequenceFromStructure(sequence, pdbid);
2373 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2374 "Coloured by " + pdbid, anots);
2376 ap.av.getAlignment().addAnnotation(an);
2377 an.createSequenceMapping(sequence, 0, true);
2378 // an.adjustForAlignment();
2379 ap.av.getAlignment().setAnnotationIndex(an, 0);
2381 ap.adjustAnnotationHeight();
2383 sequence.addAlignmentAnnotation(an);
2387 public void editSequence_actionPerformed(ActionEvent actionEvent)
2389 SequenceGroup sg = ap.av.getSelectionGroup();
2393 if (sequence == null)
2395 sequence = sg.getSequenceAt(0);
2398 EditNameDialog dialog = new EditNameDialog(
2399 sequence.getSequenceAsString(sg.getStartRes(),
2400 sg.getEndRes() + 1), null,
2401 MessageManager.getString("label.edit_sequence"), null,
2402 MessageManager.getString("label.edit_sequence"),
2407 EditCommand editCommand = new EditCommand(
2408 MessageManager.getString("label.edit_sequences"),
2409 Action.REPLACE, dialog.getName().replace(' ',
2410 ap.av.getGapCharacter()),
2411 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2412 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2414 ap.alignFrame.addHistoryItem(editCommand);
2416 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2423 * Marks as selected the colour menu item matching the given name, or the
2424 * first item ('None') if no match is found
2428 protected void setColourSelected(ColourSchemeI cs)
2430 noColourmenuItem.setSelected(true);
2436 String schemeName = cs.getSchemeName();
2438 * look for a radio button with a name that matches the colour name
2439 * (note the button text may not as it may be internationalised)
2441 for (Component menuItem : colourMenu.getMenuComponents())
2443 if (menuItem instanceof JRadioButtonMenuItem)
2445 if (schemeName.equals(((JRadioButtonMenuItem) menuItem).getName()))
2447 ((JRadioButtonMenuItem) menuItem).setSelected(true);