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.
21 package jalview.appletgui;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.bin.JalviewLite;
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.PDBEntry;
34 import jalview.datamodel.SequenceFeature;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.io.AppletFormatAdapter;
38 import jalview.io.DataSourceType;
39 import jalview.io.FileFormat;
40 import jalview.io.SequenceAnnotationReport;
41 import jalview.schemes.Blosum62ColourScheme;
42 import jalview.schemes.BuriedColourScheme;
43 import jalview.schemes.ClustalxColourScheme;
44 import jalview.schemes.CollectionColourScheme;
45 import jalview.schemes.CollectionColourSchemeI;
46 import jalview.schemes.HelixColourScheme;
47 import jalview.schemes.HydrophobicColourScheme;
48 import jalview.schemes.JalviewColourScheme;
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.ZappoColourScheme;
56 import jalview.util.MessageManager;
57 import jalview.util.UrlLink;
59 import java.awt.CheckboxMenuItem;
60 import java.awt.Frame;
62 import java.awt.MenuItem;
63 import java.awt.event.ActionEvent;
64 import java.awt.event.ActionListener;
65 import java.awt.event.ItemEvent;
66 import java.awt.event.ItemListener;
67 import java.util.Arrays;
68 import java.util.Collection;
69 import java.util.Collections;
70 import java.util.LinkedHashMap;
71 import java.util.List;
73 import java.util.SortedMap;
74 import java.util.TreeMap;
75 import java.util.Vector;
77 public class APopupMenu extends java.awt.PopupMenu implements
78 ActionListener, ItemListener
80 Menu groupMenu = new Menu();
82 MenuItem editGroupName = new MenuItem();
84 CheckboxMenuItem noColour = new CheckboxMenuItem();
86 protected CheckboxMenuItem clustalColour = new CheckboxMenuItem();
88 protected CheckboxMenuItem zappoColour = new CheckboxMenuItem();
90 protected CheckboxMenuItem taylorColour = new CheckboxMenuItem();
92 protected CheckboxMenuItem hydrophobicityColour = new CheckboxMenuItem();
94 protected CheckboxMenuItem helixColour = new CheckboxMenuItem();
96 protected CheckboxMenuItem strandColour = new CheckboxMenuItem();
98 protected CheckboxMenuItem turnColour = new CheckboxMenuItem();
100 protected CheckboxMenuItem buriedColour = new CheckboxMenuItem();
102 protected CheckboxMenuItem PIDColour = new CheckboxMenuItem();
104 protected CheckboxMenuItem BLOSUM62Colour = new CheckboxMenuItem();
106 CheckboxMenuItem nucleotideColour = new CheckboxMenuItem();
108 CheckboxMenuItem purinePyrimidineColour = new CheckboxMenuItem();
110 protected MenuItem userDefinedColour = new MenuItem();
112 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
114 protected CheckboxMenuItem conservationColour = new CheckboxMenuItem();
116 final AlignmentPanel ap;
118 MenuItem unGroupMenuItem = new MenuItem();
120 MenuItem createGroupMenuItem = new MenuItem();
122 Menu colourMenu = new Menu();
124 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
126 CheckboxMenuItem showText = new CheckboxMenuItem();
128 CheckboxMenuItem showColourText = new CheckboxMenuItem();
130 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
132 Menu seqShowAnnotationsMenu = new Menu(
133 MessageManager.getString("label.show_annotations"));
135 Menu seqHideAnnotationsMenu = new Menu(
136 MessageManager.getString("label.hide_annotations"));
138 MenuItem seqAddReferenceAnnotations = new MenuItem(
139 MessageManager.getString("label.add_reference_annotations"));
141 Menu groupShowAnnotationsMenu = new Menu(
142 MessageManager.getString("label.show_annotations"));
144 Menu groupHideAnnotationsMenu = new Menu(
145 MessageManager.getString("label.hide_annotations"));
147 MenuItem groupAddReferenceAnnotations = new MenuItem(
148 MessageManager.getString("label.add_reference_annotations"));
150 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
152 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
154 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
156 MenuItem toUpper = new MenuItem(
157 MessageManager.getString("label.to_upper_case"));
159 MenuItem toLower = new MenuItem(
160 MessageManager.getString("label.to_lower_case"));
162 MenuItem toggleCase = new MenuItem(
163 MessageManager.getString("label.toggle_case"));
165 Menu outputmenu = new Menu();
167 Menu seqMenu = new Menu();
169 MenuItem pdb = new MenuItem();
171 MenuItem hideSeqs = new MenuItem();
173 MenuItem repGroup = new MenuItem();
175 MenuItem sequenceName = new MenuItem(
176 MessageManager.getString("label.edit_name_description"));
178 MenuItem sequenceFeature = new MenuItem(
179 MessageManager.getString("label.create_sequence_feature"));
181 MenuItem editSequence = new MenuItem(
182 MessageManager.getString("label.edit_sequence"));
184 MenuItem sequenceDetails = new MenuItem(
185 MessageManager.getString("label.sequence_details"));
187 MenuItem selSeqDetails = new MenuItem(
188 MessageManager.getString("label.sequence_details"));
190 MenuItem makeReferenceSeq = new MenuItem();
194 MenuItem revealAll = new MenuItem();
196 MenuItem revealSeq = new MenuItem();
199 * index of sequence to be revealed
201 int revealSeq_index = -1;
203 Menu menu1 = new Menu();
205 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
206 Vector<String> links)
208 // /////////////////////////////////////////////////////////
209 // If this is activated from the sequence panel, the user may want to
210 // edit or annotate a particular residue. Therefore display the residue menu
212 // If from the IDPanel, we must display the sequence menu
213 // ////////////////////////////////////////////////////////
221 } catch (Exception e)
226 for (String ff : FileFormat.getWritableFormats(true))
228 MenuItem item = new MenuItem(ff);
230 item.addActionListener(this);
231 outputmenu.add(item);
234 buildAnnotationSubmenus();
236 SequenceGroup sg = ap.av.getSelectionGroup();
237 if (sg != null && sg.getSize() > 0)
239 editGroupName.setLabel(MessageManager.formatMessage(
240 "label.name_param", new Object[] { sg.getName() }));
241 showText.setState(sg.getDisplayText());
242 showColourText.setState(sg.getColourText());
243 showBoxes.setState(sg.getDisplayBoxes());
244 displayNonconserved.setState(sg.getShowNonconserved());
245 if (!ap.av.getAlignment().getGroups().contains(sg))
247 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
248 groupMenu.remove(unGroupMenuItem);
252 menu1.setLabel(MessageManager.getString("action.edit_group"));
253 groupMenu.remove(createGroupMenuItem);
256 abovePIDColour.setState(sg.cs.getThreshold() > 0);
257 conservationColour.setState(sg.cs.conservationApplied());
260 setSelectedColour(sg.cs);
268 if (links != null && links.size() > 0)
270 addFeatureLinks(seq, links);
273 // TODO: add group link menu entry here
276 seqMenu.setLabel(seq.getName());
277 if (seq == ap.av.getAlignment().getSeqrep())
279 makeReferenceSeq.setLabel(MessageManager
280 .getString("action.unmark_as_reference"));// Unmark
285 makeReferenceSeq.setLabel(MessageManager
286 .getString("action.set_as_reference")); // );
288 repGroup.setLabel(MessageManager.formatMessage(
289 "label.represent_group_with", new Object[] { seq.getName() }));
296 if (!ap.av.hasHiddenRows())
303 final int index = ap.av.getAlignment().findIndex(seq);
305 if (ap.av.adjustForHiddenSeqs(index)
306 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
308 revealSeq_index = index;
318 * Select the menu item (if any) matching the current colour scheme. This
319 * works by matching the menu item name (not display text) to the canonical
320 * name of the colour scheme.
324 protected void setSelectedColour(CollectionColourSchemeI cs)
326 if (cs == null || cs.getColourScheme() == null)
328 noColour.setState(true);
332 String name = cs.getColourScheme().getSchemeName();
333 for (int i = 0; i < colourMenu.getItemCount(); i++)
335 MenuItem item = colourMenu.getItem(i);
336 if (item instanceof CheckboxMenuItem)
338 if (name.equals(item.getName()))
340 ((CheckboxMenuItem) item).setState(true);
348 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
353 void addFeatureLinks(final SequenceI seq, List<String> links)
355 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
356 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
358 for (String link : links)
360 UrlLink urlLink = null;
363 urlLink = new UrlLink(link);
364 } catch (Exception foo)
366 System.err.println("Exception for URLLink '" + link + "': "
371 if (!urlLink.isValid())
373 System.err.println(urlLink.getInvalidMessage());
377 urlLink.createLinksFromSeq(seq, linkset);
380 addshowLinks(linkMenu, linkset.values());
382 // disable link menu if there are no valid entries
383 if (linkMenu.getItemCount() > 0)
385 linkMenu.setEnabled(true);
389 linkMenu.setEnabled(false);
394 seqMenu.add(linkMenu);
403 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
405 for (List<String> linkstrset : linkset)
407 // split linkstr into label and url
408 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
413 * Build menus for annotation types that may be shown or hidden, and for
414 * 'reference annotations' that may be added to the alignment.
416 private void buildAnnotationSubmenus()
419 * First for the currently selected sequence (if there is one):
421 final List<SequenceI> selectedSequence = (seq == null ? Collections
422 .<SequenceI> emptyList() : Arrays.asList(seq));
423 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
424 seqHideAnnotationsMenu, selectedSequence);
425 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
429 * and repeat for the current selection group (if there is one):
431 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
432 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
434 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
435 groupHideAnnotationsMenu, selectedGroup);
436 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
441 * Determine whether or not to enable 'add reference annotations' menu item.
442 * It is enable if there are any annotations, on any of the selected
443 * sequences, which are not yet on the alignment (visible or not).
446 * @param forSequences
448 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
449 List<SequenceI> forSequences)
451 menuItem.setEnabled(false);
454 * Temporary store to hold distinct calcId / type pairs for the tooltip.
455 * Using TreeMap means calcIds are shown in alphabetical order.
457 SortedMap<String, String> tipEntries = new TreeMap<String, String>();
458 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
459 AlignmentI al = this.ap.av.getAlignment();
460 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
461 tipEntries, candidates, al);
462 if (!candidates.isEmpty())
464 StringBuilder tooltip = new StringBuilder(64);
465 tooltip.append(MessageManager.getString("label.add_annotations_for"));
468 * Found annotations that could be added. Enable the menu item, and
469 * configure its action.
471 menuItem.setEnabled(true);
473 menuItem.addActionListener(new ActionListener()
476 public void actionPerformed(ActionEvent e)
478 addReferenceAnnotations_actionPerformed(candidates);
485 * Add annotations to the sequences and to the alignment.
488 * a map whose keys are sequences on the alignment, and values a list
489 * of annotations to add to each sequence
491 protected void addReferenceAnnotations_actionPerformed(
492 Map<SequenceI, List<AlignmentAnnotation>> candidates)
494 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
495 final AlignmentI alignment = this.ap.getAlignment();
496 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
502 * add a show URL menu item to the given linkMenu
506 * - menu label string
510 private void addshowLink(Menu linkMenu, final String target,
513 addshowLink(linkMenu, target, target, url);
517 * add a show URL menu item to the given linkMenu
521 * - URL target window
523 * - menu label string
527 private void addshowLink(Menu linkMenu, final String target,
528 final String label, final String url)
530 MenuItem item = new MenuItem(label);
531 item.addActionListener(new java.awt.event.ActionListener()
534 public void actionPerformed(ActionEvent e)
536 ap.alignFrame.showURL(url, target);
543 * Actions on selecting / unselecting a checkbox menu item
546 public void itemStateChanged(ItemEvent evt)
548 Object source = evt.getSource();
549 if (source == noColour)
551 noColourmenuItem_actionPerformed();
553 else if (source == clustalColour)
555 clustalColour_actionPerformed();
557 else if (source == BLOSUM62Colour)
559 BLOSUM62Colour_actionPerformed();
561 else if (evt.getSource() == PIDColour)
563 PIDColour_actionPerformed();
565 else if (source == zappoColour)
567 zappoColour_actionPerformed();
569 else if (source == taylorColour)
571 taylorColour_actionPerformed();
573 else if (source == hydrophobicityColour)
575 hydrophobicityColour_actionPerformed();
577 else if (source == helixColour)
579 helixColour_actionPerformed();
581 else if (source == strandColour)
583 strandColour_actionPerformed();
585 else if (source == turnColour)
587 turnColour_actionPerformed();
589 else if (source == buriedColour)
591 buriedColour_actionPerformed();
593 else if (source == nucleotideColour)
595 nucleotideMenuItem_actionPerformed();
597 else if (source == purinePyrimidineColour)
599 purinePyrimidineColour_actionPerformed();
601 else if (source == abovePIDColour)
603 abovePIDColour_itemStateChanged();
605 else if (source == conservationColour)
607 conservationMenuItem_itemStateChanged();
609 else if (source == showColourText)
611 showColourText_itemStateChanged();
613 else if (source == showText)
615 showText_itemStateChanged();
617 else if (source == showBoxes)
619 showBoxes_itemStateChanged();
621 else if (source == displayNonconserved)
623 this.showNonconserved_itemStateChanged();
628 * Actions on clicking a menu item
631 public void actionPerformed(ActionEvent evt)
633 Object source = evt.getSource();
634 if (source == userDefinedColour)
636 userDefinedColour_actionPerformed();
638 else if (source == unGroupMenuItem)
640 unGroupMenuItem_actionPerformed();
643 else if (source == createGroupMenuItem)
645 createGroupMenuItem_actionPerformed();
648 else if (source == sequenceName)
652 else if (source == makeReferenceSeq)
654 makeReferenceSeq_actionPerformed();
656 else if (source == sequenceDetails)
658 showSequenceDetails();
660 else if (source == selSeqDetails)
662 showSequenceSelectionDetails();
664 else if (source == pdb)
668 else if (source == hideSeqs)
670 hideSequences(false);
672 else if (source == repGroup)
676 else if (source == revealSeq)
678 ap.av.showSequence(revealSeq_index);
680 else if (source == revealAll)
682 ap.av.showAllHiddenSeqs();
685 else if (source == editGroupName)
687 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
688 getGroup().getDescription(), " Group Name",
689 "Group Description", ap.alignFrame,
690 "Edit Group Name / Description", 500, 100, true);
694 getGroup().setName(dialog.getName().replace(' ', '_'));
695 getGroup().setDescription(dialog.getDescription());
699 else if (source == copy)
701 ap.alignFrame.copy_actionPerformed();
703 else if (source == cut)
705 ap.alignFrame.cut_actionPerformed();
707 else if (source == editSequence)
709 SequenceGroup sg = ap.av.getSelectionGroup();
715 seq = sg.getSequenceAt(0);
718 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
719 sg.getStartRes(), sg.getEndRes() + 1), null,
720 "Edit Sequence ", null,
722 ap.alignFrame, "Edit Sequence", 500, 100, true);
726 EditCommand editCommand = new EditCommand(
727 MessageManager.getString("label.edit_sequences"),
728 Action.REPLACE, dialog.getName().replace(' ',
729 ap.av.getGapCharacter()),
730 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
731 sg.getStartRes(), sg.getEndRes() + 1,
732 ap.av.getAlignment());
734 ap.alignFrame.addHistoryItem(editCommand);
736 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
741 else if (source == toUpper || source == toLower || source == toggleCase)
743 SequenceGroup sg = ap.av.getSelectionGroup();
746 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
747 sg.getStartRes(), sg.getEndRes() + 1);
752 if (source == toggleCase)
754 description = "Toggle Case";
755 caseChange = ChangeCaseCommand.TOGGLE_CASE;
757 else if (source == toUpper)
759 description = "To Upper Case";
760 caseChange = ChangeCaseCommand.TO_UPPER;
764 description = "To Lower Case";
765 caseChange = ChangeCaseCommand.TO_LOWER;
768 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
769 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
770 startEnd, caseChange);
772 ap.alignFrame.addHistoryItem(caseCommand);
774 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
779 else if (source == sequenceFeature)
781 SequenceGroup sg = ap.av.getSelectionGroup();
787 int rsize = 0, gSize = sg.getSize();
788 SequenceI[] rseqs, seqs = new SequenceI[gSize];
789 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
791 for (int i = 0; i < gSize; i++)
793 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
794 int end = sg.findEndRes(sg.getSequenceAt(i));
797 seqs[rsize] = sg.getSequenceAt(i);
798 features[rsize] = new SequenceFeature(null, null, null, start,
803 rseqs = new SequenceI[rsize];
804 tfeatures = new SequenceFeature[rsize];
805 System.arraycopy(seqs, 0, rseqs, 0, rsize);
806 System.arraycopy(features, 0, tfeatures, 0, rsize);
807 features = tfeatures;
810 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
813 ap.alignFrame.sequenceFeatures.setState(true);
814 ap.av.setShowSequenceFeatures(true);
816 ap.highlightSearchResults(null);
826 void outputText(ActionEvent e)
828 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
830 Frame frame = new Frame();
832 JalviewLite.addFrame(frame, MessageManager.formatMessage(
833 "label.selection_output_command",
834 new Object[] { e.getActionCommand() }), 600, 500);
835 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
836 // now returns a full copy of sequence data
837 // TODO consider using getSequenceSelection instead here
839 FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand());
840 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
841 ap.av.getShowJVSuffix(), ap, true));
845 protected void showSequenceSelectionDetails()
847 createSequenceDetailsReport(ap.av.getSequenceSelection());
850 protected void showSequenceDetails()
852 createSequenceDetailsReport(new SequenceI[] { seq });
855 public void createSequenceDetailsReport(SequenceI[] sequences)
858 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
860 StringBuilder contents = new StringBuilder(128);
861 for (SequenceI seq : sequences)
863 contents.append(MessageManager.formatMessage(
864 "label.annotation_for_displayid",
865 new Object[] { seq.getDisplayId(true) }));
866 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
871 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
872 .getMinMax() : null);
873 contents.append("</p>");
875 Frame frame = new Frame();
877 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
878 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
879 : "Selection"), 600, 500);
880 cap.setText(MessageManager.formatMessage("label.html_content",
881 new Object[] { contents.toString() }));
886 EditNameDialog dialog = new EditNameDialog(seq.getName(),
887 seq.getDescription(), " Sequence Name",
888 "Sequence Description", ap.alignFrame,
889 "Edit Sequence Name / Description", 500, 100, true);
893 seq.setName(dialog.getName());
894 seq.setDescription(dialog.getDescription());
895 ap.paintAlignment(false);
901 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
902 if (pdbs != null&& !pdbs.isEmpty())
904 PDBEntry entry = pdbs.firstElement();
906 if (ap.av.applet.jmolAvailable)
908 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
909 null, ap, DataSourceType.URL);
913 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
914 ap, DataSourceType.URL);
920 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
921 cap.setText(MessageManager.getString("label.paste_pdb_file"));
922 cap.setPDBImport(seq);
923 Frame frame = new Frame();
925 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
926 "label.paste_pdb_file_for_sequence",
927 new Object[] { seq.getName() }), 400, 300);
931 private void jbInit() throws Exception
933 groupMenu.setLabel(MessageManager.getString("label.selection"));
934 sequenceFeature.addActionListener(this);
936 editGroupName.addActionListener(this);
937 unGroupMenuItem.setLabel(MessageManager
938 .getString("action.remove_group"));
939 unGroupMenuItem.addActionListener(this);
941 createGroupMenuItem.setLabel(MessageManager
942 .getString("action.create_group"));
943 createGroupMenuItem.addActionListener(this);
945 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
946 showBoxes.setLabel(MessageManager.getString("action.boxes"));
947 showBoxes.setState(true);
948 showBoxes.addItemListener(this);
949 sequenceName.addActionListener(this);
950 sequenceDetails.addActionListener(this);
951 selSeqDetails.addActionListener(this);
952 displayNonconserved.setLabel(MessageManager
953 .getString("label.show_non_conserved"));
954 displayNonconserved.setState(false);
955 displayNonconserved.addItemListener(this);
956 showText.setLabel(MessageManager.getString("action.text"));
957 showText.addItemListener(this);
958 showColourText.setLabel(MessageManager.getString("label.colour_text"));
959 showColourText.addItemListener(this);
960 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
961 seqMenu.setLabel(MessageManager.getString("label.sequence"));
962 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
963 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
964 repGroup.setLabel(MessageManager.formatMessage(
965 "label.represent_group_with", new Object[] { "" }));
966 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
967 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
968 menu1.setLabel(MessageManager.getString("label.group:"));
974 // groupMenu.add(selSeqDetails);
975 groupMenu.add(groupShowAnnotationsMenu);
976 groupMenu.add(groupHideAnnotationsMenu);
977 groupMenu.add(groupAddReferenceAnnotations);
978 groupMenu.add(editMenu);
979 groupMenu.add(outputmenu);
980 groupMenu.add(sequenceFeature);
981 groupMenu.add(createGroupMenuItem);
982 groupMenu.add(unGroupMenuItem);
983 groupMenu.add(menu1);
985 colourMenu.add(noColour);
986 colourMenu.add(clustalColour);
987 colourMenu.add(BLOSUM62Colour);
988 colourMenu.add(PIDColour);
989 colourMenu.add(zappoColour);
990 colourMenu.add(taylorColour);
991 colourMenu.add(hydrophobicityColour);
992 colourMenu.add(helixColour);
993 colourMenu.add(strandColour);
994 colourMenu.add(turnColour);
995 colourMenu.add(buriedColour);
996 colourMenu.add(nucleotideColour);
997 colourMenu.add(purinePyrimidineColour);
998 colourMenu.add(userDefinedColour);
999 colourMenu.addSeparator();
1000 colourMenu.add(abovePIDColour);
1001 colourMenu.add(conservationColour);
1003 noColour.setLabel(MessageManager.getString("label.none"));
1004 noColour.addItemListener(this);
1007 * setName allows setSelectedColour to do its thing
1009 clustalColour.setLabel(MessageManager
1010 .getString("label.colourScheme_clustal"));
1011 clustalColour.setName(JalviewColourScheme.Clustal.toString());
1012 clustalColour.addItemListener(this);
1013 BLOSUM62Colour.setLabel(MessageManager
1014 .getString("label.colourScheme_blosum62"));
1015 BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1016 BLOSUM62Colour.addItemListener(this);
1017 PIDColour.setLabel(MessageManager
1018 .getString("label.colourScheme_%_identity"));
1019 PIDColour.setName(JalviewColourScheme.PID.toString());
1020 PIDColour.addItemListener(this);
1021 zappoColour.setLabel(MessageManager
1022 .getString("label.colourScheme_zappo"));
1023 zappoColour.setName(JalviewColourScheme.Zappo.toString());
1024 zappoColour.addItemListener(this);
1025 taylorColour.setLabel(MessageManager
1026 .getString("label.colourScheme_taylor"));
1027 taylorColour.setName(JalviewColourScheme.Taylor.toString());
1028 taylorColour.addItemListener(this);
1029 hydrophobicityColour.setLabel(MessageManager
1030 .getString("label.colourScheme_hydrophobic"));
1031 hydrophobicityColour
1032 .setName(JalviewColourScheme.Hydrophobic.toString());
1033 hydrophobicityColour.addItemListener(this);
1034 helixColour.setLabel(MessageManager
1035 .getString("label.colourScheme_helix_propensity"));
1036 helixColour.setName(JalviewColourScheme.Helix.toString());
1037 helixColour.addItemListener(this);
1038 strandColour.setLabel(MessageManager
1039 .getString("label.colourScheme_strand_propensity"));
1040 strandColour.setName(JalviewColourScheme.Strand.toString());
1041 strandColour.addItemListener(this);
1042 turnColour.setLabel(MessageManager
1043 .getString("label.colourScheme_turn_propensity"));
1044 turnColour.setName(JalviewColourScheme.Turn.toString());
1045 turnColour.addItemListener(this);
1046 buriedColour.setLabel(MessageManager
1047 .getString("label.colourScheme_buried_index"));
1048 buriedColour.setName(JalviewColourScheme.Buried.toString());
1049 buriedColour.addItemListener(this);
1050 nucleotideColour.setLabel(MessageManager
1051 .getString("label.colourScheme_nucleotide"));
1052 nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1053 nucleotideColour.addItemListener(this);
1054 purinePyrimidineColour.setLabel(MessageManager
1055 .getString("label.colourScheme_purine/pyrimidine"));
1056 purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
1058 purinePyrimidineColour.addItemListener(this);
1060 userDefinedColour.setLabel(MessageManager
1061 .getString("action.user_defined"));
1062 userDefinedColour.addActionListener(this);
1064 abovePIDColour.setLabel(MessageManager
1065 .getString("label.above_identity_threshold"));
1066 abovePIDColour.addItemListener(this);
1067 conservationColour.setLabel(MessageManager
1068 .getString("label.conservation"));
1069 conservationColour.addItemListener(this);
1072 copy.addActionListener(this);
1074 cut.addActionListener(this);
1076 editMenu.add(editSequence);
1077 editSequence.addActionListener(this);
1079 editMenu.add(toUpper);
1080 toUpper.addActionListener(this);
1081 editMenu.add(toLower);
1082 toLower.addActionListener(this);
1083 editMenu.add(toggleCase);
1084 seqMenu.add(seqShowAnnotationsMenu);
1085 seqMenu.add(seqHideAnnotationsMenu);
1086 seqMenu.add(seqAddReferenceAnnotations);
1087 seqMenu.add(sequenceName);
1088 seqMenu.add(makeReferenceSeq);
1089 // seqMenu.add(sequenceDetails);
1091 if (!ap.av.applet.useXtrnalSviewer)
1095 seqMenu.add(repGroup);
1096 menu1.add(editGroupName);
1097 menu1.add(colourMenu);
1098 menu1.add(showBoxes);
1099 menu1.add(showText);
1100 menu1.add(showColourText);
1101 menu1.add(displayNonconserved);
1102 toggleCase.addActionListener(this);
1103 pdb.addActionListener(this);
1104 hideSeqs.addActionListener(this);
1105 repGroup.addActionListener(this);
1106 revealAll.addActionListener(this);
1107 revealSeq.addActionListener(this);
1108 makeReferenceSeq.addActionListener(this);
1113 ap.paintAlignment(true);
1116 protected void clustalColour_actionPerformed()
1118 SequenceGroup sg = getGroup();
1119 sg.cs = new CollectionColourScheme(new ClustalxColourScheme(sg,
1120 ap.av.getHiddenRepSequences()));
1124 protected void zappoColour_actionPerformed()
1126 getGroup().cs = new CollectionColourScheme(new ZappoColourScheme());
1130 protected void taylorColour_actionPerformed()
1132 getGroup().cs = new CollectionColourScheme(new TaylorColourScheme());
1136 protected void hydrophobicityColour_actionPerformed()
1138 getGroup().cs = new CollectionColourScheme(new HydrophobicColourScheme());
1142 protected void helixColour_actionPerformed()
1144 getGroup().cs = new CollectionColourScheme(new HelixColourScheme());
1148 protected void strandColour_actionPerformed()
1150 getGroup().cs = new CollectionColourScheme(new StrandColourScheme());
1154 protected void turnColour_actionPerformed()
1156 getGroup().cs = new CollectionColourScheme(new TurnColourScheme());
1160 protected void buriedColour_actionPerformed()
1162 getGroup().cs = new CollectionColourScheme(new BuriedColourScheme());
1166 public void nucleotideMenuItem_actionPerformed()
1168 getGroup().cs = new CollectionColourScheme(new NucleotideColourScheme());
1172 public void purinePyrimidineColour_actionPerformed()
1174 getGroup().cs = new CollectionColourScheme(
1175 new PurinePyrimidineColourScheme());
1179 protected void abovePIDColour_itemStateChanged()
1181 SequenceGroup sg = getGroup();
1187 if (abovePIDColour.getState())
1189 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1190 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1191 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1194 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1196 SliderPanel.showPIDSlider();
1200 // remove PIDColouring
1202 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1209 protected void userDefinedColour_actionPerformed()
1211 new UserDefinedColours(ap, getGroup());
1214 protected void PIDColour_actionPerformed()
1216 SequenceGroup sg = getGroup();
1217 sg.cs = new CollectionColourScheme(new PIDColourScheme());
1218 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1219 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1223 protected void BLOSUM62Colour_actionPerformed()
1225 SequenceGroup sg = getGroup();
1227 sg.cs = new CollectionColourScheme(new Blosum62ColourScheme());
1229 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1230 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1235 protected void noColourmenuItem_actionPerformed()
1237 getGroup().cs = null;
1241 protected void conservationMenuItem_itemStateChanged()
1243 SequenceGroup sg = getGroup();
1249 if (conservationColour.getState())
1251 Conservation conservation = Conservation.calculateConservation(
1253 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1254 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1256 sg.getGroupColourScheme().setConservation(conservation);
1257 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1258 SliderPanel.showConservationSlider();
1261 // remove ConservationColouring
1263 sg.cs.setConservation(null);
1269 SequenceGroup getGroup()
1271 SequenceGroup sg = ap.av.getSelectionGroup();
1273 // this method won't add a new group if it already exists
1276 ap.av.getAlignment().addGroup(sg);
1282 void unGroupMenuItem_actionPerformed()
1284 SequenceGroup sg = ap.av.getSelectionGroup();
1285 ap.av.getAlignment().deleteGroup(sg);
1286 ap.av.setSelectionGroup(null);
1287 ap.paintAlignment(true);
1290 void createGroupMenuItem_actionPerformed()
1292 getGroup(); // implicitly create group
1296 public void showColourText_itemStateChanged()
1298 getGroup().setColourText(showColourText.getState());
1302 public void showText_itemStateChanged()
1304 getGroup().setDisplayText(showText.getState());
1308 public void makeReferenceSeq_actionPerformed()
1310 if (!ap.av.getAlignment().hasSeqrep())
1312 // initialise the display flags so the user sees something happen
1313 ap.av.setDisplayReferenceSeq(true);
1314 ap.av.setColourByReferenceSeq(true);
1315 ap.av.getAlignment().setSeqrep(seq);
1319 if (ap.av.getAlignment().getSeqrep() == seq)
1321 ap.av.getAlignment().setSeqrep(null);
1325 ap.av.getAlignment().setSeqrep(seq);
1331 public void showNonconserved_itemStateChanged()
1333 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1337 public void showBoxes_itemStateChanged()
1339 getGroup().setDisplayBoxes(showBoxes.getState());
1343 void hideSequences(boolean representGroup)
1345 ap.av.hideSequences(seq, representGroup);
1349 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1350 * "All" is added first, followed by a separator. Then add any annotation
1351 * types associated with the current selection. Separate menus are built for
1352 * the selected sequence group (if any), and the selected sequence.
1354 * Some annotation rows are always rendered together - these can be identified
1355 * by a common graphGroup property > -1. Only one of each group will be marked
1356 * as visible (to avoid duplication of the display). For such groups we add a
1357 * composite type name, e.g.
1359 * IUPredWS (Long), IUPredWS (Short)
1363 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1364 List<SequenceI> forSequences)
1366 showMenu.removeAll();
1367 hideMenu.removeAll();
1369 final List<String> all = Arrays.asList(new String[] { MessageManager
1370 .getString("label.all") });
1371 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1372 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1374 showMenu.addSeparator();
1375 hideMenu.addSeparator();
1377 final AlignmentAnnotation[] annotations = ap.getAlignment()
1378 .getAlignmentAnnotation();
1381 * Find shown/hidden annotations types, distinguished by source (calcId),
1382 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1383 * the insertion order, which is the order of the annotations on the
1386 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1387 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1388 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1389 AlignmentAnnotationUtils.asList(annotations), forSequences);
1391 for (String calcId : hiddenTypes.keySet())
1393 for (List<String> type : hiddenTypes.get(calcId))
1395 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1399 // grey out 'show annotations' if none are hidden
1400 showMenu.setEnabled(!hiddenTypes.isEmpty());
1402 for (String calcId : shownTypes.keySet())
1404 for (List<String> type : shownTypes.get(calcId))
1406 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1410 // grey out 'hide annotations' if none are shown
1411 hideMenu.setEnabled(!shownTypes.isEmpty());
1415 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1418 * @param showOrHideMenu
1419 * the menu to add to
1420 * @param forSequences
1421 * the sequences whose annotations may be shown or hidden
1426 * if true this is a special label meaning 'All'
1427 * @param actionIsShow
1428 * if true, the select menu item action is to show the annotation
1431 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1432 final List<SequenceI> forSequences, String calcId,
1433 final List<String> types, final boolean allTypes,
1434 final boolean actionIsShow)
1436 String label = types.toString(); // [a, b, c]
1437 label = label.substring(1, label.length() - 1);
1438 final MenuItem item = new MenuItem(label);
1439 item.addActionListener(new java.awt.event.ActionListener()
1442 public void actionPerformed(ActionEvent e)
1444 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1445 types, forSequences, allTypes, actionIsShow);
1449 showOrHideMenu.add(item);