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 jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.bin.Cache;
28 import jalview.commands.ChangeCaseCommand;
29 import jalview.commands.EditCommand;
30 import jalview.commands.EditCommand.Action;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.Annotation;
34 import jalview.datamodel.ColumnSelection;
35 import jalview.datamodel.DBRefEntry;
36 import jalview.datamodel.PDBEntry;
37 import jalview.datamodel.Sequence;
38 import jalview.datamodel.SequenceFeature;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.io.FormatAdapter;
42 import jalview.io.SequenceAnnotationReport;
43 import jalview.schemes.AnnotationColourGradient;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.BuriedColourScheme;
46 import jalview.schemes.ClustalxColourScheme;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.HydrophobicColourScheme;
49 import jalview.schemes.NucleotideColourScheme;
50 import jalview.schemes.PIDColourScheme;
51 import jalview.schemes.PurinePyrimidineColourScheme;
52 import jalview.schemes.ResidueProperties;
53 import jalview.schemes.StrandColourScheme;
54 import jalview.schemes.TaylorColourScheme;
55 import jalview.schemes.TurnColourScheme;
56 import jalview.schemes.UserColourScheme;
57 import jalview.schemes.ZappoColourScheme;
58 import jalview.util.DBRefUtils;
59 import jalview.util.GroupUrlLink;
60 import jalview.util.GroupUrlLink.UrlStringTooLongException;
61 import jalview.util.MessageManager;
62 import jalview.util.UrlLink;
64 import java.awt.Color;
65 import java.awt.event.ActionEvent;
66 import java.awt.event.ActionListener;
67 import java.util.ArrayList;
68 import java.util.Arrays;
69 import java.util.Collections;
70 import java.util.Hashtable;
71 import java.util.LinkedHashMap;
72 import java.util.List;
74 import java.util.TreeMap;
75 import java.util.Vector;
77 import javax.swing.ButtonGroup;
78 import javax.swing.JCheckBoxMenuItem;
79 import javax.swing.JColorChooser;
80 import javax.swing.JMenu;
81 import javax.swing.JMenuItem;
82 import javax.swing.JOptionPane;
83 import javax.swing.JPopupMenu;
84 import javax.swing.JRadioButtonMenuItem;
90 * @version $Revision: 1.118 $
92 public class PopupMenu extends JPopupMenu
94 JMenu groupMenu = new JMenu();
96 JMenuItem groupName = new JMenuItem();
98 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
100 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
102 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
104 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
106 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
108 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
110 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
112 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
114 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
116 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
118 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
120 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
122 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
124 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
126 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
128 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
132 JMenu sequenceMenu = new JMenu();
134 JMenuItem sequenceName = new JMenuItem();
136 JMenuItem sequenceDetails = new JMenuItem();
138 JMenuItem sequenceSelDetails = new JMenuItem();
140 JMenuItem makeReferenceSeq = new JMenuItem();
142 JMenuItem chooseAnnotations = new JMenuItem();
146 JMenuItem createGroupMenuItem = new JMenuItem();
148 JMenuItem unGroupMenuItem = new JMenuItem();
150 JMenuItem outline = new JMenuItem();
152 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
154 JMenu colourMenu = new JMenu();
156 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
158 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
160 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
162 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
164 JMenu editMenu = new JMenu();
166 JMenuItem cut = new JMenuItem();
168 JMenuItem copy = new JMenuItem();
170 JMenuItem upperCase = new JMenuItem();
172 JMenuItem lowerCase = new JMenuItem();
174 JMenuItem toggle = new JMenuItem();
176 JMenu pdbMenu = new JMenu();
178 JMenu outputMenu = new JMenu();
180 JMenu seqShowAnnotationsMenu = new JMenu();
182 JMenu seqHideAnnotationsMenu = new JMenu();
184 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
185 MessageManager.getString("label.add_reference_annotations"));
187 JMenu groupShowAnnotationsMenu = new JMenu();
189 JMenu groupHideAnnotationsMenu = new JMenu();
191 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
192 MessageManager.getString("label.add_reference_annotations"));
194 JMenuItem sequenceFeature = new JMenuItem();
196 JMenuItem textColour = new JMenuItem();
198 JMenu jMenu1 = new JMenu();
200 JMenuItem pdbStructureDialog = new JMenuItem();
202 JMenu rnaStructureMenu = new JMenu();
204 JMenuItem editSequence = new JMenuItem();
206 JMenu groupLinksMenu;
208 JMenuItem hideInsertions = new JMenuItem();
211 * Creates a new PopupMenu object.
218 public PopupMenu(final AlignmentPanel ap, Sequence seq, List<String> links)
220 this(ap, seq, links, null);
230 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
231 List<String> links, List<String> groupLinks)
233 // /////////////////////////////////////////////////////////
234 // If this is activated from the sequence panel, the user may want to
235 // edit or annotate a particular residue. Therefore display the residue menu
237 // If from the IDPanel, we must display the sequence menu
238 // ////////////////////////////////////////////////////////
242 ButtonGroup colours = new ButtonGroup();
243 colours.add(noColourmenuItem);
244 colours.add(clustalColour);
245 colours.add(zappoColour);
246 colours.add(taylorColour);
247 colours.add(hydrophobicityColour);
248 colours.add(helixColour);
249 colours.add(strandColour);
250 colours.add(turnColour);
251 colours.add(buriedColour);
252 colours.add(abovePIDColour);
253 colours.add(userDefinedColour);
254 colours.add(PIDColour);
255 colours.add(BLOSUM62Colour);
256 colours.add(purinePyrimidineColour);
257 colours.add(RNAInteractionColour);
259 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
261 JMenuItem item = new JMenuItem(
262 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
264 item.addActionListener(new java.awt.event.ActionListener()
267 public void actionPerformed(ActionEvent e)
269 outputText_actionPerformed(e);
273 outputMenu.add(item);
277 * Build menus for annotation types that may be shown or hidden, and for
278 * 'reference annotations' that may be added to the alignment. First for the
279 * currently selected sequence (if there is one):
281 final List<SequenceI> selectedSequence = (seq == null ? Collections
282 .<SequenceI> emptyList() : Arrays.asList(seq));
283 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
284 seqHideAnnotationsMenu, selectedSequence);
285 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
289 * And repeat for the current selection group (if there is one):
291 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
292 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
294 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
295 groupHideAnnotationsMenu, selectedGroup);
296 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
302 } catch (Exception e)
310 sequenceMenu.setText(sequence.getName());
311 if (seq == ap.av.getAlignment().getSeqrep())
313 makeReferenceSeq.setText(MessageManager
314 .getString("action.unmark_as_reference"));
318 makeReferenceSeq.setText(MessageManager
319 .getString("action.set_as_reference"));
322 if (!ap.av.getAlignment().isNucleotide())
324 remove(rnaStructureMenu);
328 int origCount = rnaStructureMenu.getItemCount();
330 * add menu items to 2D-render any alignment or sequence secondary
331 * structure annotation
333 AlignmentAnnotation[] aas = ap.av.getAlignment()
334 .getAlignmentAnnotation();
337 for (final AlignmentAnnotation aa : aas)
339 if (aa.isValidStruc() && aa.sequenceRef == null)
342 * valid alignment RNA secondary structure annotation
344 menuItem = new JMenuItem();
345 menuItem.setText(MessageManager.formatMessage(
346 "label.2d_rna_structure_line",
347 new Object[] { aa.label }));
348 menuItem.addActionListener(new java.awt.event.ActionListener()
351 public void actionPerformed(ActionEvent e)
353 new AppVarna(seq, aa, ap);
356 rnaStructureMenu.add(menuItem);
361 if (seq.getAnnotation() != null)
363 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
364 for (final AlignmentAnnotation aa : seqAnns)
366 if (aa.isValidStruc())
369 * valid sequence RNA secondary structure annotation
371 // TODO: make rnastrucF a bit more nice
372 menuItem = new JMenuItem();
373 menuItem.setText(MessageManager.formatMessage(
374 "label.2d_rna_sequence_name",
375 new Object[] { seq.getName() }));
376 menuItem.addActionListener(new java.awt.event.ActionListener()
379 public void actionPerformed(ActionEvent e)
381 // TODO: VARNA does'nt print gaps in the sequence
382 new AppVarna(seq, aa, ap);
385 rnaStructureMenu.add(menuItem);
389 if (rnaStructureMenu.getItemCount() == origCount)
391 remove(rnaStructureMenu);
395 menuItem = new JMenuItem(
396 MessageManager.getString("action.hide_sequences"));
397 menuItem.addActionListener(new java.awt.event.ActionListener()
400 public void actionPerformed(ActionEvent e)
402 hideSequences(false);
407 if (ap.av.getSelectionGroup() != null
408 && ap.av.getSelectionGroup().getSize() > 1)
410 menuItem = new JMenuItem(MessageManager.formatMessage(
411 "label.represent_group_with",
412 new Object[] { seq.getName() }));
413 menuItem.addActionListener(new java.awt.event.ActionListener()
416 public void actionPerformed(ActionEvent e)
421 sequenceMenu.add(menuItem);
424 if (ap.av.hasHiddenRows())
426 final int index = ap.av.getAlignment().findIndex(seq);
428 if (ap.av.adjustForHiddenSeqs(index)
429 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
431 menuItem = new JMenuItem(
432 MessageManager.getString("action.reveal_sequences"));
433 menuItem.addActionListener(new ActionListener()
436 public void actionPerformed(ActionEvent e)
438 ap.av.showSequence(index);
439 if (ap.overviewPanel != null)
441 ap.overviewPanel.updateOverviewImage();
449 // for the case when no sequences are even visible
450 if (ap.av.hasHiddenRows())
453 menuItem = new JMenuItem(
454 MessageManager.getString("action.reveal_all"));
455 menuItem.addActionListener(new ActionListener()
458 public void actionPerformed(ActionEvent e)
460 ap.av.showAllHiddenSeqs();
461 if (ap.overviewPanel != null)
463 ap.overviewPanel.updateOverviewImage();
473 SequenceGroup sg = ap.av.getSelectionGroup();
474 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
475 .getGroups().contains(sg) : false;
477 if (sg != null && sg.getSize() > 0)
479 groupName.setText(MessageManager
480 .getString("label.edit_name_and_description_current_group"));
482 if (sg.cs instanceof ZappoColourScheme)
484 zappoColour.setSelected(true);
486 else if (sg.cs instanceof TaylorColourScheme)
488 taylorColour.setSelected(true);
490 else if (sg.cs instanceof PIDColourScheme)
492 PIDColour.setSelected(true);
494 else if (sg.cs instanceof Blosum62ColourScheme)
496 BLOSUM62Colour.setSelected(true);
498 else if (sg.cs instanceof UserColourScheme)
500 userDefinedColour.setSelected(true);
502 else if (sg.cs instanceof HydrophobicColourScheme)
504 hydrophobicityColour.setSelected(true);
506 else if (sg.cs instanceof HelixColourScheme)
508 helixColour.setSelected(true);
510 else if (sg.cs instanceof StrandColourScheme)
512 strandColour.setSelected(true);
514 else if (sg.cs instanceof TurnColourScheme)
516 turnColour.setSelected(true);
518 else if (sg.cs instanceof BuriedColourScheme)
520 buriedColour.setSelected(true);
522 else if (sg.cs instanceof ClustalxColourScheme)
524 clustalColour.setSelected(true);
526 else if (sg.cs instanceof PurinePyrimidineColourScheme)
528 purinePyrimidineColour.setSelected(true);
532 * else if (sg.cs instanceof CovariationColourScheme) {
533 * covariationColour.setSelected(true); }
537 noColourmenuItem.setSelected(true);
540 if (sg.cs != null && sg.cs.conservationApplied())
542 conservationMenuItem.setSelected(true);
544 displayNonconserved.setSelected(sg.getShowNonconserved());
545 showText.setSelected(sg.getDisplayText());
546 showColourText.setSelected(sg.getColourText());
547 showBoxes.setSelected(sg.getDisplayBoxes());
548 // add any groupURLs to the groupURL submenu and make it visible
549 if (groupLinks != null && groupLinks.size() > 0)
551 buildGroupURLMenu(sg, groupLinks);
553 // Add a 'show all structures' for the current selection
554 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
555 SequenceI sqass = null;
556 for (SequenceI sq : ap.av.getSequenceSelection())
558 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
559 if (pes != null && pes.size() > 0)
561 reppdb.put(pes.get(0).getId(), pes.get(0));
562 for (PDBEntry pe : pes)
564 pdbe.put(pe.getId(), pe);
574 final PDBEntry[] pe = pdbe.values().toArray(
575 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
576 new PDBEntry[reppdb.size()]);
577 final JMenuItem gpdbview, rpdbview;
582 groupMenu.setVisible(false);
583 editMenu.setVisible(false);
588 createGroupMenuItem.setVisible(true);
589 unGroupMenuItem.setVisible(false);
590 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
594 createGroupMenuItem.setVisible(false);
595 unGroupMenuItem.setVisible(true);
596 jMenu1.setText(MessageManager.getString("action.edit_group"));
601 sequenceMenu.setVisible(false);
602 pdbStructureDialog.setVisible(false);
603 rnaStructureMenu.setVisible(false);
606 if (links != null && links.size() > 0)
608 addFeatureLinks(seq, links);
613 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
618 void addFeatureLinks(final SequenceI seq, List<String> links)
620 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
621 List<String> linkset = new ArrayList<String>();
622 for (String link : links)
624 UrlLink urlLink = null;
627 urlLink = new UrlLink(link);
628 } catch (Exception foo)
630 Cache.log.error("Exception for URLLink '" + link + "'", foo);
634 if (!urlLink.isValid())
636 Cache.log.error(urlLink.getInvalidMessage());
639 final String label = urlLink.getLabel();
640 if (seq != null && urlLink.isDynamic())
643 // collect matching db-refs
644 DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(),
645 new String[] { urlLink.getTarget() });
646 // collect id string too
647 String id = seq.getName();
648 String descr = seq.getDescription();
649 if (descr != null && descr.length() < 1)
656 for (int r = 0; r < dbr.length; r++)
658 if (id != null && dbr[r].getAccessionId().equals(id))
660 // suppress duplicate link creation for the bare sequence ID
661 // string with this link
664 // create Bare ID link for this URL
665 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true);
668 for (int u = 0; u < urls.length; u += 2)
670 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
672 linkset.add(urls[u] + "|" + urls[u + 1]);
673 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
681 // create Bare ID link for this URL
682 String[] urls = urlLink.makeUrls(id, true);
685 for (int u = 0; u < urls.length; u += 2)
687 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
689 linkset.add(urls[u] + "|" + urls[u + 1]);
690 addshowLink(linkMenu, label, urls[u + 1]);
695 // Create urls from description but only for URL links which are regex
697 if (descr != null && urlLink.getRegexReplace() != null)
699 // create link for this URL from description where regex matches
700 String[] urls = urlLink.makeUrls(descr, true);
703 for (int u = 0; u < urls.length; u += 2)
705 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
707 linkset.add(urls[u] + "|" + urls[u + 1]);
708 addshowLink(linkMenu, label, urls[u + 1]);
716 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
718 linkset.add(label + "|" + urlLink.getUrl_prefix());
719 // Add a non-dynamic link
720 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
724 if (sequence != null)
726 sequenceMenu.add(linkMenu);
735 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
736 * "All" is added first, followed by a separator. Then add any annotation
737 * types associated with the current selection. Separate menus are built for
738 * the selected sequence group (if any), and the selected sequence.
740 * Some annotation rows are always rendered together - these can be identified
741 * by a common graphGroup property > -1. Only one of each group will be marked
742 * as visible (to avoid duplication of the display). For such groups we add a
743 * composite type name, e.g.
745 * IUPredWS (Long), IUPredWS (Short)
749 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
750 List<SequenceI> forSequences)
752 showMenu.removeAll();
753 hideMenu.removeAll();
755 final List<String> all = Arrays.asList(new String[] { MessageManager
756 .getString("label.all") });
757 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
758 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
760 showMenu.addSeparator();
761 hideMenu.addSeparator();
763 final AlignmentAnnotation[] annotations = ap.getAlignment()
764 .getAlignmentAnnotation();
767 * Find shown/hidden annotations types, distinguished by source (calcId),
768 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
769 * the insertion order, which is the order of the annotations on the
772 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
773 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
774 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
775 AlignmentAnnotationUtils.asList(annotations), forSequences);
777 for (String calcId : hiddenTypes.keySet())
779 for (List<String> type : hiddenTypes.get(calcId))
781 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
785 // grey out 'show annotations' if none are hidden
786 showMenu.setEnabled(!hiddenTypes.isEmpty());
788 for (String calcId : shownTypes.keySet())
790 for (List<String> type : shownTypes.get(calcId))
792 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
796 // grey out 'hide annotations' if none are shown
797 hideMenu.setEnabled(!shownTypes.isEmpty());
801 * Returns a list of sequences - either the current selection group (if there
802 * is one), else the specified single sequence.
807 protected List<SequenceI> getSequenceScope(SequenceI seq)
809 List<SequenceI> forSequences = null;
810 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
811 if (selectionGroup != null && selectionGroup.getSize() > 0)
813 forSequences = selectionGroup.getSequences();
817 forSequences = seq == null ? Collections.<SequenceI> emptyList()
818 : Arrays.asList(seq);
824 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
827 * @param showOrHideMenu
829 * @param forSequences
830 * the sequences whose annotations may be shown or hidden
835 * if true this is a special label meaning 'All'
836 * @param actionIsShow
837 * if true, the select menu item action is to show the annotation
840 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
841 final List<SequenceI> forSequences, String calcId,
842 final List<String> types, final boolean allTypes,
843 final boolean actionIsShow)
845 String label = types.toString(); // [a, b, c]
846 label = label.substring(1, label.length() - 1); // a, b, c
847 final JMenuItem item = new JMenuItem(label);
848 item.setToolTipText(calcId);
849 item.addActionListener(new java.awt.event.ActionListener()
852 public void actionPerformed(ActionEvent e)
854 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
855 types, forSequences, allTypes, actionIsShow);
859 showOrHideMenu.add(item);
862 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
865 // TODO: usability: thread off the generation of group url content so root
867 // sequence only URLs
868 // ID/regex match URLs
869 groupLinksMenu = new JMenu(
870 MessageManager.getString("action.group_link"));
871 // three types of url that might be created.
872 JMenu[] linkMenus = new JMenu[] { null,
873 new JMenu(MessageManager.getString("action.ids")),
874 new JMenu(MessageManager.getString("action.sequences")),
875 new JMenu(MessageManager.getString("action.ids_sequences")) };
877 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
878 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
879 Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
880 for (int sq = 0; sq < seqs.length; sq++)
883 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
884 .findPosition(sg.getEndRes());
885 // just collect ids from dataset sequence
886 // TODO: check if IDs collected from selecton group intersects with the
887 // current selection, too
888 SequenceI sqi = seqs[sq];
889 while (sqi.getDatasetSequence() != null)
891 sqi = sqi.getDatasetSequence();
893 DBRefEntry[] dbr = sqi.getDBRefs();
894 if (dbr != null && dbr.length > 0)
896 for (int d = 0; d < dbr.length; d++)
898 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
899 Object[] sarray = commonDbrefs.get(src);
902 sarray = new Object[2];
903 sarray[0] = new int[] { 0 };
904 sarray[1] = new String[seqs.length];
906 commonDbrefs.put(src, sarray);
909 if (((String[]) sarray[1])[sq] == null)
912 || (dbr[d].getMap().locateMappedRange(start, end) != null))
914 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
915 ((int[]) sarray[0])[0]++;
921 // now create group links for all distinct ID/sequence sets.
922 boolean addMenu = false; // indicates if there are any group links to give
924 for (String link : groupLinks)
926 GroupUrlLink urlLink = null;
929 urlLink = new GroupUrlLink(link);
930 } catch (Exception foo)
932 Cache.log.error("Exception for GroupURLLink '" + link
937 if (!urlLink.isValid())
939 Cache.log.error(urlLink.getInvalidMessage());
942 final String label = urlLink.getLabel();
943 boolean usingNames = false;
944 // Now see which parts of the group apply for this URL
945 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
946 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
947 String[] seqstr, ids; // input to makeUrl
950 int numinput = ((int[]) idset[0])[0];
951 String[] allids = ((String[]) idset[1]);
952 seqstr = new String[numinput];
953 ids = new String[numinput];
954 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
956 if (allids[sq] != null)
958 ids[idcount] = allids[sq];
959 seqstr[idcount++] = idandseqs[1][sq];
965 // just use the id/seq set
966 seqstr = idandseqs[1];
970 // and try and make the groupURL!
972 Object[] urlset = null;
975 urlset = urlLink.makeUrlStubs(ids, seqstr,
976 "FromJalview" + System.currentTimeMillis(), false);
977 } catch (UrlStringTooLongException e)
982 int type = urlLink.getGroupURLType() & 3;
983 // first two bits ofurlLink type bitfield are sequenceids and sequences
984 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
985 addshowLink(linkMenus[type], label
986 + (((type & 1) == 1) ? ("("
987 + (usingNames ? "Names" : ltarget) + ")") : ""),
994 groupLinksMenu = new JMenu(
995 MessageManager.getString("action.group_link"));
996 for (int m = 0; m < linkMenus.length; m++)
998 if (linkMenus[m] != null
999 && linkMenus[m].getMenuComponentCount() > 0)
1001 groupLinksMenu.add(linkMenus[m]);
1005 groupMenu.add(groupLinksMenu);
1010 * add a show URL menu item to the given linkMenu
1014 * - menu label string
1018 private void addshowLink(JMenu linkMenu, String label, final String url)
1020 JMenuItem item = new JMenuItem(label);
1021 item.setToolTipText(MessageManager.formatMessage(
1022 "label.open_url_param", new Object[] { url }));
1023 item.addActionListener(new java.awt.event.ActionListener()
1026 public void actionPerformed(ActionEvent e)
1028 new Thread(new Runnable()
1045 * add a late bound groupURL item to the given linkMenu
1049 * - menu label string
1050 * @param urlgenerator
1051 * GroupURLLink used to generate URL
1053 * Object array returned from the makeUrlStubs function.
1055 private void addshowLink(JMenu linkMenu, String label,
1056 final GroupUrlLink urlgenerator, final Object[] urlstub)
1058 JMenuItem item = new JMenuItem(label);
1059 item.setToolTipText(MessageManager.formatMessage(
1060 "label.open_url_seqs_param",
1061 new Object[] { urlgenerator.getUrl_prefix(),
1062 urlgenerator.getNumberInvolved(urlstub) }));
1063 // TODO: put in info about what is being sent.
1064 item.addActionListener(new ActionListener()
1067 public void actionPerformed(ActionEvent e)
1069 new Thread(new Runnable()
1077 showLink(urlgenerator.constructFrom(urlstub));
1078 } catch (UrlStringTooLongException e2)
1096 private void jbInit() throws Exception
1098 groupMenu.setText(MessageManager.getString("label.selection"));
1099 groupName.setText(MessageManager.getString("label.name"));
1100 groupName.addActionListener(new java.awt.event.ActionListener()
1103 public void actionPerformed(ActionEvent e)
1105 groupName_actionPerformed();
1108 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1109 sequenceName.setText(MessageManager
1110 .getString("label.edit_name_description"));
1111 sequenceName.addActionListener(new java.awt.event.ActionListener()
1114 public void actionPerformed(ActionEvent e)
1116 sequenceName_actionPerformed();
1119 chooseAnnotations.setText(MessageManager
1120 .getString("action.choose_annotations"));
1121 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1124 public void actionPerformed(ActionEvent e)
1126 chooseAnnotations_actionPerformed(e);
1129 sequenceDetails.setText(MessageManager
1130 .getString("label.sequence_details"));
1131 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1134 public void actionPerformed(ActionEvent e)
1136 sequenceDetails_actionPerformed();
1139 sequenceSelDetails.setText(MessageManager
1140 .getString("label.sequence_details"));
1142 .addActionListener(new java.awt.event.ActionListener()
1145 public void actionPerformed(ActionEvent e)
1147 sequenceSelectionDetails_actionPerformed();
1150 PIDColour.setFocusPainted(false);
1152 .setText(MessageManager.getString("action.remove_group"));
1153 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1156 public void actionPerformed(ActionEvent e)
1158 unGroupMenuItem_actionPerformed();
1161 createGroupMenuItem.setText(MessageManager
1162 .getString("action.create_group"));
1164 .addActionListener(new java.awt.event.ActionListener()
1167 public void actionPerformed(ActionEvent e)
1169 createGroupMenuItem_actionPerformed();
1173 outline.setText(MessageManager.getString("action.border_colour"));
1174 outline.addActionListener(new java.awt.event.ActionListener()
1177 public void actionPerformed(ActionEvent e)
1179 outline_actionPerformed();
1183 .setText(MessageManager.getString("label.nucleotide"));
1184 nucleotideMenuItem.addActionListener(new ActionListener()
1187 public void actionPerformed(ActionEvent e)
1189 nucleotideMenuItem_actionPerformed();
1192 colourMenu.setText(MessageManager.getString("label.group_colour"));
1193 showBoxes.setText(MessageManager.getString("action.boxes"));
1194 showBoxes.setState(true);
1195 showBoxes.addActionListener(new ActionListener()
1198 public void actionPerformed(ActionEvent e)
1200 showBoxes_actionPerformed();
1203 showText.setText(MessageManager.getString("action.text"));
1204 showText.setState(true);
1205 showText.addActionListener(new ActionListener()
1208 public void actionPerformed(ActionEvent e)
1210 showText_actionPerformed();
1213 showColourText.setText(MessageManager.getString("label.colour_text"));
1214 showColourText.addActionListener(new ActionListener()
1217 public void actionPerformed(ActionEvent e)
1219 showColourText_actionPerformed();
1222 displayNonconserved.setText(MessageManager
1223 .getString("label.show_non_conversed"));
1224 displayNonconserved.setState(true);
1225 displayNonconserved.addActionListener(new ActionListener()
1228 public void actionPerformed(ActionEvent e)
1230 showNonconserved_actionPerformed();
1233 editMenu.setText(MessageManager.getString("action.edit"));
1234 cut.setText(MessageManager.getString("action.cut"));
1235 cut.addActionListener(new ActionListener()
1238 public void actionPerformed(ActionEvent e)
1240 cut_actionPerformed();
1243 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1244 upperCase.addActionListener(new ActionListener()
1247 public void actionPerformed(ActionEvent e)
1252 copy.setText(MessageManager.getString("action.copy"));
1253 copy.addActionListener(new ActionListener()
1256 public void actionPerformed(ActionEvent e)
1258 copy_actionPerformed();
1261 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1262 lowerCase.addActionListener(new ActionListener()
1265 public void actionPerformed(ActionEvent e)
1270 toggle.setText(MessageManager.getString("label.toggle_case"));
1271 toggle.addActionListener(new ActionListener()
1274 public void actionPerformed(ActionEvent e)
1279 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1281 seqShowAnnotationsMenu.setText(MessageManager
1282 .getString("label.show_annotations"));
1283 seqHideAnnotationsMenu.setText(MessageManager
1284 .getString("label.hide_annotations"));
1285 groupShowAnnotationsMenu.setText(MessageManager
1286 .getString("label.show_annotations"));
1287 groupHideAnnotationsMenu.setText(MessageManager
1288 .getString("label.hide_annotations"));
1289 sequenceFeature.setText(MessageManager
1290 .getString("label.create_sequence_feature"));
1291 sequenceFeature.addActionListener(new ActionListener()
1294 public void actionPerformed(ActionEvent e)
1296 sequenceFeature_actionPerformed();
1299 textColour.setText(MessageManager.getString("label.text_colour"));
1300 textColour.addActionListener(new ActionListener()
1303 public void actionPerformed(ActionEvent e)
1305 textColour_actionPerformed();
1308 jMenu1.setText(MessageManager.getString("label.group"));
1309 pdbStructureDialog.setText(MessageManager
1310 .getString("label.show_pdbstruct_dialog"));
1311 pdbStructureDialog.addActionListener(new ActionListener()
1314 public void actionPerformed(ActionEvent actionEvent)
1316 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1317 if (ap.av.getSelectionGroup() != null)
1319 selectedSeqs = ap.av.getSequenceSelection();
1321 new StructureChooser(selectedSeqs, sequence, ap);
1325 rnaStructureMenu.setText(MessageManager
1326 .getString("label.view_rna_structure"));
1328 // colStructureMenu.setText("Colour By Structure");
1329 editSequence.setText(MessageManager.getString("label.edit_sequence")
1331 editSequence.addActionListener(new ActionListener()
1334 public void actionPerformed(ActionEvent actionEvent)
1336 editSequence_actionPerformed(actionEvent);
1339 makeReferenceSeq.setText(MessageManager
1340 .getString("label.mark_as_representative"));
1341 makeReferenceSeq.addActionListener(new ActionListener()
1345 public void actionPerformed(ActionEvent actionEvent)
1347 makeReferenceSeq_actionPerformed(actionEvent);
1351 hideInsertions.setText(MessageManager
1352 .getString("label.hide_insertions"));
1353 hideInsertions.addActionListener(new ActionListener()
1357 public void actionPerformed(ActionEvent e)
1359 hideInsertions_actionPerformed(e);
1363 * annotationMenuItem.setText("By Annotation");
1364 * annotationMenuItem.addActionListener(new ActionListener() { public void
1365 * actionPerformed(ActionEvent actionEvent) {
1366 * annotationMenuItem_actionPerformed(actionEvent); } });
1368 groupMenu.add(sequenceSelDetails);
1371 add(rnaStructureMenu);
1372 add(pdbStructureDialog);
1373 if (sequence != null)
1375 add(hideInsertions);
1377 // annotations configuration panel suppressed for now
1378 // groupMenu.add(chooseAnnotations);
1381 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1382 * (if a selection group is in force).
1384 sequenceMenu.add(seqShowAnnotationsMenu);
1385 sequenceMenu.add(seqHideAnnotationsMenu);
1386 sequenceMenu.add(seqAddReferenceAnnotations);
1387 groupMenu.add(groupShowAnnotationsMenu);
1388 groupMenu.add(groupHideAnnotationsMenu);
1389 groupMenu.add(groupAddReferenceAnnotations);
1390 groupMenu.add(editMenu);
1391 groupMenu.add(outputMenu);
1392 groupMenu.add(sequenceFeature);
1393 groupMenu.add(createGroupMenuItem);
1394 groupMenu.add(unGroupMenuItem);
1395 groupMenu.add(jMenu1);
1396 sequenceMenu.add(sequenceName);
1397 sequenceMenu.add(sequenceDetails);
1398 sequenceMenu.add(makeReferenceSeq);
1399 colourMenu.add(textColour);
1400 colourMenu.add(noColourmenuItem);
1401 colourMenu.add(clustalColour);
1402 colourMenu.add(BLOSUM62Colour);
1403 colourMenu.add(PIDColour);
1404 colourMenu.add(zappoColour);
1405 colourMenu.add(taylorColour);
1406 colourMenu.add(hydrophobicityColour);
1407 colourMenu.add(helixColour);
1408 colourMenu.add(strandColour);
1409 colourMenu.add(turnColour);
1410 colourMenu.add(buriedColour);
1411 colourMenu.add(nucleotideMenuItem);
1412 if (ap.getAlignment().isNucleotide())
1414 // JBPNote - commented since the colourscheme isn't functional
1415 colourMenu.add(purinePyrimidineColour);
1417 colourMenu.add(userDefinedColour);
1419 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1421 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1422 .getUserColourSchemes().keys();
1424 while (userColours.hasMoreElements())
1426 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1427 item.addActionListener(new ActionListener()
1430 public void actionPerformed(ActionEvent evt)
1432 userDefinedColour_actionPerformed(evt);
1435 colourMenu.add(item);
1439 colourMenu.addSeparator();
1440 colourMenu.add(abovePIDColour);
1441 colourMenu.add(conservationMenuItem);
1444 editMenu.add(editSequence);
1445 editMenu.add(upperCase);
1446 editMenu.add(lowerCase);
1447 editMenu.add(toggle);
1448 // JBPNote: These shouldn't be added here - should appear in a generic
1449 // 'apply web service to this sequence menu'
1450 // pdbMenu.add(RNAFold);
1451 // pdbMenu.add(ContraFold);
1452 jMenu1.add(groupName);
1453 jMenu1.add(colourMenu);
1454 jMenu1.add(showBoxes);
1455 jMenu1.add(showText);
1456 jMenu1.add(showColourText);
1457 jMenu1.add(outline);
1458 jMenu1.add(displayNonconserved);
1459 noColourmenuItem.setText(MessageManager.getString("label.none"));
1460 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1463 public void actionPerformed(ActionEvent e)
1465 noColourmenuItem_actionPerformed();
1469 clustalColour.setText(MessageManager
1470 .getString("label.clustalx_colours"));
1471 clustalColour.addActionListener(new java.awt.event.ActionListener()
1474 public void actionPerformed(ActionEvent e)
1476 clustalColour_actionPerformed();
1479 zappoColour.setText(MessageManager.getString("label.zappo"));
1480 zappoColour.addActionListener(new java.awt.event.ActionListener()
1483 public void actionPerformed(ActionEvent e)
1485 zappoColour_actionPerformed();
1488 taylorColour.setText(MessageManager.getString("label.taylor"));
1489 taylorColour.addActionListener(new java.awt.event.ActionListener()
1492 public void actionPerformed(ActionEvent e)
1494 taylorColour_actionPerformed();
1497 hydrophobicityColour.setText(MessageManager
1498 .getString("label.hydrophobicity"));
1499 hydrophobicityColour
1500 .addActionListener(new java.awt.event.ActionListener()
1503 public void actionPerformed(ActionEvent e)
1505 hydrophobicityColour_actionPerformed();
1508 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1509 helixColour.addActionListener(new java.awt.event.ActionListener()
1512 public void actionPerformed(ActionEvent e)
1514 helixColour_actionPerformed();
1517 strandColour.setText(MessageManager
1518 .getString("label.strand_propensity"));
1519 strandColour.addActionListener(new java.awt.event.ActionListener()
1522 public void actionPerformed(ActionEvent e)
1524 strandColour_actionPerformed();
1527 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1528 turnColour.addActionListener(new java.awt.event.ActionListener()
1531 public void actionPerformed(ActionEvent e)
1533 turnColour_actionPerformed();
1536 buriedColour.setText(MessageManager.getString("label.buried_index"));
1537 buriedColour.addActionListener(new java.awt.event.ActionListener()
1540 public void actionPerformed(ActionEvent e)
1542 buriedColour_actionPerformed();
1545 abovePIDColour.setText(MessageManager
1546 .getString("label.above_identity_percentage"));
1547 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1550 public void actionPerformed(ActionEvent e)
1552 abovePIDColour_actionPerformed();
1555 userDefinedColour.setText(MessageManager
1556 .getString("action.user_defined"));
1557 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1560 public void actionPerformed(ActionEvent e)
1562 userDefinedColour_actionPerformed(e);
1566 .setText(MessageManager.getString("label.percentage_identity"));
1567 PIDColour.addActionListener(new java.awt.event.ActionListener()
1570 public void actionPerformed(ActionEvent e)
1572 PIDColour_actionPerformed();
1575 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1576 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1579 public void actionPerformed(ActionEvent e)
1581 BLOSUM62Colour_actionPerformed();
1584 purinePyrimidineColour.setText(MessageManager
1585 .getString("label.purine_pyrimidine"));
1586 purinePyrimidineColour
1587 .addActionListener(new java.awt.event.ActionListener()
1590 public void actionPerformed(ActionEvent e)
1592 purinePyrimidineColour_actionPerformed();
1597 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1598 * public void actionPerformed(ActionEvent e) {
1599 * covariationColour_actionPerformed(); } });
1602 conservationMenuItem.setText(MessageManager
1603 .getString("label.conservation"));
1604 conservationMenuItem
1605 .addActionListener(new java.awt.event.ActionListener()
1608 public void actionPerformed(ActionEvent e)
1610 conservationMenuItem_actionPerformed();
1616 * Check for any annotations on the underlying dataset sequences (for the
1617 * current selection group) which are not 'on the alignment'.If any are found,
1618 * enable the option to add them to the alignment. The criteria for 'on the
1619 * alignment' is finding an alignment annotation on the alignment, matched on
1620 * calcId, label and sequenceRef.
1622 * A tooltip is also constructed that displays the source (calcId) and type
1623 * (label) of the annotations that can be added.
1626 * @param forSequences
1628 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1629 List<SequenceI> forSequences)
1631 menuItem.setEnabled(false);
1634 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1635 * Using TreeMap means calcIds are shown in alphabetical order.
1637 Map<String, String> tipEntries = new TreeMap<String, String>();
1638 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1639 AlignmentI al = this.ap.av.getAlignment();
1640 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1641 tipEntries, candidates, al);
1642 if (!candidates.isEmpty())
1644 StringBuilder tooltip = new StringBuilder(64);
1645 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1648 * Found annotations that could be added. Enable the menu item, and
1649 * configure its tooltip and action.
1651 menuItem.setEnabled(true);
1652 for (String calcId : tipEntries.keySet())
1654 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1656 String tooltipText = JvSwingUtils.wrapTooltip(true,
1657 tooltip.toString());
1658 menuItem.setToolTipText(tooltipText);
1660 menuItem.addActionListener(new ActionListener()
1663 public void actionPerformed(ActionEvent e)
1665 addReferenceAnnotations_actionPerformed(candidates);
1672 * Add annotations to the sequences and to the alignment.
1675 * a map whose keys are sequences on the alignment, and values a list
1676 * of annotations to add to each sequence
1678 protected void addReferenceAnnotations_actionPerformed(
1679 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1681 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1682 final AlignmentI alignment = this.ap.getAlignment();
1683 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1688 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1690 if (!ap.av.getAlignment().hasSeqrep())
1692 // initialise the display flags so the user sees something happen
1693 ap.av.setDisplayReferenceSeq(true);
1694 ap.av.setColourByReferenceSeq(true);
1695 ap.av.getAlignment().setSeqrep(sequence);
1699 if (ap.av.getAlignment().getSeqrep() == sequence)
1701 ap.av.getAlignment().setSeqrep(null);
1705 ap.av.getAlignment().setSeqrep(sequence);
1711 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1713 if (sequence != null)
1715 ColumnSelection cs = ap.av.getColumnSelection();
1718 cs = new ColumnSelection();
1720 cs.hideInsertionsFor(sequence);
1721 ap.av.setColumnSelection(cs);
1726 protected void sequenceSelectionDetails_actionPerformed()
1728 createSequenceDetailsReport(ap.av.getSequenceSelection());
1731 protected void sequenceDetails_actionPerformed()
1733 createSequenceDetailsReport(new SequenceI[] { sequence });
1736 public void createSequenceDetailsReport(SequenceI[] sequences)
1738 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1739 StringBuffer contents = new StringBuffer();
1740 for (SequenceI seq : sequences)
1742 contents.append("<p><h2>"
1745 "label.create_sequence_details_report_annotation_for",
1746 new Object[] { seq.getDisplayId(true) })
1748 new SequenceAnnotationReport(null)
1749 .createSequenceAnnotationReport(
1755 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1756 .getSeqPanel().seqCanvas.fr.getMinMax()
1758 contents.append("</p>");
1760 cap.setText("<html>" + contents.toString() + "</html>");
1762 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1763 "label.sequence_details_for",
1764 (sequences.length == 1 ? new Object[] { sequences[0]
1765 .getDisplayId(true) } : new Object[] { MessageManager
1766 .getString("label.selection") })), 500, 400);
1770 protected void showNonconserved_actionPerformed()
1772 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1777 * call to refresh view after settings change
1781 ap.updateAnnotation();
1782 ap.paintAlignment(true);
1784 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1793 protected void clustalColour_actionPerformed()
1795 SequenceGroup sg = getGroup();
1796 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1806 protected void zappoColour_actionPerformed()
1808 getGroup().cs = new ZappoColourScheme();
1818 protected void taylorColour_actionPerformed()
1820 getGroup().cs = new TaylorColourScheme();
1830 protected void hydrophobicityColour_actionPerformed()
1832 getGroup().cs = new HydrophobicColourScheme();
1842 protected void helixColour_actionPerformed()
1844 getGroup().cs = new HelixColourScheme();
1854 protected void strandColour_actionPerformed()
1856 getGroup().cs = new StrandColourScheme();
1866 protected void turnColour_actionPerformed()
1868 getGroup().cs = new TurnColourScheme();
1878 protected void buriedColour_actionPerformed()
1880 getGroup().cs = new BuriedColourScheme();
1890 public void nucleotideMenuItem_actionPerformed()
1892 getGroup().cs = new NucleotideColourScheme();
1896 protected void purinePyrimidineColour_actionPerformed()
1898 getGroup().cs = new PurinePyrimidineColourScheme();
1903 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1904 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1912 protected void abovePIDColour_actionPerformed()
1914 SequenceGroup sg = getGroup();
1920 if (abovePIDColour.isSelected())
1922 sg.cs.setConsensus(AAFrequency.calculate(
1923 sg.getSequences(ap.av.getHiddenRepSequences()),
1924 sg.getStartRes(), sg.getEndRes() + 1));
1926 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1929 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1931 SliderPanel.showPIDSlider();
1934 // remove PIDColouring
1936 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1948 protected void userDefinedColour_actionPerformed(ActionEvent e)
1950 SequenceGroup sg = getGroup();
1952 if (e.getSource().equals(userDefinedColour))
1954 new UserDefinedColours(ap, sg);
1958 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1959 .getUserColourSchemes().get(e.getActionCommand());
1967 * Open a panel where the user can choose which types of sequence annotation
1972 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1974 // todo correct way to guard against opening a duplicate panel?
1975 new AnnotationChooser(ap);
1984 protected void PIDColour_actionPerformed()
1986 SequenceGroup sg = getGroup();
1987 sg.cs = new PIDColourScheme();
1988 sg.cs.setConsensus(AAFrequency.calculate(
1989 sg.getSequences(ap.av.getHiddenRepSequences()),
1990 sg.getStartRes(), sg.getEndRes() + 1));
2000 protected void BLOSUM62Colour_actionPerformed()
2002 SequenceGroup sg = getGroup();
2004 sg.cs = new Blosum62ColourScheme();
2006 sg.cs.setConsensus(AAFrequency.calculate(
2007 sg.getSequences(ap.av.getHiddenRepSequences()),
2008 sg.getStartRes(), sg.getEndRes() + 1));
2019 protected void noColourmenuItem_actionPerformed()
2021 getGroup().cs = null;
2031 protected void conservationMenuItem_actionPerformed()
2033 SequenceGroup sg = getGroup();
2039 if (conservationMenuItem.isSelected())
2041 // JBPNote: Conservation name shouldn't be i18n translated
2042 Conservation c = new Conservation("Group",
2043 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2044 .getHiddenRepSequences()), sg.getStartRes(),
2045 sg.getEndRes() + 1);
2048 c.verdict(false, ap.av.getConsPercGaps());
2050 sg.cs.setConservation(c);
2052 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2053 SliderPanel.showConservationSlider();
2056 // remove ConservationColouring
2058 sg.cs.setConservation(null);
2064 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2066 SequenceGroup sg = getGroup();
2072 AnnotationColourGradient acg = new AnnotationColourGradient(
2073 sequence.getAnnotation()[0], null,
2074 AnnotationColourGradient.NO_THRESHOLD);
2076 acg.setPredefinedColours(true);
2088 protected void groupName_actionPerformed()
2091 SequenceGroup sg = getGroup();
2092 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2093 sg.getDescription(), " "
2094 + MessageManager.getString("label.group_name") + " ",
2095 MessageManager.getString("label.group_description") + " ",
2096 MessageManager.getString("label.edit_group_name_description"),
2104 sg.setName(dialog.getName());
2105 sg.setDescription(dialog.getDescription());
2110 * Get selection group - adding it to the alignment if necessary.
2112 * @return sequence group to operate on
2114 SequenceGroup getGroup()
2116 SequenceGroup sg = ap.av.getSelectionGroup();
2117 // this method won't add a new group if it already exists
2120 ap.av.getAlignment().addGroup(sg);
2132 void sequenceName_actionPerformed()
2134 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2135 sequence.getDescription(),
2136 " " + MessageManager.getString("label.sequence_name")
2138 MessageManager.getString("label.sequence_description") + " ",
2140 .getString("label.edit_sequence_name_description"),
2148 if (dialog.getName() != null)
2150 if (dialog.getName().indexOf(" ") > -1)
2156 .getString("label.spaces_converted_to_backslashes"),
2158 .getString("label.no_spaces_allowed_sequence_name"),
2159 JOptionPane.WARNING_MESSAGE);
2162 sequence.setName(dialog.getName().replace(' ', '_'));
2163 ap.paintAlignment(false);
2166 sequence.setDescription(dialog.getDescription());
2168 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2179 void unGroupMenuItem_actionPerformed()
2181 SequenceGroup sg = ap.av.getSelectionGroup();
2182 ap.av.getAlignment().deleteGroup(sg);
2183 ap.av.setSelectionGroup(null);
2187 void createGroupMenuItem_actionPerformed()
2189 getGroup(); // implicitly creates group - note - should apply defaults / use
2190 // standard alignment window logic for this
2200 protected void outline_actionPerformed()
2202 SequenceGroup sg = getGroup();
2203 Color col = JColorChooser.showDialog(this,
2204 MessageManager.getString("label.select_outline_colour"),
2209 sg.setOutlineColour(col);
2221 public void showBoxes_actionPerformed()
2223 getGroup().setDisplayBoxes(showBoxes.isSelected());
2233 public void showText_actionPerformed()
2235 getGroup().setDisplayText(showText.isSelected());
2245 public void showColourText_actionPerformed()
2247 getGroup().setColourText(showColourText.isSelected());
2251 public void showLink(String url)
2255 jalview.util.BrowserLauncher.openURL(url);
2256 } catch (Exception ex)
2258 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2259 MessageManager.getString("label.web_browser_not_found_unix"),
2260 MessageManager.getString("label.web_browser_not_found"),
2261 JOptionPane.WARNING_MESSAGE);
2263 ex.printStackTrace();
2267 void hideSequences(boolean representGroup)
2269 ap.av.hideSequences(sequence, representGroup);
2272 public void copy_actionPerformed()
2274 ap.alignFrame.copy_actionPerformed(null);
2277 public void cut_actionPerformed()
2279 ap.alignFrame.cut_actionPerformed(null);
2282 void changeCase(ActionEvent e)
2284 Object source = e.getSource();
2285 SequenceGroup sg = ap.av.getSelectionGroup();
2289 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2290 sg.getStartRes(), sg.getEndRes() + 1);
2295 if (source == toggle)
2297 description = MessageManager.getString("label.toggle_case");
2298 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2300 else if (source == upperCase)
2302 description = MessageManager.getString("label.to_upper_case");
2303 caseChange = ChangeCaseCommand.TO_UPPER;
2307 description = MessageManager.getString("label.to_lower_case");
2308 caseChange = ChangeCaseCommand.TO_LOWER;
2311 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2312 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2313 startEnd, caseChange);
2315 ap.alignFrame.addHistoryItem(caseCommand);
2317 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2323 public void outputText_actionPerformed(ActionEvent e)
2325 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2326 cap.setForInput(null);
2327 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2328 "label.alignment_output_command",
2329 new Object[] { e.getActionCommand() }), 600, 500);
2331 String[] omitHidden = null;
2333 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2334 // or we simply trust the user wants
2335 // wysiwig behaviour
2337 cap.setText(new FormatAdapter(ap).formatSequences(e.getActionCommand(),
2341 public void sequenceFeature_actionPerformed()
2343 SequenceGroup sg = ap.av.getSelectionGroup();
2349 int rsize = 0, gSize = sg.getSize();
2350 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2351 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2353 for (int i = 0; i < gSize; i++)
2355 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2356 int end = sg.findEndRes(sg.getSequenceAt(i));
2359 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2360 features[rsize] = new SequenceFeature(null, null, null, start, end,
2365 rseqs = new SequenceI[rsize];
2366 tfeatures = new SequenceFeature[rsize];
2367 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2368 System.arraycopy(features, 0, tfeatures, 0, rsize);
2369 features = tfeatures;
2371 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2372 features, true, ap))
2374 ap.alignFrame.setShowSeqFeatures(true);
2375 ap.highlightSearchResults(null);
2379 public void textColour_actionPerformed()
2381 SequenceGroup sg = getGroup();
2384 new TextColourChooser().chooseColour(ap, sg);
2388 public void colourByStructure(String pdbid)
2390 Annotation[] anots = ap.av.getStructureSelectionManager()
2391 .colourSequenceFromStructure(sequence, pdbid);
2393 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2394 "Coloured by " + pdbid, anots);
2396 ap.av.getAlignment().addAnnotation(an);
2397 an.createSequenceMapping(sequence, 0, true);
2398 // an.adjustForAlignment();
2399 ap.av.getAlignment().setAnnotationIndex(an, 0);
2401 ap.adjustAnnotationHeight();
2403 sequence.addAlignmentAnnotation(an);
2407 public void editSequence_actionPerformed(ActionEvent actionEvent)
2409 SequenceGroup sg = ap.av.getSelectionGroup();
2413 if (sequence == null)
2415 sequence = sg.getSequenceAt(0);
2418 EditNameDialog dialog = new EditNameDialog(
2419 sequence.getSequenceAsString(sg.getStartRes(),
2420 sg.getEndRes() + 1), null,
2421 MessageManager.getString("label.edit_sequence"), null,
2422 MessageManager.getString("label.edit_sequence"),
2427 EditCommand editCommand = new EditCommand(
2428 MessageManager.getString("label.edit_sequences"),
2429 Action.REPLACE, dialog.getName().replace(' ',
2430 ap.av.getGapCharacter()),
2431 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2432 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2434 ap.alignFrame.addHistoryItem(editCommand);
2436 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()