2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.BitSet;
30 import java.util.Collection;
31 import java.util.Collections;
32 import java.util.Hashtable;
33 import java.util.LinkedHashMap;
34 import java.util.List;
35 import java.util.Locale;
37 import java.util.Objects;
38 import java.util.SortedMap;
39 import java.util.TreeMap;
40 import java.util.Vector;
42 import javax.swing.ButtonGroup;
43 import javax.swing.JCheckBoxMenuItem;
44 import javax.swing.JInternalFrame;
45 import javax.swing.JLabel;
46 import javax.swing.JMenu;
47 import javax.swing.JMenuItem;
48 import javax.swing.JPanel;
49 import javax.swing.JPopupMenu;
50 import javax.swing.JRadioButtonMenuItem;
51 import javax.swing.JScrollPane;
53 import jalview.analysis.AAFrequency;
54 import jalview.analysis.AlignmentAnnotationUtils;
55 import jalview.analysis.AlignmentUtils;
56 import jalview.analysis.Conservation;
57 import jalview.api.AlignViewportI;
58 import jalview.bin.Console;
59 import jalview.commands.ChangeCaseCommand;
60 import jalview.commands.EditCommand;
61 import jalview.commands.EditCommand.Action;
62 import jalview.datamodel.AlignmentAnnotation;
63 import jalview.datamodel.AlignmentI;
64 import jalview.datamodel.DBRefEntry;
65 import jalview.datamodel.HiddenColumns;
66 import jalview.datamodel.MappedFeatures;
67 import jalview.datamodel.PDBEntry;
68 import jalview.datamodel.SequenceFeature;
69 import jalview.datamodel.SequenceGroup;
70 import jalview.datamodel.SequenceI;
71 import jalview.gui.ColourMenuHelper.ColourChangeListener;
72 import jalview.gui.JalviewColourChooser.ColourChooserListener;
73 import jalview.io.FileFormatI;
74 import jalview.io.FileFormats;
75 import jalview.io.FormatAdapter;
76 import jalview.io.SequenceAnnotationReport;
77 import jalview.schemes.Blosum62ColourScheme;
78 import jalview.schemes.ColourSchemeI;
79 import jalview.schemes.ColourSchemes;
80 import jalview.schemes.PIDColourScheme;
81 import jalview.schemes.ResidueColourScheme;
82 import jalview.util.Comparison;
83 import jalview.util.GroupUrlLink;
84 import jalview.util.GroupUrlLink.UrlStringTooLongException;
85 import jalview.util.MessageManager;
86 import jalview.util.Platform;
87 import jalview.util.StringUtils;
88 import jalview.util.UrlLink;
89 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
92 * The popup menu that is displayed on right-click on a sequence id, or in the
95 public class PopupMenu extends JPopupMenu implements ColourChangeListener
98 * maximum length of feature description to include in popup menu item text
100 private static final int FEATURE_DESC_MAX = 40;
103 * true for ID Panel menu, false for alignment panel menu
105 private final boolean forIdPanel;
107 private final AlignmentPanel ap;
110 * the sequence under the cursor when clicked
111 * (additional sequences may be selected)
113 private final SequenceI sequence;
115 JMenu groupMenu = new JMenu();
117 JMenuItem groupName = new JMenuItem();
119 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
121 protected JMenuItem modifyPID = new JMenuItem();
123 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
125 protected JRadioButtonMenuItem annotationColour;
127 protected JMenuItem modifyConservation = new JMenuItem();
129 JMenu sequenceMenu = new JMenu();
131 JMenuItem makeReferenceSeq = new JMenuItem();
133 JMenuItem createGroupMenuItem = new JMenuItem();
135 JMenuItem unGroupMenuItem = new JMenuItem();
137 JMenu colourMenu = new JMenu();
139 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
141 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
143 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
145 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
147 JMenu editMenu = new JMenu();
149 JMenuItem upperCase = new JMenuItem();
151 JMenuItem lowerCase = new JMenuItem();
153 JMenuItem toggle = new JMenuItem();
155 JMenu outputMenu = new JMenu();
157 JMenu seqShowAnnotationsMenu = new JMenu();
159 JMenu seqHideAnnotationsMenu = new JMenu();
161 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
162 MessageManager.getString("label.add_reference_annotations"));
164 JMenu groupShowAnnotationsMenu = new JMenu();
166 JMenu groupHideAnnotationsMenu = new JMenu();
168 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
169 MessageManager.getString("label.add_reference_annotations"));
171 JMenuItem textColour = new JMenuItem();
173 JMenu editGroupMenu = new JMenu();
175 JMenuItem chooseStructure = new JMenuItem();
177 JMenu rnaStructureMenu = new JMenu();
180 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
181 * and/or features provided. Hyperlinks may include a lookup by sequence id,
182 * or database cross-references, depending on which links are enabled in user
189 protected static JMenu buildLinkMenu(final SequenceI seq,
190 List<SequenceFeature> features)
192 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
194 List<String> nlinks = null;
197 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
198 UrlLink.sort(nlinks);
202 nlinks = new ArrayList<>();
205 if (features != null)
207 for (SequenceFeature sf : features)
209 if (sf.links != null)
211 for (String link : sf.links)
220 * instantiate the hyperlinklink templates from sequence data;
221 * note the order of the templates is preserved in the map
223 Map<String, List<String>> linkset = new LinkedHashMap<>();
224 for (String link : nlinks)
226 UrlLink urlLink = null;
229 urlLink = new UrlLink(link);
230 } catch (Exception foo)
232 Console.error("Exception for URLLink '" + link + "'", foo);
236 if (!urlLink.isValid())
238 Console.error(urlLink.getInvalidMessage());
242 urlLink.createLinksFromSeq(seq, linkset);
246 * construct menu items for the hyperlinks (still preserving
247 * the order of the sorted templates)
249 addUrlLinks(linkMenu, linkset.values());
255 * A helper method that builds menu items from the given links, with action
256 * handlers to open the link URL, and adds them to the linkMenu. Each provided
257 * link should be a list whose second item is the menu text, and whose fourth
258 * item is the URL to open when the menu item is selected.
263 static private void addUrlLinks(JMenu linkMenu,
264 Collection<List<String>> linkset)
266 for (List<String> linkstrset : linkset)
268 final String url = linkstrset.get(3);
269 JMenuItem item = new JMenuItem(linkstrset.get(1));
270 item.setToolTipText(MessageManager
271 .formatMessage("label.open_url_param", new Object[]
273 item.addActionListener(new ActionListener()
276 public void actionPerformed(ActionEvent e)
278 new Thread(new Runnable()
293 * Opens the provided url in the default web browser, or shows an error
294 * message if this fails
298 static void showLink(String url)
302 jalview.util.BrowserLauncher.openURL(url);
303 } catch (Exception ex)
305 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
306 MessageManager.getString("label.web_browser_not_found_unix"),
307 MessageManager.getString("label.web_browser_not_found"),
308 JvOptionPane.WARNING_MESSAGE);
310 ex.printStackTrace();
315 * add a late bound groupURL item to the given linkMenu
319 * - menu label string
320 * @param urlgenerator
321 * GroupURLLink used to generate URL
323 * Object array returned from the makeUrlStubs function.
325 static void addshowLink(JMenu linkMenu, String label,
326 final GroupUrlLink urlgenerator, final Object[] urlstub)
328 JMenuItem item = new JMenuItem(label);
329 item.setToolTipText(MessageManager
330 .formatMessage("label.open_url_seqs_param", new Object[]
331 { urlgenerator.getUrl_prefix(),
332 urlgenerator.getNumberInvolved(urlstub) }));
333 // TODO: put in info about what is being sent.
334 item.addActionListener(new ActionListener()
337 public void actionPerformed(ActionEvent e)
339 new Thread(new Runnable()
347 showLink(urlgenerator.constructFrom(urlstub));
348 } catch (UrlStringTooLongException e2)
361 * Constructor for a PopupMenu for a click in the alignment panel (on a
365 * the panel in which the mouse is clicked
367 * the sequence under the mouse
368 * @throws NullPointerException
371 public PopupMenu(final AlignmentPanel ap, SequenceI seq, int column)
373 this(false, ap, seq, column, null);
377 * Constructor for a PopupMenu for a click in the sequence id panel
380 * the panel in which the mouse is clicked
382 * the sequence under the mouse click
384 * templates for sequence external links
385 * @throws NullPointerException
388 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
389 List<String> groupLinks)
391 this(true, alignPanel, seq, -1, groupLinks);
395 * Private constructor that constructs a popup menu for either sequence ID
396 * Panel, or alignment context
402 * aligned column position (0...)
405 private PopupMenu(boolean fromIdPanel, final AlignmentPanel alignPanel,
406 final SequenceI seq, final int column, List<String> groupLinks)
408 Objects.requireNonNull(seq);
409 this.forIdPanel = fromIdPanel;
410 this.ap = alignPanel;
413 for (String ff : FileFormats.getInstance().getWritableFormats(true))
415 JMenuItem item = new JMenuItem(ff);
417 item.addActionListener(new ActionListener()
420 public void actionPerformed(ActionEvent e)
422 outputText_actionPerformed(e);
426 outputMenu.add(item);
430 * Build menus for annotation types that may be shown or hidden, and for
431 * 'reference annotations' that may be added to the alignment. First for the
432 * currently selected sequence (if there is one):
434 final List<SequenceI> selectedSequence = (forIdPanel && seq != null
436 : Collections.<SequenceI> emptyList());
437 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
438 seqHideAnnotationsMenu, selectedSequence);
439 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
443 * And repeat for the current selection group (if there is one):
445 final List<SequenceI> selectedGroup = (alignPanel.av
446 .getSelectionGroup() == null
447 ? Collections.<SequenceI> emptyList()
448 : alignPanel.av.getSelectionGroup().getSequences());
449 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
450 groupHideAnnotationsMenu, selectedGroup);
451 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
457 } catch (Exception e)
465 sequenceMenu.setText(sequence.getName());
466 if (seq == alignPanel.av.getAlignment().getSeqrep())
468 makeReferenceSeq.setText(
469 MessageManager.getString("action.unmark_as_reference"));
473 makeReferenceSeq.setText(
474 MessageManager.getString("action.set_as_reference"));
477 if (!alignPanel.av.getAlignment().isNucleotide())
479 remove(rnaStructureMenu);
483 int origCount = rnaStructureMenu.getItemCount();
485 * add menu items to 2D-render any alignment or sequence secondary
486 * structure annotation
488 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
489 .getAlignmentAnnotation();
492 for (final AlignmentAnnotation aa : aas)
494 if (aa.isValidStruc() && aa.sequenceRef == null)
497 * valid alignment RNA secondary structure annotation
499 menuItem = new JMenuItem();
500 menuItem.setText(MessageManager.formatMessage(
501 "label.2d_rna_structure_line", new Object[]
503 menuItem.addActionListener(new ActionListener()
506 public void actionPerformed(ActionEvent e)
508 new AppVarna(seq, aa, alignPanel);
511 rnaStructureMenu.add(menuItem);
516 if (seq.getAnnotation() != null)
518 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
519 for (final AlignmentAnnotation aa : seqAnns)
521 if (aa.isValidStruc())
524 * valid sequence RNA secondary structure annotation
526 // TODO: make rnastrucF a bit more nice
527 menuItem = new JMenuItem();
528 menuItem.setText(MessageManager.formatMessage(
529 "label.2d_rna_sequence_name", new Object[]
531 menuItem.addActionListener(new ActionListener()
534 public void actionPerformed(ActionEvent e)
536 // TODO: VARNA does'nt print gaps in the sequence
537 new AppVarna(seq, aa, alignPanel);
540 rnaStructureMenu.add(menuItem);
544 if (rnaStructureMenu.getItemCount() == origCount)
546 remove(rnaStructureMenu);
550 menuItem = new JMenuItem(
551 MessageManager.getString("action.hide_sequences"));
552 menuItem.addActionListener(new ActionListener()
555 public void actionPerformed(ActionEvent e)
557 hideSequences(false);
562 if (alignPanel.av.getSelectionGroup() != null
563 && alignPanel.av.getSelectionGroup().getSize() > 1)
565 menuItem = new JMenuItem(MessageManager
566 .formatMessage("label.represent_group_with", new Object[]
568 menuItem.addActionListener(new ActionListener()
571 public void actionPerformed(ActionEvent e)
576 sequenceMenu.add(menuItem);
579 if (alignPanel.av.hasHiddenRows())
581 final int index = alignPanel.av.getAlignment().findIndex(seq);
583 if (alignPanel.av.adjustForHiddenSeqs(index)
584 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
586 menuItem = new JMenuItem(
587 MessageManager.getString("action.reveal_sequences"));
588 menuItem.addActionListener(new ActionListener()
591 public void actionPerformed(ActionEvent e)
593 alignPanel.av.showSequence(index);
594 if (alignPanel.overviewPanel != null)
596 alignPanel.overviewPanel.updateOverviewImage();
607 * - in the IdPanel (seq not null) if any sequence is hidden
608 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
610 if (alignPanel.av.hasHiddenRows())
612 boolean addOption = seq != null;
613 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
619 JMenuItem menuItem = new JMenuItem(
620 MessageManager.getString("action.reveal_all"));
621 menuItem.addActionListener(new ActionListener()
624 public void actionPerformed(ActionEvent e)
626 alignPanel.av.showAllHiddenSeqs();
627 if (alignPanel.overviewPanel != null)
629 alignPanel.overviewPanel.updateOverviewImage();
637 SequenceGroup sg = alignPanel.av.getSelectionGroup();
638 boolean isDefinedGroup = (sg != null)
639 ? alignPanel.av.getAlignment().getGroups().contains(sg)
642 if (sg != null && sg.getSize() > 0)
644 groupName.setText(MessageManager
645 .getString("label.edit_name_and_description_current_group"));
647 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
649 conservationMenuItem.setEnabled(!sg.isNucleotide());
653 if (sg.cs.conservationApplied())
655 conservationMenuItem.setSelected(true);
657 if (sg.cs.getThreshold() > 0)
659 abovePIDColour.setSelected(true);
662 modifyConservation.setEnabled(conservationMenuItem.isSelected());
663 modifyPID.setEnabled(abovePIDColour.isSelected());
664 displayNonconserved.setSelected(sg.getShowNonconserved());
665 showText.setSelected(sg.getDisplayText());
666 showColourText.setSelected(sg.getColourText());
667 showBoxes.setSelected(sg.getDisplayBoxes());
668 // add any groupURLs to the groupURL submenu and make it visible
669 if (groupLinks != null && groupLinks.size() > 0)
671 buildGroupURLMenu(sg, groupLinks);
673 // Add a 'show all structures' for the current selection
674 Hashtable<String, PDBEntry> pdbe = new Hashtable<>(),
675 reppdb = new Hashtable<>();
677 SequenceI sqass = null;
678 for (SequenceI sq : alignPanel.av.getSequenceSelection())
680 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
681 if (pes != null && pes.size() > 0)
683 reppdb.put(pes.get(0).getId(), pes.get(0));
684 for (PDBEntry pe : pes)
686 pdbe.put(pe.getId(), pe);
696 final PDBEntry[] pe = pdbe.values()
697 .toArray(new PDBEntry[pdbe.size()]),
698 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
699 final JMenuItem gpdbview, rpdbview;
704 groupMenu.setVisible(false);
705 editMenu.setVisible(false);
710 createGroupMenuItem.setVisible(true);
711 unGroupMenuItem.setVisible(false);
713 .setText(MessageManager.getString("action.edit_new_group"));
717 createGroupMenuItem.setVisible(false);
718 unGroupMenuItem.setVisible(true);
719 editGroupMenu.setText(MessageManager.getString("action.edit_group"));
724 sequenceMenu.setVisible(false);
725 chooseStructure.setVisible(false);
726 rnaStructureMenu.setVisible(false);
729 addLinksAndFeatures(seq, column);
735 * <li>configured sequence database links (ID panel popup menu)</li>
736 * <li>non-positional feature links (ID panel popup menu)</li>
737 * <li>positional feature links (alignment panel popup menu)</li>
738 * <li>feature details links (alignment panel popup menu)</li>
740 * If this panel is also showed complementary (CDS/protein) features, then
741 * links to their feature details are also added.
746 void addLinksAndFeatures(final SequenceI seq, final int column)
748 List<SequenceFeature> features = null;
751 features = sequence.getFeatures().getNonPositionalFeatures();
755 features = ap.getFeatureRenderer().findFeaturesAtColumn(sequence,
759 addLinks(seq, features);
763 addFeatureDetails(features, seq, column);
768 * Add a menu item to show feature details for each sequence feature. Any
769 * linked 'virtual' features (CDS/protein) are also optionally found and
776 protected void addFeatureDetails(List<SequenceFeature> features,
777 final SequenceI seq, final int column)
780 * add features in CDS/protein complement at the corresponding
781 * position if configured to do so
783 MappedFeatures mf = null;
784 if (ap.av.isShowComplementFeatures())
786 if (!Comparison.isGap(sequence.getCharAt(column)))
788 AlignViewportI complement = ap.getAlignViewport()
789 .getCodingComplement();
790 AlignFrame af = Desktop.getAlignFrameFor(complement);
791 FeatureRendererModel fr2 = af.getFeatureRenderer();
792 int seqPos = sequence.findPosition(column);
793 mf = fr2.findComplementFeaturesAtResidue(sequence, seqPos);
797 if (features.isEmpty() && mf == null)
800 * no features to show at this position
805 JMenu details = new JMenu(
806 MessageManager.getString("label.feature_details"));
809 String name = seq.getName();
810 for (final SequenceFeature sf : features)
812 addFeatureDetailsMenuItem(details, name, sf, null);
817 for (final SequenceFeature sf : mf.features)
819 addFeatureDetailsMenuItem(details, name, sf, mf);
825 * A helper method to add one menu item whose action is to show details for
826 * one feature. The menu text includes feature description, but this may be
834 void addFeatureDetailsMenuItem(JMenu details, final String seqName,
835 final SequenceFeature sf, MappedFeatures mf)
837 int start = sf.getBegin();
838 int end = sf.getEnd();
842 * show local rather than linked feature coordinates
844 int[] localRange = mf.getMappedPositions(start, end);
845 if (localRange == null)
847 // e.g. variant extending to stop codon so not mappable
850 start = localRange[0];
851 end = localRange[localRange.length - 1];
853 StringBuilder desc = new StringBuilder();
854 desc.append(sf.getType()).append(" ").append(String.valueOf(start));
857 desc.append(sf.isContactFeature() ? ":" : "-");
858 desc.append(String.valueOf(end));
860 String description = sf.getDescription();
861 if (description != null)
864 description = StringUtils.stripHtmlTags(description);
867 * truncate overlong descriptions unless they contain an href
868 * (as truncation could leave corrupted html)
870 boolean hasLink = description.indexOf("a href") > -1;
871 if (description.length() > FEATURE_DESC_MAX && !hasLink)
873 description = description.substring(0, FEATURE_DESC_MAX) + "...";
875 desc.append(description);
877 String featureGroup = sf.getFeatureGroup();
878 if (featureGroup != null)
880 desc.append(" (").append(featureGroup).append(")");
882 String htmlText = JvSwingUtils.wrapTooltip(true, desc.toString());
883 JMenuItem item = new JMenuItem(htmlText);
884 item.addActionListener(new ActionListener()
887 public void actionPerformed(ActionEvent e)
889 showFeatureDetails(sf, seqName, mf);
896 * Opens a panel showing a text report of feature details
902 protected void showFeatureDetails(SequenceFeature sf, String seqName,
905 JInternalFrame details;
908 details = new JInternalFrame();
909 JPanel panel = new JPanel(new BorderLayout());
910 panel.setOpaque(true);
911 panel.setBackground(Color.white);
912 // TODO JAL-3026 set style of table correctly for feature details
913 JLabel reprt = new JLabel(MessageManager
914 .formatMessage("label.html_content", new Object[]
915 { sf.getDetailsReport(seqName, mf) }));
916 reprt.setBackground(Color.WHITE);
917 reprt.setOpaque(true);
918 panel.add(reprt, BorderLayout.CENTER);
919 details.setContentPane(panel);
929 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
930 // it appears Java's CSS does not support border-collapse :-(
931 cap.addStylesheetRule("table { border-collapse: collapse;}");
932 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
933 cap.setText(sf.getDetailsReport(seqName, mf));
936 Desktop.addInternalFrame(details,
937 MessageManager.getString("label.feature_details"), 500, 500);
941 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
942 * When seq is not null, these are links for the sequence id, which may be to
943 * external web sites for the sequence accession, and/or links embedded in
944 * non-positional features. When seq is null, only links embedded in the
945 * provided features are added. If no links are found, the menu is not added.
950 void addLinks(final SequenceI seq, List<SequenceFeature> features)
952 JMenu linkMenu = buildLinkMenu(forIdPanel ? seq : null, features);
954 // only add link menu if it has entries
955 if (linkMenu.getItemCount() > 0)
959 sequenceMenu.add(linkMenu);
969 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
970 * "All" is added first, followed by a separator. Then add any annotation
971 * types associated with the current selection. Separate menus are built for
972 * the selected sequence group (if any), and the selected sequence.
974 * Some annotation rows are always rendered together - these can be identified
975 * by a common graphGroup property > -1. Only one of each group will be marked
976 * as visible (to avoid duplication of the display). For such groups we add a
977 * composite type name, e.g.
979 * IUPredWS (Long), IUPredWS (Short)
983 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
984 List<SequenceI> forSequences)
986 showMenu.removeAll();
987 hideMenu.removeAll();
989 final List<String> all = Arrays
991 { MessageManager.getString("label.all") });
992 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
994 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
996 showMenu.addSeparator();
997 hideMenu.addSeparator();
999 final AlignmentAnnotation[] annotations = ap.getAlignment()
1000 .getAlignmentAnnotation();
1003 * Find shown/hidden annotations types, distinguished by source (calcId),
1004 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1005 * the insertion order, which is the order of the annotations on the
1008 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
1009 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
1010 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1011 AlignmentAnnotationUtils.asList(annotations), forSequences);
1013 for (String calcId : hiddenTypes.keySet())
1015 for (List<String> type : hiddenTypes.get(calcId))
1017 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1021 // grey out 'show annotations' if none are hidden
1022 showMenu.setEnabled(!hiddenTypes.isEmpty());
1024 for (String calcId : shownTypes.keySet())
1026 for (List<String> type : shownTypes.get(calcId))
1028 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1032 // grey out 'hide annotations' if none are shown
1033 hideMenu.setEnabled(!shownTypes.isEmpty());
1037 * Returns a list of sequences - either the current selection group (if there
1038 * is one), else the specified single sequence.
1043 protected List<SequenceI> getSequenceScope(SequenceI seq)
1045 List<SequenceI> forSequences = null;
1046 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
1047 if (selectionGroup != null && selectionGroup.getSize() > 0)
1049 forSequences = selectionGroup.getSequences();
1053 forSequences = seq == null ? Collections.<SequenceI> emptyList()
1054 : Arrays.asList(seq);
1056 return forSequences;
1060 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1063 * @param showOrHideMenu
1064 * the menu to add to
1065 * @param forSequences
1066 * the sequences whose annotations may be shown or hidden
1071 * if true this is a special label meaning 'All'
1072 * @param actionIsShow
1073 * if true, the select menu item action is to show the annotation
1076 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
1077 final List<SequenceI> forSequences, String calcId,
1078 final List<String> types, final boolean allTypes,
1079 final boolean actionIsShow)
1081 String label = types.toString(); // [a, b, c]
1082 label = label.substring(1, label.length() - 1); // a, b, c
1083 final JMenuItem item = new JMenuItem(label);
1084 item.setToolTipText(calcId);
1085 item.addActionListener(new ActionListener()
1088 public void actionPerformed(ActionEvent e)
1090 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1091 types, forSequences, allTypes, actionIsShow);
1095 showOrHideMenu.add(item);
1098 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
1101 // TODO: usability: thread off the generation of group url content so root
1102 // menu appears asap
1103 // sequence only URLs
1104 // ID/regex match URLs
1105 JMenu groupLinksMenu = new JMenu(
1106 MessageManager.getString("action.group_link"));
1107 // three types of url that might be created.
1108 JMenu[] linkMenus = new JMenu[] { null,
1109 new JMenu(MessageManager.getString("action.ids")),
1110 new JMenu(MessageManager.getString("action.sequences")),
1111 new JMenu(MessageManager.getString("action.ids_sequences")) };
1113 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1114 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1115 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
1116 for (int sq = 0; sq < seqs.length; sq++)
1119 int start = seqs[sq].findPosition(sg.getStartRes()),
1120 end = seqs[sq].findPosition(sg.getEndRes());
1121 // just collect ids from dataset sequence
1122 // TODO: check if IDs collected from selecton group intersects with the
1123 // current selection, too
1124 SequenceI sqi = seqs[sq];
1125 while (sqi.getDatasetSequence() != null)
1127 sqi = sqi.getDatasetSequence();
1129 List<DBRefEntry> dbr = sqi.getDBRefs();
1131 if (dbr != null && (nd = dbr.size()) > 0)
1133 for (int d = 0; d < nd; d++)
1135 DBRefEntry e = dbr.get(d);
1136 String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase(Locale.ROOT);
1137 Object[] sarray = commonDbrefs.get(src);
1140 sarray = new Object[2];
1141 sarray[0] = new int[] { 0 };
1142 sarray[1] = new String[seqs.length];
1144 commonDbrefs.put(src, sarray);
1147 if (((String[]) sarray[1])[sq] == null)
1150 || (e.getMap().locateMappedRange(start, end) != null))
1152 ((String[]) sarray[1])[sq] = e.getAccessionId();
1153 ((int[]) sarray[0])[0]++;
1159 // now create group links for all distinct ID/sequence sets.
1160 boolean addMenu = false; // indicates if there are any group links to give
1162 for (String link : groupLinks)
1164 GroupUrlLink urlLink = null;
1167 urlLink = new GroupUrlLink(link);
1168 } catch (Exception foo)
1170 Console.error("Exception for GroupURLLink '" + link + "'", foo);
1173 if (!urlLink.isValid())
1175 Console.error(urlLink.getInvalidMessage());
1178 final String label = urlLink.getLabel();
1179 boolean usingNames = false;
1180 // Now see which parts of the group apply for this URL
1181 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1182 Object[] idset = commonDbrefs.get(ltarget.toUpperCase(Locale.ROOT));
1183 String[] seqstr, ids; // input to makeUrl
1186 int numinput = ((int[]) idset[0])[0];
1187 String[] allids = ((String[]) idset[1]);
1188 seqstr = new String[numinput];
1189 ids = new String[numinput];
1190 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1192 if (allids[sq] != null)
1194 ids[idcount] = allids[sq];
1195 seqstr[idcount++] = idandseqs[1][sq];
1201 // just use the id/seq set
1202 seqstr = idandseqs[1];
1206 // and try and make the groupURL!
1208 Object[] urlset = null;
1211 urlset = urlLink.makeUrlStubs(ids, seqstr,
1212 "FromJalview" + System.currentTimeMillis(), false);
1213 } catch (UrlStringTooLongException e)
1218 int type = urlLink.getGroupURLType() & 3;
1219 // first two bits ofurlLink type bitfield are sequenceids and sequences
1220 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1221 addshowLink(linkMenus[type],
1222 label + (((type & 1) == 1)
1223 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1231 groupLinksMenu = new JMenu(
1232 MessageManager.getString("action.group_link"));
1233 for (int m = 0; m < linkMenus.length; m++)
1235 if (linkMenus[m] != null
1236 && linkMenus[m].getMenuComponentCount() > 0)
1238 groupLinksMenu.add(linkMenus[m]);
1242 groupMenu.add(groupLinksMenu);
1252 private void jbInit() throws Exception
1254 groupMenu.setText(MessageManager.getString("label.selection"));
1255 groupName.setText(MessageManager.getString("label.name"));
1256 groupName.addActionListener(new ActionListener()
1259 public void actionPerformed(ActionEvent e)
1261 groupName_actionPerformed();
1264 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1266 JMenuItem sequenceName = new JMenuItem(
1267 MessageManager.getString("label.edit_name_description"));
1268 sequenceName.addActionListener(new ActionListener()
1271 public void actionPerformed(ActionEvent e)
1273 sequenceName_actionPerformed();
1276 JMenuItem chooseAnnotations = new JMenuItem(
1277 MessageManager.getString("action.choose_annotations"));
1278 chooseAnnotations.addActionListener(new ActionListener()
1281 public void actionPerformed(ActionEvent e)
1283 chooseAnnotations_actionPerformed(e);
1286 JMenuItem sequenceDetails = new JMenuItem(
1287 MessageManager.getString("label.sequence_details"));
1288 sequenceDetails.addActionListener(new ActionListener()
1291 public void actionPerformed(ActionEvent e)
1293 createSequenceDetailsReport(new SequenceI[] { sequence });
1296 JMenuItem sequenceSelDetails = new JMenuItem(
1297 MessageManager.getString("label.sequence_details"));
1298 sequenceSelDetails.addActionListener(new ActionListener()
1301 public void actionPerformed(ActionEvent e)
1303 createSequenceDetailsReport(ap.av.getSequenceSelection());
1308 .setText(MessageManager.getString("action.remove_group"));
1309 unGroupMenuItem.addActionListener(new ActionListener()
1312 public void actionPerformed(ActionEvent e)
1314 unGroupMenuItem_actionPerformed();
1318 .setText(MessageManager.getString("action.create_group"));
1319 createGroupMenuItem.addActionListener(new ActionListener()
1322 public void actionPerformed(ActionEvent e)
1324 createGroupMenuItem_actionPerformed();
1328 JMenuItem outline = new JMenuItem(
1329 MessageManager.getString("action.border_colour"));
1330 outline.addActionListener(new ActionListener()
1333 public void actionPerformed(ActionEvent e)
1335 outline_actionPerformed();
1338 showBoxes.setText(MessageManager.getString("action.boxes"));
1339 showBoxes.setState(true);
1340 showBoxes.addActionListener(new ActionListener()
1343 public void actionPerformed(ActionEvent e)
1345 showBoxes_actionPerformed();
1348 showText.setText(MessageManager.getString("action.text"));
1349 showText.setState(true);
1350 showText.addActionListener(new ActionListener()
1353 public void actionPerformed(ActionEvent e)
1355 showText_actionPerformed();
1358 showColourText.setText(MessageManager.getString("label.colour_text"));
1359 showColourText.addActionListener(new ActionListener()
1362 public void actionPerformed(ActionEvent e)
1364 showColourText_actionPerformed();
1368 .setText(MessageManager.getString("label.show_non_conserved"));
1369 displayNonconserved.setState(true);
1370 displayNonconserved.addActionListener(new ActionListener()
1373 public void actionPerformed(ActionEvent e)
1375 showNonconserved_actionPerformed();
1378 editMenu.setText(MessageManager.getString("action.edit"));
1379 JMenuItem cut = new JMenuItem(MessageManager.getString("action.cut"));
1380 cut.addActionListener(new ActionListener()
1383 public void actionPerformed(ActionEvent e)
1385 cut_actionPerformed();
1388 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1389 upperCase.addActionListener(new ActionListener()
1392 public void actionPerformed(ActionEvent e)
1397 JMenuItem copy = new JMenuItem(MessageManager.getString("action.copy"));
1398 copy.addActionListener(new ActionListener()
1401 public void actionPerformed(ActionEvent e)
1403 copy_actionPerformed();
1406 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1407 lowerCase.addActionListener(new ActionListener()
1410 public void actionPerformed(ActionEvent e)
1415 toggle.setText(MessageManager.getString("label.toggle_case"));
1416 toggle.addActionListener(new ActionListener()
1419 public void actionPerformed(ActionEvent e)
1425 MessageManager.getString("label.out_to_textbox") + "...");
1426 seqShowAnnotationsMenu
1427 .setText(MessageManager.getString("label.show_annotations"));
1428 seqHideAnnotationsMenu
1429 .setText(MessageManager.getString("label.hide_annotations"));
1430 groupShowAnnotationsMenu
1431 .setText(MessageManager.getString("label.show_annotations"));
1432 groupHideAnnotationsMenu
1433 .setText(MessageManager.getString("label.hide_annotations"));
1434 JMenuItem sequenceFeature = new JMenuItem(
1435 MessageManager.getString("label.create_sequence_feature"));
1436 sequenceFeature.addActionListener(new ActionListener()
1439 public void actionPerformed(ActionEvent e)
1441 sequenceFeature_actionPerformed();
1444 editGroupMenu.setText(MessageManager.getString("label.group"));
1445 chooseStructure.setText(
1446 MessageManager.getString("label.show_pdbstruct_dialog"));
1447 chooseStructure.addActionListener(new ActionListener()
1450 public void actionPerformed(ActionEvent actionEvent)
1452 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1453 if (ap.av.getSelectionGroup() != null)
1455 selectedSeqs = ap.av.getSequenceSelection();
1457 new StructureChooser(selectedSeqs, sequence, ap);
1462 .setText(MessageManager.getString("label.view_rna_structure"));
1464 // colStructureMenu.setText("Colour By Structure");
1465 JMenuItem editSequence = new JMenuItem(
1466 MessageManager.getString("label.edit_sequence") + "...");
1467 editSequence.addActionListener(new ActionListener()
1470 public void actionPerformed(ActionEvent actionEvent)
1472 editSequence_actionPerformed();
1475 makeReferenceSeq.setText(
1476 MessageManager.getString("label.mark_as_representative"));
1477 makeReferenceSeq.addActionListener(new ActionListener()
1481 public void actionPerformed(ActionEvent actionEvent)
1483 makeReferenceSeq_actionPerformed(actionEvent);
1488 groupMenu.add(sequenceSelDetails);
1491 add(rnaStructureMenu);
1492 add(chooseStructure);
1495 JMenuItem hideInsertions = new JMenuItem(
1496 MessageManager.getString("label.hide_insertions"));
1497 hideInsertions.addActionListener(new ActionListener()
1501 public void actionPerformed(ActionEvent e)
1503 hideInsertions_actionPerformed(e);
1506 add(hideInsertions);
1508 // annotations configuration panel suppressed for now
1509 // groupMenu.add(chooseAnnotations);
1512 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1513 * (if a selection group is in force).
1515 sequenceMenu.add(seqShowAnnotationsMenu);
1516 sequenceMenu.add(seqHideAnnotationsMenu);
1517 sequenceMenu.add(seqAddReferenceAnnotations);
1518 groupMenu.add(groupShowAnnotationsMenu);
1519 groupMenu.add(groupHideAnnotationsMenu);
1520 groupMenu.add(groupAddReferenceAnnotations);
1521 groupMenu.add(editMenu);
1522 groupMenu.add(outputMenu);
1523 groupMenu.add(sequenceFeature);
1524 groupMenu.add(createGroupMenuItem);
1525 groupMenu.add(unGroupMenuItem);
1526 groupMenu.add(editGroupMenu);
1527 sequenceMenu.add(sequenceName);
1528 sequenceMenu.add(sequenceDetails);
1529 sequenceMenu.add(makeReferenceSeq);
1536 editMenu.add(editSequence);
1537 editMenu.add(upperCase);
1538 editMenu.add(lowerCase);
1539 editMenu.add(toggle);
1540 editGroupMenu.add(groupName);
1541 editGroupMenu.add(colourMenu);
1542 editGroupMenu.add(showBoxes);
1543 editGroupMenu.add(showText);
1544 editGroupMenu.add(showColourText);
1545 editGroupMenu.add(outline);
1546 editGroupMenu.add(displayNonconserved);
1550 * Constructs the entries for the colour menu
1552 protected void initColourMenu()
1554 colourMenu.setText(MessageManager.getString("label.group_colour"));
1555 textColour.setText(MessageManager.getString("label.text_colour"));
1556 textColour.addActionListener(new ActionListener()
1559 public void actionPerformed(ActionEvent e)
1561 textColour_actionPerformed();
1565 abovePIDColour.setText(
1566 MessageManager.getString("label.above_identity_threshold"));
1567 abovePIDColour.addActionListener(new ActionListener()
1570 public void actionPerformed(ActionEvent e)
1572 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1577 MessageManager.getString("label.modify_identity_threshold"));
1578 modifyPID.addActionListener(new ActionListener()
1581 public void actionPerformed(ActionEvent e)
1583 modifyPID_actionPerformed();
1587 conservationMenuItem
1588 .setText(MessageManager.getString("action.by_conservation"));
1589 conservationMenuItem.addActionListener(new ActionListener()
1592 public void actionPerformed(ActionEvent e)
1594 conservationMenuItem_actionPerformed(
1595 conservationMenuItem.isSelected());
1599 annotationColour = new JRadioButtonMenuItem(
1600 MessageManager.getString("action.by_annotation"));
1601 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1602 annotationColour.setEnabled(false);
1603 annotationColour.setToolTipText(
1604 MessageManager.getString("label.by_annotation_tooltip"));
1606 modifyConservation.setText(MessageManager
1607 .getString("label.modify_conservation_threshold"));
1608 modifyConservation.addActionListener(new ActionListener()
1611 public void actionPerformed(ActionEvent e)
1613 modifyConservation_actionPerformed();
1619 * Builds the group colour sub-menu, including any user-defined colours which
1620 * were loaded at startup or during the Jalview session
1622 protected void buildColourMenu()
1624 SequenceGroup sg = ap.av.getSelectionGroup();
1628 * popup menu with no sequence group scope
1632 colourMenu.removeAll();
1633 colourMenu.add(textColour);
1634 colourMenu.addSeparator();
1636 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1638 bg.add(annotationColour);
1639 colourMenu.add(annotationColour);
1641 colourMenu.addSeparator();
1642 colourMenu.add(conservationMenuItem);
1643 colourMenu.add(modifyConservation);
1644 colourMenu.add(abovePIDColour);
1645 colourMenu.add(modifyPID);
1648 protected void modifyConservation_actionPerformed()
1650 SequenceGroup sg = getGroup();
1653 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1654 SliderPanel.showConservationSlider();
1658 protected void modifyPID_actionPerformed()
1660 SequenceGroup sg = getGroup();
1663 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1665 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1666 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1667 SliderPanel.showPIDSlider();
1672 * Check for any annotations on the underlying dataset sequences (for the
1673 * current selection group) which are not 'on the alignment'.If any are found,
1674 * enable the option to add them to the alignment. The criteria for 'on the
1675 * alignment' is finding an alignment annotation on the alignment, matched on
1676 * calcId, label and sequenceRef.
1678 * A tooltip is also constructed that displays the source (calcId) and type
1679 * (label) of the annotations that can be added.
1682 * @param forSequences
1684 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1685 List<SequenceI> forSequences)
1687 menuItem.setEnabled(false);
1690 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1691 * Using TreeMap means calcIds are shown in alphabetical order.
1693 SortedMap<String, String> tipEntries = new TreeMap<>();
1694 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1695 AlignmentI al = this.ap.av.getAlignment();
1696 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1698 if (!candidates.isEmpty())
1700 StringBuilder tooltip = new StringBuilder(64);
1701 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1704 * Found annotations that could be added. Enable the menu item, and
1705 * configure its tooltip and action.
1707 menuItem.setEnabled(true);
1708 for (String calcId : tipEntries.keySet())
1710 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1712 String tooltipText = JvSwingUtils.wrapTooltip(true,
1713 tooltip.toString());
1714 menuItem.setToolTipText(tooltipText);
1716 menuItem.addActionListener(new ActionListener()
1719 public void actionPerformed(ActionEvent e)
1721 addReferenceAnnotations_actionPerformed(candidates);
1728 * Add annotations to the sequences and to the alignment.
1731 * a map whose keys are sequences on the alignment, and values a list
1732 * of annotations to add to each sequence
1734 protected void addReferenceAnnotations_actionPerformed(
1735 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1737 final AlignmentI alignment = this.ap.getAlignment();
1738 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1743 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1745 if (!ap.av.getAlignment().hasSeqrep())
1747 // initialise the display flags so the user sees something happen
1748 ap.av.setDisplayReferenceSeq(true);
1749 ap.av.setColourByReferenceSeq(true);
1750 ap.av.getAlignment().setSeqrep(sequence);
1754 if (ap.av.getAlignment().getSeqrep() == sequence)
1756 ap.av.getAlignment().setSeqrep(null);
1760 ap.av.getAlignment().setSeqrep(sequence);
1766 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1768 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1769 BitSet inserts = new BitSet();
1771 boolean markedPopup = false;
1772 // mark inserts in current selection
1773 if (ap.av.getSelectionGroup() != null)
1775 // mark just the columns in the selection group to be hidden
1776 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1777 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1779 // now clear columns without gaps
1780 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1786 inserts.and(sq.getInsertionsAsBits());
1788 hidden.clearAndHideColumns(inserts,
1789 ap.av.getSelectionGroup().getStartRes(),
1790 ap.av.getSelectionGroup().getEndRes());
1793 // now mark for sequence under popup if we haven't already done it
1794 else if (!markedPopup && sequence != null)
1796 inserts.or(sequence.getInsertionsAsBits());
1798 // and set hidden columns accordingly
1799 hidden.hideColumns(inserts);
1804 protected void sequenceSelectionDetails_actionPerformed()
1806 createSequenceDetailsReport(ap.av.getSequenceSelection());
1809 public void createSequenceDetailsReport(SequenceI[] sequences)
1811 StringBuilder contents = new StringBuilder(128);
1812 contents.append("<html><body>");
1813 for (SequenceI seq : sequences)
1815 contents.append("<p><h2>" + MessageManager.formatMessage(
1816 "label.create_sequence_details_report_annotation_for",
1818 { seq.getDisplayId(true) }) + "</h2></p>\n<p>");
1819 new SequenceAnnotationReport(false).createSequenceAnnotationReport(
1820 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1821 contents.append("</p>");
1823 contents.append("</body></html>");
1824 String report = contents.toString();
1826 JInternalFrame frame;
1827 if (Platform.isJS())
1829 JLabel textLabel = new JLabel();
1830 textLabel.setText(report);
1831 textLabel.setBackground(Color.WHITE);
1832 JPanel pane = new JPanel(new BorderLayout());
1833 pane.setOpaque(true);
1834 pane.setBackground(Color.WHITE);
1835 pane.add(textLabel, BorderLayout.NORTH);
1836 frame = new JInternalFrame();
1837 frame.getContentPane().add(new JScrollPane(pane));
1846 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1847 cap.setText(report);
1851 Desktop.addInternalFrame(frame,
1852 MessageManager.formatMessage("label.sequence_details_for",
1853 (sequences.length == 1 ? new Object[]
1854 { sequences[0].getDisplayId(true) }
1857 .getString("label.selection") })),
1861 protected void showNonconserved_actionPerformed()
1863 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1868 * call to refresh view after settings change
1872 ap.updateAnnotation();
1873 // removed paintAlignment(true) here:
1874 // updateAnnotation calls paintAlignment already, so don't need to call
1877 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1881 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1882 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1892 public void abovePIDColour_actionPerformed(boolean selected)
1894 SequenceGroup sg = getGroup();
1902 sg.cs.setConsensus(AAFrequency.calculate(
1903 sg.getSequences(ap.av.getHiddenRepSequences()),
1904 sg.getStartRes(), sg.getEndRes() + 1));
1906 int threshold = SliderPanel.setPIDSliderSource(ap,
1907 sg.getGroupColourScheme(), getGroup().getName());
1909 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1911 SliderPanel.showPIDSlider();
1914 // remove PIDColouring
1916 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1917 SliderPanel.hidePIDSlider();
1919 modifyPID.setEnabled(selected);
1925 * Open a panel where the user can choose which types of sequence annotation
1930 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1932 // todo correct way to guard against opening a duplicate panel?
1933 new AnnotationChooser(ap);
1942 public void conservationMenuItem_actionPerformed(boolean selected)
1944 SequenceGroup sg = getGroup();
1952 // JBPNote: Conservation name shouldn't be i18n translated
1953 Conservation c = new Conservation("Group",
1954 sg.getSequences(ap.av.getHiddenRepSequences()),
1955 sg.getStartRes(), sg.getEndRes() + 1);
1958 c.verdict(false, ap.av.getConsPercGaps());
1959 sg.cs.setConservation(c);
1961 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1963 SliderPanel.showConservationSlider();
1966 // remove ConservationColouring
1968 sg.cs.setConservation(null);
1969 SliderPanel.hideConservationSlider();
1971 modifyConservation.setEnabled(selected);
1977 * Shows a dialog where group name and description may be edited
1979 protected void groupName_actionPerformed()
1981 SequenceGroup sg = getGroup();
1982 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1983 sg.getDescription(),
1984 MessageManager.getString("label.group_name"),
1985 MessageManager.getString("label.group_description"));
1986 dialog.showDialog(ap.alignFrame,
1987 MessageManager.getString("label.edit_group_name_description"),
1989 sg.setName(dialog.getName());
1990 sg.setDescription(dialog.getDescription());
1996 * Get selection group - adding it to the alignment if necessary.
1998 * @return sequence group to operate on
2000 SequenceGroup getGroup()
2002 SequenceGroup sg = ap.av.getSelectionGroup();
2003 // this method won't add a new group if it already exists
2006 ap.av.getAlignment().addGroup(sg);
2013 * Shows a dialog where the sequence name and description may be edited. If a
2014 * name containing spaces is entered, these are converted to underscores, with
2015 * a warning message.
2017 void sequenceName_actionPerformed()
2019 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2020 sequence.getDescription(),
2021 MessageManager.getString("label.sequence_name"),
2022 MessageManager.getString("label.sequence_description"));
2023 dialog.showDialog(ap.alignFrame, MessageManager
2024 .getString("label.edit_sequence_name_description"), () -> {
2025 if (dialog.getName() != null)
2027 if (dialog.getName().indexOf(" ") > -1)
2029 String ok = MessageManager.getString("action.ok");
2030 String cancel = MessageManager.getString("action.cancel");
2031 String message = MessageManager.getString(
2032 "label.spaces_converted_to_underscores");
2033 String title = MessageManager.getString(
2034 "label.no_spaces_allowed_sequence_name");
2035 Object[] options = new Object[] { ok, cancel };
2037 JvOptionPane.frameDialog(message, title,
2038 JvOptionPane.WARNING_MESSAGE, null, null, null,
2041 sequence.setName(dialog.getName().replace(' ', '_'));
2042 ap.paintAlignment(false, false);
2044 sequence.setDescription(dialog.getDescription());
2045 ap.av.firePropertyChange("alignment", null,
2046 ap.av.getAlignment().getSequences());
2056 void unGroupMenuItem_actionPerformed()
2058 SequenceGroup sg = ap.av.getSelectionGroup();
2059 ap.av.getAlignment().deleteGroup(sg);
2060 ap.av.setSelectionGroup(null);
2064 void createGroupMenuItem_actionPerformed()
2066 getGroup(); // implicitly creates group - note - should apply defaults / use
2067 // standard alignment window logic for this
2072 * Offers a colour chooser and sets the selected colour as the group outline
2074 protected void outline_actionPerformed()
2076 String title = MessageManager.getString("label.select_outline_colour");
2077 ColourChooserListener listener = new ColourChooserListener()
2080 public void colourSelected(Color c)
2082 getGroup().setOutlineColour(c);
2086 JalviewColourChooser.showColourChooser(Desktop.getDesktop(), title,
2087 Color.BLUE, listener);
2096 public void showBoxes_actionPerformed()
2098 getGroup().setDisplayBoxes(showBoxes.isSelected());
2108 public void showText_actionPerformed()
2110 getGroup().setDisplayText(showText.isSelected());
2120 public void showColourText_actionPerformed()
2122 getGroup().setColourText(showColourText.isSelected());
2126 void hideSequences(boolean representGroup)
2128 ap.av.hideSequences(sequence, representGroup);
2131 public void copy_actionPerformed()
2133 ap.alignFrame.copy_actionPerformed();
2136 public void cut_actionPerformed()
2138 ap.alignFrame.cut_actionPerformed();
2141 void changeCase(ActionEvent e)
2143 Object source = e.getSource();
2144 SequenceGroup sg = ap.av.getSelectionGroup();
2148 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2149 sg.getStartRes(), sg.getEndRes() + 1);
2154 if (source == toggle)
2156 description = MessageManager.getString("label.toggle_case");
2157 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2159 else if (source == upperCase)
2161 description = MessageManager.getString("label.to_upper_case");
2162 caseChange = ChangeCaseCommand.TO_UPPER;
2166 description = MessageManager.getString("label.to_lower_case");
2167 caseChange = ChangeCaseCommand.TO_LOWER;
2170 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2171 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2172 startEnd, caseChange);
2174 ap.alignFrame.addHistoryItem(caseCommand);
2176 ap.av.firePropertyChange("alignment", null,
2177 ap.av.getAlignment().getSequences());
2182 public void outputText_actionPerformed(ActionEvent e)
2184 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2185 cap.setForInput(null);
2186 Desktop.addInternalFrame(cap, MessageManager
2187 .formatMessage("label.alignment_output_command", new Object[]
2188 { e.getActionCommand() }), 600, 500);
2190 String[] omitHidden = null;
2192 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2193 // or we simply trust the user wants
2194 // wysiwig behaviour
2196 FileFormatI fileFormat = FileFormats.getInstance()
2197 .forName(e.getActionCommand());
2199 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2202 public void sequenceFeature_actionPerformed()
2204 SequenceGroup sg = ap.av.getSelectionGroup();
2210 List<SequenceI> seqs = new ArrayList<>();
2211 List<SequenceFeature> features = new ArrayList<>();
2214 * assemble dataset sequences, and template new sequence features,
2215 * for the amend features dialog
2217 int gSize = sg.getSize();
2218 for (int i = 0; i < gSize; i++)
2220 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2221 int end = sg.findEndRes(sg.getSequenceAt(i));
2224 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2225 features.add(new SequenceFeature(null, null, start, end, null));
2230 * an entirely gapped region will generate empty lists of sequence / features
2232 if (!seqs.isEmpty())
2234 new FeatureEditor(ap, seqs, features, true).showDialog();
2238 public void textColour_actionPerformed()
2240 SequenceGroup sg = getGroup();
2243 new TextColourChooser().chooseColour(ap, sg);
2248 * Shows a dialog where sequence characters may be edited. Any changes are
2249 * applied, and added as an available 'Undo' item in the edit commands
2252 public void editSequence_actionPerformed()
2254 SequenceGroup sg = ap.av.getSelectionGroup();
2256 SequenceI seq = sequence;
2261 seq = sg.getSequenceAt(0);
2264 EditNameDialog dialog = new EditNameDialog(
2265 seq.getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
2266 null, MessageManager.getString("label.edit_sequence"), null);
2267 dialog.showDialog(ap.alignFrame,
2268 MessageManager.getString("label.edit_sequence"), () -> {
2269 EditCommand editCommand = new EditCommand(
2270 MessageManager.getString("label.edit_sequences"),
2272 dialog.getName().replace(' ',
2273 ap.av.getGapCharacter()),
2274 sg.getSequencesAsArray(
2275 ap.av.getHiddenRepSequences()),
2276 sg.getStartRes(), sg.getEndRes() + 1,
2277 ap.av.getAlignment());
2278 ap.alignFrame.addHistoryItem(editCommand);
2279 ap.av.firePropertyChange("alignment", null,
2280 ap.av.getAlignment().getSequences());
2286 * Action on user selecting an item from the colour menu (that does not have
2287 * its bespoke action handler)
2292 public void changeColour_actionPerformed(String colourSchemeName)
2294 SequenceGroup sg = getGroup();
2296 * switch to the chosen colour scheme (or null for None)
2298 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2299 .getColourScheme(colourSchemeName, ap.av, sg,
2300 ap.av.getHiddenRepSequences());
2301 sg.setColourScheme(colourScheme);
2302 if (colourScheme instanceof Blosum62ColourScheme
2303 || colourScheme instanceof PIDColourScheme)
2305 sg.cs.setConsensus(AAFrequency.calculate(
2306 sg.getSequences(ap.av.getHiddenRepSequences()),
2307 sg.getStartRes(), sg.getEndRes() + 1));