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.DBRefEntry;
35 import jalview.datamodel.HiddenColumns;
36 import jalview.datamodel.PDBEntry;
37 import jalview.datamodel.ResidueCount;
38 import jalview.datamodel.SequenceFeature;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.gui.ColourMenuHelper.ColourChangeListener;
42 import jalview.io.CountReader;
43 import jalview.io.FileFormatI;
44 import jalview.io.FileFormats;
45 import jalview.io.FormatAdapter;
46 import jalview.io.SequenceAnnotationReport;
47 import jalview.schemes.Blosum62ColourScheme;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.schemes.ColourSchemes;
50 import jalview.schemes.PIDColourScheme;
51 import jalview.schemes.ResidueColourScheme;
52 import jalview.util.GroupUrlLink;
53 import jalview.util.GroupUrlLink.UrlStringTooLongException;
54 import jalview.util.MessageManager;
55 import jalview.util.StringUtils;
56 import jalview.util.UrlLink;
58 import java.awt.Color;
59 import java.awt.event.ActionEvent;
60 import java.awt.event.ActionListener;
61 import java.io.IOException;
62 import java.net.MalformedURLException;
63 import java.util.ArrayList;
64 import java.util.Arrays;
65 import java.util.BitSet;
66 import java.util.Collection;
67 import java.util.Collections;
68 import java.util.Hashtable;
69 import java.util.LinkedHashMap;
70 import java.util.List;
72 import java.util.SortedMap;
73 import java.util.TreeMap;
74 import java.util.Vector;
76 import javax.swing.ButtonGroup;
77 import javax.swing.JCheckBoxMenuItem;
78 import javax.swing.JColorChooser;
79 import javax.swing.JMenu;
80 import javax.swing.JMenuItem;
81 import javax.swing.JPopupMenu;
82 import javax.swing.JRadioButtonMenuItem;
85 * The popup menu that is displayed on right-click on a sequence id, or in the
88 public class PopupMenu extends JPopupMenu implements ColourChangeListener
90 JMenu groupMenu = new JMenu();
92 JMenuItem groupName = new JMenuItem();
94 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
96 protected JMenuItem modifyPID = new JMenuItem();
98 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
100 protected JRadioButtonMenuItem annotationColour;
102 protected JMenuItem modifyConservation = new JMenuItem();
106 JMenu sequenceMenu = new JMenu();
108 JMenuItem sequenceName = new JMenuItem();
110 JMenuItem sequenceDetails = new JMenuItem();
112 JMenuItem sequenceSelDetails = new JMenuItem();
114 JMenuItem makeReferenceSeq = new JMenuItem();
116 JMenuItem chooseAnnotations = new JMenuItem();
120 JMenuItem createGroupMenuItem = new JMenuItem();
122 JMenuItem unGroupMenuItem = new JMenuItem();
124 JMenuItem outline = new JMenuItem();
126 JMenu colourMenu = new JMenu();
128 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
130 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
132 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
134 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
136 JMenu editMenu = new JMenu();
138 JMenuItem cut = new JMenuItem();
140 JMenuItem copy = new JMenuItem();
142 JMenuItem upperCase = new JMenuItem();
144 JMenuItem lowerCase = new JMenuItem();
146 JMenuItem toggle = new JMenuItem();
148 JMenu pdbMenu = new JMenu();
150 JMenu outputMenu = new JMenu();
152 JMenu seqShowAnnotationsMenu = new JMenu();
154 JMenu seqHideAnnotationsMenu = new JMenu();
156 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
157 MessageManager.getString("label.add_reference_annotations"));
159 JMenu groupShowAnnotationsMenu = new JMenu();
161 JMenu groupHideAnnotationsMenu = new JMenu();
163 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
164 MessageManager.getString("label.add_reference_annotations"));
166 JMenuItem sequenceFeature = new JMenuItem();
169 JMenuItem textColour = new JMenuItem();
171 JMenu jMenu1 = new JMenu();
173 JMenuItem pdbStructureDialog = new JMenuItem();
175 JMenu rnaStructureMenu = new JMenu();
177 JMenuItem editSequence = new JMenuItem();
179 JMenu groupLinksMenu;
181 JMenuItem hideInsertions = new JMenuItem();
184 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
185 * and/or features provided. Hyperlinks may include a lookup by sequence id,
186 * or database cross-references, depending on which links are enabled in user
193 static JMenu buildLinkMenu(final SequenceI seq,
194 List<SequenceFeature> features)
196 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
198 List<String> nlinks = null;
201 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
202 UrlLink.sort(nlinks);
206 nlinks = new ArrayList<>();
209 if (features != null)
211 for (SequenceFeature sf : features)
213 if (sf.links != null)
215 for (String link : sf.links)
224 * instantiate the hyperlinklink templates from sequence data;
225 * note the order of the templates is preserved in the map
227 Map<String, List<String>> linkset = new LinkedHashMap<>();
228 for (String link : nlinks)
230 UrlLink urlLink = null;
233 urlLink = new UrlLink(link);
234 } catch (Exception foo)
236 Cache.log.error("Exception for URLLink '" + link + "'", foo);
240 if (!urlLink.isValid())
242 Cache.log.error(urlLink.getInvalidMessage());
246 urlLink.createLinksFromSeq(seq, linkset);
250 * construct menu items for the hyperlinks (still preserving
251 * the order of the sorted templates)
253 addUrlLinks(linkMenu, linkset.values());
259 * A helper method that builds menu items from the given links, with action
260 * handlers to open the link URL, and adds them to the linkMenu. Each provided
261 * link should be a list whose second item is the menu text, and whose fourth
262 * item is the URL to open when the menu item is selected.
267 static private void addUrlLinks(JMenu linkMenu,
268 Collection<List<String>> linkset)
270 for (List<String> linkstrset : linkset)
272 final String url = linkstrset.get(3);
273 JMenuItem item = new JMenuItem(linkstrset.get(1));
274 item.setToolTipText(MessageManager
275 .formatMessage("label.open_url_param", new Object[]
277 item.addActionListener(new ActionListener()
280 public void actionPerformed(ActionEvent e)
282 new Thread(new Runnable()
297 * Opens the provided url in the default web browser, or shows an error
298 * message if this fails
302 static void showLink(String url)
306 jalview.util.BrowserLauncher.openURL(url);
307 } catch (Exception ex)
309 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
310 MessageManager.getString("label.web_browser_not_found_unix"),
311 MessageManager.getString("label.web_browser_not_found"),
312 JvOptionPane.WARNING_MESSAGE);
314 ex.printStackTrace();
319 * add a late bound groupURL item to the given linkMenu
323 * - menu label string
324 * @param urlgenerator
325 * GroupURLLink used to generate URL
327 * Object array returned from the makeUrlStubs function.
329 static void addshowLink(JMenu linkMenu, String label,
330 final GroupUrlLink urlgenerator, final Object[] urlstub)
332 JMenuItem item = new JMenuItem(label);
333 item.setToolTipText(MessageManager
334 .formatMessage("label.open_url_seqs_param", new Object[]
335 { urlgenerator.getUrl_prefix(),
336 urlgenerator.getNumberInvolved(urlstub) }));
337 // TODO: put in info about what is being sent.
338 item.addActionListener(new ActionListener()
341 public void actionPerformed(ActionEvent e)
343 new Thread(new Runnable()
351 showLink(urlgenerator.constructFrom(urlstub));
352 } catch (UrlStringTooLongException e2)
365 * Creates a new PopupMenu object.
370 * non-positional features (for seq not null), or positional features
371 * at residue (for seq equal to null)
373 public PopupMenu(final AlignmentPanel ap, SequenceI seq,
374 List<SequenceFeature> features)
376 this(ap, seq, features, null);
384 * the sequence under the cursor if in the Id panel, null if in the
387 * non-positional features if in the Id panel, features at the
388 * clicked residue if in the sequence panel
391 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
392 List<SequenceFeature> features, List<String> groupLinks)
394 // /////////////////////////////////////////////////////////
395 // If this is activated from the sequence panel, the user may want to
396 // edit or annotate a particular residue. Therefore display the residue menu
398 // If from the IDPanel, we must display the sequence menu
399 // ////////////////////////////////////////////////////////
400 this.ap = alignPanel;
403 for (String ff : FileFormats.getInstance().getWritableFormats(true))
405 JMenuItem item = new JMenuItem(ff);
407 item.addActionListener(new ActionListener()
410 public void actionPerformed(ActionEvent e)
412 outputText_actionPerformed(e);
416 outputMenu.add(item);
420 * Build menus for annotation types that may be shown or hidden, and for
421 * 'reference annotations' that may be added to the alignment. First for the
422 * currently selected sequence (if there is one):
424 final List<SequenceI> selectedSequence = (seq == null
425 ? Collections.<SequenceI> emptyList() : Arrays.asList(seq));
427 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
428 seqHideAnnotationsMenu, selectedSequence);
429 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
433 * And repeat for the current selection group (if there is one):
435 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
436 ? Collections.<SequenceI> emptyList()
437 : alignPanel.av.getSelectionGroup().getSequences());
438 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
439 groupHideAnnotationsMenu, selectedGroup);
440 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
446 } catch (Exception e)
454 sequenceMenu.setText(sequence.getName());
455 if (seq == alignPanel.av.getAlignment().getSeqrep())
457 makeReferenceSeq.setText(
458 MessageManager.getString("action.unmark_as_reference"));
462 makeReferenceSeq.setText(
463 MessageManager.getString("action.set_as_reference"));
466 if (!alignPanel.av.getAlignment().isNucleotide())
468 remove(rnaStructureMenu);
472 int origCount = rnaStructureMenu.getItemCount();
474 * add menu items to 2D-render any alignment or sequence secondary
475 * structure annotation
477 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
478 .getAlignmentAnnotation();
481 for (final AlignmentAnnotation aa : aas)
483 if (aa.isValidStruc() && aa.sequenceRef == null)
486 * valid alignment RNA secondary structure annotation
488 menuItem = new JMenuItem();
489 menuItem.setText(MessageManager.formatMessage(
490 "label.2d_rna_structure_line", new Object[]
492 menuItem.addActionListener(new ActionListener()
495 public void actionPerformed(ActionEvent e)
497 new AppVarna(seq, aa, alignPanel);
500 rnaStructureMenu.add(menuItem);
505 if (seq.getAnnotation() != null)
507 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
508 for (final AlignmentAnnotation aa : seqAnns)
510 if (aa.isValidStruc())
513 * valid sequence RNA secondary structure annotation
515 // TODO: make rnastrucF a bit more nice
516 menuItem = new JMenuItem();
517 menuItem.setText(MessageManager.formatMessage(
518 "label.2d_rna_sequence_name", new Object[]
520 menuItem.addActionListener(new ActionListener()
523 public void actionPerformed(ActionEvent e)
525 // TODO: VARNA does'nt print gaps in the sequence
526 new AppVarna(seq, aa, alignPanel);
529 rnaStructureMenu.add(menuItem);
533 if (rnaStructureMenu.getItemCount() == origCount)
535 remove(rnaStructureMenu);
539 if (seq.hasHMMProfile())
541 menuItem = new JMenuItem(MessageManager
542 .getString("action.add_background_frequencies"));
543 menuItem.addActionListener(new ActionListener()
546 public void actionPerformed(ActionEvent e)
550 ResidueCount counts = CountReader.getBackgroundFrequencies(ap,
554 seq.getHMM().setBackgroundFrequencies(counts);
555 ap.alignFrame.buildColourMenu();
557 } catch (MalformedURLException e1)
559 e1.printStackTrace();
560 } catch (IOException e1)
562 e1.printStackTrace();
569 menuItem = new JMenuItem(
570 MessageManager.getString("action.hide_sequences"));
571 menuItem.addActionListener(new ActionListener()
574 public void actionPerformed(ActionEvent e)
576 hideSequences(false);
581 if (alignPanel.av.getSelectionGroup() != null
582 && alignPanel.av.getSelectionGroup().getSize() > 1)
584 menuItem = new JMenuItem(MessageManager
585 .formatMessage("label.represent_group_with", new Object[]
587 menuItem.addActionListener(new ActionListener()
590 public void actionPerformed(ActionEvent e)
595 sequenceMenu.add(menuItem);
598 if (alignPanel.av.hasHiddenRows())
600 final int index = alignPanel.av.getAlignment().findIndex(seq);
602 if (alignPanel.av.adjustForHiddenSeqs(index)
603 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
605 menuItem = new JMenuItem(
606 MessageManager.getString("action.reveal_sequences"));
607 menuItem.addActionListener(new ActionListener()
610 public void actionPerformed(ActionEvent e)
612 alignPanel.av.showSequence(index);
613 if (alignPanel.overviewPanel != null)
615 alignPanel.overviewPanel.updateOverviewImage();
626 * - in the IdPanel (seq not null) if any sequence is hidden
627 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
629 if (alignPanel.av.hasHiddenRows())
631 boolean addOption = seq != null;
632 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
638 menuItem = new JMenuItem(
639 MessageManager.getString("action.reveal_all"));
640 menuItem.addActionListener(new ActionListener()
643 public void actionPerformed(ActionEvent e)
645 alignPanel.av.showAllHiddenSeqs();
646 if (alignPanel.overviewPanel != null)
648 alignPanel.overviewPanel.updateOverviewImage();
656 SequenceGroup sg = alignPanel.av.getSelectionGroup();
657 boolean isDefinedGroup = (sg != null)
658 ? alignPanel.av.getAlignment().getGroups().contains(sg)
661 if (sg != null && sg.getSize() > 0)
663 groupName.setText(MessageManager
664 .getString("label.edit_name_and_description_current_group"));
666 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
668 conservationMenuItem.setEnabled(!sg.isNucleotide());
672 if (sg.cs.conservationApplied())
674 conservationMenuItem.setSelected(true);
676 if (sg.cs.getThreshold() > 0)
678 abovePIDColour.setSelected(true);
681 modifyConservation.setEnabled(conservationMenuItem.isSelected());
682 modifyPID.setEnabled(abovePIDColour.isSelected());
683 displayNonconserved.setSelected(sg.getShowNonconserved());
684 showText.setSelected(sg.getDisplayText());
685 showColourText.setSelected(sg.getColourText());
686 showBoxes.setSelected(sg.getDisplayBoxes());
687 // add any groupURLs to the groupURL submenu and make it visible
688 if (groupLinks != null && groupLinks.size() > 0)
690 buildGroupURLMenu(sg, groupLinks);
692 // Add a 'show all structures' for the current selection
693 Hashtable<String, PDBEntry> pdbe = new Hashtable<>();
694 Hashtable<String, PDBEntry> reppdb = new Hashtable<>();
696 SequenceI sqass = null;
697 for (SequenceI sq : alignPanel.av.getSequenceSelection())
699 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
700 if (pes != null && pes.size() > 0)
702 reppdb.put(pes.get(0).getId(), pes.get(0));
703 for (PDBEntry pe : pes)
705 pdbe.put(pe.getId(), pe);
715 final PDBEntry[] pe = pdbe.values()
716 .toArray(new PDBEntry[pdbe.size()]),
717 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
718 final JMenuItem gpdbview, rpdbview;
723 groupMenu.setVisible(false);
724 editMenu.setVisible(false);
729 createGroupMenuItem.setVisible(true);
730 unGroupMenuItem.setVisible(false);
731 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
735 createGroupMenuItem.setVisible(false);
736 unGroupMenuItem.setVisible(true);
737 jMenu1.setText(MessageManager.getString("action.edit_group"));
742 sequenceMenu.setVisible(false);
743 pdbStructureDialog.setVisible(false);
744 rnaStructureMenu.setVisible(false);
747 addLinks(seq, features);
751 addFeatureDetails(features);
756 * Add a link to show feature details for each sequence feature
760 protected void addFeatureDetails(List<SequenceFeature> features)
762 if (features == null || features.isEmpty())
766 JMenu details = new JMenu(
767 MessageManager.getString("label.feature_details"));
770 for (final SequenceFeature sf : features)
772 int start = sf.getBegin();
773 int end = sf.getEnd();
777 desc = String.format("%s %d", sf.getType(), start);
781 desc = String.format("%s %d-%d", sf.getType(), start, end);
783 String tooltip = desc;
784 String description = sf.getDescription();
785 if (description != null)
787 description = StringUtils.stripHtmlTags(description);
788 if (description.length() > 12)
790 desc = desc + " " + description.substring(0, 12) + "..";
794 desc = desc + " " + description;
796 tooltip = tooltip + " " + description;
798 if (sf.getFeatureGroup() != null)
800 tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
802 JMenuItem item = new JMenuItem(desc);
803 item.setToolTipText(tooltip);
804 item.addActionListener(new ActionListener()
807 public void actionPerformed(ActionEvent e)
809 showFeatureDetails(sf);
817 * Opens a panel showing a text report of feature dteails
821 protected void showFeatureDetails(SequenceFeature sf)
823 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
824 // it appears Java's CSS does not support border-collaps :-(
825 cap.addStylesheetRule("table { border-collapse: collapse;}");
826 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
827 cap.setText(sf.getDetailsReport());
829 Desktop.addInternalFrame(cap,
830 MessageManager.getString("label.feature_details"), 500, 500);
834 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
835 * When seq is not null, these are links for the sequence id, which may be to
836 * external web sites for the sequence accession, and/or links embedded in
837 * non-positional features. When seq is null, only links embedded in the
838 * provided features are added. If no links are found, the menu is not added.
843 void addLinks(final SequenceI seq, List<SequenceFeature> features)
845 JMenu linkMenu = buildLinkMenu(seq, features);
847 // only add link menu if it has entries
848 if (linkMenu.getItemCount() > 0)
850 if (sequence != null)
852 sequenceMenu.add(linkMenu);
862 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
863 * "All" is added first, followed by a separator. Then add any annotation
864 * types associated with the current selection. Separate menus are built for
865 * the selected sequence group (if any), and the selected sequence.
867 * Some annotation rows are always rendered together - these can be identified
868 * by a common graphGroup property > -1. Only one of each group will be marked
869 * as visible (to avoid duplication of the display). For such groups we add a
870 * composite type name, e.g.
872 * IUPredWS (Long), IUPredWS (Short)
876 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
877 List<SequenceI> forSequences)
879 showMenu.removeAll();
880 hideMenu.removeAll();
882 final List<String> all = Arrays
884 { MessageManager.getString("label.all") });
885 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
887 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
889 showMenu.addSeparator();
890 hideMenu.addSeparator();
892 final AlignmentAnnotation[] annotations = ap.getAlignment()
893 .getAlignmentAnnotation();
896 * Find shown/hidden annotations types, distinguished by source (calcId),
897 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
898 * the insertion order, which is the order of the annotations on the
901 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
902 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
903 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
904 AlignmentAnnotationUtils.asList(annotations), forSequences);
906 for (String calcId : hiddenTypes.keySet())
908 for (List<String> type : hiddenTypes.get(calcId))
910 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
914 // grey out 'show annotations' if none are hidden
915 showMenu.setEnabled(!hiddenTypes.isEmpty());
917 for (String calcId : shownTypes.keySet())
919 for (List<String> type : shownTypes.get(calcId))
921 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
925 // grey out 'hide annotations' if none are shown
926 hideMenu.setEnabled(!shownTypes.isEmpty());
930 * Returns a list of sequences - either the current selection group (if there
931 * is one), else the specified single sequence.
936 protected List<SequenceI> getSequenceScope(SequenceI seq)
938 List<SequenceI> forSequences = null;
939 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
940 if (selectionGroup != null && selectionGroup.getSize() > 0)
942 forSequences = selectionGroup.getSequences();
946 forSequences = seq == null ? Collections.<SequenceI> emptyList()
947 : Arrays.asList(seq);
953 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
956 * @param showOrHideMenu
958 * @param forSequences
959 * the sequences whose annotations may be shown or hidden
964 * if true this is a special label meaning 'All'
965 * @param actionIsShow
966 * if true, the select menu item action is to show the annotation
969 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
970 final List<SequenceI> forSequences, String calcId,
971 final List<String> types, final boolean allTypes,
972 final boolean actionIsShow)
974 String label = types.toString(); // [a, b, c]
975 label = label.substring(1, label.length() - 1); // a, b, c
976 final JMenuItem item = new JMenuItem(label);
977 item.setToolTipText(calcId);
978 item.addActionListener(new ActionListener()
981 public void actionPerformed(ActionEvent e)
983 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
984 types, forSequences, allTypes, actionIsShow);
988 showOrHideMenu.add(item);
991 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
994 // TODO: usability: thread off the generation of group url content so root
996 // sequence only URLs
997 // ID/regex match URLs
998 groupLinksMenu = new JMenu(
999 MessageManager.getString("action.group_link"));
1000 // three types of url that might be created.
1001 JMenu[] linkMenus = new JMenu[] { null,
1002 new JMenu(MessageManager.getString("action.ids")),
1003 new JMenu(MessageManager.getString("action.sequences")),
1004 new JMenu(MessageManager.getString("action.ids_sequences")) };
1006 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1007 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1008 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
1009 for (int sq = 0; sq < seqs.length; sq++)
1012 int start = seqs[sq].findPosition(sg.getStartRes()),
1013 end = seqs[sq].findPosition(sg.getEndRes());
1014 // just collect ids from dataset sequence
1015 // TODO: check if IDs collected from selecton group intersects with the
1016 // current selection, too
1017 SequenceI sqi = seqs[sq];
1018 while (sqi.getDatasetSequence() != null)
1020 sqi = sqi.getDatasetSequence();
1022 DBRefEntry[] dbr = sqi.getDBRefs();
1023 if (dbr != null && dbr.length > 0)
1025 for (int d = 0; d < dbr.length; d++)
1027 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1028 Object[] sarray = commonDbrefs.get(src);
1031 sarray = new Object[2];
1032 sarray[0] = new int[] { 0 };
1033 sarray[1] = new String[seqs.length];
1035 commonDbrefs.put(src, sarray);
1038 if (((String[]) sarray[1])[sq] == null)
1040 if (!dbr[d].hasMap() || (dbr[d].getMap()
1041 .locateMappedRange(start, end) != null))
1043 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1044 ((int[]) sarray[0])[0]++;
1050 // now create group links for all distinct ID/sequence sets.
1051 boolean addMenu = false; // indicates if there are any group links to give
1053 for (String link : groupLinks)
1055 GroupUrlLink urlLink = null;
1058 urlLink = new GroupUrlLink(link);
1059 } catch (Exception foo)
1061 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
1065 if (!urlLink.isValid())
1067 Cache.log.error(urlLink.getInvalidMessage());
1070 final String label = urlLink.getLabel();
1071 boolean usingNames = false;
1072 // Now see which parts of the group apply for this URL
1073 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1074 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
1075 String[] seqstr, ids; // input to makeUrl
1078 int numinput = ((int[]) idset[0])[0];
1079 String[] allids = ((String[]) idset[1]);
1080 seqstr = new String[numinput];
1081 ids = new String[numinput];
1082 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1084 if (allids[sq] != null)
1086 ids[idcount] = allids[sq];
1087 seqstr[idcount++] = idandseqs[1][sq];
1093 // just use the id/seq set
1094 seqstr = idandseqs[1];
1098 // and try and make the groupURL!
1100 Object[] urlset = null;
1103 urlset = urlLink.makeUrlStubs(ids, seqstr,
1104 "FromJalview" + System.currentTimeMillis(), false);
1105 } catch (UrlStringTooLongException e)
1110 int type = urlLink.getGroupURLType() & 3;
1111 // first two bits ofurlLink type bitfield are sequenceids and sequences
1112 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1113 addshowLink(linkMenus[type],
1114 label + (((type & 1) == 1)
1115 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1123 groupLinksMenu = new JMenu(
1124 MessageManager.getString("action.group_link"));
1125 for (int m = 0; m < linkMenus.length; m++)
1127 if (linkMenus[m] != null
1128 && linkMenus[m].getMenuComponentCount() > 0)
1130 groupLinksMenu.add(linkMenus[m]);
1134 groupMenu.add(groupLinksMenu);
1144 private void jbInit() throws Exception
1146 groupMenu.setText(MessageManager.getString("label.selection"));
1147 groupName.setText(MessageManager.getString("label.name"));
1148 groupName.addActionListener(new ActionListener()
1151 public void actionPerformed(ActionEvent e)
1153 groupName_actionPerformed();
1156 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1157 sequenceName.setText(
1158 MessageManager.getString("label.edit_name_description"));
1159 sequenceName.addActionListener(new ActionListener()
1162 public void actionPerformed(ActionEvent e)
1164 sequenceName_actionPerformed();
1168 .setText(MessageManager.getString("action.choose_annotations"));
1169 chooseAnnotations.addActionListener(new ActionListener()
1172 public void actionPerformed(ActionEvent e)
1174 chooseAnnotations_actionPerformed(e);
1178 .setText(MessageManager.getString("label.sequence_details"));
1179 sequenceDetails.addActionListener(new ActionListener()
1182 public void actionPerformed(ActionEvent e)
1184 sequenceDetails_actionPerformed();
1188 .setText(MessageManager.getString("label.sequence_details"));
1189 sequenceSelDetails.addActionListener(new ActionListener()
1192 public void actionPerformed(ActionEvent e)
1194 sequenceSelectionDetails_actionPerformed();
1199 .setText(MessageManager.getString("action.remove_group"));
1200 unGroupMenuItem.addActionListener(new ActionListener()
1203 public void actionPerformed(ActionEvent e)
1205 unGroupMenuItem_actionPerformed();
1209 .setText(MessageManager.getString("action.create_group"));
1210 createGroupMenuItem.addActionListener(new ActionListener()
1213 public void actionPerformed(ActionEvent e)
1215 createGroupMenuItem_actionPerformed();
1219 outline.setText(MessageManager.getString("action.border_colour"));
1220 outline.addActionListener(new ActionListener()
1223 public void actionPerformed(ActionEvent e)
1225 outline_actionPerformed();
1228 showBoxes.setText(MessageManager.getString("action.boxes"));
1229 showBoxes.setState(true);
1230 showBoxes.addActionListener(new ActionListener()
1233 public void actionPerformed(ActionEvent e)
1235 showBoxes_actionPerformed();
1238 showText.setText(MessageManager.getString("action.text"));
1239 showText.setState(true);
1240 showText.addActionListener(new ActionListener()
1243 public void actionPerformed(ActionEvent e)
1245 showText_actionPerformed();
1248 showColourText.setText(MessageManager.getString("label.colour_text"));
1249 showColourText.addActionListener(new ActionListener()
1252 public void actionPerformed(ActionEvent e)
1254 showColourText_actionPerformed();
1258 .setText(MessageManager.getString("label.show_non_conserved"));
1259 displayNonconserved.setState(true);
1260 displayNonconserved.addActionListener(new ActionListener()
1263 public void actionPerformed(ActionEvent e)
1265 showNonconserved_actionPerformed();
1268 editMenu.setText(MessageManager.getString("action.edit"));
1269 cut.setText(MessageManager.getString("action.cut"));
1270 cut.addActionListener(new ActionListener()
1273 public void actionPerformed(ActionEvent e)
1275 cut_actionPerformed();
1278 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1279 upperCase.addActionListener(new ActionListener()
1282 public void actionPerformed(ActionEvent e)
1287 copy.setText(MessageManager.getString("action.copy"));
1288 copy.addActionListener(new ActionListener()
1291 public void actionPerformed(ActionEvent e)
1293 copy_actionPerformed();
1296 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1297 lowerCase.addActionListener(new ActionListener()
1300 public void actionPerformed(ActionEvent e)
1305 toggle.setText(MessageManager.getString("label.toggle_case"));
1306 toggle.addActionListener(new ActionListener()
1309 public void actionPerformed(ActionEvent e)
1315 MessageManager.getString("label.out_to_textbox") + "...");
1316 seqShowAnnotationsMenu
1317 .setText(MessageManager.getString("label.show_annotations"));
1318 seqHideAnnotationsMenu
1319 .setText(MessageManager.getString("label.hide_annotations"));
1320 groupShowAnnotationsMenu
1321 .setText(MessageManager.getString("label.show_annotations"));
1322 groupHideAnnotationsMenu
1323 .setText(MessageManager.getString("label.hide_annotations"));
1324 sequenceFeature.setText(
1325 MessageManager.getString("label.create_sequence_feature"));
1326 sequenceFeature.addActionListener(new ActionListener()
1329 public void actionPerformed(ActionEvent e)
1331 sequenceFeature_actionPerformed();
1334 jMenu1.setText(MessageManager.getString("label.group"));
1335 pdbStructureDialog.setText(
1336 MessageManager.getString("label.show_pdbstruct_dialog"));
1337 pdbStructureDialog.addActionListener(new ActionListener()
1340 public void actionPerformed(ActionEvent actionEvent)
1342 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1343 if (ap.av.getSelectionGroup() != null)
1345 selectedSeqs = ap.av.getSequenceSelection();
1347 new StructureChooser(selectedSeqs, sequence, ap);
1352 .setText(MessageManager.getString("label.view_rna_structure"));
1354 // colStructureMenu.setText("Colour By Structure");
1355 editSequence.setText(
1356 MessageManager.getString("label.edit_sequence") + "...");
1357 editSequence.addActionListener(new ActionListener()
1360 public void actionPerformed(ActionEvent actionEvent)
1362 editSequence_actionPerformed(actionEvent);
1365 makeReferenceSeq.setText(
1366 MessageManager.getString("label.mark_as_representative"));
1367 makeReferenceSeq.addActionListener(new ActionListener()
1371 public void actionPerformed(ActionEvent actionEvent)
1373 makeReferenceSeq_actionPerformed(actionEvent);
1378 .setText(MessageManager.getString("label.hide_insertions"));
1379 hideInsertions.addActionListener(new ActionListener()
1383 public void actionPerformed(ActionEvent e)
1385 hideInsertions_actionPerformed(e);
1389 groupMenu.add(sequenceSelDetails);
1392 add(rnaStructureMenu);
1393 add(pdbStructureDialog);
1394 if (sequence != null)
1396 add(hideInsertions);
1398 // annotations configuration panel suppressed for now
1399 // groupMenu.add(chooseAnnotations);
1402 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1403 * (if a selection group is in force).
1405 sequenceMenu.add(seqShowAnnotationsMenu);
1406 sequenceMenu.add(seqHideAnnotationsMenu);
1407 sequenceMenu.add(seqAddReferenceAnnotations);
1408 groupMenu.add(groupShowAnnotationsMenu);
1409 groupMenu.add(groupHideAnnotationsMenu);
1410 groupMenu.add(groupAddReferenceAnnotations);
1411 groupMenu.add(editMenu);
1412 groupMenu.add(outputMenu);
1413 groupMenu.add(sequenceFeature);
1414 groupMenu.add(createGroupMenuItem);
1415 groupMenu.add(unGroupMenuItem);
1416 groupMenu.add(jMenu1);
1417 sequenceMenu.add(sequenceName);
1418 sequenceMenu.add(sequenceDetails);
1419 sequenceMenu.add(makeReferenceSeq);
1426 editMenu.add(editSequence);
1427 editMenu.add(upperCase);
1428 editMenu.add(lowerCase);
1429 editMenu.add(toggle);
1430 // JBPNote: These shouldn't be added here - should appear in a generic
1431 // 'apply web service to this sequence menu'
1432 // pdbMenu.add(RNAFold);
1433 // pdbMenu.add(ContraFold);
1434 jMenu1.add(groupName);
1435 jMenu1.add(colourMenu);
1436 jMenu1.add(showBoxes);
1437 jMenu1.add(showText);
1438 jMenu1.add(showColourText);
1439 jMenu1.add(outline);
1440 jMenu1.add(displayNonconserved);
1444 * Constructs the entries for the colour menu
1446 protected void initColourMenu()
1448 colourMenu.setText(MessageManager.getString("label.group_colour"));
1449 textColour.setText(MessageManager.getString("label.text_colour"));
1450 textColour.addActionListener(new ActionListener()
1453 public void actionPerformed(ActionEvent e)
1455 textColour_actionPerformed();
1459 abovePIDColour.setText(
1460 MessageManager.getString("label.above_identity_threshold"));
1461 abovePIDColour.addActionListener(new ActionListener()
1464 public void actionPerformed(ActionEvent e)
1466 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1471 MessageManager.getString("label.modify_identity_threshold"));
1472 modifyPID.addActionListener(new ActionListener()
1475 public void actionPerformed(ActionEvent e)
1477 modifyPID_actionPerformed();
1481 conservationMenuItem
1482 .setText(MessageManager.getString("action.by_conservation"));
1483 conservationMenuItem.addActionListener(new ActionListener()
1486 public void actionPerformed(ActionEvent e)
1488 conservationMenuItem_actionPerformed(
1489 conservationMenuItem.isSelected());
1493 annotationColour = new JRadioButtonMenuItem(
1494 MessageManager.getString("action.by_annotation"));
1495 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1496 annotationColour.setEnabled(false);
1497 annotationColour.setToolTipText(
1498 MessageManager.getString("label.by_annotation_tooltip"));
1500 modifyConservation.setText(MessageManager
1501 .getString("label.modify_conservation_threshold"));
1502 modifyConservation.addActionListener(new ActionListener()
1505 public void actionPerformed(ActionEvent e)
1507 modifyConservation_actionPerformed();
1513 * Builds the group colour sub-menu, including any user-defined colours which
1514 * were loaded at startup or during the Jalview session
1516 protected void buildColourMenu()
1518 SequenceGroup sg = ap.av.getSelectionGroup();
1522 * popup menu with no sequence group scope
1526 colourMenu.removeAll();
1527 colourMenu.add(textColour);
1528 colourMenu.addSeparator();
1530 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1532 bg.add(annotationColour);
1533 colourMenu.add(annotationColour);
1535 colourMenu.addSeparator();
1536 colourMenu.add(conservationMenuItem);
1537 colourMenu.add(modifyConservation);
1538 colourMenu.add(abovePIDColour);
1539 colourMenu.add(modifyPID);
1542 protected void modifyConservation_actionPerformed()
1544 SequenceGroup sg = getGroup();
1547 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1548 SliderPanel.showConservationSlider();
1552 protected void modifyPID_actionPerformed()
1554 SequenceGroup sg = getGroup();
1557 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1559 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1560 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1561 SliderPanel.showPIDSlider();
1566 * Check for any annotations on the underlying dataset sequences (for the
1567 * current selection group) which are not 'on the alignment'.If any are found,
1568 * enable the option to add them to the alignment. The criteria for 'on the
1569 * alignment' is finding an alignment annotation on the alignment, matched on
1570 * calcId, label and sequenceRef.
1572 * A tooltip is also constructed that displays the source (calcId) and type
1573 * (label) of the annotations that can be added.
1576 * @param forSequences
1578 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1579 List<SequenceI> forSequences)
1581 menuItem.setEnabled(false);
1584 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1585 * Using TreeMap means calcIds are shown in alphabetical order.
1587 SortedMap<String, String> tipEntries = new TreeMap<>();
1588 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1589 AlignmentI al = this.ap.av.getAlignment();
1590 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1592 if (!candidates.isEmpty())
1594 StringBuilder tooltip = new StringBuilder(64);
1595 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1598 * Found annotations that could be added. Enable the menu item, and
1599 * configure its tooltip and action.
1601 menuItem.setEnabled(true);
1602 for (String calcId : tipEntries.keySet())
1604 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1606 String tooltipText = JvSwingUtils.wrapTooltip(true,
1607 tooltip.toString());
1608 menuItem.setToolTipText(tooltipText);
1610 menuItem.addActionListener(new ActionListener()
1613 public void actionPerformed(ActionEvent e)
1615 addReferenceAnnotations_actionPerformed(candidates);
1622 * Add annotations to the sequences and to the alignment.
1625 * a map whose keys are sequences on the alignment, and values a list
1626 * of annotations to add to each sequence
1628 protected void addReferenceAnnotations_actionPerformed(
1629 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1631 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1632 final AlignmentI alignment = this.ap.getAlignment();
1633 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1638 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1640 if (!ap.av.getAlignment().hasSeqrep())
1642 // initialise the display flags so the user sees something happen
1643 ap.av.setDisplayReferenceSeq(true);
1644 ap.av.setColourByReferenceSeq(true);
1645 ap.av.getAlignment().setSeqrep(sequence);
1649 if (ap.av.getAlignment().getSeqrep() == sequence)
1651 ap.av.getAlignment().setSeqrep(null);
1655 ap.av.getAlignment().setSeqrep(sequence);
1661 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1663 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1664 BitSet inserts = new BitSet();
1666 boolean markedPopup = false;
1667 // mark inserts in current selection
1668 if (ap.av.getSelectionGroup() != null)
1670 // mark just the columns in the selection group to be hidden
1671 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1672 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1674 // now clear columns without gaps
1675 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1681 inserts.and(sq.getInsertionsAsBits());
1683 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1684 ap.av.getSelectionGroup().getEndRes());
1687 // now mark for sequence under popup if we haven't already done it
1688 else if (!markedPopup && sequence != null)
1690 inserts.or(sequence.getInsertionsAsBits());
1692 // and set hidden columns accordingly
1693 hidden.hideColumns(inserts);
1698 protected void sequenceSelectionDetails_actionPerformed()
1700 createSequenceDetailsReport(ap.av.getSequenceSelection());
1703 protected void sequenceDetails_actionPerformed()
1705 createSequenceDetailsReport(new SequenceI[] { sequence });
1708 public void createSequenceDetailsReport(SequenceI[] sequences)
1710 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1711 StringBuilder contents = new StringBuilder(128);
1712 for (SequenceI seq : sequences)
1714 contents.append("<p><h2>" + MessageManager.formatMessage(
1715 "label.create_sequence_details_report_annotation_for",
1717 { seq.getDisplayId(true) }) + "</h2></p><p>");
1718 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
1719 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1720 contents.append("</p>");
1722 cap.setText("<html>" + contents.toString() + "</html>");
1724 Desktop.addInternalFrame(cap,
1725 MessageManager.formatMessage("label.sequence_details_for",
1726 (sequences.length == 1 ? new Object[]
1727 { sequences[0].getDisplayId(true) }
1730 .getString("label.selection") })),
1735 protected void showNonconserved_actionPerformed()
1737 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1742 * call to refresh view after settings change
1746 ap.updateAnnotation();
1747 // removed paintAlignment(true) here:
1748 // updateAnnotation calls paintAlignment already, so don't need to call
1751 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1755 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1756 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1766 public void abovePIDColour_actionPerformed(boolean selected)
1768 SequenceGroup sg = getGroup();
1776 sg.cs.setConsensus(AAFrequency.calculate(
1777 sg.getSequences(ap.av.getHiddenRepSequences()),
1778 sg.getStartRes(), sg.getEndRes() + 1));
1780 int threshold = SliderPanel.setPIDSliderSource(ap,
1781 sg.getGroupColourScheme(), getGroup().getName());
1783 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1785 SliderPanel.showPIDSlider();
1788 // remove PIDColouring
1790 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1791 SliderPanel.hidePIDSlider();
1793 modifyPID.setEnabled(selected);
1799 * Open a panel where the user can choose which types of sequence annotation
1804 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1806 // todo correct way to guard against opening a duplicate panel?
1807 new AnnotationChooser(ap);
1816 public void conservationMenuItem_actionPerformed(boolean selected)
1818 SequenceGroup sg = getGroup();
1826 // JBPNote: Conservation name shouldn't be i18n translated
1827 Conservation c = new Conservation("Group",
1828 sg.getSequences(ap.av.getHiddenRepSequences()),
1829 sg.getStartRes(), sg.getEndRes() + 1);
1832 c.verdict(false, ap.av.getConsPercGaps());
1833 sg.cs.setConservation(c);
1835 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1837 SliderPanel.showConservationSlider();
1840 // remove ConservationColouring
1842 sg.cs.setConservation(null);
1843 SliderPanel.hideConservationSlider();
1845 modifyConservation.setEnabled(selected);
1856 protected void groupName_actionPerformed()
1859 SequenceGroup sg = getGroup();
1860 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1861 sg.getDescription(),
1862 " " + MessageManager.getString("label.group_name") + " ",
1863 MessageManager.getString("label.group_description") + " ",
1864 MessageManager.getString("label.edit_group_name_description"),
1872 sg.setName(dialog.getName());
1873 sg.setDescription(dialog.getDescription());
1878 * Get selection group - adding it to the alignment if necessary.
1880 * @return sequence group to operate on
1882 SequenceGroup getGroup()
1884 SequenceGroup sg = ap.av.getSelectionGroup();
1885 // this method won't add a new group if it already exists
1888 ap.av.getAlignment().addGroup(sg);
1900 void sequenceName_actionPerformed()
1902 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1903 sequence.getDescription(),
1904 " " + MessageManager.getString("label.sequence_name")
1906 MessageManager.getString("label.sequence_description") + " ",
1907 MessageManager.getString(
1908 "label.edit_sequence_name_description"),
1916 if (dialog.getName() != null)
1918 if (dialog.getName().indexOf(" ") > -1)
1920 JvOptionPane.showMessageDialog(ap,
1922 .getString("label.spaces_converted_to_backslashes"),
1924 .getString("label.no_spaces_allowed_sequence_name"),
1925 JvOptionPane.WARNING_MESSAGE);
1928 sequence.setName(dialog.getName().replace(' ', '_'));
1929 ap.paintAlignment(false, false);
1932 sequence.setDescription(dialog.getDescription());
1934 ap.av.firePropertyChange("alignment", null,
1935 ap.av.getAlignment().getSequences());
1945 void unGroupMenuItem_actionPerformed()
1947 SequenceGroup sg = ap.av.getSelectionGroup();
1948 ap.av.getAlignment().deleteGroup(sg);
1949 ap.av.setSelectionGroup(null);
1953 void createGroupMenuItem_actionPerformed()
1955 getGroup(); // implicitly creates group - note - should apply defaults / use
1956 // standard alignment window logic for this
1966 protected void outline_actionPerformed()
1968 SequenceGroup sg = getGroup();
1969 Color col = JColorChooser.showDialog(this,
1970 MessageManager.getString("label.select_outline_colour"),
1975 sg.setOutlineColour(col);
1987 public void showBoxes_actionPerformed()
1989 getGroup().setDisplayBoxes(showBoxes.isSelected());
1999 public void showText_actionPerformed()
2001 getGroup().setDisplayText(showText.isSelected());
2011 public void showColourText_actionPerformed()
2013 getGroup().setColourText(showColourText.isSelected());
2017 void hideSequences(boolean representGroup)
2019 ap.av.hideSequences(sequence, representGroup);
2022 public void copy_actionPerformed()
2024 ap.alignFrame.copy_actionPerformed(null);
2027 public void cut_actionPerformed()
2029 ap.alignFrame.cut_actionPerformed(null);
2032 void changeCase(ActionEvent e)
2034 Object source = e.getSource();
2035 SequenceGroup sg = ap.av.getSelectionGroup();
2039 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2040 sg.getStartRes(), sg.getEndRes() + 1);
2045 if (source == toggle)
2047 description = MessageManager.getString("label.toggle_case");
2048 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2050 else if (source == upperCase)
2052 description = MessageManager.getString("label.to_upper_case");
2053 caseChange = ChangeCaseCommand.TO_UPPER;
2057 description = MessageManager.getString("label.to_lower_case");
2058 caseChange = ChangeCaseCommand.TO_LOWER;
2061 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2062 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2063 startEnd, caseChange);
2065 ap.alignFrame.addHistoryItem(caseCommand);
2067 ap.av.firePropertyChange("alignment", null,
2068 ap.av.getAlignment().getSequences());
2073 public void outputText_actionPerformed(ActionEvent e)
2075 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2076 cap.setForInput(null);
2077 Desktop.addInternalFrame(cap, MessageManager
2078 .formatMessage("label.alignment_output_command", new Object[]
2079 { e.getActionCommand() }), 600, 500);
2081 String[] omitHidden = null;
2083 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2084 // or we simply trust the user wants
2085 // wysiwig behaviour
2087 FileFormatI fileFormat = FileFormats.getInstance()
2088 .forName(e.getActionCommand());
2090 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2093 public void sequenceFeature_actionPerformed()
2095 SequenceGroup sg = ap.av.getSelectionGroup();
2101 List<SequenceI> seqs = new ArrayList<>();
2102 List<SequenceFeature> features = new ArrayList<>();
2105 * assemble dataset sequences, and template new sequence features,
2106 * for the amend features dialog
2108 int gSize = sg.getSize();
2109 for (int i = 0; i < gSize; i++)
2111 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2112 int end = sg.findEndRes(sg.getSequenceAt(i));
2115 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2116 features.add(new SequenceFeature(null, null, start, end, null));
2121 * an entirely gapped region will generate empty lists of sequence / features
2123 if (!seqs.isEmpty())
2125 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer()
2126 .amendFeatures(seqs, features, true, ap))
2128 ap.alignFrame.setShowSeqFeatures(true);
2129 ap.av.setSearchResults(null); // clear highlighting
2130 ap.repaint(); // draw new/amended features
2135 public void textColour_actionPerformed()
2137 SequenceGroup sg = getGroup();
2140 new TextColourChooser().chooseColour(ap, sg);
2144 public void colourByStructure(String pdbid)
2146 Annotation[] anots = ap.av.getStructureSelectionManager()
2147 .colourSequenceFromStructure(sequence, pdbid);
2149 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2150 "Coloured by " + pdbid, anots);
2152 ap.av.getAlignment().addAnnotation(an);
2153 an.createSequenceMapping(sequence, 0, true);
2154 // an.adjustForAlignment();
2155 ap.av.getAlignment().setAnnotationIndex(an, 0);
2157 ap.adjustAnnotationHeight();
2159 sequence.addAlignmentAnnotation(an);
2163 public void editSequence_actionPerformed(ActionEvent actionEvent)
2165 SequenceGroup sg = ap.av.getSelectionGroup();
2169 if (sequence == null)
2171 sequence = sg.getSequenceAt(0);
2174 EditNameDialog dialog = new EditNameDialog(
2175 sequence.getSequenceAsString(sg.getStartRes(),
2176 sg.getEndRes() + 1),
2177 null, MessageManager.getString("label.edit_sequence"), null,
2178 MessageManager.getString("label.edit_sequence"),
2183 EditCommand editCommand = new EditCommand(
2184 MessageManager.getString("label.edit_sequences"),
2186 dialog.getName().replace(' ', ap.av.getGapCharacter()),
2187 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2188 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2190 ap.alignFrame.addHistoryItem(editCommand);
2192 ap.av.firePropertyChange("alignment", null,
2193 ap.av.getAlignment().getSequences());
2199 * Action on user selecting an item from the colour menu (that does not have
2200 * its bespoke action handler)
2205 public void changeColour_actionPerformed(String colourSchemeName)
2207 SequenceGroup sg = getGroup();
2209 * switch to the chosen colour scheme (or null for None)
2211 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2212 .getColourScheme(colourSchemeName, ap.av, sg,
2213 ap.av.getHiddenRepSequences());
2214 sg.setColourScheme(colourScheme);
2215 if (colourScheme instanceof Blosum62ColourScheme
2216 || colourScheme instanceof PIDColourScheme)
2218 sg.cs.setConsensus(AAFrequency.calculate(
2219 sg.getSequences(ap.av.getHiddenRepSequences()),
2220 sg.getStartRes(), sg.getEndRes() + 1));