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.FileFormatI;
40 import jalview.io.FileFormats;
41 import jalview.io.SequenceAnnotationReport;
42 import jalview.schemes.Blosum62ColourScheme;
43 import jalview.schemes.BuriedColourScheme;
44 import jalview.schemes.ClustalxColourScheme;
45 import jalview.schemes.CollectionColourScheme;
46 import jalview.schemes.CollectionColourSchemeI;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.HydrophobicColourScheme;
49 import jalview.schemes.JalviewColourScheme;
50 import jalview.schemes.NucleotideColourScheme;
51 import jalview.schemes.PIDColourScheme;
52 import jalview.schemes.PurinePyrimidineColourScheme;
53 import jalview.schemes.StrandColourScheme;
54 import jalview.schemes.TaylorColourScheme;
55 import jalview.schemes.TurnColourScheme;
56 import jalview.schemes.ZappoColourScheme;
57 import jalview.util.MessageManager;
58 import jalview.util.UrlLink;
60 import java.awt.CheckboxMenuItem;
61 import java.awt.Frame;
63 import java.awt.MenuItem;
64 import java.awt.event.ActionEvent;
65 import java.awt.event.ActionListener;
66 import java.awt.event.ItemEvent;
67 import java.awt.event.ItemListener;
68 import java.util.Arrays;
69 import java.util.Collection;
70 import java.util.Collections;
71 import java.util.LinkedHashMap;
72 import java.util.List;
74 import java.util.SortedMap;
75 import java.util.TreeMap;
76 import java.util.Vector;
78 public class APopupMenu extends java.awt.PopupMenu implements
79 ActionListener, ItemListener
81 Menu groupMenu = new Menu();
83 MenuItem editGroupName = new MenuItem();
85 CheckboxMenuItem noColour = new CheckboxMenuItem();
87 protected CheckboxMenuItem clustalColour = new CheckboxMenuItem();
89 protected CheckboxMenuItem zappoColour = new CheckboxMenuItem();
91 protected CheckboxMenuItem taylorColour = new CheckboxMenuItem();
93 protected CheckboxMenuItem hydrophobicityColour = new CheckboxMenuItem();
95 protected CheckboxMenuItem helixColour = new CheckboxMenuItem();
97 protected CheckboxMenuItem strandColour = new CheckboxMenuItem();
99 protected CheckboxMenuItem turnColour = new CheckboxMenuItem();
101 protected CheckboxMenuItem buriedColour = new CheckboxMenuItem();
103 protected CheckboxMenuItem PIDColour = new CheckboxMenuItem();
105 protected CheckboxMenuItem BLOSUM62Colour = new CheckboxMenuItem();
107 CheckboxMenuItem nucleotideColour = new CheckboxMenuItem();
109 CheckboxMenuItem purinePyrimidineColour = new CheckboxMenuItem();
111 protected MenuItem userDefinedColour = new MenuItem();
113 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
115 protected CheckboxMenuItem conservationColour = new CheckboxMenuItem();
117 final AlignmentPanel ap;
119 MenuItem unGroupMenuItem = new MenuItem();
121 MenuItem createGroupMenuItem = new MenuItem();
123 Menu colourMenu = new Menu();
125 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
127 CheckboxMenuItem showText = new CheckboxMenuItem();
129 CheckboxMenuItem showColourText = new CheckboxMenuItem();
131 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
133 Menu seqShowAnnotationsMenu = new Menu(
134 MessageManager.getString("label.show_annotations"));
136 Menu seqHideAnnotationsMenu = new Menu(
137 MessageManager.getString("label.hide_annotations"));
139 MenuItem seqAddReferenceAnnotations = new MenuItem(
140 MessageManager.getString("label.add_reference_annotations"));
142 Menu groupShowAnnotationsMenu = new Menu(
143 MessageManager.getString("label.show_annotations"));
145 Menu groupHideAnnotationsMenu = new Menu(
146 MessageManager.getString("label.hide_annotations"));
148 MenuItem groupAddReferenceAnnotations = new MenuItem(
149 MessageManager.getString("label.add_reference_annotations"));
151 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
153 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
155 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
157 MenuItem toUpper = new MenuItem(
158 MessageManager.getString("label.to_upper_case"));
160 MenuItem toLower = new MenuItem(
161 MessageManager.getString("label.to_lower_case"));
163 MenuItem toggleCase = new MenuItem(
164 MessageManager.getString("label.toggle_case"));
166 Menu outputmenu = new Menu();
168 Menu seqMenu = new Menu();
170 MenuItem pdb = new MenuItem();
172 MenuItem hideSeqs = new MenuItem();
174 MenuItem repGroup = new MenuItem();
176 MenuItem sequenceName = new MenuItem(
177 MessageManager.getString("label.edit_name_description"));
179 MenuItem sequenceFeature = new MenuItem(
180 MessageManager.getString("label.create_sequence_feature"));
182 MenuItem editSequence = new MenuItem(
183 MessageManager.getString("label.edit_sequence"));
185 MenuItem sequenceDetails = new MenuItem(
186 MessageManager.getString("label.sequence_details"));
188 MenuItem selSeqDetails = new MenuItem(
189 MessageManager.getString("label.sequence_details"));
191 MenuItem makeReferenceSeq = new MenuItem();
195 MenuItem revealAll = new MenuItem();
197 MenuItem revealSeq = new MenuItem();
200 * index of sequence to be revealed
202 int revealSeq_index = -1;
204 Menu menu1 = new Menu();
206 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
207 Vector<String> links)
209 // /////////////////////////////////////////////////////////
210 // If this is activated from the sequence panel, the user may want to
211 // edit or annotate a particular residue. Therefore display the residue menu
213 // If from the IDPanel, we must display the sequence menu
214 // ////////////////////////////////////////////////////////
222 } catch (Exception e)
227 for (String ff : FileFormats.getInstance().getWritableFormats(true))
229 MenuItem item = new MenuItem(ff);
231 item.addActionListener(this);
232 outputmenu.add(item);
235 buildAnnotationSubmenus();
237 SequenceGroup sg = ap.av.getSelectionGroup();
238 if (sg != null && sg.getSize() > 0)
240 editGroupName.setLabel(MessageManager.formatMessage(
241 "label.name_param", new Object[] { sg.getName() }));
242 showText.setState(sg.getDisplayText());
243 showColourText.setState(sg.getColourText());
244 showBoxes.setState(sg.getDisplayBoxes());
245 displayNonconserved.setState(sg.getShowNonconserved());
246 if (!ap.av.getAlignment().getGroups().contains(sg))
248 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
249 groupMenu.remove(unGroupMenuItem);
253 menu1.setLabel(MessageManager.getString("action.edit_group"));
254 groupMenu.remove(createGroupMenuItem);
257 abovePIDColour.setState(sg.cs.getThreshold() > 0);
258 conservationColour.setState(sg.cs.conservationApplied());
261 setSelectedColour(sg.cs);
269 if (links != null && links.size() > 0)
271 addFeatureLinks(seq, links);
274 // TODO: add group link menu entry here
277 seqMenu.setLabel(seq.getName());
278 if (seq == ap.av.getAlignment().getSeqrep())
280 makeReferenceSeq.setLabel(MessageManager
281 .getString("action.unmark_as_reference"));// Unmark
286 makeReferenceSeq.setLabel(MessageManager
287 .getString("action.set_as_reference")); // );
289 repGroup.setLabel(MessageManager.formatMessage(
290 "label.represent_group_with", new Object[] { seq.getName() }));
297 if (!ap.av.hasHiddenRows())
304 final int index = ap.av.getAlignment().findIndex(seq);
306 if (ap.av.adjustForHiddenSeqs(index)
307 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
309 revealSeq_index = index;
319 * Select the menu item (if any) matching the current colour scheme. This
320 * works by matching the menu item name (not display text) to the canonical
321 * name of the colour scheme.
325 protected void setSelectedColour(CollectionColourSchemeI cs)
327 if (cs == null || cs.getColourScheme() == null)
329 noColour.setState(true);
333 String name = cs.getColourScheme().getSchemeName();
334 for (int i = 0; i < colourMenu.getItemCount(); i++)
336 MenuItem item = colourMenu.getItem(i);
337 if (item instanceof CheckboxMenuItem)
339 if (name.equals(item.getName()))
341 ((CheckboxMenuItem) item).setState(true);
349 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
354 void addFeatureLinks(final SequenceI seq, List<String> links)
356 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
357 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
359 for (String link : links)
361 UrlLink urlLink = null;
364 urlLink = new UrlLink(link);
365 } catch (Exception foo)
367 System.err.println("Exception for URLLink '" + link + "': "
372 if (!urlLink.isValid())
374 System.err.println(urlLink.getInvalidMessage());
378 urlLink.createLinksFromSeq(seq, linkset);
381 addshowLinks(linkMenu, linkset.values());
383 // disable link menu if there are no valid entries
384 if (linkMenu.getItemCount() > 0)
386 linkMenu.setEnabled(true);
390 linkMenu.setEnabled(false);
395 seqMenu.add(linkMenu);
404 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
406 for (List<String> linkstrset : linkset)
408 // split linkstr into label and url
409 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
414 * Build menus for annotation types that may be shown or hidden, and for
415 * 'reference annotations' that may be added to the alignment.
417 private void buildAnnotationSubmenus()
420 * First for the currently selected sequence (if there is one):
422 final List<SequenceI> selectedSequence = (seq == null ? Collections
423 .<SequenceI> emptyList() : Arrays.asList(seq));
424 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
425 seqHideAnnotationsMenu, selectedSequence);
426 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
430 * and repeat for the current selection group (if there is one):
432 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
433 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
435 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
436 groupHideAnnotationsMenu, selectedGroup);
437 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
442 * Determine whether or not to enable 'add reference annotations' menu item.
443 * It is enable if there are any annotations, on any of the selected
444 * sequences, which are not yet on the alignment (visible or not).
447 * @param forSequences
449 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
450 List<SequenceI> forSequences)
452 menuItem.setEnabled(false);
455 * Temporary store to hold distinct calcId / type pairs for the tooltip.
456 * Using TreeMap means calcIds are shown in alphabetical order.
458 SortedMap<String, String> tipEntries = new TreeMap<String, String>();
459 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
460 AlignmentI al = this.ap.av.getAlignment();
461 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
462 tipEntries, candidates, al);
463 if (!candidates.isEmpty())
465 StringBuilder tooltip = new StringBuilder(64);
466 tooltip.append(MessageManager.getString("label.add_annotations_for"));
469 * Found annotations that could be added. Enable the menu item, and
470 * configure its action.
472 menuItem.setEnabled(true);
474 menuItem.addActionListener(new ActionListener()
477 public void actionPerformed(ActionEvent e)
479 addReferenceAnnotations_actionPerformed(candidates);
486 * Add annotations to the sequences and to the alignment.
489 * a map whose keys are sequences on the alignment, and values a list
490 * of annotations to add to each sequence
492 protected void addReferenceAnnotations_actionPerformed(
493 Map<SequenceI, List<AlignmentAnnotation>> candidates)
495 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
496 final AlignmentI alignment = this.ap.getAlignment();
497 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
503 * add a show URL menu item to the given linkMenu
507 * - menu label string
511 private void addshowLink(Menu linkMenu, final String target,
514 addshowLink(linkMenu, target, target, url);
518 * add a show URL menu item to the given linkMenu
522 * - URL target window
524 * - menu label string
528 private void addshowLink(Menu linkMenu, final String target,
529 final String label, final String url)
531 MenuItem item = new MenuItem(label);
532 item.addActionListener(new java.awt.event.ActionListener()
535 public void actionPerformed(ActionEvent e)
537 ap.alignFrame.showURL(url, target);
544 * Actions on selecting / unselecting a checkbox menu item
547 public void itemStateChanged(ItemEvent evt)
549 Object source = evt.getSource();
550 if (source == noColour)
552 noColourmenuItem_actionPerformed();
554 else if (source == clustalColour)
556 clustalColour_actionPerformed();
558 else if (source == BLOSUM62Colour)
560 BLOSUM62Colour_actionPerformed();
562 else if (evt.getSource() == PIDColour)
564 PIDColour_actionPerformed();
566 else if (source == zappoColour)
568 zappoColour_actionPerformed();
570 else if (source == taylorColour)
572 taylorColour_actionPerformed();
574 else if (source == hydrophobicityColour)
576 hydrophobicityColour_actionPerformed();
578 else if (source == helixColour)
580 helixColour_actionPerformed();
582 else if (source == strandColour)
584 strandColour_actionPerformed();
586 else if (source == turnColour)
588 turnColour_actionPerformed();
590 else if (source == buriedColour)
592 buriedColour_actionPerformed();
594 else if (source == nucleotideColour)
596 nucleotideMenuItem_actionPerformed();
598 else if (source == purinePyrimidineColour)
600 purinePyrimidineColour_actionPerformed();
602 else if (source == abovePIDColour)
604 abovePIDColour_itemStateChanged();
606 else if (source == conservationColour)
608 conservationMenuItem_itemStateChanged();
610 else if (source == showColourText)
612 showColourText_itemStateChanged();
614 else if (source == showText)
616 showText_itemStateChanged();
618 else if (source == showBoxes)
620 showBoxes_itemStateChanged();
622 else if (source == displayNonconserved)
624 this.showNonconserved_itemStateChanged();
629 * Actions on clicking a menu item
632 public void actionPerformed(ActionEvent evt)
634 Object source = evt.getSource();
635 if (source == userDefinedColour)
637 userDefinedColour_actionPerformed();
639 else if (source == unGroupMenuItem)
641 unGroupMenuItem_actionPerformed();
644 else if (source == createGroupMenuItem)
646 createGroupMenuItem_actionPerformed();
649 else if (source == sequenceName)
653 else if (source == makeReferenceSeq)
655 makeReferenceSeq_actionPerformed();
657 else if (source == sequenceDetails)
659 showSequenceDetails();
661 else if (source == selSeqDetails)
663 showSequenceSelectionDetails();
665 else if (source == pdb)
669 else if (source == hideSeqs)
671 hideSequences(false);
673 else if (source == repGroup)
677 else if (source == revealSeq)
679 ap.av.showSequence(revealSeq_index);
681 else if (source == revealAll)
683 ap.av.showAllHiddenSeqs();
686 else if (source == editGroupName)
688 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
689 getGroup().getDescription(), " Group Name",
690 "Group Description", ap.alignFrame,
691 "Edit Group Name / Description", 500, 100, true);
695 getGroup().setName(dialog.getName().replace(' ', '_'));
696 getGroup().setDescription(dialog.getDescription());
700 else if (source == copy)
702 ap.alignFrame.copy_actionPerformed();
704 else if (source == cut)
706 ap.alignFrame.cut_actionPerformed();
708 else if (source == editSequence)
710 SequenceGroup sg = ap.av.getSelectionGroup();
716 seq = sg.getSequenceAt(0);
719 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
720 sg.getStartRes(), sg.getEndRes() + 1), null,
721 "Edit Sequence ", null,
723 ap.alignFrame, "Edit Sequence", 500, 100, true);
727 EditCommand editCommand = new EditCommand(
728 MessageManager.getString("label.edit_sequences"),
729 Action.REPLACE, dialog.getName().replace(' ',
730 ap.av.getGapCharacter()),
731 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
732 sg.getStartRes(), sg.getEndRes() + 1,
733 ap.av.getAlignment());
735 ap.alignFrame.addHistoryItem(editCommand);
737 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
742 else if (source == toUpper || source == toLower || source == toggleCase)
744 SequenceGroup sg = ap.av.getSelectionGroup();
747 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
748 sg.getStartRes(), sg.getEndRes() + 1);
753 if (source == toggleCase)
755 description = "Toggle Case";
756 caseChange = ChangeCaseCommand.TOGGLE_CASE;
758 else if (source == toUpper)
760 description = "To Upper Case";
761 caseChange = ChangeCaseCommand.TO_UPPER;
765 description = "To Lower Case";
766 caseChange = ChangeCaseCommand.TO_LOWER;
769 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
770 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
771 startEnd, caseChange);
773 ap.alignFrame.addHistoryItem(caseCommand);
775 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
780 else if (source == sequenceFeature)
782 SequenceGroup sg = ap.av.getSelectionGroup();
788 int rsize = 0, gSize = sg.getSize();
789 SequenceI[] rseqs, seqs = new SequenceI[gSize];
790 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
792 for (int i = 0; i < gSize; i++)
794 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
795 int end = sg.findEndRes(sg.getSequenceAt(i));
798 seqs[rsize] = sg.getSequenceAt(i);
799 features[rsize] = new SequenceFeature(null, null, null, start,
804 rseqs = new SequenceI[rsize];
805 tfeatures = new SequenceFeature[rsize];
806 System.arraycopy(seqs, 0, rseqs, 0, rsize);
807 System.arraycopy(features, 0, tfeatures, 0, rsize);
808 features = tfeatures;
811 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
814 ap.alignFrame.sequenceFeatures.setState(true);
815 ap.av.setShowSequenceFeatures(true);
817 ap.highlightSearchResults(null);
827 void outputText(ActionEvent e)
829 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
831 Frame frame = new Frame();
833 JalviewLite.addFrame(frame, MessageManager.formatMessage(
834 "label.selection_output_command",
835 new Object[] { e.getActionCommand() }), 600, 500);
836 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
837 // now returns a full copy of sequence data
838 // TODO consider using getSequenceSelection instead here
840 FileFormatI fileFormat = FileFormats.getInstance().forName(
841 e.getActionCommand());
842 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
843 ap.av.getShowJVSuffix(), ap, true));
847 protected void showSequenceSelectionDetails()
849 createSequenceDetailsReport(ap.av.getSequenceSelection());
852 protected void showSequenceDetails()
854 createSequenceDetailsReport(new SequenceI[] { seq });
857 public void createSequenceDetailsReport(SequenceI[] sequences)
860 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
862 StringBuilder contents = new StringBuilder(128);
863 for (SequenceI seq : sequences)
865 contents.append(MessageManager.formatMessage(
866 "label.annotation_for_displayid",
867 new Object[] { seq.getDisplayId(true) }));
868 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
873 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
874 .getMinMax() : null);
875 contents.append("</p>");
877 Frame frame = new Frame();
879 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
880 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
881 : "Selection"), 600, 500);
882 cap.setText(MessageManager.formatMessage("label.html_content",
883 new Object[] { contents.toString() }));
888 EditNameDialog dialog = new EditNameDialog(seq.getName(),
889 seq.getDescription(), " Sequence Name",
890 "Sequence Description", ap.alignFrame,
891 "Edit Sequence Name / Description", 500, 100, true);
895 seq.setName(dialog.getName());
896 seq.setDescription(dialog.getDescription());
897 ap.paintAlignment(false);
903 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
904 if (pdbs != null&& !pdbs.isEmpty())
906 PDBEntry entry = pdbs.firstElement();
908 if (ap.av.applet.jmolAvailable)
910 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
911 null, ap, DataSourceType.URL);
915 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
916 ap, DataSourceType.URL);
922 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
923 cap.setText(MessageManager.getString("label.paste_pdb_file"));
924 cap.setPDBImport(seq);
925 Frame frame = new Frame();
927 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
928 "label.paste_pdb_file_for_sequence",
929 new Object[] { seq.getName() }), 400, 300);
933 private void jbInit() throws Exception
935 groupMenu.setLabel(MessageManager.getString("label.selection"));
936 sequenceFeature.addActionListener(this);
938 editGroupName.addActionListener(this);
939 unGroupMenuItem.setLabel(MessageManager
940 .getString("action.remove_group"));
941 unGroupMenuItem.addActionListener(this);
943 createGroupMenuItem.setLabel(MessageManager
944 .getString("action.create_group"));
945 createGroupMenuItem.addActionListener(this);
947 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
948 showBoxes.setLabel(MessageManager.getString("action.boxes"));
949 showBoxes.setState(true);
950 showBoxes.addItemListener(this);
951 sequenceName.addActionListener(this);
952 sequenceDetails.addActionListener(this);
953 selSeqDetails.addActionListener(this);
954 displayNonconserved.setLabel(MessageManager
955 .getString("label.show_non_conserved"));
956 displayNonconserved.setState(false);
957 displayNonconserved.addItemListener(this);
958 showText.setLabel(MessageManager.getString("action.text"));
959 showText.addItemListener(this);
960 showColourText.setLabel(MessageManager.getString("label.colour_text"));
961 showColourText.addItemListener(this);
962 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
963 seqMenu.setLabel(MessageManager.getString("label.sequence"));
964 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
965 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
966 repGroup.setLabel(MessageManager.formatMessage(
967 "label.represent_group_with", new Object[] { "" }));
968 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
969 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
970 menu1.setLabel(MessageManager.getString("label.group:"));
976 // groupMenu.add(selSeqDetails);
977 groupMenu.add(groupShowAnnotationsMenu);
978 groupMenu.add(groupHideAnnotationsMenu);
979 groupMenu.add(groupAddReferenceAnnotations);
980 groupMenu.add(editMenu);
981 groupMenu.add(outputmenu);
982 groupMenu.add(sequenceFeature);
983 groupMenu.add(createGroupMenuItem);
984 groupMenu.add(unGroupMenuItem);
985 groupMenu.add(menu1);
987 colourMenu.add(noColour);
988 colourMenu.add(clustalColour);
989 colourMenu.add(BLOSUM62Colour);
990 colourMenu.add(PIDColour);
991 colourMenu.add(zappoColour);
992 colourMenu.add(taylorColour);
993 colourMenu.add(hydrophobicityColour);
994 colourMenu.add(helixColour);
995 colourMenu.add(strandColour);
996 colourMenu.add(turnColour);
997 colourMenu.add(buriedColour);
998 colourMenu.add(nucleotideColour);
999 colourMenu.add(purinePyrimidineColour);
1000 colourMenu.add(userDefinedColour);
1001 colourMenu.addSeparator();
1002 colourMenu.add(abovePIDColour);
1003 colourMenu.add(conservationColour);
1005 noColour.setLabel(MessageManager.getString("label.none"));
1006 noColour.addItemListener(this);
1009 * setName allows setSelectedColour to do its thing
1011 clustalColour.setLabel(MessageManager
1012 .getString("label.colourScheme_clustal"));
1013 clustalColour.setName(JalviewColourScheme.Clustal.toString());
1014 clustalColour.addItemListener(this);
1015 BLOSUM62Colour.setLabel(MessageManager
1016 .getString("label.colourScheme_blosum62"));
1017 BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1018 BLOSUM62Colour.addItemListener(this);
1019 PIDColour.setLabel(MessageManager
1020 .getString("label.colourScheme_%_identity"));
1021 PIDColour.setName(JalviewColourScheme.PID.toString());
1022 PIDColour.addItemListener(this);
1023 zappoColour.setLabel(MessageManager
1024 .getString("label.colourScheme_zappo"));
1025 zappoColour.setName(JalviewColourScheme.Zappo.toString());
1026 zappoColour.addItemListener(this);
1027 taylorColour.setLabel(MessageManager
1028 .getString("label.colourScheme_taylor"));
1029 taylorColour.setName(JalviewColourScheme.Taylor.toString());
1030 taylorColour.addItemListener(this);
1031 hydrophobicityColour.setLabel(MessageManager
1032 .getString("label.colourScheme_hydrophobic"));
1033 hydrophobicityColour
1034 .setName(JalviewColourScheme.Hydrophobic.toString());
1035 hydrophobicityColour.addItemListener(this);
1036 helixColour.setLabel(MessageManager
1037 .getString("label.colourScheme_helix_propensity"));
1038 helixColour.setName(JalviewColourScheme.Helix.toString());
1039 helixColour.addItemListener(this);
1040 strandColour.setLabel(MessageManager
1041 .getString("label.colourScheme_strand_propensity"));
1042 strandColour.setName(JalviewColourScheme.Strand.toString());
1043 strandColour.addItemListener(this);
1044 turnColour.setLabel(MessageManager
1045 .getString("label.colourScheme_turn_propensity"));
1046 turnColour.setName(JalviewColourScheme.Turn.toString());
1047 turnColour.addItemListener(this);
1048 buriedColour.setLabel(MessageManager
1049 .getString("label.colourScheme_buried_index"));
1050 buriedColour.setName(JalviewColourScheme.Buried.toString());
1051 buriedColour.addItemListener(this);
1052 nucleotideColour.setLabel(MessageManager
1053 .getString("label.colourScheme_nucleotide"));
1054 nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1055 nucleotideColour.addItemListener(this);
1056 purinePyrimidineColour.setLabel(MessageManager
1057 .getString("label.colourScheme_purine/pyrimidine"));
1058 purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
1060 purinePyrimidineColour.addItemListener(this);
1062 userDefinedColour.setLabel(MessageManager
1063 .getString("action.user_defined"));
1064 userDefinedColour.addActionListener(this);
1066 abovePIDColour.setLabel(MessageManager
1067 .getString("label.above_identity_threshold"));
1068 abovePIDColour.addItemListener(this);
1069 conservationColour.setLabel(MessageManager
1070 .getString("label.conservation"));
1071 conservationColour.addItemListener(this);
1074 copy.addActionListener(this);
1076 cut.addActionListener(this);
1078 editMenu.add(editSequence);
1079 editSequence.addActionListener(this);
1081 editMenu.add(toUpper);
1082 toUpper.addActionListener(this);
1083 editMenu.add(toLower);
1084 toLower.addActionListener(this);
1085 editMenu.add(toggleCase);
1086 seqMenu.add(seqShowAnnotationsMenu);
1087 seqMenu.add(seqHideAnnotationsMenu);
1088 seqMenu.add(seqAddReferenceAnnotations);
1089 seqMenu.add(sequenceName);
1090 seqMenu.add(makeReferenceSeq);
1091 // seqMenu.add(sequenceDetails);
1093 if (!ap.av.applet.useXtrnalSviewer)
1097 seqMenu.add(repGroup);
1098 menu1.add(editGroupName);
1099 menu1.add(colourMenu);
1100 menu1.add(showBoxes);
1101 menu1.add(showText);
1102 menu1.add(showColourText);
1103 menu1.add(displayNonconserved);
1104 toggleCase.addActionListener(this);
1105 pdb.addActionListener(this);
1106 hideSeqs.addActionListener(this);
1107 repGroup.addActionListener(this);
1108 revealAll.addActionListener(this);
1109 revealSeq.addActionListener(this);
1110 makeReferenceSeq.addActionListener(this);
1115 ap.paintAlignment(true);
1118 protected void clustalColour_actionPerformed()
1120 SequenceGroup sg = getGroup();
1121 sg.cs = new CollectionColourScheme(new ClustalxColourScheme(sg,
1122 ap.av.getHiddenRepSequences()));
1126 protected void zappoColour_actionPerformed()
1128 getGroup().cs = new CollectionColourScheme(new ZappoColourScheme());
1132 protected void taylorColour_actionPerformed()
1134 getGroup().cs = new CollectionColourScheme(new TaylorColourScheme());
1138 protected void hydrophobicityColour_actionPerformed()
1140 getGroup().cs = new CollectionColourScheme(new HydrophobicColourScheme());
1144 protected void helixColour_actionPerformed()
1146 getGroup().cs = new CollectionColourScheme(new HelixColourScheme());
1150 protected void strandColour_actionPerformed()
1152 getGroup().cs = new CollectionColourScheme(new StrandColourScheme());
1156 protected void turnColour_actionPerformed()
1158 getGroup().cs = new CollectionColourScheme(new TurnColourScheme());
1162 protected void buriedColour_actionPerformed()
1164 getGroup().cs = new CollectionColourScheme(new BuriedColourScheme());
1168 public void nucleotideMenuItem_actionPerformed()
1170 getGroup().cs = new CollectionColourScheme(new NucleotideColourScheme());
1174 public void purinePyrimidineColour_actionPerformed()
1176 getGroup().cs = new CollectionColourScheme(
1177 new PurinePyrimidineColourScheme());
1181 protected void abovePIDColour_itemStateChanged()
1183 SequenceGroup sg = getGroup();
1189 if (abovePIDColour.getState())
1191 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1192 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1193 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1196 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1198 SliderPanel.showPIDSlider();
1202 // remove PIDColouring
1204 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1211 protected void userDefinedColour_actionPerformed()
1213 new UserDefinedColours(ap, getGroup());
1216 protected void PIDColour_actionPerformed()
1218 SequenceGroup sg = getGroup();
1219 sg.cs = new CollectionColourScheme(new PIDColourScheme());
1220 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1221 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1225 protected void BLOSUM62Colour_actionPerformed()
1227 SequenceGroup sg = getGroup();
1229 sg.cs = new CollectionColourScheme(new Blosum62ColourScheme());
1231 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1232 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1237 protected void noColourmenuItem_actionPerformed()
1239 getGroup().cs = null;
1243 protected void conservationMenuItem_itemStateChanged()
1245 SequenceGroup sg = getGroup();
1251 if (conservationColour.getState())
1253 Conservation conservation = Conservation.calculateConservation(
1255 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1256 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1258 sg.getGroupColourScheme().setConservation(conservation);
1259 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1260 SliderPanel.showConservationSlider();
1263 // remove ConservationColouring
1265 sg.cs.setConservation(null);
1271 SequenceGroup getGroup()
1273 SequenceGroup sg = ap.av.getSelectionGroup();
1275 // this method won't add a new group if it already exists
1278 ap.av.getAlignment().addGroup(sg);
1284 void unGroupMenuItem_actionPerformed()
1286 SequenceGroup sg = ap.av.getSelectionGroup();
1287 ap.av.getAlignment().deleteGroup(sg);
1288 ap.av.setSelectionGroup(null);
1289 ap.paintAlignment(true);
1292 void createGroupMenuItem_actionPerformed()
1294 getGroup(); // implicitly create group
1298 public void showColourText_itemStateChanged()
1300 getGroup().setColourText(showColourText.getState());
1304 public void showText_itemStateChanged()
1306 getGroup().setDisplayText(showText.getState());
1310 public void makeReferenceSeq_actionPerformed()
1312 if (!ap.av.getAlignment().hasSeqrep())
1314 // initialise the display flags so the user sees something happen
1315 ap.av.setDisplayReferenceSeq(true);
1316 ap.av.setColourByReferenceSeq(true);
1317 ap.av.getAlignment().setSeqrep(seq);
1321 if (ap.av.getAlignment().getSeqrep() == seq)
1323 ap.av.getAlignment().setSeqrep(null);
1327 ap.av.getAlignment().setSeqrep(seq);
1333 public void showNonconserved_itemStateChanged()
1335 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1339 public void showBoxes_itemStateChanged()
1341 getGroup().setDisplayBoxes(showBoxes.getState());
1345 void hideSequences(boolean representGroup)
1347 ap.av.hideSequences(seq, representGroup);
1351 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1352 * "All" is added first, followed by a separator. Then add any annotation
1353 * types associated with the current selection. Separate menus are built for
1354 * the selected sequence group (if any), and the selected sequence.
1356 * Some annotation rows are always rendered together - these can be identified
1357 * by a common graphGroup property > -1. Only one of each group will be marked
1358 * as visible (to avoid duplication of the display). For such groups we add a
1359 * composite type name, e.g.
1361 * IUPredWS (Long), IUPredWS (Short)
1365 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1366 List<SequenceI> forSequences)
1368 showMenu.removeAll();
1369 hideMenu.removeAll();
1371 final List<String> all = Arrays.asList(new String[] { MessageManager
1372 .getString("label.all") });
1373 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1374 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1376 showMenu.addSeparator();
1377 hideMenu.addSeparator();
1379 final AlignmentAnnotation[] annotations = ap.getAlignment()
1380 .getAlignmentAnnotation();
1383 * Find shown/hidden annotations types, distinguished by source (calcId),
1384 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1385 * the insertion order, which is the order of the annotations on the
1388 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1389 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1390 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1391 AlignmentAnnotationUtils.asList(annotations), forSequences);
1393 for (String calcId : hiddenTypes.keySet())
1395 for (List<String> type : hiddenTypes.get(calcId))
1397 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1401 // grey out 'show annotations' if none are hidden
1402 showMenu.setEnabled(!hiddenTypes.isEmpty());
1404 for (String calcId : shownTypes.keySet())
1406 for (List<String> type : shownTypes.get(calcId))
1408 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1412 // grey out 'hide annotations' if none are shown
1413 hideMenu.setEnabled(!shownTypes.isEmpty());
1417 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1420 * @param showOrHideMenu
1421 * the menu to add to
1422 * @param forSequences
1423 * the sequences whose annotations may be shown or hidden
1428 * if true this is a special label meaning 'All'
1429 * @param actionIsShow
1430 * if true, the select menu item action is to show the annotation
1433 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1434 final List<SequenceI> forSequences, String calcId,
1435 final List<String> types, final boolean allTypes,
1436 final boolean actionIsShow)
1438 String label = types.toString(); // [a, b, c]
1439 label = label.substring(1, label.length() - 1);
1440 final MenuItem item = new MenuItem(label);
1441 item.addActionListener(new java.awt.event.ActionListener()
1444 public void actionPerformed(ActionEvent e)
1446 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1447 types, forSequences, allTypes, actionIsShow);
1451 showOrHideMenu.add(item);