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.HelixColourScheme;
46 import jalview.schemes.HydrophobicColourScheme;
47 import jalview.schemes.NucleotideColourScheme;
48 import jalview.schemes.PIDColourScheme;
49 import jalview.schemes.StrandColourScheme;
50 import jalview.schemes.TaylorColourScheme;
51 import jalview.schemes.TurnColourScheme;
52 import jalview.schemes.ZappoColourScheme;
53 import jalview.util.MessageManager;
54 import jalview.util.UrlLink;
56 import java.awt.CheckboxMenuItem;
57 import java.awt.Frame;
59 import java.awt.MenuItem;
60 import java.awt.event.ActionEvent;
61 import java.awt.event.ActionListener;
62 import java.awt.event.ItemEvent;
63 import java.awt.event.ItemListener;
64 import java.util.Arrays;
65 import java.util.Collection;
66 import java.util.Collections;
67 import java.util.LinkedHashMap;
68 import java.util.List;
70 import java.util.TreeMap;
71 import java.util.Vector;
73 public class APopupMenu extends java.awt.PopupMenu implements
74 ActionListener, ItemListener
76 Menu groupMenu = new Menu();
78 MenuItem editGroupName = new MenuItem();
80 protected MenuItem clustalColour = new MenuItem();
82 protected MenuItem zappoColour = new MenuItem();
84 protected MenuItem taylorColour = new MenuItem();
86 protected MenuItem hydrophobicityColour = new MenuItem();
88 protected MenuItem helixColour = new MenuItem();
90 protected MenuItem strandColour = new MenuItem();
92 protected MenuItem turnColour = new MenuItem();
94 protected MenuItem buriedColour = new MenuItem();
96 protected MenuItem userDefinedColour = new MenuItem();
98 protected MenuItem PIDColour = new MenuItem();
100 protected MenuItem BLOSUM62Colour = new MenuItem();
102 MenuItem noColourmenuItem = new MenuItem();
104 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
106 MenuItem modifyPID = new MenuItem();
108 protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
110 MenuItem modifyConservation = new MenuItem();
112 final AlignmentPanel ap;
114 MenuItem unGroupMenuItem = new MenuItem();
116 MenuItem createGroupMenuItem = new MenuItem();
118 MenuItem nucleotideMenuItem = new MenuItem();
120 Menu colourMenu = new Menu();
122 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
124 CheckboxMenuItem showText = new CheckboxMenuItem();
126 CheckboxMenuItem showColourText = new CheckboxMenuItem();
128 CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
130 Menu seqShowAnnotationsMenu = new Menu(
131 MessageManager.getString("label.show_annotations"));
133 Menu seqHideAnnotationsMenu = new Menu(
134 MessageManager.getString("label.hide_annotations"));
136 MenuItem seqAddReferenceAnnotations = new MenuItem(
137 MessageManager.getString("label.add_reference_annotations"));
139 Menu groupShowAnnotationsMenu = new Menu(
140 MessageManager.getString("label.show_annotations"));
142 Menu groupHideAnnotationsMenu = new Menu(
143 MessageManager.getString("label.hide_annotations"));
145 MenuItem groupAddReferenceAnnotations = new MenuItem(
146 MessageManager.getString("label.add_reference_annotations"));
148 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
150 MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
152 MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
154 MenuItem toUpper = new MenuItem(
155 MessageManager.getString("label.to_upper_case"));
157 MenuItem toLower = new MenuItem(
158 MessageManager.getString("label.to_lower_case"));
160 MenuItem toggleCase = new MenuItem(
161 MessageManager.getString("label.toggle_case"));
163 Menu outputmenu = new Menu();
165 Menu seqMenu = new Menu();
167 MenuItem pdb = new MenuItem();
169 MenuItem hideSeqs = new MenuItem();
171 MenuItem repGroup = new MenuItem();
173 MenuItem sequenceName = new MenuItem(
174 MessageManager.getString("label.edit_name_description"));
176 MenuItem sequenceFeature = new MenuItem(
177 MessageManager.getString("label.create_sequence_feature"));
179 MenuItem editSequence = new MenuItem(
180 MessageManager.getString("label.edit_sequence"));
182 MenuItem sequenceDetails = new MenuItem(
183 MessageManager.getString("label.sequence_details"));
185 MenuItem selSeqDetails = new MenuItem(
186 MessageManager.getString("label.sequence_details"));
188 MenuItem makeReferenceSeq = new MenuItem();
192 MenuItem revealAll = new MenuItem();
194 MenuItem revealSeq = new MenuItem();
197 * index of sequence to be revealed
199 int revealSeq_index = -1;
201 Menu menu1 = new Menu();
203 public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
204 Vector<String> links)
206 // /////////////////////////////////////////////////////////
207 // If this is activated from the sequence panel, the user may want to
208 // edit or annotate a particular residue. Therefore display the residue menu
210 // If from the IDPanel, we must display the sequence menu
211 // ////////////////////////////////////////////////////////
219 } catch (Exception e)
224 for (String ff : FileFormats.getInstance().getWritableFormats(true))
226 MenuItem item = new MenuItem(ff);
228 item.addActionListener(this);
229 outputmenu.add(item);
232 buildAnnotationSubmenus();
234 SequenceGroup sg = ap.av.getSelectionGroup();
235 if (sg != null && sg.getSize() > 0)
237 editGroupName.setLabel(MessageManager.formatMessage(
238 "label.name_param", new Object[] { sg.getName() }));
239 showText.setState(sg.getDisplayText());
240 showColourText.setState(sg.getColourText());
241 showBoxes.setState(sg.getDisplayBoxes());
242 displayNonconserved.setState(sg.getShowNonconserved());
243 if (!ap.av.getAlignment().getGroups().contains(sg))
245 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
246 groupMenu.remove(unGroupMenuItem);
250 menu1.setLabel(MessageManager.getString("action.edit_group"));
251 groupMenu.remove(createGroupMenuItem);
254 abovePIDColour.setState(sg.cs.getThreshold() > 0);
255 modifyPID.setEnabled(abovePIDColour.getState());
256 conservationMenuItem.setState(sg.cs.conservationApplied());
257 modifyConservation.setEnabled(conservationMenuItem.getState());
267 if (links != null && links.size() > 0)
269 addFeatureLinks(seq, links);
272 // TODO: add group link menu entry here
275 seqMenu.setLabel(seq.getName());
276 if (seq == ap.av.getAlignment().getSeqrep())
278 makeReferenceSeq.setLabel(MessageManager
279 .getString("action.unmark_as_reference"));// Unmark
284 makeReferenceSeq.setLabel(MessageManager
285 .getString("action.set_as_reference")); // );
287 repGroup.setLabel(MessageManager.formatMessage(
288 "label.represent_group_with", new Object[] { seq.getName() }));
295 if (!ap.av.hasHiddenRows())
302 final int index = ap.av.getAlignment().findIndex(seq);
304 if (ap.av.adjustForHiddenSeqs(index)
305 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
307 revealSeq_index = index;
317 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
322 void addFeatureLinks(final SequenceI seq, List<String> links)
324 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
325 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
327 for (String link : links)
329 UrlLink urlLink = null;
332 urlLink = new UrlLink(link);
333 } catch (Exception foo)
335 System.err.println("Exception for URLLink '" + link + "': "
340 if (!urlLink.isValid())
342 System.err.println(urlLink.getInvalidMessage());
346 urlLink.createLinksFromSeq(seq, linkset);
349 addshowLinks(linkMenu, linkset.values());
351 // disable link menu if there are no valid entries
352 if (linkMenu.getItemCount() > 0)
354 linkMenu.setEnabled(true);
358 linkMenu.setEnabled(false);
363 seqMenu.add(linkMenu);
372 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
374 for (List<String> linkstrset : linkset)
376 // split linkstr into label and url
377 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
382 * Build menus for annotation types that may be shown or hidden, and for
383 * 'reference annotations' that may be added to the alignment.
385 private void buildAnnotationSubmenus()
388 * First for the currently selected sequence (if there is one):
390 final List<SequenceI> selectedSequence = (seq == null ? Collections
391 .<SequenceI> emptyList() : Arrays.asList(seq));
392 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
393 seqHideAnnotationsMenu, selectedSequence);
394 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
398 * and repeat for the current selection group (if there is one):
400 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
401 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
403 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
404 groupHideAnnotationsMenu, selectedGroup);
405 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
410 * Determine whether or not to enable 'add reference annotations' menu item.
411 * It is enable if there are any annotations, on any of the selected
412 * sequences, which are not yet on the alignment (visible or not).
415 * @param forSequences
417 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
418 List<SequenceI> forSequences)
420 menuItem.setEnabled(false);
423 * Temporary store to hold distinct calcId / type pairs for the tooltip.
424 * Using TreeMap means calcIds are shown in alphabetical order.
426 Map<String, String> tipEntries = new TreeMap<String, String>();
427 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
428 AlignmentI al = this.ap.av.getAlignment();
429 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
430 tipEntries, candidates, al);
431 if (!candidates.isEmpty())
433 StringBuilder tooltip = new StringBuilder(64);
434 tooltip.append(MessageManager.getString("label.add_annotations_for"));
437 * Found annotations that could be added. Enable the menu item, and
438 * configure its action.
440 menuItem.setEnabled(true);
442 menuItem.addActionListener(new ActionListener()
445 public void actionPerformed(ActionEvent e)
447 addReferenceAnnotations_actionPerformed(candidates);
454 * Add annotations to the sequences and to the alignment.
457 * a map whose keys are sequences on the alignment, and values a list
458 * of annotations to add to each sequence
460 protected void addReferenceAnnotations_actionPerformed(
461 Map<SequenceI, List<AlignmentAnnotation>> candidates)
463 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
464 final AlignmentI alignment = this.ap.getAlignment();
465 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
471 * add a show URL menu item to the given linkMenu
475 * - menu label string
479 private void addshowLink(Menu linkMenu, final String target,
482 addshowLink(linkMenu, target, target, url);
486 * add a show URL menu item to the given linkMenu
490 * - URL target window
492 * - menu label string
496 private void addshowLink(Menu linkMenu, final String target,
497 final String label, final String url)
499 MenuItem item = new MenuItem(label);
500 item.addActionListener(new java.awt.event.ActionListener()
503 public void actionPerformed(ActionEvent e)
505 ap.alignFrame.showURL(url, target);
512 public void itemStateChanged(ItemEvent evt)
514 Object source = evt.getSource();
515 if (source == abovePIDColour)
517 abovePIDColour_itemStateChanged();
519 else if (source == conservationMenuItem)
521 conservationMenuItem_itemStateChanged();
523 else if (source == showColourText)
525 showColourText_itemStateChanged();
527 else if (source == showText)
529 showText_itemStateChanged();
531 else if (source == showBoxes)
533 showBoxes_itemStateChanged();
535 else if (source == displayNonconserved)
537 this.showNonconserved_itemStateChanged();
542 public void actionPerformed(ActionEvent evt)
544 Object source = evt.getSource();
545 if (source == clustalColour)
547 clustalColour_actionPerformed();
549 else if (source == zappoColour)
551 zappoColour_actionPerformed();
553 else if (source == taylorColour)
555 taylorColour_actionPerformed();
557 else if (source == hydrophobicityColour)
559 hydrophobicityColour_actionPerformed();
561 else if (source == helixColour)
563 helixColour_actionPerformed();
565 else if (source == strandColour)
567 strandColour_actionPerformed();
569 else if (source == turnColour)
571 turnColour_actionPerformed();
573 else if (source == buriedColour)
575 buriedColour_actionPerformed();
577 else if (source == nucleotideMenuItem)
579 nucleotideMenuItem_actionPerformed();
582 else if (source == userDefinedColour)
584 userDefinedColour_actionPerformed();
586 else if (source == PIDColour)
588 PIDColour_actionPerformed();
590 else if (source == BLOSUM62Colour)
592 BLOSUM62Colour_actionPerformed();
594 else if (source == noColourmenuItem)
596 noColourmenuItem_actionPerformed();
598 else if (source == modifyConservation)
600 conservationMenuItem_itemStateChanged();
602 else if (source == modifyPID)
604 abovePIDColour_itemStateChanged();
606 else if (source == unGroupMenuItem)
608 unGroupMenuItem_actionPerformed();
611 else if (source == createGroupMenuItem)
613 createGroupMenuItem_actionPerformed();
616 else if (source == sequenceName)
620 else if (source == makeReferenceSeq)
622 makeReferenceSeq_actionPerformed();
624 else if (source == sequenceDetails)
626 showSequenceDetails();
628 else if (source == selSeqDetails)
630 showSequenceSelectionDetails();
632 else if (source == pdb)
636 else if (source == hideSeqs)
638 hideSequences(false);
640 else if (source == repGroup)
644 else if (source == revealSeq)
646 ap.av.showSequence(revealSeq_index);
648 else if (source == revealAll)
650 ap.av.showAllHiddenSeqs();
653 else if (source == editGroupName)
655 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
656 getGroup().getDescription(), " Group Name",
657 "Group Description", ap.alignFrame,
658 "Edit Group Name / Description", 500, 100, true);
662 getGroup().setName(dialog.getName().replace(' ', '_'));
663 getGroup().setDescription(dialog.getDescription());
667 else if (source == copy)
669 ap.alignFrame.copy_actionPerformed();
671 else if (source == cut)
673 ap.alignFrame.cut_actionPerformed();
675 else if (source == editSequence)
677 SequenceGroup sg = ap.av.getSelectionGroup();
683 seq = sg.getSequenceAt(0);
686 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
687 sg.getStartRes(), sg.getEndRes() + 1), null,
688 "Edit Sequence ", null,
690 ap.alignFrame, "Edit Sequence", 500, 100, true);
694 EditCommand editCommand = new EditCommand(
695 MessageManager.getString("label.edit_sequences"),
696 Action.REPLACE, dialog.getName().replace(' ',
697 ap.av.getGapCharacter()),
698 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
699 sg.getStartRes(), sg.getEndRes() + 1,
700 ap.av.getAlignment());
702 ap.alignFrame.addHistoryItem(editCommand);
704 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
709 else if (source == toUpper || source == toLower || source == toggleCase)
711 SequenceGroup sg = ap.av.getSelectionGroup();
714 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
715 sg.getStartRes(), sg.getEndRes() + 1);
720 if (source == toggleCase)
722 description = "Toggle Case";
723 caseChange = ChangeCaseCommand.TOGGLE_CASE;
725 else if (source == toUpper)
727 description = "To Upper Case";
728 caseChange = ChangeCaseCommand.TO_UPPER;
732 description = "To Lower Case";
733 caseChange = ChangeCaseCommand.TO_LOWER;
736 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
737 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
738 startEnd, caseChange);
740 ap.alignFrame.addHistoryItem(caseCommand);
742 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
747 else if (source == sequenceFeature)
749 SequenceGroup sg = ap.av.getSelectionGroup();
755 int rsize = 0, gSize = sg.getSize();
756 SequenceI[] rseqs, seqs = new SequenceI[gSize];
757 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
759 for (int i = 0; i < gSize; i++)
761 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
762 int end = sg.findEndRes(sg.getSequenceAt(i));
765 seqs[rsize] = sg.getSequenceAt(i);
766 features[rsize] = new SequenceFeature(null, null, null, start,
771 rseqs = new SequenceI[rsize];
772 tfeatures = new SequenceFeature[rsize];
773 System.arraycopy(seqs, 0, rseqs, 0, rsize);
774 System.arraycopy(features, 0, tfeatures, 0, rsize);
775 features = tfeatures;
778 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
781 ap.alignFrame.sequenceFeatures.setState(true);
782 ap.av.setShowSequenceFeatures(true);
784 ap.highlightSearchResults(null);
794 void outputText(ActionEvent e)
796 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
798 Frame frame = new Frame();
800 JalviewLite.addFrame(frame, MessageManager.formatMessage(
801 "label.selection_output_command",
802 new Object[] { e.getActionCommand() }), 600, 500);
803 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
804 // now returns a full copy of sequence data
805 // TODO consider using getSequenceSelection instead here
807 FileFormatI fileFormat = FileFormats.getInstance().forName(
808 e.getActionCommand());
809 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
810 ap.av.getShowJVSuffix(), ap, true));
814 protected void showSequenceSelectionDetails()
816 createSequenceDetailsReport(ap.av.getSequenceSelection());
819 protected void showSequenceDetails()
821 createSequenceDetailsReport(new SequenceI[] { seq });
824 public void createSequenceDetailsReport(SequenceI[] sequences)
827 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
829 StringBuilder contents = new StringBuilder(128);
830 for (SequenceI seq : sequences)
832 contents.append(MessageManager.formatMessage(
833 "label.annotation_for_displayid",
834 new Object[] { seq.getDisplayId(true) }));
835 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
840 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
841 .getMinMax() : null);
842 contents.append("</p>");
844 Frame frame = new Frame();
846 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
847 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
848 : "Selection"), 600, 500);
849 cap.setText(MessageManager.formatMessage("label.html_content",
850 new Object[] { contents.toString() }));
855 EditNameDialog dialog = new EditNameDialog(seq.getName(),
856 seq.getDescription(), " Sequence Name",
857 "Sequence Description", ap.alignFrame,
858 "Edit Sequence Name / Description", 500, 100, true);
862 seq.setName(dialog.getName());
863 seq.setDescription(dialog.getDescription());
864 ap.paintAlignment(false);
870 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
871 if (pdbs != null&& !pdbs.isEmpty())
873 PDBEntry entry = pdbs.firstElement();
875 if (ap.av.applet.jmolAvailable)
877 new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
878 null, ap, DataSourceType.URL);
882 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
883 ap, DataSourceType.URL);
889 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
890 cap.setText(MessageManager.getString("label.paste_pdb_file"));
891 cap.setPDBImport(seq);
892 Frame frame = new Frame();
894 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
895 "label.paste_pdb_file_for_sequence",
896 new Object[] { seq.getName() }), 400, 300);
900 private void jbInit() throws Exception
902 groupMenu.setLabel(MessageManager.getString("label.selection"));
903 sequenceFeature.addActionListener(this);
905 editGroupName.addActionListener(this);
906 unGroupMenuItem.setLabel(MessageManager
907 .getString("action.remove_group"));
908 unGroupMenuItem.addActionListener(this);
910 createGroupMenuItem.setLabel(MessageManager
911 .getString("action.create_group"));
912 createGroupMenuItem.addActionListener(this);
914 nucleotideMenuItem.setLabel(MessageManager
915 .getString("label.nucleotide"));
916 nucleotideMenuItem.addActionListener(this);
917 conservationMenuItem.addItemListener(this);
918 abovePIDColour.addItemListener(this);
919 modifyPID.setLabel(MessageManager
920 .getString("label.modify_identity_threshold"));
921 modifyPID.addActionListener(this);
922 modifyConservation.setLabel(MessageManager
923 .getString("label.modify_conservation_threshold"));
924 modifyPID.setEnabled(abovePIDColour.getState());
925 modifyConservation.setEnabled(conservationMenuItem.getState());
926 modifyConservation.addActionListener(this);
927 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
928 showBoxes.setLabel(MessageManager.getString("action.boxes"));
929 showBoxes.setState(true);
930 showBoxes.addItemListener(this);
931 sequenceName.addActionListener(this);
932 sequenceDetails.addActionListener(this);
933 selSeqDetails.addActionListener(this);
934 displayNonconserved.setLabel(MessageManager
935 .getString("label.show_non_conversed"));
936 displayNonconserved.setState(false);
937 displayNonconserved.addItemListener(this);
938 showText.setLabel(MessageManager.getString("action.text"));
939 showText.addItemListener(this);
940 showColourText.setLabel(MessageManager.getString("label.colour_text"));
941 showColourText.addItemListener(this);
942 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
943 seqMenu.setLabel(MessageManager.getString("label.sequence"));
944 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
945 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
946 repGroup.setLabel(MessageManager.formatMessage(
947 "label.represent_group_with", new Object[] { "" }));
948 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
949 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
950 menu1.setLabel(MessageManager.getString("label.group:"));
956 // groupMenu.add(selSeqDetails);
957 groupMenu.add(groupShowAnnotationsMenu);
958 groupMenu.add(groupHideAnnotationsMenu);
959 groupMenu.add(groupAddReferenceAnnotations);
960 groupMenu.add(editMenu);
961 groupMenu.add(outputmenu);
962 groupMenu.add(sequenceFeature);
963 groupMenu.add(createGroupMenuItem);
964 groupMenu.add(unGroupMenuItem);
965 groupMenu.add(menu1);
967 colourMenu.add(noColourmenuItem);
968 colourMenu.add(clustalColour);
969 colourMenu.add(BLOSUM62Colour);
970 colourMenu.add(PIDColour);
971 colourMenu.add(zappoColour);
972 colourMenu.add(taylorColour);
973 colourMenu.add(hydrophobicityColour);
974 colourMenu.add(helixColour);
975 colourMenu.add(strandColour);
976 colourMenu.add(turnColour);
977 colourMenu.add(buriedColour);
978 colourMenu.add(nucleotideMenuItem);
979 colourMenu.add(userDefinedColour);
980 colourMenu.addSeparator();
981 colourMenu.add(conservationMenuItem);
982 colourMenu.add(modifyConservation);
983 colourMenu.add(abovePIDColour);
984 colourMenu.add(modifyPID);
986 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
987 noColourmenuItem.addActionListener(this);
989 clustalColour.setLabel(MessageManager
990 .getString("label.clustalx_colours"));
991 clustalColour.addActionListener(this);
992 zappoColour.setLabel(MessageManager.getString("label.zappo"));
993 zappoColour.addActionListener(this);
994 taylorColour.setLabel(MessageManager.getString("label.taylor"));
995 taylorColour.addActionListener(this);
996 hydrophobicityColour.setLabel(MessageManager
997 .getString("label.hydrophobicity"));
998 hydrophobicityColour.addActionListener(this);
1000 .setLabel(MessageManager.getString("label.helix_propensity"));
1001 helixColour.addActionListener(this);
1002 strandColour.setLabel(MessageManager
1003 .getString("label.strand_propensity"));
1004 strandColour.addActionListener(this);
1005 turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
1006 turnColour.addActionListener(this);
1007 buriedColour.setLabel(MessageManager.getString("label.buried_index"));
1008 buriedColour.addActionListener(this);
1009 abovePIDColour.setLabel(MessageManager
1010 .getString("label.above_identity_percentage"));
1012 userDefinedColour.setLabel(MessageManager
1013 .getString("action.user_defined"));
1014 userDefinedColour.addActionListener(this);
1015 PIDColour.setLabel(MessageManager
1016 .getString("label.percentage_identity"));
1017 PIDColour.addActionListener(this);
1018 BLOSUM62Colour.setLabel("BLOSUM62");
1019 BLOSUM62Colour.addActionListener(this);
1020 conservationMenuItem.setLabel(MessageManager
1021 .getString("action.by_conservation"));
1024 copy.addActionListener(this);
1026 cut.addActionListener(this);
1028 editMenu.add(editSequence);
1029 editSequence.addActionListener(this);
1031 editMenu.add(toUpper);
1032 toUpper.addActionListener(this);
1033 editMenu.add(toLower);
1034 toLower.addActionListener(this);
1035 editMenu.add(toggleCase);
1036 seqMenu.add(seqShowAnnotationsMenu);
1037 seqMenu.add(seqHideAnnotationsMenu);
1038 seqMenu.add(seqAddReferenceAnnotations);
1039 seqMenu.add(sequenceName);
1040 seqMenu.add(makeReferenceSeq);
1041 // seqMenu.add(sequenceDetails);
1043 if (!ap.av.applet.useXtrnalSviewer)
1047 seqMenu.add(repGroup);
1048 menu1.add(editGroupName);
1049 menu1.add(colourMenu);
1050 menu1.add(showBoxes);
1051 menu1.add(showText);
1052 menu1.add(showColourText);
1053 menu1.add(displayNonconserved);
1054 toggleCase.addActionListener(this);
1055 pdb.addActionListener(this);
1056 hideSeqs.addActionListener(this);
1057 repGroup.addActionListener(this);
1058 revealAll.addActionListener(this);
1059 revealSeq.addActionListener(this);
1060 makeReferenceSeq.addActionListener(this);
1065 ap.paintAlignment(true);
1068 protected void clustalColour_actionPerformed()
1070 SequenceGroup sg = getGroup();
1071 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1075 protected void zappoColour_actionPerformed()
1077 getGroup().cs = new ZappoColourScheme();
1081 protected void taylorColour_actionPerformed()
1083 getGroup().cs = new TaylorColourScheme();
1087 protected void hydrophobicityColour_actionPerformed()
1089 getGroup().cs = new HydrophobicColourScheme();
1093 protected void helixColour_actionPerformed()
1095 getGroup().cs = new HelixColourScheme();
1099 protected void strandColour_actionPerformed()
1101 getGroup().cs = new StrandColourScheme();
1105 protected void turnColour_actionPerformed()
1107 getGroup().cs = new TurnColourScheme();
1111 protected void buriedColour_actionPerformed()
1113 getGroup().cs = new BuriedColourScheme();
1117 public void nucleotideMenuItem_actionPerformed()
1119 getGroup().cs = new NucleotideColourScheme();
1123 protected void abovePIDColour_itemStateChanged()
1125 SequenceGroup sg = getGroup();
1131 if (abovePIDColour.getState())
1133 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1134 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1135 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1138 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1140 SliderPanel.showPIDSlider();
1144 // remove PIDColouring
1146 SliderPanel.hidePIDSlider();
1147 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1149 modifyPID.setEnabled(abovePIDColour.getState());
1153 protected void userDefinedColour_actionPerformed()
1155 new UserDefinedColours(ap, getGroup());
1158 protected void PIDColour_actionPerformed()
1160 SequenceGroup sg = getGroup();
1161 sg.cs = new PIDColourScheme();
1162 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1163 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1167 protected void BLOSUM62Colour_actionPerformed()
1169 SequenceGroup sg = getGroup();
1171 sg.cs = new Blosum62ColourScheme();
1173 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1174 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1179 protected void noColourmenuItem_actionPerformed()
1181 getGroup().cs = null;
1185 protected void conservationMenuItem_itemStateChanged()
1187 SequenceGroup sg = getGroup();
1193 if (conservationMenuItem.getState())
1195 sg.cs.setConservation(Conservation.calculateConservation("Group", sg
1196 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1197 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1199 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1200 SliderPanel.showConservationSlider();
1203 // remove ConservationColouring
1205 SliderPanel.hideConservationSlider();
1206 sg.cs.setConservation(null);
1208 modifyConservation.setEnabled(conservationMenuItem.getState());
1212 SequenceGroup getGroup()
1214 SequenceGroup sg = ap.av.getSelectionGroup();
1216 // this method won't add a new group if it already exists
1219 ap.av.getAlignment().addGroup(sg);
1225 void unGroupMenuItem_actionPerformed()
1227 SequenceGroup sg = ap.av.getSelectionGroup();
1228 ap.av.getAlignment().deleteGroup(sg);
1229 ap.av.setSelectionGroup(null);
1230 ap.paintAlignment(true);
1233 void createGroupMenuItem_actionPerformed()
1235 getGroup(); // implicitly create group
1239 public void showColourText_itemStateChanged()
1241 getGroup().setColourText(showColourText.getState());
1245 public void showText_itemStateChanged()
1247 getGroup().setDisplayText(showText.getState());
1251 public void makeReferenceSeq_actionPerformed()
1253 if (!ap.av.getAlignment().hasSeqrep())
1255 // initialise the display flags so the user sees something happen
1256 ap.av.setDisplayReferenceSeq(true);
1257 ap.av.setColourByReferenceSeq(true);
1258 ap.av.getAlignment().setSeqrep(seq);
1262 if (ap.av.getAlignment().getSeqrep() == seq)
1264 ap.av.getAlignment().setSeqrep(null);
1268 ap.av.getAlignment().setSeqrep(seq);
1274 public void showNonconserved_itemStateChanged()
1276 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1280 public void showBoxes_itemStateChanged()
1282 getGroup().setDisplayBoxes(showBoxes.getState());
1286 void hideSequences(boolean representGroup)
1288 ap.av.hideSequences(seq, representGroup);
1292 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1293 * "All" is added first, followed by a separator. Then add any annotation
1294 * types associated with the current selection. Separate menus are built for
1295 * the selected sequence group (if any), and the selected sequence.
1297 * Some annotation rows are always rendered together - these can be identified
1298 * by a common graphGroup property > -1. Only one of each group will be marked
1299 * as visible (to avoid duplication of the display). For such groups we add a
1300 * composite type name, e.g.
1302 * IUPredWS (Long), IUPredWS (Short)
1306 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1307 List<SequenceI> forSequences)
1309 showMenu.removeAll();
1310 hideMenu.removeAll();
1312 final List<String> all = Arrays.asList(new String[] { MessageManager
1313 .getString("label.all") });
1314 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1315 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1317 showMenu.addSeparator();
1318 hideMenu.addSeparator();
1320 final AlignmentAnnotation[] annotations = ap.getAlignment()
1321 .getAlignmentAnnotation();
1324 * Find shown/hidden annotations types, distinguished by source (calcId),
1325 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1326 * the insertion order, which is the order of the annotations on the
1329 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1330 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1331 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1332 AlignmentAnnotationUtils.asList(annotations), forSequences);
1334 for (String calcId : hiddenTypes.keySet())
1336 for (List<String> type : hiddenTypes.get(calcId))
1338 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1342 // grey out 'show annotations' if none are hidden
1343 showMenu.setEnabled(!hiddenTypes.isEmpty());
1345 for (String calcId : shownTypes.keySet())
1347 for (List<String> type : shownTypes.get(calcId))
1349 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1353 // grey out 'hide annotations' if none are shown
1354 hideMenu.setEnabled(!shownTypes.isEmpty());
1358 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1361 * @param showOrHideMenu
1362 * the menu to add to
1363 * @param forSequences
1364 * the sequences whose annotations may be shown or hidden
1369 * if true this is a special label meaning 'All'
1370 * @param actionIsShow
1371 * if true, the select menu item action is to show the annotation
1374 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1375 final List<SequenceI> forSequences, String calcId,
1376 final List<String> types, final boolean allTypes,
1377 final boolean actionIsShow)
1379 String label = types.toString(); // [a, b, c]
1380 label = label.substring(1, label.length() - 1);
1381 final MenuItem item = new MenuItem(label);
1382 item.addActionListener(new java.awt.event.ActionListener()
1385 public void actionPerformed(ActionEvent e)
1387 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1388 types, forSequences, allTypes, actionIsShow);
1392 showOrHideMenu.add(item);