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;
90 import jalview.viewmodel.seqfeatures.IdColumn;
91 import jalview.viewmodel.seqfeatures.IdColumns;
94 * The popup menu that is displayed on right-click on a sequence id, or in the
97 public class PopupMenu extends JPopupMenu implements ColourChangeListener
100 * maximum length of feature description to include in popup menu item text
102 private static final int FEATURE_DESC_MAX = 40;
105 * true for ID Panel menu, false for alignment panel menu
107 private final boolean forIdPanel;
109 private final AlignmentPanel ap;
112 * the sequence under the cursor when clicked
113 * (additional sequences may be selected)
115 private final SequenceI sequence;
117 JMenu groupMenu = new JMenu();
119 JMenuItem groupName = new JMenuItem();
121 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
123 protected JMenuItem modifyPID = new JMenuItem();
125 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
127 protected JRadioButtonMenuItem annotationColour;
129 protected JMenuItem modifyConservation = new JMenuItem();
131 JMenu sequenceMenu = new JMenu();
133 JMenuItem makeReferenceSeq = new JMenuItem();
135 JMenuItem createGroupMenuItem = new JMenuItem();
137 JMenuItem unGroupMenuItem = new JMenuItem();
139 JMenu colourMenu = new JMenu();
141 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
143 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
145 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
147 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
149 JMenu editMenu = new JMenu();
151 JMenuItem upperCase = new JMenuItem();
153 JMenuItem lowerCase = new JMenuItem();
155 JMenuItem toggle = new JMenuItem();
157 JMenu outputMenu = new JMenu();
159 JMenu seqShowAnnotationsMenu = new JMenu();
161 JMenu seqHideAnnotationsMenu = new JMenu();
163 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
164 MessageManager.getString("label.add_reference_annotations"));
166 JMenu groupShowAnnotationsMenu = new JMenu();
168 JMenu groupHideAnnotationsMenu = new JMenu();
170 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
171 MessageManager.getString("label.add_reference_annotations"));
173 JMenuItem textColour = new JMenuItem();
175 JMenu editGroupMenu = new JMenu();
177 JMenuItem chooseStructure = new JMenuItem();
179 JMenu rnaStructureMenu = new JMenu();
182 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
183 * and/or features provided. Hyperlinks may include a lookup by sequence id,
184 * or database cross-references, depending on which links are enabled in user
191 protected static JMenu buildLinkMenu(final SequenceI seq,
192 List<SequenceFeature> features)
194 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
196 List<String> nlinks = null;
199 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
200 UrlLink.sort(nlinks);
204 nlinks = new ArrayList<>();
207 if (features != null)
209 for (SequenceFeature sf : features)
211 if (sf.links != null)
213 for (String link : sf.links)
222 * instantiate the hyperlinklink templates from sequence data;
223 * note the order of the templates is preserved in the map
225 Map<String, List<String>> linkset = new LinkedHashMap<>();
226 for (String link : nlinks)
228 UrlLink urlLink = null;
231 urlLink = new UrlLink(link);
232 } catch (Exception foo)
234 Console.error("Exception for URLLink '" + link + "'", foo);
238 if (!urlLink.isValid())
240 Console.error(urlLink.getInvalidMessage());
244 urlLink.createLinksFromSeq(seq, linkset);
248 * construct menu items for the hyperlinks (still preserving
249 * the order of the sorted templates)
251 addUrlLinks(linkMenu, linkset.values());
257 * A helper method that builds menu items from the given links, with action
258 * handlers to open the link URL, and adds them to the linkMenu. Each provided
259 * link should be a list whose second item is the menu text, and whose fourth
260 * item is the URL to open when the menu item is selected.
265 static private void addUrlLinks(JMenu linkMenu,
266 Collection<List<String>> linkset)
268 for (List<String> linkstrset : linkset)
270 final String url = linkstrset.get(3);
271 JMenuItem item = new JMenuItem(linkstrset.get(1));
272 item.setToolTipText(MessageManager
273 .formatMessage("label.open_url_param", new Object[]
275 item.addActionListener(new ActionListener()
278 public void actionPerformed(ActionEvent e)
280 new Thread(new Runnable()
295 * Opens the provided url in the default web browser, or shows an error
296 * message if this fails
300 static void showLink(String url)
304 jalview.util.BrowserLauncher.openURL(url);
305 } catch (Exception ex)
307 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
308 MessageManager.getString("label.web_browser_not_found_unix"),
309 MessageManager.getString("label.web_browser_not_found"),
310 JvOptionPane.WARNING_MESSAGE);
312 ex.printStackTrace();
317 * add a late bound groupURL item to the given linkMenu
321 * - menu label string
322 * @param urlgenerator
323 * GroupURLLink used to generate URL
325 * Object array returned from the makeUrlStubs function.
327 static void addshowLink(JMenu linkMenu, String label,
328 final GroupUrlLink urlgenerator, final Object[] urlstub)
330 JMenuItem item = new JMenuItem(label);
331 item.setToolTipText(MessageManager
332 .formatMessage("label.open_url_seqs_param", new Object[]
333 { urlgenerator.getUrl_prefix(),
334 urlgenerator.getNumberInvolved(urlstub) }));
335 // TODO: put in info about what is being sent.
336 item.addActionListener(new ActionListener()
339 public void actionPerformed(ActionEvent e)
341 new Thread(new Runnable()
349 showLink(urlgenerator.constructFrom(urlstub));
350 } catch (UrlStringTooLongException e2)
363 * Constructor for a PopupMenu for a click in the alignment panel (on a
367 * the panel in which the mouse is clicked
369 * the sequence under the mouse
370 * @throws NullPointerException
373 public PopupMenu(final AlignmentPanel ap, SequenceI seq, int column)
375 this(false, ap, seq, column, null);
379 * Constructor for a PopupMenu for a click in the sequence id panel
382 * the panel in which the mouse is clicked
384 * the sequence under the mouse click
386 * templates for sequence external links
387 * @throws NullPointerException
390 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
391 List<String> groupLinks)
393 this(true, alignPanel, seq, -1, groupLinks);
397 * Private constructor that constructs a popup menu for either sequence ID
398 * Panel, or alignment context
404 * aligned column position (0...)
407 private PopupMenu(boolean fromIdPanel, final AlignmentPanel alignPanel,
408 final SequenceI seq, final int column, List<String> groupLinks)
410 Objects.requireNonNull(seq);
411 this.forIdPanel = fromIdPanel;
412 this.ap = alignPanel;
415 for (String ff : FileFormats.getInstance().getWritableFormats(true))
417 JMenuItem item = new JMenuItem(ff);
419 item.addActionListener(new ActionListener()
422 public void actionPerformed(ActionEvent e)
424 outputText_actionPerformed(e);
428 outputMenu.add(item);
432 * Build menus for annotation types that may be shown or hidden, and for
433 * 'reference annotations' that may be added to the alignment. First for the
434 * currently selected sequence (if there is one):
436 final List<SequenceI> selectedSequence = (forIdPanel && seq != null
438 : Collections.<SequenceI> emptyList());
439 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
440 seqHideAnnotationsMenu, selectedSequence);
441 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
445 * And repeat for the current selection group (if there is one):
447 final List<SequenceI> selectedGroup = (alignPanel.av
448 .getSelectionGroup() == null
449 ? Collections.<SequenceI> emptyList()
450 : alignPanel.av.getSelectionGroup().getSequences());
451 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
452 groupHideAnnotationsMenu, selectedGroup);
453 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
459 } catch (Exception e)
467 sequenceMenu.setText(sequence.getName());
468 if (seq == alignPanel.av.getAlignment().getSeqrep())
470 makeReferenceSeq.setText(
471 MessageManager.getString("action.unmark_as_reference"));
475 makeReferenceSeq.setText(
476 MessageManager.getString("action.set_as_reference"));
479 if (!alignPanel.av.getAlignment().isNucleotide())
481 remove(rnaStructureMenu);
485 int origCount = rnaStructureMenu.getItemCount();
487 * add menu items to 2D-render any alignment or sequence secondary
488 * structure annotation
490 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
491 .getAlignmentAnnotation();
494 for (final AlignmentAnnotation aa : aas)
496 if (aa.isValidStruc() && aa.sequenceRef == null)
499 * valid alignment RNA secondary structure annotation
501 menuItem = new JMenuItem();
502 menuItem.setText(MessageManager.formatMessage(
503 "label.2d_rna_structure_line", new Object[]
505 menuItem.addActionListener(new ActionListener()
508 public void actionPerformed(ActionEvent e)
510 new AppVarna(seq, aa, alignPanel);
513 rnaStructureMenu.add(menuItem);
518 if (seq.getAnnotation() != null)
520 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
521 for (final AlignmentAnnotation aa : seqAnns)
523 if (aa.isValidStruc())
526 * valid sequence RNA secondary structure annotation
528 // TODO: make rnastrucF a bit more nice
529 menuItem = new JMenuItem();
530 menuItem.setText(MessageManager.formatMessage(
531 "label.2d_rna_sequence_name", new Object[]
533 menuItem.addActionListener(new ActionListener()
536 public void actionPerformed(ActionEvent e)
538 // TODO: VARNA does'nt print gaps in the sequence
539 new AppVarna(seq, aa, alignPanel);
542 rnaStructureMenu.add(menuItem);
546 if (rnaStructureMenu.getItemCount() == origCount)
548 remove(rnaStructureMenu);
552 menuItem = new JMenuItem(
553 MessageManager.getString("action.hide_sequences"));
554 menuItem.addActionListener(new ActionListener()
557 public void actionPerformed(ActionEvent e)
559 hideSequences(false);
564 if (alignPanel.av.getSelectionGroup() != null
565 && alignPanel.av.getSelectionGroup().getSize() > 1)
567 menuItem = new JMenuItem(MessageManager
568 .formatMessage("label.represent_group_with", new Object[]
570 menuItem.addActionListener(new ActionListener()
573 public void actionPerformed(ActionEvent e)
578 sequenceMenu.add(menuItem);
581 if (alignPanel.av.hasHiddenRows())
583 final int index = alignPanel.av.getAlignment().findIndex(seq);
585 if (alignPanel.av.adjustForHiddenSeqs(index)
586 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
588 menuItem = new JMenuItem(
589 MessageManager.getString("action.reveal_sequences"));
590 menuItem.addActionListener(new ActionListener()
593 public void actionPerformed(ActionEvent e)
595 alignPanel.av.showSequence(index);
596 if (alignPanel.overviewPanel != null)
598 alignPanel.overviewPanel.updateOverviewImage();
609 * - in the IdPanel (seq not null) if any sequence is hidden
610 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
612 if (alignPanel.av.hasHiddenRows())
614 boolean addOption = seq != null;
615 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
621 JMenuItem menuItem = new JMenuItem(
622 MessageManager.getString("action.reveal_all"));
623 menuItem.addActionListener(new ActionListener()
626 public void actionPerformed(ActionEvent e)
628 alignPanel.av.showAllHiddenSeqs();
629 if (alignPanel.overviewPanel != null)
631 alignPanel.overviewPanel.updateOverviewImage();
639 SequenceGroup sg = alignPanel.av.getSelectionGroup();
640 boolean isDefinedGroup = (sg != null)
641 ? alignPanel.av.getAlignment().getGroups().contains(sg)
644 if (sg != null && sg.getSize() > 0)
646 groupName.setText(MessageManager
647 .getString("label.edit_name_and_description_current_group"));
649 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
651 conservationMenuItem.setEnabled(!sg.isNucleotide());
655 if (sg.cs.conservationApplied())
657 conservationMenuItem.setSelected(true);
659 if (sg.cs.getThreshold() > 0)
661 abovePIDColour.setSelected(true);
664 modifyConservation.setEnabled(conservationMenuItem.isSelected());
665 modifyPID.setEnabled(abovePIDColour.isSelected());
666 displayNonconserved.setSelected(sg.getShowNonconserved());
667 showText.setSelected(sg.getDisplayText());
668 showColourText.setSelected(sg.getColourText());
669 showBoxes.setSelected(sg.getDisplayBoxes());
670 // add any groupURLs to the groupURL submenu and make it visible
671 if (groupLinks != null && groupLinks.size() > 0)
673 buildGroupURLMenu(sg, groupLinks);
675 // Add a 'show all structures' for the current selection
676 Hashtable<String, PDBEntry> pdbe = new Hashtable<>(),
677 reppdb = new Hashtable<>();
679 SequenceI sqass = null;
680 for (SequenceI sq : alignPanel.av.getSequenceSelection())
682 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
683 if (pes != null && pes.size() > 0)
685 reppdb.put(pes.get(0).getId(), pes.get(0));
686 for (PDBEntry pe : pes)
688 pdbe.put(pe.getId(), pe);
698 final PDBEntry[] pe = pdbe.values()
699 .toArray(new PDBEntry[pdbe.size()]),
700 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
701 final JMenuItem gpdbview, rpdbview;
706 groupMenu.setVisible(false);
707 editMenu.setVisible(false);
712 createGroupMenuItem.setVisible(true);
713 unGroupMenuItem.setVisible(false);
715 .setText(MessageManager.getString("action.edit_new_group"));
719 createGroupMenuItem.setVisible(false);
720 unGroupMenuItem.setVisible(true);
721 editGroupMenu.setText(MessageManager.getString("action.edit_group"));
726 sequenceMenu.setVisible(false);
727 chooseStructure.setVisible(false);
728 rnaStructureMenu.setVisible(false);
733 addDisplayColumnsMenu();
736 addLinksAndFeatures(seq, column);
739 void addDisplayColumnsMenu()
741 JMenu dis_cols = new JMenu(
742 MessageManager.getString("action.displayed_columns"));
743 final IdColumns id_cols = ap.av.getIdColumns();
744 id_cols.updateTypeList();
745 for (final IdColumn col : id_cols.getIdColumns())
747 JMenuItem col_entry = new JCheckBoxMenuItem(col.getLabel(),
749 col_entry.addActionListener(new ActionListener()
753 public void actionPerformed(ActionEvent e)
755 id_cols.toggleVisible(col.getLabel());
758 dis_cols.add(col_entry);
766 * <li>configured sequence database links (ID panel popup menu)</li>
767 * <li>non-positional feature links (ID panel popup menu)</li>
768 * <li>positional feature links (alignment panel popup menu)</li>
769 * <li>feature details links (alignment panel popup menu)</li>
771 * If this panel is also showed complementary (CDS/protein) features, then
772 * links to their feature details are also added.
777 void addLinksAndFeatures(final SequenceI seq, final int column)
779 List<SequenceFeature> features = null;
782 features = sequence.getFeatures().getNonPositionalFeatures();
786 features = ap.getFeatureRenderer().findFeaturesAtColumn(sequence,
790 addLinks(seq, features);
794 addFeatureDetails(features, seq, column);
799 * Add a menu item to show feature details for each sequence feature. Any
800 * linked 'virtual' features (CDS/protein) are also optionally found and
807 protected void addFeatureDetails(List<SequenceFeature> features,
808 final SequenceI seq, final int column)
811 * add features in CDS/protein complement at the corresponding
812 * position if configured to do so
814 MappedFeatures mf = null;
815 if (ap.av.isShowComplementFeatures())
817 if (!Comparison.isGap(sequence.getCharAt(column)))
819 AlignViewportI complement = ap.getAlignViewport()
820 .getCodingComplement();
821 AlignFrame af = Desktop.getAlignFrameFor(complement);
822 FeatureRendererModel fr2 = af.getFeatureRenderer();
823 int seqPos = sequence.findPosition(column);
824 mf = fr2.findComplementFeaturesAtResidue(sequence, seqPos);
828 if (features.isEmpty() && mf == null)
831 * no features to show at this position
836 JMenu details = new JMenu(
837 MessageManager.getString("label.feature_details"));
840 String name = seq.getName();
841 for (final SequenceFeature sf : features)
843 addFeatureDetailsMenuItem(details, name, sf, null);
848 for (final SequenceFeature sf : mf.features)
850 addFeatureDetailsMenuItem(details, name, sf, mf);
856 * A helper method to add one menu item whose action is to show details for
857 * one feature. The menu text includes feature description, but this may be
865 void addFeatureDetailsMenuItem(JMenu details, final String seqName,
866 final SequenceFeature sf, MappedFeatures mf)
868 int start = sf.getBegin();
869 int end = sf.getEnd();
873 * show local rather than linked feature coordinates
875 int[] localRange = mf.getMappedPositions(start, end);
876 if (localRange == null)
878 // e.g. variant extending to stop codon so not mappable
881 start = localRange[0];
882 end = localRange[localRange.length - 1];
884 StringBuilder desc = new StringBuilder();
885 desc.append(sf.getType()).append(" ").append(String.valueOf(start));
888 desc.append(sf.isContactFeature() ? ":" : "-");
889 desc.append(String.valueOf(end));
891 String description = sf.getDescription();
892 if (description != null)
895 description = StringUtils.stripHtmlTags(description);
898 * truncate overlong descriptions unless they contain an href
899 * (as truncation could leave corrupted html)
901 boolean hasLink = description.indexOf("a href") > -1;
902 if (description.length() > FEATURE_DESC_MAX && !hasLink)
904 description = description.substring(0, FEATURE_DESC_MAX) + "...";
906 desc.append(description);
908 String featureGroup = sf.getFeatureGroup();
909 if (featureGroup != null)
911 desc.append(" (").append(featureGroup).append(")");
913 String htmlText = JvSwingUtils.wrapTooltip(true, desc.toString());
914 JMenuItem item = new JMenuItem(htmlText);
915 item.addActionListener(new ActionListener()
918 public void actionPerformed(ActionEvent e)
920 showFeatureDetails(sf, seqName, mf);
927 * Opens a panel showing a text report of feature details
933 protected void showFeatureDetails(SequenceFeature sf, String seqName,
936 JInternalFrame details;
939 details = new JInternalFrame();
940 JPanel panel = new JPanel(new BorderLayout());
941 panel.setOpaque(true);
942 panel.setBackground(Color.white);
943 // TODO JAL-3026 set style of table correctly for feature details
944 JLabel reprt = new JLabel(MessageManager
945 .formatMessage("label.html_content", new Object[]
946 { sf.getDetailsReport(seqName, mf) }));
947 reprt.setBackground(Color.WHITE);
948 reprt.setOpaque(true);
949 panel.add(reprt, BorderLayout.CENTER);
950 details.setContentPane(panel);
960 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
961 // it appears Java's CSS does not support border-collapse :-(
962 cap.addStylesheetRule("table { border-collapse: collapse;}");
963 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
964 cap.setText(sf.getDetailsReport(seqName, mf));
967 Desktop.addInternalFrame(details,
968 MessageManager.getString("label.feature_details"), 500, 500);
972 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
973 * When seq is not null, these are links for the sequence id, which may be to
974 * external web sites for the sequence accession, and/or links embedded in
975 * non-positional features. When seq is null, only links embedded in the
976 * provided features are added. If no links are found, the menu is not added.
981 void addLinks(final SequenceI seq, List<SequenceFeature> features)
983 JMenu linkMenu = buildLinkMenu(forIdPanel ? seq : null, features);
985 // only add link menu if it has entries
986 if (linkMenu.getItemCount() > 0)
990 sequenceMenu.add(linkMenu);
1000 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1001 * "All" is added first, followed by a separator. Then add any annotation
1002 * types associated with the current selection. Separate menus are built for
1003 * the selected sequence group (if any), and the selected sequence.
1005 * Some annotation rows are always rendered together - these can be identified
1006 * by a common graphGroup property > -1. Only one of each group will be marked
1007 * as visible (to avoid duplication of the display). For such groups we add a
1008 * composite type name, e.g.
1010 * IUPredWS (Long), IUPredWS (Short)
1014 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
1015 List<SequenceI> forSequences)
1017 showMenu.removeAll();
1018 hideMenu.removeAll();
1020 final List<String> all = Arrays
1021 .asList(new String[]
1022 { MessageManager.getString("label.all") });
1023 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
1025 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1027 showMenu.addSeparator();
1028 hideMenu.addSeparator();
1030 final AlignmentAnnotation[] annotations = ap.getAlignment()
1031 .getAlignmentAnnotation();
1034 * Find shown/hidden annotations types, distinguished by source (calcId),
1035 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1036 * the insertion order, which is the order of the annotations on the
1039 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
1040 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
1041 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1042 AlignmentAnnotationUtils.asList(annotations), forSequences);
1044 for (String calcId : hiddenTypes.keySet())
1046 for (List<String> type : hiddenTypes.get(calcId))
1048 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1052 // grey out 'show annotations' if none are hidden
1053 showMenu.setEnabled(!hiddenTypes.isEmpty());
1055 for (String calcId : shownTypes.keySet())
1057 for (List<String> type : shownTypes.get(calcId))
1059 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1063 // grey out 'hide annotations' if none are shown
1064 hideMenu.setEnabled(!shownTypes.isEmpty());
1068 * Returns a list of sequences - either the current selection group (if there
1069 * is one), else the specified single sequence.
1074 protected List<SequenceI> getSequenceScope(SequenceI seq)
1076 List<SequenceI> forSequences = null;
1077 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
1078 if (selectionGroup != null && selectionGroup.getSize() > 0)
1080 forSequences = selectionGroup.getSequences();
1084 forSequences = seq == null ? Collections.<SequenceI> emptyList()
1085 : Arrays.asList(seq);
1087 return forSequences;
1091 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1094 * @param showOrHideMenu
1095 * the menu to add to
1096 * @param forSequences
1097 * the sequences whose annotations may be shown or hidden
1102 * if true this is a special label meaning 'All'
1103 * @param actionIsShow
1104 * if true, the select menu item action is to show the annotation
1107 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
1108 final List<SequenceI> forSequences, String calcId,
1109 final List<String> types, final boolean allTypes,
1110 final boolean actionIsShow)
1112 String label = types.toString(); // [a, b, c]
1113 label = label.substring(1, label.length() - 1); // a, b, c
1114 final JMenuItem item = new JMenuItem(label);
1115 item.setToolTipText(calcId);
1116 item.addActionListener(new ActionListener()
1119 public void actionPerformed(ActionEvent e)
1121 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1122 types, forSequences, allTypes, actionIsShow);
1126 showOrHideMenu.add(item);
1129 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
1132 // TODO: usability: thread off the generation of group url content so root
1133 // menu appears asap
1134 // sequence only URLs
1135 // ID/regex match URLs
1136 JMenu groupLinksMenu = new JMenu(
1137 MessageManager.getString("action.group_link"));
1138 // three types of url that might be created.
1139 JMenu[] linkMenus = new JMenu[] { null,
1140 new JMenu(MessageManager.getString("action.ids")),
1141 new JMenu(MessageManager.getString("action.sequences")),
1142 new JMenu(MessageManager.getString("action.ids_sequences")) };
1144 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1145 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1146 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
1147 for (int sq = 0; sq < seqs.length; sq++)
1150 int start = seqs[sq].findPosition(sg.getStartRes()),
1151 end = seqs[sq].findPosition(sg.getEndRes());
1152 // just collect ids from dataset sequence
1153 // TODO: check if IDs collected from selecton group intersects with the
1154 // current selection, too
1155 SequenceI sqi = seqs[sq];
1156 while (sqi.getDatasetSequence() != null)
1158 sqi = sqi.getDatasetSequence();
1160 List<DBRefEntry> dbr = sqi.getDBRefs();
1162 if (dbr != null && (nd = dbr.size()) > 0)
1164 for (int d = 0; d < nd; d++)
1166 DBRefEntry e = dbr.get(d);
1167 String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase(Locale.ROOT);
1168 Object[] sarray = commonDbrefs.get(src);
1171 sarray = new Object[2];
1172 sarray[0] = new int[] { 0 };
1173 sarray[1] = new String[seqs.length];
1175 commonDbrefs.put(src, sarray);
1178 if (((String[]) sarray[1])[sq] == null)
1181 || (e.getMap().locateMappedRange(start, end) != null))
1183 ((String[]) sarray[1])[sq] = e.getAccessionId();
1184 ((int[]) sarray[0])[0]++;
1190 // now create group links for all distinct ID/sequence sets.
1191 boolean addMenu = false; // indicates if there are any group links to give
1193 for (String link : groupLinks)
1195 GroupUrlLink urlLink = null;
1198 urlLink = new GroupUrlLink(link);
1199 } catch (Exception foo)
1201 Console.error("Exception for GroupURLLink '" + link + "'", foo);
1204 if (!urlLink.isValid())
1206 Console.error(urlLink.getInvalidMessage());
1209 final String label = urlLink.getLabel();
1210 boolean usingNames = false;
1211 // Now see which parts of the group apply for this URL
1212 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1213 Object[] idset = commonDbrefs.get(ltarget.toUpperCase(Locale.ROOT));
1214 String[] seqstr, ids; // input to makeUrl
1217 int numinput = ((int[]) idset[0])[0];
1218 String[] allids = ((String[]) idset[1]);
1219 seqstr = new String[numinput];
1220 ids = new String[numinput];
1221 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1223 if (allids[sq] != null)
1225 ids[idcount] = allids[sq];
1226 seqstr[idcount++] = idandseqs[1][sq];
1232 // just use the id/seq set
1233 seqstr = idandseqs[1];
1237 // and try and make the groupURL!
1239 Object[] urlset = null;
1242 urlset = urlLink.makeUrlStubs(ids, seqstr,
1243 "FromJalview" + System.currentTimeMillis(), false);
1244 } catch (UrlStringTooLongException e)
1249 int type = urlLink.getGroupURLType() & 3;
1250 // first two bits ofurlLink type bitfield are sequenceids and sequences
1251 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1252 addshowLink(linkMenus[type],
1253 label + (((type & 1) == 1)
1254 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1262 groupLinksMenu = new JMenu(
1263 MessageManager.getString("action.group_link"));
1264 for (int m = 0; m < linkMenus.length; m++)
1266 if (linkMenus[m] != null
1267 && linkMenus[m].getMenuComponentCount() > 0)
1269 groupLinksMenu.add(linkMenus[m]);
1273 groupMenu.add(groupLinksMenu);
1283 private void jbInit() throws Exception
1285 groupMenu.setText(MessageManager.getString("label.selection"));
1286 groupName.setText(MessageManager.getString("label.name"));
1287 groupName.addActionListener(new ActionListener()
1290 public void actionPerformed(ActionEvent e)
1292 groupName_actionPerformed();
1295 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1297 JMenuItem sequenceName = new JMenuItem(
1298 MessageManager.getString("label.edit_name_description"));
1299 sequenceName.addActionListener(new ActionListener()
1302 public void actionPerformed(ActionEvent e)
1304 sequenceName_actionPerformed();
1307 JMenuItem chooseAnnotations = new JMenuItem(
1308 MessageManager.getString("action.choose_annotations"));
1309 chooseAnnotations.addActionListener(new ActionListener()
1312 public void actionPerformed(ActionEvent e)
1314 chooseAnnotations_actionPerformed(e);
1317 JMenuItem sequenceDetails = new JMenuItem(
1318 MessageManager.getString("label.sequence_details"));
1319 sequenceDetails.addActionListener(new ActionListener()
1322 public void actionPerformed(ActionEvent e)
1324 createSequenceDetailsReport(new SequenceI[] { sequence });
1327 JMenuItem sequenceSelDetails = new JMenuItem(
1328 MessageManager.getString("label.sequence_details"));
1329 sequenceSelDetails.addActionListener(new ActionListener()
1332 public void actionPerformed(ActionEvent e)
1334 createSequenceDetailsReport(ap.av.getSequenceSelection());
1339 .setText(MessageManager.getString("action.remove_group"));
1340 unGroupMenuItem.addActionListener(new ActionListener()
1343 public void actionPerformed(ActionEvent e)
1345 unGroupMenuItem_actionPerformed();
1349 .setText(MessageManager.getString("action.create_group"));
1350 createGroupMenuItem.addActionListener(new ActionListener()
1353 public void actionPerformed(ActionEvent e)
1355 createGroupMenuItem_actionPerformed();
1359 JMenuItem outline = new JMenuItem(
1360 MessageManager.getString("action.border_colour"));
1361 outline.addActionListener(new ActionListener()
1364 public void actionPerformed(ActionEvent e)
1366 outline_actionPerformed();
1369 showBoxes.setText(MessageManager.getString("action.boxes"));
1370 showBoxes.setState(true);
1371 showBoxes.addActionListener(new ActionListener()
1374 public void actionPerformed(ActionEvent e)
1376 showBoxes_actionPerformed();
1379 showText.setText(MessageManager.getString("action.text"));
1380 showText.setState(true);
1381 showText.addActionListener(new ActionListener()
1384 public void actionPerformed(ActionEvent e)
1386 showText_actionPerformed();
1389 showColourText.setText(MessageManager.getString("label.colour_text"));
1390 showColourText.addActionListener(new ActionListener()
1393 public void actionPerformed(ActionEvent e)
1395 showColourText_actionPerformed();
1399 .setText(MessageManager.getString("label.show_non_conserved"));
1400 displayNonconserved.setState(true);
1401 displayNonconserved.addActionListener(new ActionListener()
1404 public void actionPerformed(ActionEvent e)
1406 showNonconserved_actionPerformed();
1409 editMenu.setText(MessageManager.getString("action.edit"));
1410 JMenuItem cut = new JMenuItem(MessageManager.getString("action.cut"));
1411 cut.addActionListener(new ActionListener()
1414 public void actionPerformed(ActionEvent e)
1416 cut_actionPerformed();
1419 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1420 upperCase.addActionListener(new ActionListener()
1423 public void actionPerformed(ActionEvent e)
1428 JMenuItem copy = new JMenuItem(MessageManager.getString("action.copy"));
1429 copy.addActionListener(new ActionListener()
1432 public void actionPerformed(ActionEvent e)
1434 copy_actionPerformed();
1437 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1438 lowerCase.addActionListener(new ActionListener()
1441 public void actionPerformed(ActionEvent e)
1446 toggle.setText(MessageManager.getString("label.toggle_case"));
1447 toggle.addActionListener(new ActionListener()
1450 public void actionPerformed(ActionEvent e)
1456 MessageManager.getString("label.out_to_textbox") + "...");
1457 seqShowAnnotationsMenu
1458 .setText(MessageManager.getString("label.show_annotations"));
1459 seqHideAnnotationsMenu
1460 .setText(MessageManager.getString("label.hide_annotations"));
1461 groupShowAnnotationsMenu
1462 .setText(MessageManager.getString("label.show_annotations"));
1463 groupHideAnnotationsMenu
1464 .setText(MessageManager.getString("label.hide_annotations"));
1465 JMenuItem sequenceFeature = new JMenuItem(
1466 MessageManager.getString("label.create_sequence_feature"));
1467 sequenceFeature.addActionListener(new ActionListener()
1470 public void actionPerformed(ActionEvent e)
1472 sequenceFeature_actionPerformed();
1475 editGroupMenu.setText(MessageManager.getString("label.group"));
1476 chooseStructure.setText(
1477 MessageManager.getString("label.show_pdbstruct_dialog"));
1478 chooseStructure.addActionListener(new ActionListener()
1481 public void actionPerformed(ActionEvent actionEvent)
1483 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1484 if (ap.av.getSelectionGroup() != null)
1486 selectedSeqs = ap.av.getSequenceSelection();
1488 new StructureChooser(selectedSeqs, sequence, ap);
1493 .setText(MessageManager.getString("label.view_rna_structure"));
1495 // colStructureMenu.setText("Colour By Structure");
1496 JMenuItem editSequence = new JMenuItem(
1497 MessageManager.getString("label.edit_sequence") + "...");
1498 editSequence.addActionListener(new ActionListener()
1501 public void actionPerformed(ActionEvent actionEvent)
1503 editSequence_actionPerformed();
1506 makeReferenceSeq.setText(
1507 MessageManager.getString("label.mark_as_representative"));
1508 makeReferenceSeq.addActionListener(new ActionListener()
1512 public void actionPerformed(ActionEvent actionEvent)
1514 makeReferenceSeq_actionPerformed(actionEvent);
1519 groupMenu.add(sequenceSelDetails);
1522 add(rnaStructureMenu);
1523 add(chooseStructure);
1526 JMenuItem hideInsertions = new JMenuItem(
1527 MessageManager.getString("label.hide_insertions"));
1528 hideInsertions.addActionListener(new ActionListener()
1532 public void actionPerformed(ActionEvent e)
1534 hideInsertions_actionPerformed(e);
1537 add(hideInsertions);
1539 // annotations configuration panel suppressed for now
1540 // groupMenu.add(chooseAnnotations);
1543 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1544 * (if a selection group is in force).
1546 sequenceMenu.add(seqShowAnnotationsMenu);
1547 sequenceMenu.add(seqHideAnnotationsMenu);
1548 sequenceMenu.add(seqAddReferenceAnnotations);
1549 groupMenu.add(groupShowAnnotationsMenu);
1550 groupMenu.add(groupHideAnnotationsMenu);
1551 groupMenu.add(groupAddReferenceAnnotations);
1552 groupMenu.add(editMenu);
1553 groupMenu.add(outputMenu);
1554 groupMenu.add(sequenceFeature);
1555 groupMenu.add(createGroupMenuItem);
1556 groupMenu.add(unGroupMenuItem);
1557 groupMenu.add(editGroupMenu);
1558 sequenceMenu.add(sequenceName);
1559 sequenceMenu.add(sequenceDetails);
1560 sequenceMenu.add(makeReferenceSeq);
1567 editMenu.add(editSequence);
1568 editMenu.add(upperCase);
1569 editMenu.add(lowerCase);
1570 editMenu.add(toggle);
1571 editGroupMenu.add(groupName);
1572 editGroupMenu.add(colourMenu);
1573 editGroupMenu.add(showBoxes);
1574 editGroupMenu.add(showText);
1575 editGroupMenu.add(showColourText);
1576 editGroupMenu.add(outline);
1577 editGroupMenu.add(displayNonconserved);
1581 * Constructs the entries for the colour menu
1583 protected void initColourMenu()
1585 colourMenu.setText(MessageManager.getString("label.group_colour"));
1586 textColour.setText(MessageManager.getString("label.text_colour"));
1587 textColour.addActionListener(new ActionListener()
1590 public void actionPerformed(ActionEvent e)
1592 textColour_actionPerformed();
1596 abovePIDColour.setText(
1597 MessageManager.getString("label.above_identity_threshold"));
1598 abovePIDColour.addActionListener(new ActionListener()
1601 public void actionPerformed(ActionEvent e)
1603 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1608 MessageManager.getString("label.modify_identity_threshold"));
1609 modifyPID.addActionListener(new ActionListener()
1612 public void actionPerformed(ActionEvent e)
1614 modifyPID_actionPerformed();
1618 conservationMenuItem
1619 .setText(MessageManager.getString("action.by_conservation"));
1620 conservationMenuItem.addActionListener(new ActionListener()
1623 public void actionPerformed(ActionEvent e)
1625 conservationMenuItem_actionPerformed(
1626 conservationMenuItem.isSelected());
1630 annotationColour = new JRadioButtonMenuItem(
1631 MessageManager.getString("action.by_annotation"));
1632 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1633 annotationColour.setEnabled(false);
1634 annotationColour.setToolTipText(
1635 MessageManager.getString("label.by_annotation_tooltip"));
1637 modifyConservation.setText(MessageManager
1638 .getString("label.modify_conservation_threshold"));
1639 modifyConservation.addActionListener(new ActionListener()
1642 public void actionPerformed(ActionEvent e)
1644 modifyConservation_actionPerformed();
1650 * Builds the group colour sub-menu, including any user-defined colours which
1651 * were loaded at startup or during the Jalview session
1653 protected void buildColourMenu()
1655 SequenceGroup sg = ap.av.getSelectionGroup();
1659 * popup menu with no sequence group scope
1663 colourMenu.removeAll();
1664 colourMenu.add(textColour);
1665 colourMenu.addSeparator();
1667 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1669 bg.add(annotationColour);
1670 colourMenu.add(annotationColour);
1672 colourMenu.addSeparator();
1673 colourMenu.add(conservationMenuItem);
1674 colourMenu.add(modifyConservation);
1675 colourMenu.add(abovePIDColour);
1676 colourMenu.add(modifyPID);
1679 protected void modifyConservation_actionPerformed()
1681 SequenceGroup sg = getGroup();
1684 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1685 SliderPanel.showConservationSlider();
1689 protected void modifyPID_actionPerformed()
1691 SequenceGroup sg = getGroup();
1694 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1696 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1697 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1698 SliderPanel.showPIDSlider();
1703 * Check for any annotations on the underlying dataset sequences (for the
1704 * current selection group) which are not 'on the alignment'.If any are found,
1705 * enable the option to add them to the alignment. The criteria for 'on the
1706 * alignment' is finding an alignment annotation on the alignment, matched on
1707 * calcId, label and sequenceRef.
1709 * A tooltip is also constructed that displays the source (calcId) and type
1710 * (label) of the annotations that can be added.
1713 * @param forSequences
1715 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1716 List<SequenceI> forSequences)
1718 menuItem.setEnabled(false);
1721 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1722 * Using TreeMap means calcIds are shown in alphabetical order.
1724 SortedMap<String, String> tipEntries = new TreeMap<>();
1725 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1726 AlignmentI al = this.ap.av.getAlignment();
1727 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1729 if (!candidates.isEmpty())
1731 StringBuilder tooltip = new StringBuilder(64);
1732 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1735 * Found annotations that could be added. Enable the menu item, and
1736 * configure its tooltip and action.
1738 menuItem.setEnabled(true);
1739 for (String calcId : tipEntries.keySet())
1741 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1743 String tooltipText = JvSwingUtils.wrapTooltip(true,
1744 tooltip.toString());
1745 menuItem.setToolTipText(tooltipText);
1747 menuItem.addActionListener(new ActionListener()
1750 public void actionPerformed(ActionEvent e)
1752 addReferenceAnnotations_actionPerformed(candidates);
1759 * Add annotations to the sequences and to the alignment.
1762 * a map whose keys are sequences on the alignment, and values a list
1763 * of annotations to add to each sequence
1765 protected void addReferenceAnnotations_actionPerformed(
1766 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1768 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1769 final AlignmentI alignment = this.ap.getAlignment();
1770 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1775 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1777 if (!ap.av.getAlignment().hasSeqrep())
1779 // initialise the display flags so the user sees something happen
1780 ap.av.setDisplayReferenceSeq(true);
1781 ap.av.setColourByReferenceSeq(true);
1782 ap.av.getAlignment().setSeqrep(sequence);
1786 if (ap.av.getAlignment().getSeqrep() == sequence)
1788 ap.av.getAlignment().setSeqrep(null);
1792 ap.av.getAlignment().setSeqrep(sequence);
1798 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1800 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1801 BitSet inserts = new BitSet();
1803 boolean markedPopup = false;
1804 // mark inserts in current selection
1805 if (ap.av.getSelectionGroup() != null)
1807 // mark just the columns in the selection group to be hidden
1808 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1809 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1811 // now clear columns without gaps
1812 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1818 inserts.and(sq.getInsertionsAsBits());
1820 hidden.clearAndHideColumns(inserts,
1821 ap.av.getSelectionGroup().getStartRes(),
1822 ap.av.getSelectionGroup().getEndRes());
1825 // now mark for sequence under popup if we haven't already done it
1826 else if (!markedPopup && sequence != null)
1828 inserts.or(sequence.getInsertionsAsBits());
1830 // and set hidden columns accordingly
1831 hidden.hideColumns(inserts);
1836 protected void sequenceSelectionDetails_actionPerformed()
1838 createSequenceDetailsReport(ap.av.getSequenceSelection());
1841 public void createSequenceDetailsReport(SequenceI[] sequences)
1843 StringBuilder contents = new StringBuilder(128);
1844 contents.append("<html><body>");
1845 for (SequenceI seq : sequences)
1847 contents.append("<p><h2>" + MessageManager.formatMessage(
1848 "label.create_sequence_details_report_annotation_for",
1850 { seq.getDisplayId(true) }) + "</h2></p>\n<p>");
1851 new SequenceAnnotationReport(false).createSequenceAnnotationReport(
1852 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1853 contents.append("</p>");
1855 contents.append("</body></html>");
1856 String report = contents.toString();
1858 JInternalFrame frame;
1859 if (Platform.isJS())
1861 JLabel textLabel = new JLabel();
1862 textLabel.setText(report);
1863 textLabel.setBackground(Color.WHITE);
1864 JPanel pane = new JPanel(new BorderLayout());
1865 pane.setOpaque(true);
1866 pane.setBackground(Color.WHITE);
1867 pane.add(textLabel, BorderLayout.NORTH);
1868 frame = new JInternalFrame();
1869 frame.getContentPane().add(new JScrollPane(pane));
1878 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1879 cap.setText(report);
1883 Desktop.addInternalFrame(frame,
1884 MessageManager.formatMessage("label.sequence_details_for",
1885 (sequences.length == 1 ? new Object[]
1886 { sequences[0].getDisplayId(true) }
1889 .getString("label.selection") })),
1893 protected void showNonconserved_actionPerformed()
1895 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1900 * call to refresh view after settings change
1904 ap.updateAnnotation();
1905 // removed paintAlignment(true) here:
1906 // updateAnnotation calls paintAlignment already, so don't need to call
1909 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1913 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1914 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1924 public void abovePIDColour_actionPerformed(boolean selected)
1926 SequenceGroup sg = getGroup();
1934 sg.cs.setConsensus(AAFrequency.calculate(
1935 sg.getSequences(ap.av.getHiddenRepSequences()),
1936 sg.getStartRes(), sg.getEndRes() + 1));
1938 int threshold = SliderPanel.setPIDSliderSource(ap,
1939 sg.getGroupColourScheme(), getGroup().getName());
1941 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1943 SliderPanel.showPIDSlider();
1946 // remove PIDColouring
1948 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1949 SliderPanel.hidePIDSlider();
1951 modifyPID.setEnabled(selected);
1957 * Open a panel where the user can choose which types of sequence annotation
1962 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1964 // todo correct way to guard against opening a duplicate panel?
1965 new AnnotationChooser(ap);
1974 public void conservationMenuItem_actionPerformed(boolean selected)
1976 SequenceGroup sg = getGroup();
1984 // JBPNote: Conservation name shouldn't be i18n translated
1985 Conservation c = new Conservation("Group",
1986 sg.getSequences(ap.av.getHiddenRepSequences()),
1987 sg.getStartRes(), sg.getEndRes() + 1);
1990 c.verdict(false, ap.av.getConsPercGaps());
1991 sg.cs.setConservation(c);
1993 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1995 SliderPanel.showConservationSlider();
1998 // remove ConservationColouring
2000 sg.cs.setConservation(null);
2001 SliderPanel.hideConservationSlider();
2003 modifyConservation.setEnabled(selected);
2009 * Shows a dialog where group name and description may be edited
2011 protected void groupName_actionPerformed()
2013 SequenceGroup sg = getGroup();
2014 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2015 sg.getDescription(),
2016 MessageManager.getString("label.group_name"),
2017 MessageManager.getString("label.group_description"));
2018 dialog.showDialog(ap.alignFrame,
2019 MessageManager.getString("label.edit_group_name_description"),
2021 sg.setName(dialog.getName());
2022 sg.setDescription(dialog.getDescription());
2029 * Get selection group - adding it to the alignment if necessary.
2031 * @return sequence group to operate on
2033 SequenceGroup getGroup()
2035 SequenceGroup sg = ap.av.getSelectionGroup();
2036 // this method won't add a new group if it already exists
2039 ap.av.getAlignment().addGroup(sg);
2046 * Shows a dialog where the sequence name and description may be edited. If a
2047 * name containing spaces is entered, these are converted to underscores, with
2048 * a warning message.
2050 void sequenceName_actionPerformed()
2052 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2053 sequence.getDescription(),
2054 MessageManager.getString("label.sequence_name"),
2055 MessageManager.getString("label.sequence_description"));
2056 dialog.showDialog(ap.alignFrame, MessageManager
2057 .getString("label.edit_sequence_name_description"), () -> {
2058 if (dialog.getName() != null)
2060 if (dialog.getName().indexOf(" ") > -1)
2062 JvOptionPane.showMessageDialog(ap,
2063 MessageManager.getString(
2064 "label.spaces_converted_to_underscores"),
2065 MessageManager.getString(
2066 "label.no_spaces_allowed_sequence_name"),
2067 JvOptionPane.WARNING_MESSAGE);
2069 sequence.setName(dialog.getName().replace(' ', '_'));
2070 ap.paintAlignment(false, false);
2072 sequence.setDescription(dialog.getDescription());
2073 ap.av.firePropertyChange("alignment", null,
2074 ap.av.getAlignment().getSequences());
2085 void unGroupMenuItem_actionPerformed()
2087 SequenceGroup sg = ap.av.getSelectionGroup();
2088 ap.av.getAlignment().deleteGroup(sg);
2089 ap.av.setSelectionGroup(null);
2093 void createGroupMenuItem_actionPerformed()
2095 getGroup(); // implicitly creates group - note - should apply defaults / use
2096 // standard alignment window logic for this
2101 * Offers a colour chooser and sets the selected colour as the group outline
2103 protected void outline_actionPerformed()
2105 String title = MessageManager.getString("label.select_outline_colour");
2106 ColourChooserListener listener = new ColourChooserListener()
2109 public void colourSelected(Color c)
2111 getGroup().setOutlineColour(c);
2115 JalviewColourChooser.showColourChooser(Desktop.getDesktop(), title,
2116 Color.BLUE, listener);
2125 public void showBoxes_actionPerformed()
2127 getGroup().setDisplayBoxes(showBoxes.isSelected());
2137 public void showText_actionPerformed()
2139 getGroup().setDisplayText(showText.isSelected());
2149 public void showColourText_actionPerformed()
2151 getGroup().setColourText(showColourText.isSelected());
2155 void hideSequences(boolean representGroup)
2157 ap.av.hideSequences(sequence, representGroup);
2160 public void copy_actionPerformed()
2162 ap.alignFrame.copy_actionPerformed();
2165 public void cut_actionPerformed()
2167 ap.alignFrame.cut_actionPerformed();
2170 void changeCase(ActionEvent e)
2172 Object source = e.getSource();
2173 SequenceGroup sg = ap.av.getSelectionGroup();
2177 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2178 sg.getStartRes(), sg.getEndRes() + 1);
2183 if (source == toggle)
2185 description = MessageManager.getString("label.toggle_case");
2186 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2188 else if (source == upperCase)
2190 description = MessageManager.getString("label.to_upper_case");
2191 caseChange = ChangeCaseCommand.TO_UPPER;
2195 description = MessageManager.getString("label.to_lower_case");
2196 caseChange = ChangeCaseCommand.TO_LOWER;
2199 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2200 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2201 startEnd, caseChange);
2203 ap.alignFrame.addHistoryItem(caseCommand);
2205 ap.av.firePropertyChange("alignment", null,
2206 ap.av.getAlignment().getSequences());
2211 public void outputText_actionPerformed(ActionEvent e)
2213 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2214 cap.setForInput(null);
2215 Desktop.addInternalFrame(cap, MessageManager
2216 .formatMessage("label.alignment_output_command", new Object[]
2217 { e.getActionCommand() }), 600, 500);
2219 String[] omitHidden = null;
2221 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2222 // or we simply trust the user wants
2223 // wysiwig behaviour
2225 FileFormatI fileFormat = FileFormats.getInstance()
2226 .forName(e.getActionCommand());
2228 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2231 public void sequenceFeature_actionPerformed()
2233 SequenceGroup sg = ap.av.getSelectionGroup();
2239 List<SequenceI> seqs = new ArrayList<>();
2240 List<SequenceFeature> features = new ArrayList<>();
2243 * assemble dataset sequences, and template new sequence features,
2244 * for the amend features dialog
2246 int gSize = sg.getSize();
2247 for (int i = 0; i < gSize; i++)
2249 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2250 int end = sg.findEndRes(sg.getSequenceAt(i));
2253 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2254 features.add(new SequenceFeature(null, null, start, end, null));
2259 * an entirely gapped region will generate empty lists of sequence / features
2261 if (!seqs.isEmpty())
2263 new FeatureEditor(ap, seqs, features, true).showDialog();
2267 public void textColour_actionPerformed()
2269 SequenceGroup sg = getGroup();
2272 new TextColourChooser().chooseColour(ap, sg);
2277 * Shows a dialog where sequence characters may be edited. Any changes are
2278 * applied, and added as an available 'Undo' item in the edit commands
2281 public void editSequence_actionPerformed()
2283 SequenceGroup sg = ap.av.getSelectionGroup();
2285 SequenceI seq = sequence;
2290 seq = sg.getSequenceAt(0);
2293 EditNameDialog dialog = new EditNameDialog(
2294 seq.getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
2295 null, MessageManager.getString("label.edit_sequence"), null);
2296 dialog.showDialog(ap.alignFrame,
2297 MessageManager.getString("label.edit_sequence"), () -> {
2298 EditCommand editCommand = new EditCommand(
2299 MessageManager.getString("label.edit_sequences"),
2301 dialog.getName().replace(' ',
2302 ap.av.getGapCharacter()),
2303 sg.getSequencesAsArray(
2304 ap.av.getHiddenRepSequences()),
2305 sg.getStartRes(), sg.getEndRes() + 1,
2306 ap.av.getAlignment());
2307 ap.alignFrame.addHistoryItem(editCommand);
2308 ap.av.firePropertyChange("alignment", null,
2309 ap.av.getAlignment().getSequences());
2316 * Action on user selecting an item from the colour menu (that does not have
2317 * its bespoke action handler)
2322 public void changeColour_actionPerformed(String colourSchemeName)
2324 SequenceGroup sg = getGroup();
2326 * switch to the chosen colour scheme (or null for None)
2328 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2329 .getColourScheme(colourSchemeName, ap.av, sg,
2330 ap.av.getHiddenRepSequences());
2331 sg.setColourScheme(colourScheme);
2332 if (colourScheme instanceof Blosum62ColourScheme
2333 || colourScheme instanceof PIDColourScheme)
2335 sg.cs.setConsensus(AAFrequency.calculate(
2336 sg.getSequences(ap.av.getHiddenRepSequences()),
2337 sg.getStartRes(), sg.getEndRes() + 1));