2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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 jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.Conservation;
26 import jalview.commands.ChangeCaseCommand;
27 import jalview.commands.EditCommand;
28 import jalview.commands.EditCommand.Action;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.ColumnSelection;
33 import jalview.datamodel.DBRefEntry;
34 import jalview.datamodel.PDBEntry;
35 import jalview.datamodel.Sequence;
36 import jalview.datamodel.SequenceFeature;
37 import jalview.datamodel.SequenceGroup;
38 import jalview.datamodel.SequenceI;
39 import jalview.io.FormatAdapter;
40 import jalview.io.SequenceAnnotationReport;
41 import jalview.schemes.AnnotationColourGradient;
42 import jalview.schemes.Blosum62ColourScheme;
43 import jalview.schemes.BuriedColourScheme;
44 import jalview.schemes.ClustalxColourScheme;
45 import jalview.schemes.HelixColourScheme;
46 import jalview.schemes.HydrophobicColourScheme;
47 import jalview.schemes.NucleotideColourScheme;
48 import jalview.schemes.PIDColourScheme;
49 import jalview.schemes.PurinePyrimidineColourScheme;
50 import jalview.schemes.ResidueProperties;
51 import jalview.schemes.StrandColourScheme;
52 import jalview.schemes.TaylorColourScheme;
53 import jalview.schemes.TurnColourScheme;
54 import jalview.schemes.UserColourScheme;
55 import jalview.schemes.ZappoColourScheme;
56 import jalview.util.GroupUrlLink;
57 import jalview.util.GroupUrlLink.UrlStringTooLongException;
58 import jalview.util.MessageManager;
59 import jalview.util.UrlLink;
61 import java.awt.Color;
62 import java.awt.event.ActionEvent;
63 import java.awt.event.ActionListener;
64 import java.util.ArrayList;
65 import java.util.Arrays;
66 import java.util.Collection;
67 import java.util.Collections;
68 import java.util.Hashtable;
69 import java.util.LinkedHashMap;
70 import java.util.List;
72 import java.util.TreeMap;
73 import java.util.Vector;
75 import javax.swing.ButtonGroup;
76 import javax.swing.JCheckBoxMenuItem;
77 import javax.swing.JColorChooser;
78 import javax.swing.JMenu;
79 import javax.swing.JMenuItem;
80 import javax.swing.JOptionPane;
81 import javax.swing.JPopupMenu;
82 import javax.swing.JRadioButtonMenuItem;
88 * @version $Revision: 1.118 $
90 public class PopupMenu extends JPopupMenu
92 private static final String ALL_ANNOTATIONS = "All";
94 private static final String COMMA = ",";
96 JMenu groupMenu = new JMenu();
98 JMenuItem groupName = new JMenuItem();
100 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
102 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
104 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
106 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
108 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
110 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
112 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
114 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
116 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
118 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
120 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
122 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
124 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
126 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
128 // protected JRadioButtonMenuItem covariationColour = new
129 // JRadioButtonMenuItem();
131 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
133 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
137 JMenu sequenceMenu = new JMenu();
139 JMenuItem sequenceName = new JMenuItem();
141 JMenuItem sequenceDetails = new JMenuItem();
143 JMenuItem sequenceSelDetails = new JMenuItem();
145 JMenuItem makeReferenceSeq = new JMenuItem();
147 JMenuItem chooseAnnotations = new JMenuItem();
151 JMenuItem createGroupMenuItem = new JMenuItem();
153 JMenuItem unGroupMenuItem = new JMenuItem();
155 JMenuItem outline = new JMenuItem();
157 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
159 JMenu colourMenu = new JMenu();
161 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
163 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
165 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
167 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
169 JMenu editMenu = new JMenu();
171 JMenuItem cut = new JMenuItem();
173 JMenuItem copy = new JMenuItem();
175 JMenuItem upperCase = new JMenuItem();
177 JMenuItem lowerCase = new JMenuItem();
179 JMenuItem toggle = new JMenuItem();
181 JMenu pdbMenu = new JMenu();
183 JMenuItem pdbFromFile = new JMenuItem();
185 // JBPNote: Commented these out - Should add these services via the web
186 // services menu system.
187 // JMenuItem ContraFold = new JMenuItem();
189 // JMenuItem RNAFold = new JMenuItem();
191 JMenuItem enterPDB = new JMenuItem();
193 JMenuItem discoverPDB = new JMenuItem();
195 JMenu outputMenu = new JMenu();
197 JMenu seqShowAnnotationsMenu = new JMenu();
199 JMenu seqHideAnnotationsMenu = new JMenu();
201 JMenuItem seqAddReferenceAnnotations = new JMenuItem();
203 JMenu groupShowAnnotationsMenu = new JMenu();
205 JMenu groupHideAnnotationsMenu = new JMenu();
207 JMenuItem groupAddReferenceAnnotations = new JMenuItem();
209 JMenuItem sequenceFeature = new JMenuItem();
211 JMenuItem textColour = new JMenuItem();
213 JMenu jMenu1 = new JMenu();
215 JMenu structureMenu = new JMenu();
217 JMenu viewStructureMenu = new JMenu();
219 // JMenu colStructureMenu = new JMenu();
220 JMenuItem editSequence = new JMenuItem();
222 // JMenuItem annotationMenuItem = new JMenuItem();
224 JMenu groupLinksMenu;
226 JMenuItem hideInsertions = new JMenuItem();
229 * Creates a new PopupMenu object.
236 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
238 this(ap, seq, links, null);
248 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
249 Vector links, Vector groupLinks)
251 // /////////////////////////////////////////////////////////
252 // If this is activated from the sequence panel, the user may want to
253 // edit or annotate a particular residue. Therefore display the residue menu
255 // If from the IDPanel, we must display the sequence menu
256 // ////////////////////////////////////////////////////////
260 ButtonGroup colours = new ButtonGroup();
261 colours.add(noColourmenuItem);
262 colours.add(clustalColour);
263 colours.add(zappoColour);
264 colours.add(taylorColour);
265 colours.add(hydrophobicityColour);
266 colours.add(helixColour);
267 colours.add(strandColour);
268 colours.add(turnColour);
269 colours.add(buriedColour);
270 colours.add(abovePIDColour);
271 colours.add(userDefinedColour);
272 colours.add(PIDColour);
273 colours.add(BLOSUM62Colour);
274 colours.add(purinePyrimidineColour);
275 colours.add(RNAInteractionColour);
276 // colours.add(covariationColour);
278 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
280 JMenuItem item = new JMenuItem(
281 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
283 item.addActionListener(new java.awt.event.ActionListener()
286 public void actionPerformed(ActionEvent e)
288 outputText_actionPerformed(e);
292 outputMenu.add(item);
296 * Build menus for annotation types that may be shown or hidden, and for
297 * 'reference annotations' that may be added to the alignment. First for the
298 * currently selected sequence (if there is one):
300 final List<SequenceI> selectedSequence = (seq == null ? Collections
301 .<SequenceI> emptyList() : Arrays.asList(seq));
302 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
303 seqHideAnnotationsMenu, selectedSequence);
304 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
308 * And repeat for the current selection group (if there is one):
310 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
311 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
313 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
314 groupHideAnnotationsMenu, selectedGroup);
315 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
321 } catch (Exception e)
329 sequenceMenu.setText(sequence.getName());
330 if (seq == ap.av.getAlignment().getSeqrep())
332 makeReferenceSeq.setText("Unmark representative");
334 makeReferenceSeq.setText("Mark as representative");
337 if (seq.getDatasetSequence().getPDBId() != null
338 && seq.getDatasetSequence().getPDBId().size() > 0)
340 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
343 while (e.hasMoreElements())
345 final PDBEntry pdb = (PDBEntry) e.nextElement();
347 menuItem = new JMenuItem();
348 menuItem.setText(pdb.getId());
349 menuItem.addActionListener(new ActionListener()
352 public void actionPerformed(ActionEvent e)
354 // TODO re JAL-860: optionally open dialog or provide a menu entry
355 // allowing user to open just one structure per sequence
356 // new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
357 // { pdb })[0], null, ap);
358 new StructureViewer(ap.getStructureSelectionManager())
360 ap.av.collateForPDB(new PDBEntry[]
361 { pdb })[0], null, ap);
364 viewStructureMenu.add(menuItem);
367 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
368 * menuItem.addActionListener(new java.awt.event.ActionListener() {
369 * public void actionPerformed(ActionEvent e) {
370 * colourByStructure(pdb.getId()); } });
371 * colStructureMenu.add(menuItem);
377 if (ap.av.getAlignment().isNucleotide() == false)
379 structureMenu.remove(viewStructureMenu);
381 // structureMenu.remove(colStructureMenu);
383 if (ap.av.getAlignment().isNucleotide() == true)
385 AlignmentAnnotation[] aa = ap.av.getAlignment()
386 .getAlignmentAnnotation();
387 for (int i = 0; aa != null && i < aa.length; i++)
389 if (aa[i].isValidStruc() && aa[i].sequenceRef == null)
391 final String rnastruc = aa[i].getRNAStruc();
392 final String structureLine = aa[i].label + " (alignment)";
393 menuItem = new JMenuItem();
394 menuItem.setText(MessageManager.formatMessage(
395 "label.2d_rna_structure_line", new String[]
397 menuItem.addActionListener(new java.awt.event.ActionListener()
400 public void actionPerformed(ActionEvent e)
402 // // System.out.println("1:"+structureLine);
403 // System.out.println("1:sname" + seq.getName());
404 // System.out.println("2:seq" + seq);
406 // // System.out.println("3:"+seq.getSequenceAsString());
407 // System.out.println("3:strucseq" + rnastruc);
408 // // System.out.println("4:struc"+seq.getRNA());
409 // System.out.println("5:name" + seq.getName());
410 // System.out.println("6:ap" + ap);
411 new AppVarna(structureLine, seq, seq.getSequenceAsString(),
412 rnastruc, seq.getName(), ap);
413 // new AppVarna(seq.getName(),seq,rnastruc,seq.getRNA(),
414 // seq.getName(), ap);
415 System.out.println("end");
418 viewStructureMenu.add(menuItem);
422 // SequenceFeatures[] test = seq.getSequenceFeatures();
424 if (seq.getAnnotation() != null)
426 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
427 for (int i = 0; i < seqAnno.length; i++)
429 if (seqAnno[i].isValidStruc())
431 final String rnastruc = seqAnno[i].getRNAStruc();
433 // TODO: make rnastrucF a bit more nice
434 menuItem = new JMenuItem();
435 menuItem.setText(MessageManager.formatMessage(
436 "label.2d_rna_sequence_name", new String[]
438 menuItem.addActionListener(new java.awt.event.ActionListener()
441 public void actionPerformed(ActionEvent e)
443 // TODO: VARNA does'nt print gaps in the sequence
445 new AppVarna(seq.getName() + " structure", seq, seq
446 .getSequenceAsString(), rnastruc, seq.getName(),
450 viewStructureMenu.add(menuItem);
456 menuItem = new JMenuItem(
457 MessageManager.getString("action.hide_sequences"));
458 menuItem.addActionListener(new java.awt.event.ActionListener()
461 public void actionPerformed(ActionEvent e)
463 hideSequences(false);
468 if (ap.av.getSelectionGroup() != null
469 && ap.av.getSelectionGroup().getSize() > 1)
471 menuItem = new JMenuItem(MessageManager.formatMessage(
472 "label.represent_group_with", new String[]
474 menuItem.addActionListener(new java.awt.event.ActionListener()
477 public void actionPerformed(ActionEvent e)
482 sequenceMenu.add(menuItem);
485 if (ap.av.hasHiddenRows())
487 final int index = ap.av.getAlignment().findIndex(seq);
489 if (ap.av.adjustForHiddenSeqs(index)
490 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
492 menuItem = new JMenuItem(
493 MessageManager.getString("action.reveal_sequences"));
494 menuItem.addActionListener(new ActionListener()
497 public void actionPerformed(ActionEvent e)
499 ap.av.showSequence(index);
500 if (ap.overviewPanel != null)
502 ap.overviewPanel.updateOverviewImage();
510 // for the case when no sequences are even visible
511 if (ap.av.hasHiddenRows())
514 menuItem = new JMenuItem(
515 MessageManager.getString("action.reveal_all"));
516 menuItem.addActionListener(new ActionListener()
519 public void actionPerformed(ActionEvent e)
521 ap.av.showAllHiddenSeqs();
522 if (ap.overviewPanel != null)
524 ap.overviewPanel.updateOverviewImage();
534 SequenceGroup sg = ap.av.getSelectionGroup();
535 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
536 .getGroups().contains(sg) : false;
538 if (sg != null && sg.getSize() > 0)
540 groupName.setText(MessageManager.formatMessage("label.name_param",
543 groupName.setText(MessageManager
544 .getString("label.edit_name_and_description_current_group"));
546 if (sg.cs instanceof ZappoColourScheme)
548 zappoColour.setSelected(true);
550 else if (sg.cs instanceof TaylorColourScheme)
552 taylorColour.setSelected(true);
554 else if (sg.cs instanceof PIDColourScheme)
556 PIDColour.setSelected(true);
558 else if (sg.cs instanceof Blosum62ColourScheme)
560 BLOSUM62Colour.setSelected(true);
562 else if (sg.cs instanceof UserColourScheme)
564 userDefinedColour.setSelected(true);
566 else if (sg.cs instanceof HydrophobicColourScheme)
568 hydrophobicityColour.setSelected(true);
570 else if (sg.cs instanceof HelixColourScheme)
572 helixColour.setSelected(true);
574 else if (sg.cs instanceof StrandColourScheme)
576 strandColour.setSelected(true);
578 else if (sg.cs instanceof TurnColourScheme)
580 turnColour.setSelected(true);
582 else if (sg.cs instanceof BuriedColourScheme)
584 buriedColour.setSelected(true);
586 else if (sg.cs instanceof ClustalxColourScheme)
588 clustalColour.setSelected(true);
590 else if (sg.cs instanceof PurinePyrimidineColourScheme)
592 purinePyrimidineColour.setSelected(true);
596 * else if (sg.cs instanceof CovariationColourScheme) {
597 * covariationColour.setSelected(true); }
601 noColourmenuItem.setSelected(true);
604 if (sg.cs != null && sg.cs.conservationApplied())
606 conservationMenuItem.setSelected(true);
608 displayNonconserved.setSelected(sg.getShowNonconserved());
609 showText.setSelected(sg.getDisplayText());
610 showColourText.setSelected(sg.getColourText());
611 showBoxes.setSelected(sg.getDisplayBoxes());
612 // add any groupURLs to the groupURL submenu and make it visible
613 if (groupLinks != null && groupLinks.size() > 0)
615 buildGroupURLMenu(sg, groupLinks);
617 // Add a 'show all structures' for the current selection
618 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
619 SequenceI sqass = null;
620 for (SequenceI sq : ap.av.getSequenceSelection())
622 Vector<PDBEntry> pes = sq.getDatasetSequence().getPDBId();
623 if (pes != null && pes.size() > 0)
625 reppdb.put(pes.get(0).getId(), pes.get(0));
626 for (PDBEntry pe : pes)
628 pdbe.put(pe.getId(), pe);
638 final PDBEntry[] pe = pdbe.values().toArray(
639 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
640 new PDBEntry[reppdb.size()]);
641 final JMenuItem gpdbview, rpdbview;
642 if (pdbe.size() == 1)
644 structureMenu.add(gpdbview = new JMenuItem(MessageManager
645 .formatMessage("label.view_structure_for", new String[]
646 { sqass.getDisplayId(false) })));
650 structureMenu.add(gpdbview = new JMenuItem(MessageManager
651 .formatMessage("label.view_all_structures", new String[]
652 { new Integer(pdbe.size()).toString() })));
654 gpdbview.setToolTipText(MessageManager
655 .getString("label.open_new_jmol_view_with_all_structures_associated_current_selection_superimpose_using_alignment"));
656 gpdbview.addActionListener(new ActionListener()
660 public void actionPerformed(ActionEvent e)
662 new StructureViewer(ap.getStructureSelectionManager())
663 .viewStructures(ap, pe, ap.av.collateForPDB(pe));
666 if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
668 structureMenu.add(rpdbview = new JMenuItem(MessageManager
670 "label.view_all_representative_structures",
672 { new Integer(reppdb.size()).toString() })));
673 rpdbview.setToolTipText(MessageManager
674 .getString("label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment"));
675 rpdbview.addActionListener(new ActionListener()
679 public void actionPerformed(ActionEvent e)
681 new StructureViewer(ap.getStructureSelectionManager())
682 .viewStructures(ap, pr, ap.av.collateForPDB(pr));
690 groupMenu.setVisible(false);
691 editMenu.setVisible(false);
696 createGroupMenuItem.setVisible(true);
697 unGroupMenuItem.setVisible(false);
698 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
702 createGroupMenuItem.setVisible(false);
703 unGroupMenuItem.setVisible(true);
704 jMenu1.setText(MessageManager.getString("action.edit_group"));
709 sequenceMenu.setVisible(false);
710 structureMenu.setVisible(false);
713 if (links != null && links.size() > 0)
716 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
717 Vector linkset = new Vector();
718 for (int i = 0; i < links.size(); i++)
720 String link = links.elementAt(i).toString();
721 UrlLink urlLink = null;
724 urlLink = new UrlLink(link);
725 } catch (Exception foo)
727 jalview.bin.Cache.log.error("Exception for URLLink '" + link
732 if (!urlLink.isValid())
734 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
737 final String label = urlLink.getLabel();
738 if (seq != null && urlLink.isDynamic())
741 // collect matching db-refs
742 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
743 seq.getDBRef(), new String[]
744 { urlLink.getTarget() });
745 // collect id string too
746 String id = seq.getName();
747 String descr = seq.getDescription();
748 if (descr != null && descr.length() < 1)
755 for (int r = 0; r < dbr.length; r++)
757 if (id != null && dbr[r].getAccessionId().equals(id))
759 // suppress duplicate link creation for the bare sequence ID
760 // string with this link
763 // create Bare ID link for this RUL
764 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
768 for (int u = 0; u < urls.length; u += 2)
770 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
772 linkset.addElement(urls[u] + "|" + urls[u + 1]);
773 addshowLink(linkMenu, label + "|" + urls[u],
782 // create Bare ID link for this RUL
783 String[] urls = urlLink.makeUrls(id, true);
786 for (int u = 0; u < urls.length; u += 2)
788 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
790 linkset.addElement(urls[u] + "|" + urls[u + 1]);
791 addshowLink(linkMenu, label, urls[u + 1]);
796 // Create urls from description but only for URL links which are regex
798 if (descr != null && urlLink.getRegexReplace() != null)
800 // create link for this URL from description where regex matches
801 String[] urls = urlLink.makeUrls(descr, true);
804 for (int u = 0; u < urls.length; u += 2)
806 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
808 linkset.addElement(urls[u] + "|" + urls[u + 1]);
809 addshowLink(linkMenu, label, urls[u + 1]);
817 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
819 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
820 // Add a non-dynamic link
821 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
825 if (sequence != null)
827 sequenceMenu.add(linkMenu);
837 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
838 * "All" is added first, followed by a separator. Then add any annotation
839 * types associated with the current selection. Separate menus are built for
840 * the selected sequence group (if any), and the selected sequence.
842 * Some annotation rows are always rendered together - these can be identified
843 * by a common graphGroup property > -1. Only one of each group will be marked
844 * as visible (to avoid duplication of the display). For such groups we add a
845 * composite type name, e.g.
847 * IUPredWS (Long), IUPredWS (Short)
851 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
852 List<SequenceI> forSequences)
854 showMenu.removeAll();
855 hideMenu.removeAll();
857 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
858 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
859 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
861 showMenu.addSeparator();
862 hideMenu.addSeparator();
864 final AlignmentAnnotation[] annotations = ap.getAlignment()
865 .getAlignmentAnnotation();
868 * Find shown/hidden annotations types, distinguished by source (calcId),
869 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
870 * the insertion order, which is the order of the annotations on the
873 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
874 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
875 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes,
877 AlignmentAnnotationUtils.asList(annotations),
880 for (String calcId : hiddenTypes.keySet())
882 for (List<String> type : hiddenTypes.get(calcId))
884 addAnnotationTypeToShowHide(showMenu, forSequences,
885 calcId, type, false, true);
888 // grey out 'show annotations' if none are hidden
889 showMenu.setEnabled(!hiddenTypes.isEmpty());
891 for (String calcId : shownTypes.keySet())
893 for (List<String> type : shownTypes.get(calcId))
895 addAnnotationTypeToShowHide(hideMenu, forSequences,
896 calcId, type, false, false);
899 // grey out 'hide annotations' if none are shown
900 hideMenu.setEnabled(!shownTypes.isEmpty());
904 * Returns a list of sequences - either the current selection group (if there
905 * is one), else the specified single sequence.
910 protected List<SequenceI> getSequenceScope(SequenceI seq)
912 List<SequenceI> forSequences = null;
913 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
914 if (selectionGroup != null && selectionGroup.getSize() > 0)
916 forSequences = selectionGroup.getSequences();
920 forSequences = seq == null ? Collections.<SequenceI> emptyList()
921 : Arrays.asList(seq);
927 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
930 * @param showOrHideMenu
932 * @param forSequences
933 * the sequences whose annotations may be shown or hidden
938 * if true this is a special label meaning 'All'
939 * @param actionIsShow
940 * if true, the select menu item action is to show the annotation
943 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
944 final List<SequenceI> forSequences, String calcId,
945 final List<String> types, final boolean allTypes,
946 final boolean actionIsShow)
948 String label = types.toString(); // [a, b, c]
949 label = label.substring(1, label.length() - 1);
950 final JMenuItem item = new JMenuItem(label);
951 item.setToolTipText(calcId);
952 item.addActionListener(new java.awt.event.ActionListener()
955 public void actionPerformed(ActionEvent e)
957 showHideAnnotation_actionPerformed(types, forSequences, allTypes,
961 showOrHideMenu.add(item);
965 * Action on selecting a list of annotation type (or the 'all types' values)
966 * to show or hide for the specified sequences.
969 * @param forSequences
973 protected void showHideAnnotation_actionPerformed(
974 Collection<String> types, List<SequenceI> forSequences,
975 boolean anyType, boolean doShow)
977 for (AlignmentAnnotation aa : ap.getAlignment()
978 .getAlignmentAnnotation())
980 if (anyType || types.contains(aa.label))
982 if ((aa.sequenceRef != null)
983 && forSequences.contains(aa.sequenceRef))
992 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
995 // TODO: usability: thread off the generation of group url content so root
997 // sequence only URLs
998 // ID/regex match URLs
999 groupLinksMenu = new JMenu(
1000 MessageManager.getString("action.group_link"));
1001 JMenu[] linkMenus = new JMenu[]
1002 { null, new JMenu(MessageManager.getString("action.ids")),
1003 new JMenu(MessageManager.getString("action.sequences")),
1004 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
1011 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1012 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1013 Hashtable commonDbrefs = new Hashtable();
1014 for (int sq = 0; sq < seqs.length; sq++)
1017 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
1018 .findPosition(sg.getEndRes());
1019 // just collect ids from dataset sequence
1020 // TODO: check if IDs collected from selecton group intersects with the
1021 // current selection, too
1022 SequenceI sqi = seqs[sq];
1023 while (sqi.getDatasetSequence() != null)
1025 sqi = sqi.getDatasetSequence();
1027 DBRefEntry[] dbr = sqi.getDBRef();
1028 if (dbr != null && dbr.length > 0)
1030 for (int d = 0; d < dbr.length; d++)
1032 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1033 Object[] sarray = (Object[]) commonDbrefs.get(src);
1036 sarray = new Object[2];
1037 sarray[0] = new int[]
1039 sarray[1] = new String[seqs.length];
1041 commonDbrefs.put(src, sarray);
1044 if (((String[]) sarray[1])[sq] == null)
1046 if (!dbr[d].hasMap()
1047 || (dbr[d].getMap().locateMappedRange(start, end) != null))
1049 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1050 ((int[]) sarray[0])[0]++;
1056 // now create group links for all distinct ID/sequence sets.
1057 boolean addMenu = false; // indicates if there are any group links to give
1059 for (int i = 0; i < groupLinks.size(); i++)
1061 String link = groupLinks.elementAt(i).toString();
1062 GroupUrlLink urlLink = null;
1065 urlLink = new GroupUrlLink(link);
1066 } catch (Exception foo)
1068 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
1073 if (!urlLink.isValid())
1075 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
1078 final String label = urlLink.getLabel();
1079 boolean usingNames = false;
1080 // Now see which parts of the group apply for this URL
1081 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1082 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
1083 String[] seqstr, ids; // input to makeUrl
1086 int numinput = ((int[]) idset[0])[0];
1087 String[] allids = ((String[]) idset[1]);
1088 seqstr = new String[numinput];
1089 ids = new String[numinput];
1090 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1092 if (allids[sq] != null)
1094 ids[idcount] = allids[sq];
1095 seqstr[idcount++] = idandseqs[1][sq];
1101 // just use the id/seq set
1102 seqstr = idandseqs[1];
1106 // and try and make the groupURL!
1108 Object[] urlset = null;
1111 urlset = urlLink.makeUrlStubs(ids, seqstr,
1112 "FromJalview" + System.currentTimeMillis(), false);
1113 } catch (UrlStringTooLongException e)
1118 int type = urlLink.getGroupURLType() & 3;
1119 // System.out.println(urlLink.getGroupURLType()
1120 // +" "+((String[])urlset[3])[0]);
1121 // first two bits ofurlLink type bitfield are sequenceids and sequences
1122 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1123 addshowLink(linkMenus[type], label
1124 + (((type & 1) == 1) ? ("("
1125 + (usingNames ? "Names" : ltarget) + ")") : ""),
1132 groupLinksMenu = new JMenu(
1133 MessageManager.getString("action.group_link"));
1134 for (int m = 0; m < linkMenus.length; m++)
1136 if (linkMenus[m] != null
1137 && linkMenus[m].getMenuComponentCount() > 0)
1139 groupLinksMenu.add(linkMenus[m]);
1143 groupMenu.add(groupLinksMenu);
1148 * add a show URL menu item to the given linkMenu
1152 * - menu label string
1156 private void addshowLink(JMenu linkMenu, String label, final String url)
1158 JMenuItem item = new JMenuItem(label);
1159 item.setToolTipText(MessageManager.formatMessage(
1160 "label.open_url_param", new String[]
1162 item.addActionListener(new java.awt.event.ActionListener()
1165 public void actionPerformed(ActionEvent e)
1167 new Thread(new Runnable()
1184 * add a late bound groupURL item to the given linkMenu
1188 * - menu label string
1189 * @param urlgenerator
1190 * GroupURLLink used to generate URL
1192 * Object array returned from the makeUrlStubs function.
1194 private void addshowLink(JMenu linkMenu, String label,
1195 final GroupUrlLink urlgenerator, final Object[] urlstub)
1197 JMenuItem item = new JMenuItem(label);
1198 item.setToolTipText(MessageManager.formatMessage(
1199 "label.open_url_seqs_param",
1201 { urlgenerator.getUrl_prefix(),
1202 urlgenerator.getNumberInvolved(urlstub) }));
1203 // TODO: put in info about what is being sent.
1204 item.addActionListener(new java.awt.event.ActionListener()
1207 public void actionPerformed(ActionEvent e)
1209 new Thread(new Runnable()
1217 showLink(urlgenerator.constructFrom(urlstub));
1218 } catch (UrlStringTooLongException e)
1236 private void jbInit() throws Exception
1238 groupMenu.setText(MessageManager.getString("label.group"));
1239 groupMenu.setText(MessageManager.getString("label.selection"));
1240 groupName.setText(MessageManager.getString("label.name"));
1241 groupName.addActionListener(new java.awt.event.ActionListener()
1244 public void actionPerformed(ActionEvent e)
1246 groupName_actionPerformed();
1249 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1250 sequenceName.setText(MessageManager
1251 .getString("label.edit_name_description"));
1252 sequenceName.addActionListener(new java.awt.event.ActionListener()
1255 public void actionPerformed(ActionEvent e)
1257 sequenceName_actionPerformed();
1260 chooseAnnotations.setText(MessageManager
1261 .getString("label.choose_annotations") + "...");
1262 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1265 public void actionPerformed(ActionEvent e)
1267 chooseAnnotations_actionPerformed(e);
1270 sequenceDetails.setText(MessageManager
1271 .getString("label.sequence_details") + "...");
1272 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1275 public void actionPerformed(ActionEvent e)
1277 sequenceDetails_actionPerformed();
1280 sequenceSelDetails.setText(MessageManager
1281 .getString("label.sequence_details") + "...");
1283 .addActionListener(new java.awt.event.ActionListener()
1286 public void actionPerformed(ActionEvent e)
1288 sequenceSelectionDetails_actionPerformed();
1291 PIDColour.setFocusPainted(false);
1293 .setText(MessageManager.getString("action.remove_group"));
1294 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1297 public void actionPerformed(ActionEvent e)
1299 unGroupMenuItem_actionPerformed();
1302 createGroupMenuItem.setText(MessageManager
1303 .getString("action.create_group"));
1305 .addActionListener(new java.awt.event.ActionListener()
1308 public void actionPerformed(ActionEvent e)
1310 createGroupMenuItem_actionPerformed();
1314 outline.setText(MessageManager.getString("action.border_colour"));
1315 outline.addActionListener(new java.awt.event.ActionListener()
1318 public void actionPerformed(ActionEvent e)
1320 outline_actionPerformed();
1324 .setText(MessageManager.getString("label.nucleotide"));
1325 nucleotideMenuItem.addActionListener(new ActionListener()
1328 public void actionPerformed(ActionEvent e)
1330 nucleotideMenuItem_actionPerformed();
1333 colourMenu.setText(MessageManager.getString("label.group_colour"));
1334 showBoxes.setText(MessageManager.getString("action.boxes"));
1335 showBoxes.setState(true);
1336 showBoxes.addActionListener(new ActionListener()
1339 public void actionPerformed(ActionEvent e)
1341 showBoxes_actionPerformed();
1344 showText.setText(MessageManager.getString("action.text"));
1345 showText.setState(true);
1346 showText.addActionListener(new ActionListener()
1349 public void actionPerformed(ActionEvent e)
1351 showText_actionPerformed();
1354 showColourText.setText(MessageManager.getString("label.colour_text"));
1355 showColourText.addActionListener(new ActionListener()
1358 public void actionPerformed(ActionEvent e)
1360 showColourText_actionPerformed();
1363 displayNonconserved.setText(MessageManager
1364 .getString("label.show_non_conversed"));
1365 displayNonconserved.setState(true);
1366 displayNonconserved.addActionListener(new ActionListener()
1369 public void actionPerformed(ActionEvent e)
1371 showNonconserved_actionPerformed();
1374 editMenu.setText(MessageManager.getString("action.edit"));
1375 cut.setText(MessageManager.getString("action.cut"));
1376 cut.addActionListener(new ActionListener()
1379 public void actionPerformed(ActionEvent e)
1381 cut_actionPerformed();
1384 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1385 upperCase.addActionListener(new ActionListener()
1388 public void actionPerformed(ActionEvent e)
1393 copy.setText(MessageManager.getString("action.copy"));
1394 copy.addActionListener(new ActionListener()
1397 public void actionPerformed(ActionEvent e)
1399 copy_actionPerformed();
1402 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1403 lowerCase.addActionListener(new ActionListener()
1406 public void actionPerformed(ActionEvent e)
1411 toggle.setText(MessageManager.getString("label.toggle_case"));
1412 toggle.addActionListener(new ActionListener()
1415 public void actionPerformed(ActionEvent e)
1420 pdbMenu.setText(MessageManager
1421 .getString("label.associate_structure_with_sequence"));
1422 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1423 pdbFromFile.addActionListener(new ActionListener()
1426 public void actionPerformed(ActionEvent e)
1428 pdbFromFile_actionPerformed();
1431 // RNAFold.setText("From RNA Fold with predict2D");
1432 // RNAFold.addActionListener(new ActionListener()
1434 // public void actionPerformed(ActionEvent e)
1437 // RNAFold_actionPerformed();
1438 // } catch (Exception e1) {
1439 // // TODO Auto-generated catch block
1440 // e1.printStackTrace();
1444 // ContraFold.setText("From Contra Fold with predict2D");
1445 // ContraFold.addActionListener(new ActionListener()
1447 // public void actionPerformed(ActionEvent e)
1450 // ContraFold_actionPerformed();
1451 // } catch (Exception e1) {
1452 // // TODO Auto-generated catch block
1453 // e1.printStackTrace();
1457 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1458 enterPDB.addActionListener(new ActionListener()
1461 public void actionPerformed(ActionEvent e)
1463 enterPDB_actionPerformed();
1466 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1467 discoverPDB.addActionListener(new ActionListener()
1470 public void actionPerformed(ActionEvent e)
1472 discoverPDB_actionPerformed();
1475 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1477 seqShowAnnotationsMenu.setText(MessageManager
1478 .getString("label.show_annotations"));
1479 seqHideAnnotationsMenu.setText(MessageManager
1480 .getString("label.hide_annotations"));
1481 groupShowAnnotationsMenu.setText(MessageManager
1482 .getString("label.show_annotations"));
1483 groupHideAnnotationsMenu.setText(MessageManager
1484 .getString("label.hide_annotations"));
1485 sequenceFeature.setText(MessageManager
1486 .getString("label.create_sequence_feature"));
1487 sequenceFeature.addActionListener(new ActionListener()
1490 public void actionPerformed(ActionEvent e)
1492 sequenceFeature_actionPerformed();
1495 textColour.setText(MessageManager.getString("label.text_colour"));
1496 textColour.addActionListener(new ActionListener()
1499 public void actionPerformed(ActionEvent e)
1501 textColour_actionPerformed();
1504 jMenu1.setText(MessageManager.getString("label.group"));
1505 structureMenu.setText(MessageManager.getString("label.structure"));
1506 viewStructureMenu.setText(MessageManager
1507 .getString("label.view_structure"));
1508 // colStructureMenu.setText("Colour By Structure");
1509 editSequence.setText(MessageManager.getString("label.edit_sequence")
1511 editSequence.addActionListener(new ActionListener()
1514 public void actionPerformed(ActionEvent actionEvent)
1516 editSequence_actionPerformed(actionEvent);
1519 makeReferenceSeq.setText(MessageManager
1520 .getString("label.mark_as_representative"));
1521 makeReferenceSeq.addActionListener(new ActionListener()
1525 public void actionPerformed(ActionEvent actionEvent)
1527 makeReferenceSeq_actionPerformed(actionEvent);
1531 hideInsertions.setText(MessageManager.getString("label.hide_insertions"));
1532 hideInsertions.addActionListener(new ActionListener()
1536 public void actionPerformed(ActionEvent e)
1538 hideInsertions_actionPerformed(e);
1542 * annotationMenuItem.setText("By Annotation");
1543 * annotationMenuItem.addActionListener(new ActionListener() { public void
1544 * actionPerformed(ActionEvent actionEvent) {
1545 * annotationMenuItem_actionPerformed(actionEvent); } });
1547 groupMenu.add(sequenceSelDetails);
1553 add(hideInsertions);
1555 // annotations configuration panel suppressed for now
1556 // groupMenu.add(chooseAnnotations);
1559 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1560 * (if a selection group is in force).
1562 sequenceMenu.add(seqShowAnnotationsMenu);
1563 sequenceMenu.add(seqHideAnnotationsMenu);
1564 sequenceMenu.add(seqAddReferenceAnnotations);
1565 groupMenu.add(groupShowAnnotationsMenu);
1566 groupMenu.add(groupHideAnnotationsMenu);
1567 groupMenu.add(groupAddReferenceAnnotations);
1568 groupMenu.add(editMenu);
1569 groupMenu.add(outputMenu);
1570 groupMenu.add(sequenceFeature);
1571 groupMenu.add(createGroupMenuItem);
1572 groupMenu.add(unGroupMenuItem);
1573 groupMenu.add(jMenu1);
1574 sequenceMenu.add(sequenceName);
1575 sequenceMenu.add(sequenceDetails);
1576 sequenceMenu.add(makeReferenceSeq);
1577 colourMenu.add(textColour);
1578 colourMenu.add(noColourmenuItem);
1579 colourMenu.add(clustalColour);
1580 colourMenu.add(BLOSUM62Colour);
1581 colourMenu.add(PIDColour);
1582 colourMenu.add(zappoColour);
1583 colourMenu.add(taylorColour);
1584 colourMenu.add(hydrophobicityColour);
1585 colourMenu.add(helixColour);
1586 colourMenu.add(strandColour);
1587 colourMenu.add(turnColour);
1588 colourMenu.add(buriedColour);
1589 colourMenu.add(nucleotideMenuItem);
1590 if (ap.getAlignment().isNucleotide())
1592 // JBPNote - commented since the colourscheme isn't functional
1593 // colourMenu.add(RNAInteractionColour);
1594 colourMenu.add(purinePyrimidineColour);
1596 // colourMenu.add(covariationColour);
1597 colourMenu.add(userDefinedColour);
1599 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1601 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1602 .getUserColourSchemes().keys();
1604 while (userColours.hasMoreElements())
1606 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1607 item.addActionListener(new ActionListener()
1610 public void actionPerformed(ActionEvent evt)
1612 userDefinedColour_actionPerformed(evt);
1615 colourMenu.add(item);
1619 colourMenu.addSeparator();
1620 colourMenu.add(abovePIDColour);
1621 colourMenu.add(conservationMenuItem);
1622 // colourMenu.add(annotationMenuItem);
1625 editMenu.add(editSequence);
1626 editMenu.add(upperCase);
1627 editMenu.add(lowerCase);
1628 editMenu.add(toggle);
1629 pdbMenu.add(pdbFromFile);
1630 // JBPNote: These shouldn't be added here - should appear in a generic
1631 // 'apply web service to this sequence menu'
1632 // pdbMenu.add(RNAFold);
1633 // pdbMenu.add(ContraFold);
1634 pdbMenu.add(enterPDB);
1635 pdbMenu.add(discoverPDB);
1636 jMenu1.add(groupName);
1637 jMenu1.add(colourMenu);
1638 jMenu1.add(showBoxes);
1639 jMenu1.add(showText);
1640 jMenu1.add(showColourText);
1641 jMenu1.add(outline);
1642 jMenu1.add(displayNonconserved);
1643 structureMenu.add(pdbMenu);
1644 structureMenu.add(viewStructureMenu);
1645 // structureMenu.add(colStructureMenu);
1646 noColourmenuItem.setText(MessageManager.getString("label.none"));
1647 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1650 public void actionPerformed(ActionEvent e)
1652 noColourmenuItem_actionPerformed();
1656 clustalColour.setText(MessageManager
1657 .getString("label.clustalx_colours"));
1658 clustalColour.addActionListener(new java.awt.event.ActionListener()
1661 public void actionPerformed(ActionEvent e)
1663 clustalColour_actionPerformed();
1666 zappoColour.setText(MessageManager.getString("label.zappo"));
1667 zappoColour.addActionListener(new java.awt.event.ActionListener()
1670 public void actionPerformed(ActionEvent e)
1672 zappoColour_actionPerformed();
1675 taylorColour.setText(MessageManager.getString("label.taylor"));
1676 taylorColour.addActionListener(new java.awt.event.ActionListener()
1679 public void actionPerformed(ActionEvent e)
1681 taylorColour_actionPerformed();
1684 hydrophobicityColour.setText(MessageManager
1685 .getString("label.hydrophobicity"));
1686 hydrophobicityColour
1687 .addActionListener(new java.awt.event.ActionListener()
1690 public void actionPerformed(ActionEvent e)
1692 hydrophobicityColour_actionPerformed();
1695 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1696 helixColour.addActionListener(new java.awt.event.ActionListener()
1699 public void actionPerformed(ActionEvent e)
1701 helixColour_actionPerformed();
1704 strandColour.setText(MessageManager
1705 .getString("label.strand_propensity"));
1706 strandColour.addActionListener(new java.awt.event.ActionListener()
1709 public void actionPerformed(ActionEvent e)
1711 strandColour_actionPerformed();
1714 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1715 turnColour.addActionListener(new java.awt.event.ActionListener()
1718 public void actionPerformed(ActionEvent e)
1720 turnColour_actionPerformed();
1723 buriedColour.setText(MessageManager.getString("label.buried_index"));
1724 buriedColour.addActionListener(new java.awt.event.ActionListener()
1727 public void actionPerformed(ActionEvent e)
1729 buriedColour_actionPerformed();
1732 abovePIDColour.setText(MessageManager
1733 .getString("label.above_identity_percentage"));
1734 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1737 public void actionPerformed(ActionEvent e)
1739 abovePIDColour_actionPerformed();
1742 userDefinedColour.setText(MessageManager
1743 .getString("action.user_defined"));
1744 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1747 public void actionPerformed(ActionEvent e)
1749 userDefinedColour_actionPerformed(e);
1753 .setText(MessageManager.getString("label.percentage_identity"));
1754 PIDColour.addActionListener(new java.awt.event.ActionListener()
1757 public void actionPerformed(ActionEvent e)
1759 PIDColour_actionPerformed();
1762 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1763 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1766 public void actionPerformed(ActionEvent e)
1768 BLOSUM62Colour_actionPerformed();
1771 purinePyrimidineColour.setText(MessageManager
1772 .getString("label.purine_pyrimidine"));
1773 purinePyrimidineColour
1774 .addActionListener(new java.awt.event.ActionListener()
1777 public void actionPerformed(ActionEvent e)
1779 purinePyrimidineColour_actionPerformed();
1784 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1785 * public void actionPerformed(ActionEvent e) {
1786 * covariationColour_actionPerformed(); } });
1789 conservationMenuItem.setText(MessageManager
1790 .getString("label.conservation"));
1791 conservationMenuItem
1792 .addActionListener(new java.awt.event.ActionListener()
1795 public void actionPerformed(ActionEvent e)
1797 conservationMenuItem_actionPerformed();
1803 * Check for any annotations on the underlying dataset sequences (for the
1804 * current selection group) which are not 'on the alignment'.If any are found,
1805 * enable the option to add them to the alignment. The criteria for 'on the
1806 * alignment' is finding an alignment annotation on the alignment, matched on
1807 * calcId, label and sequenceRef.
1809 * A tooltip is also constructed that displays the source (calcId) and type
1810 * (label) of the annotations that can be added.
1813 * @param forSequences
1815 protected void configureReferenceAnnotationsMenu(
1816 JMenuItem menuItem, List<SequenceI> forSequences)
1818 menuItem.setText(MessageManager
1819 .getString("label.add_reference_annotations"));
1820 menuItem.setEnabled(false);
1821 if (forSequences == null)
1827 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1828 * Using TreeMap means calcIds are shown in alphabetical order.
1830 Map<String, String> tipEntries = new TreeMap<String, String>();
1831 StringBuilder tooltip = new StringBuilder(64);
1832 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1835 * For each sequence selected in the alignment, make a list of any
1836 * annotations on the underlying dataset sequence which are not already on
1839 * Build a map of { alignmentSequence, <List of annotations to add> }
1841 AlignmentI al = this.ap.av.getAlignment();
1842 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1843 for (SequenceI seq : forSequences)
1845 SequenceI dataset = seq.getDatasetSequence();
1846 if (dataset == null)
1850 AlignmentAnnotation[] datasetAnnotations = dataset.getAnnotation();
1851 if (datasetAnnotations == null)
1855 final List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1856 for (AlignmentAnnotation dsann : datasetAnnotations)
1859 * Find matching annotations on the alignment.
1861 final Iterable<AlignmentAnnotation> matchedAlignmentAnnotations = al
1862 .findAnnotations(seq, dsann.getCalcId(),
1864 if (!matchedAlignmentAnnotations.iterator().hasNext())
1867 tipEntries.put(dsann.getCalcId(), dsann.label);
1871 * Save any addable annotations for this sequence
1873 if (!result.isEmpty())
1875 candidates.put(seq, result);
1878 if (!candidates.isEmpty())
1881 * Found annotations that could be added. Enable the menu item, and
1882 * configure its tooltip and action.
1884 menuItem.setEnabled(true);
1885 for (String calcId : tipEntries.keySet())
1887 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1889 String tooltipText = JvSwingUtils.wrapTooltip(true,
1890 tooltip.toString());
1891 menuItem.setToolTipText(tooltipText);
1893 menuItem.addActionListener(new ActionListener()
1896 public void actionPerformed(ActionEvent e)
1898 addReferenceAnnotations_actionPerformed(candidates);
1905 * Add annotations to the sequences and to the alignment.
1908 * a map whose keys are sequences on the alignment, and values a list
1909 * of annotations to add to each sequence
1911 protected void addReferenceAnnotations_actionPerformed(
1912 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1915 * Add annotations at the top of the annotation, in the same order as their
1916 * related sequences.
1918 for (SequenceI seq : candidates.keySet())
1920 for (AlignmentAnnotation ann : candidates.get(seq))
1922 AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann);
1924 int endRes = ann.annotations.length;
1925 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1926 if (selectionGroup != null)
1928 startRes = selectionGroup.getStartRes();
1929 endRes = selectionGroup.getEndRes();
1931 copyAnn.restrict(startRes, endRes);
1934 * Add to the sequence (sets copyAnn.datasetSequence), unless the
1935 * original annotation is already on the sequence.
1937 if (!seq.hasAnnotation(ann))
1939 seq.addAlignmentAnnotation(copyAnn);
1942 copyAnn.adjustForAlignment();
1943 // add to the alignment and set visible
1944 this.ap.getAlignment().addAnnotation(copyAnn);
1945 copyAnn.visible = true;
1951 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1953 if (!ap.av.getAlignment().hasSeqrep())
1955 // initialise the display flags so the user sees something happen
1956 ap.av.setDisplayReferenceSeq(true);
1957 ap.av.setColourByReferenceSeq(true);
1958 ap.av.getAlignment().setSeqrep(sequence);
1962 if (ap.av.getAlignment().getSeqrep() == sequence)
1964 ap.av.getAlignment().setSeqrep(null);
1968 ap.av.getAlignment().setSeqrep(sequence);
1974 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1976 if (sequence != null)
1978 ColumnSelection cs = ap.av.getColumnSelection();
1981 cs = new ColumnSelection();
1983 cs.hideInsertionsFor(sequence);
1984 ap.av.setColumnSelection(cs);
1988 protected void sequenceSelectionDetails_actionPerformed()
1990 createSequenceDetailsReport(ap.av.getSequenceSelection());
1993 protected void sequenceDetails_actionPerformed()
1995 createSequenceDetailsReport(new SequenceI[]
1999 public void createSequenceDetailsReport(SequenceI[] sequences)
2001 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
2002 StringBuffer contents = new StringBuffer();
2003 for (SequenceI seq : sequences)
2005 contents.append("<p><h2>"
2008 "label.create_sequence_details_report_annotation_for",
2010 { seq.getDisplayId(true) }) + "</h2></p><p>");
2011 new SequenceAnnotationReport(null)
2012 .createSequenceAnnotationReport(
2018 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
2019 .getSeqPanel().seqCanvas.fr
2022 contents.append("</p>");
2024 cap.setText("<html>" + contents.toString() + "</html>");
2026 Desktop.instance.addInternalFrame(cap, MessageManager.formatMessage(
2027 "label.sequece_details_for",
2028 (sequences.length == 1 ? new String[]
2029 { sequences[0].getDisplayId(true) } : new String[]
2030 { MessageManager.getString("label.selection") })), 500, 400);
2034 protected void showNonconserved_actionPerformed()
2036 getGroup().setShowNonconserved(displayNonconserved.isSelected());
2041 * call to refresh view after settings change
2045 ap.updateAnnotation();
2046 ap.paintAlignment(true);
2048 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
2057 protected void clustalColour_actionPerformed()
2059 SequenceGroup sg = getGroup();
2060 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
2070 protected void zappoColour_actionPerformed()
2072 getGroup().cs = new ZappoColourScheme();
2082 protected void taylorColour_actionPerformed()
2084 getGroup().cs = new TaylorColourScheme();
2094 protected void hydrophobicityColour_actionPerformed()
2096 getGroup().cs = new HydrophobicColourScheme();
2106 protected void helixColour_actionPerformed()
2108 getGroup().cs = new HelixColourScheme();
2118 protected void strandColour_actionPerformed()
2120 getGroup().cs = new StrandColourScheme();
2130 protected void turnColour_actionPerformed()
2132 getGroup().cs = new TurnColourScheme();
2142 protected void buriedColour_actionPerformed()
2144 getGroup().cs = new BuriedColourScheme();
2154 public void nucleotideMenuItem_actionPerformed()
2156 getGroup().cs = new NucleotideColourScheme();
2160 protected void purinePyrimidineColour_actionPerformed()
2162 getGroup().cs = new PurinePyrimidineColourScheme();
2167 * protected void covariationColour_actionPerformed() { getGroup().cs = new
2168 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
2176 protected void abovePIDColour_actionPerformed()
2178 SequenceGroup sg = getGroup();
2184 if (abovePIDColour.isSelected())
2186 sg.cs.setConsensus(AAFrequency.calculate(
2187 sg.getSequences(ap.av.getHiddenRepSequences()),
2188 sg.getStartRes(), sg.getEndRes() + 1));
2190 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
2193 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
2195 SliderPanel.showPIDSlider();
2198 // remove PIDColouring
2200 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
2212 protected void userDefinedColour_actionPerformed(ActionEvent e)
2214 SequenceGroup sg = getGroup();
2216 if (e.getSource().equals(userDefinedColour))
2218 new UserDefinedColours(ap, sg);
2222 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2223 .getUserColourSchemes().get(e.getActionCommand());
2231 * Open a panel where the user can choose which types of sequence annotation
2236 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2238 // todo correct way to guard against opening a duplicate panel?
2239 new AnnotationChooser(ap);
2248 protected void PIDColour_actionPerformed()
2250 SequenceGroup sg = getGroup();
2251 sg.cs = new PIDColourScheme();
2252 sg.cs.setConsensus(AAFrequency.calculate(
2253 sg.getSequences(ap.av.getHiddenRepSequences()),
2254 sg.getStartRes(), sg.getEndRes() + 1));
2264 protected void BLOSUM62Colour_actionPerformed()
2266 SequenceGroup sg = getGroup();
2268 sg.cs = new Blosum62ColourScheme();
2270 sg.cs.setConsensus(AAFrequency.calculate(
2271 sg.getSequences(ap.av.getHiddenRepSequences()),
2272 sg.getStartRes(), sg.getEndRes() + 1));
2283 protected void noColourmenuItem_actionPerformed()
2285 getGroup().cs = null;
2295 protected void conservationMenuItem_actionPerformed()
2297 SequenceGroup sg = getGroup();
2303 if (conservationMenuItem.isSelected())
2305 // JBPNote: Conservation name shouldn't be i18n translated
2306 Conservation c = new Conservation("Group",
2307 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2308 .getHiddenRepSequences()), sg.getStartRes(),
2309 sg.getEndRes() + 1);
2312 c.verdict(false, ap.av.getConsPercGaps());
2314 sg.cs.setConservation(c);
2316 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2317 SliderPanel.showConservationSlider();
2320 // remove ConservationColouring
2322 sg.cs.setConservation(null);
2328 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2330 SequenceGroup sg = getGroup();
2336 AnnotationColourGradient acg = new AnnotationColourGradient(
2337 sequence.getAnnotation()[0], null,
2338 AnnotationColourGradient.NO_THRESHOLD);
2340 acg.setPredefinedColours(true);
2352 protected void groupName_actionPerformed()
2355 SequenceGroup sg = getGroup();
2356 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2357 sg.getDescription(), " "
2358 + MessageManager.getString("label.group_name") + " ",
2359 MessageManager.getString("label.group_description") + " ",
2360 MessageManager.getString("label.edit_group_name_description"),
2368 sg.setName(dialog.getName());
2369 sg.setDescription(dialog.getDescription());
2374 * Get selection group - adding it to the alignment if necessary.
2376 * @return sequence group to operate on
2378 SequenceGroup getGroup()
2380 SequenceGroup sg = ap.av.getSelectionGroup();
2381 // this method won't add a new group if it already exists
2384 ap.av.getAlignment().addGroup(sg);
2396 void sequenceName_actionPerformed()
2398 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2399 sequence.getDescription(),
2400 " " + MessageManager.getString("label.sequence_name")
2402 MessageManager.getString("label.sequence_description") + " ",
2404 .getString("label.edit_sequence_name_description"),
2412 if (dialog.getName() != null)
2414 if (dialog.getName().indexOf(" ") > -1)
2420 .getString("label.spaces_converted_to_backslashes"),
2422 .getString("label.no_spaces_allowed_sequence_name"),
2423 JOptionPane.WARNING_MESSAGE);
2426 sequence.setName(dialog.getName().replace(' ', '_'));
2427 ap.paintAlignment(false);
2430 sequence.setDescription(dialog.getDescription());
2432 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2443 void unGroupMenuItem_actionPerformed()
2445 SequenceGroup sg = ap.av.getSelectionGroup();
2446 ap.av.getAlignment().deleteGroup(sg);
2447 ap.av.setSelectionGroup(null);
2451 void createGroupMenuItem_actionPerformed()
2453 getGroup(); // implicitly creates group - note - should apply defaults / use
2454 // standard alignment window logic for this
2464 protected void outline_actionPerformed()
2466 SequenceGroup sg = getGroup();
2467 Color col = JColorChooser.showDialog(this,
2468 MessageManager.getString("label.select_outline_colour"),
2473 sg.setOutlineColour(col);
2485 public void showBoxes_actionPerformed()
2487 getGroup().setDisplayBoxes(showBoxes.isSelected());
2497 public void showText_actionPerformed()
2499 getGroup().setDisplayText(showText.isSelected());
2509 public void showColourText_actionPerformed()
2511 getGroup().setColourText(showColourText.isSelected());
2515 public void showLink(String url)
2519 jalview.util.BrowserLauncher.openURL(url);
2520 } catch (Exception ex)
2522 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2523 MessageManager.getString("label.web_browser_not_found_unix"),
2524 MessageManager.getString("label.web_browser_not_found"),
2525 JOptionPane.WARNING_MESSAGE);
2527 ex.printStackTrace();
2531 void hideSequences(boolean representGroup)
2533 SequenceGroup sg = ap.av.getSelectionGroup();
2534 if (sg == null || sg.getSize() < 1)
2536 ap.av.hideSequence(new SequenceI[]
2541 ap.av.setSelectionGroup(null);
2545 ap.av.hideRepSequences(sequence, sg);
2550 int gsize = sg.getSize();
2551 SequenceI[] hseqs = sg.getSequences().toArray(new SequenceI[gsize]);
2553 ap.av.hideSequence(hseqs);
2554 // refresh(); TODO: ? needed ?
2555 ap.av.sendSelection();
2558 public void copy_actionPerformed()
2560 ap.alignFrame.copy_actionPerformed(null);
2563 public void cut_actionPerformed()
2565 ap.alignFrame.cut_actionPerformed(null);
2568 void changeCase(ActionEvent e)
2570 Object source = e.getSource();
2571 SequenceGroup sg = ap.av.getSelectionGroup();
2575 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2577 sg.getEndRes() + 1);
2582 if (source == toggle)
2584 description = MessageManager.getString("label.toggle_case");
2585 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2587 else if (source == upperCase)
2589 description = MessageManager.getString("label.to_upper_case");
2590 caseChange = ChangeCaseCommand.TO_UPPER;
2594 description = MessageManager.getString("label.to_lower_case");
2595 caseChange = ChangeCaseCommand.TO_LOWER;
2598 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2599 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2600 startEnd, caseChange);
2602 ap.alignFrame.addHistoryItem(caseCommand);
2604 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2610 public void outputText_actionPerformed(ActionEvent e)
2612 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2613 cap.setForInput(null);
2614 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2615 "label.alignment_output_command", new String[]
2616 { e.getActionCommand() }), 600, 500);
2618 String[] omitHidden = null;
2620 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2621 // or we simply trust the user wants
2622 // wysiwig behaviour
2624 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
2628 public void pdbFromFile_actionPerformed()
2630 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2631 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2632 chooser.setFileView(new jalview.io.JalviewFileView());
2633 chooser.setDialogTitle(MessageManager.formatMessage(
2634 "label.select_pdb_file_for", new String[]
2635 { sequence.getDisplayId(false) }));
2636 chooser.setToolTipText(MessageManager.formatMessage(
2637 "label.load_pdb_file_associate_with_sequence", new String[]
2638 { sequence.getDisplayId(false) }));
2640 int value = chooser.showOpenDialog(null);
2642 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2644 String choice = chooser.getSelectedFile().getPath();
2645 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2646 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2647 jalview.io.AppletFormatAdapter.FILE, sequence, true,
2653 // JBNote: commented out - these won't be instantiated here...!
2654 // public void RNAFold_actionPerformed() throws Exception
2656 // Predict2D P2D = new Predict2D();
2657 // P2D.getStructure2DFromRNAFold("toto");
2660 // public void ContraFold_actionPerformed() throws Exception
2662 // Predict2D P2D = new Predict2D();
2663 // P2D.getStructure2DFromContraFold("toto");
2665 public void enterPDB_actionPerformed()
2667 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2668 MessageManager.getString("label.enter_pdb_id"),
2669 MessageManager.getString("label.enter_pdb_id"),
2670 JOptionPane.QUESTION_MESSAGE);
2672 if (id != null && id.length() > 0)
2674 PDBEntry entry = new PDBEntry();
2675 entry.setId(id.toUpperCase());
2676 sequence.getDatasetSequence().addPDBId(entry);
2680 public void discoverPDB_actionPerformed()
2683 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2685 : ap.av.getSequenceSelection());
2686 Thread discpdb = new Thread(new Runnable()
2692 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2693 .fetchDBRefs(false);
2700 public void sequenceFeature_actionPerformed()
2702 SequenceGroup sg = ap.av.getSelectionGroup();
2708 int rsize = 0, gSize = sg.getSize();
2709 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2710 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2712 for (int i = 0; i < gSize; i++)
2714 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2715 int end = sg.findEndRes(sg.getSequenceAt(i));
2718 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2719 features[rsize] = new SequenceFeature(null, null, null, start, end,
2724 rseqs = new SequenceI[rsize];
2725 tfeatures = new SequenceFeature[rsize];
2726 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2727 System.arraycopy(features, 0, tfeatures, 0, rsize);
2728 features = tfeatures;
2730 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2731 features, true, ap))
2733 ap.alignFrame.setShowSeqFeatures(true);
2734 ap.highlightSearchResults(null);
2738 public void textColour_actionPerformed()
2740 SequenceGroup sg = getGroup();
2743 new TextColourChooser().chooseColour(ap, sg);
2747 public void colourByStructure(String pdbid)
2749 Annotation[] anots = ap.av.getStructureSelectionManager()
2750 .colourSequenceFromStructure(sequence, pdbid);
2752 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2753 "Coloured by " + pdbid, anots);
2755 ap.av.getAlignment().addAnnotation(an);
2756 an.createSequenceMapping(sequence, 0, true);
2757 // an.adjustForAlignment();
2758 ap.av.getAlignment().setAnnotationIndex(an, 0);
2760 ap.adjustAnnotationHeight();
2762 sequence.addAlignmentAnnotation(an);
2766 public void editSequence_actionPerformed(ActionEvent actionEvent)
2768 SequenceGroup sg = ap.av.getSelectionGroup();
2772 if (sequence == null)
2774 sequence = sg.getSequenceAt(0);
2777 EditNameDialog dialog = new EditNameDialog(
2778 sequence.getSequenceAsString(sg.getStartRes(),
2779 sg.getEndRes() + 1), null,
2780 MessageManager.getString("label.edit_sequence"), null,
2781 MessageManager.getString("label.edit_sequence"),
2786 EditCommand editCommand = new EditCommand(
2787 MessageManager.getString("label.edit_sequences"),
2788 Action.REPLACE, dialog.getName().replace(' ',
2789 ap.av.getGapCharacter()),
2790 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2791 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2793 ap.alignFrame.addHistoryItem(editCommand);
2795 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()