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 java.awt.CheckboxMenuItem;
24 import java.awt.Frame;
26 import java.awt.MenuItem;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.awt.event.ItemEvent;
30 import java.awt.event.ItemListener;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.LinkedHashMap;
36 import java.util.List;
38 import java.util.SortedMap;
39 import java.util.TreeMap;
40 import java.util.Vector;
42 import jalview.analysis.AAFrequency;
43 import jalview.analysis.AlignmentAnnotationUtils;
44 import jalview.analysis.AlignmentUtils;
45 import jalview.analysis.Conservation;
46 import jalview.bin.JalviewLite;
47 import jalview.commands.ChangeCaseCommand;
48 import jalview.commands.EditCommand;
49 import jalview.commands.EditCommand.Action;
50 import jalview.datamodel.AlignmentAnnotation;
51 import jalview.datamodel.AlignmentI;
52 import jalview.datamodel.PDBEntry;
53 import jalview.datamodel.SequenceFeature;
54 import jalview.datamodel.SequenceGroup;
55 import jalview.datamodel.SequenceI;
56 import jalview.io.AppletFormatAdapter;
57 import jalview.io.DataSourceType;
58 import jalview.io.FileFormatI;
59 import jalview.io.FileFormats;
60 import jalview.io.SequenceAnnotationReport;
61 import jalview.renderer.ResidueShader;
62 import jalview.renderer.ResidueShaderI;
63 import jalview.schemes.Blosum62ColourScheme;
64 import jalview.schemes.BuriedColourScheme;
65 import jalview.schemes.ClustalxColourScheme;
66 import jalview.schemes.HelixColourScheme;
67 import jalview.schemes.HydrophobicColourScheme;
68 import jalview.schemes.JalviewColourScheme;
69 import jalview.schemes.NucleotideColourScheme;
70 import jalview.schemes.PIDColourScheme;
71 import jalview.schemes.PurinePyrimidineColourScheme;
72 import jalview.schemes.StrandColourScheme;
73 import jalview.schemes.TaylorColourScheme;
74 import jalview.schemes.TurnColourScheme;
75 import jalview.schemes.ZappoColourScheme;
76 import jalview.util.MessageManager;
77 import jalview.util.UrlLink;
79 public class APopupMenu extends java.awt.PopupMenu
80 implements ActionListener, ItemListener
82 Menu groupMenu = new Menu();
84 MenuItem editGroupName = new MenuItem();
86 CheckboxMenuItem noColour = new CheckboxMenuItem();
88 protected CheckboxMenuItem clustalColour = new CheckboxMenuItem();
90 protected CheckboxMenuItem zappoColour = new CheckboxMenuItem();
92 protected CheckboxMenuItem taylorColour = new CheckboxMenuItem();
94 protected CheckboxMenuItem hydrophobicityColour = new CheckboxMenuItem();
96 protected CheckboxMenuItem helixColour = new CheckboxMenuItem();
98 protected CheckboxMenuItem strandColour = new CheckboxMenuItem();
100 protected CheckboxMenuItem turnColour = new CheckboxMenuItem();
102 protected CheckboxMenuItem buriedColour = new CheckboxMenuItem();
104 protected CheckboxMenuItem PIDColour = new CheckboxMenuItem();
106 protected CheckboxMenuItem BLOSUM62Colour = new CheckboxMenuItem();
108 CheckboxMenuItem nucleotideColour = new CheckboxMenuItem();
110 CheckboxMenuItem purinePyrimidineColour = new CheckboxMenuItem();
112 protected MenuItem userDefinedColour = new MenuItem();
114 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
116 MenuItem modifyPID = new MenuItem();
118 protected CheckboxMenuItem conservationColour = new CheckboxMenuItem();
120 MenuItem modifyConservation = new MenuItem();
122 MenuItem noColourmenuItem = new MenuItem();
124 final AlignmentPanel ap;
126 MenuItem unGroupMenuItem = new MenuItem();
128 MenuItem createGroupMenuItem = new MenuItem();
130 Menu colourMenu = new Menu();
132 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
134 CheckboxMenuItem showText = new CheckboxMenuItem();
136 CheckboxMenuItem showColourText = new CheckboxMenuItem();
138 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
140 Menu seqShowAnnotationsMenu = new Menu(
141 MessageManager.getString("label.show_annotations"));
143 Menu seqHideAnnotationsMenu = new Menu(
144 MessageManager.getString("label.hide_annotations"));
146 MenuItem seqAddReferenceAnnotations = new MenuItem(
147 MessageManager.getString("label.add_reference_annotations"));
149 Menu groupShowAnnotationsMenu = new Menu(
150 MessageManager.getString("label.show_annotations"));
152 Menu groupHideAnnotationsMenu = new Menu(
153 MessageManager.getString("label.hide_annotations"));
155 MenuItem groupAddReferenceAnnotations = new MenuItem(
156 MessageManager.getString("label.add_reference_annotations"));
158 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
160 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
162 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
164 MenuItem toUpper = new MenuItem(
165 MessageManager.getString("label.to_upper_case"));
167 MenuItem toLower = new MenuItem(
168 MessageManager.getString("label.to_lower_case"));
170 MenuItem toggleCase = new MenuItem(
171 MessageManager.getString("label.toggle_case"));
173 Menu outputmenu = new Menu();
175 Menu seqMenu = new Menu();
177 MenuItem pdb = new MenuItem();
179 MenuItem hideSeqs = new MenuItem();
181 MenuItem repGroup = new MenuItem();
183 MenuItem sequenceName = new MenuItem(
184 MessageManager.getString("label.edit_name_description"));
186 MenuItem sequenceFeature = new MenuItem(
187 MessageManager.getString("label.create_sequence_feature"));
189 MenuItem editSequence = new MenuItem(
190 MessageManager.getString("label.edit_sequence"));
192 MenuItem sequenceDetails = new MenuItem(
193 MessageManager.getString("label.sequence_details"));
195 MenuItem selSeqDetails = new MenuItem(
196 MessageManager.getString("label.sequence_details"));
198 MenuItem makeReferenceSeq = new MenuItem();
202 MenuItem revealAll = new MenuItem();
204 MenuItem revealSeq = new MenuItem();
207 * index of sequence to be revealed
209 int revealSeq_index = -1;
211 Menu menu1 = new Menu();
213 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
216 // /////////////////////////////////////////////////////////
217 // If this is activated from the sequence panel, the user may want to
218 // edit or annotate a particular residue. Therefore display the residue menu
220 // If from the IDPanel, we must display the sequence menu
221 // ////////////////////////////////////////////////////////
229 } catch (Exception e)
234 for (String ff : FileFormats.getInstance().getWritableFormats(true))
236 MenuItem item = new MenuItem(ff);
238 item.addActionListener(this);
239 outputmenu.add(item);
242 buildAnnotationSubmenus();
244 SequenceGroup sg = ap.av.getSelectionGroup();
245 if (sg != null && sg.getSize() > 0)
247 if (sg.isNucleotide())
249 conservationColour.setEnabled(false);
250 clustalColour.setEnabled(false);
251 BLOSUM62Colour.setEnabled(false);
252 zappoColour.setEnabled(false);
253 taylorColour.setEnabled(false);
254 hydrophobicityColour.setEnabled(false);
255 helixColour.setEnabled(false);
256 strandColour.setEnabled(false);
257 turnColour.setEnabled(false);
258 buriedColour.setEnabled(false);
262 purinePyrimidineColour.setEnabled(false);
263 nucleotideColour.setEnabled(false);
265 editGroupName.setLabel(
266 MessageManager.formatMessage("label.name_param", new Object[]
268 showText.setState(sg.getDisplayText());
269 showColourText.setState(sg.getColourText());
270 showBoxes.setState(sg.getDisplayBoxes());
271 displayNonconserved.setState(sg.getShowNonconserved());
272 if (!ap.av.getAlignment().getGroups().contains(sg))
274 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
275 groupMenu.remove(unGroupMenuItem);
279 menu1.setLabel(MessageManager.getString("action.edit_group"));
280 groupMenu.remove(createGroupMenuItem);
283 abovePIDColour.setState(sg.cs.getThreshold() > 0);
284 conservationColour.setState(sg.cs.conservationApplied());
285 modifyPID.setEnabled(abovePIDColour.getState());
286 modifyConservation.setEnabled(conservationColour.getState());
289 setSelectedColour(sg.cs);
297 if (links != null && links.size() > 0)
299 addFeatureLinks(seq, links);
302 // TODO: add group link menu entry here
305 seqMenu.setLabel(seq.getName());
306 if (seq == ap.av.getAlignment().getSeqrep())
308 makeReferenceSeq.setLabel(
309 MessageManager.getString("action.unmark_as_reference"));// Unmark
314 makeReferenceSeq.setLabel(
315 MessageManager.getString("action.set_as_reference")); // );
317 repGroup.setLabel(MessageManager
318 .formatMessage("label.represent_group_with", new Object[]
326 if (!ap.av.hasHiddenRows())
333 final int index = ap.av.getAlignment().findIndex(seq);
335 if (ap.av.adjustForHiddenSeqs(index)
336 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
338 revealSeq_index = index;
348 * Select the menu item (if any) matching the current colour scheme. This
349 * works by matching the menu item name (not display text) to the canonical
350 * name of the colour scheme.
354 protected void setSelectedColour(ResidueShaderI cs)
356 if (cs == null || cs.getColourScheme() == null)
358 noColour.setState(true);
362 String name = cs.getColourScheme().getSchemeName();
363 for (int i = 0; i < colourMenu.getItemCount(); i++)
365 MenuItem item = colourMenu.getItem(i);
366 if (item instanceof CheckboxMenuItem)
368 if (name.equals(item.getName()))
370 ((CheckboxMenuItem) item).setState(true);
378 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
383 void addFeatureLinks(final SequenceI seq, List<String> links)
385 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
386 Map<String, List<String>> linkset = new LinkedHashMap<>();
388 for (String link : links)
390 UrlLink urlLink = null;
393 urlLink = new UrlLink(link);
394 } catch (Exception foo)
396 System.err.println("Exception for URLLink '" + link + "': "
401 if (!urlLink.isValid())
403 System.err.println(urlLink.getInvalidMessage());
407 urlLink.createLinksFromSeq(seq, linkset);
410 addshowLinks(linkMenu, linkset.values());
412 // disable link menu if there are no valid entries
413 if (linkMenu.getItemCount() > 0)
415 linkMenu.setEnabled(true);
419 linkMenu.setEnabled(false);
424 seqMenu.add(linkMenu);
433 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
435 for (List<String> linkstrset : linkset)
437 // split linkstr into label and url
438 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
443 * Build menus for annotation types that may be shown or hidden, and for
444 * 'reference annotations' that may be added to the alignment.
446 private void buildAnnotationSubmenus()
449 * First for the currently selected sequence (if there is one):
451 final List<SequenceI> selectedSequence = (seq == null
452 ? Collections.<SequenceI> emptyList()
453 : Arrays.asList(seq));
454 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
455 seqHideAnnotationsMenu, selectedSequence);
456 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
460 * and repeat for the current selection group (if there is one):
462 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null
463 ? Collections.<SequenceI> emptyList()
464 : ap.av.getSelectionGroup().getSequences());
465 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
466 groupHideAnnotationsMenu, selectedGroup);
467 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
472 * Determine whether or not to enable 'add reference annotations' menu item.
473 * It is enable if there are any annotations, on any of the selected
474 * sequences, which are not yet on the alignment (visible or not).
477 * @param forSequences
479 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
480 List<SequenceI> forSequences)
482 menuItem.setEnabled(false);
485 * Temporary store to hold distinct calcId / type pairs for the tooltip.
486 * Using TreeMap means calcIds are shown in alphabetical order.
488 SortedMap<String, String> tipEntries = new TreeMap<>();
489 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
490 AlignmentI al = this.ap.av.getAlignment();
491 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
493 if (!candidates.isEmpty())
495 StringBuilder tooltip = new StringBuilder(64);
496 tooltip.append(MessageManager.getString("label.add_annotations_for"));
499 * Found annotations that could be added. Enable the menu item, and
500 * configure its action.
502 menuItem.setEnabled(true);
504 menuItem.addActionListener(new ActionListener()
507 public void actionPerformed(ActionEvent e)
509 addReferenceAnnotations_actionPerformed(candidates);
516 * Add annotations to the sequences and to the alignment.
519 * a map whose keys are sequences on the alignment, and values a list
520 * of annotations to add to each sequence
522 protected void addReferenceAnnotations_actionPerformed(
523 Map<SequenceI, List<AlignmentAnnotation>> candidates)
525 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
526 final AlignmentI alignment = this.ap.getAlignment();
527 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
533 * add a show URL menu item to the given linkMenu
537 * - menu label string
541 private void addshowLink(Menu linkMenu, final String target,
544 addshowLink(linkMenu, target, target, url);
548 * add a show URL menu item to the given linkMenu
552 * - URL target window
554 * - menu label string
558 private void addshowLink(Menu linkMenu, final String target,
559 final String label, final String url)
561 MenuItem item = new MenuItem(label);
562 item.addActionListener(new java.awt.event.ActionListener()
565 public void actionPerformed(ActionEvent e)
567 ap.alignFrame.showURL(url, target);
574 * Actions on selecting / unselecting a checkbox menu item
577 public void itemStateChanged(ItemEvent evt)
579 Object source = evt.getSource();
580 if (source == noColour)
582 noColourmenuItem_actionPerformed();
584 else if (source == clustalColour)
586 clustalColour_actionPerformed();
588 else if (source == BLOSUM62Colour)
590 BLOSUM62Colour_actionPerformed();
592 else if (evt.getSource() == PIDColour)
594 PIDColour_actionPerformed();
596 else if (source == zappoColour)
598 zappoColour_actionPerformed();
600 else if (source == taylorColour)
602 taylorColour_actionPerformed();
604 else if (source == hydrophobicityColour)
606 hydrophobicityColour_actionPerformed();
608 else if (source == helixColour)
610 helixColour_actionPerformed();
612 else if (source == strandColour)
614 strandColour_actionPerformed();
616 else if (source == turnColour)
618 turnColour_actionPerformed();
620 else if (source == buriedColour)
622 buriedColour_actionPerformed();
624 else if (source == nucleotideColour)
626 nucleotideMenuItem_actionPerformed();
628 else if (source == purinePyrimidineColour)
630 purinePyrimidineColour_actionPerformed();
632 else if (source == abovePIDColour)
634 abovePIDColour_itemStateChanged();
636 else if (source == conservationColour)
638 conservationMenuItem_itemStateChanged();
640 else if (source == showColourText)
642 showColourText_itemStateChanged();
644 else if (source == showText)
646 showText_itemStateChanged();
648 else if (source == showBoxes)
650 showBoxes_itemStateChanged();
652 else if (source == displayNonconserved)
654 this.showNonconserved_itemStateChanged();
659 * Actions on clicking a menu item
662 public void actionPerformed(ActionEvent evt)
664 Object source = evt.getSource();
665 if (source == userDefinedColour)
667 userDefinedColour_actionPerformed();
669 else if (source == modifyConservation)
671 conservationMenuItem_itemStateChanged();
673 else if (source == modifyPID)
675 abovePIDColour_itemStateChanged();
677 else if (source == unGroupMenuItem)
679 unGroupMenuItem_actionPerformed();
682 else if (source == createGroupMenuItem)
684 createGroupMenuItem_actionPerformed();
687 else if (source == sequenceName)
691 else if (source == makeReferenceSeq)
693 makeReferenceSeq_actionPerformed();
695 else if (source == sequenceDetails)
697 showSequenceDetails();
699 else if (source == selSeqDetails)
701 showSequenceSelectionDetails();
703 else if (source == pdb)
707 else if (source == hideSeqs)
709 hideSequences(false);
711 else if (source == repGroup)
715 else if (source == revealSeq)
717 ap.av.showSequence(revealSeq_index);
719 else if (source == revealAll)
721 ap.av.showAllHiddenSeqs();
724 else if (source == editGroupName)
726 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
727 getGroup().getDescription(), " Group Name",
728 "Group Description", ap.alignFrame,
729 "Edit Group Name / Description", 500, 100, true);
733 getGroup().setName(dialog.getName().replace(' ', '_'));
734 getGroup().setDescription(dialog.getDescription());
738 else if (source == copy)
740 ap.alignFrame.copy_actionPerformed();
742 else if (source == cut)
744 ap.alignFrame.cut_actionPerformed();
746 else if (source == editSequence)
748 SequenceGroup sg = ap.av.getSelectionGroup();
754 seq = sg.getSequenceAt(0);
757 EditNameDialog dialog = new EditNameDialog(
758 seq.getSequenceAsString(sg.getStartRes(),
760 null, "Edit Sequence ", null,
762 ap.alignFrame, "Edit Sequence", 500, 100, true);
766 EditCommand editCommand = new EditCommand(
767 MessageManager.getString("label.edit_sequences"),
769 dialog.getName().replace(' ', ap.av.getGapCharacter()),
770 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
771 sg.getStartRes(), sg.getEndRes() + 1,
772 ap.av.getAlignment());
774 ap.alignFrame.addHistoryItem(editCommand);
776 ap.av.firePropertyChange("alignment", null,
777 ap.av.getAlignment().getSequences());
781 else if (source == toUpper || source == toLower || source == toggleCase)
783 SequenceGroup sg = ap.av.getSelectionGroup();
786 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
787 sg.getStartRes(), sg.getEndRes() + 1);
792 if (source == toggleCase)
794 description = "Toggle Case";
795 caseChange = ChangeCaseCommand.TOGGLE_CASE;
797 else if (source == toUpper)
799 description = "To Upper Case";
800 caseChange = ChangeCaseCommand.TO_UPPER;
804 description = "To Lower Case";
805 caseChange = ChangeCaseCommand.TO_LOWER;
808 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
809 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
810 startEnd, caseChange);
812 ap.alignFrame.addHistoryItem(caseCommand);
814 ap.av.firePropertyChange("alignment", null,
815 ap.av.getAlignment().getSequences());
819 else if (source == sequenceFeature)
821 SequenceGroup sg = ap.av.getSelectionGroup();
827 int gSize = sg.getSize();
828 List<SequenceI> seqs = new ArrayList<>();
829 List<SequenceFeature> features = new ArrayList<>();
831 for (int i = 0; i < gSize; i++)
833 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
834 int end = sg.findEndRes(sg.getSequenceAt(i));
837 seqs.add(sg.getSequenceAt(i));
838 features.add(new SequenceFeature(null, null, start, end,
845 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
848 ap.alignFrame.sequenceFeatures.setState(true);
849 ap.av.setShowSequenceFeatures(true);
850 ap.av.setSearchResults(null); // clear highlighting
851 ap.repaint(); // draw new/amended features
862 void outputText(ActionEvent e)
864 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
866 Frame frame = new Frame();
868 JalviewLite.addFrame(frame, MessageManager
869 .formatMessage("label.selection_output_command", new Object[]
870 { e.getActionCommand() }), 600, 500);
871 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
872 // now returns a full copy of sequence data
873 // TODO consider using getSequenceSelection instead here
875 FileFormatI fileFormat = FileFormats.getInstance()
876 .forName(e.getActionCommand());
877 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
878 ap.av.getShowJVSuffix(), ap, true));
882 protected void showSequenceSelectionDetails()
884 createSequenceDetailsReport(ap.av.getSequenceSelection());
887 protected void showSequenceDetails()
889 createSequenceDetailsReport(new SequenceI[] { seq });
892 public void createSequenceDetailsReport(SequenceI[] sequences)
895 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
897 StringBuilder contents = new StringBuilder(128);
898 for (SequenceI seq : sequences)
900 contents.append(MessageManager
901 .formatMessage("label.annotation_for_displayid", new Object[]
902 { seq.getDisplayId(true) }));
903 new SequenceAnnotationReport(false).createSequenceAnnotationReport(
904 contents, seq, true, true, ap.seqPanel.seqCanvas.fr);
905 contents.append("</p>");
907 Frame frame = new Frame();
909 jalview.bin.JalviewLite.addFrame(frame,
910 "Sequence Details for " + (sequences.length == 1
911 ? sequences[0].getDisplayId(true)
915 MessageManager.formatMessage("label.html_content", new Object[]
916 { contents.toString() }));
921 EditNameDialog dialog = new EditNameDialog(seq.getName(),
922 seq.getDescription(), " Sequence Name",
923 "Sequence Description", ap.alignFrame,
924 "Edit Sequence Name / Description", 500, 100, true);
928 seq.setName(dialog.getName());
929 seq.setDescription(dialog.getDescription());
930 ap.paintAlignment(false, false);
936 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
937 if (pdbs != null && !pdbs.isEmpty())
939 PDBEntry entry = pdbs.firstElement();
941 if (ap.av.applet.jmolAvailable)
943 new AppletJmol(entry, new SequenceI[] { seq }, null, ap,
948 new mc_view.AppletPDBViewer(entry, new SequenceI[] { seq }, null, ap,
955 CutAndPasteTransfer cap = new CutAndPasteTransfer(true,
957 cap.setText(MessageManager.getString("label.paste_pdb_file"));
958 cap.setPDBImport(seq);
959 Frame frame = new Frame();
961 JalviewLite.addFrame(frame, MessageManager.formatMessage(
962 "label.paste_pdb_file_for_sequence", new Object[]
963 { seq.getName() }), 400, 300);
967 private void jbInit() throws Exception
969 groupMenu.setLabel(MessageManager.getString("label.selection"));
970 sequenceFeature.addActionListener(this);
972 editGroupName.addActionListener(this);
974 .setLabel(MessageManager.getString("action.remove_group"));
975 unGroupMenuItem.addActionListener(this);
978 .setLabel(MessageManager.getString("action.create_group"));
979 createGroupMenuItem.addActionListener(this);
981 modifyPID.setEnabled(abovePIDColour.getState());
982 modifyConservation.setEnabled(conservationColour.getState());
983 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
984 showBoxes.setLabel(MessageManager.getString("action.boxes"));
985 showBoxes.setState(true);
986 showBoxes.addItemListener(this);
987 sequenceName.addActionListener(this);
988 sequenceDetails.addActionListener(this);
989 selSeqDetails.addActionListener(this);
991 .setLabel(MessageManager.getString("label.show_non_conserved"));
992 displayNonconserved.setState(false);
993 displayNonconserved.addItemListener(this);
994 showText.setLabel(MessageManager.getString("action.text"));
995 showText.addItemListener(this);
996 showColourText.setLabel(MessageManager.getString("label.colour_text"));
997 showColourText.addItemListener(this);
998 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
999 seqMenu.setLabel(MessageManager.getString("label.sequence"));
1000 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
1001 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
1002 repGroup.setLabel(MessageManager
1003 .formatMessage("label.represent_group_with", new Object[]
1005 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
1006 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
1007 menu1.setLabel(MessageManager.getString("label.group:"));
1011 this.add(revealSeq);
1012 this.add(revealAll);
1013 // groupMenu.add(selSeqDetails);
1014 groupMenu.add(groupShowAnnotationsMenu);
1015 groupMenu.add(groupHideAnnotationsMenu);
1016 groupMenu.add(groupAddReferenceAnnotations);
1017 groupMenu.add(editMenu);
1018 groupMenu.add(outputmenu);
1019 groupMenu.add(sequenceFeature);
1020 groupMenu.add(createGroupMenuItem);
1021 groupMenu.add(unGroupMenuItem);
1022 groupMenu.add(menu1);
1024 colourMenu.add(noColour);
1025 colourMenu.add(clustalColour);
1026 colourMenu.add(BLOSUM62Colour);
1027 colourMenu.add(PIDColour);
1028 colourMenu.add(zappoColour);
1029 colourMenu.add(taylorColour);
1030 colourMenu.add(hydrophobicityColour);
1031 colourMenu.add(helixColour);
1032 colourMenu.add(strandColour);
1033 colourMenu.add(turnColour);
1034 colourMenu.add(buriedColour);
1035 colourMenu.add(nucleotideColour);
1036 colourMenu.add(purinePyrimidineColour);
1037 colourMenu.add(userDefinedColour);
1038 colourMenu.addSeparator();
1039 colourMenu.add(conservationColour);
1040 colourMenu.add(modifyConservation);
1041 colourMenu.add(abovePIDColour);
1042 colourMenu.add(modifyPID);
1044 noColour.setLabel(MessageManager.getString("label.none"));
1045 noColour.addItemListener(this);
1048 * setName allows setSelectedColour to do its thing
1050 clustalColour.setLabel(
1051 MessageManager.getString("label.colourScheme_clustal"));
1052 clustalColour.setName(JalviewColourScheme.Clustal.toString());
1053 clustalColour.addItemListener(this);
1054 BLOSUM62Colour.setLabel(
1055 MessageManager.getString("label.colourScheme_blosum62"));
1056 BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1057 BLOSUM62Colour.addItemListener(this);
1059 MessageManager.getString("label.colourScheme_%identity"));
1060 PIDColour.setName(JalviewColourScheme.PID.toString());
1061 PIDColour.addItemListener(this);
1063 .setLabel(MessageManager.getString("label.colourScheme_zappo"));
1064 zappoColour.setName(JalviewColourScheme.Zappo.toString());
1065 zappoColour.addItemListener(this);
1066 taylorColour.setLabel(
1067 MessageManager.getString("label.colourScheme_taylor"));
1068 taylorColour.setName(JalviewColourScheme.Taylor.toString());
1069 taylorColour.addItemListener(this);
1070 hydrophobicityColour.setLabel(
1071 MessageManager.getString("label.colourScheme_hydrophobic"));
1072 hydrophobicityColour
1073 .setName(JalviewColourScheme.Hydrophobic.toString());
1074 hydrophobicityColour.addItemListener(this);
1075 helixColour.setLabel(MessageManager
1076 .getString("label.colourScheme_helixpropensity"));
1077 helixColour.setName(JalviewColourScheme.Helix.toString());
1078 helixColour.addItemListener(this);
1079 strandColour.setLabel(MessageManager
1080 .getString("label.colourScheme_strandpropensity"));
1081 strandColour.setName(JalviewColourScheme.Strand.toString());
1082 strandColour.addItemListener(this);
1083 turnColour.setLabel(
1084 MessageManager.getString("label.colourScheme_turnpropensity"));
1085 turnColour.setName(JalviewColourScheme.Turn.toString());
1086 turnColour.addItemListener(this);
1087 buriedColour.setLabel(
1088 MessageManager.getString("label.colourScheme_buriedindex"));
1089 buriedColour.setName(JalviewColourScheme.Buried.toString());
1090 buriedColour.addItemListener(this);
1091 nucleotideColour.setLabel(
1092 MessageManager.getString("label.colourScheme_nucleotide"));
1093 nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1094 nucleotideColour.addItemListener(this);
1095 purinePyrimidineColour.setLabel(MessageManager
1096 .getString("label.colourScheme_purine/pyrimidine"));
1097 purinePyrimidineColour
1098 .setName(JalviewColourScheme.PurinePyrimidine.toString());
1099 purinePyrimidineColour.addItemListener(this);
1102 .setLabel(MessageManager.getString("action.user_defined"));
1103 userDefinedColour.addActionListener(this);
1105 abovePIDColour.setLabel(
1106 MessageManager.getString("label.above_identity_threshold"));
1107 abovePIDColour.addItemListener(this);
1109 MessageManager.getString("label.modify_identity_threshold"));
1110 modifyPID.addActionListener(this);
1112 .setLabel(MessageManager.getString("action.by_conservation"));
1113 conservationColour.addItemListener(this);
1114 modifyConservation.setLabel(MessageManager
1115 .getString("label.modify_conservation_threshold"));
1116 modifyConservation.addActionListener(this);
1118 PIDColour.addActionListener(this);
1119 BLOSUM62Colour.addActionListener(this);
1122 copy.addActionListener(this);
1124 cut.addActionListener(this);
1126 editMenu.add(editSequence);
1127 editSequence.addActionListener(this);
1129 editMenu.add(toUpper);
1130 toUpper.addActionListener(this);
1131 editMenu.add(toLower);
1132 toLower.addActionListener(this);
1133 editMenu.add(toggleCase);
1134 seqMenu.add(seqShowAnnotationsMenu);
1135 seqMenu.add(seqHideAnnotationsMenu);
1136 seqMenu.add(seqAddReferenceAnnotations);
1137 seqMenu.add(sequenceName);
1138 seqMenu.add(makeReferenceSeq);
1139 // seqMenu.add(sequenceDetails);
1141 if (!ap.av.applet.useXtrnalSviewer)
1145 seqMenu.add(repGroup);
1146 menu1.add(editGroupName);
1147 menu1.add(colourMenu);
1148 menu1.add(showBoxes);
1149 menu1.add(showText);
1150 menu1.add(showColourText);
1151 menu1.add(displayNonconserved);
1152 toggleCase.addActionListener(this);
1153 pdb.addActionListener(this);
1154 hideSeqs.addActionListener(this);
1155 repGroup.addActionListener(this);
1156 revealAll.addActionListener(this);
1157 revealSeq.addActionListener(this);
1158 makeReferenceSeq.addActionListener(this);
1163 ap.paintAlignment(true, true);
1166 protected void clustalColour_actionPerformed()
1168 SequenceGroup sg = getGroup();
1169 sg.cs = new ResidueShader(
1170 new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences()));
1174 protected void zappoColour_actionPerformed()
1176 getGroup().cs = new ResidueShader(new ZappoColourScheme());
1180 protected void taylorColour_actionPerformed()
1182 getGroup().cs = new ResidueShader(new TaylorColourScheme());
1186 protected void hydrophobicityColour_actionPerformed()
1188 getGroup().cs = new ResidueShader(new HydrophobicColourScheme());
1192 protected void helixColour_actionPerformed()
1194 getGroup().cs = new ResidueShader(new HelixColourScheme());
1198 protected void strandColour_actionPerformed()
1200 getGroup().cs = new ResidueShader(new StrandColourScheme());
1204 protected void turnColour_actionPerformed()
1206 getGroup().cs = new ResidueShader(new TurnColourScheme());
1210 protected void buriedColour_actionPerformed()
1212 getGroup().cs = new ResidueShader(new BuriedColourScheme());
1216 public void nucleotideMenuItem_actionPerformed()
1218 getGroup().cs = new ResidueShader(new NucleotideColourScheme());
1222 public void purinePyrimidineColour_actionPerformed()
1224 getGroup().cs = new ResidueShader(new PurinePyrimidineColourScheme());
1228 protected void abovePIDColour_itemStateChanged()
1230 SequenceGroup sg = getGroup();
1236 if (abovePIDColour.getState())
1238 sg.cs.setConsensus(AAFrequency.calculate(
1239 sg.getSequences(ap.av.getHiddenRepSequences()), 0,
1240 ap.av.getAlignment().getWidth()));
1241 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,
1242 getGroup().getName());
1244 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1246 SliderPanel.showPIDSlider();
1250 // remove PIDColouring
1252 SliderPanel.hidePIDSlider();
1253 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1255 modifyPID.setEnabled(abovePIDColour.getState());
1259 protected void userDefinedColour_actionPerformed()
1261 new UserDefinedColours(ap, getGroup());
1264 protected void PIDColour_actionPerformed()
1266 SequenceGroup sg = getGroup();
1267 sg.cs = new ResidueShader(new PIDColourScheme());
1268 sg.cs.setConsensus(AAFrequency.calculate(
1269 sg.getSequences(ap.av.getHiddenRepSequences()), 0,
1270 ap.av.getAlignment().getWidth()));
1274 protected void BLOSUM62Colour_actionPerformed()
1276 SequenceGroup sg = getGroup();
1278 sg.cs = new ResidueShader(new Blosum62ColourScheme());
1280 sg.cs.setConsensus(AAFrequency.calculate(
1281 sg.getSequences(ap.av.getHiddenRepSequences()), 0,
1282 ap.av.getAlignment().getWidth()));
1287 protected void noColourmenuItem_actionPerformed()
1289 getGroup().cs = null;
1293 protected void conservationMenuItem_itemStateChanged()
1295 SequenceGroup sg = getGroup();
1301 if (conservationColour.getState())
1303 Conservation conservation = Conservation.calculateConservation(
1304 "Group", sg.getSequences(ap.av.getHiddenRepSequences()), 0,
1305 ap.av.getAlignment().getWidth(), false,
1306 ap.av.getConsPercGaps(), false);
1307 sg.getGroupColourScheme().setConservation(conservation);
1308 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1309 SliderPanel.showConservationSlider();
1312 // remove ConservationColouring
1314 SliderPanel.hideConservationSlider();
1315 sg.cs.setConservation(null);
1317 modifyConservation.setEnabled(conservationColour.getState());
1321 SequenceGroup getGroup()
1323 SequenceGroup sg = ap.av.getSelectionGroup();
1325 // this method won't add a new group if it already exists
1328 ap.av.getAlignment().addGroup(sg);
1334 void unGroupMenuItem_actionPerformed()
1336 SequenceGroup sg = ap.av.getSelectionGroup();
1337 ap.av.getAlignment().deleteGroup(sg);
1338 ap.av.setSelectionGroup(null);
1339 ap.paintAlignment(true, true);
1342 void createGroupMenuItem_actionPerformed()
1344 getGroup(); // implicitly create group
1348 public void showColourText_itemStateChanged()
1350 getGroup().setColourText(showColourText.getState());
1354 public void showText_itemStateChanged()
1356 getGroup().setDisplayText(showText.getState());
1360 public void makeReferenceSeq_actionPerformed()
1362 if (!ap.av.getAlignment().hasSeqrep())
1364 // initialise the display flags so the user sees something happen
1365 ap.av.setDisplayReferenceSeq(true);
1366 ap.av.setColourByReferenceSeq(true);
1367 ap.av.getAlignment().setSeqrep(seq);
1371 if (ap.av.getAlignment().getSeqrep() == seq)
1373 ap.av.getAlignment().setSeqrep(null);
1377 ap.av.getAlignment().setSeqrep(seq);
1383 public void showNonconserved_itemStateChanged()
1385 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1389 public void showBoxes_itemStateChanged()
1391 getGroup().setDisplayBoxes(showBoxes.getState());
1395 void hideSequences(boolean representGroup)
1397 ap.av.hideSequences(seq, representGroup);
1401 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1402 * "All" is added first, followed by a separator. Then add any annotation
1403 * types associated with the current selection. Separate menus are built for
1404 * the selected sequence group (if any), and the selected sequence.
1406 * Some annotation rows are always rendered together - these can be identified
1407 * by a common graphGroup property > -1. Only one of each group will be marked
1408 * as visible (to avoid duplication of the display). For such groups we add a
1409 * composite type name, e.g.
1411 * IUPredWS (Long), IUPredWS (Short)
1415 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1416 List<SequenceI> forSequences)
1418 showMenu.removeAll();
1419 hideMenu.removeAll();
1421 final List<String> all = Arrays
1422 .asList(new String[]
1423 { MessageManager.getString("label.all") });
1424 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
1426 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1428 showMenu.addSeparator();
1429 hideMenu.addSeparator();
1431 final AlignmentAnnotation[] annotations = ap.getAlignment()
1432 .getAlignmentAnnotation();
1435 * Find shown/hidden annotations types, distinguished by source (calcId),
1436 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1437 * the insertion order, which is the order of the annotations on the
1440 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
1441 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
1442 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1443 AlignmentAnnotationUtils.asList(annotations), forSequences);
1445 for (String calcId : hiddenTypes.keySet())
1447 for (List<String> type : hiddenTypes.get(calcId))
1449 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1453 // grey out 'show annotations' if none are hidden
1454 showMenu.setEnabled(!hiddenTypes.isEmpty());
1456 for (String calcId : shownTypes.keySet())
1458 for (List<String> type : shownTypes.get(calcId))
1460 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1464 // grey out 'hide annotations' if none are shown
1465 hideMenu.setEnabled(!shownTypes.isEmpty());
1469 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1472 * @param showOrHideMenu
1473 * the menu to add to
1474 * @param forSequences
1475 * the sequences whose annotations may be shown or hidden
1480 * if true this is a special label meaning 'All'
1481 * @param actionIsShow
1482 * if true, the select menu item action is to show the annotation
1485 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1486 final List<SequenceI> forSequences, String calcId,
1487 final List<String> types, final boolean allTypes,
1488 final boolean actionIsShow)
1490 String label = types.toString(); // [a, b, c]
1491 label = label.substring(1, label.length() - 1);
1492 final MenuItem item = new MenuItem(label);
1493 item.addActionListener(new java.awt.event.ActionListener()
1496 public void actionPerformed(ActionEvent e)
1498 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1499 types, forSequences, allTypes, actionIsShow);
1503 showOrHideMenu.add(item);