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.ResidueProperties;
55 import jalview.schemes.StrandColourScheme;
56 import jalview.schemes.TaylorColourScheme;
57 import jalview.schemes.TurnColourScheme;
58 import jalview.schemes.UserColourScheme;
59 import jalview.schemes.ZappoColourScheme;
60 import jalview.util.DBRefUtils;
61 import jalview.util.GroupUrlLink;
62 import jalview.util.GroupUrlLink.UrlStringTooLongException;
63 import jalview.util.MessageManager;
64 import jalview.util.UrlLink;
66 import java.awt.Color;
67 import java.awt.event.ActionEvent;
68 import java.awt.event.ActionListener;
69 import java.util.ArrayList;
70 import java.util.Arrays;
71 import java.util.Collections;
72 import java.util.Hashtable;
73 import java.util.LinkedHashMap;
74 import java.util.List;
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.JOptionPane;
85 import javax.swing.JPopupMenu;
86 import javax.swing.JRadioButtonMenuItem;
92 * @version $Revision: 1.118 $
94 public class PopupMenu extends JPopupMenu
96 JMenu groupMenu = new JMenu();
98 JMenuItem groupName = new JMenuItem();
100 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
102 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
104 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
106 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
108 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
110 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
112 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
114 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
116 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
118 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
120 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
122 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
124 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
126 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
128 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
130 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
134 JMenu sequenceMenu = new JMenu();
136 JMenuItem sequenceName = new JMenuItem();
138 JMenuItem sequenceDetails = new JMenuItem();
140 JMenuItem sequenceSelDetails = new JMenuItem();
142 JMenuItem makeReferenceSeq = new JMenuItem();
144 JMenuItem chooseAnnotations = new JMenuItem();
148 JMenuItem createGroupMenuItem = new JMenuItem();
150 JMenuItem unGroupMenuItem = new JMenuItem();
152 JMenuItem outline = new JMenuItem();
154 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
156 JMenu colourMenu = new JMenu();
158 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
160 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
162 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
164 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
166 JMenu editMenu = new JMenu();
168 JMenuItem cut = new JMenuItem();
170 JMenuItem copy = new JMenuItem();
172 JMenuItem upperCase = new JMenuItem();
174 JMenuItem lowerCase = new JMenuItem();
176 JMenuItem toggle = new JMenuItem();
178 JMenu pdbMenu = new JMenu();
180 JMenu outputMenu = new JMenu();
182 JMenu seqShowAnnotationsMenu = new JMenu();
184 JMenu seqHideAnnotationsMenu = new JMenu();
186 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
187 MessageManager.getString("label.add_reference_annotations"));
189 JMenu groupShowAnnotationsMenu = new JMenu();
191 JMenu groupHideAnnotationsMenu = new JMenu();
193 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
194 MessageManager.getString("label.add_reference_annotations"));
196 JMenuItem sequenceFeature = new JMenuItem();
198 JMenuItem textColour = new JMenuItem();
200 JMenu jMenu1 = new JMenu();
202 JMenuItem pdbStructureDialog = new JMenuItem();
204 JMenu rnaStructureMenu = new JMenu();
206 JMenuItem editSequence = new JMenuItem();
208 JMenu groupLinksMenu;
210 JMenuItem hideInsertions = new JMenuItem();
213 * Creates a new PopupMenu object.
220 public PopupMenu(final AlignmentPanel ap, Sequence seq, List<String> links)
222 this(ap, seq, links, null);
232 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
233 List<String> links, List<String> groupLinks)
235 // /////////////////////////////////////////////////////////
236 // If this is activated from the sequence panel, the user may want to
237 // edit or annotate a particular residue. Therefore display the residue menu
239 // If from the IDPanel, we must display the sequence menu
240 // ////////////////////////////////////////////////////////
244 ButtonGroup colours = new ButtonGroup();
245 colours.add(noColourmenuItem);
246 colours.add(clustalColour);
247 colours.add(zappoColour);
248 colours.add(taylorColour);
249 colours.add(hydrophobicityColour);
250 colours.add(helixColour);
251 colours.add(strandColour);
252 colours.add(turnColour);
253 colours.add(buriedColour);
254 colours.add(abovePIDColour);
255 colours.add(userDefinedColour);
256 colours.add(PIDColour);
257 colours.add(BLOSUM62Colour);
258 colours.add(purinePyrimidineColour);
259 colours.add(RNAInteractionColour);
261 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
263 JMenuItem item = new JMenuItem(
264 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
266 item.addActionListener(new java.awt.event.ActionListener()
269 public void actionPerformed(ActionEvent e)
271 outputText_actionPerformed(e);
275 outputMenu.add(item);
279 * Build menus for annotation types that may be shown or hidden, and for
280 * 'reference annotations' that may be added to the alignment. First for the
281 * currently selected sequence (if there is one):
283 final List<SequenceI> selectedSequence = (seq == null ? Collections
284 .<SequenceI> emptyList() : Arrays.asList(seq));
285 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
286 seqHideAnnotationsMenu, selectedSequence);
287 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
291 * And repeat for the current selection group (if there is one):
293 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
294 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
296 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
297 groupHideAnnotationsMenu, selectedGroup);
298 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
304 } catch (Exception e)
312 sequenceMenu.setText(sequence.getName());
313 if (seq == ap.av.getAlignment().getSeqrep())
315 makeReferenceSeq.setText(MessageManager
316 .getString("action.unmark_as_reference"));
320 makeReferenceSeq.setText(MessageManager
321 .getString("action.set_as_reference"));
324 if (!ap.av.getAlignment().isNucleotide())
326 remove(rnaStructureMenu);
330 int origCount = rnaStructureMenu.getItemCount();
332 * add menu items to 2D-render any alignment or sequence secondary
333 * structure annotation
335 AlignmentAnnotation[] aas = ap.av.getAlignment()
336 .getAlignmentAnnotation();
339 for (final AlignmentAnnotation aa : aas)
341 if (aa.isValidStruc() && aa.sequenceRef == null)
344 * valid alignment RNA secondary structure annotation
346 menuItem = new JMenuItem();
347 menuItem.setText(MessageManager.formatMessage(
348 "label.2d_rna_structure_line",
349 new Object[] { aa.label }));
350 menuItem.addActionListener(new java.awt.event.ActionListener()
353 public void actionPerformed(ActionEvent e)
355 new AppVarna(seq, aa, ap);
358 rnaStructureMenu.add(menuItem);
363 if (seq.getAnnotation() != null)
365 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
366 for (final AlignmentAnnotation aa : seqAnns)
368 if (aa.isValidStruc())
371 * valid sequence RNA secondary structure annotation
373 // TODO: make rnastrucF a bit more nice
374 menuItem = new JMenuItem();
375 menuItem.setText(MessageManager.formatMessage(
376 "label.2d_rna_sequence_name",
377 new Object[] { seq.getName() }));
378 menuItem.addActionListener(new java.awt.event.ActionListener()
381 public void actionPerformed(ActionEvent e)
383 // TODO: VARNA does'nt print gaps in the sequence
384 new AppVarna(seq, aa, ap);
387 rnaStructureMenu.add(menuItem);
391 if (rnaStructureMenu.getItemCount() == origCount)
393 remove(rnaStructureMenu);
397 menuItem = new JMenuItem(
398 MessageManager.getString("action.hide_sequences"));
399 menuItem.addActionListener(new java.awt.event.ActionListener()
402 public void actionPerformed(ActionEvent e)
404 hideSequences(false);
409 if (ap.av.getSelectionGroup() != null
410 && ap.av.getSelectionGroup().getSize() > 1)
412 menuItem = new JMenuItem(MessageManager.formatMessage(
413 "label.represent_group_with",
414 new Object[] { seq.getName() }));
415 menuItem.addActionListener(new java.awt.event.ActionListener()
418 public void actionPerformed(ActionEvent e)
423 sequenceMenu.add(menuItem);
426 if (ap.av.hasHiddenRows())
428 final int index = ap.av.getAlignment().findIndex(seq);
430 if (ap.av.adjustForHiddenSeqs(index)
431 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
433 menuItem = new JMenuItem(
434 MessageManager.getString("action.reveal_sequences"));
435 menuItem.addActionListener(new ActionListener()
438 public void actionPerformed(ActionEvent e)
440 ap.av.showSequence(index);
441 if (ap.overviewPanel != null)
443 ap.overviewPanel.updateOverviewImage();
451 // for the case when no sequences are even visible
452 if (ap.av.hasHiddenRows())
455 menuItem = new JMenuItem(
456 MessageManager.getString("action.reveal_all"));
457 menuItem.addActionListener(new ActionListener()
460 public void actionPerformed(ActionEvent e)
462 ap.av.showAllHiddenSeqs();
463 if (ap.overviewPanel != null)
465 ap.overviewPanel.updateOverviewImage();
475 SequenceGroup sg = ap.av.getSelectionGroup();
476 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
477 .getGroups().contains(sg) : false;
479 if (sg != null && sg.getSize() > 0)
481 groupName.setText(MessageManager
482 .getString("label.edit_name_and_description_current_group"));
484 if (sg.cs instanceof ZappoColourScheme)
486 zappoColour.setSelected(true);
488 else if (sg.cs instanceof TaylorColourScheme)
490 taylorColour.setSelected(true);
492 else if (sg.cs instanceof PIDColourScheme)
494 PIDColour.setSelected(true);
496 else if (sg.cs instanceof Blosum62ColourScheme)
498 BLOSUM62Colour.setSelected(true);
500 else if (sg.cs instanceof UserColourScheme)
502 userDefinedColour.setSelected(true);
504 else if (sg.cs instanceof HydrophobicColourScheme)
506 hydrophobicityColour.setSelected(true);
508 else if (sg.cs instanceof HelixColourScheme)
510 helixColour.setSelected(true);
512 else if (sg.cs instanceof StrandColourScheme)
514 strandColour.setSelected(true);
516 else if (sg.cs instanceof TurnColourScheme)
518 turnColour.setSelected(true);
520 else if (sg.cs instanceof BuriedColourScheme)
522 buriedColour.setSelected(true);
524 else if (sg.cs instanceof ClustalxColourScheme)
526 clustalColour.setSelected(true);
528 else if (sg.cs instanceof PurinePyrimidineColourScheme)
530 purinePyrimidineColour.setSelected(true);
534 * else if (sg.cs instanceof CovariationColourScheme) {
535 * covariationColour.setSelected(true); }
539 noColourmenuItem.setSelected(true);
542 if (sg.cs != null && sg.cs.conservationApplied())
544 conservationMenuItem.setSelected(true);
546 displayNonconserved.setSelected(sg.getShowNonconserved());
547 showText.setSelected(sg.getDisplayText());
548 showColourText.setSelected(sg.getColourText());
549 showBoxes.setSelected(sg.getDisplayBoxes());
550 // add any groupURLs to the groupURL submenu and make it visible
551 if (groupLinks != null && groupLinks.size() > 0)
553 buildGroupURLMenu(sg, groupLinks);
555 // Add a 'show all structures' for the current selection
556 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
557 SequenceI sqass = null;
558 for (SequenceI sq : ap.av.getSequenceSelection())
560 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
561 if (pes != null && pes.size() > 0)
563 reppdb.put(pes.get(0).getId(), pes.get(0));
564 for (PDBEntry pe : pes)
566 pdbe.put(pe.getId(), pe);
576 final PDBEntry[] pe = pdbe.values().toArray(
577 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
578 new PDBEntry[reppdb.size()]);
579 final JMenuItem gpdbview, rpdbview;
584 groupMenu.setVisible(false);
585 editMenu.setVisible(false);
590 createGroupMenuItem.setVisible(true);
591 unGroupMenuItem.setVisible(false);
592 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
596 createGroupMenuItem.setVisible(false);
597 unGroupMenuItem.setVisible(true);
598 jMenu1.setText(MessageManager.getString("action.edit_group"));
603 sequenceMenu.setVisible(false);
604 pdbStructureDialog.setVisible(false);
605 rnaStructureMenu.setVisible(false);
608 if (links != null && links.size() > 0)
610 addFeatureLinks(seq, links);
615 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
620 void addFeatureLinks(final SequenceI seq, List<String> links)
622 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
623 List<String> linkset = new ArrayList<String>();
624 for (String link : links)
626 UrlLink urlLink = null;
629 urlLink = new UrlLink(link);
630 } catch (Exception foo)
632 Cache.log.error("Exception for URLLink '" + link + "'", foo);
636 if (!urlLink.isValid())
638 Cache.log.error(urlLink.getInvalidMessage());
641 final String label = urlLink.getLabel();
642 if (seq != null && urlLink.isDynamic())
645 // collect matching db-refs
646 DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(),
647 new String[] { urlLink.getTarget() });
648 // collect id string too
649 String id = seq.getName();
650 String descr = seq.getDescription();
651 if (descr != null && descr.length() < 1)
658 for (int r = 0; r < dbr.length; r++)
660 if (id != null && dbr[r].getAccessionId().equals(id))
662 // suppress duplicate link creation for the bare sequence ID
663 // string with this link
666 // create Bare ID link for this URL
667 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true);
670 for (int u = 0; u < urls.length; u += 2)
672 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
674 linkset.add(urls[u] + "|" + urls[u + 1]);
675 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
683 // create Bare ID link for this URL
684 String[] urls = urlLink.makeUrls(id, true);
687 for (int u = 0; u < urls.length; u += 2)
689 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
691 linkset.add(urls[u] + "|" + urls[u + 1]);
692 addshowLink(linkMenu, label, urls[u + 1]);
697 // Create urls from description but only for URL links which are regex
699 if (descr != null && urlLink.getRegexReplace() != null)
701 // create link for this URL from description where regex matches
702 String[] urls = urlLink.makeUrls(descr, true);
705 for (int u = 0; u < urls.length; u += 2)
707 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
709 linkset.add(urls[u] + "|" + urls[u + 1]);
710 addshowLink(linkMenu, label, urls[u + 1]);
718 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
720 linkset.add(label + "|" + urlLink.getUrl_prefix());
721 // Add a non-dynamic link
722 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
726 if (sequence != null)
728 sequenceMenu.add(linkMenu);
737 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
738 * "All" is added first, followed by a separator. Then add any annotation
739 * types associated with the current selection. Separate menus are built for
740 * the selected sequence group (if any), and the selected sequence.
742 * Some annotation rows are always rendered together - these can be identified
743 * by a common graphGroup property > -1. Only one of each group will be marked
744 * as visible (to avoid duplication of the display). For such groups we add a
745 * composite type name, e.g.
747 * IUPredWS (Long), IUPredWS (Short)
751 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
752 List<SequenceI> forSequences)
754 showMenu.removeAll();
755 hideMenu.removeAll();
757 final List<String> all = Arrays.asList(new String[] { MessageManager
758 .getString("label.all") });
759 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
760 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
762 showMenu.addSeparator();
763 hideMenu.addSeparator();
765 final AlignmentAnnotation[] annotations = ap.getAlignment()
766 .getAlignmentAnnotation();
769 * Find shown/hidden annotations types, distinguished by source (calcId),
770 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
771 * the insertion order, which is the order of the annotations on the
774 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
775 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
776 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
777 AlignmentAnnotationUtils.asList(annotations), forSequences);
779 for (String calcId : hiddenTypes.keySet())
781 for (List<String> type : hiddenTypes.get(calcId))
783 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
787 // grey out 'show annotations' if none are hidden
788 showMenu.setEnabled(!hiddenTypes.isEmpty());
790 for (String calcId : shownTypes.keySet())
792 for (List<String> type : shownTypes.get(calcId))
794 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
798 // grey out 'hide annotations' if none are shown
799 hideMenu.setEnabled(!shownTypes.isEmpty());
803 * Returns a list of sequences - either the current selection group (if there
804 * is one), else the specified single sequence.
809 protected List<SequenceI> getSequenceScope(SequenceI seq)
811 List<SequenceI> forSequences = null;
812 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
813 if (selectionGroup != null && selectionGroup.getSize() > 0)
815 forSequences = selectionGroup.getSequences();
819 forSequences = seq == null ? Collections.<SequenceI> emptyList()
820 : Arrays.asList(seq);
826 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
829 * @param showOrHideMenu
831 * @param forSequences
832 * the sequences whose annotations may be shown or hidden
837 * if true this is a special label meaning 'All'
838 * @param actionIsShow
839 * if true, the select menu item action is to show the annotation
842 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
843 final List<SequenceI> forSequences, String calcId,
844 final List<String> types, final boolean allTypes,
845 final boolean actionIsShow)
847 String label = types.toString(); // [a, b, c]
848 label = label.substring(1, label.length() - 1); // a, b, c
849 final JMenuItem item = new JMenuItem(label);
850 item.setToolTipText(calcId);
851 item.addActionListener(new java.awt.event.ActionListener()
854 public void actionPerformed(ActionEvent e)
856 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
857 types, forSequences, allTypes, actionIsShow);
861 showOrHideMenu.add(item);
864 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
867 // TODO: usability: thread off the generation of group url content so root
869 // sequence only URLs
870 // ID/regex match URLs
871 groupLinksMenu = new JMenu(
872 MessageManager.getString("action.group_link"));
873 // three types of url that might be created.
874 JMenu[] linkMenus = new JMenu[] { null,
875 new JMenu(MessageManager.getString("action.ids")),
876 new JMenu(MessageManager.getString("action.sequences")),
877 new JMenu(MessageManager.getString("action.ids_sequences")) };
879 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
880 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
881 Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
882 for (int sq = 0; sq < seqs.length; sq++)
885 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
886 .findPosition(sg.getEndRes());
887 // just collect ids from dataset sequence
888 // TODO: check if IDs collected from selecton group intersects with the
889 // current selection, too
890 SequenceI sqi = seqs[sq];
891 while (sqi.getDatasetSequence() != null)
893 sqi = sqi.getDatasetSequence();
895 DBRefEntry[] dbr = sqi.getDBRefs();
896 if (dbr != null && dbr.length > 0)
898 for (int d = 0; d < dbr.length; d++)
900 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
901 Object[] sarray = commonDbrefs.get(src);
904 sarray = new Object[2];
905 sarray[0] = new int[] { 0 };
906 sarray[1] = new String[seqs.length];
908 commonDbrefs.put(src, sarray);
911 if (((String[]) sarray[1])[sq] == null)
914 || (dbr[d].getMap().locateMappedRange(start, end) != null))
916 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
917 ((int[]) sarray[0])[0]++;
923 // now create group links for all distinct ID/sequence sets.
924 boolean addMenu = false; // indicates if there are any group links to give
926 for (String link : groupLinks)
928 GroupUrlLink urlLink = null;
931 urlLink = new GroupUrlLink(link);
932 } catch (Exception foo)
934 Cache.log.error("Exception for GroupURLLink '" + link
939 if (!urlLink.isValid())
941 Cache.log.error(urlLink.getInvalidMessage());
944 final String label = urlLink.getLabel();
945 boolean usingNames = false;
946 // Now see which parts of the group apply for this URL
947 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
948 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
949 String[] seqstr, ids; // input to makeUrl
952 int numinput = ((int[]) idset[0])[0];
953 String[] allids = ((String[]) idset[1]);
954 seqstr = new String[numinput];
955 ids = new String[numinput];
956 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
958 if (allids[sq] != null)
960 ids[idcount] = allids[sq];
961 seqstr[idcount++] = idandseqs[1][sq];
967 // just use the id/seq set
968 seqstr = idandseqs[1];
972 // and try and make the groupURL!
974 Object[] urlset = null;
977 urlset = urlLink.makeUrlStubs(ids, seqstr,
978 "FromJalview" + System.currentTimeMillis(), false);
979 } catch (UrlStringTooLongException e)
984 int type = urlLink.getGroupURLType() & 3;
985 // first two bits ofurlLink type bitfield are sequenceids and sequences
986 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
987 addshowLink(linkMenus[type], label
988 + (((type & 1) == 1) ? ("("
989 + (usingNames ? "Names" : ltarget) + ")") : ""),
996 groupLinksMenu = new JMenu(
997 MessageManager.getString("action.group_link"));
998 for (int m = 0; m < linkMenus.length; m++)
1000 if (linkMenus[m] != null
1001 && linkMenus[m].getMenuComponentCount() > 0)
1003 groupLinksMenu.add(linkMenus[m]);
1007 groupMenu.add(groupLinksMenu);
1012 * add a show URL menu item to the given linkMenu
1016 * - menu label string
1020 private void addshowLink(JMenu linkMenu, String label, final String url)
1022 JMenuItem item = new JMenuItem(label);
1023 item.setToolTipText(MessageManager.formatMessage(
1024 "label.open_url_param", new Object[] { url }));
1025 item.addActionListener(new java.awt.event.ActionListener()
1028 public void actionPerformed(ActionEvent e)
1030 new Thread(new Runnable()
1047 * add a late bound groupURL item to the given linkMenu
1051 * - menu label string
1052 * @param urlgenerator
1053 * GroupURLLink used to generate URL
1055 * Object array returned from the makeUrlStubs function.
1057 private void addshowLink(JMenu linkMenu, String label,
1058 final GroupUrlLink urlgenerator, final Object[] urlstub)
1060 JMenuItem item = new JMenuItem(label);
1061 item.setToolTipText(MessageManager.formatMessage(
1062 "label.open_url_seqs_param",
1063 new Object[] { urlgenerator.getUrl_prefix(),
1064 urlgenerator.getNumberInvolved(urlstub) }));
1065 // TODO: put in info about what is being sent.
1066 item.addActionListener(new ActionListener()
1069 public void actionPerformed(ActionEvent e)
1071 new Thread(new Runnable()
1079 showLink(urlgenerator.constructFrom(urlstub));
1080 } catch (UrlStringTooLongException e2)
1098 private void jbInit() throws Exception
1100 groupMenu.setText(MessageManager.getString("label.selection"));
1101 groupName.setText(MessageManager.getString("label.name"));
1102 groupName.addActionListener(new java.awt.event.ActionListener()
1105 public void actionPerformed(ActionEvent e)
1107 groupName_actionPerformed();
1110 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1111 sequenceName.setText(MessageManager
1112 .getString("label.edit_name_description"));
1113 sequenceName.addActionListener(new java.awt.event.ActionListener()
1116 public void actionPerformed(ActionEvent e)
1118 sequenceName_actionPerformed();
1121 chooseAnnotations.setText(MessageManager
1122 .getString("action.choose_annotations"));
1123 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1126 public void actionPerformed(ActionEvent e)
1128 chooseAnnotations_actionPerformed(e);
1131 sequenceDetails.setText(MessageManager
1132 .getString("label.sequence_details"));
1133 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1136 public void actionPerformed(ActionEvent e)
1138 sequenceDetails_actionPerformed();
1141 sequenceSelDetails.setText(MessageManager
1142 .getString("label.sequence_details"));
1144 .addActionListener(new java.awt.event.ActionListener()
1147 public void actionPerformed(ActionEvent e)
1149 sequenceSelectionDetails_actionPerformed();
1152 PIDColour.setFocusPainted(false);
1154 .setText(MessageManager.getString("action.remove_group"));
1155 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1158 public void actionPerformed(ActionEvent e)
1160 unGroupMenuItem_actionPerformed();
1163 createGroupMenuItem.setText(MessageManager
1164 .getString("action.create_group"));
1166 .addActionListener(new java.awt.event.ActionListener()
1169 public void actionPerformed(ActionEvent e)
1171 createGroupMenuItem_actionPerformed();
1175 outline.setText(MessageManager.getString("action.border_colour"));
1176 outline.addActionListener(new java.awt.event.ActionListener()
1179 public void actionPerformed(ActionEvent e)
1181 outline_actionPerformed();
1185 .setText(MessageManager.getString("label.nucleotide"));
1186 nucleotideMenuItem.addActionListener(new ActionListener()
1189 public void actionPerformed(ActionEvent e)
1191 nucleotideMenuItem_actionPerformed();
1194 colourMenu.setText(MessageManager.getString("label.group_colour"));
1195 showBoxes.setText(MessageManager.getString("action.boxes"));
1196 showBoxes.setState(true);
1197 showBoxes.addActionListener(new ActionListener()
1200 public void actionPerformed(ActionEvent e)
1202 showBoxes_actionPerformed();
1205 showText.setText(MessageManager.getString("action.text"));
1206 showText.setState(true);
1207 showText.addActionListener(new ActionListener()
1210 public void actionPerformed(ActionEvent e)
1212 showText_actionPerformed();
1215 showColourText.setText(MessageManager.getString("label.colour_text"));
1216 showColourText.addActionListener(new ActionListener()
1219 public void actionPerformed(ActionEvent e)
1221 showColourText_actionPerformed();
1224 displayNonconserved.setText(MessageManager
1225 .getString("label.show_non_conversed"));
1226 displayNonconserved.setState(true);
1227 displayNonconserved.addActionListener(new ActionListener()
1230 public void actionPerformed(ActionEvent e)
1232 showNonconserved_actionPerformed();
1235 editMenu.setText(MessageManager.getString("action.edit"));
1236 cut.setText(MessageManager.getString("action.cut"));
1237 cut.addActionListener(new ActionListener()
1240 public void actionPerformed(ActionEvent e)
1242 cut_actionPerformed();
1245 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1246 upperCase.addActionListener(new ActionListener()
1249 public void actionPerformed(ActionEvent e)
1254 copy.setText(MessageManager.getString("action.copy"));
1255 copy.addActionListener(new ActionListener()
1258 public void actionPerformed(ActionEvent e)
1260 copy_actionPerformed();
1263 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1264 lowerCase.addActionListener(new ActionListener()
1267 public void actionPerformed(ActionEvent e)
1272 toggle.setText(MessageManager.getString("label.toggle_case"));
1273 toggle.addActionListener(new ActionListener()
1276 public void actionPerformed(ActionEvent e)
1281 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1283 seqShowAnnotationsMenu.setText(MessageManager
1284 .getString("label.show_annotations"));
1285 seqHideAnnotationsMenu.setText(MessageManager
1286 .getString("label.hide_annotations"));
1287 groupShowAnnotationsMenu.setText(MessageManager
1288 .getString("label.show_annotations"));
1289 groupHideAnnotationsMenu.setText(MessageManager
1290 .getString("label.hide_annotations"));
1291 sequenceFeature.setText(MessageManager
1292 .getString("label.create_sequence_feature"));
1293 sequenceFeature.addActionListener(new ActionListener()
1296 public void actionPerformed(ActionEvent e)
1298 sequenceFeature_actionPerformed();
1301 textColour.setText(MessageManager.getString("label.text_colour"));
1302 textColour.addActionListener(new ActionListener()
1305 public void actionPerformed(ActionEvent e)
1307 textColour_actionPerformed();
1310 jMenu1.setText(MessageManager.getString("label.group"));
1311 pdbStructureDialog.setText(MessageManager
1312 .getString("label.show_pdbstruct_dialog"));
1313 pdbStructureDialog.addActionListener(new ActionListener()
1316 public void actionPerformed(ActionEvent actionEvent)
1318 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1319 if (ap.av.getSelectionGroup() != null)
1321 selectedSeqs = ap.av.getSequenceSelection();
1323 new StructureChooser(selectedSeqs, sequence, ap);
1327 rnaStructureMenu.setText(MessageManager
1328 .getString("label.view_rna_structure"));
1330 // colStructureMenu.setText("Colour By Structure");
1331 editSequence.setText(MessageManager.getString("label.edit_sequence")
1333 editSequence.addActionListener(new ActionListener()
1336 public void actionPerformed(ActionEvent actionEvent)
1338 editSequence_actionPerformed(actionEvent);
1341 makeReferenceSeq.setText(MessageManager
1342 .getString("label.mark_as_representative"));
1343 makeReferenceSeq.addActionListener(new ActionListener()
1347 public void actionPerformed(ActionEvent actionEvent)
1349 makeReferenceSeq_actionPerformed(actionEvent);
1353 hideInsertions.setText(MessageManager
1354 .getString("label.hide_insertions"));
1355 hideInsertions.addActionListener(new ActionListener()
1359 public void actionPerformed(ActionEvent e)
1361 hideInsertions_actionPerformed(e);
1365 * annotationMenuItem.setText("By Annotation");
1366 * annotationMenuItem.addActionListener(new ActionListener() { public void
1367 * actionPerformed(ActionEvent actionEvent) {
1368 * annotationMenuItem_actionPerformed(actionEvent); } });
1370 groupMenu.add(sequenceSelDetails);
1373 add(rnaStructureMenu);
1374 add(pdbStructureDialog);
1375 if (sequence != null)
1377 add(hideInsertions);
1379 // annotations configuration panel suppressed for now
1380 // groupMenu.add(chooseAnnotations);
1383 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1384 * (if a selection group is in force).
1386 sequenceMenu.add(seqShowAnnotationsMenu);
1387 sequenceMenu.add(seqHideAnnotationsMenu);
1388 sequenceMenu.add(seqAddReferenceAnnotations);
1389 groupMenu.add(groupShowAnnotationsMenu);
1390 groupMenu.add(groupHideAnnotationsMenu);
1391 groupMenu.add(groupAddReferenceAnnotations);
1392 groupMenu.add(editMenu);
1393 groupMenu.add(outputMenu);
1394 groupMenu.add(sequenceFeature);
1395 groupMenu.add(createGroupMenuItem);
1396 groupMenu.add(unGroupMenuItem);
1397 groupMenu.add(jMenu1);
1398 sequenceMenu.add(sequenceName);
1399 sequenceMenu.add(sequenceDetails);
1400 sequenceMenu.add(makeReferenceSeq);
1401 colourMenu.add(textColour);
1402 colourMenu.add(noColourmenuItem);
1403 colourMenu.add(clustalColour);
1404 colourMenu.add(BLOSUM62Colour);
1405 colourMenu.add(PIDColour);
1406 colourMenu.add(zappoColour);
1407 colourMenu.add(taylorColour);
1408 colourMenu.add(hydrophobicityColour);
1409 colourMenu.add(helixColour);
1410 colourMenu.add(strandColour);
1411 colourMenu.add(turnColour);
1412 colourMenu.add(buriedColour);
1413 colourMenu.add(nucleotideMenuItem);
1414 if (ap.getAlignment().isNucleotide())
1416 // JBPNote - commented since the colourscheme isn't functional
1417 colourMenu.add(purinePyrimidineColour);
1419 colourMenu.add(userDefinedColour);
1421 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1423 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1424 .getUserColourSchemes().keys();
1426 while (userColours.hasMoreElements())
1428 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1429 item.addActionListener(new ActionListener()
1432 public void actionPerformed(ActionEvent evt)
1434 userDefinedColour_actionPerformed(evt);
1437 colourMenu.add(item);
1441 colourMenu.addSeparator();
1442 colourMenu.add(abovePIDColour);
1443 colourMenu.add(conservationMenuItem);
1446 editMenu.add(editSequence);
1447 editMenu.add(upperCase);
1448 editMenu.add(lowerCase);
1449 editMenu.add(toggle);
1450 // JBPNote: These shouldn't be added here - should appear in a generic
1451 // 'apply web service to this sequence menu'
1452 // pdbMenu.add(RNAFold);
1453 // pdbMenu.add(ContraFold);
1454 jMenu1.add(groupName);
1455 jMenu1.add(colourMenu);
1456 jMenu1.add(showBoxes);
1457 jMenu1.add(showText);
1458 jMenu1.add(showColourText);
1459 jMenu1.add(outline);
1460 jMenu1.add(displayNonconserved);
1461 noColourmenuItem.setText(MessageManager.getString("label.none"));
1462 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1465 public void actionPerformed(ActionEvent e)
1467 noColourmenuItem_actionPerformed();
1471 clustalColour.setText(MessageManager
1472 .getString("label.clustalx_colours"));
1473 clustalColour.addActionListener(new java.awt.event.ActionListener()
1476 public void actionPerformed(ActionEvent e)
1478 clustalColour_actionPerformed();
1481 zappoColour.setText(MessageManager.getString("label.zappo"));
1482 zappoColour.addActionListener(new java.awt.event.ActionListener()
1485 public void actionPerformed(ActionEvent e)
1487 zappoColour_actionPerformed();
1490 taylorColour.setText(MessageManager.getString("label.taylor"));
1491 taylorColour.addActionListener(new java.awt.event.ActionListener()
1494 public void actionPerformed(ActionEvent e)
1496 taylorColour_actionPerformed();
1499 hydrophobicityColour.setText(MessageManager
1500 .getString("label.hydrophobicity"));
1501 hydrophobicityColour
1502 .addActionListener(new java.awt.event.ActionListener()
1505 public void actionPerformed(ActionEvent e)
1507 hydrophobicityColour_actionPerformed();
1510 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1511 helixColour.addActionListener(new java.awt.event.ActionListener()
1514 public void actionPerformed(ActionEvent e)
1516 helixColour_actionPerformed();
1519 strandColour.setText(MessageManager
1520 .getString("label.strand_propensity"));
1521 strandColour.addActionListener(new java.awt.event.ActionListener()
1524 public void actionPerformed(ActionEvent e)
1526 strandColour_actionPerformed();
1529 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1530 turnColour.addActionListener(new java.awt.event.ActionListener()
1533 public void actionPerformed(ActionEvent e)
1535 turnColour_actionPerformed();
1538 buriedColour.setText(MessageManager.getString("label.buried_index"));
1539 buriedColour.addActionListener(new java.awt.event.ActionListener()
1542 public void actionPerformed(ActionEvent e)
1544 buriedColour_actionPerformed();
1547 abovePIDColour.setText(MessageManager
1548 .getString("label.above_identity_percentage"));
1549 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1552 public void actionPerformed(ActionEvent e)
1554 abovePIDColour_actionPerformed();
1557 userDefinedColour.setText(MessageManager
1558 .getString("action.user_defined"));
1559 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1562 public void actionPerformed(ActionEvent e)
1564 userDefinedColour_actionPerformed(e);
1568 .setText(MessageManager.getString("label.percentage_identity"));
1569 PIDColour.addActionListener(new java.awt.event.ActionListener()
1572 public void actionPerformed(ActionEvent e)
1574 PIDColour_actionPerformed();
1577 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1578 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1581 public void actionPerformed(ActionEvent e)
1583 BLOSUM62Colour_actionPerformed();
1586 purinePyrimidineColour.setText(MessageManager
1587 .getString("label.purine_pyrimidine"));
1588 purinePyrimidineColour
1589 .addActionListener(new java.awt.event.ActionListener()
1592 public void actionPerformed(ActionEvent e)
1594 purinePyrimidineColour_actionPerformed();
1599 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1600 * public void actionPerformed(ActionEvent e) {
1601 * covariationColour_actionPerformed(); } });
1604 conservationMenuItem.setText(MessageManager
1605 .getString("label.conservation"));
1606 conservationMenuItem
1607 .addActionListener(new java.awt.event.ActionListener()
1610 public void actionPerformed(ActionEvent e)
1612 conservationMenuItem_actionPerformed();
1618 * Check for any annotations on the underlying dataset sequences (for the
1619 * current selection group) which are not 'on the alignment'.If any are found,
1620 * enable the option to add them to the alignment. The criteria for 'on the
1621 * alignment' is finding an alignment annotation on the alignment, matched on
1622 * calcId, label and sequenceRef.
1624 * A tooltip is also constructed that displays the source (calcId) and type
1625 * (label) of the annotations that can be added.
1628 * @param forSequences
1630 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1631 List<SequenceI> forSequences)
1633 menuItem.setEnabled(false);
1636 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1637 * Using TreeMap means calcIds are shown in alphabetical order.
1639 Map<String, String> tipEntries = new TreeMap<String, String>();
1640 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1641 AlignmentI al = this.ap.av.getAlignment();
1642 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1643 tipEntries, candidates, al);
1644 if (!candidates.isEmpty())
1646 StringBuilder tooltip = new StringBuilder(64);
1647 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1650 * Found annotations that could be added. Enable the menu item, and
1651 * configure its tooltip and action.
1653 menuItem.setEnabled(true);
1654 for (String calcId : tipEntries.keySet())
1656 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1658 String tooltipText = JvSwingUtils.wrapTooltip(true,
1659 tooltip.toString());
1660 menuItem.setToolTipText(tooltipText);
1662 menuItem.addActionListener(new ActionListener()
1665 public void actionPerformed(ActionEvent e)
1667 addReferenceAnnotations_actionPerformed(candidates);
1674 * Add annotations to the sequences and to the alignment.
1677 * a map whose keys are sequences on the alignment, and values a list
1678 * of annotations to add to each sequence
1680 protected void addReferenceAnnotations_actionPerformed(
1681 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1683 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1684 final AlignmentI alignment = this.ap.getAlignment();
1685 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1690 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1692 if (!ap.av.getAlignment().hasSeqrep())
1694 // initialise the display flags so the user sees something happen
1695 ap.av.setDisplayReferenceSeq(true);
1696 ap.av.setColourByReferenceSeq(true);
1697 ap.av.getAlignment().setSeqrep(sequence);
1701 if (ap.av.getAlignment().getSeqrep() == sequence)
1703 ap.av.getAlignment().setSeqrep(null);
1707 ap.av.getAlignment().setSeqrep(sequence);
1713 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1715 if (sequence != null)
1717 ColumnSelection cs = ap.av.getColumnSelection();
1720 cs = new ColumnSelection();
1722 cs.hideInsertionsFor(sequence);
1723 ap.av.setColumnSelection(cs);
1728 protected void sequenceSelectionDetails_actionPerformed()
1730 createSequenceDetailsReport(ap.av.getSequenceSelection());
1733 protected void sequenceDetails_actionPerformed()
1735 createSequenceDetailsReport(new SequenceI[] { sequence });
1738 public void createSequenceDetailsReport(SequenceI[] sequences)
1740 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1741 StringBuffer contents = new StringBuffer();
1742 for (SequenceI seq : sequences)
1744 contents.append("<p><h2>"
1747 "label.create_sequence_details_report_annotation_for",
1748 new Object[] { seq.getDisplayId(true) })
1750 new SequenceAnnotationReport(null)
1751 .createSequenceAnnotationReport(
1757 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1758 .getSeqPanel().seqCanvas.fr.getMinMax()
1760 contents.append("</p>");
1762 cap.setText("<html>" + contents.toString() + "</html>");
1764 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1765 "label.sequence_details_for",
1766 (sequences.length == 1 ? new Object[] { sequences[0]
1767 .getDisplayId(true) } : new Object[] { MessageManager
1768 .getString("label.selection") })), 500, 400);
1772 protected void showNonconserved_actionPerformed()
1774 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1779 * call to refresh view after settings change
1783 ap.updateAnnotation();
1784 ap.paintAlignment(true);
1786 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1795 protected void clustalColour_actionPerformed()
1797 SequenceGroup sg = getGroup();
1798 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1808 protected void zappoColour_actionPerformed()
1810 getGroup().cs = new ZappoColourScheme();
1820 protected void taylorColour_actionPerformed()
1822 getGroup().cs = new TaylorColourScheme();
1832 protected void hydrophobicityColour_actionPerformed()
1834 getGroup().cs = new HydrophobicColourScheme();
1844 protected void helixColour_actionPerformed()
1846 getGroup().cs = new HelixColourScheme();
1856 protected void strandColour_actionPerformed()
1858 getGroup().cs = new StrandColourScheme();
1868 protected void turnColour_actionPerformed()
1870 getGroup().cs = new TurnColourScheme();
1880 protected void buriedColour_actionPerformed()
1882 getGroup().cs = new BuriedColourScheme();
1892 public void nucleotideMenuItem_actionPerformed()
1894 getGroup().cs = new NucleotideColourScheme();
1898 protected void purinePyrimidineColour_actionPerformed()
1900 getGroup().cs = new PurinePyrimidineColourScheme();
1905 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1906 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1914 protected void abovePIDColour_actionPerformed()
1916 SequenceGroup sg = getGroup();
1922 if (abovePIDColour.isSelected())
1924 sg.cs.setConsensus(AAFrequency.calculate(
1925 sg.getSequences(ap.av.getHiddenRepSequences()),
1926 sg.getStartRes(), sg.getEndRes() + 1));
1928 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1931 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1933 SliderPanel.showPIDSlider();
1936 // remove PIDColouring
1938 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1950 protected void userDefinedColour_actionPerformed(ActionEvent e)
1952 SequenceGroup sg = getGroup();
1954 if (e.getSource().equals(userDefinedColour))
1956 new UserDefinedColours(ap, sg);
1960 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1961 .getUserColourSchemes().get(e.getActionCommand());
1969 * Open a panel where the user can choose which types of sequence annotation
1974 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1976 // todo correct way to guard against opening a duplicate panel?
1977 new AnnotationChooser(ap);
1986 protected void PIDColour_actionPerformed()
1988 SequenceGroup sg = getGroup();
1989 sg.cs = new PIDColourScheme();
1990 sg.cs.setConsensus(AAFrequency.calculate(
1991 sg.getSequences(ap.av.getHiddenRepSequences()),
1992 sg.getStartRes(), sg.getEndRes() + 1));
2002 protected void BLOSUM62Colour_actionPerformed()
2004 SequenceGroup sg = getGroup();
2006 sg.cs = new Blosum62ColourScheme();
2008 sg.cs.setConsensus(AAFrequency.calculate(
2009 sg.getSequences(ap.av.getHiddenRepSequences()),
2010 sg.getStartRes(), sg.getEndRes() + 1));
2021 protected void noColourmenuItem_actionPerformed()
2023 getGroup().cs = null;
2033 protected void conservationMenuItem_actionPerformed()
2035 SequenceGroup sg = getGroup();
2041 if (conservationMenuItem.isSelected())
2043 // JBPNote: Conservation name shouldn't be i18n translated
2044 Conservation c = new Conservation("Group",
2045 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2046 .getHiddenRepSequences()), sg.getStartRes(),
2047 sg.getEndRes() + 1);
2050 c.verdict(false, ap.av.getConsPercGaps());
2052 sg.cs.setConservation(c);
2054 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2055 SliderPanel.showConservationSlider();
2058 // remove ConservationColouring
2060 sg.cs.setConservation(null);
2066 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2068 SequenceGroup sg = getGroup();
2074 AnnotationColourGradient acg = new AnnotationColourGradient(
2075 sequence.getAnnotation()[0], null,
2076 AnnotationColourGradient.NO_THRESHOLD);
2078 acg.setPredefinedColours(true);
2090 protected void groupName_actionPerformed()
2093 SequenceGroup sg = getGroup();
2094 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2095 sg.getDescription(), " "
2096 + MessageManager.getString("label.group_name") + " ",
2097 MessageManager.getString("label.group_description") + " ",
2098 MessageManager.getString("label.edit_group_name_description"),
2106 sg.setName(dialog.getName());
2107 sg.setDescription(dialog.getDescription());
2112 * Get selection group - adding it to the alignment if necessary.
2114 * @return sequence group to operate on
2116 SequenceGroup getGroup()
2118 SequenceGroup sg = ap.av.getSelectionGroup();
2119 // this method won't add a new group if it already exists
2122 ap.av.getAlignment().addGroup(sg);
2134 void sequenceName_actionPerformed()
2136 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2137 sequence.getDescription(),
2138 " " + MessageManager.getString("label.sequence_name")
2140 MessageManager.getString("label.sequence_description") + " ",
2142 .getString("label.edit_sequence_name_description"),
2150 if (dialog.getName() != null)
2152 if (dialog.getName().indexOf(" ") > -1)
2158 .getString("label.spaces_converted_to_backslashes"),
2160 .getString("label.no_spaces_allowed_sequence_name"),
2161 JOptionPane.WARNING_MESSAGE);
2164 sequence.setName(dialog.getName().replace(' ', '_'));
2165 ap.paintAlignment(false);
2168 sequence.setDescription(dialog.getDescription());
2170 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2181 void unGroupMenuItem_actionPerformed()
2183 SequenceGroup sg = ap.av.getSelectionGroup();
2184 ap.av.getAlignment().deleteGroup(sg);
2185 ap.av.setSelectionGroup(null);
2189 void createGroupMenuItem_actionPerformed()
2191 getGroup(); // implicitly creates group - note - should apply defaults / use
2192 // standard alignment window logic for this
2202 protected void outline_actionPerformed()
2204 SequenceGroup sg = getGroup();
2205 Color col = JColorChooser.showDialog(this,
2206 MessageManager.getString("label.select_outline_colour"),
2211 sg.setOutlineColour(col);
2223 public void showBoxes_actionPerformed()
2225 getGroup().setDisplayBoxes(showBoxes.isSelected());
2235 public void showText_actionPerformed()
2237 getGroup().setDisplayText(showText.isSelected());
2247 public void showColourText_actionPerformed()
2249 getGroup().setColourText(showColourText.isSelected());
2253 public void showLink(String url)
2257 jalview.util.BrowserLauncher.openURL(url);
2258 } catch (Exception ex)
2260 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2261 MessageManager.getString("label.web_browser_not_found_unix"),
2262 MessageManager.getString("label.web_browser_not_found"),
2263 JOptionPane.WARNING_MESSAGE);
2265 ex.printStackTrace();
2269 void hideSequences(boolean representGroup)
2271 ap.av.hideSequences(sequence, representGroup);
2274 public void copy_actionPerformed()
2276 ap.alignFrame.copy_actionPerformed(null);
2279 public void cut_actionPerformed()
2281 ap.alignFrame.cut_actionPerformed(null);
2284 void changeCase(ActionEvent e)
2286 Object source = e.getSource();
2287 SequenceGroup sg = ap.av.getSelectionGroup();
2291 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2292 sg.getStartRes(), sg.getEndRes() + 1);
2297 if (source == toggle)
2299 description = MessageManager.getString("label.toggle_case");
2300 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2302 else if (source == upperCase)
2304 description = MessageManager.getString("label.to_upper_case");
2305 caseChange = ChangeCaseCommand.TO_UPPER;
2309 description = MessageManager.getString("label.to_lower_case");
2310 caseChange = ChangeCaseCommand.TO_LOWER;
2313 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2314 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2315 startEnd, caseChange);
2317 ap.alignFrame.addHistoryItem(caseCommand);
2319 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2325 public void outputText_actionPerformed(ActionEvent e)
2327 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2328 cap.setForInput(null);
2329 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2330 "label.alignment_output_command",
2331 new Object[] { e.getActionCommand() }), 600, 500);
2333 String[] omitHidden = null;
2335 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2336 // or we simply trust the user wants
2337 // wysiwig behaviour
2339 FileFormatI fileFormat = FileFormat.forName(e.getActionCommand());
2340 cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2343 public void sequenceFeature_actionPerformed()
2345 SequenceGroup sg = ap.av.getSelectionGroup();
2351 int rsize = 0, gSize = sg.getSize();
2352 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2353 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2355 for (int i = 0; i < gSize; i++)
2357 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2358 int end = sg.findEndRes(sg.getSequenceAt(i));
2361 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2362 features[rsize] = new SequenceFeature(null, null, null, start, end,
2367 rseqs = new SequenceI[rsize];
2368 tfeatures = new SequenceFeature[rsize];
2369 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2370 System.arraycopy(features, 0, tfeatures, 0, rsize);
2371 features = tfeatures;
2373 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2374 features, true, ap))
2376 ap.alignFrame.setShowSeqFeatures(true);
2377 ap.highlightSearchResults(null);
2381 public void textColour_actionPerformed()
2383 SequenceGroup sg = getGroup();
2386 new TextColourChooser().chooseColour(ap, sg);
2390 public void colourByStructure(String pdbid)
2392 Annotation[] anots = ap.av.getStructureSelectionManager()
2393 .colourSequenceFromStructure(sequence, pdbid);
2395 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2396 "Coloured by " + pdbid, anots);
2398 ap.av.getAlignment().addAnnotation(an);
2399 an.createSequenceMapping(sequence, 0, true);
2400 // an.adjustForAlignment();
2401 ap.av.getAlignment().setAnnotationIndex(an, 0);
2403 ap.adjustAnnotationHeight();
2405 sequence.addAlignmentAnnotation(an);
2409 public void editSequence_actionPerformed(ActionEvent actionEvent)
2411 SequenceGroup sg = ap.av.getSelectionGroup();
2415 if (sequence == null)
2417 sequence = sg.getSequenceAt(0);
2420 EditNameDialog dialog = new EditNameDialog(
2421 sequence.getSequenceAsString(sg.getStartRes(),
2422 sg.getEndRes() + 1), null,
2423 MessageManager.getString("label.edit_sequence"), null,
2424 MessageManager.getString("label.edit_sequence"),
2429 EditCommand editCommand = new EditCommand(
2430 MessageManager.getString("label.edit_sequences"),
2431 Action.REPLACE, dialog.getName().replace(' ',
2432 ap.av.getGapCharacter()),
2433 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2434 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2436 ap.alignFrame.addHistoryItem(editCommand);
2438 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()