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.ArrayList;
27 import java.util.Arrays;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.Hashtable;
31 import java.util.LinkedHashMap;
32 import java.util.List;
34 import java.util.TreeMap;
35 import java.util.Vector;
37 import javax.swing.ButtonGroup;
38 import javax.swing.JCheckBoxMenuItem;
39 import javax.swing.JColorChooser;
40 import javax.swing.JMenu;
41 import javax.swing.JMenuItem;
42 import javax.swing.JOptionPane;
43 import javax.swing.JPopupMenu;
44 import javax.swing.JRadioButtonMenuItem;
46 import jalview.analysis.AAFrequency;
47 import jalview.analysis.AlignmentAnnotationUtils;
48 import jalview.analysis.Conservation;
49 import jalview.commands.ChangeCaseCommand;
50 import jalview.commands.EditCommand;
51 import jalview.commands.EditCommand.Action;
52 import jalview.datamodel.AlignmentAnnotation;
53 import jalview.datamodel.AlignmentI;
54 import jalview.datamodel.Annotation;
55 import jalview.datamodel.ColumnSelection;
56 import jalview.datamodel.DBRefEntry;
57 import jalview.datamodel.PDBEntry;
58 import jalview.datamodel.Sequence;
59 import jalview.datamodel.SequenceFeature;
60 import jalview.datamodel.SequenceGroup;
61 import jalview.datamodel.SequenceI;
62 import jalview.io.FormatAdapter;
63 import jalview.io.SequenceAnnotationReport;
64 import jalview.schemes.AnnotationColourGradient;
65 import jalview.schemes.Blosum62ColourScheme;
66 import jalview.schemes.BuriedColourScheme;
67 import jalview.schemes.ClustalxColourScheme;
68 import jalview.schemes.HelixColourScheme;
69 import jalview.schemes.HydrophobicColourScheme;
70 import jalview.schemes.NucleotideColourScheme;
71 import jalview.schemes.PIDColourScheme;
72 import jalview.schemes.PurinePyrimidineColourScheme;
73 import jalview.schemes.ResidueProperties;
74 import jalview.schemes.StrandColourScheme;
75 import jalview.schemes.TaylorColourScheme;
76 import jalview.schemes.TurnColourScheme;
77 import jalview.schemes.UserColourScheme;
78 import jalview.schemes.ZappoColourScheme;
79 import jalview.util.GroupUrlLink;
80 import jalview.util.GroupUrlLink.UrlStringTooLongException;
81 import jalview.util.MessageManager;
82 import jalview.util.UrlLink;
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 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
130 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
134 JMenu sequenceMenu = new JMenu();
136 JMenuItem sequenceName = new JMenuItem();
138 JMenuItem sequenceDetails = new JMenuItem();
140 JMenuItem sequenceSelDetails = new JMenuItem();
142 JMenuItem makeReferenceSeq = new JMenuItem();
144 JMenuItem chooseAnnotations = new JMenuItem();
148 JMenuItem createGroupMenuItem = new JMenuItem();
150 JMenuItem unGroupMenuItem = new JMenuItem();
152 JMenuItem outline = new JMenuItem();
154 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
156 JMenu colourMenu = new JMenu();
158 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
160 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
162 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
164 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
166 JMenu editMenu = new JMenu();
168 JMenuItem cut = new JMenuItem();
170 JMenuItem copy = new JMenuItem();
172 JMenuItem upperCase = new JMenuItem();
174 JMenuItem lowerCase = new JMenuItem();
176 JMenuItem toggle = new JMenuItem();
178 JMenu pdbMenu = new JMenu();
180 JMenuItem pdbFromFile = new JMenuItem();
182 JMenuItem enterPDB = new JMenuItem();
184 JMenuItem discoverPDB = new JMenuItem();
186 JMenu outputMenu = new JMenu();
188 JMenu seqShowAnnotationsMenu = new JMenu();
190 JMenu seqHideAnnotationsMenu = new JMenu();
192 JMenuItem seqAddReferenceAnnotations = new JMenuItem();
194 JMenu groupShowAnnotationsMenu = new JMenu();
196 JMenu groupHideAnnotationsMenu = new JMenu();
198 JMenuItem groupAddReferenceAnnotations = new JMenuItem();
200 JMenuItem sequenceFeature = new JMenuItem();
202 JMenuItem textColour = new JMenuItem();
204 JMenu jMenu1 = new JMenu();
206 JMenuItem structureMenu = new JMenuItem();
208 JMenu viewStructureMenu = new JMenu();
210 JMenuItem editSequence = new JMenuItem();
212 JMenu groupLinksMenu;
214 JMenuItem hideInsertions = new JMenuItem();
217 * Creates a new PopupMenu object.
224 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
226 this(ap, seq, links, null);
236 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
237 Vector links, Vector groupLinks)
239 // /////////////////////////////////////////////////////////
240 // If this is activated from the sequence panel, the user may want to
241 // edit or annotate a particular residue. Therefore display the residue menu
243 // If from the IDPanel, we must display the sequence menu
244 // ////////////////////////////////////////////////////////
248 ButtonGroup colours = new ButtonGroup();
249 colours.add(noColourmenuItem);
250 colours.add(clustalColour);
251 colours.add(zappoColour);
252 colours.add(taylorColour);
253 colours.add(hydrophobicityColour);
254 colours.add(helixColour);
255 colours.add(strandColour);
256 colours.add(turnColour);
257 colours.add(buriedColour);
258 colours.add(abovePIDColour);
259 colours.add(userDefinedColour);
260 colours.add(PIDColour);
261 colours.add(BLOSUM62Colour);
262 colours.add(purinePyrimidineColour);
263 colours.add(RNAInteractionColour);
265 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
267 JMenuItem item = new JMenuItem(
268 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
270 item.addActionListener(new java.awt.event.ActionListener()
273 public void actionPerformed(ActionEvent e)
275 outputText_actionPerformed(e);
279 outputMenu.add(item);
283 * Build menus for annotation types that may be shown or hidden, and for
284 * 'reference annotations' that may be added to the alignment. First for the
285 * currently selected sequence (if there is one):
287 final List<SequenceI> selectedSequence = (seq == null ? Collections
288 .<SequenceI> emptyList() : Arrays.asList(seq));
289 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
290 seqHideAnnotationsMenu, selectedSequence);
291 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
295 * And repeat for the current selection group (if there is one):
297 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
298 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
300 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
301 groupHideAnnotationsMenu, selectedGroup);
302 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
308 } catch (Exception e)
316 sequenceMenu.setText(sequence.getName());
317 if (seq == ap.av.getAlignment().getSeqrep())
319 makeReferenceSeq.setText("Unmark representative");
321 makeReferenceSeq.setText("Mark as representative");
324 if (seq.getDatasetSequence().getPDBId() != null
325 && seq.getDatasetSequence().getPDBId().size() > 0)
327 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
330 while (e.hasMoreElements())
332 final PDBEntry pdb = (PDBEntry) e.nextElement();
334 menuItem = new JMenuItem();
335 menuItem.setText(pdb.getId());
336 menuItem.addActionListener(new ActionListener()
339 public void actionPerformed(ActionEvent e)
341 // TODO re JAL-860: optionally open dialog or provide a menu entry
342 // allowing user to open just one structure per sequence
343 // new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
344 // { pdb })[0], null, ap);
345 new StructureViewer(ap.getStructureSelectionManager())
347 ap.av.collateForPDB(new PDBEntry[]
348 { pdb })[0], null, ap);
351 viewStructureMenu.add(menuItem);
354 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
355 * menuItem.addActionListener(new java.awt.event.ActionListener() {
356 * public void actionPerformed(ActionEvent e) {
357 * colourByStructure(pdb.getId()); } });
358 * colStructureMenu.add(menuItem);
364 if (ap.av.getAlignment().isNucleotide() == false)
366 structureMenu.remove(viewStructureMenu);
369 if (ap.av.getAlignment().isNucleotide() == true)
371 AlignmentAnnotation[] aa = ap.av.getAlignment()
372 .getAlignmentAnnotation();
373 for (int i = 0; aa != null && i < aa.length; i++)
375 if (aa[i].isValidStruc() && aa[i].sequenceRef == null)
377 final String rnastruc = aa[i].getRNAStruc();
378 final String structureLine = aa[i].label + " (alignment)";
379 menuItem = new JMenuItem();
380 menuItem.setText(MessageManager.formatMessage(
381 "label.2d_rna_structure_line", new Object[]
383 menuItem.addActionListener(new java.awt.event.ActionListener()
386 public void actionPerformed(ActionEvent e)
388 new AppVarna(structureLine, seq, seq.getSequenceAsString(),
389 rnastruc, seq.getName(), ap);
390 System.out.println("end");
393 viewStructureMenu.add(menuItem);
398 if (seq.getAnnotation() != null)
400 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
401 for (int i = 0; i < seqAnno.length; i++)
403 if (seqAnno[i].isValidStruc())
405 final String rnastruc = seqAnno[i].getRNAStruc();
407 // TODO: make rnastrucF a bit more nice
408 menuItem = new JMenuItem();
409 menuItem.setText(MessageManager.formatMessage(
410 "label.2d_rna_sequence_name", new Object[]
412 menuItem.addActionListener(new java.awt.event.ActionListener()
415 public void actionPerformed(ActionEvent e)
417 // TODO: VARNA does'nt print gaps in the sequence
419 new AppVarna(seq.getName() + " structure", seq, seq
420 .getSequenceAsString(), rnastruc, seq.getName(),
424 viewStructureMenu.add(menuItem);
430 menuItem = new JMenuItem(
431 MessageManager.getString("action.hide_sequences"));
432 menuItem.addActionListener(new java.awt.event.ActionListener()
435 public void actionPerformed(ActionEvent e)
437 hideSequences(false);
442 if (ap.av.getSelectionGroup() != null
443 && ap.av.getSelectionGroup().getSize() > 1)
445 menuItem = new JMenuItem(MessageManager.formatMessage(
446 "label.represent_group_with", new Object[]
448 menuItem.addActionListener(new java.awt.event.ActionListener()
451 public void actionPerformed(ActionEvent e)
456 sequenceMenu.add(menuItem);
459 if (ap.av.hasHiddenRows())
461 final int index = ap.av.getAlignment().findIndex(seq);
463 if (ap.av.adjustForHiddenSeqs(index)
464 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
466 menuItem = new JMenuItem(
467 MessageManager.getString("action.reveal_sequences"));
468 menuItem.addActionListener(new ActionListener()
471 public void actionPerformed(ActionEvent e)
473 ap.av.showSequence(index);
474 if (ap.overviewPanel != null)
476 ap.overviewPanel.updateOverviewImage();
484 // for the case when no sequences are even visible
485 if (ap.av.hasHiddenRows())
488 menuItem = new JMenuItem(
489 MessageManager.getString("action.reveal_all"));
490 menuItem.addActionListener(new ActionListener()
493 public void actionPerformed(ActionEvent e)
495 ap.av.showAllHiddenSeqs();
496 if (ap.overviewPanel != null)
498 ap.overviewPanel.updateOverviewImage();
508 SequenceGroup sg = ap.av.getSelectionGroup();
509 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
510 .getGroups().contains(sg) : false;
512 if (sg != null && sg.getSize() > 0)
514 groupName.setText(MessageManager.formatMessage("label.name_param",
517 groupName.setText(MessageManager
518 .getString("label.edit_name_and_description_current_group"));
520 if (sg.cs instanceof ZappoColourScheme)
522 zappoColour.setSelected(true);
524 else if (sg.cs instanceof TaylorColourScheme)
526 taylorColour.setSelected(true);
528 else if (sg.cs instanceof PIDColourScheme)
530 PIDColour.setSelected(true);
532 else if (sg.cs instanceof Blosum62ColourScheme)
534 BLOSUM62Colour.setSelected(true);
536 else if (sg.cs instanceof UserColourScheme)
538 userDefinedColour.setSelected(true);
540 else if (sg.cs instanceof HydrophobicColourScheme)
542 hydrophobicityColour.setSelected(true);
544 else if (sg.cs instanceof HelixColourScheme)
546 helixColour.setSelected(true);
548 else if (sg.cs instanceof StrandColourScheme)
550 strandColour.setSelected(true);
552 else if (sg.cs instanceof TurnColourScheme)
554 turnColour.setSelected(true);
556 else if (sg.cs instanceof BuriedColourScheme)
558 buriedColour.setSelected(true);
560 else if (sg.cs instanceof ClustalxColourScheme)
562 clustalColour.setSelected(true);
564 else if (sg.cs instanceof PurinePyrimidineColourScheme)
566 purinePyrimidineColour.setSelected(true);
570 * else if (sg.cs instanceof CovariationColourScheme) {
571 * covariationColour.setSelected(true); }
575 noColourmenuItem.setSelected(true);
578 if (sg.cs != null && sg.cs.conservationApplied())
580 conservationMenuItem.setSelected(true);
582 displayNonconserved.setSelected(sg.getShowNonconserved());
583 showText.setSelected(sg.getDisplayText());
584 showColourText.setSelected(sg.getColourText());
585 showBoxes.setSelected(sg.getDisplayBoxes());
586 // add any groupURLs to the groupURL submenu and make it visible
587 if (groupLinks != null && groupLinks.size() > 0)
589 buildGroupURLMenu(sg, groupLinks);
591 // Add a 'show all structures' for the current selection
592 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
593 SequenceI sqass = null;
594 for (SequenceI sq : ap.av.getSequenceSelection())
596 Vector<PDBEntry> pes = sq.getDatasetSequence().getPDBId();
597 if (pes != null && pes.size() > 0)
599 reppdb.put(pes.get(0).getId(), pes.get(0));
600 for (PDBEntry pe : pes)
602 pdbe.put(pe.getId(), pe);
612 final PDBEntry[] pe = pdbe.values().toArray(
613 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
614 new PDBEntry[reppdb.size()]);
615 final JMenuItem gpdbview, rpdbview;
620 groupMenu.setVisible(false);
621 editMenu.setVisible(false);
626 createGroupMenuItem.setVisible(true);
627 unGroupMenuItem.setVisible(false);
628 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
632 createGroupMenuItem.setVisible(false);
633 unGroupMenuItem.setVisible(true);
634 jMenu1.setText(MessageManager.getString("action.edit_group"));
639 sequenceMenu.setVisible(false);
640 structureMenu.setVisible(false);
643 if (links != null && links.size() > 0)
646 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
647 Vector linkset = new Vector();
648 for (int i = 0; i < links.size(); i++)
650 String link = links.elementAt(i).toString();
651 UrlLink urlLink = null;
654 urlLink = new UrlLink(link);
655 } catch (Exception foo)
657 jalview.bin.Cache.log.error("Exception for URLLink '" + link
662 if (!urlLink.isValid())
664 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
667 final String label = urlLink.getLabel();
668 if (seq != null && urlLink.isDynamic())
671 // collect matching db-refs
672 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
673 seq.getDBRef(), new String[]
674 { urlLink.getTarget() });
675 // collect id string too
676 String id = seq.getName();
677 String descr = seq.getDescription();
678 if (descr != null && descr.length() < 1)
685 for (int r = 0; r < dbr.length; r++)
687 if (id != null && dbr[r].getAccessionId().equals(id))
689 // suppress duplicate link creation for the bare sequence ID
690 // string with this link
693 // create Bare ID link for this RUL
694 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
698 for (int u = 0; u < urls.length; u += 2)
700 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
702 linkset.addElement(urls[u] + "|" + urls[u + 1]);
703 addshowLink(linkMenu, label + "|" + urls[u],
712 // create Bare ID link for this RUL
713 String[] urls = urlLink.makeUrls(id, true);
716 for (int u = 0; u < urls.length; u += 2)
718 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
720 linkset.addElement(urls[u] + "|" + urls[u + 1]);
721 addshowLink(linkMenu, label, urls[u + 1]);
726 // Create urls from description but only for URL links which are regex
728 if (descr != null && urlLink.getRegexReplace() != null)
730 // create link for this URL from description where regex matches
731 String[] urls = urlLink.makeUrls(descr, true);
734 for (int u = 0; u < urls.length; u += 2)
736 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
738 linkset.addElement(urls[u] + "|" + urls[u + 1]);
739 addshowLink(linkMenu, label, urls[u + 1]);
747 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
749 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
750 // Add a non-dynamic link
751 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
755 if (sequence != null)
757 sequenceMenu.add(linkMenu);
767 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
768 * "All" is added first, followed by a separator. Then add any annotation
769 * types associated with the current selection. Separate menus are built for
770 * the selected sequence group (if any), and the selected sequence.
772 * Some annotation rows are always rendered together - these can be identified
773 * by a common graphGroup property > -1. Only one of each group will be marked
774 * as visible (to avoid duplication of the display). For such groups we add a
775 * composite type name, e.g.
777 * IUPredWS (Long), IUPredWS (Short)
781 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
782 List<SequenceI> forSequences)
784 showMenu.removeAll();
785 hideMenu.removeAll();
787 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
788 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
789 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
791 showMenu.addSeparator();
792 hideMenu.addSeparator();
794 final AlignmentAnnotation[] annotations = ap.getAlignment()
795 .getAlignmentAnnotation();
798 * Find shown/hidden annotations types, distinguished by source (calcId),
799 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
800 * the insertion order, which is the order of the annotations on the
803 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
804 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
805 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes,
807 AlignmentAnnotationUtils.asList(annotations),
810 for (String calcId : hiddenTypes.keySet())
812 for (List<String> type : hiddenTypes.get(calcId))
814 addAnnotationTypeToShowHide(showMenu, forSequences,
815 calcId, type, false, true);
818 // grey out 'show annotations' if none are hidden
819 showMenu.setEnabled(!hiddenTypes.isEmpty());
821 for (String calcId : shownTypes.keySet())
823 for (List<String> type : shownTypes.get(calcId))
825 addAnnotationTypeToShowHide(hideMenu, forSequences,
826 calcId, type, false, false);
829 // grey out 'hide annotations' if none are shown
830 hideMenu.setEnabled(!shownTypes.isEmpty());
834 * Returns a list of sequences - either the current selection group (if there
835 * is one), else the specified single sequence.
840 protected List<SequenceI> getSequenceScope(SequenceI seq)
842 List<SequenceI> forSequences = null;
843 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
844 if (selectionGroup != null && selectionGroup.getSize() > 0)
846 forSequences = selectionGroup.getSequences();
850 forSequences = seq == null ? Collections.<SequenceI> emptyList()
851 : Arrays.asList(seq);
857 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
860 * @param showOrHideMenu
862 * @param forSequences
863 * the sequences whose annotations may be shown or hidden
868 * if true this is a special label meaning 'All'
869 * @param actionIsShow
870 * if true, the select menu item action is to show the annotation
873 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
874 final List<SequenceI> forSequences, String calcId,
875 final List<String> types, final boolean allTypes,
876 final boolean actionIsShow)
878 String label = types.toString(); // [a, b, c]
879 label = label.substring(1, label.length() - 1);
880 final JMenuItem item = new JMenuItem(label);
881 item.setToolTipText(calcId);
882 item.addActionListener(new java.awt.event.ActionListener()
885 public void actionPerformed(ActionEvent e)
887 showHideAnnotation_actionPerformed(types, forSequences, allTypes,
891 showOrHideMenu.add(item);
895 * Action on selecting a list of annotation type (or the 'all types' values)
896 * to show or hide for the specified sequences.
899 * @param forSequences
903 protected void showHideAnnotation_actionPerformed(
904 Collection<String> types, List<SequenceI> forSequences,
905 boolean anyType, boolean doShow)
907 for (AlignmentAnnotation aa : ap.getAlignment()
908 .getAlignmentAnnotation())
910 if (anyType || types.contains(aa.label))
912 if ((aa.sequenceRef != null)
913 && forSequences.contains(aa.sequenceRef))
922 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
925 // TODO: usability: thread off the generation of group url content so root
927 // sequence only URLs
928 // ID/regex match URLs
929 groupLinksMenu = new JMenu(
930 MessageManager.getString("action.group_link"));
931 JMenu[] linkMenus = new JMenu[]
932 { null, new JMenu(MessageManager.getString("action.ids")),
933 new JMenu(MessageManager.getString("action.sequences")),
934 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
941 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
942 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
943 Hashtable commonDbrefs = new Hashtable();
944 for (int sq = 0; sq < seqs.length; sq++)
947 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
948 .findPosition(sg.getEndRes());
949 // just collect ids from dataset sequence
950 // TODO: check if IDs collected from selecton group intersects with the
951 // current selection, too
952 SequenceI sqi = seqs[sq];
953 while (sqi.getDatasetSequence() != null)
955 sqi = sqi.getDatasetSequence();
957 DBRefEntry[] dbr = sqi.getDBRef();
958 if (dbr != null && dbr.length > 0)
960 for (int d = 0; d < dbr.length; d++)
962 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
963 Object[] sarray = (Object[]) commonDbrefs.get(src);
966 sarray = new Object[2];
967 sarray[0] = new int[]
969 sarray[1] = new String[seqs.length];
971 commonDbrefs.put(src, sarray);
974 if (((String[]) sarray[1])[sq] == null)
977 || (dbr[d].getMap().locateMappedRange(start, end) != null))
979 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
980 ((int[]) sarray[0])[0]++;
986 // now create group links for all distinct ID/sequence sets.
987 boolean addMenu = false; // indicates if there are any group links to give
989 for (int i = 0; i < groupLinks.size(); i++)
991 String link = groupLinks.elementAt(i).toString();
992 GroupUrlLink urlLink = null;
995 urlLink = new GroupUrlLink(link);
996 } catch (Exception foo)
998 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
1003 if (!urlLink.isValid())
1005 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
1008 final String label = urlLink.getLabel();
1009 boolean usingNames = false;
1010 // Now see which parts of the group apply for this URL
1011 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1012 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
1013 String[] seqstr, ids; // input to makeUrl
1016 int numinput = ((int[]) idset[0])[0];
1017 String[] allids = ((String[]) idset[1]);
1018 seqstr = new String[numinput];
1019 ids = new String[numinput];
1020 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1022 if (allids[sq] != null)
1024 ids[idcount] = allids[sq];
1025 seqstr[idcount++] = idandseqs[1][sq];
1031 // just use the id/seq set
1032 seqstr = idandseqs[1];
1036 // and try and make the groupURL!
1038 Object[] urlset = null;
1041 urlset = urlLink.makeUrlStubs(ids, seqstr,
1042 "FromJalview" + System.currentTimeMillis(), false);
1043 } catch (UrlStringTooLongException e)
1048 int type = urlLink.getGroupURLType() & 3;
1049 // first two bits ofurlLink type bitfield are sequenceids and sequences
1050 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1051 addshowLink(linkMenus[type], label
1052 + (((type & 1) == 1) ? ("("
1053 + (usingNames ? "Names" : ltarget) + ")") : ""),
1060 groupLinksMenu = new JMenu(
1061 MessageManager.getString("action.group_link"));
1062 for (int m = 0; m < linkMenus.length; m++)
1064 if (linkMenus[m] != null
1065 && linkMenus[m].getMenuComponentCount() > 0)
1067 groupLinksMenu.add(linkMenus[m]);
1071 groupMenu.add(groupLinksMenu);
1076 * add a show URL menu item to the given linkMenu
1080 * - menu label string
1084 private void addshowLink(JMenu linkMenu, String label, final String url)
1086 JMenuItem item = new JMenuItem(label);
1087 item.setToolTipText(MessageManager.formatMessage(
1088 "label.open_url_param", new Object[]
1090 item.addActionListener(new java.awt.event.ActionListener()
1093 public void actionPerformed(ActionEvent e)
1095 new Thread(new Runnable()
1112 * add a late bound groupURL item to the given linkMenu
1116 * - menu label string
1117 * @param urlgenerator
1118 * GroupURLLink used to generate URL
1120 * Object array returned from the makeUrlStubs function.
1122 private void addshowLink(JMenu linkMenu, String label,
1123 final GroupUrlLink urlgenerator, final Object[] urlstub)
1125 JMenuItem item = new JMenuItem(label);
1126 item.setToolTipText(MessageManager.formatMessage(
1127 "label.open_url_seqs_param",
1129 { urlgenerator.getUrl_prefix(),
1130 urlgenerator.getNumberInvolved(urlstub) }));
1131 // TODO: put in info about what is being sent.
1132 item.addActionListener(new java.awt.event.ActionListener()
1135 public void actionPerformed(ActionEvent e)
1137 new Thread(new Runnable()
1145 showLink(urlgenerator.constructFrom(urlstub));
1146 } catch (UrlStringTooLongException e)
1164 private void jbInit() throws Exception
1166 groupMenu.setText(MessageManager.getString("label.group"));
1167 groupMenu.setText(MessageManager.getString("label.selection"));
1168 groupName.setText(MessageManager.getString("label.name"));
1169 groupName.addActionListener(new java.awt.event.ActionListener()
1172 public void actionPerformed(ActionEvent e)
1174 groupName_actionPerformed();
1177 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1178 sequenceName.setText(MessageManager
1179 .getString("label.edit_name_description"));
1180 sequenceName.addActionListener(new java.awt.event.ActionListener()
1183 public void actionPerformed(ActionEvent e)
1185 sequenceName_actionPerformed();
1188 chooseAnnotations.setText(MessageManager
1189 .getString("label.choose_annotations") + "...");
1190 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1193 public void actionPerformed(ActionEvent e)
1195 chooseAnnotations_actionPerformed(e);
1198 sequenceDetails.setText(MessageManager
1199 .getString("label.sequence_details") + "...");
1200 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1203 public void actionPerformed(ActionEvent e)
1205 sequenceDetails_actionPerformed();
1208 sequenceSelDetails.setText(MessageManager
1209 .getString("label.sequence_details") + "...");
1211 .addActionListener(new java.awt.event.ActionListener()
1214 public void actionPerformed(ActionEvent e)
1216 sequenceSelectionDetails_actionPerformed();
1219 PIDColour.setFocusPainted(false);
1221 .setText(MessageManager.getString("action.remove_group"));
1222 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1225 public void actionPerformed(ActionEvent e)
1227 unGroupMenuItem_actionPerformed();
1230 createGroupMenuItem.setText(MessageManager
1231 .getString("action.create_group"));
1233 .addActionListener(new java.awt.event.ActionListener()
1236 public void actionPerformed(ActionEvent e)
1238 createGroupMenuItem_actionPerformed();
1242 outline.setText(MessageManager.getString("action.border_colour"));
1243 outline.addActionListener(new java.awt.event.ActionListener()
1246 public void actionPerformed(ActionEvent e)
1248 outline_actionPerformed();
1252 .setText(MessageManager.getString("label.nucleotide"));
1253 nucleotideMenuItem.addActionListener(new ActionListener()
1256 public void actionPerformed(ActionEvent e)
1258 nucleotideMenuItem_actionPerformed();
1261 colourMenu.setText(MessageManager.getString("label.group_colour"));
1262 showBoxes.setText(MessageManager.getString("action.boxes"));
1263 showBoxes.setState(true);
1264 showBoxes.addActionListener(new ActionListener()
1267 public void actionPerformed(ActionEvent e)
1269 showBoxes_actionPerformed();
1272 showText.setText(MessageManager.getString("action.text"));
1273 showText.setState(true);
1274 showText.addActionListener(new ActionListener()
1277 public void actionPerformed(ActionEvent e)
1279 showText_actionPerformed();
1282 showColourText.setText(MessageManager.getString("label.colour_text"));
1283 showColourText.addActionListener(new ActionListener()
1286 public void actionPerformed(ActionEvent e)
1288 showColourText_actionPerformed();
1291 displayNonconserved.setText(MessageManager
1292 .getString("label.show_non_conversed"));
1293 displayNonconserved.setState(true);
1294 displayNonconserved.addActionListener(new ActionListener()
1297 public void actionPerformed(ActionEvent e)
1299 showNonconserved_actionPerformed();
1302 editMenu.setText(MessageManager.getString("action.edit"));
1303 cut.setText(MessageManager.getString("action.cut"));
1304 cut.addActionListener(new ActionListener()
1307 public void actionPerformed(ActionEvent e)
1309 cut_actionPerformed();
1312 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1313 upperCase.addActionListener(new ActionListener()
1316 public void actionPerformed(ActionEvent e)
1321 copy.setText(MessageManager.getString("action.copy"));
1322 copy.addActionListener(new ActionListener()
1325 public void actionPerformed(ActionEvent e)
1327 copy_actionPerformed();
1330 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1331 lowerCase.addActionListener(new ActionListener()
1334 public void actionPerformed(ActionEvent e)
1339 toggle.setText(MessageManager.getString("label.toggle_case"));
1340 toggle.addActionListener(new ActionListener()
1343 public void actionPerformed(ActionEvent e)
1348 pdbMenu.setText(MessageManager
1349 .getString("label.associate_structure_with_sequence"));
1350 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1351 pdbFromFile.addActionListener(new ActionListener()
1354 public void actionPerformed(ActionEvent e)
1356 pdbFromFile_actionPerformed();
1360 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1361 enterPDB.addActionListener(new ActionListener()
1364 public void actionPerformed(ActionEvent e)
1366 enterPDB_actionPerformed();
1369 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1370 discoverPDB.addActionListener(new ActionListener()
1373 public void actionPerformed(ActionEvent e)
1375 discoverPDB_actionPerformed();
1378 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1380 seqShowAnnotationsMenu.setText(MessageManager
1381 .getString("label.show_annotations"));
1382 seqHideAnnotationsMenu.setText(MessageManager
1383 .getString("label.hide_annotations"));
1384 groupShowAnnotationsMenu.setText(MessageManager
1385 .getString("label.show_annotations"));
1386 groupHideAnnotationsMenu.setText(MessageManager
1387 .getString("label.hide_annotations"));
1388 sequenceFeature.setText(MessageManager
1389 .getString("label.create_sequence_feature"));
1390 sequenceFeature.addActionListener(new ActionListener()
1393 public void actionPerformed(ActionEvent e)
1395 sequenceFeature_actionPerformed();
1398 textColour.setText(MessageManager.getString("label.text_colour"));
1399 textColour.addActionListener(new ActionListener()
1402 public void actionPerformed(ActionEvent e)
1404 textColour_actionPerformed();
1407 jMenu1.setText(MessageManager.getString("label.group"));
1408 structureMenu.setText(MessageManager.getString("label.view_structure"));
1409 structureMenu.addActionListener(new ActionListener()
1412 public void actionPerformed(ActionEvent actionEvent)
1414 SequenceI[] selectedSeqs = new SequenceI[]
1416 if (ap.av.getSelectionGroup() != null)
1418 selectedSeqs = ap.av.getSequenceSelection();
1420 new StructureChooser(selectedSeqs, sequence, ap);
1424 viewStructureMenu.setText(MessageManager
1425 .getString("label.view_structure"));
1426 // colStructureMenu.setText("Colour By Structure");
1427 editSequence.setText(MessageManager.getString("label.edit_sequence")
1429 editSequence.addActionListener(new ActionListener()
1432 public void actionPerformed(ActionEvent actionEvent)
1434 editSequence_actionPerformed(actionEvent);
1437 makeReferenceSeq.setText(MessageManager
1438 .getString("label.mark_as_representative"));
1439 makeReferenceSeq.addActionListener(new ActionListener()
1443 public void actionPerformed(ActionEvent actionEvent)
1445 makeReferenceSeq_actionPerformed(actionEvent);
1449 hideInsertions.setText(MessageManager.getString("label.hide_insertions"));
1450 hideInsertions.addActionListener(new ActionListener()
1454 public void actionPerformed(ActionEvent e)
1456 hideInsertions_actionPerformed(e);
1460 * annotationMenuItem.setText("By Annotation");
1461 * annotationMenuItem.addActionListener(new ActionListener() { public void
1462 * actionPerformed(ActionEvent actionEvent) {
1463 * annotationMenuItem_actionPerformed(actionEvent); } });
1465 groupMenu.add(sequenceSelDetails);
1471 add(hideInsertions);
1473 // annotations configuration panel suppressed for now
1474 // groupMenu.add(chooseAnnotations);
1477 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1478 * (if a selection group is in force).
1480 sequenceMenu.add(seqShowAnnotationsMenu);
1481 sequenceMenu.add(seqHideAnnotationsMenu);
1482 sequenceMenu.add(seqAddReferenceAnnotations);
1483 groupMenu.add(groupShowAnnotationsMenu);
1484 groupMenu.add(groupHideAnnotationsMenu);
1485 groupMenu.add(groupAddReferenceAnnotations);
1486 groupMenu.add(editMenu);
1487 groupMenu.add(outputMenu);
1488 groupMenu.add(sequenceFeature);
1489 groupMenu.add(createGroupMenuItem);
1490 groupMenu.add(unGroupMenuItem);
1491 groupMenu.add(jMenu1);
1492 sequenceMenu.add(sequenceName);
1493 sequenceMenu.add(sequenceDetails);
1494 sequenceMenu.add(makeReferenceSeq);
1495 colourMenu.add(textColour);
1496 colourMenu.add(noColourmenuItem);
1497 colourMenu.add(clustalColour);
1498 colourMenu.add(BLOSUM62Colour);
1499 colourMenu.add(PIDColour);
1500 colourMenu.add(zappoColour);
1501 colourMenu.add(taylorColour);
1502 colourMenu.add(hydrophobicityColour);
1503 colourMenu.add(helixColour);
1504 colourMenu.add(strandColour);
1505 colourMenu.add(turnColour);
1506 colourMenu.add(buriedColour);
1507 colourMenu.add(nucleotideMenuItem);
1508 if (ap.getAlignment().isNucleotide())
1510 // JBPNote - commented since the colourscheme isn't functional
1511 colourMenu.add(purinePyrimidineColour);
1513 colourMenu.add(userDefinedColour);
1515 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1517 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1518 .getUserColourSchemes().keys();
1520 while (userColours.hasMoreElements())
1522 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1523 item.addActionListener(new ActionListener()
1526 public void actionPerformed(ActionEvent evt)
1528 userDefinedColour_actionPerformed(evt);
1531 colourMenu.add(item);
1535 colourMenu.addSeparator();
1536 colourMenu.add(abovePIDColour);
1537 colourMenu.add(conservationMenuItem);
1540 editMenu.add(editSequence);
1541 editMenu.add(upperCase);
1542 editMenu.add(lowerCase);
1543 editMenu.add(toggle);
1544 pdbMenu.add(pdbFromFile);
1545 // JBPNote: These shouldn't be added here - should appear in a generic
1546 // 'apply web service to this sequence menu'
1547 // pdbMenu.add(RNAFold);
1548 // pdbMenu.add(ContraFold);
1549 pdbMenu.add(enterPDB);
1550 pdbMenu.add(discoverPDB);
1551 jMenu1.add(groupName);
1552 jMenu1.add(colourMenu);
1553 jMenu1.add(showBoxes);
1554 jMenu1.add(showText);
1555 jMenu1.add(showColourText);
1556 jMenu1.add(outline);
1557 jMenu1.add(displayNonconserved);
1558 noColourmenuItem.setText(MessageManager.getString("label.none"));
1559 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1562 public void actionPerformed(ActionEvent e)
1564 noColourmenuItem_actionPerformed();
1568 clustalColour.setText(MessageManager
1569 .getString("label.clustalx_colours"));
1570 clustalColour.addActionListener(new java.awt.event.ActionListener()
1573 public void actionPerformed(ActionEvent e)
1575 clustalColour_actionPerformed();
1578 zappoColour.setText(MessageManager.getString("label.zappo"));
1579 zappoColour.addActionListener(new java.awt.event.ActionListener()
1582 public void actionPerformed(ActionEvent e)
1584 zappoColour_actionPerformed();
1587 taylorColour.setText(MessageManager.getString("label.taylor"));
1588 taylorColour.addActionListener(new java.awt.event.ActionListener()
1591 public void actionPerformed(ActionEvent e)
1593 taylorColour_actionPerformed();
1596 hydrophobicityColour.setText(MessageManager
1597 .getString("label.hydrophobicity"));
1598 hydrophobicityColour
1599 .addActionListener(new java.awt.event.ActionListener()
1602 public void actionPerformed(ActionEvent e)
1604 hydrophobicityColour_actionPerformed();
1607 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1608 helixColour.addActionListener(new java.awt.event.ActionListener()
1611 public void actionPerformed(ActionEvent e)
1613 helixColour_actionPerformed();
1616 strandColour.setText(MessageManager
1617 .getString("label.strand_propensity"));
1618 strandColour.addActionListener(new java.awt.event.ActionListener()
1621 public void actionPerformed(ActionEvent e)
1623 strandColour_actionPerformed();
1626 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1627 turnColour.addActionListener(new java.awt.event.ActionListener()
1630 public void actionPerformed(ActionEvent e)
1632 turnColour_actionPerformed();
1635 buriedColour.setText(MessageManager.getString("label.buried_index"));
1636 buriedColour.addActionListener(new java.awt.event.ActionListener()
1639 public void actionPerformed(ActionEvent e)
1641 buriedColour_actionPerformed();
1644 abovePIDColour.setText(MessageManager
1645 .getString("label.above_identity_percentage"));
1646 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1649 public void actionPerformed(ActionEvent e)
1651 abovePIDColour_actionPerformed();
1654 userDefinedColour.setText(MessageManager
1655 .getString("action.user_defined"));
1656 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1659 public void actionPerformed(ActionEvent e)
1661 userDefinedColour_actionPerformed(e);
1665 .setText(MessageManager.getString("label.percentage_identity"));
1666 PIDColour.addActionListener(new java.awt.event.ActionListener()
1669 public void actionPerformed(ActionEvent e)
1671 PIDColour_actionPerformed();
1674 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1675 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1678 public void actionPerformed(ActionEvent e)
1680 BLOSUM62Colour_actionPerformed();
1683 purinePyrimidineColour.setText(MessageManager
1684 .getString("label.purine_pyrimidine"));
1685 purinePyrimidineColour
1686 .addActionListener(new java.awt.event.ActionListener()
1689 public void actionPerformed(ActionEvent e)
1691 purinePyrimidineColour_actionPerformed();
1696 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1697 * public void actionPerformed(ActionEvent e) {
1698 * covariationColour_actionPerformed(); } });
1701 conservationMenuItem.setText(MessageManager
1702 .getString("label.conservation"));
1703 conservationMenuItem
1704 .addActionListener(new java.awt.event.ActionListener()
1707 public void actionPerformed(ActionEvent e)
1709 conservationMenuItem_actionPerformed();
1715 * Check for any annotations on the underlying dataset sequences (for the
1716 * current selection group) which are not 'on the alignment'.If any are found,
1717 * enable the option to add them to the alignment. The criteria for 'on the
1718 * alignment' is finding an alignment annotation on the alignment, matched on
1719 * calcId, label and sequenceRef.
1721 * A tooltip is also constructed that displays the source (calcId) and type
1722 * (label) of the annotations that can be added.
1725 * @param forSequences
1727 protected void configureReferenceAnnotationsMenu(
1728 JMenuItem menuItem, List<SequenceI> forSequences)
1730 menuItem.setText(MessageManager
1731 .getString("label.add_reference_annotations"));
1732 menuItem.setEnabled(false);
1733 if (forSequences == null)
1739 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1740 * Using TreeMap means calcIds are shown in alphabetical order.
1742 Map<String, String> tipEntries = new TreeMap<String, String>();
1743 StringBuilder tooltip = new StringBuilder(64);
1744 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1747 * For each sequence selected in the alignment, make a list of any
1748 * annotations on the underlying dataset sequence which are not already on
1751 * Build a map of { alignmentSequence, <List of annotations to add> }
1753 AlignmentI al = this.ap.av.getAlignment();
1754 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1755 for (SequenceI seq : forSequences)
1757 SequenceI dataset = seq.getDatasetSequence();
1758 if (dataset == null)
1762 AlignmentAnnotation[] datasetAnnotations = dataset.getAnnotation();
1763 if (datasetAnnotations == null)
1767 final List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1768 for (AlignmentAnnotation dsann : datasetAnnotations)
1771 * Find matching annotations on the alignment.
1773 final Iterable<AlignmentAnnotation> matchedAlignmentAnnotations = al
1774 .findAnnotations(seq, dsann.getCalcId(),
1776 if (!matchedAlignmentAnnotations.iterator().hasNext())
1779 tipEntries.put(dsann.getCalcId(), dsann.label);
1783 * Save any addable annotations for this sequence
1785 if (!result.isEmpty())
1787 candidates.put(seq, result);
1790 if (!candidates.isEmpty())
1793 * Found annotations that could be added. Enable the menu item, and
1794 * configure its tooltip and action.
1796 menuItem.setEnabled(true);
1797 for (String calcId : tipEntries.keySet())
1799 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1801 String tooltipText = JvSwingUtils.wrapTooltip(true,
1802 tooltip.toString());
1803 menuItem.setToolTipText(tooltipText);
1805 menuItem.addActionListener(new ActionListener()
1808 public void actionPerformed(ActionEvent e)
1810 addReferenceAnnotations_actionPerformed(candidates);
1817 * Add annotations to the sequences and to the alignment.
1820 * a map whose keys are sequences on the alignment, and values a list
1821 * of annotations to add to each sequence
1823 protected void addReferenceAnnotations_actionPerformed(
1824 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1827 * Add annotations at the top of the annotation, in the same order as their
1828 * related sequences.
1830 for (SequenceI seq : candidates.keySet())
1832 for (AlignmentAnnotation ann : candidates.get(seq))
1834 AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann);
1836 int endRes = ann.annotations.length;
1837 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1838 if (selectionGroup != null)
1840 startRes = selectionGroup.getStartRes();
1841 endRes = selectionGroup.getEndRes();
1843 copyAnn.restrict(startRes, endRes);
1846 * Add to the sequence (sets copyAnn.datasetSequence), unless the
1847 * original annotation is already on the sequence.
1849 if (!seq.hasAnnotation(ann))
1851 seq.addAlignmentAnnotation(copyAnn);
1854 copyAnn.adjustForAlignment();
1855 // add to the alignment and set visible
1856 this.ap.getAlignment().addAnnotation(copyAnn);
1857 copyAnn.visible = true;
1863 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1865 if (!ap.av.getAlignment().hasSeqrep())
1867 // initialise the display flags so the user sees something happen
1868 ap.av.setDisplayReferenceSeq(true);
1869 ap.av.setColourByReferenceSeq(true);
1870 ap.av.getAlignment().setSeqrep(sequence);
1874 if (ap.av.getAlignment().getSeqrep() == sequence)
1876 ap.av.getAlignment().setSeqrep(null);
1880 ap.av.getAlignment().setSeqrep(sequence);
1886 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1888 if (sequence != null)
1890 ColumnSelection cs = ap.av.getColumnSelection();
1893 cs = new ColumnSelection();
1895 cs.hideInsertionsFor(sequence);
1896 ap.av.setColumnSelection(cs);
1900 protected void sequenceSelectionDetails_actionPerformed()
1902 createSequenceDetailsReport(ap.av.getSequenceSelection());
1905 protected void sequenceDetails_actionPerformed()
1907 createSequenceDetailsReport(new SequenceI[]
1911 public void createSequenceDetailsReport(SequenceI[] sequences)
1913 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1914 StringBuffer contents = new StringBuffer();
1915 for (SequenceI seq : sequences)
1917 contents.append("<p><h2>"
1920 "label.create_sequence_details_report_annotation_for",
1922 { seq.getDisplayId(true) }) + "</h2></p><p>");
1923 new SequenceAnnotationReport(null)
1924 .createSequenceAnnotationReport(
1930 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1931 .getSeqPanel().seqCanvas.fr
1934 contents.append("</p>");
1936 cap.setText("<html>" + contents.toString() + "</html>");
1938 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1939 "label.sequence_details_for",
1940 (sequences.length == 1 ? new Object[]
1941 { sequences[0].getDisplayId(true) } : new Object[]
1942 { MessageManager.getString("label.selection") })), 500, 400);
1946 protected void showNonconserved_actionPerformed()
1948 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1953 * call to refresh view after settings change
1957 ap.updateAnnotation();
1958 ap.paintAlignment(true);
1960 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1969 protected void clustalColour_actionPerformed()
1971 SequenceGroup sg = getGroup();
1972 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1982 protected void zappoColour_actionPerformed()
1984 getGroup().cs = new ZappoColourScheme();
1994 protected void taylorColour_actionPerformed()
1996 getGroup().cs = new TaylorColourScheme();
2006 protected void hydrophobicityColour_actionPerformed()
2008 getGroup().cs = new HydrophobicColourScheme();
2018 protected void helixColour_actionPerformed()
2020 getGroup().cs = new HelixColourScheme();
2030 protected void strandColour_actionPerformed()
2032 getGroup().cs = new StrandColourScheme();
2042 protected void turnColour_actionPerformed()
2044 getGroup().cs = new TurnColourScheme();
2054 protected void buriedColour_actionPerformed()
2056 getGroup().cs = new BuriedColourScheme();
2066 public void nucleotideMenuItem_actionPerformed()
2068 getGroup().cs = new NucleotideColourScheme();
2072 protected void purinePyrimidineColour_actionPerformed()
2074 getGroup().cs = new PurinePyrimidineColourScheme();
2079 * protected void covariationColour_actionPerformed() { getGroup().cs = new
2080 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
2088 protected void abovePIDColour_actionPerformed()
2090 SequenceGroup sg = getGroup();
2096 if (abovePIDColour.isSelected())
2098 sg.cs.setConsensus(AAFrequency.calculate(
2099 sg.getSequences(ap.av.getHiddenRepSequences()),
2100 sg.getStartRes(), sg.getEndRes() + 1));
2102 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
2105 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
2107 SliderPanel.showPIDSlider();
2110 // remove PIDColouring
2112 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
2124 protected void userDefinedColour_actionPerformed(ActionEvent e)
2126 SequenceGroup sg = getGroup();
2128 if (e.getSource().equals(userDefinedColour))
2130 new UserDefinedColours(ap, sg);
2134 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2135 .getUserColourSchemes().get(e.getActionCommand());
2143 * Open a panel where the user can choose which types of sequence annotation
2148 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2150 // todo correct way to guard against opening a duplicate panel?
2151 new AnnotationChooser(ap);
2160 protected void PIDColour_actionPerformed()
2162 SequenceGroup sg = getGroup();
2163 sg.cs = new PIDColourScheme();
2164 sg.cs.setConsensus(AAFrequency.calculate(
2165 sg.getSequences(ap.av.getHiddenRepSequences()),
2166 sg.getStartRes(), sg.getEndRes() + 1));
2176 protected void BLOSUM62Colour_actionPerformed()
2178 SequenceGroup sg = getGroup();
2180 sg.cs = new Blosum62ColourScheme();
2182 sg.cs.setConsensus(AAFrequency.calculate(
2183 sg.getSequences(ap.av.getHiddenRepSequences()),
2184 sg.getStartRes(), sg.getEndRes() + 1));
2195 protected void noColourmenuItem_actionPerformed()
2197 getGroup().cs = null;
2207 protected void conservationMenuItem_actionPerformed()
2209 SequenceGroup sg = getGroup();
2215 if (conservationMenuItem.isSelected())
2217 // JBPNote: Conservation name shouldn't be i18n translated
2218 Conservation c = new Conservation("Group",
2219 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2220 .getHiddenRepSequences()), sg.getStartRes(),
2221 sg.getEndRes() + 1);
2224 c.verdict(false, ap.av.getConsPercGaps());
2226 sg.cs.setConservation(c);
2228 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2229 SliderPanel.showConservationSlider();
2232 // remove ConservationColouring
2234 sg.cs.setConservation(null);
2240 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2242 SequenceGroup sg = getGroup();
2248 AnnotationColourGradient acg = new AnnotationColourGradient(
2249 sequence.getAnnotation()[0], null,
2250 AnnotationColourGradient.NO_THRESHOLD);
2252 acg.setPredefinedColours(true);
2264 protected void groupName_actionPerformed()
2267 SequenceGroup sg = getGroup();
2268 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2269 sg.getDescription(), " "
2270 + MessageManager.getString("label.group_name") + " ",
2271 MessageManager.getString("label.group_description") + " ",
2272 MessageManager.getString("label.edit_group_name_description"),
2280 sg.setName(dialog.getName());
2281 sg.setDescription(dialog.getDescription());
2286 * Get selection group - adding it to the alignment if necessary.
2288 * @return sequence group to operate on
2290 SequenceGroup getGroup()
2292 SequenceGroup sg = ap.av.getSelectionGroup();
2293 // this method won't add a new group if it already exists
2296 ap.av.getAlignment().addGroup(sg);
2308 void sequenceName_actionPerformed()
2310 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2311 sequence.getDescription(),
2312 " " + MessageManager.getString("label.sequence_name")
2314 MessageManager.getString("label.sequence_description") + " ",
2316 .getString("label.edit_sequence_name_description"),
2324 if (dialog.getName() != null)
2326 if (dialog.getName().indexOf(" ") > -1)
2332 .getString("label.spaces_converted_to_backslashes"),
2334 .getString("label.no_spaces_allowed_sequence_name"),
2335 JOptionPane.WARNING_MESSAGE);
2338 sequence.setName(dialog.getName().replace(' ', '_'));
2339 ap.paintAlignment(false);
2342 sequence.setDescription(dialog.getDescription());
2344 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2355 void unGroupMenuItem_actionPerformed()
2357 SequenceGroup sg = ap.av.getSelectionGroup();
2358 ap.av.getAlignment().deleteGroup(sg);
2359 ap.av.setSelectionGroup(null);
2363 void createGroupMenuItem_actionPerformed()
2365 getGroup(); // implicitly creates group - note - should apply defaults / use
2366 // standard alignment window logic for this
2376 protected void outline_actionPerformed()
2378 SequenceGroup sg = getGroup();
2379 Color col = JColorChooser.showDialog(this,
2380 MessageManager.getString("label.select_outline_colour"),
2385 sg.setOutlineColour(col);
2397 public void showBoxes_actionPerformed()
2399 getGroup().setDisplayBoxes(showBoxes.isSelected());
2409 public void showText_actionPerformed()
2411 getGroup().setDisplayText(showText.isSelected());
2421 public void showColourText_actionPerformed()
2423 getGroup().setColourText(showColourText.isSelected());
2427 public void showLink(String url)
2431 jalview.util.BrowserLauncher.openURL(url);
2432 } catch (Exception ex)
2434 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2435 MessageManager.getString("label.web_browser_not_found_unix"),
2436 MessageManager.getString("label.web_browser_not_found"),
2437 JOptionPane.WARNING_MESSAGE);
2439 ex.printStackTrace();
2443 void hideSequences(boolean representGroup)
2445 SequenceGroup sg = ap.av.getSelectionGroup();
2446 if (sg == null || sg.getSize() < 1)
2448 ap.av.hideSequence(new SequenceI[]
2453 ap.av.setSelectionGroup(null);
2457 ap.av.hideRepSequences(sequence, sg);
2462 int gsize = sg.getSize();
2463 SequenceI[] hseqs = sg.getSequences().toArray(new SequenceI[gsize]);
2465 ap.av.hideSequence(hseqs);
2466 // refresh(); TODO: ? needed ?
2467 ap.av.sendSelection();
2470 public void copy_actionPerformed()
2472 ap.alignFrame.copy_actionPerformed(null);
2475 public void cut_actionPerformed()
2477 ap.alignFrame.cut_actionPerformed(null);
2480 void changeCase(ActionEvent e)
2482 Object source = e.getSource();
2483 SequenceGroup sg = ap.av.getSelectionGroup();
2487 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2489 sg.getEndRes() + 1);
2494 if (source == toggle)
2496 description = MessageManager.getString("label.toggle_case");
2497 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2499 else if (source == upperCase)
2501 description = MessageManager.getString("label.to_upper_case");
2502 caseChange = ChangeCaseCommand.TO_UPPER;
2506 description = MessageManager.getString("label.to_lower_case");
2507 caseChange = ChangeCaseCommand.TO_LOWER;
2510 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2511 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2512 startEnd, caseChange);
2514 ap.alignFrame.addHistoryItem(caseCommand);
2516 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2522 public void outputText_actionPerformed(ActionEvent e)
2524 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2525 cap.setForInput(null);
2526 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2527 "label.alignment_output_command", new Object[]
2528 { e.getActionCommand() }), 600, 500);
2530 String[] omitHidden = null;
2532 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2533 // or we simply trust the user wants
2534 // wysiwig behaviour
2536 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
2540 public void pdbFromFile_actionPerformed()
2542 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2543 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2544 chooser.setFileView(new jalview.io.JalviewFileView());
2545 chooser.setDialogTitle(MessageManager.formatMessage(
2546 "label.select_pdb_file_for", new Object[]
2547 { sequence.getDisplayId(false) }));
2548 chooser.setToolTipText(MessageManager.formatMessage(
2549 "label.load_pdb_file_associate_with_sequence", new Object[]
2550 { sequence.getDisplayId(false) }));
2552 int value = chooser.showOpenDialog(null);
2554 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2556 String choice = chooser.getSelectedFile().getPath();
2557 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2558 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2559 jalview.io.AppletFormatAdapter.FILE, sequence, true,
2566 public void enterPDB_actionPerformed()
2568 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2569 MessageManager.getString("label.enter_pdb_id"),
2570 MessageManager.getString("label.enter_pdb_id"),
2571 JOptionPane.QUESTION_MESSAGE);
2573 if (id != null && id.length() > 0)
2575 PDBEntry entry = new PDBEntry();
2576 entry.setId(id.toUpperCase());
2577 sequence.getDatasetSequence().addPDBId(entry);
2581 public void discoverPDB_actionPerformed()
2584 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2586 : ap.av.getSequenceSelection());
2587 Thread discpdb = new Thread(new Runnable()
2593 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2594 .fetchDBRefs(false);
2601 public void sequenceFeature_actionPerformed()
2603 SequenceGroup sg = ap.av.getSelectionGroup();
2609 int rsize = 0, gSize = sg.getSize();
2610 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2611 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2613 for (int i = 0; i < gSize; i++)
2615 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2616 int end = sg.findEndRes(sg.getSequenceAt(i));
2619 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2620 features[rsize] = new SequenceFeature(null, null, null, start, end,
2625 rseqs = new SequenceI[rsize];
2626 tfeatures = new SequenceFeature[rsize];
2627 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2628 System.arraycopy(features, 0, tfeatures, 0, rsize);
2629 features = tfeatures;
2631 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2632 features, true, ap))
2634 ap.alignFrame.setShowSeqFeatures(true);
2635 ap.highlightSearchResults(null);
2639 public void textColour_actionPerformed()
2641 SequenceGroup sg = getGroup();
2644 new TextColourChooser().chooseColour(ap, sg);
2648 public void colourByStructure(String pdbid)
2650 Annotation[] anots = ap.av.getStructureSelectionManager()
2651 .colourSequenceFromStructure(sequence, pdbid);
2653 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2654 "Coloured by " + pdbid, anots);
2656 ap.av.getAlignment().addAnnotation(an);
2657 an.createSequenceMapping(sequence, 0, true);
2658 // an.adjustForAlignment();
2659 ap.av.getAlignment().setAnnotationIndex(an, 0);
2661 ap.adjustAnnotationHeight();
2663 sequence.addAlignmentAnnotation(an);
2667 public void editSequence_actionPerformed(ActionEvent actionEvent)
2669 SequenceGroup sg = ap.av.getSelectionGroup();
2673 if (sequence == null)
2675 sequence = sg.getSequenceAt(0);
2678 EditNameDialog dialog = new EditNameDialog(
2679 sequence.getSequenceAsString(sg.getStartRes(),
2680 sg.getEndRes() + 1), null,
2681 MessageManager.getString("label.edit_sequence"), null,
2682 MessageManager.getString("label.edit_sequence"),
2687 EditCommand editCommand = new EditCommand(
2688 MessageManager.getString("label.edit_sequences"),
2689 Action.REPLACE, dialog.getName().replace(' ',
2690 ap.av.getGapCharacter()),
2691 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2692 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2694 ap.alignFrame.addHistoryItem(editCommand);
2696 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()