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.
23 import java.awt.Color;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.Hashtable;
29 import java.util.LinkedHashMap;
30 import java.util.List;
32 import java.util.TreeMap;
33 import java.util.Vector;
35 import javax.swing.ButtonGroup;
36 import javax.swing.JCheckBoxMenuItem;
37 import javax.swing.JColorChooser;
38 import javax.swing.JMenu;
39 import javax.swing.JMenuItem;
40 import javax.swing.JOptionPane;
41 import javax.swing.JPopupMenu;
42 import javax.swing.JRadioButtonMenuItem;
44 import jalview.analysis.AAFrequency;
45 import jalview.analysis.AlignmentAnnotationUtils;
46 import jalview.analysis.AlignmentUtils;
47 import jalview.analysis.Conservation;
48 import jalview.commands.ChangeCaseCommand;
49 import jalview.commands.EditCommand;
50 import jalview.commands.EditCommand.Action;
51 import jalview.datamodel.AlignmentAnnotation;
52 import jalview.datamodel.AlignmentI;
53 import jalview.datamodel.Annotation;
54 import jalview.datamodel.ColumnSelection;
55 import jalview.datamodel.DBRefEntry;
56 import jalview.datamodel.PDBEntry;
57 import jalview.datamodel.Sequence;
58 import jalview.datamodel.SequenceFeature;
59 import jalview.datamodel.SequenceGroup;
60 import jalview.datamodel.SequenceI;
61 import jalview.io.FormatAdapter;
62 import jalview.io.SequenceAnnotationReport;
63 import jalview.schemes.AnnotationColourGradient;
64 import jalview.schemes.Blosum62ColourScheme;
65 import jalview.schemes.BuriedColourScheme;
66 import jalview.schemes.ClustalxColourScheme;
67 import jalview.schemes.HelixColourScheme;
68 import jalview.schemes.HydrophobicColourScheme;
69 import jalview.schemes.NucleotideColourScheme;
70 import jalview.schemes.PIDColourScheme;
71 import jalview.schemes.PurinePyrimidineColourScheme;
72 import jalview.schemes.ResidueProperties;
73 import jalview.schemes.StrandColourScheme;
74 import jalview.schemes.TaylorColourScheme;
75 import jalview.schemes.TurnColourScheme;
76 import jalview.schemes.UserColourScheme;
77 import jalview.schemes.ZappoColourScheme;
78 import jalview.util.GroupUrlLink;
79 import jalview.util.GroupUrlLink.UrlStringTooLongException;
80 import jalview.util.MessageManager;
81 import jalview.util.UrlLink;
87 * @version $Revision: 1.118 $
89 public class PopupMenu extends JPopupMenu
91 private static final String ALL_ANNOTATIONS = "All";
93 private static final String COMMA = ",";
95 JMenu groupMenu = new JMenu();
97 JMenuItem groupName = new JMenuItem();
99 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
101 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
103 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
105 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
107 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
109 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
111 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
113 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
115 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
117 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
119 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
121 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
123 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
125 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
127 // protected JRadioButtonMenuItem covariationColour = new
128 // JRadioButtonMenuItem();
130 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
132 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
136 JMenu sequenceMenu = new JMenu();
138 JMenuItem sequenceName = new JMenuItem();
140 JMenuItem sequenceDetails = new JMenuItem();
142 JMenuItem sequenceSelDetails = new JMenuItem();
144 JMenuItem makeReferenceSeq = new JMenuItem();
146 JMenuItem chooseAnnotations = new JMenuItem();
150 JMenuItem createGroupMenuItem = new JMenuItem();
152 JMenuItem unGroupMenuItem = new JMenuItem();
154 JMenuItem outline = new JMenuItem();
156 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
158 JMenu colourMenu = new JMenu();
160 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
162 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
164 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
166 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
168 JMenu editMenu = new JMenu();
170 JMenuItem cut = new JMenuItem();
172 JMenuItem copy = new JMenuItem();
174 JMenuItem upperCase = new JMenuItem();
176 JMenuItem lowerCase = new JMenuItem();
178 JMenuItem toggle = new JMenuItem();
180 JMenu pdbMenu = new JMenu();
182 JMenuItem pdbFromFile = new JMenuItem();
184 // JBPNote: Commented these out - Should add these services via the web
185 // services menu system.
186 // JMenuItem ContraFold = new JMenuItem();
188 // JMenuItem RNAFold = new JMenuItem();
190 JMenuItem enterPDB = new JMenuItem();
192 JMenuItem discoverPDB = new JMenuItem();
194 JMenu outputMenu = new JMenu();
196 JMenu seqShowAnnotationsMenu = new JMenu();
198 JMenu seqHideAnnotationsMenu = new JMenu();
200 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
201 MessageManager.getString("label.add_reference_annotations"));
203 JMenu groupShowAnnotationsMenu = new JMenu();
205 JMenu groupHideAnnotationsMenu = new JMenu();
207 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
208 MessageManager.getString("label.add_reference_annotations"));
210 JMenuItem sequenceFeature = new JMenuItem();
212 JMenuItem textColour = new JMenuItem();
214 JMenu jMenu1 = new JMenu();
216 JMenu structureMenu = new JMenu();
218 JMenu viewStructureMenu = new JMenu();
220 // JMenu colStructureMenu = new JMenu();
221 JMenuItem editSequence = new JMenuItem();
223 // JMenuItem annotationMenuItem = new JMenuItem();
225 JMenu groupLinksMenu;
227 JMenuItem hideInsertions = new JMenuItem();
230 * Creates a new PopupMenu object.
237 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
239 this(ap, seq, links, null);
249 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
250 Vector links, Vector groupLinks)
252 // /////////////////////////////////////////////////////////
253 // If this is activated from the sequence panel, the user may want to
254 // edit or annotate a particular residue. Therefore display the residue menu
256 // If from the IDPanel, we must display the sequence menu
257 // ////////////////////////////////////////////////////////
261 ButtonGroup colours = new ButtonGroup();
262 colours.add(noColourmenuItem);
263 colours.add(clustalColour);
264 colours.add(zappoColour);
265 colours.add(taylorColour);
266 colours.add(hydrophobicityColour);
267 colours.add(helixColour);
268 colours.add(strandColour);
269 colours.add(turnColour);
270 colours.add(buriedColour);
271 colours.add(abovePIDColour);
272 colours.add(userDefinedColour);
273 colours.add(PIDColour);
274 colours.add(BLOSUM62Colour);
275 colours.add(purinePyrimidineColour);
276 colours.add(RNAInteractionColour);
277 // colours.add(covariationColour);
279 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
281 JMenuItem item = new JMenuItem(
282 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
284 item.addActionListener(new java.awt.event.ActionListener()
287 public void actionPerformed(ActionEvent e)
289 outputText_actionPerformed(e);
293 outputMenu.add(item);
297 * Build menus for annotation types that may be shown or hidden, and for
298 * 'reference annotations' that may be added to the alignment. First for the
299 * currently selected sequence (if there is one):
301 final List<SequenceI> selectedSequence = (seq == null ? Collections
302 .<SequenceI> emptyList() : Arrays.asList(seq));
303 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
304 seqHideAnnotationsMenu, selectedSequence);
305 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
309 * And repeat for the current selection group (if there is one):
311 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
312 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
314 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
315 groupHideAnnotationsMenu, selectedGroup);
316 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
322 } catch (Exception e)
330 sequenceMenu.setText(sequence.getName());
331 if (seq == ap.av.getAlignment().getSeqrep())
333 makeReferenceSeq.setText("Unmark representative");
335 makeReferenceSeq.setText("Mark as representative");
338 if (seq.getDatasetSequence().getPDBId() != null
339 && seq.getDatasetSequence().getPDBId().size() > 0)
341 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
344 while (e.hasMoreElements())
346 final PDBEntry pdb = (PDBEntry) e.nextElement();
348 menuItem = new JMenuItem();
349 menuItem.setText(pdb.getId());
350 menuItem.addActionListener(new ActionListener()
353 public void actionPerformed(ActionEvent e)
355 // TODO re JAL-860: optionally open dialog or provide a menu entry
356 // allowing user to open just one structure per sequence
357 // new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
358 // { pdb })[0], null, ap);
359 new StructureViewer(ap.getStructureSelectionManager())
361 ap.av.collateForPDB(new PDBEntry[]
362 { pdb })[0], null, ap);
365 viewStructureMenu.add(menuItem);
368 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
369 * menuItem.addActionListener(new java.awt.event.ActionListener() {
370 * public void actionPerformed(ActionEvent e) {
371 * colourByStructure(pdb.getId()); } });
372 * colStructureMenu.add(menuItem);
378 if (ap.av.getAlignment().isNucleotide() == false)
380 structureMenu.remove(viewStructureMenu);
382 // structureMenu.remove(colStructureMenu);
384 if (ap.av.getAlignment().isNucleotide() == true)
386 AlignmentAnnotation[] aa = ap.av.getAlignment()
387 .getAlignmentAnnotation();
388 for (int i = 0; aa != null && i < aa.length; i++)
390 if (aa[i].isValidStruc() && aa[i].sequenceRef == null)
392 final String rnastruc = aa[i].getRNAStruc();
393 final String structureLine = aa[i].label + " (alignment)";
394 menuItem = new JMenuItem();
395 menuItem.setText(MessageManager.formatMessage(
396 "label.2d_rna_structure_line", new Object[]
398 menuItem.addActionListener(new java.awt.event.ActionListener()
401 public void actionPerformed(ActionEvent e)
403 // // System.out.println("1:"+structureLine);
404 // System.out.println("1:sname" + seq.getName());
405 // System.out.println("2:seq" + seq);
407 // // System.out.println("3:"+seq.getSequenceAsString());
408 // System.out.println("3:strucseq" + rnastruc);
409 // // System.out.println("4:struc"+seq.getRNA());
410 // System.out.println("5:name" + seq.getName());
411 // System.out.println("6:ap" + ap);
412 new AppVarna(structureLine, seq, seq.getSequenceAsString(),
413 rnastruc, seq.getName(), ap);
414 // new AppVarna(seq.getName(),seq,rnastruc,seq.getRNA(),
415 // seq.getName(), ap);
416 System.out.println("end");
419 viewStructureMenu.add(menuItem);
423 // SequenceFeatures[] test = seq.getSequenceFeatures();
425 if (seq.getAnnotation() != null)
427 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
428 for (int i = 0; i < seqAnno.length; i++)
430 if (seqAnno[i].isValidStruc())
432 final String rnastruc = seqAnno[i].getRNAStruc();
434 // TODO: make rnastrucF a bit more nice
435 menuItem = new JMenuItem();
436 menuItem.setText(MessageManager.formatMessage(
437 "label.2d_rna_sequence_name", new Object[]
439 menuItem.addActionListener(new java.awt.event.ActionListener()
442 public void actionPerformed(ActionEvent e)
444 // TODO: VARNA does'nt print gaps in the sequence
446 new AppVarna(seq.getName() + " structure", seq, seq
447 .getSequenceAsString(), rnastruc, seq.getName(),
451 viewStructureMenu.add(menuItem);
457 menuItem = new JMenuItem(
458 MessageManager.getString("action.hide_sequences"));
459 menuItem.addActionListener(new java.awt.event.ActionListener()
462 public void actionPerformed(ActionEvent e)
464 hideSequences(false);
469 if (ap.av.getSelectionGroup() != null
470 && ap.av.getSelectionGroup().getSize() > 1)
472 menuItem = new JMenuItem(MessageManager.formatMessage(
473 "label.represent_group_with", new Object[]
475 menuItem.addActionListener(new java.awt.event.ActionListener()
478 public void actionPerformed(ActionEvent e)
483 sequenceMenu.add(menuItem);
486 if (ap.av.hasHiddenRows())
488 final int index = ap.av.getAlignment().findIndex(seq);
490 if (ap.av.adjustForHiddenSeqs(index)
491 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
493 menuItem = new JMenuItem(
494 MessageManager.getString("action.reveal_sequences"));
495 menuItem.addActionListener(new ActionListener()
498 public void actionPerformed(ActionEvent e)
500 ap.av.showSequence(index);
501 if (ap.overviewPanel != null)
503 ap.overviewPanel.updateOverviewImage();
511 // for the case when no sequences are even visible
512 if (ap.av.hasHiddenRows())
515 menuItem = new JMenuItem(
516 MessageManager.getString("action.reveal_all"));
517 menuItem.addActionListener(new ActionListener()
520 public void actionPerformed(ActionEvent e)
522 ap.av.showAllHiddenSeqs();
523 if (ap.overviewPanel != null)
525 ap.overviewPanel.updateOverviewImage();
535 SequenceGroup sg = ap.av.getSelectionGroup();
536 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
537 .getGroups().contains(sg) : false;
539 if (sg != null && sg.getSize() > 0)
541 groupName.setText(MessageManager.formatMessage("label.name_param",
544 groupName.setText(MessageManager
545 .getString("label.edit_name_and_description_current_group"));
547 if (sg.cs instanceof ZappoColourScheme)
549 zappoColour.setSelected(true);
551 else if (sg.cs instanceof TaylorColourScheme)
553 taylorColour.setSelected(true);
555 else if (sg.cs instanceof PIDColourScheme)
557 PIDColour.setSelected(true);
559 else if (sg.cs instanceof Blosum62ColourScheme)
561 BLOSUM62Colour.setSelected(true);
563 else if (sg.cs instanceof UserColourScheme)
565 userDefinedColour.setSelected(true);
567 else if (sg.cs instanceof HydrophobicColourScheme)
569 hydrophobicityColour.setSelected(true);
571 else if (sg.cs instanceof HelixColourScheme)
573 helixColour.setSelected(true);
575 else if (sg.cs instanceof StrandColourScheme)
577 strandColour.setSelected(true);
579 else if (sg.cs instanceof TurnColourScheme)
581 turnColour.setSelected(true);
583 else if (sg.cs instanceof BuriedColourScheme)
585 buriedColour.setSelected(true);
587 else if (sg.cs instanceof ClustalxColourScheme)
589 clustalColour.setSelected(true);
591 else if (sg.cs instanceof PurinePyrimidineColourScheme)
593 purinePyrimidineColour.setSelected(true);
597 * else if (sg.cs instanceof CovariationColourScheme) {
598 * covariationColour.setSelected(true); }
602 noColourmenuItem.setSelected(true);
605 if (sg.cs != null && sg.cs.conservationApplied())
607 conservationMenuItem.setSelected(true);
609 displayNonconserved.setSelected(sg.getShowNonconserved());
610 showText.setSelected(sg.getDisplayText());
611 showColourText.setSelected(sg.getColourText());
612 showBoxes.setSelected(sg.getDisplayBoxes());
613 // add any groupURLs to the groupURL submenu and make it visible
614 if (groupLinks != null && groupLinks.size() > 0)
616 buildGroupURLMenu(sg, groupLinks);
618 // Add a 'show all structures' for the current selection
619 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
620 SequenceI sqass = null;
621 for (SequenceI sq : ap.av.getSequenceSelection())
623 Vector<PDBEntry> pes = sq.getDatasetSequence().getPDBId();
624 if (pes != null && pes.size() > 0)
626 reppdb.put(pes.get(0).getId(), pes.get(0));
627 for (PDBEntry pe : pes)
629 pdbe.put(pe.getId(), pe);
639 final PDBEntry[] pe = pdbe.values().toArray(
640 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
641 new PDBEntry[reppdb.size()]);
642 final JMenuItem gpdbview, rpdbview;
643 if (pdbe.size() == 1)
645 structureMenu.add(gpdbview = new JMenuItem(MessageManager
646 .formatMessage("label.view_structure_for", new Object[]
647 { sqass.getDisplayId(false) })));
651 structureMenu.add(gpdbview = new JMenuItem(MessageManager
652 .formatMessage("label.view_all_structures", new Object[]
653 { new Integer(pdbe.size()).toString() })));
655 gpdbview.setToolTipText(MessageManager
656 .getString("label.open_new_jmol_view_with_all_structures_associated_current_selection_superimpose_using_alignment"));
657 gpdbview.addActionListener(new ActionListener()
661 public void actionPerformed(ActionEvent e)
663 new StructureViewer(ap.getStructureSelectionManager())
664 .viewStructures(ap, pe, ap.av.collateForPDB(pe));
667 if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
669 structureMenu.add(rpdbview = new JMenuItem(MessageManager
671 "label.view_all_representative_structures",
673 { new Integer(reppdb.size()).toString() })));
674 rpdbview.setToolTipText(MessageManager
675 .getString("label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment"));
676 rpdbview.addActionListener(new ActionListener()
680 public void actionPerformed(ActionEvent e)
682 new StructureViewer(ap.getStructureSelectionManager())
683 .viewStructures(ap, pr, ap.av.collateForPDB(pr));
691 groupMenu.setVisible(false);
692 editMenu.setVisible(false);
697 createGroupMenuItem.setVisible(true);
698 unGroupMenuItem.setVisible(false);
699 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
703 createGroupMenuItem.setVisible(false);
704 unGroupMenuItem.setVisible(true);
705 jMenu1.setText(MessageManager.getString("action.edit_group"));
710 sequenceMenu.setVisible(false);
711 structureMenu.setVisible(false);
714 if (links != null && links.size() > 0)
717 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
718 Vector linkset = new Vector();
719 for (int i = 0; i < links.size(); i++)
721 String link = links.elementAt(i).toString();
722 UrlLink urlLink = null;
725 urlLink = new UrlLink(link);
726 } catch (Exception foo)
728 jalview.bin.Cache.log.error("Exception for URLLink '" + link
733 if (!urlLink.isValid())
735 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
738 final String label = urlLink.getLabel();
739 if (seq != null && urlLink.isDynamic())
742 // collect matching db-refs
743 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
744 seq.getDBRef(), new String[]
745 { urlLink.getTarget() });
746 // collect id string too
747 String id = seq.getName();
748 String descr = seq.getDescription();
749 if (descr != null && descr.length() < 1)
756 for (int r = 0; r < dbr.length; r++)
758 if (id != null && dbr[r].getAccessionId().equals(id))
760 // suppress duplicate link creation for the bare sequence ID
761 // string with this link
764 // create Bare ID link for this RUL
765 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
769 for (int u = 0; u < urls.length; u += 2)
771 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
773 linkset.addElement(urls[u] + "|" + urls[u + 1]);
774 addshowLink(linkMenu, label + "|" + urls[u],
783 // create Bare ID link for this RUL
784 String[] urls = urlLink.makeUrls(id, true);
787 for (int u = 0; u < urls.length; u += 2)
789 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
791 linkset.addElement(urls[u] + "|" + urls[u + 1]);
792 addshowLink(linkMenu, label, urls[u + 1]);
797 // Create urls from description but only for URL links which are regex
799 if (descr != null && urlLink.getRegexReplace() != null)
801 // create link for this URL from description where regex matches
802 String[] urls = urlLink.makeUrls(descr, true);
805 for (int u = 0; u < urls.length; u += 2)
807 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
809 linkset.addElement(urls[u] + "|" + urls[u + 1]);
810 addshowLink(linkMenu, label, urls[u + 1]);
818 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
820 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
821 // Add a non-dynamic link
822 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
826 if (sequence != null)
828 sequenceMenu.add(linkMenu);
838 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
839 * "All" is added first, followed by a separator. Then add any annotation
840 * types associated with the current selection. Separate menus are built for
841 * the selected sequence group (if any), and the selected sequence.
843 * Some annotation rows are always rendered together - these can be identified
844 * by a common graphGroup property > -1. Only one of each group will be marked
845 * as visible (to avoid duplication of the display). For such groups we add a
846 * composite type name, e.g.
848 * IUPredWS (Long), IUPredWS (Short)
852 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
853 List<SequenceI> forSequences)
855 showMenu.removeAll();
856 hideMenu.removeAll();
858 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
859 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
860 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
862 showMenu.addSeparator();
863 hideMenu.addSeparator();
865 final AlignmentAnnotation[] annotations = ap.getAlignment()
866 .getAlignmentAnnotation();
869 * Find shown/hidden annotations types, distinguished by source (calcId),
870 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
871 * the insertion order, which is the order of the annotations on the
874 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
875 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
876 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes,
878 AlignmentAnnotationUtils.asList(annotations),
881 for (String calcId : hiddenTypes.keySet())
883 for (List<String> type : hiddenTypes.get(calcId))
885 addAnnotationTypeToShowHide(showMenu, forSequences,
886 calcId, type, false, true);
889 // grey out 'show annotations' if none are hidden
890 showMenu.setEnabled(!hiddenTypes.isEmpty());
892 for (String calcId : shownTypes.keySet())
894 for (List<String> type : shownTypes.get(calcId))
896 addAnnotationTypeToShowHide(hideMenu, forSequences,
897 calcId, type, false, false);
900 // grey out 'hide annotations' if none are shown
901 hideMenu.setEnabled(!shownTypes.isEmpty());
905 * Returns a list of sequences - either the current selection group (if there
906 * is one), else the specified single sequence.
911 protected List<SequenceI> getSequenceScope(SequenceI seq)
913 List<SequenceI> forSequences = null;
914 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
915 if (selectionGroup != null && selectionGroup.getSize() > 0)
917 forSequences = selectionGroup.getSequences();
921 forSequences = seq == null ? Collections.<SequenceI> emptyList()
922 : Arrays.asList(seq);
928 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
931 * @param showOrHideMenu
933 * @param forSequences
934 * the sequences whose annotations may be shown or hidden
939 * if true this is a special label meaning 'All'
940 * @param actionIsShow
941 * if true, the select menu item action is to show the annotation
944 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
945 final List<SequenceI> forSequences, String calcId,
946 final List<String> types, final boolean allTypes,
947 final boolean actionIsShow)
949 String label = types.toString(); // [a, b, c]
950 label = label.substring(1, label.length() - 1); // a, b, c
951 final JMenuItem item = new JMenuItem(label);
952 item.setToolTipText(calcId);
953 item.addActionListener(new java.awt.event.ActionListener()
956 public void actionPerformed(ActionEvent e)
958 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(), types,
959 forSequences, allTypes, actionIsShow);
963 showOrHideMenu.add(item);
966 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
969 // TODO: usability: thread off the generation of group url content so root
971 // sequence only URLs
972 // ID/regex match URLs
973 groupLinksMenu = new JMenu(
974 MessageManager.getString("action.group_link"));
975 JMenu[] linkMenus = new JMenu[]
976 { null, new JMenu(MessageManager.getString("action.ids")),
977 new JMenu(MessageManager.getString("action.sequences")),
978 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
985 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
986 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
987 Hashtable commonDbrefs = new Hashtable();
988 for (int sq = 0; sq < seqs.length; sq++)
991 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
992 .findPosition(sg.getEndRes());
993 // just collect ids from dataset sequence
994 // TODO: check if IDs collected from selecton group intersects with the
995 // current selection, too
996 SequenceI sqi = seqs[sq];
997 while (sqi.getDatasetSequence() != null)
999 sqi = sqi.getDatasetSequence();
1001 DBRefEntry[] dbr = sqi.getDBRef();
1002 if (dbr != null && dbr.length > 0)
1004 for (int d = 0; d < dbr.length; d++)
1006 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1007 Object[] sarray = (Object[]) commonDbrefs.get(src);
1010 sarray = new Object[2];
1011 sarray[0] = new int[]
1013 sarray[1] = new String[seqs.length];
1015 commonDbrefs.put(src, sarray);
1018 if (((String[]) sarray[1])[sq] == null)
1020 if (!dbr[d].hasMap()
1021 || (dbr[d].getMap().locateMappedRange(start, end) != null))
1023 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1024 ((int[]) sarray[0])[0]++;
1030 // now create group links for all distinct ID/sequence sets.
1031 boolean addMenu = false; // indicates if there are any group links to give
1033 for (int i = 0; i < groupLinks.size(); i++)
1035 String link = groupLinks.elementAt(i).toString();
1036 GroupUrlLink urlLink = null;
1039 urlLink = new GroupUrlLink(link);
1040 } catch (Exception foo)
1042 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
1047 if (!urlLink.isValid())
1049 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
1052 final String label = urlLink.getLabel();
1053 boolean usingNames = false;
1054 // Now see which parts of the group apply for this URL
1055 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1056 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
1057 String[] seqstr, ids; // input to makeUrl
1060 int numinput = ((int[]) idset[0])[0];
1061 String[] allids = ((String[]) idset[1]);
1062 seqstr = new String[numinput];
1063 ids = new String[numinput];
1064 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1066 if (allids[sq] != null)
1068 ids[idcount] = allids[sq];
1069 seqstr[idcount++] = idandseqs[1][sq];
1075 // just use the id/seq set
1076 seqstr = idandseqs[1];
1080 // and try and make the groupURL!
1082 Object[] urlset = null;
1085 urlset = urlLink.makeUrlStubs(ids, seqstr,
1086 "FromJalview" + System.currentTimeMillis(), false);
1087 } catch (UrlStringTooLongException e)
1092 int type = urlLink.getGroupURLType() & 3;
1093 // System.out.println(urlLink.getGroupURLType()
1094 // +" "+((String[])urlset[3])[0]);
1095 // first two bits ofurlLink type bitfield are sequenceids and sequences
1096 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1097 addshowLink(linkMenus[type], label
1098 + (((type & 1) == 1) ? ("("
1099 + (usingNames ? "Names" : ltarget) + ")") : ""),
1106 groupLinksMenu = new JMenu(
1107 MessageManager.getString("action.group_link"));
1108 for (int m = 0; m < linkMenus.length; m++)
1110 if (linkMenus[m] != null
1111 && linkMenus[m].getMenuComponentCount() > 0)
1113 groupLinksMenu.add(linkMenus[m]);
1117 groupMenu.add(groupLinksMenu);
1122 * add a show URL menu item to the given linkMenu
1126 * - menu label string
1130 private void addshowLink(JMenu linkMenu, String label, final String url)
1132 JMenuItem item = new JMenuItem(label);
1133 item.setToolTipText(MessageManager.formatMessage(
1134 "label.open_url_param", new Object[]
1136 item.addActionListener(new java.awt.event.ActionListener()
1139 public void actionPerformed(ActionEvent e)
1141 new Thread(new Runnable()
1158 * add a late bound groupURL item to the given linkMenu
1162 * - menu label string
1163 * @param urlgenerator
1164 * GroupURLLink used to generate URL
1166 * Object array returned from the makeUrlStubs function.
1168 private void addshowLink(JMenu linkMenu, String label,
1169 final GroupUrlLink urlgenerator, final Object[] urlstub)
1171 JMenuItem item = new JMenuItem(label);
1172 item.setToolTipText(MessageManager.formatMessage(
1173 "label.open_url_seqs_param",
1175 { urlgenerator.getUrl_prefix(),
1176 urlgenerator.getNumberInvolved(urlstub) }));
1177 // TODO: put in info about what is being sent.
1178 item.addActionListener(new java.awt.event.ActionListener()
1181 public void actionPerformed(ActionEvent e)
1183 new Thread(new Runnable()
1191 showLink(urlgenerator.constructFrom(urlstub));
1192 } catch (UrlStringTooLongException e)
1210 private void jbInit() throws Exception
1212 groupMenu.setText(MessageManager.getString("label.group"));
1213 groupMenu.setText(MessageManager.getString("label.selection"));
1214 groupName.setText(MessageManager.getString("label.name"));
1215 groupName.addActionListener(new java.awt.event.ActionListener()
1218 public void actionPerformed(ActionEvent e)
1220 groupName_actionPerformed();
1223 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1224 sequenceName.setText(MessageManager
1225 .getString("label.edit_name_description"));
1226 sequenceName.addActionListener(new java.awt.event.ActionListener()
1229 public void actionPerformed(ActionEvent e)
1231 sequenceName_actionPerformed();
1234 chooseAnnotations.setText(MessageManager
1235 .getString("label.choose_annotations") + "...");
1236 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1239 public void actionPerformed(ActionEvent e)
1241 chooseAnnotations_actionPerformed(e);
1244 sequenceDetails.setText(MessageManager
1245 .getString("label.sequence_details") + "...");
1246 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1249 public void actionPerformed(ActionEvent e)
1251 sequenceDetails_actionPerformed();
1254 sequenceSelDetails.setText(MessageManager
1255 .getString("label.sequence_details") + "...");
1257 .addActionListener(new java.awt.event.ActionListener()
1260 public void actionPerformed(ActionEvent e)
1262 sequenceSelectionDetails_actionPerformed();
1265 PIDColour.setFocusPainted(false);
1267 .setText(MessageManager.getString("action.remove_group"));
1268 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1271 public void actionPerformed(ActionEvent e)
1273 unGroupMenuItem_actionPerformed();
1276 createGroupMenuItem.setText(MessageManager
1277 .getString("action.create_group"));
1279 .addActionListener(new java.awt.event.ActionListener()
1282 public void actionPerformed(ActionEvent e)
1284 createGroupMenuItem_actionPerformed();
1288 outline.setText(MessageManager.getString("action.border_colour"));
1289 outline.addActionListener(new java.awt.event.ActionListener()
1292 public void actionPerformed(ActionEvent e)
1294 outline_actionPerformed();
1298 .setText(MessageManager.getString("label.nucleotide"));
1299 nucleotideMenuItem.addActionListener(new ActionListener()
1302 public void actionPerformed(ActionEvent e)
1304 nucleotideMenuItem_actionPerformed();
1307 colourMenu.setText(MessageManager.getString("label.group_colour"));
1308 showBoxes.setText(MessageManager.getString("action.boxes"));
1309 showBoxes.setState(true);
1310 showBoxes.addActionListener(new ActionListener()
1313 public void actionPerformed(ActionEvent e)
1315 showBoxes_actionPerformed();
1318 showText.setText(MessageManager.getString("action.text"));
1319 showText.setState(true);
1320 showText.addActionListener(new ActionListener()
1323 public void actionPerformed(ActionEvent e)
1325 showText_actionPerformed();
1328 showColourText.setText(MessageManager.getString("label.colour_text"));
1329 showColourText.addActionListener(new ActionListener()
1332 public void actionPerformed(ActionEvent e)
1334 showColourText_actionPerformed();
1337 displayNonconserved.setText(MessageManager
1338 .getString("label.show_non_conversed"));
1339 displayNonconserved.setState(true);
1340 displayNonconserved.addActionListener(new ActionListener()
1343 public void actionPerformed(ActionEvent e)
1345 showNonconserved_actionPerformed();
1348 editMenu.setText(MessageManager.getString("action.edit"));
1349 cut.setText(MessageManager.getString("action.cut"));
1350 cut.addActionListener(new ActionListener()
1353 public void actionPerformed(ActionEvent e)
1355 cut_actionPerformed();
1358 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1359 upperCase.addActionListener(new ActionListener()
1362 public void actionPerformed(ActionEvent e)
1367 copy.setText(MessageManager.getString("action.copy"));
1368 copy.addActionListener(new ActionListener()
1371 public void actionPerformed(ActionEvent e)
1373 copy_actionPerformed();
1376 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1377 lowerCase.addActionListener(new ActionListener()
1380 public void actionPerformed(ActionEvent e)
1385 toggle.setText(MessageManager.getString("label.toggle_case"));
1386 toggle.addActionListener(new ActionListener()
1389 public void actionPerformed(ActionEvent e)
1394 pdbMenu.setText(MessageManager
1395 .getString("label.associate_structure_with_sequence"));
1396 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1397 pdbFromFile.addActionListener(new ActionListener()
1400 public void actionPerformed(ActionEvent e)
1402 pdbFromFile_actionPerformed();
1405 // RNAFold.setText("From RNA Fold with predict2D");
1406 // RNAFold.addActionListener(new ActionListener()
1408 // public void actionPerformed(ActionEvent e)
1411 // RNAFold_actionPerformed();
1412 // } catch (Exception e1) {
1413 // // TODO Auto-generated catch block
1414 // e1.printStackTrace();
1418 // ContraFold.setText("From Contra Fold with predict2D");
1419 // ContraFold.addActionListener(new ActionListener()
1421 // public void actionPerformed(ActionEvent e)
1424 // ContraFold_actionPerformed();
1425 // } catch (Exception e1) {
1426 // // TODO Auto-generated catch block
1427 // e1.printStackTrace();
1431 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1432 enterPDB.addActionListener(new ActionListener()
1435 public void actionPerformed(ActionEvent e)
1437 enterPDB_actionPerformed();
1440 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1441 discoverPDB.addActionListener(new ActionListener()
1444 public void actionPerformed(ActionEvent e)
1446 discoverPDB_actionPerformed();
1449 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1451 seqShowAnnotationsMenu.setText(MessageManager
1452 .getString("label.show_annotations"));
1453 seqHideAnnotationsMenu.setText(MessageManager
1454 .getString("label.hide_annotations"));
1455 groupShowAnnotationsMenu.setText(MessageManager
1456 .getString("label.show_annotations"));
1457 groupHideAnnotationsMenu.setText(MessageManager
1458 .getString("label.hide_annotations"));
1459 sequenceFeature.setText(MessageManager
1460 .getString("label.create_sequence_feature"));
1461 sequenceFeature.addActionListener(new ActionListener()
1464 public void actionPerformed(ActionEvent e)
1466 sequenceFeature_actionPerformed();
1469 textColour.setText(MessageManager.getString("label.text_colour"));
1470 textColour.addActionListener(new ActionListener()
1473 public void actionPerformed(ActionEvent e)
1475 textColour_actionPerformed();
1478 jMenu1.setText(MessageManager.getString("label.group"));
1479 structureMenu.setText(MessageManager.getString("label.structure"));
1480 viewStructureMenu.setText(MessageManager
1481 .getString("label.view_structure"));
1482 // colStructureMenu.setText("Colour By Structure");
1483 editSequence.setText(MessageManager.getString("label.edit_sequence")
1485 editSequence.addActionListener(new ActionListener()
1488 public void actionPerformed(ActionEvent actionEvent)
1490 editSequence_actionPerformed(actionEvent);
1493 makeReferenceSeq.setText(MessageManager
1494 .getString("label.mark_as_representative"));
1495 makeReferenceSeq.addActionListener(new ActionListener()
1499 public void actionPerformed(ActionEvent actionEvent)
1501 makeReferenceSeq_actionPerformed(actionEvent);
1505 hideInsertions.setText(MessageManager.getString("label.hide_insertions"));
1506 hideInsertions.addActionListener(new ActionListener()
1510 public void actionPerformed(ActionEvent e)
1512 hideInsertions_actionPerformed(e);
1516 * annotationMenuItem.setText("By Annotation");
1517 * annotationMenuItem.addActionListener(new ActionListener() { public void
1518 * actionPerformed(ActionEvent actionEvent) {
1519 * annotationMenuItem_actionPerformed(actionEvent); } });
1521 groupMenu.add(sequenceSelDetails);
1527 add(hideInsertions);
1529 // annotations configuration panel suppressed for now
1530 // groupMenu.add(chooseAnnotations);
1533 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1534 * (if a selection group is in force).
1536 sequenceMenu.add(seqShowAnnotationsMenu);
1537 sequenceMenu.add(seqHideAnnotationsMenu);
1538 sequenceMenu.add(seqAddReferenceAnnotations);
1539 groupMenu.add(groupShowAnnotationsMenu);
1540 groupMenu.add(groupHideAnnotationsMenu);
1541 groupMenu.add(groupAddReferenceAnnotations);
1542 groupMenu.add(editMenu);
1543 groupMenu.add(outputMenu);
1544 groupMenu.add(sequenceFeature);
1545 groupMenu.add(createGroupMenuItem);
1546 groupMenu.add(unGroupMenuItem);
1547 groupMenu.add(jMenu1);
1548 sequenceMenu.add(sequenceName);
1549 sequenceMenu.add(sequenceDetails);
1550 sequenceMenu.add(makeReferenceSeq);
1551 colourMenu.add(textColour);
1552 colourMenu.add(noColourmenuItem);
1553 colourMenu.add(clustalColour);
1554 colourMenu.add(BLOSUM62Colour);
1555 colourMenu.add(PIDColour);
1556 colourMenu.add(zappoColour);
1557 colourMenu.add(taylorColour);
1558 colourMenu.add(hydrophobicityColour);
1559 colourMenu.add(helixColour);
1560 colourMenu.add(strandColour);
1561 colourMenu.add(turnColour);
1562 colourMenu.add(buriedColour);
1563 colourMenu.add(nucleotideMenuItem);
1564 if (ap.getAlignment().isNucleotide())
1566 // JBPNote - commented since the colourscheme isn't functional
1567 // colourMenu.add(RNAInteractionColour);
1568 colourMenu.add(purinePyrimidineColour);
1570 // colourMenu.add(covariationColour);
1571 colourMenu.add(userDefinedColour);
1573 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1575 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1576 .getUserColourSchemes().keys();
1578 while (userColours.hasMoreElements())
1580 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1581 item.addActionListener(new ActionListener()
1584 public void actionPerformed(ActionEvent evt)
1586 userDefinedColour_actionPerformed(evt);
1589 colourMenu.add(item);
1593 colourMenu.addSeparator();
1594 colourMenu.add(abovePIDColour);
1595 colourMenu.add(conservationMenuItem);
1596 // colourMenu.add(annotationMenuItem);
1599 editMenu.add(editSequence);
1600 editMenu.add(upperCase);
1601 editMenu.add(lowerCase);
1602 editMenu.add(toggle);
1603 pdbMenu.add(pdbFromFile);
1604 // JBPNote: These shouldn't be added here - should appear in a generic
1605 // 'apply web service to this sequence menu'
1606 // pdbMenu.add(RNAFold);
1607 // pdbMenu.add(ContraFold);
1608 pdbMenu.add(enterPDB);
1609 pdbMenu.add(discoverPDB);
1610 jMenu1.add(groupName);
1611 jMenu1.add(colourMenu);
1612 jMenu1.add(showBoxes);
1613 jMenu1.add(showText);
1614 jMenu1.add(showColourText);
1615 jMenu1.add(outline);
1616 jMenu1.add(displayNonconserved);
1617 structureMenu.add(pdbMenu);
1618 structureMenu.add(viewStructureMenu);
1619 // structureMenu.add(colStructureMenu);
1620 noColourmenuItem.setText(MessageManager.getString("label.none"));
1621 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1624 public void actionPerformed(ActionEvent e)
1626 noColourmenuItem_actionPerformed();
1630 clustalColour.setText(MessageManager
1631 .getString("label.clustalx_colours"));
1632 clustalColour.addActionListener(new java.awt.event.ActionListener()
1635 public void actionPerformed(ActionEvent e)
1637 clustalColour_actionPerformed();
1640 zappoColour.setText(MessageManager.getString("label.zappo"));
1641 zappoColour.addActionListener(new java.awt.event.ActionListener()
1644 public void actionPerformed(ActionEvent e)
1646 zappoColour_actionPerformed();
1649 taylorColour.setText(MessageManager.getString("label.taylor"));
1650 taylorColour.addActionListener(new java.awt.event.ActionListener()
1653 public void actionPerformed(ActionEvent e)
1655 taylorColour_actionPerformed();
1658 hydrophobicityColour.setText(MessageManager
1659 .getString("label.hydrophobicity"));
1660 hydrophobicityColour
1661 .addActionListener(new java.awt.event.ActionListener()
1664 public void actionPerformed(ActionEvent e)
1666 hydrophobicityColour_actionPerformed();
1669 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1670 helixColour.addActionListener(new java.awt.event.ActionListener()
1673 public void actionPerformed(ActionEvent e)
1675 helixColour_actionPerformed();
1678 strandColour.setText(MessageManager
1679 .getString("label.strand_propensity"));
1680 strandColour.addActionListener(new java.awt.event.ActionListener()
1683 public void actionPerformed(ActionEvent e)
1685 strandColour_actionPerformed();
1688 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1689 turnColour.addActionListener(new java.awt.event.ActionListener()
1692 public void actionPerformed(ActionEvent e)
1694 turnColour_actionPerformed();
1697 buriedColour.setText(MessageManager.getString("label.buried_index"));
1698 buriedColour.addActionListener(new java.awt.event.ActionListener()
1701 public void actionPerformed(ActionEvent e)
1703 buriedColour_actionPerformed();
1706 abovePIDColour.setText(MessageManager
1707 .getString("label.above_identity_percentage"));
1708 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1711 public void actionPerformed(ActionEvent e)
1713 abovePIDColour_actionPerformed();
1716 userDefinedColour.setText(MessageManager
1717 .getString("action.user_defined"));
1718 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1721 public void actionPerformed(ActionEvent e)
1723 userDefinedColour_actionPerformed(e);
1727 .setText(MessageManager.getString("label.percentage_identity"));
1728 PIDColour.addActionListener(new java.awt.event.ActionListener()
1731 public void actionPerformed(ActionEvent e)
1733 PIDColour_actionPerformed();
1736 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1737 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1740 public void actionPerformed(ActionEvent e)
1742 BLOSUM62Colour_actionPerformed();
1745 purinePyrimidineColour.setText(MessageManager
1746 .getString("label.purine_pyrimidine"));
1747 purinePyrimidineColour
1748 .addActionListener(new java.awt.event.ActionListener()
1751 public void actionPerformed(ActionEvent e)
1753 purinePyrimidineColour_actionPerformed();
1758 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1759 * public void actionPerformed(ActionEvent e) {
1760 * covariationColour_actionPerformed(); } });
1763 conservationMenuItem.setText(MessageManager
1764 .getString("label.conservation"));
1765 conservationMenuItem
1766 .addActionListener(new java.awt.event.ActionListener()
1769 public void actionPerformed(ActionEvent e)
1771 conservationMenuItem_actionPerformed();
1777 * Check for any annotations on the underlying dataset sequences (for the
1778 * current selection group) which are not 'on the alignment'.If any are found,
1779 * enable the option to add them to the alignment. The criteria for 'on the
1780 * alignment' is finding an alignment annotation on the alignment, matched on
1781 * calcId, label and sequenceRef.
1783 * A tooltip is also constructed that displays the source (calcId) and type
1784 * (label) of the annotations that can be added.
1787 * @param forSequences
1789 protected void configureReferenceAnnotationsMenu(
1790 JMenuItem menuItem, List<SequenceI> forSequences)
1792 menuItem.setEnabled(false);
1795 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1796 * Using TreeMap means calcIds are shown in alphabetical order.
1798 Map<String, String> tipEntries = new TreeMap<String, String>();
1799 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1800 AlignmentI al = this.ap.av.getAlignment();
1801 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1802 tipEntries, candidates, al);
1803 if (!candidates.isEmpty())
1805 StringBuilder tooltip = new StringBuilder(64);
1806 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1809 * Found annotations that could be added. Enable the menu item, and
1810 * configure its tooltip and action.
1812 menuItem.setEnabled(true);
1813 for (String calcId : tipEntries.keySet())
1815 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1817 String tooltipText = JvSwingUtils.wrapTooltip(true,
1818 tooltip.toString());
1819 menuItem.setToolTipText(tooltipText);
1821 menuItem.addActionListener(new ActionListener()
1824 public void actionPerformed(ActionEvent e)
1826 addReferenceAnnotations_actionPerformed(candidates);
1833 * Add annotations to the sequences and to the alignment.
1836 * a map whose keys are sequences on the alignment, and values a list
1837 * of annotations to add to each sequence
1839 protected void addReferenceAnnotations_actionPerformed(
1840 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1842 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1843 final AlignmentI alignment = this.ap.getAlignment();
1844 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1849 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1851 if (!ap.av.getAlignment().hasSeqrep())
1853 // initialise the display flags so the user sees something happen
1854 ap.av.setDisplayReferenceSeq(true);
1855 ap.av.setColourByReferenceSeq(true);
1856 ap.av.getAlignment().setSeqrep(sequence);
1860 if (ap.av.getAlignment().getSeqrep() == sequence)
1862 ap.av.getAlignment().setSeqrep(null);
1866 ap.av.getAlignment().setSeqrep(sequence);
1872 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1874 if (sequence != null)
1876 ColumnSelection cs = ap.av.getColumnSelection();
1879 cs = new ColumnSelection();
1881 cs.hideInsertionsFor(sequence);
1882 ap.av.setColumnSelection(cs);
1886 protected void sequenceSelectionDetails_actionPerformed()
1888 createSequenceDetailsReport(ap.av.getSequenceSelection());
1891 protected void sequenceDetails_actionPerformed()
1893 createSequenceDetailsReport(new SequenceI[]
1897 public void createSequenceDetailsReport(SequenceI[] sequences)
1899 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1900 StringBuffer contents = new StringBuffer();
1901 for (SequenceI seq : sequences)
1903 contents.append("<p><h2>"
1906 "label.create_sequence_details_report_annotation_for",
1908 { seq.getDisplayId(true) }) + "</h2></p><p>");
1909 new SequenceAnnotationReport(null)
1910 .createSequenceAnnotationReport(
1916 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1917 .getSeqPanel().seqCanvas.fr
1920 contents.append("</p>");
1922 cap.setText("<html>" + contents.toString() + "</html>");
1924 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1925 "label.sequence_details_for",
1926 (sequences.length == 1 ? new Object[]
1927 { sequences[0].getDisplayId(true) } : new Object[]
1928 { MessageManager.getString("label.selection") })), 500, 400);
1932 protected void showNonconserved_actionPerformed()
1934 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1939 * call to refresh view after settings change
1943 ap.updateAnnotation();
1944 ap.paintAlignment(true);
1946 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1955 protected void clustalColour_actionPerformed()
1957 SequenceGroup sg = getGroup();
1958 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1968 protected void zappoColour_actionPerformed()
1970 getGroup().cs = new ZappoColourScheme();
1980 protected void taylorColour_actionPerformed()
1982 getGroup().cs = new TaylorColourScheme();
1992 protected void hydrophobicityColour_actionPerformed()
1994 getGroup().cs = new HydrophobicColourScheme();
2004 protected void helixColour_actionPerformed()
2006 getGroup().cs = new HelixColourScheme();
2016 protected void strandColour_actionPerformed()
2018 getGroup().cs = new StrandColourScheme();
2028 protected void turnColour_actionPerformed()
2030 getGroup().cs = new TurnColourScheme();
2040 protected void buriedColour_actionPerformed()
2042 getGroup().cs = new BuriedColourScheme();
2052 public void nucleotideMenuItem_actionPerformed()
2054 getGroup().cs = new NucleotideColourScheme();
2058 protected void purinePyrimidineColour_actionPerformed()
2060 getGroup().cs = new PurinePyrimidineColourScheme();
2065 * protected void covariationColour_actionPerformed() { getGroup().cs = new
2066 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
2074 protected void abovePIDColour_actionPerformed()
2076 SequenceGroup sg = getGroup();
2082 if (abovePIDColour.isSelected())
2084 sg.cs.setConsensus(AAFrequency.calculate(
2085 sg.getSequences(ap.av.getHiddenRepSequences()),
2086 sg.getStartRes(), sg.getEndRes() + 1));
2088 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
2091 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
2093 SliderPanel.showPIDSlider();
2096 // remove PIDColouring
2098 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
2110 protected void userDefinedColour_actionPerformed(ActionEvent e)
2112 SequenceGroup sg = getGroup();
2114 if (e.getSource().equals(userDefinedColour))
2116 new UserDefinedColours(ap, sg);
2120 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2121 .getUserColourSchemes().get(e.getActionCommand());
2129 * Open a panel where the user can choose which types of sequence annotation
2134 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2136 // todo correct way to guard against opening a duplicate panel?
2137 new AnnotationChooser(ap);
2146 protected void PIDColour_actionPerformed()
2148 SequenceGroup sg = getGroup();
2149 sg.cs = new PIDColourScheme();
2150 sg.cs.setConsensus(AAFrequency.calculate(
2151 sg.getSequences(ap.av.getHiddenRepSequences()),
2152 sg.getStartRes(), sg.getEndRes() + 1));
2162 protected void BLOSUM62Colour_actionPerformed()
2164 SequenceGroup sg = getGroup();
2166 sg.cs = new Blosum62ColourScheme();
2168 sg.cs.setConsensus(AAFrequency.calculate(
2169 sg.getSequences(ap.av.getHiddenRepSequences()),
2170 sg.getStartRes(), sg.getEndRes() + 1));
2181 protected void noColourmenuItem_actionPerformed()
2183 getGroup().cs = null;
2193 protected void conservationMenuItem_actionPerformed()
2195 SequenceGroup sg = getGroup();
2201 if (conservationMenuItem.isSelected())
2203 // JBPNote: Conservation name shouldn't be i18n translated
2204 Conservation c = new Conservation("Group",
2205 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2206 .getHiddenRepSequences()), sg.getStartRes(),
2207 sg.getEndRes() + 1);
2210 c.verdict(false, ap.av.getConsPercGaps());
2212 sg.cs.setConservation(c);
2214 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2215 SliderPanel.showConservationSlider();
2218 // remove ConservationColouring
2220 sg.cs.setConservation(null);
2226 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2228 SequenceGroup sg = getGroup();
2234 AnnotationColourGradient acg = new AnnotationColourGradient(
2235 sequence.getAnnotation()[0], null,
2236 AnnotationColourGradient.NO_THRESHOLD);
2238 acg.setPredefinedColours(true);
2250 protected void groupName_actionPerformed()
2253 SequenceGroup sg = getGroup();
2254 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2255 sg.getDescription(), " "
2256 + MessageManager.getString("label.group_name") + " ",
2257 MessageManager.getString("label.group_description") + " ",
2258 MessageManager.getString("label.edit_group_name_description"),
2266 sg.setName(dialog.getName());
2267 sg.setDescription(dialog.getDescription());
2272 * Get selection group - adding it to the alignment if necessary.
2274 * @return sequence group to operate on
2276 SequenceGroup getGroup()
2278 SequenceGroup sg = ap.av.getSelectionGroup();
2279 // this method won't add a new group if it already exists
2282 ap.av.getAlignment().addGroup(sg);
2294 void sequenceName_actionPerformed()
2296 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2297 sequence.getDescription(),
2298 " " + MessageManager.getString("label.sequence_name")
2300 MessageManager.getString("label.sequence_description") + " ",
2302 .getString("label.edit_sequence_name_description"),
2310 if (dialog.getName() != null)
2312 if (dialog.getName().indexOf(" ") > -1)
2318 .getString("label.spaces_converted_to_backslashes"),
2320 .getString("label.no_spaces_allowed_sequence_name"),
2321 JOptionPane.WARNING_MESSAGE);
2324 sequence.setName(dialog.getName().replace(' ', '_'));
2325 ap.paintAlignment(false);
2328 sequence.setDescription(dialog.getDescription());
2330 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2341 void unGroupMenuItem_actionPerformed()
2343 SequenceGroup sg = ap.av.getSelectionGroup();
2344 ap.av.getAlignment().deleteGroup(sg);
2345 ap.av.setSelectionGroup(null);
2349 void createGroupMenuItem_actionPerformed()
2351 getGroup(); // implicitly creates group - note - should apply defaults / use
2352 // standard alignment window logic for this
2362 protected void outline_actionPerformed()
2364 SequenceGroup sg = getGroup();
2365 Color col = JColorChooser.showDialog(this,
2366 MessageManager.getString("label.select_outline_colour"),
2371 sg.setOutlineColour(col);
2383 public void showBoxes_actionPerformed()
2385 getGroup().setDisplayBoxes(showBoxes.isSelected());
2395 public void showText_actionPerformed()
2397 getGroup().setDisplayText(showText.isSelected());
2407 public void showColourText_actionPerformed()
2409 getGroup().setColourText(showColourText.isSelected());
2413 public void showLink(String url)
2417 jalview.util.BrowserLauncher.openURL(url);
2418 } catch (Exception ex)
2420 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2421 MessageManager.getString("label.web_browser_not_found_unix"),
2422 MessageManager.getString("label.web_browser_not_found"),
2423 JOptionPane.WARNING_MESSAGE);
2425 ex.printStackTrace();
2429 void hideSequences(boolean representGroup)
2431 SequenceGroup sg = ap.av.getSelectionGroup();
2432 if (sg == null || sg.getSize() < 1)
2434 ap.av.hideSequence(new SequenceI[]
2439 ap.av.setSelectionGroup(null);
2443 ap.av.hideRepSequences(sequence, sg);
2448 int gsize = sg.getSize();
2449 SequenceI[] hseqs = sg.getSequences().toArray(new SequenceI[gsize]);
2451 ap.av.hideSequence(hseqs);
2452 // refresh(); TODO: ? needed ?
2453 ap.av.sendSelection();
2456 public void copy_actionPerformed()
2458 ap.alignFrame.copy_actionPerformed(null);
2461 public void cut_actionPerformed()
2463 ap.alignFrame.cut_actionPerformed(null);
2466 void changeCase(ActionEvent e)
2468 Object source = e.getSource();
2469 SequenceGroup sg = ap.av.getSelectionGroup();
2473 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2475 sg.getEndRes() + 1);
2480 if (source == toggle)
2482 description = MessageManager.getString("label.toggle_case");
2483 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2485 else if (source == upperCase)
2487 description = MessageManager.getString("label.to_upper_case");
2488 caseChange = ChangeCaseCommand.TO_UPPER;
2492 description = MessageManager.getString("label.to_lower_case");
2493 caseChange = ChangeCaseCommand.TO_LOWER;
2496 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2497 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2498 startEnd, caseChange);
2500 ap.alignFrame.addHistoryItem(caseCommand);
2502 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2508 public void outputText_actionPerformed(ActionEvent e)
2510 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2511 cap.setForInput(null);
2512 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2513 "label.alignment_output_command", new Object[]
2514 { e.getActionCommand() }), 600, 500);
2516 String[] omitHidden = null;
2518 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2519 // or we simply trust the user wants
2520 // wysiwig behaviour
2522 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
2526 public void pdbFromFile_actionPerformed()
2528 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2529 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2530 chooser.setFileView(new jalview.io.JalviewFileView());
2531 chooser.setDialogTitle(MessageManager.formatMessage(
2532 "label.select_pdb_file_for", new Object[]
2533 { sequence.getDisplayId(false) }));
2534 chooser.setToolTipText(MessageManager.formatMessage(
2535 "label.load_pdb_file_associate_with_sequence", new Object[]
2536 { sequence.getDisplayId(false) }));
2538 int value = chooser.showOpenDialog(null);
2540 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2542 String choice = chooser.getSelectedFile().getPath();
2543 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2544 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2545 jalview.io.AppletFormatAdapter.FILE, sequence, true,
2551 // JBNote: commented out - these won't be instantiated here...!
2552 // public void RNAFold_actionPerformed() throws Exception
2554 // Predict2D P2D = new Predict2D();
2555 // P2D.getStructure2DFromRNAFold("toto");
2558 // public void ContraFold_actionPerformed() throws Exception
2560 // Predict2D P2D = new Predict2D();
2561 // P2D.getStructure2DFromContraFold("toto");
2563 public void enterPDB_actionPerformed()
2565 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2566 MessageManager.getString("label.enter_pdb_id"),
2567 MessageManager.getString("label.enter_pdb_id"),
2568 JOptionPane.QUESTION_MESSAGE);
2570 if (id != null && id.length() > 0)
2572 PDBEntry entry = new PDBEntry();
2573 entry.setId(id.toUpperCase());
2574 sequence.getDatasetSequence().addPDBId(entry);
2578 public void discoverPDB_actionPerformed()
2581 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2583 : ap.av.getSequenceSelection());
2584 Thread discpdb = new Thread(new Runnable()
2590 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2591 .fetchDBRefs(false);
2598 public void sequenceFeature_actionPerformed()
2600 SequenceGroup sg = ap.av.getSelectionGroup();
2606 int rsize = 0, gSize = sg.getSize();
2607 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2608 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2610 for (int i = 0; i < gSize; i++)
2612 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2613 int end = sg.findEndRes(sg.getSequenceAt(i));
2616 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2617 features[rsize] = new SequenceFeature(null, null, null, start, end,
2622 rseqs = new SequenceI[rsize];
2623 tfeatures = new SequenceFeature[rsize];
2624 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2625 System.arraycopy(features, 0, tfeatures, 0, rsize);
2626 features = tfeatures;
2628 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2629 features, true, ap))
2631 ap.alignFrame.setShowSeqFeatures(true);
2632 ap.highlightSearchResults(null);
2636 public void textColour_actionPerformed()
2638 SequenceGroup sg = getGroup();
2641 new TextColourChooser().chooseColour(ap, sg);
2645 public void colourByStructure(String pdbid)
2647 Annotation[] anots = ap.av.getStructureSelectionManager()
2648 .colourSequenceFromStructure(sequence, pdbid);
2650 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2651 "Coloured by " + pdbid, anots);
2653 ap.av.getAlignment().addAnnotation(an);
2654 an.createSequenceMapping(sequence, 0, true);
2655 // an.adjustForAlignment();
2656 ap.av.getAlignment().setAnnotationIndex(an, 0);
2658 ap.adjustAnnotationHeight();
2660 sequence.addAlignmentAnnotation(an);
2664 public void editSequence_actionPerformed(ActionEvent actionEvent)
2666 SequenceGroup sg = ap.av.getSelectionGroup();
2670 if (sequence == null)
2672 sequence = sg.getSequenceAt(0);
2675 EditNameDialog dialog = new EditNameDialog(
2676 sequence.getSequenceAsString(sg.getStartRes(),
2677 sg.getEndRes() + 1), null,
2678 MessageManager.getString("label.edit_sequence"), null,
2679 MessageManager.getString("label.edit_sequence"),
2684 EditCommand editCommand = new EditCommand(
2685 MessageManager.getString("label.edit_sequences"),
2686 Action.REPLACE, dialog.getName().replace(' ',
2687 ap.av.getGapCharacter()),
2688 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2689 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2691 ap.alignFrame.addHistoryItem(editCommand);
2693 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()