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.FormatAdapter;
42 import jalview.io.SequenceAnnotationReport;
43 import jalview.schemes.AnnotationColourGradient;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.BuriedColourScheme;
46 import jalview.schemes.ClustalxColourScheme;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.HydrophobicColourScheme;
49 import jalview.schemes.NucleotideColourScheme;
50 import jalview.schemes.PIDColourScheme;
51 import jalview.schemes.PurinePyrimidineColourScheme;
52 import jalview.schemes.StrandColourScheme;
53 import jalview.schemes.TaylorColourScheme;
54 import jalview.schemes.TurnColourScheme;
55 import jalview.schemes.UserColourScheme;
56 import jalview.schemes.ZappoColourScheme;
57 import jalview.util.DBRefUtils;
58 import jalview.util.GroupUrlLink;
59 import jalview.util.GroupUrlLink.UrlStringTooLongException;
60 import jalview.util.MessageManager;
61 import jalview.util.UrlLink;
63 import java.awt.Color;
64 import java.awt.event.ActionEvent;
65 import java.awt.event.ActionListener;
66 import java.util.ArrayList;
67 import java.util.Arrays;
68 import java.util.Collections;
69 import java.util.Hashtable;
70 import java.util.LinkedHashMap;
71 import java.util.List;
73 import java.util.TreeMap;
74 import java.util.Vector;
76 import javax.swing.ButtonGroup;
77 import javax.swing.JCheckBoxMenuItem;
78 import javax.swing.JColorChooser;
79 import javax.swing.JMenu;
80 import javax.swing.JMenuItem;
81 import javax.swing.JOptionPane;
82 import javax.swing.JPopupMenu;
83 import javax.swing.JRadioButtonMenuItem;
89 * @version $Revision: 1.118 $
91 public class PopupMenu extends JPopupMenu
93 JMenu groupMenu = new JMenu();
95 JMenuItem groupName = new JMenuItem();
97 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
99 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
101 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
103 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
105 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
107 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
109 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
111 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
113 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
115 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
117 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
119 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
121 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
123 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
125 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
127 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
131 JMenu sequenceMenu = new JMenu();
133 JMenuItem sequenceName = new JMenuItem();
135 JMenuItem sequenceDetails = new JMenuItem();
137 JMenuItem sequenceSelDetails = new JMenuItem();
139 JMenuItem makeReferenceSeq = new JMenuItem();
141 JMenuItem chooseAnnotations = new JMenuItem();
145 JMenuItem createGroupMenuItem = new JMenuItem();
147 JMenuItem unGroupMenuItem = new JMenuItem();
149 JMenuItem outline = new JMenuItem();
151 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
153 JMenu colourMenu = new JMenu();
155 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
157 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
159 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
161 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
163 JMenu editMenu = new JMenu();
165 JMenuItem cut = new JMenuItem();
167 JMenuItem copy = new JMenuItem();
169 JMenuItem upperCase = new JMenuItem();
171 JMenuItem lowerCase = new JMenuItem();
173 JMenuItem toggle = new JMenuItem();
175 JMenu pdbMenu = new JMenu();
177 JMenu outputMenu = new JMenu();
179 JMenu seqShowAnnotationsMenu = new JMenu();
181 JMenu seqHideAnnotationsMenu = new JMenu();
183 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
184 MessageManager.getString("label.add_reference_annotations"));
186 JMenu groupShowAnnotationsMenu = new JMenu();
188 JMenu groupHideAnnotationsMenu = new JMenu();
190 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
191 MessageManager.getString("label.add_reference_annotations"));
193 JMenuItem sequenceFeature = new JMenuItem();
195 JMenuItem textColour = new JMenuItem();
197 JMenu jMenu1 = new JMenu();
199 JMenuItem pdbStructureDialog = new JMenuItem();
201 JMenu rnaStructureMenu = new JMenu();
203 JMenuItem editSequence = new JMenuItem();
205 JMenu groupLinksMenu;
207 JMenuItem hideInsertions = new JMenuItem();
210 * Creates a new PopupMenu object.
217 public PopupMenu(final AlignmentPanel ap, Sequence seq, List<String> links)
219 this(ap, seq, links, null);
229 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
230 List<String> links, List<String> groupLinks)
232 // /////////////////////////////////////////////////////////
233 // If this is activated from the sequence panel, the user may want to
234 // edit or annotate a particular residue. Therefore display the residue menu
236 // If from the IDPanel, we must display the sequence menu
237 // ////////////////////////////////////////////////////////
241 ButtonGroup colours = new ButtonGroup();
242 colours.add(noColourmenuItem);
243 colours.add(clustalColour);
244 colours.add(zappoColour);
245 colours.add(taylorColour);
246 colours.add(hydrophobicityColour);
247 colours.add(helixColour);
248 colours.add(strandColour);
249 colours.add(turnColour);
250 colours.add(buriedColour);
251 colours.add(abovePIDColour);
252 colours.add(userDefinedColour);
253 colours.add(PIDColour);
254 colours.add(BLOSUM62Colour);
255 colours.add(purinePyrimidineColour);
256 colours.add(RNAInteractionColour);
258 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
260 JMenuItem item = new JMenuItem(
261 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
263 item.addActionListener(new java.awt.event.ActionListener()
266 public void actionPerformed(ActionEvent e)
268 outputText_actionPerformed(e);
272 outputMenu.add(item);
276 * Build menus for annotation types that may be shown or hidden, and for
277 * 'reference annotations' that may be added to the alignment. First for the
278 * currently selected sequence (if there is one):
280 final List<SequenceI> selectedSequence = (seq == null ? Collections
281 .<SequenceI> emptyList() : Arrays.asList(seq));
282 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
283 seqHideAnnotationsMenu, selectedSequence);
284 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
288 * And repeat for the current selection group (if there is one):
290 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
291 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
293 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
294 groupHideAnnotationsMenu, selectedGroup);
295 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
301 } catch (Exception e)
309 sequenceMenu.setText(sequence.getName());
310 if (seq == ap.av.getAlignment().getSeqrep())
312 makeReferenceSeq.setText(MessageManager
313 .getString("action.unmark_as_reference"));
317 makeReferenceSeq.setText(MessageManager
318 .getString("action.set_as_reference"));
321 if (!ap.av.getAlignment().isNucleotide())
323 remove(rnaStructureMenu);
327 int origCount = rnaStructureMenu.getItemCount();
329 * add menu items to 2D-render any alignment or sequence secondary
330 * structure annotation
332 AlignmentAnnotation[] aas = ap.av.getAlignment()
333 .getAlignmentAnnotation();
336 for (final AlignmentAnnotation aa : aas)
338 if (aa.isValidStruc() && aa.sequenceRef == null)
341 * valid alignment RNA secondary structure annotation
343 menuItem = new JMenuItem();
344 menuItem.setText(MessageManager.formatMessage(
345 "label.2d_rna_structure_line",
346 new Object[] { aa.label }));
347 menuItem.addActionListener(new java.awt.event.ActionListener()
350 public void actionPerformed(ActionEvent e)
352 new AppVarna(seq, aa, ap);
355 rnaStructureMenu.add(menuItem);
360 if (seq.getAnnotation() != null)
362 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
363 for (final AlignmentAnnotation aa : seqAnns)
365 if (aa.isValidStruc())
368 * valid sequence RNA secondary structure annotation
370 // TODO: make rnastrucF a bit more nice
371 menuItem = new JMenuItem();
372 menuItem.setText(MessageManager.formatMessage(
373 "label.2d_rna_sequence_name",
374 new Object[] { seq.getName() }));
375 menuItem.addActionListener(new java.awt.event.ActionListener()
378 public void actionPerformed(ActionEvent e)
380 // TODO: VARNA does'nt print gaps in the sequence
381 new AppVarna(seq, aa, ap);
384 rnaStructureMenu.add(menuItem);
388 if (rnaStructureMenu.getItemCount() == origCount)
390 remove(rnaStructureMenu);
394 menuItem = new JMenuItem(
395 MessageManager.getString("action.hide_sequences"));
396 menuItem.addActionListener(new java.awt.event.ActionListener()
399 public void actionPerformed(ActionEvent e)
401 hideSequences(false);
406 if (ap.av.getSelectionGroup() != null
407 && ap.av.getSelectionGroup().getSize() > 1)
409 menuItem = new JMenuItem(MessageManager.formatMessage(
410 "label.represent_group_with",
411 new Object[] { seq.getName() }));
412 menuItem.addActionListener(new java.awt.event.ActionListener()
415 public void actionPerformed(ActionEvent e)
420 sequenceMenu.add(menuItem);
423 if (ap.av.hasHiddenRows())
425 final int index = ap.av.getAlignment().findIndex(seq);
427 if (ap.av.adjustForHiddenSeqs(index)
428 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
430 menuItem = new JMenuItem(
431 MessageManager.getString("action.reveal_sequences"));
432 menuItem.addActionListener(new ActionListener()
435 public void actionPerformed(ActionEvent e)
437 ap.av.showSequence(index);
438 if (ap.overviewPanel != null)
440 ap.overviewPanel.updateOverviewImage();
448 // for the case when no sequences are even visible
449 if (ap.av.hasHiddenRows())
452 menuItem = new JMenuItem(
453 MessageManager.getString("action.reveal_all"));
454 menuItem.addActionListener(new ActionListener()
457 public void actionPerformed(ActionEvent e)
459 ap.av.showAllHiddenSeqs();
460 if (ap.overviewPanel != null)
462 ap.overviewPanel.updateOverviewImage();
472 SequenceGroup sg = ap.av.getSelectionGroup();
473 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
474 .getGroups().contains(sg) : false;
476 if (sg != null && sg.getSize() > 0)
478 groupName.setText(MessageManager
479 .getString("label.edit_name_and_description_current_group"));
481 if (sg.cs instanceof ZappoColourScheme)
483 zappoColour.setSelected(true);
485 else if (sg.cs instanceof TaylorColourScheme)
487 taylorColour.setSelected(true);
489 else if (sg.cs instanceof PIDColourScheme)
491 PIDColour.setSelected(true);
493 else if (sg.cs instanceof Blosum62ColourScheme)
495 BLOSUM62Colour.setSelected(true);
497 else if (sg.cs instanceof UserColourScheme)
499 userDefinedColour.setSelected(true);
501 else if (sg.cs instanceof HydrophobicColourScheme)
503 hydrophobicityColour.setSelected(true);
505 else if (sg.cs instanceof HelixColourScheme)
507 helixColour.setSelected(true);
509 else if (sg.cs instanceof StrandColourScheme)
511 strandColour.setSelected(true);
513 else if (sg.cs instanceof TurnColourScheme)
515 turnColour.setSelected(true);
517 else if (sg.cs instanceof BuriedColourScheme)
519 buriedColour.setSelected(true);
521 else if (sg.cs instanceof ClustalxColourScheme)
523 clustalColour.setSelected(true);
525 else if (sg.cs instanceof PurinePyrimidineColourScheme)
527 purinePyrimidineColour.setSelected(true);
531 * else if (sg.cs instanceof CovariationColourScheme) {
532 * covariationColour.setSelected(true); }
536 noColourmenuItem.setSelected(true);
539 if (sg.cs != null && sg.cs.conservationApplied())
541 conservationMenuItem.setSelected(true);
543 displayNonconserved.setSelected(sg.getShowNonconserved());
544 showText.setSelected(sg.getDisplayText());
545 showColourText.setSelected(sg.getColourText());
546 showBoxes.setSelected(sg.getDisplayBoxes());
547 // add any groupURLs to the groupURL submenu and make it visible
548 if (groupLinks != null && groupLinks.size() > 0)
550 buildGroupURLMenu(sg, groupLinks);
552 // Add a 'show all structures' for the current selection
553 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
554 SequenceI sqass = null;
555 for (SequenceI sq : ap.av.getSequenceSelection())
557 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
558 if (pes != null && pes.size() > 0)
560 reppdb.put(pes.get(0).getId(), pes.get(0));
561 for (PDBEntry pe : pes)
563 pdbe.put(pe.getId(), pe);
573 final PDBEntry[] pe = pdbe.values().toArray(
574 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
575 new PDBEntry[reppdb.size()]);
576 final JMenuItem gpdbview, rpdbview;
581 groupMenu.setVisible(false);
582 editMenu.setVisible(false);
587 createGroupMenuItem.setVisible(true);
588 unGroupMenuItem.setVisible(false);
589 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
593 createGroupMenuItem.setVisible(false);
594 unGroupMenuItem.setVisible(true);
595 jMenu1.setText(MessageManager.getString("action.edit_group"));
600 sequenceMenu.setVisible(false);
601 pdbStructureDialog.setVisible(false);
602 rnaStructureMenu.setVisible(false);
605 if (links != null && links.size() > 0)
607 addFeatureLinks(seq, links);
612 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
617 void addFeatureLinks(final SequenceI seq, List<String> links)
619 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
620 List<String> linkset = new ArrayList<String>();
621 for (String link : links)
623 UrlLink urlLink = null;
626 urlLink = new UrlLink(link);
627 } catch (Exception foo)
629 Cache.log.error("Exception for URLLink '" + link + "'", foo);
633 if (!urlLink.isValid())
635 Cache.log.error(urlLink.getInvalidMessage());
638 final String label = urlLink.getLabel();
639 if (seq != null && urlLink.isDynamic())
642 // collect matching db-refs
643 DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(),
644 new String[] { urlLink.getTarget() });
645 // collect id string too
646 String id = seq.getName();
647 String descr = seq.getDescription();
648 if (descr != null && descr.length() < 1)
655 for (int r = 0; r < dbr.length; r++)
657 if (id != null && dbr[r].getAccessionId().equals(id))
659 // suppress duplicate link creation for the bare sequence ID
660 // string with this link
663 // create Bare ID link for this URL
664 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true);
667 for (int u = 0; u < urls.length; u += 2)
669 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
671 linkset.add(urls[u] + "|" + urls[u + 1]);
672 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
680 // create Bare ID link for this URL
681 String[] urls = urlLink.makeUrls(id, true);
684 for (int u = 0; u < urls.length; u += 2)
686 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
688 linkset.add(urls[u] + "|" + urls[u + 1]);
689 addshowLink(linkMenu, label, urls[u + 1]);
694 // Create urls from description but only for URL links which are regex
696 if (descr != null && urlLink.getRegexReplace() != null)
698 // create link for this URL from description where regex matches
699 String[] urls = urlLink.makeUrls(descr, true);
702 for (int u = 0; u < urls.length; u += 2)
704 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
706 linkset.add(urls[u] + "|" + urls[u + 1]);
707 addshowLink(linkMenu, label, urls[u + 1]);
715 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
717 linkset.add(label + "|" + urlLink.getUrl_prefix());
718 // Add a non-dynamic link
719 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
723 if (sequence != null)
725 sequenceMenu.add(linkMenu);
734 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
735 * "All" is added first, followed by a separator. Then add any annotation
736 * types associated with the current selection. Separate menus are built for
737 * the selected sequence group (if any), and the selected sequence.
739 * Some annotation rows are always rendered together - these can be identified
740 * by a common graphGroup property > -1. Only one of each group will be marked
741 * as visible (to avoid duplication of the display). For such groups we add a
742 * composite type name, e.g.
744 * IUPredWS (Long), IUPredWS (Short)
748 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
749 List<SequenceI> forSequences)
751 showMenu.removeAll();
752 hideMenu.removeAll();
754 final List<String> all = Arrays.asList(new String[] { MessageManager
755 .getString("label.all") });
756 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
757 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
759 showMenu.addSeparator();
760 hideMenu.addSeparator();
762 final AlignmentAnnotation[] annotations = ap.getAlignment()
763 .getAlignmentAnnotation();
766 * Find shown/hidden annotations types, distinguished by source (calcId),
767 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
768 * the insertion order, which is the order of the annotations on the
771 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
772 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
773 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
774 AlignmentAnnotationUtils.asList(annotations), forSequences);
776 for (String calcId : hiddenTypes.keySet())
778 for (List<String> type : hiddenTypes.get(calcId))
780 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
784 // grey out 'show annotations' if none are hidden
785 showMenu.setEnabled(!hiddenTypes.isEmpty());
787 for (String calcId : shownTypes.keySet())
789 for (List<String> type : shownTypes.get(calcId))
791 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
795 // grey out 'hide annotations' if none are shown
796 hideMenu.setEnabled(!shownTypes.isEmpty());
800 * Returns a list of sequences - either the current selection group (if there
801 * is one), else the specified single sequence.
806 protected List<SequenceI> getSequenceScope(SequenceI seq)
808 List<SequenceI> forSequences = null;
809 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
810 if (selectionGroup != null && selectionGroup.getSize() > 0)
812 forSequences = selectionGroup.getSequences();
816 forSequences = seq == null ? Collections.<SequenceI> emptyList()
817 : Arrays.asList(seq);
823 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
826 * @param showOrHideMenu
828 * @param forSequences
829 * the sequences whose annotations may be shown or hidden
834 * if true this is a special label meaning 'All'
835 * @param actionIsShow
836 * if true, the select menu item action is to show the annotation
839 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
840 final List<SequenceI> forSequences, String calcId,
841 final List<String> types, final boolean allTypes,
842 final boolean actionIsShow)
844 String label = types.toString(); // [a, b, c]
845 label = label.substring(1, label.length() - 1); // a, b, c
846 final JMenuItem item = new JMenuItem(label);
847 item.setToolTipText(calcId);
848 item.addActionListener(new java.awt.event.ActionListener()
851 public void actionPerformed(ActionEvent e)
853 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
854 types, forSequences, allTypes, actionIsShow);
858 showOrHideMenu.add(item);
861 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
864 // TODO: usability: thread off the generation of group url content so root
866 // sequence only URLs
867 // ID/regex match URLs
868 groupLinksMenu = new JMenu(
869 MessageManager.getString("action.group_link"));
870 // three types of url that might be created.
871 JMenu[] linkMenus = new JMenu[] { null,
872 new JMenu(MessageManager.getString("action.ids")),
873 new JMenu(MessageManager.getString("action.sequences")),
874 new JMenu(MessageManager.getString("action.ids_sequences")) };
876 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
877 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
878 Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
879 for (int sq = 0; sq < seqs.length; sq++)
882 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
883 .findPosition(sg.getEndRes());
884 // just collect ids from dataset sequence
885 // TODO: check if IDs collected from selecton group intersects with the
886 // current selection, too
887 SequenceI sqi = seqs[sq];
888 while (sqi.getDatasetSequence() != null)
890 sqi = sqi.getDatasetSequence();
892 DBRefEntry[] dbr = sqi.getDBRefs();
893 if (dbr != null && dbr.length > 0)
895 for (int d = 0; d < dbr.length; d++)
897 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
898 Object[] sarray = commonDbrefs.get(src);
901 sarray = new Object[2];
902 sarray[0] = new int[] { 0 };
903 sarray[1] = new String[seqs.length];
905 commonDbrefs.put(src, sarray);
908 if (((String[]) sarray[1])[sq] == null)
911 || (dbr[d].getMap().locateMappedRange(start, end) != null))
913 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
914 ((int[]) sarray[0])[0]++;
920 // now create group links for all distinct ID/sequence sets.
921 boolean addMenu = false; // indicates if there are any group links to give
923 for (String link : groupLinks)
925 GroupUrlLink urlLink = null;
928 urlLink = new GroupUrlLink(link);
929 } catch (Exception foo)
931 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
935 if (!urlLink.isValid())
937 Cache.log.error(urlLink.getInvalidMessage());
940 final String label = urlLink.getLabel();
941 boolean usingNames = false;
942 // Now see which parts of the group apply for this URL
943 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
944 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
945 String[] seqstr, ids; // input to makeUrl
948 int numinput = ((int[]) idset[0])[0];
949 String[] allids = ((String[]) idset[1]);
950 seqstr = new String[numinput];
951 ids = new String[numinput];
952 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
954 if (allids[sq] != null)
956 ids[idcount] = allids[sq];
957 seqstr[idcount++] = idandseqs[1][sq];
963 // just use the id/seq set
964 seqstr = idandseqs[1];
968 // and try and make the groupURL!
970 Object[] urlset = null;
973 urlset = urlLink.makeUrlStubs(ids, seqstr,
974 "FromJalview" + System.currentTimeMillis(), false);
975 } catch (UrlStringTooLongException e)
980 int type = urlLink.getGroupURLType() & 3;
981 // first two bits ofurlLink type bitfield are sequenceids and sequences
982 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
983 addshowLink(linkMenus[type], label
984 + (((type & 1) == 1) ? ("("
985 + (usingNames ? "Names" : ltarget) + ")") : ""),
992 groupLinksMenu = new JMenu(
993 MessageManager.getString("action.group_link"));
994 for (int m = 0; m < linkMenus.length; m++)
996 if (linkMenus[m] != null
997 && linkMenus[m].getMenuComponentCount() > 0)
999 groupLinksMenu.add(linkMenus[m]);
1003 groupMenu.add(groupLinksMenu);
1008 * add a show URL menu item to the given linkMenu
1012 * - menu label string
1016 private void addshowLink(JMenu linkMenu, String label, final String url)
1018 JMenuItem item = new JMenuItem(label);
1019 item.setToolTipText(MessageManager.formatMessage(
1020 "label.open_url_param", new Object[] { url }));
1021 item.addActionListener(new java.awt.event.ActionListener()
1024 public void actionPerformed(ActionEvent e)
1026 new Thread(new Runnable()
1043 * add a late bound groupURL item to the given linkMenu
1047 * - menu label string
1048 * @param urlgenerator
1049 * GroupURLLink used to generate URL
1051 * Object array returned from the makeUrlStubs function.
1053 private void addshowLink(JMenu linkMenu, String label,
1054 final GroupUrlLink urlgenerator, final Object[] urlstub)
1056 JMenuItem item = new JMenuItem(label);
1057 item.setToolTipText(MessageManager.formatMessage(
1058 "label.open_url_seqs_param",
1059 new Object[] { urlgenerator.getUrl_prefix(),
1060 urlgenerator.getNumberInvolved(urlstub) }));
1061 // TODO: put in info about what is being sent.
1062 item.addActionListener(new ActionListener()
1065 public void actionPerformed(ActionEvent e)
1067 new Thread(new Runnable()
1075 showLink(urlgenerator.constructFrom(urlstub));
1076 } catch (UrlStringTooLongException e2)
1094 private void jbInit() throws Exception
1096 groupMenu.setText(MessageManager.getString("label.selection"));
1097 groupName.setText(MessageManager.getString("label.name"));
1098 groupName.addActionListener(new java.awt.event.ActionListener()
1101 public void actionPerformed(ActionEvent e)
1103 groupName_actionPerformed();
1106 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1107 sequenceName.setText(MessageManager
1108 .getString("label.edit_name_description"));
1109 sequenceName.addActionListener(new java.awt.event.ActionListener()
1112 public void actionPerformed(ActionEvent e)
1114 sequenceName_actionPerformed();
1117 chooseAnnotations.setText(MessageManager
1118 .getString("action.choose_annotations"));
1119 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1122 public void actionPerformed(ActionEvent e)
1124 chooseAnnotations_actionPerformed(e);
1127 sequenceDetails.setText(MessageManager
1128 .getString("label.sequence_details"));
1129 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1132 public void actionPerformed(ActionEvent e)
1134 sequenceDetails_actionPerformed();
1137 sequenceSelDetails.setText(MessageManager
1138 .getString("label.sequence_details"));
1140 .addActionListener(new java.awt.event.ActionListener()
1143 public void actionPerformed(ActionEvent e)
1145 sequenceSelectionDetails_actionPerformed();
1148 PIDColour.setFocusPainted(false);
1150 .setText(MessageManager.getString("action.remove_group"));
1151 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1154 public void actionPerformed(ActionEvent e)
1156 unGroupMenuItem_actionPerformed();
1159 createGroupMenuItem.setText(MessageManager
1160 .getString("action.create_group"));
1162 .addActionListener(new java.awt.event.ActionListener()
1165 public void actionPerformed(ActionEvent e)
1167 createGroupMenuItem_actionPerformed();
1171 outline.setText(MessageManager.getString("action.border_colour"));
1172 outline.addActionListener(new java.awt.event.ActionListener()
1175 public void actionPerformed(ActionEvent e)
1177 outline_actionPerformed();
1181 .setText(MessageManager.getString("label.nucleotide"));
1182 nucleotideMenuItem.addActionListener(new ActionListener()
1185 public void actionPerformed(ActionEvent e)
1187 nucleotideMenuItem_actionPerformed();
1190 colourMenu.setText(MessageManager.getString("label.group_colour"));
1191 showBoxes.setText(MessageManager.getString("action.boxes"));
1192 showBoxes.setState(true);
1193 showBoxes.addActionListener(new ActionListener()
1196 public void actionPerformed(ActionEvent e)
1198 showBoxes_actionPerformed();
1201 showText.setText(MessageManager.getString("action.text"));
1202 showText.setState(true);
1203 showText.addActionListener(new ActionListener()
1206 public void actionPerformed(ActionEvent e)
1208 showText_actionPerformed();
1211 showColourText.setText(MessageManager.getString("label.colour_text"));
1212 showColourText.addActionListener(new ActionListener()
1215 public void actionPerformed(ActionEvent e)
1217 showColourText_actionPerformed();
1220 displayNonconserved.setText(MessageManager
1221 .getString("label.show_non_conversed"));
1222 displayNonconserved.setState(true);
1223 displayNonconserved.addActionListener(new ActionListener()
1226 public void actionPerformed(ActionEvent e)
1228 showNonconserved_actionPerformed();
1231 editMenu.setText(MessageManager.getString("action.edit"));
1232 cut.setText(MessageManager.getString("action.cut"));
1233 cut.addActionListener(new ActionListener()
1236 public void actionPerformed(ActionEvent e)
1238 cut_actionPerformed();
1241 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1242 upperCase.addActionListener(new ActionListener()
1245 public void actionPerformed(ActionEvent e)
1250 copy.setText(MessageManager.getString("action.copy"));
1251 copy.addActionListener(new ActionListener()
1254 public void actionPerformed(ActionEvent e)
1256 copy_actionPerformed();
1259 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1260 lowerCase.addActionListener(new ActionListener()
1263 public void actionPerformed(ActionEvent e)
1268 toggle.setText(MessageManager.getString("label.toggle_case"));
1269 toggle.addActionListener(new ActionListener()
1272 public void actionPerformed(ActionEvent e)
1277 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1279 seqShowAnnotationsMenu.setText(MessageManager
1280 .getString("label.show_annotations"));
1281 seqHideAnnotationsMenu.setText(MessageManager
1282 .getString("label.hide_annotations"));
1283 groupShowAnnotationsMenu.setText(MessageManager
1284 .getString("label.show_annotations"));
1285 groupHideAnnotationsMenu.setText(MessageManager
1286 .getString("label.hide_annotations"));
1287 sequenceFeature.setText(MessageManager
1288 .getString("label.create_sequence_feature"));
1289 sequenceFeature.addActionListener(new ActionListener()
1292 public void actionPerformed(ActionEvent e)
1294 sequenceFeature_actionPerformed();
1297 textColour.setText(MessageManager.getString("label.text_colour"));
1298 textColour.addActionListener(new ActionListener()
1301 public void actionPerformed(ActionEvent e)
1303 textColour_actionPerformed();
1306 jMenu1.setText(MessageManager.getString("label.group"));
1307 pdbStructureDialog.setText(MessageManager
1308 .getString("label.show_pdbstruct_dialog"));
1309 pdbStructureDialog.addActionListener(new ActionListener()
1312 public void actionPerformed(ActionEvent actionEvent)
1314 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1315 if (ap.av.getSelectionGroup() != null)
1317 selectedSeqs = ap.av.getSequenceSelection();
1319 new StructureChooser(selectedSeqs, sequence, ap);
1323 rnaStructureMenu.setText(MessageManager
1324 .getString("label.view_rna_structure"));
1326 // colStructureMenu.setText("Colour By Structure");
1327 editSequence.setText(MessageManager.getString("label.edit_sequence")
1329 editSequence.addActionListener(new ActionListener()
1332 public void actionPerformed(ActionEvent actionEvent)
1334 editSequence_actionPerformed(actionEvent);
1337 makeReferenceSeq.setText(MessageManager
1338 .getString("label.mark_as_representative"));
1339 makeReferenceSeq.addActionListener(new ActionListener()
1343 public void actionPerformed(ActionEvent actionEvent)
1345 makeReferenceSeq_actionPerformed(actionEvent);
1349 hideInsertions.setText(MessageManager
1350 .getString("label.hide_insertions"));
1351 hideInsertions.addActionListener(new ActionListener()
1355 public void actionPerformed(ActionEvent e)
1357 hideInsertions_actionPerformed(e);
1361 * annotationMenuItem.setText("By Annotation");
1362 * annotationMenuItem.addActionListener(new ActionListener() { public void
1363 * actionPerformed(ActionEvent actionEvent) {
1364 * annotationMenuItem_actionPerformed(actionEvent); } });
1366 groupMenu.add(sequenceSelDetails);
1369 add(rnaStructureMenu);
1370 add(pdbStructureDialog);
1371 if (sequence != null)
1373 add(hideInsertions);
1375 // annotations configuration panel suppressed for now
1376 // groupMenu.add(chooseAnnotations);
1379 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1380 * (if a selection group is in force).
1382 sequenceMenu.add(seqShowAnnotationsMenu);
1383 sequenceMenu.add(seqHideAnnotationsMenu);
1384 sequenceMenu.add(seqAddReferenceAnnotations);
1385 groupMenu.add(groupShowAnnotationsMenu);
1386 groupMenu.add(groupHideAnnotationsMenu);
1387 groupMenu.add(groupAddReferenceAnnotations);
1388 groupMenu.add(editMenu);
1389 groupMenu.add(outputMenu);
1390 groupMenu.add(sequenceFeature);
1391 groupMenu.add(createGroupMenuItem);
1392 groupMenu.add(unGroupMenuItem);
1393 groupMenu.add(jMenu1);
1394 sequenceMenu.add(sequenceName);
1395 sequenceMenu.add(sequenceDetails);
1396 sequenceMenu.add(makeReferenceSeq);
1397 colourMenu.add(textColour);
1398 colourMenu.add(noColourmenuItem);
1399 colourMenu.add(clustalColour);
1400 colourMenu.add(BLOSUM62Colour);
1401 colourMenu.add(PIDColour);
1402 colourMenu.add(zappoColour);
1403 colourMenu.add(taylorColour);
1404 colourMenu.add(hydrophobicityColour);
1405 colourMenu.add(helixColour);
1406 colourMenu.add(strandColour);
1407 colourMenu.add(turnColour);
1408 colourMenu.add(buriedColour);
1409 colourMenu.add(nucleotideMenuItem);
1410 if (ap.getAlignment().isNucleotide())
1412 // JBPNote - commented since the colourscheme isn't functional
1413 colourMenu.add(purinePyrimidineColour);
1415 colourMenu.add(userDefinedColour);
1417 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1419 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1420 .getUserColourSchemes().keys();
1422 while (userColours.hasMoreElements())
1424 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1425 item.addActionListener(new ActionListener()
1428 public void actionPerformed(ActionEvent evt)
1430 userDefinedColour_actionPerformed(evt);
1433 colourMenu.add(item);
1437 colourMenu.addSeparator();
1438 colourMenu.add(abovePIDColour);
1439 colourMenu.add(conservationMenuItem);
1442 editMenu.add(editSequence);
1443 editMenu.add(upperCase);
1444 editMenu.add(lowerCase);
1445 editMenu.add(toggle);
1446 // JBPNote: These shouldn't be added here - should appear in a generic
1447 // 'apply web service to this sequence menu'
1448 // pdbMenu.add(RNAFold);
1449 // pdbMenu.add(ContraFold);
1450 jMenu1.add(groupName);
1451 jMenu1.add(colourMenu);
1452 jMenu1.add(showBoxes);
1453 jMenu1.add(showText);
1454 jMenu1.add(showColourText);
1455 jMenu1.add(outline);
1456 jMenu1.add(displayNonconserved);
1457 noColourmenuItem.setText(MessageManager.getString("label.none"));
1458 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1461 public void actionPerformed(ActionEvent e)
1463 noColourmenuItem_actionPerformed();
1467 clustalColour.setText(MessageManager
1468 .getString("label.clustalx_colours"));
1469 clustalColour.addActionListener(new java.awt.event.ActionListener()
1472 public void actionPerformed(ActionEvent e)
1474 clustalColour_actionPerformed();
1477 zappoColour.setText(MessageManager.getString("label.zappo"));
1478 zappoColour.addActionListener(new java.awt.event.ActionListener()
1481 public void actionPerformed(ActionEvent e)
1483 zappoColour_actionPerformed();
1486 taylorColour.setText(MessageManager.getString("label.taylor"));
1487 taylorColour.addActionListener(new java.awt.event.ActionListener()
1490 public void actionPerformed(ActionEvent e)
1492 taylorColour_actionPerformed();
1495 hydrophobicityColour.setText(MessageManager
1496 .getString("label.hydrophobicity"));
1497 hydrophobicityColour
1498 .addActionListener(new java.awt.event.ActionListener()
1501 public void actionPerformed(ActionEvent e)
1503 hydrophobicityColour_actionPerformed();
1506 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1507 helixColour.addActionListener(new java.awt.event.ActionListener()
1510 public void actionPerformed(ActionEvent e)
1512 helixColour_actionPerformed();
1515 strandColour.setText(MessageManager
1516 .getString("label.strand_propensity"));
1517 strandColour.addActionListener(new java.awt.event.ActionListener()
1520 public void actionPerformed(ActionEvent e)
1522 strandColour_actionPerformed();
1525 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1526 turnColour.addActionListener(new java.awt.event.ActionListener()
1529 public void actionPerformed(ActionEvent e)
1531 turnColour_actionPerformed();
1534 buriedColour.setText(MessageManager.getString("label.buried_index"));
1535 buriedColour.addActionListener(new java.awt.event.ActionListener()
1538 public void actionPerformed(ActionEvent e)
1540 buriedColour_actionPerformed();
1543 abovePIDColour.setText(MessageManager
1544 .getString("label.above_identity_percentage"));
1545 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1548 public void actionPerformed(ActionEvent e)
1550 abovePIDColour_actionPerformed();
1553 userDefinedColour.setText(MessageManager
1554 .getString("action.user_defined"));
1555 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1558 public void actionPerformed(ActionEvent e)
1560 userDefinedColour_actionPerformed(e);
1564 .setText(MessageManager.getString("label.percentage_identity"));
1565 PIDColour.addActionListener(new java.awt.event.ActionListener()
1568 public void actionPerformed(ActionEvent e)
1570 PIDColour_actionPerformed();
1573 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1574 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1577 public void actionPerformed(ActionEvent e)
1579 BLOSUM62Colour_actionPerformed();
1582 purinePyrimidineColour.setText(MessageManager
1583 .getString("label.purine_pyrimidine"));
1584 purinePyrimidineColour
1585 .addActionListener(new java.awt.event.ActionListener()
1588 public void actionPerformed(ActionEvent e)
1590 purinePyrimidineColour_actionPerformed();
1595 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1596 * public void actionPerformed(ActionEvent e) {
1597 * covariationColour_actionPerformed(); } });
1600 conservationMenuItem.setText(MessageManager
1601 .getString("label.conservation"));
1602 conservationMenuItem
1603 .addActionListener(new java.awt.event.ActionListener()
1606 public void actionPerformed(ActionEvent e)
1608 conservationMenuItem_actionPerformed();
1614 * Check for any annotations on the underlying dataset sequences (for the
1615 * current selection group) which are not 'on the alignment'.If any are found,
1616 * enable the option to add them to the alignment. The criteria for 'on the
1617 * alignment' is finding an alignment annotation on the alignment, matched on
1618 * calcId, label and sequenceRef.
1620 * A tooltip is also constructed that displays the source (calcId) and type
1621 * (label) of the annotations that can be added.
1624 * @param forSequences
1626 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1627 List<SequenceI> forSequences)
1629 menuItem.setEnabled(false);
1632 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1633 * Using TreeMap means calcIds are shown in alphabetical order.
1635 Map<String, String> tipEntries = new TreeMap<String, String>();
1636 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1637 AlignmentI al = this.ap.av.getAlignment();
1638 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1639 tipEntries, candidates, al);
1640 if (!candidates.isEmpty())
1642 StringBuilder tooltip = new StringBuilder(64);
1643 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1646 * Found annotations that could be added. Enable the menu item, and
1647 * configure its tooltip and action.
1649 menuItem.setEnabled(true);
1650 for (String calcId : tipEntries.keySet())
1652 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1654 String tooltipText = JvSwingUtils.wrapTooltip(true,
1655 tooltip.toString());
1656 menuItem.setToolTipText(tooltipText);
1658 menuItem.addActionListener(new ActionListener()
1661 public void actionPerformed(ActionEvent e)
1663 addReferenceAnnotations_actionPerformed(candidates);
1670 * Add annotations to the sequences and to the alignment.
1673 * a map whose keys are sequences on the alignment, and values a list
1674 * of annotations to add to each sequence
1676 protected void addReferenceAnnotations_actionPerformed(
1677 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1679 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1680 final AlignmentI alignment = this.ap.getAlignment();
1681 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1686 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1688 if (!ap.av.getAlignment().hasSeqrep())
1690 // initialise the display flags so the user sees something happen
1691 ap.av.setDisplayReferenceSeq(true);
1692 ap.av.setColourByReferenceSeq(true);
1693 ap.av.getAlignment().setSeqrep(sequence);
1697 if (ap.av.getAlignment().getSeqrep() == sequence)
1699 ap.av.getAlignment().setSeqrep(null);
1703 ap.av.getAlignment().setSeqrep(sequence);
1709 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1711 if (sequence != null)
1713 ColumnSelection cs = ap.av.getColumnSelection();
1716 cs = new ColumnSelection();
1718 cs.hideInsertionsFor(sequence);
1719 ap.av.setColumnSelection(cs);
1724 protected void sequenceSelectionDetails_actionPerformed()
1726 createSequenceDetailsReport(ap.av.getSequenceSelection());
1729 protected void sequenceDetails_actionPerformed()
1731 createSequenceDetailsReport(new SequenceI[] { sequence });
1734 public void createSequenceDetailsReport(SequenceI[] sequences)
1736 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1737 StringBuffer contents = new StringBuffer();
1738 for (SequenceI seq : sequences)
1740 contents.append("<p><h2>"
1743 "label.create_sequence_details_report_annotation_for",
1744 new Object[] { seq.getDisplayId(true) })
1746 new SequenceAnnotationReport(null)
1747 .createSequenceAnnotationReport(
1753 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1754 .getSeqPanel().seqCanvas.fr.getMinMax()
1756 contents.append("</p>");
1758 cap.setText("<html>" + contents.toString() + "</html>");
1760 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1761 "label.sequence_details_for",
1762 (sequences.length == 1 ? new Object[] { sequences[0]
1763 .getDisplayId(true) } : new Object[] { MessageManager
1764 .getString("label.selection") })), 500, 400);
1768 protected void showNonconserved_actionPerformed()
1770 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1775 * call to refresh view after settings change
1779 ap.updateAnnotation();
1780 ap.paintAlignment(true);
1782 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1791 protected void clustalColour_actionPerformed()
1793 SequenceGroup sg = getGroup();
1794 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1804 protected void zappoColour_actionPerformed()
1806 getGroup().cs = new ZappoColourScheme();
1816 protected void taylorColour_actionPerformed()
1818 getGroup().cs = new TaylorColourScheme();
1828 protected void hydrophobicityColour_actionPerformed()
1830 getGroup().cs = new HydrophobicColourScheme();
1840 protected void helixColour_actionPerformed()
1842 getGroup().cs = new HelixColourScheme();
1852 protected void strandColour_actionPerformed()
1854 getGroup().cs = new StrandColourScheme();
1864 protected void turnColour_actionPerformed()
1866 getGroup().cs = new TurnColourScheme();
1876 protected void buriedColour_actionPerformed()
1878 getGroup().cs = new BuriedColourScheme();
1888 public void nucleotideMenuItem_actionPerformed()
1890 getGroup().cs = new NucleotideColourScheme();
1894 protected void purinePyrimidineColour_actionPerformed()
1896 getGroup().cs = new PurinePyrimidineColourScheme();
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 = (UserColourScheme) 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", 3, 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 JOptionPane.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 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2256 MessageManager.getString("label.web_browser_not_found_unix"),
2257 MessageManager.getString("label.web_browser_not_found"),
2258 JOptionPane.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 cap.setText(new FormatAdapter(ap).formatSequences(e.getActionCommand(),
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()