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.ResidueProperties;
53 import jalview.schemes.StrandColourScheme;
54 import jalview.schemes.TaylorColourScheme;
55 import jalview.schemes.TurnColourScheme;
56 import jalview.schemes.UserColourScheme;
57 import jalview.schemes.ZappoColourScheme;
58 import jalview.util.DBRefUtils;
59 import jalview.util.GroupUrlLink;
60 import jalview.util.GroupUrlLink.UrlStringTooLongException;
61 import jalview.util.MessageManager;
62 import jalview.util.UrlLink;
64 import java.awt.Color;
65 import java.awt.event.ActionEvent;
66 import java.awt.event.ActionListener;
67 import java.util.ArrayList;
68 import java.util.Arrays;
69 import java.util.Collections;
70 import java.util.Hashtable;
71 import java.util.LinkedHashMap;
72 import java.util.List;
74 import java.util.TreeMap;
75 import java.util.Vector;
77 import javax.swing.ButtonGroup;
78 import javax.swing.JCheckBoxMenuItem;
79 import javax.swing.JColorChooser;
80 import javax.swing.JMenu;
81 import javax.swing.JMenuItem;
82 import javax.swing.JOptionPane;
83 import javax.swing.JPopupMenu;
84 import javax.swing.JRadioButtonMenuItem;
90 * @version $Revision: 1.118 $
92 public class PopupMenu extends JPopupMenu
94 private static final String ALL_ANNOTATIONS = "All";
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.formatMessage("label.name_param",
482 new Object[] { sg.getName() }));
483 groupName.setText(MessageManager
484 .getString("label.edit_name_and_description_current_group"));
486 if (sg.cs instanceof ZappoColourScheme)
488 zappoColour.setSelected(true);
490 else if (sg.cs instanceof TaylorColourScheme)
492 taylorColour.setSelected(true);
494 else if (sg.cs instanceof PIDColourScheme)
496 PIDColour.setSelected(true);
498 else if (sg.cs instanceof Blosum62ColourScheme)
500 BLOSUM62Colour.setSelected(true);
502 else if (sg.cs instanceof UserColourScheme)
504 userDefinedColour.setSelected(true);
506 else if (sg.cs instanceof HydrophobicColourScheme)
508 hydrophobicityColour.setSelected(true);
510 else if (sg.cs instanceof HelixColourScheme)
512 helixColour.setSelected(true);
514 else if (sg.cs instanceof StrandColourScheme)
516 strandColour.setSelected(true);
518 else if (sg.cs instanceof TurnColourScheme)
520 turnColour.setSelected(true);
522 else if (sg.cs instanceof BuriedColourScheme)
524 buriedColour.setSelected(true);
526 else if (sg.cs instanceof ClustalxColourScheme)
528 clustalColour.setSelected(true);
530 else if (sg.cs instanceof PurinePyrimidineColourScheme)
532 purinePyrimidineColour.setSelected(true);
536 * else if (sg.cs instanceof CovariationColourScheme) {
537 * covariationColour.setSelected(true); }
541 noColourmenuItem.setSelected(true);
544 if (sg.cs != null && sg.cs.conservationApplied())
546 conservationMenuItem.setSelected(true);
548 displayNonconserved.setSelected(sg.getShowNonconserved());
549 showText.setSelected(sg.getDisplayText());
550 showColourText.setSelected(sg.getColourText());
551 showBoxes.setSelected(sg.getDisplayBoxes());
552 // add any groupURLs to the groupURL submenu and make it visible
553 if (groupLinks != null && groupLinks.size() > 0)
555 buildGroupURLMenu(sg, groupLinks);
557 // Add a 'show all structures' for the current selection
558 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
559 SequenceI sqass = null;
560 for (SequenceI sq : ap.av.getSequenceSelection())
562 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
563 if (pes != null && pes.size() > 0)
565 reppdb.put(pes.get(0).getId(), pes.get(0));
566 for (PDBEntry pe : pes)
568 pdbe.put(pe.getId(), pe);
578 final PDBEntry[] pe = pdbe.values().toArray(
579 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
580 new PDBEntry[reppdb.size()]);
581 final JMenuItem gpdbview, rpdbview;
586 groupMenu.setVisible(false);
587 editMenu.setVisible(false);
592 createGroupMenuItem.setVisible(true);
593 unGroupMenuItem.setVisible(false);
594 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
598 createGroupMenuItem.setVisible(false);
599 unGroupMenuItem.setVisible(true);
600 jMenu1.setText(MessageManager.getString("action.edit_group"));
605 sequenceMenu.setVisible(false);
606 pdbStructureDialog.setVisible(false);
607 rnaStructureMenu.setVisible(false);
610 if (links != null && links.size() > 0)
612 addFeatureLinks(seq, links);
617 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
622 void addFeatureLinks(final SequenceI seq, List<String> links)
624 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
625 List<String> linkset = new ArrayList<String>();
626 for (String link : links)
628 UrlLink urlLink = null;
631 urlLink = new UrlLink(link);
632 } catch (Exception foo)
634 Cache.log.error("Exception for URLLink '" + link + "'", foo);
638 if (!urlLink.isValid())
640 Cache.log.error(urlLink.getInvalidMessage());
643 final String label = urlLink.getLabel();
644 if (seq != null && urlLink.isDynamic())
647 // collect matching db-refs
648 DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(),
649 new String[] { urlLink.getTarget() });
650 // collect id string too
651 String id = seq.getName();
652 String descr = seq.getDescription();
653 if (descr != null && descr.length() < 1)
660 for (int r = 0; r < dbr.length; r++)
662 if (id != null && dbr[r].getAccessionId().equals(id))
664 // suppress duplicate link creation for the bare sequence ID
665 // string with this link
668 // create Bare ID link for this URL
669 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true);
672 for (int u = 0; u < urls.length; u += 2)
674 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
676 linkset.add(urls[u] + "|" + urls[u + 1]);
677 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
685 // create Bare ID link for this URL
686 String[] urls = urlLink.makeUrls(id, true);
689 for (int u = 0; u < urls.length; u += 2)
691 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
693 linkset.add(urls[u] + "|" + urls[u + 1]);
694 addshowLink(linkMenu, label, urls[u + 1]);
699 // Create urls from description but only for URL links which are regex
701 if (descr != null && urlLink.getRegexReplace() != null)
703 // create link for this URL from description where regex matches
704 String[] urls = urlLink.makeUrls(descr, true);
707 for (int u = 0; u < urls.length; u += 2)
709 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
711 linkset.add(urls[u] + "|" + urls[u + 1]);
712 addshowLink(linkMenu, label, urls[u + 1]);
720 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
722 linkset.add(label + "|" + urlLink.getUrl_prefix());
723 // Add a non-dynamic link
724 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
728 if (sequence != null)
730 sequenceMenu.add(linkMenu);
739 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
740 * "All" is added first, followed by a separator. Then add any annotation
741 * types associated with the current selection. Separate menus are built for
742 * the selected sequence group (if any), and the selected sequence.
744 * Some annotation rows are always rendered together - these can be identified
745 * by a common graphGroup property > -1. Only one of each group will be marked
746 * as visible (to avoid duplication of the display). For such groups we add a
747 * composite type name, e.g.
749 * IUPredWS (Long), IUPredWS (Short)
753 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
754 List<SequenceI> forSequences)
756 showMenu.removeAll();
757 hideMenu.removeAll();
759 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
760 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
761 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
763 showMenu.addSeparator();
764 hideMenu.addSeparator();
766 final AlignmentAnnotation[] annotations = ap.getAlignment()
767 .getAlignmentAnnotation();
770 * Find shown/hidden annotations types, distinguished by source (calcId),
771 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
772 * the insertion order, which is the order of the annotations on the
775 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
776 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
777 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
778 AlignmentAnnotationUtils.asList(annotations), forSequences);
780 for (String calcId : hiddenTypes.keySet())
782 for (List<String> type : hiddenTypes.get(calcId))
784 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
788 // grey out 'show annotations' if none are hidden
789 showMenu.setEnabled(!hiddenTypes.isEmpty());
791 for (String calcId : shownTypes.keySet())
793 for (List<String> type : shownTypes.get(calcId))
795 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
799 // grey out 'hide annotations' if none are shown
800 hideMenu.setEnabled(!shownTypes.isEmpty());
804 * Returns a list of sequences - either the current selection group (if there
805 * is one), else the specified single sequence.
810 protected List<SequenceI> getSequenceScope(SequenceI seq)
812 List<SequenceI> forSequences = null;
813 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
814 if (selectionGroup != null && selectionGroup.getSize() > 0)
816 forSequences = selectionGroup.getSequences();
820 forSequences = seq == null ? Collections.<SequenceI> emptyList()
821 : Arrays.asList(seq);
827 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
830 * @param showOrHideMenu
832 * @param forSequences
833 * the sequences whose annotations may be shown or hidden
838 * if true this is a special label meaning 'All'
839 * @param actionIsShow
840 * if true, the select menu item action is to show the annotation
843 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
844 final List<SequenceI> forSequences, String calcId,
845 final List<String> types, final boolean allTypes,
846 final boolean actionIsShow)
848 String label = types.toString(); // [a, b, c]
849 label = label.substring(1, label.length() - 1); // a, b, c
850 final JMenuItem item = new JMenuItem(label);
851 item.setToolTipText(calcId);
852 item.addActionListener(new java.awt.event.ActionListener()
855 public void actionPerformed(ActionEvent e)
857 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
858 types, forSequences, allTypes, actionIsShow);
862 showOrHideMenu.add(item);
865 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
868 // TODO: usability: thread off the generation of group url content so root
870 // sequence only URLs
871 // ID/regex match URLs
872 groupLinksMenu = new JMenu(
873 MessageManager.getString("action.group_link"));
874 // three types of url that might be created.
875 JMenu[] linkMenus = new JMenu[] { null,
876 new JMenu(MessageManager.getString("action.ids")),
877 new JMenu(MessageManager.getString("action.sequences")),
878 new JMenu(MessageManager.getString("action.ids_sequences")) };
880 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
881 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
882 Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
883 for (int sq = 0; sq < seqs.length; sq++)
886 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
887 .findPosition(sg.getEndRes());
888 // just collect ids from dataset sequence
889 // TODO: check if IDs collected from selecton group intersects with the
890 // current selection, too
891 SequenceI sqi = seqs[sq];
892 while (sqi.getDatasetSequence() != null)
894 sqi = sqi.getDatasetSequence();
896 DBRefEntry[] dbr = sqi.getDBRefs();
897 if (dbr != null && dbr.length > 0)
899 for (int d = 0; d < dbr.length; d++)
901 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
902 Object[] sarray = commonDbrefs.get(src);
905 sarray = new Object[2];
906 sarray[0] = new int[] { 0 };
907 sarray[1] = new String[seqs.length];
909 commonDbrefs.put(src, sarray);
912 if (((String[]) sarray[1])[sq] == null)
915 || (dbr[d].getMap().locateMappedRange(start, end) != null))
917 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
918 ((int[]) sarray[0])[0]++;
924 // now create group links for all distinct ID/sequence sets.
925 boolean addMenu = false; // indicates if there are any group links to give
927 for (String link : groupLinks)
929 GroupUrlLink urlLink = null;
932 urlLink = new GroupUrlLink(link);
933 } catch (Exception foo)
935 Cache.log.error("Exception for GroupURLLink '" + link
940 if (!urlLink.isValid())
942 Cache.log.error(urlLink.getInvalidMessage());
945 final String label = urlLink.getLabel();
946 boolean usingNames = false;
947 // Now see which parts of the group apply for this URL
948 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
949 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
950 String[] seqstr, ids; // input to makeUrl
953 int numinput = ((int[]) idset[0])[0];
954 String[] allids = ((String[]) idset[1]);
955 seqstr = new String[numinput];
956 ids = new String[numinput];
957 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
959 if (allids[sq] != null)
961 ids[idcount] = allids[sq];
962 seqstr[idcount++] = idandseqs[1][sq];
968 // just use the id/seq set
969 seqstr = idandseqs[1];
973 // and try and make the groupURL!
975 Object[] urlset = null;
978 urlset = urlLink.makeUrlStubs(ids, seqstr,
979 "FromJalview" + System.currentTimeMillis(), false);
980 } catch (UrlStringTooLongException e)
985 int type = urlLink.getGroupURLType() & 3;
986 // first two bits ofurlLink type bitfield are sequenceids and sequences
987 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
988 addshowLink(linkMenus[type], label
989 + (((type & 1) == 1) ? ("("
990 + (usingNames ? "Names" : ltarget) + ")") : ""),
997 groupLinksMenu = new JMenu(
998 MessageManager.getString("action.group_link"));
999 for (int m = 0; m < linkMenus.length; m++)
1001 if (linkMenus[m] != null
1002 && linkMenus[m].getMenuComponentCount() > 0)
1004 groupLinksMenu.add(linkMenus[m]);
1008 groupMenu.add(groupLinksMenu);
1013 * add a show URL menu item to the given linkMenu
1017 * - menu label string
1021 private void addshowLink(JMenu linkMenu, String label, final String url)
1023 JMenuItem item = new JMenuItem(label);
1024 item.setToolTipText(MessageManager.formatMessage(
1025 "label.open_url_param", new Object[] { url }));
1026 item.addActionListener(new java.awt.event.ActionListener()
1029 public void actionPerformed(ActionEvent e)
1031 new Thread(new Runnable()
1048 * add a late bound groupURL item to the given linkMenu
1052 * - menu label string
1053 * @param urlgenerator
1054 * GroupURLLink used to generate URL
1056 * Object array returned from the makeUrlStubs function.
1058 private void addshowLink(JMenu linkMenu, String label,
1059 final GroupUrlLink urlgenerator, final Object[] urlstub)
1061 JMenuItem item = new JMenuItem(label);
1062 item.setToolTipText(MessageManager.formatMessage(
1063 "label.open_url_seqs_param",
1064 new Object[] { urlgenerator.getUrl_prefix(),
1065 urlgenerator.getNumberInvolved(urlstub) }));
1066 // TODO: put in info about what is being sent.
1067 item.addActionListener(new ActionListener()
1070 public void actionPerformed(ActionEvent e)
1072 new Thread(new Runnable()
1080 showLink(urlgenerator.constructFrom(urlstub));
1081 } catch (UrlStringTooLongException e2)
1099 private void jbInit() throws Exception
1101 groupMenu.setText(MessageManager.getString("label.group"));
1102 groupMenu.setText(MessageManager.getString("label.selection"));
1103 groupName.setText(MessageManager.getString("label.name"));
1104 groupName.addActionListener(new java.awt.event.ActionListener()
1107 public void actionPerformed(ActionEvent e)
1109 groupName_actionPerformed();
1112 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1113 sequenceName.setText(MessageManager
1114 .getString("label.edit_name_description"));
1115 sequenceName.addActionListener(new java.awt.event.ActionListener()
1118 public void actionPerformed(ActionEvent e)
1120 sequenceName_actionPerformed();
1123 chooseAnnotations.setText(MessageManager
1124 .getString("action.choose_annotations"));
1125 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1128 public void actionPerformed(ActionEvent e)
1130 chooseAnnotations_actionPerformed(e);
1133 sequenceDetails.setText(MessageManager
1134 .getString("label.sequence_details"));
1135 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1138 public void actionPerformed(ActionEvent e)
1140 sequenceDetails_actionPerformed();
1143 sequenceSelDetails.setText(MessageManager
1144 .getString("label.sequence_details"));
1146 .addActionListener(new java.awt.event.ActionListener()
1149 public void actionPerformed(ActionEvent e)
1151 sequenceSelectionDetails_actionPerformed();
1154 PIDColour.setFocusPainted(false);
1156 .setText(MessageManager.getString("action.remove_group"));
1157 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1160 public void actionPerformed(ActionEvent e)
1162 unGroupMenuItem_actionPerformed();
1165 createGroupMenuItem.setText(MessageManager
1166 .getString("action.create_group"));
1168 .addActionListener(new java.awt.event.ActionListener()
1171 public void actionPerformed(ActionEvent e)
1173 createGroupMenuItem_actionPerformed();
1177 outline.setText(MessageManager.getString("action.border_colour"));
1178 outline.addActionListener(new java.awt.event.ActionListener()
1181 public void actionPerformed(ActionEvent e)
1183 outline_actionPerformed();
1187 .setText(MessageManager.getString("label.nucleotide"));
1188 nucleotideMenuItem.addActionListener(new ActionListener()
1191 public void actionPerformed(ActionEvent e)
1193 nucleotideMenuItem_actionPerformed();
1196 colourMenu.setText(MessageManager.getString("label.group_colour"));
1197 showBoxes.setText(MessageManager.getString("action.boxes"));
1198 showBoxes.setState(true);
1199 showBoxes.addActionListener(new ActionListener()
1202 public void actionPerformed(ActionEvent e)
1204 showBoxes_actionPerformed();
1207 showText.setText(MessageManager.getString("action.text"));
1208 showText.setState(true);
1209 showText.addActionListener(new ActionListener()
1212 public void actionPerformed(ActionEvent e)
1214 showText_actionPerformed();
1217 showColourText.setText(MessageManager.getString("label.colour_text"));
1218 showColourText.addActionListener(new ActionListener()
1221 public void actionPerformed(ActionEvent e)
1223 showColourText_actionPerformed();
1226 displayNonconserved.setText(MessageManager
1227 .getString("label.show_non_conversed"));
1228 displayNonconserved.setState(true);
1229 displayNonconserved.addActionListener(new ActionListener()
1232 public void actionPerformed(ActionEvent e)
1234 showNonconserved_actionPerformed();
1237 editMenu.setText(MessageManager.getString("action.edit"));
1238 cut.setText(MessageManager.getString("action.cut"));
1239 cut.addActionListener(new ActionListener()
1242 public void actionPerformed(ActionEvent e)
1244 cut_actionPerformed();
1247 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1248 upperCase.addActionListener(new ActionListener()
1251 public void actionPerformed(ActionEvent e)
1256 copy.setText(MessageManager.getString("action.copy"));
1257 copy.addActionListener(new ActionListener()
1260 public void actionPerformed(ActionEvent e)
1262 copy_actionPerformed();
1265 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1266 lowerCase.addActionListener(new ActionListener()
1269 public void actionPerformed(ActionEvent e)
1274 toggle.setText(MessageManager.getString("label.toggle_case"));
1275 toggle.addActionListener(new ActionListener()
1278 public void actionPerformed(ActionEvent e)
1283 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1285 seqShowAnnotationsMenu.setText(MessageManager
1286 .getString("label.show_annotations"));
1287 seqHideAnnotationsMenu.setText(MessageManager
1288 .getString("label.hide_annotations"));
1289 groupShowAnnotationsMenu.setText(MessageManager
1290 .getString("label.show_annotations"));
1291 groupHideAnnotationsMenu.setText(MessageManager
1292 .getString("label.hide_annotations"));
1293 sequenceFeature.setText(MessageManager
1294 .getString("label.create_sequence_feature"));
1295 sequenceFeature.addActionListener(new ActionListener()
1298 public void actionPerformed(ActionEvent e)
1300 sequenceFeature_actionPerformed();
1303 textColour.setText(MessageManager.getString("label.text_colour"));
1304 textColour.addActionListener(new ActionListener()
1307 public void actionPerformed(ActionEvent e)
1309 textColour_actionPerformed();
1312 jMenu1.setText(MessageManager.getString("label.group"));
1313 pdbStructureDialog.setText(MessageManager
1314 .getString("label.show_pdbstruct_dialog"));
1315 pdbStructureDialog.addActionListener(new ActionListener()
1318 public void actionPerformed(ActionEvent actionEvent)
1320 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1321 if (ap.av.getSelectionGroup() != null)
1323 selectedSeqs = ap.av.getSequenceSelection();
1325 new StructureChooser(selectedSeqs, sequence, ap);
1329 rnaStructureMenu.setText(MessageManager
1330 .getString("label.view_rna_structure"));
1332 // colStructureMenu.setText("Colour By Structure");
1333 editSequence.setText(MessageManager.getString("label.edit_sequence")
1335 editSequence.addActionListener(new ActionListener()
1338 public void actionPerformed(ActionEvent actionEvent)
1340 editSequence_actionPerformed(actionEvent);
1343 makeReferenceSeq.setText(MessageManager
1344 .getString("label.mark_as_representative"));
1345 makeReferenceSeq.addActionListener(new ActionListener()
1349 public void actionPerformed(ActionEvent actionEvent)
1351 makeReferenceSeq_actionPerformed(actionEvent);
1355 hideInsertions.setText(MessageManager
1356 .getString("label.hide_insertions"));
1357 hideInsertions.addActionListener(new ActionListener()
1361 public void actionPerformed(ActionEvent e)
1363 hideInsertions_actionPerformed(e);
1367 * annotationMenuItem.setText("By Annotation");
1368 * annotationMenuItem.addActionListener(new ActionListener() { public void
1369 * actionPerformed(ActionEvent actionEvent) {
1370 * annotationMenuItem_actionPerformed(actionEvent); } });
1372 groupMenu.add(sequenceSelDetails);
1375 add(rnaStructureMenu);
1376 add(pdbStructureDialog);
1377 if (sequence != null)
1379 add(hideInsertions);
1381 // annotations configuration panel suppressed for now
1382 // groupMenu.add(chooseAnnotations);
1385 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1386 * (if a selection group is in force).
1388 sequenceMenu.add(seqShowAnnotationsMenu);
1389 sequenceMenu.add(seqHideAnnotationsMenu);
1390 sequenceMenu.add(seqAddReferenceAnnotations);
1391 groupMenu.add(groupShowAnnotationsMenu);
1392 groupMenu.add(groupHideAnnotationsMenu);
1393 groupMenu.add(groupAddReferenceAnnotations);
1394 groupMenu.add(editMenu);
1395 groupMenu.add(outputMenu);
1396 groupMenu.add(sequenceFeature);
1397 groupMenu.add(createGroupMenuItem);
1398 groupMenu.add(unGroupMenuItem);
1399 groupMenu.add(jMenu1);
1400 sequenceMenu.add(sequenceName);
1401 sequenceMenu.add(sequenceDetails);
1402 sequenceMenu.add(makeReferenceSeq);
1403 colourMenu.add(textColour);
1404 colourMenu.add(noColourmenuItem);
1405 colourMenu.add(clustalColour);
1406 colourMenu.add(BLOSUM62Colour);
1407 colourMenu.add(PIDColour);
1408 colourMenu.add(zappoColour);
1409 colourMenu.add(taylorColour);
1410 colourMenu.add(hydrophobicityColour);
1411 colourMenu.add(helixColour);
1412 colourMenu.add(strandColour);
1413 colourMenu.add(turnColour);
1414 colourMenu.add(buriedColour);
1415 colourMenu.add(nucleotideMenuItem);
1416 if (ap.getAlignment().isNucleotide())
1418 // JBPNote - commented since the colourscheme isn't functional
1419 colourMenu.add(purinePyrimidineColour);
1421 colourMenu.add(userDefinedColour);
1423 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1425 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1426 .getUserColourSchemes().keys();
1428 while (userColours.hasMoreElements())
1430 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1431 item.addActionListener(new ActionListener()
1434 public void actionPerformed(ActionEvent evt)
1436 userDefinedColour_actionPerformed(evt);
1439 colourMenu.add(item);
1443 colourMenu.addSeparator();
1444 colourMenu.add(abovePIDColour);
1445 colourMenu.add(conservationMenuItem);
1448 editMenu.add(editSequence);
1449 editMenu.add(upperCase);
1450 editMenu.add(lowerCase);
1451 editMenu.add(toggle);
1452 // JBPNote: These shouldn't be added here - should appear in a generic
1453 // 'apply web service to this sequence menu'
1454 // pdbMenu.add(RNAFold);
1455 // pdbMenu.add(ContraFold);
1456 jMenu1.add(groupName);
1457 jMenu1.add(colourMenu);
1458 jMenu1.add(showBoxes);
1459 jMenu1.add(showText);
1460 jMenu1.add(showColourText);
1461 jMenu1.add(outline);
1462 jMenu1.add(displayNonconserved);
1463 noColourmenuItem.setText(MessageManager.getString("label.none"));
1464 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1467 public void actionPerformed(ActionEvent e)
1469 noColourmenuItem_actionPerformed();
1473 clustalColour.setText(MessageManager
1474 .getString("label.clustalx_colours"));
1475 clustalColour.addActionListener(new java.awt.event.ActionListener()
1478 public void actionPerformed(ActionEvent e)
1480 clustalColour_actionPerformed();
1483 zappoColour.setText(MessageManager.getString("label.zappo"));
1484 zappoColour.addActionListener(new java.awt.event.ActionListener()
1487 public void actionPerformed(ActionEvent e)
1489 zappoColour_actionPerformed();
1492 taylorColour.setText(MessageManager.getString("label.taylor"));
1493 taylorColour.addActionListener(new java.awt.event.ActionListener()
1496 public void actionPerformed(ActionEvent e)
1498 taylorColour_actionPerformed();
1501 hydrophobicityColour.setText(MessageManager
1502 .getString("label.hydrophobicity"));
1503 hydrophobicityColour
1504 .addActionListener(new java.awt.event.ActionListener()
1507 public void actionPerformed(ActionEvent e)
1509 hydrophobicityColour_actionPerformed();
1512 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1513 helixColour.addActionListener(new java.awt.event.ActionListener()
1516 public void actionPerformed(ActionEvent e)
1518 helixColour_actionPerformed();
1521 strandColour.setText(MessageManager
1522 .getString("label.strand_propensity"));
1523 strandColour.addActionListener(new java.awt.event.ActionListener()
1526 public void actionPerformed(ActionEvent e)
1528 strandColour_actionPerformed();
1531 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1532 turnColour.addActionListener(new java.awt.event.ActionListener()
1535 public void actionPerformed(ActionEvent e)
1537 turnColour_actionPerformed();
1540 buriedColour.setText(MessageManager.getString("label.buried_index"));
1541 buriedColour.addActionListener(new java.awt.event.ActionListener()
1544 public void actionPerformed(ActionEvent e)
1546 buriedColour_actionPerformed();
1549 abovePIDColour.setText(MessageManager
1550 .getString("label.above_identity_percentage"));
1551 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1554 public void actionPerformed(ActionEvent e)
1556 abovePIDColour_actionPerformed();
1559 userDefinedColour.setText(MessageManager
1560 .getString("action.user_defined"));
1561 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1564 public void actionPerformed(ActionEvent e)
1566 userDefinedColour_actionPerformed(e);
1570 .setText(MessageManager.getString("label.percentage_identity"));
1571 PIDColour.addActionListener(new java.awt.event.ActionListener()
1574 public void actionPerformed(ActionEvent e)
1576 PIDColour_actionPerformed();
1579 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1580 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1583 public void actionPerformed(ActionEvent e)
1585 BLOSUM62Colour_actionPerformed();
1588 purinePyrimidineColour.setText(MessageManager
1589 .getString("label.purine_pyrimidine"));
1590 purinePyrimidineColour
1591 .addActionListener(new java.awt.event.ActionListener()
1594 public void actionPerformed(ActionEvent e)
1596 purinePyrimidineColour_actionPerformed();
1601 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1602 * public void actionPerformed(ActionEvent e) {
1603 * covariationColour_actionPerformed(); } });
1606 conservationMenuItem.setText(MessageManager
1607 .getString("label.conservation"));
1608 conservationMenuItem
1609 .addActionListener(new java.awt.event.ActionListener()
1612 public void actionPerformed(ActionEvent e)
1614 conservationMenuItem_actionPerformed();
1620 * Check for any annotations on the underlying dataset sequences (for the
1621 * current selection group) which are not 'on the alignment'.If any are found,
1622 * enable the option to add them to the alignment. The criteria for 'on the
1623 * alignment' is finding an alignment annotation on the alignment, matched on
1624 * calcId, label and sequenceRef.
1626 * A tooltip is also constructed that displays the source (calcId) and type
1627 * (label) of the annotations that can be added.
1630 * @param forSequences
1632 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1633 List<SequenceI> forSequences)
1635 menuItem.setEnabled(false);
1638 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1639 * Using TreeMap means calcIds are shown in alphabetical order.
1641 Map<String, String> tipEntries = new TreeMap<String, String>();
1642 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1643 AlignmentI al = this.ap.av.getAlignment();
1644 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1645 tipEntries, candidates, al);
1646 if (!candidates.isEmpty())
1648 StringBuilder tooltip = new StringBuilder(64);
1649 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1652 * Found annotations that could be added. Enable the menu item, and
1653 * configure its tooltip and action.
1655 menuItem.setEnabled(true);
1656 for (String calcId : tipEntries.keySet())
1658 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1660 String tooltipText = JvSwingUtils.wrapTooltip(true,
1661 tooltip.toString());
1662 menuItem.setToolTipText(tooltipText);
1664 menuItem.addActionListener(new ActionListener()
1667 public void actionPerformed(ActionEvent e)
1669 addReferenceAnnotations_actionPerformed(candidates);
1676 * Add annotations to the sequences and to the alignment.
1679 * a map whose keys are sequences on the alignment, and values a list
1680 * of annotations to add to each sequence
1682 protected void addReferenceAnnotations_actionPerformed(
1683 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1685 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1686 final AlignmentI alignment = this.ap.getAlignment();
1687 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1692 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1694 if (!ap.av.getAlignment().hasSeqrep())
1696 // initialise the display flags so the user sees something happen
1697 ap.av.setDisplayReferenceSeq(true);
1698 ap.av.setColourByReferenceSeq(true);
1699 ap.av.getAlignment().setSeqrep(sequence);
1703 if (ap.av.getAlignment().getSeqrep() == sequence)
1705 ap.av.getAlignment().setSeqrep(null);
1709 ap.av.getAlignment().setSeqrep(sequence);
1715 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1717 if (sequence != null)
1719 ColumnSelection cs = ap.av.getColumnSelection();
1722 cs = new ColumnSelection();
1724 cs.hideInsertionsFor(sequence);
1725 ap.av.setColumnSelection(cs);
1730 protected void sequenceSelectionDetails_actionPerformed()
1732 createSequenceDetailsReport(ap.av.getSequenceSelection());
1735 protected void sequenceDetails_actionPerformed()
1737 createSequenceDetailsReport(new SequenceI[] { sequence });
1740 public void createSequenceDetailsReport(SequenceI[] sequences)
1742 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1743 StringBuffer contents = new StringBuffer();
1744 for (SequenceI seq : sequences)
1746 contents.append("<p><h2>"
1749 "label.create_sequence_details_report_annotation_for",
1750 new Object[] { seq.getDisplayId(true) })
1752 new SequenceAnnotationReport(null)
1753 .createSequenceAnnotationReport(
1759 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1760 .getSeqPanel().seqCanvas.fr.getMinMax()
1762 contents.append("</p>");
1764 cap.setText("<html>" + contents.toString() + "</html>");
1766 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1767 "label.sequence_details_for",
1768 (sequences.length == 1 ? new Object[] { sequences[0]
1769 .getDisplayId(true) } : new Object[] { MessageManager
1770 .getString("label.selection") })), 500, 400);
1774 protected void showNonconserved_actionPerformed()
1776 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1781 * call to refresh view after settings change
1785 ap.updateAnnotation();
1786 ap.paintAlignment(true);
1788 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1797 protected void clustalColour_actionPerformed()
1799 SequenceGroup sg = getGroup();
1800 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1810 protected void zappoColour_actionPerformed()
1812 getGroup().cs = new ZappoColourScheme();
1822 protected void taylorColour_actionPerformed()
1824 getGroup().cs = new TaylorColourScheme();
1834 protected void hydrophobicityColour_actionPerformed()
1836 getGroup().cs = new HydrophobicColourScheme();
1846 protected void helixColour_actionPerformed()
1848 getGroup().cs = new HelixColourScheme();
1858 protected void strandColour_actionPerformed()
1860 getGroup().cs = new StrandColourScheme();
1870 protected void turnColour_actionPerformed()
1872 getGroup().cs = new TurnColourScheme();
1882 protected void buriedColour_actionPerformed()
1884 getGroup().cs = new BuriedColourScheme();
1894 public void nucleotideMenuItem_actionPerformed()
1896 getGroup().cs = new NucleotideColourScheme();
1900 protected void purinePyrimidineColour_actionPerformed()
1902 getGroup().cs = new PurinePyrimidineColourScheme();
1907 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1908 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1916 protected void abovePIDColour_actionPerformed()
1918 SequenceGroup sg = getGroup();
1924 if (abovePIDColour.isSelected())
1926 sg.cs.setConsensus(AAFrequency.calculate(
1927 sg.getSequences(ap.av.getHiddenRepSequences()),
1928 sg.getStartRes(), sg.getEndRes() + 1));
1930 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1933 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1935 SliderPanel.showPIDSlider();
1938 // remove PIDColouring
1940 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1952 protected void userDefinedColour_actionPerformed(ActionEvent e)
1954 SequenceGroup sg = getGroup();
1956 if (e.getSource().equals(userDefinedColour))
1958 new UserDefinedColours(ap, sg);
1962 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1963 .getUserColourSchemes().get(e.getActionCommand());
1971 * Open a panel where the user can choose which types of sequence annotation
1976 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1978 // todo correct way to guard against opening a duplicate panel?
1979 new AnnotationChooser(ap);
1988 protected void PIDColour_actionPerformed()
1990 SequenceGroup sg = getGroup();
1991 sg.cs = new PIDColourScheme();
1992 sg.cs.setConsensus(AAFrequency.calculate(
1993 sg.getSequences(ap.av.getHiddenRepSequences()),
1994 sg.getStartRes(), sg.getEndRes() + 1));
2004 protected void BLOSUM62Colour_actionPerformed()
2006 SequenceGroup sg = getGroup();
2008 sg.cs = new Blosum62ColourScheme();
2010 sg.cs.setConsensus(AAFrequency.calculate(
2011 sg.getSequences(ap.av.getHiddenRepSequences()),
2012 sg.getStartRes(), sg.getEndRes() + 1));
2023 protected void noColourmenuItem_actionPerformed()
2025 getGroup().cs = null;
2035 protected void conservationMenuItem_actionPerformed()
2037 SequenceGroup sg = getGroup();
2043 if (conservationMenuItem.isSelected())
2045 // JBPNote: Conservation name shouldn't be i18n translated
2046 Conservation c = new Conservation("Group",
2047 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2048 .getHiddenRepSequences()), sg.getStartRes(),
2049 sg.getEndRes() + 1);
2052 c.verdict(false, ap.av.getConsPercGaps());
2054 sg.cs.setConservation(c);
2056 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2057 SliderPanel.showConservationSlider();
2060 // remove ConservationColouring
2062 sg.cs.setConservation(null);
2068 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2070 SequenceGroup sg = getGroup();
2076 AnnotationColourGradient acg = new AnnotationColourGradient(
2077 sequence.getAnnotation()[0], null,
2078 AnnotationColourGradient.NO_THRESHOLD);
2080 acg.setPredefinedColours(true);
2092 protected void groupName_actionPerformed()
2095 SequenceGroup sg = getGroup();
2096 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2097 sg.getDescription(), " "
2098 + MessageManager.getString("label.group_name") + " ",
2099 MessageManager.getString("label.group_description") + " ",
2100 MessageManager.getString("label.edit_group_name_description"),
2108 sg.setName(dialog.getName());
2109 sg.setDescription(dialog.getDescription());
2114 * Get selection group - adding it to the alignment if necessary.
2116 * @return sequence group to operate on
2118 SequenceGroup getGroup()
2120 SequenceGroup sg = ap.av.getSelectionGroup();
2121 // this method won't add a new group if it already exists
2124 ap.av.getAlignment().addGroup(sg);
2136 void sequenceName_actionPerformed()
2138 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2139 sequence.getDescription(),
2140 " " + MessageManager.getString("label.sequence_name")
2142 MessageManager.getString("label.sequence_description") + " ",
2144 .getString("label.edit_sequence_name_description"),
2152 if (dialog.getName() != null)
2154 if (dialog.getName().indexOf(" ") > -1)
2160 .getString("label.spaces_converted_to_backslashes"),
2162 .getString("label.no_spaces_allowed_sequence_name"),
2163 JOptionPane.WARNING_MESSAGE);
2166 sequence.setName(dialog.getName().replace(' ', '_'));
2167 ap.paintAlignment(false);
2170 sequence.setDescription(dialog.getDescription());
2172 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2183 void unGroupMenuItem_actionPerformed()
2185 SequenceGroup sg = ap.av.getSelectionGroup();
2186 ap.av.getAlignment().deleteGroup(sg);
2187 ap.av.setSelectionGroup(null);
2191 void createGroupMenuItem_actionPerformed()
2193 getGroup(); // implicitly creates group - note - should apply defaults / use
2194 // standard alignment window logic for this
2204 protected void outline_actionPerformed()
2206 SequenceGroup sg = getGroup();
2207 Color col = JColorChooser.showDialog(this,
2208 MessageManager.getString("label.select_outline_colour"),
2213 sg.setOutlineColour(col);
2225 public void showBoxes_actionPerformed()
2227 getGroup().setDisplayBoxes(showBoxes.isSelected());
2237 public void showText_actionPerformed()
2239 getGroup().setDisplayText(showText.isSelected());
2249 public void showColourText_actionPerformed()
2251 getGroup().setColourText(showColourText.isSelected());
2255 public void showLink(String url)
2259 jalview.util.BrowserLauncher.openURL(url);
2260 } catch (Exception ex)
2262 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2263 MessageManager.getString("label.web_browser_not_found_unix"),
2264 MessageManager.getString("label.web_browser_not_found"),
2265 JOptionPane.WARNING_MESSAGE);
2267 ex.printStackTrace();
2271 void hideSequences(boolean representGroup)
2273 ap.av.hideSequences(sequence, representGroup);
2276 public void copy_actionPerformed()
2278 ap.alignFrame.copy_actionPerformed(null);
2281 public void cut_actionPerformed()
2283 ap.alignFrame.cut_actionPerformed(null);
2286 void changeCase(ActionEvent e)
2288 Object source = e.getSource();
2289 SequenceGroup sg = ap.av.getSelectionGroup();
2293 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2294 sg.getStartRes(), sg.getEndRes() + 1);
2299 if (source == toggle)
2301 description = MessageManager.getString("label.toggle_case");
2302 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2304 else if (source == upperCase)
2306 description = MessageManager.getString("label.to_upper_case");
2307 caseChange = ChangeCaseCommand.TO_UPPER;
2311 description = MessageManager.getString("label.to_lower_case");
2312 caseChange = ChangeCaseCommand.TO_LOWER;
2315 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2316 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2317 startEnd, caseChange);
2319 ap.alignFrame.addHistoryItem(caseCommand);
2321 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2327 public void outputText_actionPerformed(ActionEvent e)
2329 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2330 cap.setForInput(null);
2331 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2332 "label.alignment_output_command",
2333 new Object[] { e.getActionCommand() }), 600, 500);
2335 String[] omitHidden = null;
2337 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2338 // or we simply trust the user wants
2339 // wysiwig behaviour
2341 cap.setText(new FormatAdapter(ap).formatSequences(e.getActionCommand(),
2345 public void sequenceFeature_actionPerformed()
2347 SequenceGroup sg = ap.av.getSelectionGroup();
2353 int rsize = 0, gSize = sg.getSize();
2354 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2355 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2357 for (int i = 0; i < gSize; i++)
2359 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2360 int end = sg.findEndRes(sg.getSequenceAt(i));
2363 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2364 features[rsize] = new SequenceFeature(null, null, null, start, end,
2369 rseqs = new SequenceI[rsize];
2370 tfeatures = new SequenceFeature[rsize];
2371 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2372 System.arraycopy(features, 0, tfeatures, 0, rsize);
2373 features = tfeatures;
2375 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2376 features, true, ap))
2378 ap.alignFrame.setShowSeqFeatures(true);
2379 ap.highlightSearchResults(null);
2383 public void textColour_actionPerformed()
2385 SequenceGroup sg = getGroup();
2388 new TextColourChooser().chooseColour(ap, sg);
2392 public void colourByStructure(String pdbid)
2394 Annotation[] anots = ap.av.getStructureSelectionManager()
2395 .colourSequenceFromStructure(sequence, pdbid);
2397 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2398 "Coloured by " + pdbid, anots);
2400 ap.av.getAlignment().addAnnotation(an);
2401 an.createSequenceMapping(sequence, 0, true);
2402 // an.adjustForAlignment();
2403 ap.av.getAlignment().setAnnotationIndex(an, 0);
2405 ap.adjustAnnotationHeight();
2407 sequence.addAlignmentAnnotation(an);
2411 public void editSequence_actionPerformed(ActionEvent actionEvent)
2413 SequenceGroup sg = ap.av.getSelectionGroup();
2417 if (sequence == null)
2419 sequence = sg.getSequenceAt(0);
2422 EditNameDialog dialog = new EditNameDialog(
2423 sequence.getSequenceAsString(sg.getStartRes(),
2424 sg.getEndRes() + 1), null,
2425 MessageManager.getString("label.edit_sequence"), null,
2426 MessageManager.getString("label.edit_sequence"),
2431 EditCommand editCommand = new EditCommand(
2432 MessageManager.getString("label.edit_sequences"),
2433 Action.REPLACE, dialog.getName().replace(' ',
2434 ap.av.getGapCharacter()),
2435 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2436 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2438 ap.alignFrame.addHistoryItem(editCommand);
2440 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()