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.renderer.ResidueShader;
43 import jalview.renderer.ResidueShaderI;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.BuriedColourScheme;
46 import jalview.schemes.ClustalxColourScheme;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.HydrophobicColourScheme;
49 import jalview.schemes.JalviewColourScheme;
50 import jalview.schemes.NucleotideColourScheme;
51 import jalview.schemes.PIDColourScheme;
52 import jalview.schemes.PurinePyrimidineColourScheme;
53 import jalview.schemes.StrandColourScheme;
54 import jalview.schemes.TaylorColourScheme;
55 import jalview.schemes.TurnColourScheme;
56 import jalview.schemes.ZappoColourScheme;
57 import jalview.util.MessageManager;
58 import jalview.util.UrlLink;
60 import java.awt.CheckboxMenuItem;
61 import java.awt.Frame;
63 import java.awt.MenuItem;
64 import java.awt.event.ActionEvent;
65 import java.awt.event.ActionListener;
66 import java.awt.event.ItemEvent;
67 import java.awt.event.ItemListener;
68 import java.util.ArrayList;
69 import java.util.Arrays;
70 import java.util.Collection;
71 import java.util.Collections;
72 import java.util.LinkedHashMap;
73 import java.util.List;
75 import java.util.SortedMap;
76 import java.util.TreeMap;
77 import java.util.Vector;
79 public class APopupMenu extends java.awt.PopupMenu implements
80 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(MessageManager.formatMessage(
266 "label.name_param", new Object[] { sg.getName() }));
267 showText.setState(sg.getDisplayText());
268 showColourText.setState(sg.getColourText());
269 showBoxes.setState(sg.getDisplayBoxes());
270 displayNonconserved.setState(sg.getShowNonconserved());
271 if (!ap.av.getAlignment().getGroups().contains(sg))
273 menu1.setLabel(MessageManager.getString("action.edit_new_group"));
274 groupMenu.remove(unGroupMenuItem);
278 menu1.setLabel(MessageManager.getString("action.edit_group"));
279 groupMenu.remove(createGroupMenuItem);
282 abovePIDColour.setState(sg.cs.getThreshold() > 0);
283 conservationColour.setState(sg.cs.conservationApplied());
284 modifyPID.setEnabled(abovePIDColour.getState());
285 modifyConservation.setEnabled(conservationColour.getState());
288 setSelectedColour(sg.cs);
296 if (links != null && links.size() > 0)
298 addFeatureLinks(seq, links);
301 // TODO: add group link menu entry here
304 seqMenu.setLabel(seq.getName());
305 if (seq == ap.av.getAlignment().getSeqrep())
307 makeReferenceSeq.setLabel(MessageManager
308 .getString("action.unmark_as_reference"));// Unmark
313 makeReferenceSeq.setLabel(MessageManager
314 .getString("action.set_as_reference")); // );
316 repGroup.setLabel(MessageManager.formatMessage(
317 "label.represent_group_with", new Object[] { seq.getName() }));
324 if (!ap.av.hasHiddenRows())
331 final int index = ap.av.getAlignment().findIndex(seq);
333 if (ap.av.adjustForHiddenSeqs(index)
334 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
336 revealSeq_index = index;
346 * Select the menu item (if any) matching the current colour scheme. This
347 * works by matching the menu item name (not display text) to the canonical
348 * name of the colour scheme.
352 protected void setSelectedColour(ResidueShaderI cs)
354 if (cs == null || cs.getColourScheme() == null)
356 noColour.setState(true);
360 String name = cs.getColourScheme().getSchemeName();
361 for (int i = 0; i < colourMenu.getItemCount(); i++)
363 MenuItem item = colourMenu.getItem(i);
364 if (item instanceof CheckboxMenuItem)
366 if (name.equals(item.getName()))
368 ((CheckboxMenuItem) item).setState(true);
376 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
381 void addFeatureLinks(final SequenceI seq, List<String> links)
383 Menu linkMenu = new Menu(MessageManager.getString("action.link"));
384 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
386 for (String link : links)
388 UrlLink urlLink = null;
391 urlLink = new UrlLink(link);
392 } catch (Exception foo)
394 System.err.println("Exception for URLLink '" + link + "': "
399 if (!urlLink.isValid())
401 System.err.println(urlLink.getInvalidMessage());
405 urlLink.createLinksFromSeq(seq, linkset);
408 addshowLinks(linkMenu, linkset.values());
410 // disable link menu if there are no valid entries
411 if (linkMenu.getItemCount() > 0)
413 linkMenu.setEnabled(true);
417 linkMenu.setEnabled(false);
422 seqMenu.add(linkMenu);
431 private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
433 for (List<String> linkstrset : linkset)
435 // split linkstr into label and url
436 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
441 * Build menus for annotation types that may be shown or hidden, and for
442 * 'reference annotations' that may be added to the alignment.
444 private void buildAnnotationSubmenus()
447 * First for the currently selected sequence (if there is one):
449 final List<SequenceI> selectedSequence = (seq == null ? Collections
450 .<SequenceI> emptyList() : Arrays.asList(seq));
451 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
452 seqHideAnnotationsMenu, selectedSequence);
453 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
457 * and repeat for the current selection group (if there is one):
459 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
460 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
462 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
463 groupHideAnnotationsMenu, selectedGroup);
464 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
469 * Determine whether or not to enable 'add reference annotations' menu item.
470 * It is enable if there are any annotations, on any of the selected
471 * sequences, which are not yet on the alignment (visible or not).
474 * @param forSequences
476 private void configureReferenceAnnotationsMenu(MenuItem menuItem,
477 List<SequenceI> forSequences)
479 menuItem.setEnabled(false);
482 * Temporary store to hold distinct calcId / type pairs for the tooltip.
483 * Using TreeMap means calcIds are shown in alphabetical order.
485 SortedMap<String, String> tipEntries = new TreeMap<String, String>();
486 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
487 AlignmentI al = this.ap.av.getAlignment();
488 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
489 tipEntries, candidates, al);
490 if (!candidates.isEmpty())
492 StringBuilder tooltip = new StringBuilder(64);
493 tooltip.append(MessageManager.getString("label.add_annotations_for"));
496 * Found annotations that could be added. Enable the menu item, and
497 * configure its action.
499 menuItem.setEnabled(true);
501 menuItem.addActionListener(new ActionListener()
504 public void actionPerformed(ActionEvent e)
506 addReferenceAnnotations_actionPerformed(candidates);
513 * Add annotations to the sequences and to the alignment.
516 * a map whose keys are sequences on the alignment, and values a list
517 * of annotations to add to each sequence
519 protected void addReferenceAnnotations_actionPerformed(
520 Map<SequenceI, List<AlignmentAnnotation>> candidates)
522 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
523 final AlignmentI alignment = this.ap.getAlignment();
524 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
530 * add a show URL menu item to the given linkMenu
534 * - menu label string
538 private void addshowLink(Menu linkMenu, final String target,
541 addshowLink(linkMenu, target, target, url);
545 * add a show URL menu item to the given linkMenu
549 * - URL target window
551 * - menu label string
555 private void addshowLink(Menu linkMenu, final String target,
556 final String label, final String url)
558 MenuItem item = new MenuItem(label);
559 item.addActionListener(new java.awt.event.ActionListener()
562 public void actionPerformed(ActionEvent e)
564 ap.alignFrame.showURL(url, target);
571 * Actions on selecting / unselecting a checkbox menu item
574 public void itemStateChanged(ItemEvent evt)
576 Object source = evt.getSource();
577 if (source == noColour)
579 noColourmenuItem_actionPerformed();
581 else if (source == clustalColour)
583 clustalColour_actionPerformed();
585 else if (source == BLOSUM62Colour)
587 BLOSUM62Colour_actionPerformed();
589 else if (evt.getSource() == PIDColour)
591 PIDColour_actionPerformed();
593 else if (source == zappoColour)
595 zappoColour_actionPerformed();
597 else if (source == taylorColour)
599 taylorColour_actionPerformed();
601 else if (source == hydrophobicityColour)
603 hydrophobicityColour_actionPerformed();
605 else if (source == helixColour)
607 helixColour_actionPerformed();
609 else if (source == strandColour)
611 strandColour_actionPerformed();
613 else if (source == turnColour)
615 turnColour_actionPerformed();
617 else if (source == buriedColour)
619 buriedColour_actionPerformed();
621 else if (source == nucleotideColour)
623 nucleotideMenuItem_actionPerformed();
625 else if (source == purinePyrimidineColour)
627 purinePyrimidineColour_actionPerformed();
629 else if (source == abovePIDColour)
631 abovePIDColour_itemStateChanged();
633 else if (source == conservationColour)
635 conservationMenuItem_itemStateChanged();
637 else if (source == showColourText)
639 showColourText_itemStateChanged();
641 else if (source == showText)
643 showText_itemStateChanged();
645 else if (source == showBoxes)
647 showBoxes_itemStateChanged();
649 else if (source == displayNonconserved)
651 this.showNonconserved_itemStateChanged();
656 * Actions on clicking a menu item
659 public void actionPerformed(ActionEvent evt)
661 Object source = evt.getSource();
662 if (source == userDefinedColour)
664 userDefinedColour_actionPerformed();
666 else if (source == modifyConservation)
668 conservationMenuItem_itemStateChanged();
670 else if (source == modifyPID)
672 abovePIDColour_itemStateChanged();
674 else if (source == unGroupMenuItem)
676 unGroupMenuItem_actionPerformed();
679 else if (source == createGroupMenuItem)
681 createGroupMenuItem_actionPerformed();
684 else if (source == sequenceName)
688 else if (source == makeReferenceSeq)
690 makeReferenceSeq_actionPerformed();
692 else if (source == sequenceDetails)
694 showSequenceDetails();
696 else if (source == selSeqDetails)
698 showSequenceSelectionDetails();
700 else if (source == pdb)
704 else if (source == hideSeqs)
706 hideSequences(false);
708 else if (source == repGroup)
712 else if (source == revealSeq)
714 ap.av.showSequence(revealSeq_index);
716 else if (source == revealAll)
718 ap.av.showAllHiddenSeqs();
721 else if (source == editGroupName)
723 EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
724 getGroup().getDescription(), " Group Name",
725 "Group Description", ap.alignFrame,
726 "Edit Group Name / Description", 500, 100, true);
730 getGroup().setName(dialog.getName().replace(' ', '_'));
731 getGroup().setDescription(dialog.getDescription());
735 else if (source == copy)
737 ap.alignFrame.copy_actionPerformed();
739 else if (source == cut)
741 ap.alignFrame.cut_actionPerformed();
743 else if (source == editSequence)
745 SequenceGroup sg = ap.av.getSelectionGroup();
751 seq = sg.getSequenceAt(0);
754 EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
755 sg.getStartRes(), sg.getEndRes() + 1), null,
756 "Edit Sequence ", null,
758 ap.alignFrame, "Edit Sequence", 500, 100, true);
762 EditCommand editCommand = new EditCommand(
763 MessageManager.getString("label.edit_sequences"),
764 Action.REPLACE, dialog.getName().replace(' ',
765 ap.av.getGapCharacter()),
766 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
767 sg.getStartRes(), sg.getEndRes() + 1,
768 ap.av.getAlignment());
770 ap.alignFrame.addHistoryItem(editCommand);
772 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
777 else if (source == toUpper || source == toLower || source == toggleCase)
779 SequenceGroup sg = ap.av.getSelectionGroup();
782 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
783 sg.getStartRes(), sg.getEndRes() + 1);
788 if (source == toggleCase)
790 description = "Toggle Case";
791 caseChange = ChangeCaseCommand.TOGGLE_CASE;
793 else if (source == toUpper)
795 description = "To Upper Case";
796 caseChange = ChangeCaseCommand.TO_UPPER;
800 description = "To Lower Case";
801 caseChange = ChangeCaseCommand.TO_LOWER;
804 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
805 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
806 startEnd, caseChange);
808 ap.alignFrame.addHistoryItem(caseCommand);
810 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
815 else if (source == sequenceFeature)
817 SequenceGroup sg = ap.av.getSelectionGroup();
823 int gSize = sg.getSize();
824 List<SequenceI> seqs = new ArrayList<SequenceI>();
825 List<SequenceFeature> features = new ArrayList<SequenceFeature>();
827 for (int i = 0; i < gSize; i++)
829 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
830 int end = sg.findEndRes(sg.getSequenceAt(i));
833 seqs.add(sg.getSequenceAt(i));
834 features.add(new SequenceFeature(null, null, start, end,
841 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
844 ap.alignFrame.sequenceFeatures.setState(true);
845 ap.av.setShowSequenceFeatures(true);
846 ap.av.setSearchResults(null); // clear highlighting
847 ap.repaint(); // draw new/amended features
858 void outputText(ActionEvent e)
860 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
862 Frame frame = new Frame();
864 JalviewLite.addFrame(frame, MessageManager.formatMessage(
865 "label.selection_output_command",
866 new Object[] { e.getActionCommand() }), 600, 500);
867 // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
868 // now returns a full copy of sequence data
869 // TODO consider using getSequenceSelection instead here
871 FileFormatI fileFormat = FileFormats.getInstance().forName(
872 e.getActionCommand());
873 cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
874 ap.av.getShowJVSuffix(), ap, true));
878 protected void showSequenceSelectionDetails()
880 createSequenceDetailsReport(ap.av.getSequenceSelection());
883 protected void showSequenceDetails()
885 createSequenceDetailsReport(new SequenceI[] { seq });
888 public void createSequenceDetailsReport(SequenceI[] sequences)
891 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
893 StringBuilder contents = new StringBuilder(128);
894 for (SequenceI seq : sequences)
896 contents.append(MessageManager.formatMessage(
897 "label.annotation_for_displayid",
898 new Object[] { seq.getDisplayId(true) }));
899 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
904 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
905 .getMinMax() : null);
906 contents.append("</p>");
908 Frame frame = new Frame();
910 jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
911 + (sequences.length == 1 ? sequences[0].getDisplayId(true)
912 : "Selection"), 600, 500);
913 cap.setText(MessageManager.formatMessage("label.html_content",
914 new Object[] { contents.toString() }));
919 EditNameDialog dialog = new EditNameDialog(seq.getName(),
920 seq.getDescription(), " Sequence Name",
921 "Sequence Description", ap.alignFrame,
922 "Edit Sequence Name / Description", 500, 100, true);
926 seq.setName(dialog.getName());
927 seq.setDescription(dialog.getDescription());
928 ap.paintAlignment(false);
934 Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
935 if (pdbs != null && !pdbs.isEmpty())
937 PDBEntry entry = pdbs.firstElement();
939 if (ap.av.applet.jmolAvailable)
941 new AppletJmol(entry, new SequenceI[] { seq }, null, ap,
946 new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
947 ap, DataSourceType.URL);
953 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
954 cap.setText(MessageManager.getString("label.paste_pdb_file"));
955 cap.setPDBImport(seq);
956 Frame frame = new Frame();
958 JalviewLite.addFrame(frame, MessageManager.formatMessage(
959 "label.paste_pdb_file_for_sequence",
960 new Object[] { seq.getName() }), 400, 300);
964 private void jbInit() throws Exception
966 groupMenu.setLabel(MessageManager.getString("label.selection"));
967 sequenceFeature.addActionListener(this);
969 editGroupName.addActionListener(this);
970 unGroupMenuItem.setLabel(MessageManager
971 .getString("action.remove_group"));
972 unGroupMenuItem.addActionListener(this);
974 createGroupMenuItem.setLabel(MessageManager
975 .getString("action.create_group"));
976 createGroupMenuItem.addActionListener(this);
978 modifyPID.setEnabled(abovePIDColour.getState());
979 modifyConservation.setEnabled(conservationColour.getState());
980 colourMenu.setLabel(MessageManager.getString("label.group_colour"));
981 showBoxes.setLabel(MessageManager.getString("action.boxes"));
982 showBoxes.setState(true);
983 showBoxes.addItemListener(this);
984 sequenceName.addActionListener(this);
985 sequenceDetails.addActionListener(this);
986 selSeqDetails.addActionListener(this);
987 displayNonconserved.setLabel(MessageManager
988 .getString("label.show_non_conserved"));
989 displayNonconserved.setState(false);
990 displayNonconserved.addItemListener(this);
991 showText.setLabel(MessageManager.getString("action.text"));
992 showText.addItemListener(this);
993 showColourText.setLabel(MessageManager.getString("label.colour_text"));
994 showColourText.addItemListener(this);
995 outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
996 seqMenu.setLabel(MessageManager.getString("label.sequence"));
997 pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
998 hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
999 repGroup.setLabel(MessageManager.formatMessage(
1000 "label.represent_group_with", new Object[] { "" }));
1001 revealAll.setLabel(MessageManager.getString("action.reveal_all"));
1002 revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
1003 menu1.setLabel(MessageManager.getString("label.group:"));
1007 this.add(revealSeq);
1008 this.add(revealAll);
1009 // groupMenu.add(selSeqDetails);
1010 groupMenu.add(groupShowAnnotationsMenu);
1011 groupMenu.add(groupHideAnnotationsMenu);
1012 groupMenu.add(groupAddReferenceAnnotations);
1013 groupMenu.add(editMenu);
1014 groupMenu.add(outputmenu);
1015 groupMenu.add(sequenceFeature);
1016 groupMenu.add(createGroupMenuItem);
1017 groupMenu.add(unGroupMenuItem);
1018 groupMenu.add(menu1);
1020 colourMenu.add(noColour);
1021 colourMenu.add(clustalColour);
1022 colourMenu.add(BLOSUM62Colour);
1023 colourMenu.add(PIDColour);
1024 colourMenu.add(zappoColour);
1025 colourMenu.add(taylorColour);
1026 colourMenu.add(hydrophobicityColour);
1027 colourMenu.add(helixColour);
1028 colourMenu.add(strandColour);
1029 colourMenu.add(turnColour);
1030 colourMenu.add(buriedColour);
1031 colourMenu.add(nucleotideColour);
1032 colourMenu.add(purinePyrimidineColour);
1033 colourMenu.add(userDefinedColour);
1034 colourMenu.addSeparator();
1035 colourMenu.add(conservationColour);
1036 colourMenu.add(modifyConservation);
1037 colourMenu.add(abovePIDColour);
1038 colourMenu.add(modifyPID);
1040 noColour.setLabel(MessageManager.getString("label.none"));
1041 noColour.addItemListener(this);
1044 * setName allows setSelectedColour to do its thing
1046 clustalColour.setLabel(MessageManager
1047 .getString("label.colourScheme_clustal"));
1048 clustalColour.setName(JalviewColourScheme.Clustal.toString());
1049 clustalColour.addItemListener(this);
1050 BLOSUM62Colour.setLabel(MessageManager
1051 .getString("label.colourScheme_blosum62"));
1052 BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1053 BLOSUM62Colour.addItemListener(this);
1054 PIDColour.setLabel(MessageManager
1055 .getString("label.colourScheme_%_identity"));
1056 PIDColour.setName(JalviewColourScheme.PID.toString());
1057 PIDColour.addItemListener(this);
1058 zappoColour.setLabel(MessageManager
1059 .getString("label.colourScheme_zappo"));
1060 zappoColour.setName(JalviewColourScheme.Zappo.toString());
1061 zappoColour.addItemListener(this);
1062 taylorColour.setLabel(MessageManager
1063 .getString("label.colourScheme_taylor"));
1064 taylorColour.setName(JalviewColourScheme.Taylor.toString());
1065 taylorColour.addItemListener(this);
1066 hydrophobicityColour.setLabel(MessageManager
1067 .getString("label.colourScheme_hydrophobic"));
1068 hydrophobicityColour
1069 .setName(JalviewColourScheme.Hydrophobic.toString());
1070 hydrophobicityColour.addItemListener(this);
1071 helixColour.setLabel(MessageManager
1072 .getString("label.colourScheme_helix_propensity"));
1073 helixColour.setName(JalviewColourScheme.Helix.toString());
1074 helixColour.addItemListener(this);
1075 strandColour.setLabel(MessageManager
1076 .getString("label.colourScheme_strand_propensity"));
1077 strandColour.setName(JalviewColourScheme.Strand.toString());
1078 strandColour.addItemListener(this);
1079 turnColour.setLabel(MessageManager
1080 .getString("label.colourScheme_turn_propensity"));
1081 turnColour.setName(JalviewColourScheme.Turn.toString());
1082 turnColour.addItemListener(this);
1083 buriedColour.setLabel(MessageManager
1084 .getString("label.colourScheme_buried_index"));
1085 buriedColour.setName(JalviewColourScheme.Buried.toString());
1086 buriedColour.addItemListener(this);
1087 nucleotideColour.setLabel(MessageManager
1088 .getString("label.colourScheme_nucleotide"));
1089 nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1090 nucleotideColour.addItemListener(this);
1091 purinePyrimidineColour.setLabel(MessageManager
1092 .getString("label.colourScheme_purine/pyrimidine"));
1093 purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
1095 purinePyrimidineColour.addItemListener(this);
1097 userDefinedColour.setLabel(MessageManager
1098 .getString("action.user_defined"));
1099 userDefinedColour.addActionListener(this);
1101 abovePIDColour.setLabel(MessageManager
1102 .getString("label.above_identity_threshold"));
1103 abovePIDColour.addItemListener(this);
1104 modifyPID.setLabel(MessageManager
1105 .getString("label.modify_identity_threshold"));
1106 modifyPID.addActionListener(this);
1107 conservationColour.setLabel(MessageManager
1108 .getString("action.by_conservation"));
1109 conservationColour.addItemListener(this);
1110 modifyConservation.setLabel(MessageManager
1111 .getString("label.modify_conservation_threshold"));
1112 modifyConservation.addActionListener(this);
1114 PIDColour.addActionListener(this);
1115 BLOSUM62Colour.addActionListener(this);
1118 copy.addActionListener(this);
1120 cut.addActionListener(this);
1122 editMenu.add(editSequence);
1123 editSequence.addActionListener(this);
1125 editMenu.add(toUpper);
1126 toUpper.addActionListener(this);
1127 editMenu.add(toLower);
1128 toLower.addActionListener(this);
1129 editMenu.add(toggleCase);
1130 seqMenu.add(seqShowAnnotationsMenu);
1131 seqMenu.add(seqHideAnnotationsMenu);
1132 seqMenu.add(seqAddReferenceAnnotations);
1133 seqMenu.add(sequenceName);
1134 seqMenu.add(makeReferenceSeq);
1135 // seqMenu.add(sequenceDetails);
1137 if (!ap.av.applet.useXtrnalSviewer)
1141 seqMenu.add(repGroup);
1142 menu1.add(editGroupName);
1143 menu1.add(colourMenu);
1144 menu1.add(showBoxes);
1145 menu1.add(showText);
1146 menu1.add(showColourText);
1147 menu1.add(displayNonconserved);
1148 toggleCase.addActionListener(this);
1149 pdb.addActionListener(this);
1150 hideSeqs.addActionListener(this);
1151 repGroup.addActionListener(this);
1152 revealAll.addActionListener(this);
1153 revealSeq.addActionListener(this);
1154 makeReferenceSeq.addActionListener(this);
1159 ap.paintAlignment(true);
1162 protected void clustalColour_actionPerformed()
1164 SequenceGroup sg = getGroup();
1165 sg.cs = new ResidueShader(new ClustalxColourScheme(sg,
1166 ap.av.getHiddenRepSequences()));
1170 protected void zappoColour_actionPerformed()
1172 getGroup().cs = new ResidueShader(new ZappoColourScheme());
1176 protected void taylorColour_actionPerformed()
1178 getGroup().cs = new ResidueShader(new TaylorColourScheme());
1182 protected void hydrophobicityColour_actionPerformed()
1184 getGroup().cs = new ResidueShader(new HydrophobicColourScheme());
1188 protected void helixColour_actionPerformed()
1190 getGroup().cs = new ResidueShader(new HelixColourScheme());
1194 protected void strandColour_actionPerformed()
1196 getGroup().cs = new ResidueShader(new StrandColourScheme());
1200 protected void turnColour_actionPerformed()
1202 getGroup().cs = new ResidueShader(new TurnColourScheme());
1206 protected void buriedColour_actionPerformed()
1208 getGroup().cs = new ResidueShader(new BuriedColourScheme());
1212 public void nucleotideMenuItem_actionPerformed()
1214 getGroup().cs = new ResidueShader(new NucleotideColourScheme());
1218 public void purinePyrimidineColour_actionPerformed()
1220 getGroup().cs = new ResidueShader(
1221 new PurinePyrimidineColourScheme());
1225 protected void abovePIDColour_itemStateChanged()
1227 SequenceGroup sg = getGroup();
1233 if (abovePIDColour.getState())
1235 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1236 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1237 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1240 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1242 SliderPanel.showPIDSlider();
1246 // remove PIDColouring
1248 SliderPanel.hidePIDSlider();
1249 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1251 modifyPID.setEnabled(abovePIDColour.getState());
1255 protected void userDefinedColour_actionPerformed()
1257 new UserDefinedColours(ap, getGroup());
1260 protected void PIDColour_actionPerformed()
1262 SequenceGroup sg = getGroup();
1263 sg.cs = new ResidueShader(new PIDColourScheme());
1264 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1265 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1269 protected void BLOSUM62Colour_actionPerformed()
1271 SequenceGroup sg = getGroup();
1273 sg.cs = new ResidueShader(new Blosum62ColourScheme());
1275 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1276 .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1281 protected void noColourmenuItem_actionPerformed()
1283 getGroup().cs = null;
1287 protected void conservationMenuItem_itemStateChanged()
1289 SequenceGroup sg = getGroup();
1295 if (conservationColour.getState())
1297 Conservation conservation = Conservation.calculateConservation(
1299 .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1300 .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1302 sg.getGroupColourScheme().setConservation(conservation);
1303 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1304 SliderPanel.showConservationSlider();
1307 // remove ConservationColouring
1309 SliderPanel.hideConservationSlider();
1310 sg.cs.setConservation(null);
1312 modifyConservation.setEnabled(conservationColour.getState());
1316 SequenceGroup getGroup()
1318 SequenceGroup sg = ap.av.getSelectionGroup();
1320 // this method won't add a new group if it already exists
1323 ap.av.getAlignment().addGroup(sg);
1329 void unGroupMenuItem_actionPerformed()
1331 SequenceGroup sg = ap.av.getSelectionGroup();
1332 ap.av.getAlignment().deleteGroup(sg);
1333 ap.av.setSelectionGroup(null);
1334 ap.paintAlignment(true);
1337 void createGroupMenuItem_actionPerformed()
1339 getGroup(); // implicitly create group
1343 public void showColourText_itemStateChanged()
1345 getGroup().setColourText(showColourText.getState());
1349 public void showText_itemStateChanged()
1351 getGroup().setDisplayText(showText.getState());
1355 public void makeReferenceSeq_actionPerformed()
1357 if (!ap.av.getAlignment().hasSeqrep())
1359 // initialise the display flags so the user sees something happen
1360 ap.av.setDisplayReferenceSeq(true);
1361 ap.av.setColourByReferenceSeq(true);
1362 ap.av.getAlignment().setSeqrep(seq);
1366 if (ap.av.getAlignment().getSeqrep() == seq)
1368 ap.av.getAlignment().setSeqrep(null);
1372 ap.av.getAlignment().setSeqrep(seq);
1378 public void showNonconserved_itemStateChanged()
1380 getGroup().setShowNonconserved(this.displayNonconserved.getState());
1384 public void showBoxes_itemStateChanged()
1386 getGroup().setDisplayBoxes(showBoxes.getState());
1390 void hideSequences(boolean representGroup)
1392 ap.av.hideSequences(seq, representGroup);
1396 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1397 * "All" is added first, followed by a separator. Then add any annotation
1398 * types associated with the current selection. Separate menus are built for
1399 * the selected sequence group (if any), and the selected sequence.
1401 * Some annotation rows are always rendered together - these can be identified
1402 * by a common graphGroup property > -1. Only one of each group will be marked
1403 * as visible (to avoid duplication of the display). For such groups we add a
1404 * composite type name, e.g.
1406 * IUPredWS (Long), IUPredWS (Short)
1410 protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1411 List<SequenceI> forSequences)
1413 showMenu.removeAll();
1414 hideMenu.removeAll();
1416 final List<String> all = Arrays.asList(new String[] { MessageManager
1417 .getString("label.all") });
1418 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1419 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1421 showMenu.addSeparator();
1422 hideMenu.addSeparator();
1424 final AlignmentAnnotation[] annotations = ap.getAlignment()
1425 .getAlignmentAnnotation();
1428 * Find shown/hidden annotations types, distinguished by source (calcId),
1429 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1430 * the insertion order, which is the order of the annotations on the
1433 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1434 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1435 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1436 AlignmentAnnotationUtils.asList(annotations), forSequences);
1438 for (String calcId : hiddenTypes.keySet())
1440 for (List<String> type : hiddenTypes.get(calcId))
1442 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1446 // grey out 'show annotations' if none are hidden
1447 showMenu.setEnabled(!hiddenTypes.isEmpty());
1449 for (String calcId : shownTypes.keySet())
1451 for (List<String> type : shownTypes.get(calcId))
1453 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1457 // grey out 'hide annotations' if none are shown
1458 hideMenu.setEnabled(!shownTypes.isEmpty());
1462 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1465 * @param showOrHideMenu
1466 * the menu to add to
1467 * @param forSequences
1468 * the sequences whose annotations may be shown or hidden
1473 * if true this is a special label meaning 'All'
1474 * @param actionIsShow
1475 * if true, the select menu item action is to show the annotation
1478 protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1479 final List<SequenceI> forSequences, String calcId,
1480 final List<String> types, final boolean allTypes,
1481 final boolean actionIsShow)
1483 String label = types.toString(); // [a, b, c]
1484 label = label.substring(1, label.length() - 1);
1485 final MenuItem item = new MenuItem(label);
1486 item.addActionListener(new java.awt.event.ActionListener()
1489 public void actionPerformed(ActionEvent e)
1491 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1492 types, forSequences, allTypes, actionIsShow);
1496 showOrHideMenu.add(item);