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.HelixColourScheme;
46 import jalview.schemes.HydrophobicColourScheme;
47 import jalview.schemes.NucleotideColourScheme;
48 import jalview.schemes.PIDColourScheme;
49 import jalview.schemes.PurinePyrimidineColourScheme;
50 import jalview.schemes.StrandColourScheme;
51 import jalview.schemes.TaylorColourScheme;
52 import jalview.schemes.TurnColourScheme;
53 import jalview.schemes.ZappoColourScheme;
54 import jalview.util.MessageManager;
55 import jalview.util.UrlLink;
57 import java.awt.CheckboxMenuItem;
58 import java.awt.Frame;
60 import java.awt.MenuItem;
61 import java.awt.event.ActionEvent;
62 import java.awt.event.ActionListener;
63 import java.awt.event.ItemEvent;
64 import java.awt.event.ItemListener;
65 import java.util.Arrays;
66 import java.util.Collection;
67 import java.util.Collections;
68 import java.util.LinkedHashMap;
69 import java.util.List;
71 import java.util.SortedMap;
72 import java.util.TreeMap;
73 import java.util.Vector;
75 public class APopupMenu extends java.awt.PopupMenu implements
76 ActionListener, ItemListener
78 Menu groupMenu = new Menu();
80 MenuItem editGroupName = new MenuItem();
82 protected MenuItem clustalColour = new MenuItem();
84 protected MenuItem zappoColour = new MenuItem();
86 protected MenuItem taylorColour = new MenuItem();
88 protected MenuItem hydrophobicityColour = new MenuItem();
90 protected MenuItem helixColour = new MenuItem();
92 protected MenuItem strandColour = new MenuItem();
94 protected MenuItem turnColour = new MenuItem();
96 protected MenuItem buriedColour = new MenuItem();
98 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
100 protected MenuItem userDefinedColour = new MenuItem();
102 protected MenuItem PIDColour = new MenuItem();
104 protected MenuItem BLOSUM62Colour = new MenuItem();
106 MenuItem noColourmenuItem = new MenuItem();
108 protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
110 final AlignmentPanel ap;
112 MenuItem unGroupMenuItem = new MenuItem();
114 MenuItem createGroupMenuItem = new MenuItem();
116 MenuItem nucleotideMenuItem = new MenuItem();
118 MenuItem purinePyrimidineMenuItem = new MenuItem();
120 Menu colourMenu = new Menu();
122 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
124 CheckboxMenuItem showText = new CheckboxMenuItem();
126 CheckboxMenuItem showColourText = new CheckboxMenuItem();
128 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
130 Menu seqShowAnnotationsMenu = new Menu(
131 MessageManager.getString("label.show_annotations"));
133 Menu seqHideAnnotationsMenu = new Menu(
134 MessageManager.getString("label.hide_annotations"));
136 MenuItem seqAddReferenceAnnotations = new MenuItem(
137 MessageManager.getString("label.add_reference_annotations"));
139 Menu groupShowAnnotationsMenu = new Menu(
140 MessageManager.getString("label.show_annotations"));
142 Menu groupHideAnnotationsMenu = new Menu(
143 MessageManager.getString("label.hide_annotations"));
145 MenuItem groupAddReferenceAnnotations = new MenuItem(
146 MessageManager.getString("label.add_reference_annotations"));
148 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
150 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
152 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
154 MenuItem toUpper = new MenuItem(
155 MessageManager.getString("label.to_upper_case"));
157 MenuItem toLower = new MenuItem(
158 MessageManager.getString("label.to_lower_case"));
160 MenuItem toggleCase = new MenuItem(
161 MessageManager.getString("label.toggle_case"));
163 Menu outputmenu = new Menu();
165 Menu seqMenu = new Menu();
167 MenuItem pdb = new MenuItem();
169 MenuItem hideSeqs = new MenuItem();
171 MenuItem repGroup = new MenuItem();
173 MenuItem sequenceName = new MenuItem(
174 MessageManager.getString("label.edit_name_description"));
176 MenuItem sequenceFeature = new MenuItem(
177 MessageManager.getString("label.create_sequence_feature"));
179 MenuItem editSequence = new MenuItem(
180 MessageManager.getString("label.edit_sequence"));
182 MenuItem sequenceDetails = new MenuItem(
183 MessageManager.getString("label.sequence_details"));
185 MenuItem selSeqDetails = new MenuItem(
186 MessageManager.getString("label.sequence_details"));
188 MenuItem makeReferenceSeq = new MenuItem();
192 MenuItem revealAll = new MenuItem();
194 MenuItem revealSeq = new MenuItem();
197 * index of sequence to be revealed
199 int revealSeq_index = -1;
201 Menu menu1 = new Menu();
203 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
204 Vector<String> links)
206 // /////////////////////////////////////////////////////////
207 // If this is activated from the sequence panel, the user may want to
208 // edit or annotate a particular residue. Therefore display the residue menu
210 // If from the IDPanel, we must display the sequence menu
211 // ////////////////////////////////////////////////////////
219 } catch (Exception e)
224 for (String ff : FileFormat.getWritableFormats(true))
226 MenuItem item = new MenuItem(ff);
228 item.addActionListener(this);
229 outputmenu.add(item);
232 buildAnnotationSubmenus();
234 SequenceGroup sg = ap.av.getSelectionGroup();
235 if (sg != null && sg.getSize() > 0)
237 editGroupName.setLabel(MessageManager.formatMessage(
238 "label.name_param", new Object[] { sg.getName() }));
239 showText.setState(sg.getDisplayText());
240 showColourText.setState(sg.getColourText());
241 showBoxes.setState(sg.getDisplayBoxes());
242 displayNonconserved.setState(sg.getShowNonconserved());
243 if (!ap.av.getAlignment().getGroups().contains(sg))
245 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
246 groupMenu.remove(unGroupMenuItem);
250 menu1.setLabel(MessageManager.getString("action.edit_group"));
251 groupMenu.remove(createGroupMenuItem);
261 if (links != null && links.size() > 0)
263 addFeatureLinks(seq, links);
266 // TODO: add group link menu entry here
269 seqMenu.setLabel(seq.getName());
270 if (seq == ap.av.getAlignment().getSeqrep())
272 makeReferenceSeq.setLabel(MessageManager
273 .getString("action.unmark_as_reference"));// Unmark
278 makeReferenceSeq.setLabel(MessageManager
279 .getString("action.set_as_reference")); // );
281 repGroup.setLabel(MessageManager.formatMessage(
282 "label.represent_group_with", new Object[] { seq.getName() }));
289 if (!ap.av.hasHiddenRows())
296 final int index = ap.av.getAlignment().findIndex(seq);
298 if (ap.av.adjustForHiddenSeqs(index)
299 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
301 revealSeq_index = index;
311 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
316 void addFeatureLinks(final SequenceI seq, List<String> links)
318 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
319 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
321 for (String link : links)
323 UrlLink urlLink = null;
326 urlLink = new UrlLink(link);
327 } catch (Exception foo)
329 System.err.println("Exception for URLLink '" + link + "': "
334 if (!urlLink.isValid())
336 System.err.println(urlLink.getInvalidMessage());
340 urlLink.createLinksFromSeq(seq, linkset);
343 addshowLinks(linkMenu, linkset.values());
345 // disable link menu if there are no valid entries
346 if (linkMenu.getItemCount() > 0)
348 linkMenu.setEnabled(true);
352 linkMenu.setEnabled(false);
357 seqMenu.add(linkMenu);
366 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
368 for (List<String> linkstrset : linkset)
370 // split linkstr into label and url
371 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
376 * Build menus for annotation types that may be shown or hidden, and for
377 * 'reference annotations' that may be added to the alignment.
379 private void buildAnnotationSubmenus()
382 * First for the currently selected sequence (if there is one):
384 final List<SequenceI> selectedSequence = (seq == null ? Collections
385 .<SequenceI> emptyList() : Arrays.asList(seq));
386 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
387 seqHideAnnotationsMenu, selectedSequence);
388 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
392 * and repeat for the current selection group (if there is one):
394 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
395 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
397 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
398 groupHideAnnotationsMenu, selectedGroup);
399 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
404 * Determine whether or not to enable 'add reference annotations' menu item.
405 * It is enable if there are any annotations, on any of the selected
406 * sequences, which are not yet on the alignment (visible or not).
409 * @param forSequences
411 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
412 List<SequenceI> forSequences)
414 menuItem.setEnabled(false);
417 * Temporary store to hold distinct calcId / type pairs for the tooltip.
418 * Using TreeMap means calcIds are shown in alphabetical order.
420 SortedMap<String, String> tipEntries = new TreeMap<String, String>();
421 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
422 AlignmentI al = this.ap.av.getAlignment();
423 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
424 tipEntries, candidates, al);
425 if (!candidates.isEmpty())
427 StringBuilder tooltip = new StringBuilder(64);
428 tooltip.append(MessageManager.getString("label.add_annotations_for"));
431 * Found annotations that could be added. Enable the menu item, and
432 * configure its action.
434 menuItem.setEnabled(true);
436 menuItem.addActionListener(new ActionListener()
439 public void actionPerformed(ActionEvent e)
441 addReferenceAnnotations_actionPerformed(candidates);
448 * Add annotations to the sequences and to the alignment.
451 * a map whose keys are sequences on the alignment, and values a list
452 * of annotations to add to each sequence
454 protected void addReferenceAnnotations_actionPerformed(
455 Map<SequenceI, List<AlignmentAnnotation>> candidates)
457 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
458 final AlignmentI alignment = this.ap.getAlignment();
459 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
465 * add a show URL menu item to the given linkMenu
469 * - menu label string
473 private void addshowLink(Menu linkMenu, final String target,
476 addshowLink(linkMenu, target, target, url);
480 * add a show URL menu item to the given linkMenu
484 * - URL target window
486 * - menu label string
490 private void addshowLink(Menu linkMenu, final String target,
491 final String label, final String url)
493 MenuItem item = new MenuItem(label);
494 item.addActionListener(new java.awt.event.ActionListener()
497 public void actionPerformed(ActionEvent e)
499 ap.alignFrame.showURL(url, target);
506 public void itemStateChanged(ItemEvent evt)
508 if (evt.getSource() == abovePIDColour)
510 abovePIDColour_itemStateChanged();
512 else if (evt.getSource() == showColourText)
514 showColourText_itemStateChanged();
516 else if (evt.getSource() == showText)
518 showText_itemStateChanged();
520 else if (evt.getSource() == showBoxes)
522 showBoxes_itemStateChanged();
524 else if (evt.getSource() == displayNonconserved)
526 this.showNonconserved_itemStateChanged();
531 public void actionPerformed(ActionEvent evt)
533 Object source = evt.getSource();
534 if (source == clustalColour)
536 clustalColour_actionPerformed();
538 else if (source == zappoColour)
540 zappoColour_actionPerformed();
542 else if (source == taylorColour)
544 taylorColour_actionPerformed();
546 else if (source == hydrophobicityColour)
548 hydrophobicityColour_actionPerformed();
550 else if (source == helixColour)
552 helixColour_actionPerformed();
554 else if (source == strandColour)
556 strandColour_actionPerformed();
558 else if (source == turnColour)
560 turnColour_actionPerformed();
562 else if (source == buriedColour)
564 buriedColour_actionPerformed();
566 else if (source == nucleotideMenuItem)
568 nucleotideMenuItem_actionPerformed();
570 else if (source == purinePyrimidineMenuItem)
572 purinePyrimidineColour_actionPerformed();
575 else if (source == userDefinedColour)
577 userDefinedColour_actionPerformed();
579 else if (source == PIDColour)
581 PIDColour_actionPerformed();
583 else if (source == BLOSUM62Colour)
585 BLOSUM62Colour_actionPerformed();
587 else if (source == noColourmenuItem)
589 noColourmenuItem_actionPerformed();
591 else if (source == conservationMenuItem)
593 conservationMenuItem_itemStateChanged();
595 else if (source == unGroupMenuItem)
597 unGroupMenuItem_actionPerformed();
600 else if (source == createGroupMenuItem)
602 createGroupMenuItem_actionPerformed();
605 else if (source == sequenceName)
609 else if (source == makeReferenceSeq)
611 makeReferenceSeq_actionPerformed();
613 else if (source == sequenceDetails)
615 showSequenceDetails();
617 else if (source == selSeqDetails)
619 showSequenceSelectionDetails();
621 else if (source == pdb)
625 else if (source == hideSeqs)
627 hideSequences(false);
629 else if (source == repGroup)
633 else if (source == revealSeq)
635 ap.av.showSequence(revealSeq_index);
637 else if (source == revealAll)
639 ap.av.showAllHiddenSeqs();
642 else if (source == editGroupName)
644 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
645 getGroup().getDescription(), " Group Name",
646 "Group Description", ap.alignFrame,
647 "Edit Group Name / Description", 500, 100, true);
651 getGroup().setName(dialog.getName().replace(' ', '_'));
652 getGroup().setDescription(dialog.getDescription());
656 else if (source == copy)
658 ap.alignFrame.copy_actionPerformed();
660 else if (source == cut)
662 ap.alignFrame.cut_actionPerformed();
664 else if (source == editSequence)
666 SequenceGroup sg = ap.av.getSelectionGroup();
672 seq = sg.getSequenceAt(0);
675 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
676 sg.getStartRes(), sg.getEndRes() + 1), null,
677 "Edit Sequence ", null,
679 ap.alignFrame, "Edit Sequence", 500, 100, true);
683 EditCommand editCommand = new EditCommand(
684 MessageManager.getString("label.edit_sequences"),
685 Action.REPLACE, dialog.getName().replace(' ',
686 ap.av.getGapCharacter()),
687 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
688 sg.getStartRes(), sg.getEndRes() + 1,
689 ap.av.getAlignment());
691 ap.alignFrame.addHistoryItem(editCommand);
693 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
698 else if (source == toUpper || source == toLower || source == toggleCase)
700 SequenceGroup sg = ap.av.getSelectionGroup();
703 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
704 sg.getStartRes(), sg.getEndRes() + 1);
709 if (source == toggleCase)
711 description = "Toggle Case";
712 caseChange = ChangeCaseCommand.TOGGLE_CASE;
714 else if (source == toUpper)
716 description = "To Upper Case";
717 caseChange = ChangeCaseCommand.TO_UPPER;
721 description = "To Lower Case";
722 caseChange = ChangeCaseCommand.TO_LOWER;
725 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
726 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
727 startEnd, caseChange);
729 ap.alignFrame.addHistoryItem(caseCommand);
731 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
736 else if (source == sequenceFeature)
738 SequenceGroup sg = ap.av.getSelectionGroup();
744 int rsize = 0, gSize = sg.getSize();
745 SequenceI[] rseqs, seqs = new SequenceI[gSize];
746 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
748 for (int i = 0; i < gSize; i++)
750 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
751 int end = sg.findEndRes(sg.getSequenceAt(i));
754 seqs[rsize] = sg.getSequenceAt(i);
755 features[rsize] = new SequenceFeature(null, null, null, start,
760 rseqs = new SequenceI[rsize];
761 tfeatures = new SequenceFeature[rsize];
762 System.arraycopy(seqs, 0, rseqs, 0, rsize);
763 System.arraycopy(features, 0, tfeatures, 0, rsize);
764 features = tfeatures;
767 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
770 ap.alignFrame.sequenceFeatures.setState(true);
771 ap.av.setShowSequenceFeatures(true);
773 ap.highlightSearchResults(null);
783 void outputText(ActionEvent e)
785 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
787 Frame frame = new Frame();
789 JalviewLite.addFrame(frame, MessageManager.formatMessage(
790 "label.selection_output_command",
791 new Object[] { e.getActionCommand() }), 600, 500);
792 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
793 // now returns a full copy of sequence data
794 // TODO consider using getSequenceSelection instead here
796 FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand());
797 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
798 ap.av.getShowJVSuffix(), ap, true));
802 protected void showSequenceSelectionDetails()
804 createSequenceDetailsReport(ap.av.getSequenceSelection());
807 protected void showSequenceDetails()
809 createSequenceDetailsReport(new SequenceI[] { seq });
812 public void createSequenceDetailsReport(SequenceI[] sequences)
815 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
817 StringBuilder contents = new StringBuilder(128);
818 for (SequenceI seq : sequences)
820 contents.append(MessageManager.formatMessage(
821 "label.annotation_for_displayid",
822 new Object[] { seq.getDisplayId(true) }));
823 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
828 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
829 .getMinMax() : null);
830 contents.append("</p>");
832 Frame frame = new Frame();
834 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
835 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
836 : "Selection"), 600, 500);
837 cap.setText(MessageManager.formatMessage("label.html_content",
838 new Object[] { contents.toString() }));
843 EditNameDialog dialog = new EditNameDialog(seq.getName(),
844 seq.getDescription(), " Sequence Name",
845 "Sequence Description", ap.alignFrame,
846 "Edit Sequence Name / Description", 500, 100, true);
850 seq.setName(dialog.getName());
851 seq.setDescription(dialog.getDescription());
852 ap.paintAlignment(false);
858 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
859 if (pdbs != null&& !pdbs.isEmpty())
861 PDBEntry entry = pdbs.firstElement();
863 if (ap.av.applet.jmolAvailable)
865 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
866 null, ap, DataSourceType.URL);
870 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
871 ap, DataSourceType.URL);
877 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
878 cap.setText(MessageManager.getString("label.paste_pdb_file"));
879 cap.setPDBImport(seq);
880 Frame frame = new Frame();
882 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
883 "label.paste_pdb_file_for_sequence",
884 new Object[] { seq.getName() }), 400, 300);
888 private void jbInit() throws Exception
890 groupMenu.setLabel(MessageManager.getString("label.selection"));
891 sequenceFeature.addActionListener(this);
893 editGroupName.addActionListener(this);
894 unGroupMenuItem.setLabel(MessageManager
895 .getString("action.remove_group"));
896 unGroupMenuItem.addActionListener(this);
898 createGroupMenuItem.setLabel(MessageManager
899 .getString("action.create_group"));
900 createGroupMenuItem.addActionListener(this);
902 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
903 showBoxes.setLabel(MessageManager.getString("action.boxes"));
904 showBoxes.setState(true);
905 showBoxes.addItemListener(this);
906 sequenceName.addActionListener(this);
907 sequenceDetails.addActionListener(this);
908 selSeqDetails.addActionListener(this);
909 displayNonconserved.setLabel(MessageManager
910 .getString("label.show_non_conserved"));
911 displayNonconserved.setState(false);
912 displayNonconserved.addItemListener(this);
913 showText.setLabel(MessageManager.getString("action.text"));
914 showText.addItemListener(this);
915 showColourText.setLabel(MessageManager.getString("label.colour_text"));
916 showColourText.addItemListener(this);
917 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
918 seqMenu.setLabel(MessageManager.getString("label.sequence"));
919 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
920 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
921 repGroup.setLabel(MessageManager.formatMessage(
922 "label.represent_group_with", new Object[] { "" }));
923 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
924 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
925 menu1.setLabel(MessageManager.getString("label.group:"));
931 // groupMenu.add(selSeqDetails);
932 groupMenu.add(groupShowAnnotationsMenu);
933 groupMenu.add(groupHideAnnotationsMenu);
934 groupMenu.add(groupAddReferenceAnnotations);
935 groupMenu.add(editMenu);
936 groupMenu.add(outputmenu);
937 groupMenu.add(sequenceFeature);
938 groupMenu.add(createGroupMenuItem);
939 groupMenu.add(unGroupMenuItem);
940 groupMenu.add(menu1);
942 colourMenu.add(noColourmenuItem);
943 colourMenu.add(clustalColour);
944 colourMenu.add(BLOSUM62Colour);
945 colourMenu.add(PIDColour);
946 colourMenu.add(zappoColour);
947 colourMenu.add(taylorColour);
948 colourMenu.add(hydrophobicityColour);
949 colourMenu.add(helixColour);
950 colourMenu.add(strandColour);
951 colourMenu.add(turnColour);
952 colourMenu.add(buriedColour);
953 colourMenu.add(nucleotideMenuItem);
954 colourMenu.add(purinePyrimidineMenuItem);
955 colourMenu.add(userDefinedColour);
956 colourMenu.addSeparator();
957 colourMenu.add(abovePIDColour);
958 colourMenu.add(conservationMenuItem);
960 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
961 noColourmenuItem.addActionListener(this);
963 clustalColour.setLabel(MessageManager
964 .getString("label.colourScheme_clustal"));
965 clustalColour.addActionListener(this);
966 zappoColour.setLabel(MessageManager
967 .getString("label.colourScheme_zappo"));
968 zappoColour.addActionListener(this);
969 taylorColour.setLabel(MessageManager
970 .getString("label.colourScheme_taylor"));
971 taylorColour.addActionListener(this);
972 hydrophobicityColour.setLabel(MessageManager
973 .getString("label.colourScheme_hydrophobic"));
974 hydrophobicityColour.addActionListener(this);
975 helixColour.setLabel(MessageManager
976 .getString("label.colourScheme_helix_propensity"));
977 helixColour.addActionListener(this);
978 strandColour.setLabel(MessageManager
979 .getString("label.colourScheme_strand_propensity"));
980 strandColour.addActionListener(this);
981 turnColour.setLabel(MessageManager
982 .getString("label.colourScheme_turn_propensity"));
983 turnColour.addActionListener(this);
984 buriedColour.setLabel(MessageManager
985 .getString("label.colourScheme_buried_index"));
986 buriedColour.addActionListener(this);
987 abovePIDColour.setLabel(MessageManager
988 .getString("label.above_identity_threshold"));
990 userDefinedColour.setLabel(MessageManager
991 .getString("action.user_defined"));
992 userDefinedColour.addActionListener(this);
993 PIDColour.setLabel(MessageManager
994 .getString("label.colourScheme_%_identity"));
995 PIDColour.addActionListener(this);
996 BLOSUM62Colour.setLabel(MessageManager
997 .getString("label.colourScheme_blosum62"));
998 BLOSUM62Colour.addActionListener(this);
999 conservationMenuItem.setLabel(MessageManager
1000 .getString("label.conservation"));
1001 nucleotideMenuItem.setLabel(MessageManager
1002 .getString("label.colourScheme_nucleotide"));
1003 nucleotideMenuItem.addActionListener(this);
1004 purinePyrimidineMenuItem.setLabel(MessageManager
1005 .getString("label.colourScheme_purine/pyrimidine"));
1006 purinePyrimidineMenuItem.addActionListener(this);
1007 conservationMenuItem.addItemListener(this);
1008 abovePIDColour.addItemListener(this);
1011 copy.addActionListener(this);
1013 cut.addActionListener(this);
1015 editMenu.add(editSequence);
1016 editSequence.addActionListener(this);
1018 editMenu.add(toUpper);
1019 toUpper.addActionListener(this);
1020 editMenu.add(toLower);
1021 toLower.addActionListener(this);
1022 editMenu.add(toggleCase);
1023 seqMenu.add(seqShowAnnotationsMenu);
1024 seqMenu.add(seqHideAnnotationsMenu);
1025 seqMenu.add(seqAddReferenceAnnotations);
1026 seqMenu.add(sequenceName);
1027 seqMenu.add(makeReferenceSeq);
1028 // seqMenu.add(sequenceDetails);
1030 if (!ap.av.applet.useXtrnalSviewer)
1034 seqMenu.add(repGroup);
1035 menu1.add(editGroupName);
1036 menu1.add(colourMenu);
1037 menu1.add(showBoxes);
1038 menu1.add(showText);
1039 menu1.add(showColourText);
1040 menu1.add(displayNonconserved);
1041 toggleCase.addActionListener(this);
1042 pdb.addActionListener(this);
1043 hideSeqs.addActionListener(this);
1044 repGroup.addActionListener(this);
1045 revealAll.addActionListener(this);
1046 revealSeq.addActionListener(this);
1047 makeReferenceSeq.addActionListener(this);
1052 ap.paintAlignment(true);
1055 protected void clustalColour_actionPerformed()
1057 SequenceGroup sg = getGroup();
1058 sg.cs = new CollectionColourScheme(new ClustalxColourScheme(sg,
1059 ap.av.getHiddenRepSequences()));
1063 protected void zappoColour_actionPerformed()
1065 getGroup().cs = new CollectionColourScheme(new ZappoColourScheme());
1069 protected void taylorColour_actionPerformed()
1071 getGroup().cs = new CollectionColourScheme(new TaylorColourScheme());
1075 protected void hydrophobicityColour_actionPerformed()
1077 getGroup().cs = new CollectionColourScheme(new HydrophobicColourScheme());
1081 protected void helixColour_actionPerformed()
1083 getGroup().cs = new CollectionColourScheme(new HelixColourScheme());
1087 protected void strandColour_actionPerformed()
1089 getGroup().cs = new CollectionColourScheme(new StrandColourScheme());
1093 protected void turnColour_actionPerformed()
1095 getGroup().cs = new CollectionColourScheme(new TurnColourScheme());
1099 protected void buriedColour_actionPerformed()
1101 getGroup().cs = new CollectionColourScheme(new BuriedColourScheme());
1105 public void nucleotideMenuItem_actionPerformed()
1107 getGroup().cs = new CollectionColourScheme(new NucleotideColourScheme());
1111 public void purinePyrimidineColour_actionPerformed()
1113 getGroup().cs = new CollectionColourScheme(
1114 new PurinePyrimidineColourScheme());
1118 protected void abovePIDColour_itemStateChanged()
1120 SequenceGroup sg = getGroup();
1126 if (abovePIDColour.getState())
1128 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1129 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1130 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1133 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1135 SliderPanel.showPIDSlider();
1139 // remove PIDColouring
1141 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1148 protected void userDefinedColour_actionPerformed()
1150 new UserDefinedColours(ap, getGroup());
1153 protected void PIDColour_actionPerformed()
1155 SequenceGroup sg = getGroup();
1156 sg.cs = new CollectionColourScheme(new PIDColourScheme());
1157 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1158 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1162 protected void BLOSUM62Colour_actionPerformed()
1164 SequenceGroup sg = getGroup();
1166 sg.cs = new CollectionColourScheme(new Blosum62ColourScheme());
1168 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1169 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1174 protected void noColourmenuItem_actionPerformed()
1176 getGroup().cs = null;
1180 protected void conservationMenuItem_itemStateChanged()
1182 SequenceGroup sg = getGroup();
1188 if (conservationMenuItem.getState())
1190 Conservation conservation = Conservation.calculateConservation("Group", sg
1191 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1192 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1194 sg.getGroupColourScheme().setConservation(conservation);
1195 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1196 SliderPanel.showConservationSlider();
1199 // remove ConservationColouring
1201 sg.cs.setConservation(null);
1207 SequenceGroup getGroup()
1209 SequenceGroup sg = ap.av.getSelectionGroup();
1211 // this method won't add a new group if it already exists
1214 ap.av.getAlignment().addGroup(sg);
1220 void unGroupMenuItem_actionPerformed()
1222 SequenceGroup sg = ap.av.getSelectionGroup();
1223 ap.av.getAlignment().deleteGroup(sg);
1224 ap.av.setSelectionGroup(null);
1225 ap.paintAlignment(true);
1228 void createGroupMenuItem_actionPerformed()
1230 getGroup(); // implicitly create group
1234 public void showColourText_itemStateChanged()
1236 getGroup().setColourText(showColourText.getState());
1240 public void showText_itemStateChanged()
1242 getGroup().setDisplayText(showText.getState());
1246 public void makeReferenceSeq_actionPerformed()
1248 if (!ap.av.getAlignment().hasSeqrep())
1250 // initialise the display flags so the user sees something happen
1251 ap.av.setDisplayReferenceSeq(true);
1252 ap.av.setColourByReferenceSeq(true);
1253 ap.av.getAlignment().setSeqrep(seq);
1257 if (ap.av.getAlignment().getSeqrep() == seq)
1259 ap.av.getAlignment().setSeqrep(null);
1263 ap.av.getAlignment().setSeqrep(seq);
1269 public void showNonconserved_itemStateChanged()
1271 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1275 public void showBoxes_itemStateChanged()
1277 getGroup().setDisplayBoxes(showBoxes.getState());
1281 void hideSequences(boolean representGroup)
1283 ap.av.hideSequences(seq, representGroup);
1287 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1288 * "All" is added first, followed by a separator. Then add any annotation
1289 * types associated with the current selection. Separate menus are built for
1290 * the selected sequence group (if any), and the selected sequence.
1292 * Some annotation rows are always rendered together - these can be identified
1293 * by a common graphGroup property > -1. Only one of each group will be marked
1294 * as visible (to avoid duplication of the display). For such groups we add a
1295 * composite type name, e.g.
1297 * IUPredWS (Long), IUPredWS (Short)
1301 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1302 List<SequenceI> forSequences)
1304 showMenu.removeAll();
1305 hideMenu.removeAll();
1307 final List<String> all = Arrays.asList(new String[] { MessageManager
1308 .getString("label.all") });
1309 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1310 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1312 showMenu.addSeparator();
1313 hideMenu.addSeparator();
1315 final AlignmentAnnotation[] annotations = ap.getAlignment()
1316 .getAlignmentAnnotation();
1319 * Find shown/hidden annotations types, distinguished by source (calcId),
1320 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1321 * the insertion order, which is the order of the annotations on the
1324 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1325 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1326 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1327 AlignmentAnnotationUtils.asList(annotations), forSequences);
1329 for (String calcId : hiddenTypes.keySet())
1331 for (List<String> type : hiddenTypes.get(calcId))
1333 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1337 // grey out 'show annotations' if none are hidden
1338 showMenu.setEnabled(!hiddenTypes.isEmpty());
1340 for (String calcId : shownTypes.keySet())
1342 for (List<String> type : shownTypes.get(calcId))
1344 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1348 // grey out 'hide annotations' if none are shown
1349 hideMenu.setEnabled(!shownTypes.isEmpty());
1353 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1356 * @param showOrHideMenu
1357 * the menu to add to
1358 * @param forSequences
1359 * the sequences whose annotations may be shown or hidden
1364 * if true this is a special label meaning 'All'
1365 * @param actionIsShow
1366 * if true, the select menu item action is to show the annotation
1369 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1370 final List<SequenceI> forSequences, String calcId,
1371 final List<String> types, final boolean allTypes,
1372 final boolean actionIsShow)
1374 String label = types.toString(); // [a, b, c]
1375 label = label.substring(1, label.length() - 1);
1376 final MenuItem item = new MenuItem(label);
1377 item.addActionListener(new java.awt.event.ActionListener()
1380 public void actionPerformed(ActionEvent e)
1382 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1383 types, forSequences, allTypes, actionIsShow);
1387 showOrHideMenu.add(item);