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.ColourSchemeI;
46 import jalview.schemes.HelixColourScheme;
47 import jalview.schemes.HydrophobicColourScheme;
48 import jalview.schemes.JalviewColourScheme;
49 import jalview.schemes.NucleotideColourScheme;
50 import jalview.schemes.PIDColourScheme;
51 import jalview.schemes.PurinePyrimidineColourScheme;
52 import jalview.schemes.StrandColourScheme;
53 import jalview.schemes.TaylorColourScheme;
54 import jalview.schemes.TurnColourScheme;
55 import jalview.schemes.ZappoColourScheme;
56 import jalview.util.MessageManager;
57 import jalview.util.UrlLink;
59 import java.awt.CheckboxMenuItem;
60 import java.awt.Frame;
62 import java.awt.MenuItem;
63 import java.awt.event.ActionEvent;
64 import java.awt.event.ActionListener;
65 import java.awt.event.ItemEvent;
66 import java.awt.event.ItemListener;
67 import java.util.Arrays;
68 import java.util.Collection;
69 import java.util.Collections;
70 import java.util.LinkedHashMap;
71 import java.util.List;
73 import java.util.SortedMap;
74 import java.util.TreeMap;
75 import java.util.Vector;
77 public class APopupMenu extends java.awt.PopupMenu implements
78 ActionListener, ItemListener
80 Menu groupMenu = new Menu();
82 MenuItem editGroupName = new MenuItem();
84 CheckboxMenuItem noColour = new CheckboxMenuItem();
86 protected CheckboxMenuItem clustalColour = new CheckboxMenuItem();
88 protected CheckboxMenuItem zappoColour = new CheckboxMenuItem();
90 protected CheckboxMenuItem taylorColour = new CheckboxMenuItem();
92 protected CheckboxMenuItem hydrophobicityColour = new CheckboxMenuItem();
94 protected CheckboxMenuItem helixColour = new CheckboxMenuItem();
96 protected CheckboxMenuItem strandColour = new CheckboxMenuItem();
98 protected CheckboxMenuItem turnColour = new CheckboxMenuItem();
100 protected CheckboxMenuItem buriedColour = new CheckboxMenuItem();
102 protected CheckboxMenuItem PIDColour = new CheckboxMenuItem();
104 protected CheckboxMenuItem BLOSUM62Colour = new CheckboxMenuItem();
106 CheckboxMenuItem nucleotideColour = new CheckboxMenuItem();
108 CheckboxMenuItem purinePyrimidineColour = new CheckboxMenuItem();
110 protected MenuItem userDefinedColour = new MenuItem();
112 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
114 MenuItem modifyPID = new MenuItem();
116 protected CheckboxMenuItem conservationColour = new CheckboxMenuItem();
118 MenuItem modifyConservation = new MenuItem();
120 MenuItem noColourmenuItem = new MenuItem();
122 final AlignmentPanel ap;
124 MenuItem unGroupMenuItem = new MenuItem();
126 MenuItem createGroupMenuItem = new MenuItem();
128 Menu colourMenu = new Menu();
130 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
132 CheckboxMenuItem showText = new CheckboxMenuItem();
134 CheckboxMenuItem showColourText = new CheckboxMenuItem();
136 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
138 Menu seqShowAnnotationsMenu = new Menu(
139 MessageManager.getString("label.show_annotations"));
141 Menu seqHideAnnotationsMenu = new Menu(
142 MessageManager.getString("label.hide_annotations"));
144 MenuItem seqAddReferenceAnnotations = new MenuItem(
145 MessageManager.getString("label.add_reference_annotations"));
147 Menu groupShowAnnotationsMenu = new Menu(
148 MessageManager.getString("label.show_annotations"));
150 Menu groupHideAnnotationsMenu = new Menu(
151 MessageManager.getString("label.hide_annotations"));
153 MenuItem groupAddReferenceAnnotations = new MenuItem(
154 MessageManager.getString("label.add_reference_annotations"));
156 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
158 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
160 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
162 MenuItem toUpper = new MenuItem(
163 MessageManager.getString("label.to_upper_case"));
165 MenuItem toLower = new MenuItem(
166 MessageManager.getString("label.to_lower_case"));
168 MenuItem toggleCase = new MenuItem(
169 MessageManager.getString("label.toggle_case"));
171 Menu outputmenu = new Menu();
173 Menu seqMenu = new Menu();
175 MenuItem pdb = new MenuItem();
177 MenuItem hideSeqs = new MenuItem();
179 MenuItem repGroup = new MenuItem();
181 MenuItem sequenceName = new MenuItem(
182 MessageManager.getString("label.edit_name_description"));
184 MenuItem sequenceFeature = new MenuItem(
185 MessageManager.getString("label.create_sequence_feature"));
187 MenuItem editSequence = new MenuItem(
188 MessageManager.getString("label.edit_sequence"));
190 MenuItem sequenceDetails = new MenuItem(
191 MessageManager.getString("label.sequence_details"));
193 MenuItem selSeqDetails = new MenuItem(
194 MessageManager.getString("label.sequence_details"));
196 MenuItem makeReferenceSeq = new MenuItem();
200 MenuItem revealAll = new MenuItem();
202 MenuItem revealSeq = new MenuItem();
205 * index of sequence to be revealed
207 int revealSeq_index = -1;
209 Menu menu1 = new Menu();
211 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
212 Vector<String> links)
214 // /////////////////////////////////////////////////////////
215 // If this is activated from the sequence panel, the user may want to
216 // edit or annotate a particular residue. Therefore display the residue menu
218 // If from the IDPanel, we must display the sequence menu
219 // ////////////////////////////////////////////////////////
227 } catch (Exception e)
232 for (String ff : FileFormats.getInstance().getWritableFormats(true))
234 MenuItem item = new MenuItem(ff);
236 item.addActionListener(this);
237 outputmenu.add(item);
240 buildAnnotationSubmenus();
242 SequenceGroup sg = ap.av.getSelectionGroup();
243 if (sg != null && sg.getSize() > 0)
245 editGroupName.setLabel(MessageManager.formatMessage(
246 "label.name_param", new Object[] { sg.getName() }));
247 showText.setState(sg.getDisplayText());
248 showColourText.setState(sg.getColourText());
249 showBoxes.setState(sg.getDisplayBoxes());
250 displayNonconserved.setState(sg.getShowNonconserved());
251 if (!ap.av.getAlignment().getGroups().contains(sg))
253 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
254 groupMenu.remove(unGroupMenuItem);
258 menu1.setLabel(MessageManager.getString("action.edit_group"));
259 groupMenu.remove(createGroupMenuItem);
262 abovePIDColour.setState(sg.cs.getThreshold() > 0);
263 conservationColour.setState(sg.cs.conservationApplied());
264 modifyPID.setEnabled(abovePIDColour.getState());
265 modifyConservation.setEnabled(conservationColour.getState());
268 setSelectedColour(sg.cs);
276 if (links != null && links.size() > 0)
278 addFeatureLinks(seq, links);
281 // TODO: add group link menu entry here
284 seqMenu.setLabel(seq.getName());
285 if (seq == ap.av.getAlignment().getSeqrep())
287 makeReferenceSeq.setLabel(MessageManager
288 .getString("action.unmark_as_reference"));// Unmark
293 makeReferenceSeq.setLabel(MessageManager
294 .getString("action.set_as_reference")); // );
296 repGroup.setLabel(MessageManager.formatMessage(
297 "label.represent_group_with", new Object[] { seq.getName() }));
304 if (!ap.av.hasHiddenRows())
311 final int index = ap.av.getAlignment().findIndex(seq);
313 if (ap.av.adjustForHiddenSeqs(index)
314 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
316 revealSeq_index = index;
326 * Select the menu item (if any) matching the current colour scheme. This
327 * works by matching the menu item name (not display text) to the canonical
328 * name of the colour scheme.
332 protected void setSelectedColour(ColourSchemeI cs)
336 noColour.setState(true);
340 for (int i = 0; i < colourMenu.getItemCount(); i++)
342 MenuItem item = colourMenu.getItem(i);
343 if (item instanceof CheckboxMenuItem)
345 if (cs.getSchemeName().equals(item.getName()))
347 ((CheckboxMenuItem) item).setState(true);
355 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
360 void addFeatureLinks(final SequenceI seq, List<String> links)
362 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
363 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
365 for (String link : links)
367 UrlLink urlLink = null;
370 urlLink = new UrlLink(link);
371 } catch (Exception foo)
373 System.err.println("Exception for URLLink '" + link + "': "
378 if (!urlLink.isValid())
380 System.err.println(urlLink.getInvalidMessage());
384 urlLink.createLinksFromSeq(seq, linkset);
387 addshowLinks(linkMenu, linkset.values());
389 // disable link menu if there are no valid entries
390 if (linkMenu.getItemCount() > 0)
392 linkMenu.setEnabled(true);
396 linkMenu.setEnabled(false);
401 seqMenu.add(linkMenu);
410 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
412 for (List<String> linkstrset : linkset)
414 // split linkstr into label and url
415 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
420 * Build menus for annotation types that may be shown or hidden, and for
421 * 'reference annotations' that may be added to the alignment.
423 private void buildAnnotationSubmenus()
426 * First for the currently selected sequence (if there is one):
428 final List<SequenceI> selectedSequence = (seq == null ? Collections
429 .<SequenceI> emptyList() : Arrays.asList(seq));
430 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
431 seqHideAnnotationsMenu, selectedSequence);
432 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
436 * and repeat for the current selection group (if there is one):
438 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
439 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
441 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
442 groupHideAnnotationsMenu, selectedGroup);
443 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
448 * Determine whether or not to enable 'add reference annotations' menu item.
449 * It is enable if there are any annotations, on any of the selected
450 * sequences, which are not yet on the alignment (visible or not).
453 * @param forSequences
455 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
456 List<SequenceI> forSequences)
458 menuItem.setEnabled(false);
461 * Temporary store to hold distinct calcId / type pairs for the tooltip.
462 * Using TreeMap means calcIds are shown in alphabetical order.
464 SortedMap<String, String> tipEntries = new TreeMap<String, String>();
465 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
466 AlignmentI al = this.ap.av.getAlignment();
467 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
468 tipEntries, candidates, al);
469 if (!candidates.isEmpty())
471 StringBuilder tooltip = new StringBuilder(64);
472 tooltip.append(MessageManager.getString("label.add_annotations_for"));
475 * Found annotations that could be added. Enable the menu item, and
476 * configure its action.
478 menuItem.setEnabled(true);
480 menuItem.addActionListener(new ActionListener()
483 public void actionPerformed(ActionEvent e)
485 addReferenceAnnotations_actionPerformed(candidates);
492 * Add annotations to the sequences and to the alignment.
495 * a map whose keys are sequences on the alignment, and values a list
496 * of annotations to add to each sequence
498 protected void addReferenceAnnotations_actionPerformed(
499 Map<SequenceI, List<AlignmentAnnotation>> candidates)
501 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
502 final AlignmentI alignment = this.ap.getAlignment();
503 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
509 * add a show URL menu item to the given linkMenu
513 * - menu label string
517 private void addshowLink(Menu linkMenu, final String target,
520 addshowLink(linkMenu, target, target, url);
524 * add a show URL menu item to the given linkMenu
528 * - URL target window
530 * - menu label string
534 private void addshowLink(Menu linkMenu, final String target,
535 final String label, final String url)
537 MenuItem item = new MenuItem(label);
538 item.addActionListener(new java.awt.event.ActionListener()
541 public void actionPerformed(ActionEvent e)
543 ap.alignFrame.showURL(url, target);
550 * Actions on selecting / unselecting a checkbox menu item
553 public void itemStateChanged(ItemEvent evt)
555 Object source = evt.getSource();
556 if (source == noColour)
558 noColourmenuItem_actionPerformed();
560 else if (source == clustalColour)
562 clustalColour_actionPerformed();
564 else if (source == BLOSUM62Colour)
566 BLOSUM62Colour_actionPerformed();
568 else if (source == PIDColour)
570 PIDColour_actionPerformed();
572 else if (source == zappoColour)
574 zappoColour_actionPerformed();
576 else if (source == taylorColour)
578 taylorColour_actionPerformed();
580 else if (source == hydrophobicityColour)
582 hydrophobicityColour_actionPerformed();
584 else if (source == helixColour)
586 helixColour_actionPerformed();
588 else if (source == strandColour)
590 strandColour_actionPerformed();
592 else if (source == turnColour)
594 turnColour_actionPerformed();
596 else if (source == buriedColour)
598 buriedColour_actionPerformed();
600 else if (source == nucleotideColour)
602 nucleotideMenuItem_actionPerformed();
604 else if (source == purinePyrimidineColour)
606 purinePyrimidineColour_actionPerformed();
608 else if (source == abovePIDColour)
610 abovePIDColour_itemStateChanged();
612 else if (source == conservationColour)
614 conservationMenuItem_itemStateChanged();
616 else if (source == showColourText)
618 showColourText_itemStateChanged();
620 else if (source == showText)
622 showText_itemStateChanged();
624 else if (source == showBoxes)
626 showBoxes_itemStateChanged();
628 else if (source == displayNonconserved)
630 this.showNonconserved_itemStateChanged();
635 * Actions on clicking a menu item
638 public void actionPerformed(ActionEvent evt)
640 Object source = evt.getSource();
641 if (source == userDefinedColour)
643 userDefinedColour_actionPerformed();
645 else if (source == modifyConservation)
647 conservationMenuItem_itemStateChanged();
649 else if (source == modifyPID)
651 abovePIDColour_itemStateChanged();
653 else if (source == unGroupMenuItem)
655 unGroupMenuItem_actionPerformed();
658 else if (source == createGroupMenuItem)
660 createGroupMenuItem_actionPerformed();
663 else if (source == sequenceName)
667 else if (source == makeReferenceSeq)
669 makeReferenceSeq_actionPerformed();
671 else if (source == sequenceDetails)
673 showSequenceDetails();
675 else if (source == selSeqDetails)
677 showSequenceSelectionDetails();
679 else if (source == pdb)
683 else if (source == hideSeqs)
685 hideSequences(false);
687 else if (source == repGroup)
691 else if (source == revealSeq)
693 ap.av.showSequence(revealSeq_index);
695 else if (source == revealAll)
697 ap.av.showAllHiddenSeqs();
700 else if (source == editGroupName)
702 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
703 getGroup().getDescription(), " Group Name",
704 "Group Description", ap.alignFrame,
705 "Edit Group Name / Description", 500, 100, true);
709 getGroup().setName(dialog.getName().replace(' ', '_'));
710 getGroup().setDescription(dialog.getDescription());
714 else if (source == copy)
716 ap.alignFrame.copy_actionPerformed();
718 else if (source == cut)
720 ap.alignFrame.cut_actionPerformed();
722 else if (source == editSequence)
724 SequenceGroup sg = ap.av.getSelectionGroup();
730 seq = sg.getSequenceAt(0);
733 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
734 sg.getStartRes(), sg.getEndRes() + 1), null,
735 "Edit Sequence ", null,
737 ap.alignFrame, "Edit Sequence", 500, 100, true);
741 EditCommand editCommand = new EditCommand(
742 MessageManager.getString("label.edit_sequences"),
743 Action.REPLACE, dialog.getName().replace(' ',
744 ap.av.getGapCharacter()),
745 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
746 sg.getStartRes(), sg.getEndRes() + 1,
747 ap.av.getAlignment());
749 ap.alignFrame.addHistoryItem(editCommand);
751 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
756 else if (source == toUpper || source == toLower || source == toggleCase)
758 SequenceGroup sg = ap.av.getSelectionGroup();
761 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
762 sg.getStartRes(), sg.getEndRes() + 1);
767 if (source == toggleCase)
769 description = "Toggle Case";
770 caseChange = ChangeCaseCommand.TOGGLE_CASE;
772 else if (source == toUpper)
774 description = "To Upper Case";
775 caseChange = ChangeCaseCommand.TO_UPPER;
779 description = "To Lower Case";
780 caseChange = ChangeCaseCommand.TO_LOWER;
783 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
784 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
785 startEnd, caseChange);
787 ap.alignFrame.addHistoryItem(caseCommand);
789 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
794 else if (source == sequenceFeature)
796 SequenceGroup sg = ap.av.getSelectionGroup();
802 int rsize = 0, gSize = sg.getSize();
803 SequenceI[] rseqs, seqs = new SequenceI[gSize];
804 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
806 for (int i = 0; i < gSize; i++)
808 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
809 int end = sg.findEndRes(sg.getSequenceAt(i));
812 seqs[rsize] = sg.getSequenceAt(i);
813 features[rsize] = new SequenceFeature(null, null, null, start,
818 rseqs = new SequenceI[rsize];
819 tfeatures = new SequenceFeature[rsize];
820 System.arraycopy(seqs, 0, rseqs, 0, rsize);
821 System.arraycopy(features, 0, tfeatures, 0, rsize);
822 features = tfeatures;
825 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
828 ap.alignFrame.sequenceFeatures.setState(true);
829 ap.av.setShowSequenceFeatures(true);
831 ap.highlightSearchResults(null);
841 void outputText(ActionEvent e)
843 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
845 Frame frame = new Frame();
847 JalviewLite.addFrame(frame, MessageManager.formatMessage(
848 "label.selection_output_command",
849 new Object[] { e.getActionCommand() }), 600, 500);
850 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
851 // now returns a full copy of sequence data
852 // TODO consider using getSequenceSelection instead here
854 FileFormatI fileFormat = FileFormats.getInstance().forName(
855 e.getActionCommand());
856 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
857 ap.av.getShowJVSuffix(), ap, true));
861 protected void showSequenceSelectionDetails()
863 createSequenceDetailsReport(ap.av.getSequenceSelection());
866 protected void showSequenceDetails()
868 createSequenceDetailsReport(new SequenceI[] { seq });
871 public void createSequenceDetailsReport(SequenceI[] sequences)
874 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
876 StringBuilder contents = new StringBuilder(128);
877 for (SequenceI seq : sequences)
879 contents.append(MessageManager.formatMessage(
880 "label.annotation_for_displayid",
881 new Object[] { seq.getDisplayId(true) }));
882 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
887 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
888 .getMinMax() : null);
889 contents.append("</p>");
891 Frame frame = new Frame();
893 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
894 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
895 : "Selection"), 600, 500);
896 cap.setText(MessageManager.formatMessage("label.html_content",
897 new Object[] { contents.toString() }));
902 EditNameDialog dialog = new EditNameDialog(seq.getName(),
903 seq.getDescription(), " Sequence Name",
904 "Sequence Description", ap.alignFrame,
905 "Edit Sequence Name / Description", 500, 100, true);
909 seq.setName(dialog.getName());
910 seq.setDescription(dialog.getDescription());
911 ap.paintAlignment(false);
917 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
918 if (pdbs != null && !pdbs.isEmpty())
920 PDBEntry entry = pdbs.firstElement();
922 if (ap.av.applet.jmolAvailable)
924 new AppletJmol(entry, new SequenceI[] { seq }, null, ap,
929 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
930 ap, DataSourceType.URL);
936 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
937 cap.setText(MessageManager.getString("label.paste_pdb_file"));
938 cap.setPDBImport(seq);
939 Frame frame = new Frame();
941 JalviewLite.addFrame(frame, MessageManager.formatMessage(
942 "label.paste_pdb_file_for_sequence",
943 new Object[] { seq.getName() }), 400, 300);
947 private void jbInit() throws Exception
949 groupMenu.setLabel(MessageManager.getString("label.selection"));
950 sequenceFeature.addActionListener(this);
952 editGroupName.addActionListener(this);
953 unGroupMenuItem.setLabel(MessageManager
954 .getString("action.remove_group"));
955 unGroupMenuItem.addActionListener(this);
957 createGroupMenuItem.setLabel(MessageManager
958 .getString("action.create_group"));
959 createGroupMenuItem.addActionListener(this);
961 modifyPID.setEnabled(abovePIDColour.getState());
962 modifyConservation.setEnabled(conservationColour.getState());
963 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
964 showBoxes.setLabel(MessageManager.getString("action.boxes"));
965 showBoxes.setState(true);
966 showBoxes.addItemListener(this);
967 sequenceName.addActionListener(this);
968 sequenceDetails.addActionListener(this);
969 selSeqDetails.addActionListener(this);
970 displayNonconserved.setLabel(MessageManager
971 .getString("label.show_non_conserved"));
972 displayNonconserved.setState(false);
973 displayNonconserved.addItemListener(this);
974 showText.setLabel(MessageManager.getString("action.text"));
975 showText.addItemListener(this);
976 showColourText.setLabel(MessageManager.getString("label.colour_text"));
977 showColourText.addItemListener(this);
978 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
979 seqMenu.setLabel(MessageManager.getString("label.sequence"));
980 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
981 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
982 repGroup.setLabel(MessageManager.formatMessage(
983 "label.represent_group_with", new Object[] { "" }));
984 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
985 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
986 menu1.setLabel(MessageManager.getString("label.group:"));
992 // groupMenu.add(selSeqDetails);
993 groupMenu.add(groupShowAnnotationsMenu);
994 groupMenu.add(groupHideAnnotationsMenu);
995 groupMenu.add(groupAddReferenceAnnotations);
996 groupMenu.add(editMenu);
997 groupMenu.add(outputmenu);
998 groupMenu.add(sequenceFeature);
999 groupMenu.add(createGroupMenuItem);
1000 groupMenu.add(unGroupMenuItem);
1001 groupMenu.add(menu1);
1003 colourMenu.add(noColour);
1004 colourMenu.add(clustalColour);
1005 colourMenu.add(BLOSUM62Colour);
1006 colourMenu.add(PIDColour);
1007 colourMenu.add(zappoColour);
1008 colourMenu.add(taylorColour);
1009 colourMenu.add(hydrophobicityColour);
1010 colourMenu.add(helixColour);
1011 colourMenu.add(strandColour);
1012 colourMenu.add(turnColour);
1013 colourMenu.add(buriedColour);
1014 colourMenu.add(nucleotideColour);
1015 colourMenu.add(purinePyrimidineColour);
1016 colourMenu.add(userDefinedColour);
1017 colourMenu.addSeparator();
1018 colourMenu.add(conservationColour);
1019 colourMenu.add(modifyConservation);
1020 colourMenu.add(abovePIDColour);
1021 colourMenu.add(modifyPID);
1023 noColour.setLabel(MessageManager.getString("label.none"));
1024 noColour.addItemListener(this);
1027 * setName allows setSelectedColour to do its thing
1029 clustalColour.setLabel(MessageManager
1030 .getString("label.colourScheme_clustal"));
1031 clustalColour.setName(JalviewColourScheme.Clustal.toString());
1032 clustalColour.addItemListener(this);
1033 BLOSUM62Colour.setLabel(MessageManager
1034 .getString("label.colourScheme_blosum62"));
1035 BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1036 BLOSUM62Colour.addItemListener(this);
1037 PIDColour.setLabel(MessageManager
1038 .getString("label.colourScheme_%_identity"));
1039 PIDColour.setName(JalviewColourScheme.PID.toString());
1040 PIDColour.addItemListener(this);
1041 zappoColour.setLabel(MessageManager
1042 .getString("label.colourScheme_zappo"));
1043 zappoColour.setName(JalviewColourScheme.Zappo.toString());
1044 zappoColour.addItemListener(this);
1045 taylorColour.setLabel(MessageManager
1046 .getString("label.colourScheme_taylor"));
1047 taylorColour.setName(JalviewColourScheme.Taylor.toString());
1048 taylorColour.addItemListener(this);
1049 hydrophobicityColour.setLabel(MessageManager
1050 .getString("label.colourScheme_hydrophobic"));
1051 hydrophobicityColour
1052 .setName(JalviewColourScheme.Hydrophobic.toString());
1053 hydrophobicityColour.addItemListener(this);
1054 helixColour.setLabel(MessageManager
1055 .getString("label.colourScheme_helix_propensity"));
1056 helixColour.setName(JalviewColourScheme.Helix.toString());
1057 helixColour.addItemListener(this);
1058 strandColour.setLabel(MessageManager
1059 .getString("label.colourScheme_strand_propensity"));
1060 strandColour.setName(JalviewColourScheme.Strand.toString());
1061 strandColour.addItemListener(this);
1062 turnColour.setLabel(MessageManager
1063 .getString("label.colourScheme_turn_propensity"));
1064 turnColour.setName(JalviewColourScheme.Turn.toString());
1065 turnColour.addItemListener(this);
1066 buriedColour.setLabel(MessageManager
1067 .getString("label.colourScheme_buried_index"));
1068 buriedColour.setName(JalviewColourScheme.Buried.toString());
1069 buriedColour.addItemListener(this);
1070 nucleotideColour.setLabel(MessageManager
1071 .getString("label.colourScheme_nucleotide"));
1072 nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1073 nucleotideColour.addItemListener(this);
1074 purinePyrimidineColour.setLabel(MessageManager
1075 .getString("label.colourScheme_purine/pyrimidine"));
1076 purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
1078 purinePyrimidineColour.addItemListener(this);
1080 userDefinedColour.setLabel(MessageManager
1081 .getString("action.user_defined"));
1082 userDefinedColour.addActionListener(this);
1084 abovePIDColour.setLabel(MessageManager
1085 .getString("label.above_identity_threshold"));
1086 abovePIDColour.addItemListener(this);
1087 modifyPID.setLabel(MessageManager
1088 .getString("label.modify_identity_threshold"));
1089 modifyPID.addActionListener(this);
1090 conservationColour.setLabel(MessageManager
1091 .getString("action.by_conservation"));
1092 conservationColour.addItemListener(this);
1093 modifyConservation.setLabel(MessageManager
1094 .getString("label.modify_conservation_threshold"));
1095 modifyConservation.addActionListener(this);
1097 PIDColour.addActionListener(this);
1098 BLOSUM62Colour.addActionListener(this);
1101 copy.addActionListener(this);
1103 cut.addActionListener(this);
1105 editMenu.add(editSequence);
1106 editSequence.addActionListener(this);
1108 editMenu.add(toUpper);
1109 toUpper.addActionListener(this);
1110 editMenu.add(toLower);
1111 toLower.addActionListener(this);
1112 editMenu.add(toggleCase);
1113 seqMenu.add(seqShowAnnotationsMenu);
1114 seqMenu.add(seqHideAnnotationsMenu);
1115 seqMenu.add(seqAddReferenceAnnotations);
1116 seqMenu.add(sequenceName);
1117 seqMenu.add(makeReferenceSeq);
1118 // seqMenu.add(sequenceDetails);
1120 if (!ap.av.applet.useXtrnalSviewer)
1124 seqMenu.add(repGroup);
1125 menu1.add(editGroupName);
1126 menu1.add(colourMenu);
1127 menu1.add(showBoxes);
1128 menu1.add(showText);
1129 menu1.add(showColourText);
1130 menu1.add(displayNonconserved);
1131 toggleCase.addActionListener(this);
1132 pdb.addActionListener(this);
1133 hideSeqs.addActionListener(this);
1134 repGroup.addActionListener(this);
1135 revealAll.addActionListener(this);
1136 revealSeq.addActionListener(this);
1137 makeReferenceSeq.addActionListener(this);
1142 ap.paintAlignment(true);
1145 protected void clustalColour_actionPerformed()
1147 SequenceGroup sg = getGroup();
1148 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1152 protected void zappoColour_actionPerformed()
1154 getGroup().cs = new ZappoColourScheme();
1158 protected void taylorColour_actionPerformed()
1160 getGroup().cs = new TaylorColourScheme();
1164 protected void hydrophobicityColour_actionPerformed()
1166 getGroup().cs = new HydrophobicColourScheme();
1170 protected void helixColour_actionPerformed()
1172 getGroup().cs = new HelixColourScheme();
1176 protected void strandColour_actionPerformed()
1178 getGroup().cs = new StrandColourScheme();
1182 protected void turnColour_actionPerformed()
1184 getGroup().cs = new TurnColourScheme();
1188 protected void buriedColour_actionPerformed()
1190 getGroup().cs = new BuriedColourScheme();
1194 public void nucleotideMenuItem_actionPerformed()
1196 getGroup().cs = new NucleotideColourScheme();
1200 public void purinePyrimidineColour_actionPerformed()
1202 getGroup().cs = new PurinePyrimidineColourScheme();
1206 protected void abovePIDColour_itemStateChanged()
1208 SequenceGroup sg = getGroup();
1214 if (abovePIDColour.getState())
1216 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1217 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1218 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1221 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1223 SliderPanel.showPIDSlider();
1227 // remove PIDColouring
1229 SliderPanel.hidePIDSlider();
1230 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1232 modifyPID.setEnabled(abovePIDColour.getState());
1236 protected void userDefinedColour_actionPerformed()
1238 new UserDefinedColours(ap, getGroup());
1241 protected void PIDColour_actionPerformed()
1243 SequenceGroup sg = getGroup();
1244 sg.cs = new PIDColourScheme();
1245 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1246 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1250 protected void BLOSUM62Colour_actionPerformed()
1252 SequenceGroup sg = getGroup();
1254 sg.cs = new Blosum62ColourScheme();
1256 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1257 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1262 protected void noColourmenuItem_actionPerformed()
1264 getGroup().cs = null;
1268 protected void conservationMenuItem_itemStateChanged()
1270 SequenceGroup sg = getGroup();
1276 if (conservationColour.getState())
1278 sg.cs.setConservation(Conservation.calculateConservation("Group", sg
1279 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1280 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1282 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1283 SliderPanel.showConservationSlider();
1286 // remove ConservationColouring
1288 SliderPanel.hideConservationSlider();
1289 sg.cs.setConservation(null);
1291 modifyConservation.setEnabled(conservationColour.getState());
1295 SequenceGroup getGroup()
1297 SequenceGroup sg = ap.av.getSelectionGroup();
1299 // this method won't add a new group if it already exists
1302 ap.av.getAlignment().addGroup(sg);
1308 void unGroupMenuItem_actionPerformed()
1310 SequenceGroup sg = ap.av.getSelectionGroup();
1311 ap.av.getAlignment().deleteGroup(sg);
1312 ap.av.setSelectionGroup(null);
1313 ap.paintAlignment(true);
1316 void createGroupMenuItem_actionPerformed()
1318 getGroup(); // implicitly create group
1322 public void showColourText_itemStateChanged()
1324 getGroup().setColourText(showColourText.getState());
1328 public void showText_itemStateChanged()
1330 getGroup().setDisplayText(showText.getState());
1334 public void makeReferenceSeq_actionPerformed()
1336 if (!ap.av.getAlignment().hasSeqrep())
1338 // initialise the display flags so the user sees something happen
1339 ap.av.setDisplayReferenceSeq(true);
1340 ap.av.setColourByReferenceSeq(true);
1341 ap.av.getAlignment().setSeqrep(seq);
1345 if (ap.av.getAlignment().getSeqrep() == seq)
1347 ap.av.getAlignment().setSeqrep(null);
1351 ap.av.getAlignment().setSeqrep(seq);
1357 public void showNonconserved_itemStateChanged()
1359 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1363 public void showBoxes_itemStateChanged()
1365 getGroup().setDisplayBoxes(showBoxes.getState());
1369 void hideSequences(boolean representGroup)
1371 ap.av.hideSequences(seq, representGroup);
1375 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1376 * "All" is added first, followed by a separator. Then add any annotation
1377 * types associated with the current selection. Separate menus are built for
1378 * the selected sequence group (if any), and the selected sequence.
1380 * Some annotation rows are always rendered together - these can be identified
1381 * by a common graphGroup property > -1. Only one of each group will be marked
1382 * as visible (to avoid duplication of the display). For such groups we add a
1383 * composite type name, e.g.
1385 * IUPredWS (Long), IUPredWS (Short)
1389 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1390 List<SequenceI> forSequences)
1392 showMenu.removeAll();
1393 hideMenu.removeAll();
1395 final List<String> all = Arrays.asList(new String[] { MessageManager
1396 .getString("label.all") });
1397 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1398 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1400 showMenu.addSeparator();
1401 hideMenu.addSeparator();
1403 final AlignmentAnnotation[] annotations = ap.getAlignment()
1404 .getAlignmentAnnotation();
1407 * Find shown/hidden annotations types, distinguished by source (calcId),
1408 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1409 * the insertion order, which is the order of the annotations on the
1412 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1413 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1414 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1415 AlignmentAnnotationUtils.asList(annotations), forSequences);
1417 for (String calcId : hiddenTypes.keySet())
1419 for (List<String> type : hiddenTypes.get(calcId))
1421 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1425 // grey out 'show annotations' if none are hidden
1426 showMenu.setEnabled(!hiddenTypes.isEmpty());
1428 for (String calcId : shownTypes.keySet())
1430 for (List<String> type : shownTypes.get(calcId))
1432 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1436 // grey out 'hide annotations' if none are shown
1437 hideMenu.setEnabled(!shownTypes.isEmpty());
1441 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1444 * @param showOrHideMenu
1445 * the menu to add to
1446 * @param forSequences
1447 * the sequences whose annotations may be shown or hidden
1452 * if true this is a special label meaning 'All'
1453 * @param actionIsShow
1454 * if true, the select menu item action is to show the annotation
1457 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1458 final List<SequenceI> forSequences, String calcId,
1459 final List<String> types, final boolean allTypes,
1460 final boolean actionIsShow)
1462 String label = types.toString(); // [a, b, c]
1463 label = label.substring(1, label.length() - 1);
1464 final MenuItem item = new MenuItem(label);
1465 item.addActionListener(new java.awt.event.ActionListener()
1468 public void actionPerformed(ActionEvent e)
1470 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1471 types, forSequences, allTypes, actionIsShow);
1475 showOrHideMenu.add(item);