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.HelixColourScheme;
50 import jalview.schemes.HydrophobicColourScheme;
51 import jalview.schemes.NucleotideColourScheme;
52 import jalview.schemes.PIDColourScheme;
53 import jalview.schemes.PurinePyrimidineColourScheme;
54 import jalview.schemes.StrandColourScheme;
55 import jalview.schemes.TCoffeeColourScheme;
56 import jalview.schemes.TaylorColourScheme;
57 import jalview.schemes.TurnColourScheme;
58 import jalview.schemes.UserColourScheme;
59 import jalview.schemes.ZappoColourScheme;
60 import jalview.util.GroupUrlLink;
61 import jalview.util.GroupUrlLink.UrlStringTooLongException;
62 import jalview.util.MessageManager;
63 import jalview.util.UrlLink;
65 import java.awt.Color;
66 import java.awt.event.ActionEvent;
67 import java.awt.event.ActionListener;
68 import java.util.Arrays;
69 import java.util.Collection;
70 import java.util.Collections;
71 import java.util.Hashtable;
72 import java.util.LinkedHashMap;
73 import java.util.List;
75 import java.util.SortedMap;
76 import java.util.TreeMap;
77 import java.util.Vector;
79 import javax.swing.ButtonGroup;
80 import javax.swing.JCheckBoxMenuItem;
81 import javax.swing.JColorChooser;
82 import javax.swing.JMenu;
83 import javax.swing.JMenuItem;
84 import javax.swing.JPopupMenu;
85 import javax.swing.JRadioButtonMenuItem;
91 * @version $Revision: 1.118 $
93 public class PopupMenu extends JPopupMenu
95 JMenu groupMenu = new JMenu();
97 JMenuItem groupName = new JMenuItem();
99 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
101 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
103 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
105 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
107 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
109 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
111 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
113 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
115 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
117 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
119 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
121 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
123 JRadioButtonMenuItem nucleotideColour = new JRadioButtonMenuItem();
125 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
127 protected JRadioButtonMenuItem tcoffeeColour = new JRadioButtonMenuItem();
129 // protected JRadioButtonMenuItem RNAInteractionColour;
131 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
133 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
137 JMenu sequenceMenu = new JMenu();
139 JMenuItem sequenceName = new JMenuItem();
141 JMenuItem sequenceDetails = new JMenuItem();
143 JMenuItem sequenceSelDetails = new JMenuItem();
145 JMenuItem makeReferenceSeq = new JMenuItem();
147 JMenuItem chooseAnnotations = new JMenuItem();
151 JMenuItem createGroupMenuItem = new JMenuItem();
153 JMenuItem unGroupMenuItem = new JMenuItem();
155 JMenuItem outline = new JMenuItem();
157 JMenu colourMenu = new JMenu();
159 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
161 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
163 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
165 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
167 JMenu editMenu = new JMenu();
169 JMenuItem cut = new JMenuItem();
171 JMenuItem copy = new JMenuItem();
173 JMenuItem upperCase = new JMenuItem();
175 JMenuItem lowerCase = new JMenuItem();
177 JMenuItem toggle = new JMenuItem();
179 JMenu pdbMenu = new JMenu();
181 JMenu outputMenu = new JMenu();
183 JMenu seqShowAnnotationsMenu = new JMenu();
185 JMenu seqHideAnnotationsMenu = new JMenu();
187 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
188 MessageManager.getString("label.add_reference_annotations"));
190 JMenu groupShowAnnotationsMenu = new JMenu();
192 JMenu groupHideAnnotationsMenu = new JMenu();
194 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
195 MessageManager.getString("label.add_reference_annotations"));
197 JMenuItem sequenceFeature = new JMenuItem();
199 JMenuItem textColour = new JMenuItem();
201 JMenu jMenu1 = new JMenu();
203 JMenuItem pdbStructureDialog = new JMenuItem();
205 JMenu rnaStructureMenu = new JMenu();
207 JMenuItem editSequence = new JMenuItem();
209 JMenu groupLinksMenu;
211 JMenuItem hideInsertions = new JMenuItem();
214 * Creates a new PopupMenu object.
221 public PopupMenu(final AlignmentPanel ap, Sequence seq, List<String> links)
223 this(ap, seq, links, null);
233 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
234 List<String> links, List<String> groupLinks)
236 // /////////////////////////////////////////////////////////
237 // If this is activated from the sequence panel, the user may want to
238 // edit or annotate a particular residue. Therefore display the residue menu
240 // If from the IDPanel, we must display the sequence menu
241 // ////////////////////////////////////////////////////////
245 for (String ff : FileFormat.getWritableFormats(true))
247 JMenuItem item = new JMenuItem(ff);
249 item.addActionListener(new java.awt.event.ActionListener()
252 public void actionPerformed(ActionEvent e)
254 outputText_actionPerformed(e);
258 outputMenu.add(item);
262 * Build menus for annotation types that may be shown or hidden, and for
263 * 'reference annotations' that may be added to the alignment. First for the
264 * currently selected sequence (if there is one):
266 final List<SequenceI> selectedSequence = (seq == null ? Collections
267 .<SequenceI> emptyList() : Arrays.asList(seq));
268 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
269 seqHideAnnotationsMenu, selectedSequence);
270 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
274 * And repeat for the current selection group (if there is one):
276 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
277 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
279 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
280 groupHideAnnotationsMenu, selectedGroup);
281 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
287 } catch (Exception e)
295 sequenceMenu.setText(sequence.getName());
296 if (seq == ap.av.getAlignment().getSeqrep())
298 makeReferenceSeq.setText(MessageManager
299 .getString("action.unmark_as_reference"));
303 makeReferenceSeq.setText(MessageManager
304 .getString("action.set_as_reference"));
307 if (!ap.av.getAlignment().isNucleotide())
309 remove(rnaStructureMenu);
313 int origCount = rnaStructureMenu.getItemCount();
315 * add menu items to 2D-render any alignment or sequence secondary
316 * structure annotation
318 AlignmentAnnotation[] aas = ap.av.getAlignment()
319 .getAlignmentAnnotation();
322 for (final AlignmentAnnotation aa : aas)
324 if (aa.isValidStruc() && aa.sequenceRef == null)
327 * valid alignment RNA secondary structure annotation
329 menuItem = new JMenuItem();
330 menuItem.setText(MessageManager.formatMessage(
331 "label.2d_rna_structure_line",
332 new Object[] { aa.label }));
333 menuItem.addActionListener(new java.awt.event.ActionListener()
336 public void actionPerformed(ActionEvent e)
338 new AppVarna(seq, aa, ap);
341 rnaStructureMenu.add(menuItem);
346 if (seq.getAnnotation() != null)
348 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
349 for (final AlignmentAnnotation aa : seqAnns)
351 if (aa.isValidStruc())
354 * valid sequence RNA secondary structure annotation
356 // TODO: make rnastrucF a bit more nice
357 menuItem = new JMenuItem();
358 menuItem.setText(MessageManager.formatMessage(
359 "label.2d_rna_sequence_name",
360 new Object[] { seq.getName() }));
361 menuItem.addActionListener(new java.awt.event.ActionListener()
364 public void actionPerformed(ActionEvent e)
366 // TODO: VARNA does'nt print gaps in the sequence
367 new AppVarna(seq, aa, ap);
370 rnaStructureMenu.add(menuItem);
374 if (rnaStructureMenu.getItemCount() == origCount)
376 remove(rnaStructureMenu);
380 menuItem = new JMenuItem(
381 MessageManager.getString("action.hide_sequences"));
382 menuItem.addActionListener(new java.awt.event.ActionListener()
385 public void actionPerformed(ActionEvent e)
387 hideSequences(false);
392 if (ap.av.getSelectionGroup() != null
393 && ap.av.getSelectionGroup().getSize() > 1)
395 menuItem = new JMenuItem(MessageManager.formatMessage(
396 "label.represent_group_with",
397 new Object[] { seq.getName() }));
398 menuItem.addActionListener(new java.awt.event.ActionListener()
401 public void actionPerformed(ActionEvent e)
406 sequenceMenu.add(menuItem);
409 if (ap.av.hasHiddenRows())
411 final int index = ap.av.getAlignment().findIndex(seq);
413 if (ap.av.adjustForHiddenSeqs(index)
414 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
416 menuItem = new JMenuItem(
417 MessageManager.getString("action.reveal_sequences"));
418 menuItem.addActionListener(new ActionListener()
421 public void actionPerformed(ActionEvent e)
423 ap.av.showSequence(index);
424 if (ap.overviewPanel != null)
426 ap.overviewPanel.updateOverviewImage();
434 // for the case when no sequences are even visible
435 if (ap.av.hasHiddenRows())
438 menuItem = new JMenuItem(
439 MessageManager.getString("action.reveal_all"));
440 menuItem.addActionListener(new ActionListener()
443 public void actionPerformed(ActionEvent e)
445 ap.av.showAllHiddenSeqs();
446 if (ap.overviewPanel != null)
448 ap.overviewPanel.updateOverviewImage();
458 SequenceGroup sg = ap.av.getSelectionGroup();
459 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
460 .getGroups().contains(sg) : false;
462 if (sg != null && sg.getSize() > 0)
464 groupName.setText(MessageManager
465 .getString("label.edit_name_and_description_current_group"));
467 if (sg.cs instanceof ZappoColourScheme)
469 zappoColour.setSelected(true);
471 else if (sg.cs instanceof TaylorColourScheme)
473 taylorColour.setSelected(true);
475 else if (sg.cs instanceof PIDColourScheme)
477 PIDColour.setSelected(true);
479 else if (sg.cs instanceof Blosum62ColourScheme)
481 BLOSUM62Colour.setSelected(true);
483 else if (sg.cs instanceof UserColourScheme)
485 userDefinedColour.setSelected(true);
487 else if (sg.cs instanceof HydrophobicColourScheme)
489 hydrophobicityColour.setSelected(true);
491 else if (sg.cs instanceof HelixColourScheme)
493 helixColour.setSelected(true);
495 else if (sg.cs instanceof StrandColourScheme)
497 strandColour.setSelected(true);
499 else if (sg.cs instanceof TurnColourScheme)
501 turnColour.setSelected(true);
503 else if (sg.cs instanceof BuriedColourScheme)
505 buriedColour.setSelected(true);
507 else if (sg.cs instanceof ClustalxColourScheme)
509 clustalColour.setSelected(true);
511 else if (sg.cs instanceof PurinePyrimidineColourScheme)
513 purinePyrimidineColour.setSelected(true);
515 else if (sg.cs instanceof NucleotideColourScheme)
517 nucleotideColour.setSelected(true);
521 * else if (sg.cs instanceof CovariationColourScheme) {
522 * covariationColour.setSelected(true); }
526 noColourmenuItem.setSelected(true);
529 if (sg.cs != null && sg.cs.conservationApplied())
531 conservationMenuItem.setSelected(true);
533 displayNonconserved.setSelected(sg.getShowNonconserved());
534 showText.setSelected(sg.getDisplayText());
535 showColourText.setSelected(sg.getColourText());
536 showBoxes.setSelected(sg.getDisplayBoxes());
537 // add any groupURLs to the groupURL submenu and make it visible
538 if (groupLinks != null && groupLinks.size() > 0)
540 buildGroupURLMenu(sg, groupLinks);
542 // Add a 'show all structures' for the current selection
543 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
544 SequenceI sqass = null;
545 for (SequenceI sq : ap.av.getSequenceSelection())
547 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
548 if (pes != null && pes.size() > 0)
550 reppdb.put(pes.get(0).getId(), pes.get(0));
551 for (PDBEntry pe : pes)
553 pdbe.put(pe.getId(), pe);
563 final PDBEntry[] pe = pdbe.values().toArray(
564 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
565 new PDBEntry[reppdb.size()]);
566 final JMenuItem gpdbview, rpdbview;
571 groupMenu.setVisible(false);
572 editMenu.setVisible(false);
577 createGroupMenuItem.setVisible(true);
578 unGroupMenuItem.setVisible(false);
579 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
583 createGroupMenuItem.setVisible(false);
584 unGroupMenuItem.setVisible(true);
585 jMenu1.setText(MessageManager.getString("action.edit_group"));
590 sequenceMenu.setVisible(false);
591 pdbStructureDialog.setVisible(false);
592 rnaStructureMenu.setVisible(false);
595 if (links != null && links.size() > 0)
597 addFeatureLinks(seq, links);
602 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
607 void addFeatureLinks(final SequenceI seq, List<String> links)
609 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
610 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
612 for (String link : links)
614 UrlLink urlLink = null;
617 urlLink = new UrlLink(link);
618 } catch (Exception foo)
620 Cache.log.error("Exception for URLLink '" + link + "'", foo);
624 if (!urlLink.isValid())
626 Cache.log.error(urlLink.getInvalidMessage());
630 urlLink.createLinksFromSeq(seq, linkset);
633 addshowLinks(linkMenu, linkset.values());
635 // disable link menu if there are no valid entries
636 if (linkMenu.getItemCount() > 0)
638 linkMenu.setEnabled(true);
642 linkMenu.setEnabled(false);
645 if (sequence != null)
647 sequenceMenu.add(linkMenu);
659 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
660 * "All" is added first, followed by a separator. Then add any annotation
661 * types associated with the current selection. Separate menus are built for
662 * the selected sequence group (if any), and the selected sequence.
664 * Some annotation rows are always rendered together - these can be identified
665 * by a common graphGroup property > -1. Only one of each group will be marked
666 * as visible (to avoid duplication of the display). For such groups we add a
667 * composite type name, e.g.
669 * IUPredWS (Long), IUPredWS (Short)
673 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
674 List<SequenceI> forSequences)
676 showMenu.removeAll();
677 hideMenu.removeAll();
679 final List<String> all = Arrays.asList(new String[] { MessageManager
680 .getString("label.all") });
681 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
682 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
684 showMenu.addSeparator();
685 hideMenu.addSeparator();
687 final AlignmentAnnotation[] annotations = ap.getAlignment()
688 .getAlignmentAnnotation();
691 * Find shown/hidden annotations types, distinguished by source (calcId),
692 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
693 * the insertion order, which is the order of the annotations on the
696 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
697 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
698 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
699 AlignmentAnnotationUtils.asList(annotations), forSequences);
701 for (String calcId : hiddenTypes.keySet())
703 for (List<String> type : hiddenTypes.get(calcId))
705 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
709 // grey out 'show annotations' if none are hidden
710 showMenu.setEnabled(!hiddenTypes.isEmpty());
712 for (String calcId : shownTypes.keySet())
714 for (List<String> type : shownTypes.get(calcId))
716 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
720 // grey out 'hide annotations' if none are shown
721 hideMenu.setEnabled(!shownTypes.isEmpty());
725 * Returns a list of sequences - either the current selection group (if there
726 * is one), else the specified single sequence.
731 protected List<SequenceI> getSequenceScope(SequenceI seq)
733 List<SequenceI> forSequences = null;
734 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
735 if (selectionGroup != null && selectionGroup.getSize() > 0)
737 forSequences = selectionGroup.getSequences();
741 forSequences = seq == null ? Collections.<SequenceI> emptyList()
742 : Arrays.asList(seq);
748 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
751 * @param showOrHideMenu
753 * @param forSequences
754 * the sequences whose annotations may be shown or hidden
759 * if true this is a special label meaning 'All'
760 * @param actionIsShow
761 * if true, the select menu item action is to show the annotation
764 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
765 final List<SequenceI> forSequences, String calcId,
766 final List<String> types, final boolean allTypes,
767 final boolean actionIsShow)
769 String label = types.toString(); // [a, b, c]
770 label = label.substring(1, label.length() - 1); // a, b, c
771 final JMenuItem item = new JMenuItem(label);
772 item.setToolTipText(calcId);
773 item.addActionListener(new java.awt.event.ActionListener()
776 public void actionPerformed(ActionEvent e)
778 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
779 types, forSequences, allTypes, actionIsShow);
783 showOrHideMenu.add(item);
786 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
789 // TODO: usability: thread off the generation of group url content so root
791 // sequence only URLs
792 // ID/regex match URLs
793 groupLinksMenu = new JMenu(
794 MessageManager.getString("action.group_link"));
795 // three types of url that might be created.
796 JMenu[] linkMenus = new JMenu[] { null,
797 new JMenu(MessageManager.getString("action.ids")),
798 new JMenu(MessageManager.getString("action.sequences")),
799 new JMenu(MessageManager.getString("action.ids_sequences")) };
801 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
802 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
803 Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
804 for (int sq = 0; sq < seqs.length; sq++)
807 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
808 .findPosition(sg.getEndRes());
809 // just collect ids from dataset sequence
810 // TODO: check if IDs collected from selecton group intersects with the
811 // current selection, too
812 SequenceI sqi = seqs[sq];
813 while (sqi.getDatasetSequence() != null)
815 sqi = sqi.getDatasetSequence();
817 DBRefEntry[] dbr = sqi.getDBRefs();
818 if (dbr != null && dbr.length > 0)
820 for (int d = 0; d < dbr.length; d++)
822 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
823 Object[] sarray = commonDbrefs.get(src);
826 sarray = new Object[2];
827 sarray[0] = new int[] { 0 };
828 sarray[1] = new String[seqs.length];
830 commonDbrefs.put(src, sarray);
833 if (((String[]) sarray[1])[sq] == null)
836 || (dbr[d].getMap().locateMappedRange(start, end) != null))
838 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
839 ((int[]) sarray[0])[0]++;
845 // now create group links for all distinct ID/sequence sets.
846 boolean addMenu = false; // indicates if there are any group links to give
848 for (String link : groupLinks)
850 GroupUrlLink urlLink = null;
853 urlLink = new GroupUrlLink(link);
854 } catch (Exception foo)
856 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
860 if (!urlLink.isValid())
862 Cache.log.error(urlLink.getInvalidMessage());
865 final String label = urlLink.getLabel();
866 boolean usingNames = false;
867 // Now see which parts of the group apply for this URL
868 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
869 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
870 String[] seqstr, ids; // input to makeUrl
873 int numinput = ((int[]) idset[0])[0];
874 String[] allids = ((String[]) idset[1]);
875 seqstr = new String[numinput];
876 ids = new String[numinput];
877 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
879 if (allids[sq] != null)
881 ids[idcount] = allids[sq];
882 seqstr[idcount++] = idandseqs[1][sq];
888 // just use the id/seq set
889 seqstr = idandseqs[1];
893 // and try and make the groupURL!
895 Object[] urlset = null;
898 urlset = urlLink.makeUrlStubs(ids, seqstr,
899 "FromJalview" + System.currentTimeMillis(), false);
900 } catch (UrlStringTooLongException e)
905 int type = urlLink.getGroupURLType() & 3;
906 // first two bits ofurlLink type bitfield are sequenceids and sequences
907 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
908 addshowLink(linkMenus[type], label
909 + (((type & 1) == 1) ? ("("
910 + (usingNames ? "Names" : ltarget) + ")") : ""),
917 groupLinksMenu = new JMenu(
918 MessageManager.getString("action.group_link"));
919 for (int m = 0; m < linkMenus.length; m++)
921 if (linkMenus[m] != null
922 && linkMenus[m].getMenuComponentCount() > 0)
924 groupLinksMenu.add(linkMenus[m]);
928 groupMenu.add(groupLinksMenu);
932 private void addshowLinks(JMenu linkMenu, Collection<List<String>> linkset)
934 for (List<String> linkstrset : linkset)
936 // split linkstr into label and url
937 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
942 * add a show URL menu item to the given linkMenu
946 * - menu label string
950 private void addshowLink(JMenu linkMenu, String label, final String url)
952 JMenuItem item = new JMenuItem(label);
953 item.setToolTipText(MessageManager.formatMessage(
954 "label.open_url_param", new Object[] { url }));
955 item.addActionListener(new java.awt.event.ActionListener()
958 public void actionPerformed(ActionEvent e)
960 new Thread(new Runnable()
977 * add a late bound groupURL item to the given linkMenu
981 * - menu label string
982 * @param urlgenerator
983 * GroupURLLink used to generate URL
985 * Object array returned from the makeUrlStubs function.
987 private void addshowLink(JMenu linkMenu, String label,
988 final GroupUrlLink urlgenerator, final Object[] urlstub)
990 JMenuItem item = new JMenuItem(label);
991 item.setToolTipText(MessageManager.formatMessage(
992 "label.open_url_seqs_param",
993 new Object[] { urlgenerator.getUrl_prefix(),
994 urlgenerator.getNumberInvolved(urlstub) }));
995 // TODO: put in info about what is being sent.
996 item.addActionListener(new ActionListener()
999 public void actionPerformed(ActionEvent e)
1001 new Thread(new Runnable()
1009 showLink(urlgenerator.constructFrom(urlstub));
1010 } catch (UrlStringTooLongException e2)
1028 private void jbInit() throws Exception
1030 groupMenu.setText(MessageManager.getString("label.selection"));
1031 groupName.setText(MessageManager.getString("label.name"));
1032 groupName.addActionListener(new java.awt.event.ActionListener()
1035 public void actionPerformed(ActionEvent e)
1037 groupName_actionPerformed();
1040 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1041 sequenceName.setText(MessageManager
1042 .getString("label.edit_name_description"));
1043 sequenceName.addActionListener(new java.awt.event.ActionListener()
1046 public void actionPerformed(ActionEvent e)
1048 sequenceName_actionPerformed();
1051 chooseAnnotations.setText(MessageManager
1052 .getString("action.choose_annotations"));
1053 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1056 public void actionPerformed(ActionEvent e)
1058 chooseAnnotations_actionPerformed(e);
1061 sequenceDetails.setText(MessageManager
1062 .getString("label.sequence_details"));
1063 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1066 public void actionPerformed(ActionEvent e)
1068 sequenceDetails_actionPerformed();
1071 sequenceSelDetails.setText(MessageManager
1072 .getString("label.sequence_details"));
1074 .addActionListener(new java.awt.event.ActionListener()
1077 public void actionPerformed(ActionEvent e)
1079 sequenceSelectionDetails_actionPerformed();
1082 PIDColour.setFocusPainted(false);
1084 .setText(MessageManager.getString("action.remove_group"));
1085 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1088 public void actionPerformed(ActionEvent e)
1090 unGroupMenuItem_actionPerformed();
1093 createGroupMenuItem.setText(MessageManager
1094 .getString("action.create_group"));
1096 .addActionListener(new java.awt.event.ActionListener()
1099 public void actionPerformed(ActionEvent e)
1101 createGroupMenuItem_actionPerformed();
1105 outline.setText(MessageManager.getString("action.border_colour"));
1106 outline.addActionListener(new java.awt.event.ActionListener()
1109 public void actionPerformed(ActionEvent e)
1111 outline_actionPerformed();
1115 .setText(MessageManager.getString("label.nucleotide"));
1116 nucleotideColour.addActionListener(new ActionListener()
1119 public void actionPerformed(ActionEvent e)
1121 nucleotideMenuItem_actionPerformed();
1124 colourMenu.setText(MessageManager.getString("label.group_colour"));
1125 showBoxes.setText(MessageManager.getString("action.boxes"));
1126 showBoxes.setState(true);
1127 showBoxes.addActionListener(new ActionListener()
1130 public void actionPerformed(ActionEvent e)
1132 showBoxes_actionPerformed();
1135 showText.setText(MessageManager.getString("action.text"));
1136 showText.setState(true);
1137 showText.addActionListener(new ActionListener()
1140 public void actionPerformed(ActionEvent e)
1142 showText_actionPerformed();
1145 showColourText.setText(MessageManager.getString("label.colour_text"));
1146 showColourText.addActionListener(new ActionListener()
1149 public void actionPerformed(ActionEvent e)
1151 showColourText_actionPerformed();
1154 displayNonconserved.setText(MessageManager
1155 .getString("label.show_non_conserved"));
1156 displayNonconserved.setState(true);
1157 displayNonconserved.addActionListener(new ActionListener()
1160 public void actionPerformed(ActionEvent e)
1162 showNonconserved_actionPerformed();
1165 editMenu.setText(MessageManager.getString("action.edit"));
1166 cut.setText(MessageManager.getString("action.cut"));
1167 cut.addActionListener(new ActionListener()
1170 public void actionPerformed(ActionEvent e)
1172 cut_actionPerformed();
1175 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1176 upperCase.addActionListener(new ActionListener()
1179 public void actionPerformed(ActionEvent e)
1184 copy.setText(MessageManager.getString("action.copy"));
1185 copy.addActionListener(new ActionListener()
1188 public void actionPerformed(ActionEvent e)
1190 copy_actionPerformed();
1193 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1194 lowerCase.addActionListener(new ActionListener()
1197 public void actionPerformed(ActionEvent e)
1202 toggle.setText(MessageManager.getString("label.toggle_case"));
1203 toggle.addActionListener(new ActionListener()
1206 public void actionPerformed(ActionEvent e)
1211 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1213 seqShowAnnotationsMenu.setText(MessageManager
1214 .getString("label.show_annotations"));
1215 seqHideAnnotationsMenu.setText(MessageManager
1216 .getString("label.hide_annotations"));
1217 groupShowAnnotationsMenu.setText(MessageManager
1218 .getString("label.show_annotations"));
1219 groupHideAnnotationsMenu.setText(MessageManager
1220 .getString("label.hide_annotations"));
1221 sequenceFeature.setText(MessageManager
1222 .getString("label.create_sequence_feature"));
1223 sequenceFeature.addActionListener(new ActionListener()
1226 public void actionPerformed(ActionEvent e)
1228 sequenceFeature_actionPerformed();
1231 textColour.setText(MessageManager.getString("label.text_colour"));
1232 textColour.addActionListener(new ActionListener()
1235 public void actionPerformed(ActionEvent e)
1237 textColour_actionPerformed();
1240 jMenu1.setText(MessageManager.getString("label.group"));
1241 pdbStructureDialog.setText(MessageManager
1242 .getString("label.show_pdbstruct_dialog"));
1243 pdbStructureDialog.addActionListener(new ActionListener()
1246 public void actionPerformed(ActionEvent actionEvent)
1248 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1249 if (ap.av.getSelectionGroup() != null)
1251 selectedSeqs = ap.av.getSequenceSelection();
1253 new StructureChooser(selectedSeqs, sequence, ap);
1257 rnaStructureMenu.setText(MessageManager
1258 .getString("label.view_rna_structure"));
1260 // colStructureMenu.setText("Colour By Structure");
1261 editSequence.setText(MessageManager.getString("label.edit_sequence")
1263 editSequence.addActionListener(new ActionListener()
1266 public void actionPerformed(ActionEvent actionEvent)
1268 editSequence_actionPerformed(actionEvent);
1271 makeReferenceSeq.setText(MessageManager
1272 .getString("label.mark_as_representative"));
1273 makeReferenceSeq.addActionListener(new ActionListener()
1277 public void actionPerformed(ActionEvent actionEvent)
1279 makeReferenceSeq_actionPerformed(actionEvent);
1283 hideInsertions.setText(MessageManager
1284 .getString("label.hide_insertions"));
1285 hideInsertions.addActionListener(new ActionListener()
1289 public void actionPerformed(ActionEvent e)
1291 hideInsertions_actionPerformed(e);
1295 * annotationMenuItem.setText("By Annotation");
1296 * annotationMenuItem.addActionListener(new ActionListener() { public void
1297 * actionPerformed(ActionEvent actionEvent) {
1298 * annotationMenuItem_actionPerformed(actionEvent); } });
1300 groupMenu.add(sequenceSelDetails);
1303 add(rnaStructureMenu);
1304 add(pdbStructureDialog);
1305 if (sequence != null)
1307 add(hideInsertions);
1309 // annotations configuration panel suppressed for now
1310 // groupMenu.add(chooseAnnotations);
1313 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1314 * (if a selection group is in force).
1316 sequenceMenu.add(seqShowAnnotationsMenu);
1317 sequenceMenu.add(seqHideAnnotationsMenu);
1318 sequenceMenu.add(seqAddReferenceAnnotations);
1319 groupMenu.add(groupShowAnnotationsMenu);
1320 groupMenu.add(groupHideAnnotationsMenu);
1321 groupMenu.add(groupAddReferenceAnnotations);
1322 groupMenu.add(editMenu);
1323 groupMenu.add(outputMenu);
1324 groupMenu.add(sequenceFeature);
1325 groupMenu.add(createGroupMenuItem);
1326 groupMenu.add(unGroupMenuItem);
1327 groupMenu.add(jMenu1);
1328 sequenceMenu.add(sequenceName);
1329 sequenceMenu.add(sequenceDetails);
1330 sequenceMenu.add(makeReferenceSeq);
1336 editMenu.add(editSequence);
1337 editMenu.add(upperCase);
1338 editMenu.add(lowerCase);
1339 editMenu.add(toggle);
1340 // JBPNote: These shouldn't be added here - should appear in a generic
1341 // 'apply web service to this sequence menu'
1342 // pdbMenu.add(RNAFold);
1343 // pdbMenu.add(ContraFold);
1344 jMenu1.add(groupName);
1345 jMenu1.add(colourMenu);
1346 jMenu1.add(showBoxes);
1347 jMenu1.add(showText);
1348 jMenu1.add(showColourText);
1349 jMenu1.add(outline);
1350 jMenu1.add(displayNonconserved);
1351 noColourmenuItem.setText(MessageManager.getString("label.none"));
1352 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1355 public void actionPerformed(ActionEvent e)
1357 noColourmenuItem_actionPerformed();
1361 clustalColour.setText(MessageManager.getString("label.clustalx"));
1362 clustalColour.addActionListener(new java.awt.event.ActionListener()
1365 public void actionPerformed(ActionEvent e)
1367 clustalColour_actionPerformed();
1370 zappoColour.setText(MessageManager.getString("label.zappo"));
1371 zappoColour.addActionListener(new java.awt.event.ActionListener()
1374 public void actionPerformed(ActionEvent e)
1376 zappoColour_actionPerformed();
1379 taylorColour.setText(MessageManager.getString("label.taylor"));
1380 taylorColour.addActionListener(new java.awt.event.ActionListener()
1383 public void actionPerformed(ActionEvent e)
1385 taylorColour_actionPerformed();
1388 hydrophobicityColour.setText(MessageManager
1389 .getString("label.hydrophobicity"));
1390 hydrophobicityColour
1391 .addActionListener(new java.awt.event.ActionListener()
1394 public void actionPerformed(ActionEvent e)
1396 hydrophobicityColour_actionPerformed();
1399 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1400 helixColour.addActionListener(new java.awt.event.ActionListener()
1403 public void actionPerformed(ActionEvent e)
1405 helixColour_actionPerformed();
1408 strandColour.setText(MessageManager
1409 .getString("label.strand_propensity"));
1410 strandColour.addActionListener(new java.awt.event.ActionListener()
1413 public void actionPerformed(ActionEvent e)
1415 strandColour_actionPerformed();
1418 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1419 turnColour.addActionListener(new java.awt.event.ActionListener()
1422 public void actionPerformed(ActionEvent e)
1424 turnColour_actionPerformed();
1427 buriedColour.setText(MessageManager.getString("label.buried_index"));
1428 buriedColour.addActionListener(new java.awt.event.ActionListener()
1431 public void actionPerformed(ActionEvent e)
1433 buriedColour_actionPerformed();
1436 abovePIDColour.setText(MessageManager
1437 .getString("label.above_identity_threshold"));
1438 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1441 public void actionPerformed(ActionEvent e)
1443 abovePIDColour_actionPerformed();
1446 userDefinedColour.setText(MessageManager
1447 .getString("action.user_defined"));
1448 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1451 public void actionPerformed(ActionEvent e)
1453 userDefinedColour_actionPerformed(e);
1457 .setText(MessageManager.getString("label.percentage_identity"));
1458 PIDColour.addActionListener(new java.awt.event.ActionListener()
1461 public void actionPerformed(ActionEvent e)
1463 PIDColour_actionPerformed();
1467 .setText(MessageManager.getString("label.blosum62_score"));
1468 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1471 public void actionPerformed(ActionEvent e)
1473 BLOSUM62Colour_actionPerformed();
1476 purinePyrimidineColour.setText(MessageManager
1477 .getString("label.purine_pyrimidine"));
1478 purinePyrimidineColour
1479 .addActionListener(new java.awt.event.ActionListener()
1482 public void actionPerformed(ActionEvent e)
1484 purinePyrimidineColour_actionPerformed();
1488 tcoffeeColour.setText(MessageManager.getString("label.tcoffee_scores"));
1489 tcoffeeColour.addActionListener(new ActionListener()
1492 public void actionPerformed(ActionEvent e)
1494 tcoffeeColorScheme_actionPerformed();
1499 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1500 * public void actionPerformed(ActionEvent e) {
1501 * covariationColour_actionPerformed(); } });
1504 conservationMenuItem.setText(MessageManager
1505 .getString("action.by_conservation"));
1506 conservationMenuItem.addActionListener(new ActionListener()
1509 public void actionPerformed(ActionEvent e)
1511 conservationMenuItem_actionPerformed();
1517 * Adds items to the group colour sub-menu
1519 protected void buildColourMenu()
1521 SequenceGroup sg = getGroup();
1522 colourMenu.removeAll();
1523 colourMenu.add(textColour);
1524 colourMenu.add(noColourmenuItem);
1525 colourMenu.add(clustalColour);
1526 // in Java 8, isApplicableTo can be a static method on the interface
1527 clustalColour.setEnabled(new ClustalxColourScheme(sg, null)
1528 .isApplicableTo(sg));
1529 colourMenu.add(BLOSUM62Colour);
1531 .setEnabled(new Blosum62ColourScheme().isApplicableTo(sg));
1532 colourMenu.add(PIDColour);
1533 PIDColour.setEnabled(new PIDColourScheme().isApplicableTo(sg));
1534 colourMenu.add(zappoColour);
1535 zappoColour.setEnabled(new ZappoColourScheme().isApplicableTo(sg));
1536 colourMenu.add(taylorColour);
1537 taylorColour.setEnabled(new TaylorColourScheme().isApplicableTo(sg));
1538 colourMenu.add(hydrophobicityColour);
1539 hydrophobicityColour.setEnabled(new HydrophobicColourScheme()
1540 .isApplicableTo(sg));
1541 colourMenu.add(helixColour);
1542 helixColour.setEnabled(new HelixColourScheme().isApplicableTo(sg));
1543 colourMenu.add(strandColour);
1544 strandColour.setEnabled(new StrandColourScheme().isApplicableTo(sg));
1545 colourMenu.add(turnColour);
1546 turnColour.setEnabled(new TurnColourScheme().isApplicableTo(sg));
1547 colourMenu.add(buriedColour);
1548 buriedColour.setEnabled(new BuriedColourScheme().isApplicableTo(sg));
1549 colourMenu.add(nucleotideColour);
1550 nucleotideColour.setEnabled(new NucleotideColourScheme()
1551 .isApplicableTo(sg));
1552 colourMenu.add(purinePyrimidineColour);
1553 purinePyrimidineColour.setEnabled(new PurinePyrimidineColourScheme()
1554 .isApplicableTo(sg));
1555 colourMenu.add(tcoffeeColour);
1557 .setEnabled(new TCoffeeColourScheme(sg).isApplicableTo(sg));
1559 SortedMap<String, UserColourScheme> userColourSchemes = UserDefinedColours
1560 .getUserColourSchemes();
1561 if (userColourSchemes != null)
1563 for (String userColour : userColourSchemes.keySet())
1565 JMenuItem item = new JMenuItem(userColour);
1566 item.addActionListener(new ActionListener()
1569 public void actionPerformed(ActionEvent evt)
1571 userDefinedColour_actionPerformed(evt);
1574 colourMenu.add(item);
1577 colourMenu.add(userDefinedColour);
1579 colourMenu.addSeparator();
1580 colourMenu.add(conservationMenuItem);
1581 colourMenu.add(abovePIDColour);
1584 * add some of these items to a ButtonGroup so their
1585 * selection is mutually exclusive
1587 ButtonGroup colours = new ButtonGroup();
1588 colours.add(noColourmenuItem);
1589 colours.add(clustalColour);
1590 colours.add(BLOSUM62Colour);
1591 colours.add(PIDColour);
1592 colours.add(zappoColour);
1593 colours.add(taylorColour);
1594 colours.add(hydrophobicityColour);
1595 colours.add(helixColour);
1596 colours.add(strandColour);
1597 colours.add(turnColour);
1598 colours.add(buriedColour);
1599 colours.add(purinePyrimidineColour);
1600 colours.add(tcoffeeColour);
1601 colours.add(nucleotideColour);
1602 colours.add(userDefinedColour);
1603 colours.add(abovePIDColour);
1604 // colours.add(RNAInteractionColour);
1609 * Check for any annotations on the underlying dataset sequences (for the
1610 * current selection group) which are not 'on the alignment'.If any are found,
1611 * enable the option to add them to the alignment. The criteria for 'on the
1612 * alignment' is finding an alignment annotation on the alignment, matched on
1613 * calcId, label and sequenceRef.
1615 * A tooltip is also constructed that displays the source (calcId) and type
1616 * (label) of the annotations that can be added.
1619 * @param forSequences
1621 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1622 List<SequenceI> forSequences)
1624 menuItem.setEnabled(false);
1627 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1628 * Using TreeMap means calcIds are shown in alphabetical order.
1630 SortedMap<String, String> tipEntries = new TreeMap<String, String>();
1631 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1632 AlignmentI al = this.ap.av.getAlignment();
1633 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1634 tipEntries, candidates, al);
1635 if (!candidates.isEmpty())
1637 StringBuilder tooltip = new StringBuilder(64);
1638 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1641 * Found annotations that could be added. Enable the menu item, and
1642 * configure its tooltip and action.
1644 menuItem.setEnabled(true);
1645 for (String calcId : tipEntries.keySet())
1647 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1649 String tooltipText = JvSwingUtils.wrapTooltip(true,
1650 tooltip.toString());
1651 menuItem.setToolTipText(tooltipText);
1653 menuItem.addActionListener(new ActionListener()
1656 public void actionPerformed(ActionEvent e)
1658 addReferenceAnnotations_actionPerformed(candidates);
1665 * Add annotations to the sequences and to the alignment.
1668 * a map whose keys are sequences on the alignment, and values a list
1669 * of annotations to add to each sequence
1671 protected void addReferenceAnnotations_actionPerformed(
1672 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1674 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1675 final AlignmentI alignment = this.ap.getAlignment();
1676 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1681 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1683 if (!ap.av.getAlignment().hasSeqrep())
1685 // initialise the display flags so the user sees something happen
1686 ap.av.setDisplayReferenceSeq(true);
1687 ap.av.setColourByReferenceSeq(true);
1688 ap.av.getAlignment().setSeqrep(sequence);
1692 if (ap.av.getAlignment().getSeqrep() == sequence)
1694 ap.av.getAlignment().setSeqrep(null);
1698 ap.av.getAlignment().setSeqrep(sequence);
1704 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1706 if (sequence != null)
1708 ColumnSelection cs = ap.av.getColumnSelection();
1711 cs = new ColumnSelection();
1713 cs.hideInsertionsFor(sequence);
1714 ap.av.setColumnSelection(cs);
1719 protected void sequenceSelectionDetails_actionPerformed()
1721 createSequenceDetailsReport(ap.av.getSequenceSelection());
1724 protected void sequenceDetails_actionPerformed()
1726 createSequenceDetailsReport(new SequenceI[] { sequence });
1729 public void createSequenceDetailsReport(SequenceI[] sequences)
1731 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1732 StringBuilder contents = new StringBuilder(128);
1733 for (SequenceI seq : sequences)
1735 contents.append("<p><h2>"
1738 "label.create_sequence_details_report_annotation_for",
1739 new Object[] { seq.getDisplayId(true) })
1741 new SequenceAnnotationReport(null)
1742 .createSequenceAnnotationReport(
1747 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1748 .getSeqPanel().seqCanvas.fr.getMinMax()
1750 contents.append("</p>");
1752 cap.setText("<html>" + contents.toString() + "</html>");
1754 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1755 "label.sequence_details_for",
1756 (sequences.length == 1 ? new Object[] { sequences[0]
1757 .getDisplayId(true) } : new Object[] { MessageManager
1758 .getString("label.selection") })), 500, 400);
1762 protected void showNonconserved_actionPerformed()
1764 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1769 * call to refresh view after settings change
1773 ap.updateAnnotation();
1774 ap.paintAlignment(true);
1776 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1785 protected void clustalColour_actionPerformed()
1787 SequenceGroup sg = getGroup();
1788 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1798 protected void zappoColour_actionPerformed()
1800 getGroup().cs = new ZappoColourScheme();
1810 protected void taylorColour_actionPerformed()
1812 getGroup().cs = new TaylorColourScheme();
1822 protected void hydrophobicityColour_actionPerformed()
1824 getGroup().cs = new HydrophobicColourScheme();
1834 protected void helixColour_actionPerformed()
1836 getGroup().cs = new HelixColourScheme();
1846 protected void strandColour_actionPerformed()
1848 getGroup().cs = new StrandColourScheme();
1858 protected void turnColour_actionPerformed()
1860 getGroup().cs = new TurnColourScheme();
1870 protected void buriedColour_actionPerformed()
1872 getGroup().cs = new BuriedColourScheme();
1882 public void nucleotideMenuItem_actionPerformed()
1884 getGroup().cs = new NucleotideColourScheme();
1888 protected void purinePyrimidineColour_actionPerformed()
1890 getGroup().cs = new PurinePyrimidineColourScheme();
1894 protected void tcoffeeColorScheme_actionPerformed()
1896 getGroup().cs = new TCoffeeColourScheme(getGroup());
1901 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1902 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1910 protected void abovePIDColour_actionPerformed()
1912 SequenceGroup sg = getGroup();
1918 if (abovePIDColour.isSelected())
1920 sg.cs.setConsensus(AAFrequency.calculate(
1921 sg.getSequences(ap.av.getHiddenRepSequences()),
1922 sg.getStartRes(), sg.getEndRes() + 1));
1924 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1927 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1929 SliderPanel.showPIDSlider();
1932 // remove PIDColouring
1934 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1946 protected void userDefinedColour_actionPerformed(ActionEvent e)
1948 SequenceGroup sg = getGroup();
1950 if (e.getSource().equals(userDefinedColour))
1952 new UserDefinedColours(ap, sg);
1956 UserColourScheme udc = UserDefinedColours
1957 .getUserColourSchemes().get(e.getActionCommand());
1965 * Open a panel where the user can choose which types of sequence annotation
1970 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1972 // todo correct way to guard against opening a duplicate panel?
1973 new AnnotationChooser(ap);
1982 protected void PIDColour_actionPerformed()
1984 SequenceGroup sg = getGroup();
1985 sg.cs = new PIDColourScheme();
1986 sg.cs.setConsensus(AAFrequency.calculate(
1987 sg.getSequences(ap.av.getHiddenRepSequences()),
1988 sg.getStartRes(), sg.getEndRes() + 1));
1998 protected void BLOSUM62Colour_actionPerformed()
2000 SequenceGroup sg = getGroup();
2002 sg.cs = new Blosum62ColourScheme();
2004 sg.cs.setConsensus(AAFrequency.calculate(
2005 sg.getSequences(ap.av.getHiddenRepSequences()),
2006 sg.getStartRes(), sg.getEndRes() + 1));
2017 protected void noColourmenuItem_actionPerformed()
2019 getGroup().cs = null;
2029 protected void conservationMenuItem_actionPerformed()
2031 SequenceGroup sg = getGroup();
2037 if (conservationMenuItem.isSelected())
2039 // JBPNote: Conservation name shouldn't be i18n translated
2040 Conservation c = new Conservation("Group", sg.getSequences(ap.av
2041 .getHiddenRepSequences()), sg.getStartRes(),
2042 sg.getEndRes() + 1);
2045 c.verdict(false, ap.av.getConsPercGaps());
2047 sg.cs.setConservation(c);
2049 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2050 SliderPanel.showConservationSlider();
2053 // remove ConservationColouring
2055 sg.cs.setConservation(null);
2061 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2063 SequenceGroup sg = getGroup();
2069 AnnotationColourGradient acg = new AnnotationColourGradient(
2070 sequence.getAnnotation()[0], null,
2071 AnnotationColourGradient.NO_THRESHOLD);
2073 acg.setPredefinedColours(true);
2085 protected void groupName_actionPerformed()
2088 SequenceGroup sg = getGroup();
2089 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2090 sg.getDescription(), " "
2091 + MessageManager.getString("label.group_name") + " ",
2092 MessageManager.getString("label.group_description") + " ",
2093 MessageManager.getString("label.edit_group_name_description"),
2101 sg.setName(dialog.getName());
2102 sg.setDescription(dialog.getDescription());
2107 * Get selection group - adding it to the alignment if necessary.
2109 * @return sequence group to operate on
2111 SequenceGroup getGroup()
2113 SequenceGroup sg = ap.av.getSelectionGroup();
2114 // this method won't add a new group if it already exists
2117 ap.av.getAlignment().addGroup(sg);
2129 void sequenceName_actionPerformed()
2131 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2132 sequence.getDescription(),
2133 " " + MessageManager.getString("label.sequence_name")
2135 MessageManager.getString("label.sequence_description") + " ",
2137 .getString("label.edit_sequence_name_description"),
2145 if (dialog.getName() != null)
2147 if (dialog.getName().indexOf(" ") > -1)
2153 .getString("label.spaces_converted_to_backslashes"),
2155 .getString("label.no_spaces_allowed_sequence_name"),
2156 JvOptionPane.WARNING_MESSAGE);
2159 sequence.setName(dialog.getName().replace(' ', '_'));
2160 ap.paintAlignment(false);
2163 sequence.setDescription(dialog.getDescription());
2165 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2176 void unGroupMenuItem_actionPerformed()
2178 SequenceGroup sg = ap.av.getSelectionGroup();
2179 ap.av.getAlignment().deleteGroup(sg);
2180 ap.av.setSelectionGroup(null);
2184 void createGroupMenuItem_actionPerformed()
2186 getGroup(); // implicitly creates group - note - should apply defaults / use
2187 // standard alignment window logic for this
2197 protected void outline_actionPerformed()
2199 SequenceGroup sg = getGroup();
2200 Color col = JColorChooser.showDialog(this,
2201 MessageManager.getString("label.select_outline_colour"),
2206 sg.setOutlineColour(col);
2218 public void showBoxes_actionPerformed()
2220 getGroup().setDisplayBoxes(showBoxes.isSelected());
2230 public void showText_actionPerformed()
2232 getGroup().setDisplayText(showText.isSelected());
2242 public void showColourText_actionPerformed()
2244 getGroup().setColourText(showColourText.isSelected());
2248 public void showLink(String url)
2252 jalview.util.BrowserLauncher.openURL(url);
2253 } catch (Exception ex)
2255 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
2256 MessageManager.getString("label.web_browser_not_found_unix"),
2257 MessageManager.getString("label.web_browser_not_found"),
2258 JvOptionPane.WARNING_MESSAGE);
2260 ex.printStackTrace();
2264 void hideSequences(boolean representGroup)
2266 ap.av.hideSequences(sequence, representGroup);
2269 public void copy_actionPerformed()
2271 ap.alignFrame.copy_actionPerformed(null);
2274 public void cut_actionPerformed()
2276 ap.alignFrame.cut_actionPerformed(null);
2279 void changeCase(ActionEvent e)
2281 Object source = e.getSource();
2282 SequenceGroup sg = ap.av.getSelectionGroup();
2286 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2287 sg.getStartRes(), sg.getEndRes() + 1);
2292 if (source == toggle)
2294 description = MessageManager.getString("label.toggle_case");
2295 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2297 else if (source == upperCase)
2299 description = MessageManager.getString("label.to_upper_case");
2300 caseChange = ChangeCaseCommand.TO_UPPER;
2304 description = MessageManager.getString("label.to_lower_case");
2305 caseChange = ChangeCaseCommand.TO_LOWER;
2308 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2309 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2310 startEnd, caseChange);
2312 ap.alignFrame.addHistoryItem(caseCommand);
2314 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2320 public void outputText_actionPerformed(ActionEvent e)
2322 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2323 cap.setForInput(null);
2324 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2325 "label.alignment_output_command",
2326 new Object[] { e.getActionCommand() }), 600, 500);
2328 String[] omitHidden = null;
2330 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2331 // or we simply trust the user wants
2332 // wysiwig behaviour
2334 FileFormatI fileFormat = FileFormat.forName(e.getActionCommand());
2335 cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2338 public void sequenceFeature_actionPerformed()
2340 SequenceGroup sg = ap.av.getSelectionGroup();
2346 int rsize = 0, gSize = sg.getSize();
2347 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2348 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2350 for (int i = 0; i < gSize; i++)
2352 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2353 int end = sg.findEndRes(sg.getSequenceAt(i));
2356 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2357 features[rsize] = new SequenceFeature(null, null, null, start, end,
2362 rseqs = new SequenceI[rsize];
2363 tfeatures = new SequenceFeature[rsize];
2364 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2365 System.arraycopy(features, 0, tfeatures, 0, rsize);
2366 features = tfeatures;
2368 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2369 features, true, ap))
2371 ap.alignFrame.setShowSeqFeatures(true);
2372 ap.highlightSearchResults(null);
2376 public void textColour_actionPerformed()
2378 SequenceGroup sg = getGroup();
2381 new TextColourChooser().chooseColour(ap, sg);
2385 public void colourByStructure(String pdbid)
2387 Annotation[] anots = ap.av.getStructureSelectionManager()
2388 .colourSequenceFromStructure(sequence, pdbid);
2390 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2391 "Coloured by " + pdbid, anots);
2393 ap.av.getAlignment().addAnnotation(an);
2394 an.createSequenceMapping(sequence, 0, true);
2395 // an.adjustForAlignment();
2396 ap.av.getAlignment().setAnnotationIndex(an, 0);
2398 ap.adjustAnnotationHeight();
2400 sequence.addAlignmentAnnotation(an);
2404 public void editSequence_actionPerformed(ActionEvent actionEvent)
2406 SequenceGroup sg = ap.av.getSelectionGroup();
2410 if (sequence == null)
2412 sequence = sg.getSequenceAt(0);
2415 EditNameDialog dialog = new EditNameDialog(
2416 sequence.getSequenceAsString(sg.getStartRes(),
2417 sg.getEndRes() + 1), null,
2418 MessageManager.getString("label.edit_sequence"), null,
2419 MessageManager.getString("label.edit_sequence"),
2424 EditCommand editCommand = new EditCommand(
2425 MessageManager.getString("label.edit_sequences"),
2426 Action.REPLACE, dialog.getName().replace(' ',
2427 ap.av.getGapCharacter()),
2428 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2429 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2431 ap.alignFrame.addHistoryItem(editCommand);
2433 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()