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.util.Locale;
25 import java.awt.BorderLayout;
26 import java.awt.Color;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.BitSet;
32 import java.util.Collection;
33 import java.util.Collections;
34 import java.util.Hashtable;
35 import java.util.LinkedHashMap;
36 import java.util.List;
38 import java.util.Objects;
39 import java.util.SortedMap;
40 import java.util.TreeMap;
41 import java.util.Vector;
43 import javax.swing.ButtonGroup;
44 import javax.swing.JCheckBoxMenuItem;
45 import javax.swing.JInternalFrame;
46 import javax.swing.JLabel;
47 import javax.swing.JMenu;
48 import javax.swing.JMenuItem;
49 import javax.swing.JPanel;
50 import javax.swing.JPopupMenu;
51 import javax.swing.JRadioButtonMenuItem;
52 import javax.swing.JScrollPane;
54 import jalview.analysis.AAFrequency;
55 import jalview.analysis.AlignmentAnnotationUtils;
56 import jalview.analysis.AlignmentUtils;
57 import jalview.analysis.Conservation;
58 import jalview.api.AlignViewportI;
59 import jalview.bin.Console;
60 import jalview.commands.ChangeCaseCommand;
61 import jalview.commands.EditCommand;
62 import jalview.commands.EditCommand.Action;
63 import jalview.datamodel.AlignmentAnnotation;
64 import jalview.datamodel.AlignmentI;
65 import jalview.datamodel.DBRefEntry;
66 import jalview.datamodel.HiddenColumns;
67 import jalview.datamodel.MappedFeatures;
68 import jalview.datamodel.PDBEntry;
69 import jalview.datamodel.SequenceFeature;
70 import jalview.datamodel.SequenceGroup;
71 import jalview.datamodel.SequenceI;
72 import jalview.gui.ColourMenuHelper.ColourChangeListener;
73 import jalview.gui.JalviewColourChooser.ColourChooserListener;
74 import jalview.io.FileFormatI;
75 import jalview.io.FileFormats;
76 import jalview.io.FormatAdapter;
77 import jalview.io.SequenceAnnotationReport;
78 import jalview.schemes.Blosum62ColourScheme;
79 import jalview.schemes.ColourSchemeI;
80 import jalview.schemes.ColourSchemes;
81 import jalview.schemes.PIDColourScheme;
82 import jalview.schemes.ResidueColourScheme;
83 import jalview.util.Comparison;
84 import jalview.util.GroupUrlLink;
85 import jalview.util.GroupUrlLink.UrlStringTooLongException;
86 import jalview.util.MessageManager;
87 import jalview.util.Platform;
88 import jalview.util.StringUtils;
89 import jalview.util.UrlLink;
90 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
93 * The popup menu that is displayed on right-click on a sequence id, or in the
96 public class PopupMenu extends JPopupMenu implements ColourChangeListener
99 * maximum length of feature description to include in popup menu item text
101 private static final int FEATURE_DESC_MAX = 40;
104 * true for ID Panel menu, false for alignment panel menu
106 private final boolean forIdPanel;
108 private final AlignmentPanel ap;
111 * the sequence under the cursor when clicked
112 * (additional sequences may be selected)
114 private final SequenceI sequence;
116 JMenu groupMenu = new JMenu();
118 JMenuItem groupName = new JMenuItem();
120 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
122 protected JMenuItem modifyPID = new JMenuItem();
124 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
126 protected JRadioButtonMenuItem annotationColour;
128 protected JMenuItem modifyConservation = new JMenuItem();
130 JMenu sequenceMenu = new JMenu();
132 JMenuItem makeReferenceSeq = new JMenuItem();
134 JMenuItem createGroupMenuItem = new JMenuItem();
136 JMenuItem unGroupMenuItem = new JMenuItem();
138 JMenu colourMenu = new JMenu();
140 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
142 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
144 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
146 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
148 JMenu editMenu = new JMenu();
150 JMenuItem upperCase = new JMenuItem();
152 JMenuItem lowerCase = new JMenuItem();
154 JMenuItem toggle = new JMenuItem();
156 JMenu outputMenu = new JMenu();
158 JMenu seqShowAnnotationsMenu = new JMenu();
160 JMenu seqHideAnnotationsMenu = new JMenu();
162 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
163 MessageManager.getString("label.add_reference_annotations"));
165 JMenu groupShowAnnotationsMenu = new JMenu();
167 JMenu groupHideAnnotationsMenu = new JMenu();
169 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
170 MessageManager.getString("label.add_reference_annotations"));
172 JMenuItem textColour = new JMenuItem();
174 JMenu editGroupMenu = new JMenu();
176 JMenuItem chooseStructure = new JMenuItem();
178 JMenu rnaStructureMenu = new JMenu();
181 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
182 * and/or features provided. Hyperlinks may include a lookup by sequence id,
183 * or database cross-references, depending on which links are enabled in user
190 protected static JMenu buildLinkMenu(final SequenceI seq,
191 List<SequenceFeature> features)
193 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
195 List<String> nlinks = null;
198 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
199 UrlLink.sort(nlinks);
203 nlinks = new ArrayList<>();
206 if (features != null)
208 for (SequenceFeature sf : features)
210 if (sf.links != null)
212 for (String link : sf.links)
221 * instantiate the hyperlinklink templates from sequence data;
222 * note the order of the templates is preserved in the map
224 Map<String, List<String>> linkset = new LinkedHashMap<>();
225 for (String link : nlinks)
227 UrlLink urlLink = null;
230 urlLink = new UrlLink(link);
231 } catch (Exception foo)
233 Console.error("Exception for URLLink '" + link + "'", foo);
237 if (!urlLink.isValid())
239 Console.error(urlLink.getInvalidMessage());
243 urlLink.createLinksFromSeq(seq, linkset);
247 * construct menu items for the hyperlinks (still preserving
248 * the order of the sorted templates)
250 addUrlLinks(linkMenu, linkset.values());
256 * A helper method that builds menu items from the given links, with action
257 * handlers to open the link URL, and adds them to the linkMenu. Each provided
258 * link should be a list whose second item is the menu text, and whose fourth
259 * item is the URL to open when the menu item is selected.
264 static private void addUrlLinks(JMenu linkMenu,
265 Collection<List<String>> linkset)
267 for (List<String> linkstrset : linkset)
269 final String url = linkstrset.get(3);
270 JMenuItem item = new JMenuItem(linkstrset.get(1));
271 item.setToolTipText(MessageManager
272 .formatMessage("label.open_url_param", new Object[]
274 item.addActionListener(new ActionListener()
277 public void actionPerformed(ActionEvent e)
279 new Thread(new Runnable()
294 * Opens the provided url in the default web browser, or shows an error
295 * message if this fails
299 static void showLink(String url)
303 jalview.util.BrowserLauncher.openURL(url);
304 } catch (Exception ex)
306 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
307 MessageManager.getString("label.web_browser_not_found_unix"),
308 MessageManager.getString("label.web_browser_not_found"),
309 JvOptionPane.WARNING_MESSAGE);
311 ex.printStackTrace();
316 * add a late bound groupURL item to the given linkMenu
320 * - menu label string
321 * @param urlgenerator
322 * GroupURLLink used to generate URL
324 * Object array returned from the makeUrlStubs function.
326 static void addshowLink(JMenu linkMenu, String label,
327 final GroupUrlLink urlgenerator, final Object[] urlstub)
329 JMenuItem item = new JMenuItem(label);
330 item.setToolTipText(MessageManager
331 .formatMessage("label.open_url_seqs_param", new Object[]
332 { urlgenerator.getUrl_prefix(),
333 urlgenerator.getNumberInvolved(urlstub) }));
334 // TODO: put in info about what is being sent.
335 item.addActionListener(new ActionListener()
338 public void actionPerformed(ActionEvent e)
340 new Thread(new Runnable()
348 showLink(urlgenerator.constructFrom(urlstub));
349 } catch (UrlStringTooLongException e2)
362 * Constructor for a PopupMenu for a click in the alignment panel (on a residue)
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,
406 final AlignmentPanel alignPanel,
407 final SequenceI seq, final int column, List<String> groupLinks)
409 Objects.requireNonNull(seq);
410 this.forIdPanel = fromIdPanel;
411 this.ap = alignPanel;
414 for (String ff : FileFormats.getInstance().getWritableFormats(true))
416 JMenuItem item = new JMenuItem(ff);
418 item.addActionListener(new ActionListener()
421 public void actionPerformed(ActionEvent e)
423 outputText_actionPerformed(e);
427 outputMenu.add(item);
431 * Build menus for annotation types that may be shown or hidden, and for
432 * 'reference annotations' that may be added to the alignment. First for the
433 * currently selected sequence (if there is one):
435 final List<SequenceI> selectedSequence = (forIdPanel && seq != null
437 : Collections.<SequenceI> emptyList());
438 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
439 seqHideAnnotationsMenu, selectedSequence);
440 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
444 * And repeat for the current selection group (if there is one):
446 final List<SequenceI> selectedGroup = (alignPanel.av.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<>(), reppdb = new Hashtable<>();
676 SequenceI sqass = null;
677 for (SequenceI sq : alignPanel.av.getSequenceSelection())
679 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
680 if (pes != null && pes.size() > 0)
682 reppdb.put(pes.get(0).getId(), pes.get(0));
683 for (PDBEntry pe : pes)
685 pdbe.put(pe.getId(), pe);
695 final PDBEntry[] pe = pdbe.values()
696 .toArray(new PDBEntry[pdbe.size()]),
697 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
698 final JMenuItem gpdbview, rpdbview;
703 groupMenu.setVisible(false);
704 editMenu.setVisible(false);
709 createGroupMenuItem.setVisible(true);
710 unGroupMenuItem.setVisible(false);
711 editGroupMenu.setText(MessageManager.getString("action.edit_new_group"));
715 createGroupMenuItem.setVisible(false);
716 unGroupMenuItem.setVisible(true);
717 editGroupMenu.setText(MessageManager.getString("action.edit_group"));
722 sequenceMenu.setVisible(false);
723 chooseStructure.setVisible(false);
724 rnaStructureMenu.setVisible(false);
727 addLinksAndFeatures(seq, column);
733 * <li>configured sequence database links (ID panel popup menu)</li>
734 * <li>non-positional feature links (ID panel popup menu)</li>
735 * <li>positional feature links (alignment panel popup menu)</li>
736 * <li>feature details links (alignment panel popup menu)</li>
738 * If this panel is also showed complementary (CDS/protein) features, then links
739 * to their feature details are also added.
744 void addLinksAndFeatures(final SequenceI seq, final int column)
746 List<SequenceFeature> features = null;
749 features = sequence.getFeatures().getNonPositionalFeatures();
753 features = ap.getFeatureRenderer().findFeaturesAtColumn(sequence,
757 addLinks(seq, features);
761 addFeatureDetails(features, seq, column);
766 * Add a menu item to show feature details for each sequence feature. Any
767 * linked 'virtual' features (CDS/protein) are also optionally found and
774 protected void addFeatureDetails(List<SequenceFeature> features,
775 final SequenceI seq, final int column)
778 * add features in CDS/protein complement at the corresponding
779 * position if configured to do so
781 MappedFeatures mf = null;
782 if (ap.av.isShowComplementFeatures())
784 if (!Comparison.isGap(sequence.getCharAt(column)))
786 AlignViewportI complement = ap.getAlignViewport()
787 .getCodingComplement();
788 AlignFrame af = Desktop.getAlignFrameFor(complement);
789 FeatureRendererModel fr2 = af.getFeatureRenderer();
790 int seqPos = sequence.findPosition(column);
791 mf = fr2.findComplementFeaturesAtResidue(sequence, seqPos);
795 if (features.isEmpty() && mf == null)
798 * no features to show at this position
803 JMenu details = new JMenu(
804 MessageManager.getString("label.feature_details"));
807 String name = seq.getName();
808 for (final SequenceFeature sf : features)
810 addFeatureDetailsMenuItem(details, name, sf, null);
815 for (final SequenceFeature sf : mf.features)
817 addFeatureDetailsMenuItem(details, name, sf, mf);
823 * A helper method to add one menu item whose action is to show details for
824 * one feature. The menu text includes feature description, but this may be
832 void addFeatureDetailsMenuItem(JMenu details, final String seqName,
833 final SequenceFeature sf, MappedFeatures mf)
835 int start = sf.getBegin();
836 int end = sf.getEnd();
840 * show local rather than linked feature coordinates
842 int[] localRange = mf.getMappedPositions(start, end);
843 if (localRange == null)
845 // e.g. variant extending to stop codon so not mappable
848 start = localRange[0];
849 end = localRange[localRange.length - 1];
851 StringBuilder desc = new StringBuilder();
852 desc.append(sf.getType()).append(" ").append(String.valueOf(start));
855 desc.append(sf.isContactFeature() ? ":" : "-");
856 desc.append(String.valueOf(end));
858 String description = sf.getDescription();
859 if (description != null)
862 description = StringUtils.stripHtmlTags(description);
865 * truncate overlong descriptions unless they contain an href
866 * (as truncation could leave corrupted html)
868 boolean hasLink = description.indexOf("a href") > -1;
869 if (description.length() > FEATURE_DESC_MAX && !hasLink)
871 description = description.substring(0, FEATURE_DESC_MAX) + "...";
873 desc.append(description);
875 String featureGroup = sf.getFeatureGroup();
876 if (featureGroup != null)
878 desc.append(" (").append(featureGroup).append(")");
880 String htmlText = JvSwingUtils.wrapTooltip(true, desc.toString());
881 JMenuItem item = new JMenuItem(htmlText);
882 item.addActionListener(new ActionListener()
885 public void actionPerformed(ActionEvent e)
887 showFeatureDetails(sf, seqName, mf);
894 * Opens a panel showing a text report of feature details
900 protected void showFeatureDetails(SequenceFeature sf, String seqName,
903 JInternalFrame details;
906 details = new JInternalFrame();
907 JPanel panel = new JPanel(new BorderLayout());
908 panel.setOpaque(true);
909 panel.setBackground(Color.white);
910 // TODO JAL-3026 set style of table correctly for feature details
911 JLabel reprt = new JLabel(MessageManager
912 .formatMessage("label.html_content", new Object[]
913 { sf.getDetailsReport(seqName, mf) }));
914 reprt.setBackground(Color.WHITE);
915 reprt.setOpaque(true);
916 panel.add(reprt, BorderLayout.CENTER);
917 details.setContentPane(panel);
927 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
928 // it appears Java's CSS does not support border-collapse :-(
929 cap.addStylesheetRule("table { border-collapse: collapse;}");
930 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
931 cap.setText(sf.getDetailsReport(seqName, mf));
934 Desktop.addInternalFrame(details,
935 MessageManager.getString("label.feature_details"), 500, 500);
939 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
940 * When seq is not null, these are links for the sequence id, which may be to
941 * external web sites for the sequence accession, and/or links embedded in
942 * non-positional features. When seq is null, only links embedded in the
943 * provided features are added. If no links are found, the menu is not added.
948 void addLinks(final SequenceI seq, List<SequenceFeature> features)
950 JMenu linkMenu = buildLinkMenu(forIdPanel ? seq : null, features);
952 // only add link menu if it has entries
953 if (linkMenu.getItemCount() > 0)
957 sequenceMenu.add(linkMenu);
967 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
968 * "All" is added first, followed by a separator. Then add any annotation
969 * types associated with the current selection. Separate menus are built for
970 * the selected sequence group (if any), and the selected sequence.
972 * Some annotation rows are always rendered together - these can be identified
973 * by a common graphGroup property > -1. Only one of each group will be marked
974 * as visible (to avoid duplication of the display). For such groups we add a
975 * composite type name, e.g.
977 * IUPredWS (Long), IUPredWS (Short)
981 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
982 List<SequenceI> forSequences)
984 showMenu.removeAll();
985 hideMenu.removeAll();
987 final List<String> all = Arrays
989 { MessageManager.getString("label.all") });
990 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
992 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
994 showMenu.addSeparator();
995 hideMenu.addSeparator();
997 final AlignmentAnnotation[] annotations = ap.getAlignment()
998 .getAlignmentAnnotation();
1001 * Find shown/hidden annotations types, distinguished by source (calcId),
1002 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1003 * the insertion order, which is the order of the annotations on the
1006 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
1007 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
1008 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1009 AlignmentAnnotationUtils.asList(annotations), forSequences);
1011 for (String calcId : hiddenTypes.keySet())
1013 for (List<String> type : hiddenTypes.get(calcId))
1015 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1019 // grey out 'show annotations' if none are hidden
1020 showMenu.setEnabled(!hiddenTypes.isEmpty());
1022 for (String calcId : shownTypes.keySet())
1024 for (List<String> type : shownTypes.get(calcId))
1026 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1030 // grey out 'hide annotations' if none are shown
1031 hideMenu.setEnabled(!shownTypes.isEmpty());
1035 * Returns a list of sequences - either the current selection group (if there
1036 * is one), else the specified single sequence.
1041 protected List<SequenceI> getSequenceScope(SequenceI seq)
1043 List<SequenceI> forSequences = null;
1044 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
1045 if (selectionGroup != null && selectionGroup.getSize() > 0)
1047 forSequences = selectionGroup.getSequences();
1051 forSequences = seq == null ? Collections.<SequenceI> emptyList()
1052 : Arrays.asList(seq);
1054 return forSequences;
1058 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1061 * @param showOrHideMenu
1062 * the menu to add to
1063 * @param forSequences
1064 * the sequences whose annotations may be shown or hidden
1069 * if true this is a special label meaning 'All'
1070 * @param actionIsShow
1071 * if true, the select menu item action is to show the annotation
1074 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
1075 final List<SequenceI> forSequences, String calcId,
1076 final List<String> types, final boolean allTypes,
1077 final boolean actionIsShow)
1079 String label = types.toString(); // [a, b, c]
1080 label = label.substring(1, label.length() - 1); // a, b, c
1081 final JMenuItem item = new JMenuItem(label);
1082 item.setToolTipText(calcId);
1083 item.addActionListener(new ActionListener()
1086 public void actionPerformed(ActionEvent e)
1088 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1089 types, forSequences, allTypes, actionIsShow);
1093 showOrHideMenu.add(item);
1096 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
1099 // TODO: usability: thread off the generation of group url content so root
1100 // menu appears asap
1101 // sequence only URLs
1102 // ID/regex match URLs
1103 JMenu groupLinksMenu = new JMenu(
1104 MessageManager.getString("action.group_link"));
1105 // three types of url that might be created.
1106 JMenu[] linkMenus = new JMenu[] { null,
1107 new JMenu(MessageManager.getString("action.ids")),
1108 new JMenu(MessageManager.getString("action.sequences")),
1109 new JMenu(MessageManager.getString("action.ids_sequences")) };
1111 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1112 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1113 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
1114 for (int sq = 0; sq < seqs.length; sq++)
1117 int start = seqs[sq].findPosition(sg.getStartRes()),
1118 end = seqs[sq].findPosition(sg.getEndRes());
1119 // just collect ids from dataset sequence
1120 // TODO: check if IDs collected from selecton group intersects with the
1121 // current selection, too
1122 SequenceI sqi = seqs[sq];
1123 while (sqi.getDatasetSequence() != null)
1125 sqi = sqi.getDatasetSequence();
1127 List<DBRefEntry> dbr = sqi.getDBRefs();
1129 if (dbr != null && (nd = dbr.size()) > 0)
1131 for (int d = 0; d < nd; d++)
1133 DBRefEntry e = dbr.get(d);
1134 String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase(Locale.ROOT);
1135 Object[] sarray = commonDbrefs.get(src);
1138 sarray = new Object[2];
1139 sarray[0] = new int[] { 0 };
1140 sarray[1] = new String[seqs.length];
1142 commonDbrefs.put(src, sarray);
1145 if (((String[]) sarray[1])[sq] == null)
1147 if (!e.hasMap() || (e.getMap()
1148 .locateMappedRange(start, end) != null))
1150 ((String[]) sarray[1])[sq] = e.getAccessionId();
1151 ((int[]) sarray[0])[0]++;
1157 // now create group links for all distinct ID/sequence sets.
1158 boolean addMenu = false; // indicates if there are any group links to give
1160 for (String link : groupLinks)
1162 GroupUrlLink urlLink = null;
1165 urlLink = new GroupUrlLink(link);
1166 } catch (Exception foo)
1168 Console.error("Exception for GroupURLLink '" + link + "'", foo);
1171 if (!urlLink.isValid())
1173 Console.error(urlLink.getInvalidMessage());
1176 final String label = urlLink.getLabel();
1177 boolean usingNames = false;
1178 // Now see which parts of the group apply for this URL
1179 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1180 Object[] idset = commonDbrefs.get(ltarget.toUpperCase(Locale.ROOT));
1181 String[] seqstr, ids; // input to makeUrl
1184 int numinput = ((int[]) idset[0])[0];
1185 String[] allids = ((String[]) idset[1]);
1186 seqstr = new String[numinput];
1187 ids = new String[numinput];
1188 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1190 if (allids[sq] != null)
1192 ids[idcount] = allids[sq];
1193 seqstr[idcount++] = idandseqs[1][sq];
1199 // just use the id/seq set
1200 seqstr = idandseqs[1];
1204 // and try and make the groupURL!
1206 Object[] urlset = null;
1209 urlset = urlLink.makeUrlStubs(ids, seqstr,
1210 "FromJalview" + System.currentTimeMillis(), false);
1211 } catch (UrlStringTooLongException e)
1216 int type = urlLink.getGroupURLType() & 3;
1217 // first two bits ofurlLink type bitfield are sequenceids and sequences
1218 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1219 addshowLink(linkMenus[type],
1220 label + (((type & 1) == 1)
1221 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1229 groupLinksMenu = new JMenu(
1230 MessageManager.getString("action.group_link"));
1231 for (int m = 0; m < linkMenus.length; m++)
1233 if (linkMenus[m] != null
1234 && linkMenus[m].getMenuComponentCount() > 0)
1236 groupLinksMenu.add(linkMenus[m]);
1240 groupMenu.add(groupLinksMenu);
1250 private void jbInit() throws Exception
1252 groupMenu.setText(MessageManager.getString("label.selection"));
1253 groupName.setText(MessageManager.getString("label.name"));
1254 groupName.addActionListener(new ActionListener()
1257 public void actionPerformed(ActionEvent e)
1259 groupName_actionPerformed();
1262 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1264 JMenuItem sequenceName = new JMenuItem(
1265 MessageManager.getString("label.edit_name_description"));
1266 sequenceName.addActionListener(new ActionListener()
1269 public void actionPerformed(ActionEvent e)
1271 sequenceName_actionPerformed();
1274 JMenuItem chooseAnnotations = new JMenuItem(
1275 MessageManager.getString("action.choose_annotations"));
1276 chooseAnnotations.addActionListener(new ActionListener()
1279 public void actionPerformed(ActionEvent e)
1281 chooseAnnotations_actionPerformed(e);
1284 JMenuItem sequenceDetails = new JMenuItem(
1285 MessageManager.getString("label.sequence_details"));
1286 sequenceDetails.addActionListener(new ActionListener()
1289 public void actionPerformed(ActionEvent e)
1291 createSequenceDetailsReport(new SequenceI[] { sequence });
1294 JMenuItem sequenceSelDetails = new JMenuItem(
1295 MessageManager.getString("label.sequence_details"));
1296 sequenceSelDetails.addActionListener(new ActionListener()
1299 public void actionPerformed(ActionEvent e)
1301 createSequenceDetailsReport(ap.av.getSequenceSelection());
1306 .setText(MessageManager.getString("action.remove_group"));
1307 unGroupMenuItem.addActionListener(new ActionListener()
1310 public void actionPerformed(ActionEvent e)
1312 unGroupMenuItem_actionPerformed();
1316 .setText(MessageManager.getString("action.create_group"));
1317 createGroupMenuItem.addActionListener(new ActionListener()
1320 public void actionPerformed(ActionEvent e)
1322 createGroupMenuItem_actionPerformed();
1326 JMenuItem outline = new JMenuItem(
1327 MessageManager.getString("action.border_colour"));
1328 outline.addActionListener(new ActionListener()
1331 public void actionPerformed(ActionEvent e)
1333 outline_actionPerformed();
1336 showBoxes.setText(MessageManager.getString("action.boxes"));
1337 showBoxes.setState(true);
1338 showBoxes.addActionListener(new ActionListener()
1341 public void actionPerformed(ActionEvent e)
1343 showBoxes_actionPerformed();
1346 showText.setText(MessageManager.getString("action.text"));
1347 showText.setState(true);
1348 showText.addActionListener(new ActionListener()
1351 public void actionPerformed(ActionEvent e)
1353 showText_actionPerformed();
1356 showColourText.setText(MessageManager.getString("label.colour_text"));
1357 showColourText.addActionListener(new ActionListener()
1360 public void actionPerformed(ActionEvent e)
1362 showColourText_actionPerformed();
1366 .setText(MessageManager.getString("label.show_non_conserved"));
1367 displayNonconserved.setState(true);
1368 displayNonconserved.addActionListener(new ActionListener()
1371 public void actionPerformed(ActionEvent e)
1373 showNonconserved_actionPerformed();
1376 editMenu.setText(MessageManager.getString("action.edit"));
1377 JMenuItem cut = new JMenuItem(MessageManager.getString("action.cut"));
1378 cut.addActionListener(new ActionListener()
1381 public void actionPerformed(ActionEvent e)
1383 cut_actionPerformed();
1386 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1387 upperCase.addActionListener(new ActionListener()
1390 public void actionPerformed(ActionEvent e)
1395 JMenuItem copy = new JMenuItem(MessageManager.getString("action.copy"));
1396 copy.addActionListener(new ActionListener()
1399 public void actionPerformed(ActionEvent e)
1401 copy_actionPerformed();
1404 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1405 lowerCase.addActionListener(new ActionListener()
1408 public void actionPerformed(ActionEvent e)
1413 toggle.setText(MessageManager.getString("label.toggle_case"));
1414 toggle.addActionListener(new ActionListener()
1417 public void actionPerformed(ActionEvent e)
1423 MessageManager.getString("label.out_to_textbox") + "...");
1424 seqShowAnnotationsMenu
1425 .setText(MessageManager.getString("label.show_annotations"));
1426 seqHideAnnotationsMenu
1427 .setText(MessageManager.getString("label.hide_annotations"));
1428 groupShowAnnotationsMenu
1429 .setText(MessageManager.getString("label.show_annotations"));
1430 groupHideAnnotationsMenu
1431 .setText(MessageManager.getString("label.hide_annotations"));
1432 JMenuItem sequenceFeature = new JMenuItem(
1433 MessageManager.getString("label.create_sequence_feature"));
1434 sequenceFeature.addActionListener(new ActionListener()
1437 public void actionPerformed(ActionEvent e)
1439 sequenceFeature_actionPerformed();
1442 editGroupMenu.setText(MessageManager.getString("label.group"));
1443 chooseStructure.setText(
1444 MessageManager.getString("label.show_pdbstruct_dialog"));
1445 chooseStructure.addActionListener(new ActionListener()
1448 public void actionPerformed(ActionEvent actionEvent)
1450 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1451 if (ap.av.getSelectionGroup() != null)
1453 selectedSeqs = ap.av.getSequenceSelection();
1455 new StructureChooser(selectedSeqs, sequence, ap);
1460 .setText(MessageManager.getString("label.view_rna_structure"));
1462 // colStructureMenu.setText("Colour By Structure");
1463 JMenuItem editSequence = new JMenuItem(
1464 MessageManager.getString("label.edit_sequence") + "...");
1465 editSequence.addActionListener(new ActionListener()
1468 public void actionPerformed(ActionEvent actionEvent)
1470 editSequence_actionPerformed();
1473 makeReferenceSeq.setText(
1474 MessageManager.getString("label.mark_as_representative"));
1475 makeReferenceSeq.addActionListener(new ActionListener()
1479 public void actionPerformed(ActionEvent actionEvent)
1481 makeReferenceSeq_actionPerformed(actionEvent);
1486 groupMenu.add(sequenceSelDetails);
1489 add(rnaStructureMenu);
1490 add(chooseStructure);
1493 JMenuItem hideInsertions = new JMenuItem(
1494 MessageManager.getString("label.hide_insertions"));
1495 hideInsertions.addActionListener(new ActionListener()
1499 public void actionPerformed(ActionEvent e)
1501 hideInsertions_actionPerformed(e);
1504 add(hideInsertions);
1506 // annotations configuration panel suppressed for now
1507 // groupMenu.add(chooseAnnotations);
1510 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1511 * (if a selection group is in force).
1513 sequenceMenu.add(seqShowAnnotationsMenu);
1514 sequenceMenu.add(seqHideAnnotationsMenu);
1515 sequenceMenu.add(seqAddReferenceAnnotations);
1516 groupMenu.add(groupShowAnnotationsMenu);
1517 groupMenu.add(groupHideAnnotationsMenu);
1518 groupMenu.add(groupAddReferenceAnnotations);
1519 groupMenu.add(editMenu);
1520 groupMenu.add(outputMenu);
1521 groupMenu.add(sequenceFeature);
1522 groupMenu.add(createGroupMenuItem);
1523 groupMenu.add(unGroupMenuItem);
1524 groupMenu.add(editGroupMenu);
1525 sequenceMenu.add(sequenceName);
1526 sequenceMenu.add(sequenceDetails);
1527 sequenceMenu.add(makeReferenceSeq);
1534 editMenu.add(editSequence);
1535 editMenu.add(upperCase);
1536 editMenu.add(lowerCase);
1537 editMenu.add(toggle);
1538 editGroupMenu.add(groupName);
1539 editGroupMenu.add(colourMenu);
1540 editGroupMenu.add(showBoxes);
1541 editGroupMenu.add(showText);
1542 editGroupMenu.add(showColourText);
1543 editGroupMenu.add(outline);
1544 editGroupMenu.add(displayNonconserved);
1548 * Constructs the entries for the colour menu
1550 protected void initColourMenu()
1552 colourMenu.setText(MessageManager.getString("label.group_colour"));
1553 textColour.setText(MessageManager.getString("label.text_colour"));
1554 textColour.addActionListener(new ActionListener()
1557 public void actionPerformed(ActionEvent e)
1559 textColour_actionPerformed();
1563 abovePIDColour.setText(
1564 MessageManager.getString("label.above_identity_threshold"));
1565 abovePIDColour.addActionListener(new ActionListener()
1568 public void actionPerformed(ActionEvent e)
1570 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1575 MessageManager.getString("label.modify_identity_threshold"));
1576 modifyPID.addActionListener(new ActionListener()
1579 public void actionPerformed(ActionEvent e)
1581 modifyPID_actionPerformed();
1585 conservationMenuItem
1586 .setText(MessageManager.getString("action.by_conservation"));
1587 conservationMenuItem.addActionListener(new ActionListener()
1590 public void actionPerformed(ActionEvent e)
1592 conservationMenuItem_actionPerformed(
1593 conservationMenuItem.isSelected());
1597 annotationColour = new JRadioButtonMenuItem(
1598 MessageManager.getString("action.by_annotation"));
1599 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1600 annotationColour.setEnabled(false);
1601 annotationColour.setToolTipText(
1602 MessageManager.getString("label.by_annotation_tooltip"));
1604 modifyConservation.setText(MessageManager
1605 .getString("label.modify_conservation_threshold"));
1606 modifyConservation.addActionListener(new ActionListener()
1609 public void actionPerformed(ActionEvent e)
1611 modifyConservation_actionPerformed();
1617 * Builds the group colour sub-menu, including any user-defined colours which
1618 * were loaded at startup or during the Jalview session
1620 protected void buildColourMenu()
1622 SequenceGroup sg = ap.av.getSelectionGroup();
1626 * popup menu with no sequence group scope
1630 colourMenu.removeAll();
1631 colourMenu.add(textColour);
1632 colourMenu.addSeparator();
1634 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1636 bg.add(annotationColour);
1637 colourMenu.add(annotationColour);
1639 colourMenu.addSeparator();
1640 colourMenu.add(conservationMenuItem);
1641 colourMenu.add(modifyConservation);
1642 colourMenu.add(abovePIDColour);
1643 colourMenu.add(modifyPID);
1646 protected void modifyConservation_actionPerformed()
1648 SequenceGroup sg = getGroup();
1651 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1652 SliderPanel.showConservationSlider();
1656 protected void modifyPID_actionPerformed()
1658 SequenceGroup sg = getGroup();
1661 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1663 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1664 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1665 SliderPanel.showPIDSlider();
1670 * Check for any annotations on the underlying dataset sequences (for the
1671 * current selection group) which are not 'on the alignment'.If any are found,
1672 * enable the option to add them to the alignment. The criteria for 'on the
1673 * alignment' is finding an alignment annotation on the alignment, matched on
1674 * calcId, label and sequenceRef.
1676 * A tooltip is also constructed that displays the source (calcId) and type
1677 * (label) of the annotations that can be added.
1680 * @param forSequences
1682 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1683 List<SequenceI> forSequences)
1685 menuItem.setEnabled(false);
1688 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1689 * Using TreeMap means calcIds are shown in alphabetical order.
1691 SortedMap<String, String> tipEntries = new TreeMap<>();
1692 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1693 AlignmentI al = this.ap.av.getAlignment();
1694 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1696 if (!candidates.isEmpty())
1698 StringBuilder tooltip = new StringBuilder(64);
1699 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1702 * Found annotations that could be added. Enable the menu item, and
1703 * configure its tooltip and action.
1705 menuItem.setEnabled(true);
1706 for (String calcId : tipEntries.keySet())
1708 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1710 String tooltipText = JvSwingUtils.wrapTooltip(true,
1711 tooltip.toString());
1712 menuItem.setToolTipText(tooltipText);
1714 menuItem.addActionListener(new ActionListener()
1717 public void actionPerformed(ActionEvent e)
1719 addReferenceAnnotations_actionPerformed(candidates);
1726 * Add annotations to the sequences and to the alignment.
1729 * a map whose keys are sequences on the alignment, and values a list
1730 * of annotations to add to each sequence
1732 protected void addReferenceAnnotations_actionPerformed(
1733 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1735 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1736 final AlignmentI alignment = this.ap.getAlignment();
1737 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1742 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1744 if (!ap.av.getAlignment().hasSeqrep())
1746 // initialise the display flags so the user sees something happen
1747 ap.av.setDisplayReferenceSeq(true);
1748 ap.av.setColourByReferenceSeq(true);
1749 ap.av.getAlignment().setSeqrep(sequence);
1753 if (ap.av.getAlignment().getSeqrep() == sequence)
1755 ap.av.getAlignment().setSeqrep(null);
1759 ap.av.getAlignment().setSeqrep(sequence);
1765 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1767 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1768 BitSet inserts = new BitSet();
1770 boolean markedPopup = false;
1771 // mark inserts in current selection
1772 if (ap.av.getSelectionGroup() != null)
1774 // mark just the columns in the selection group to be hidden
1775 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1776 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1778 // now clear columns without gaps
1779 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1785 inserts.and(sq.getInsertionsAsBits());
1787 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1788 ap.av.getSelectionGroup().getEndRes());
1791 // now mark for sequence under popup if we haven't already done it
1792 else if (!markedPopup && sequence != null)
1794 inserts.or(sequence.getInsertionsAsBits());
1796 // and set hidden columns accordingly
1797 hidden.hideColumns(inserts);
1802 protected void sequenceSelectionDetails_actionPerformed()
1804 createSequenceDetailsReport(ap.av.getSequenceSelection());
1807 public void createSequenceDetailsReport(SequenceI[] sequences)
1809 StringBuilder contents = new StringBuilder(128);
1810 contents.append("<html><body>");
1811 for (SequenceI seq : sequences)
1813 contents.append("<p><h2>" + MessageManager.formatMessage(
1814 "label.create_sequence_details_report_annotation_for",
1816 { seq.getDisplayId(true) }) + "</h2></p><p>");
1817 new SequenceAnnotationReport(false).createSequenceAnnotationReport(
1818 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1819 contents.append("</p>");
1821 contents.append("</body></html>");
1822 String report = contents.toString();
1824 JInternalFrame frame;
1825 if (Platform.isJS())
1827 JLabel textLabel = new JLabel();
1828 textLabel.setText(report);
1829 textLabel.setBackground(Color.WHITE);
1830 JPanel pane = new JPanel(new BorderLayout());
1831 pane.setOpaque(true);
1832 pane.setBackground(Color.WHITE);
1833 pane.add(textLabel, BorderLayout.NORTH);
1834 frame = new JInternalFrame();
1835 frame.getContentPane().add(new JScrollPane(pane));
1844 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1845 cap.setText(report);
1849 Desktop.addInternalFrame(frame,
1850 MessageManager.formatMessage("label.sequence_details_for",
1851 (sequences.length == 1 ? new Object[]
1852 { sequences[0].getDisplayId(true) }
1855 .getString("label.selection") })),
1859 protected void showNonconserved_actionPerformed()
1861 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1866 * call to refresh view after settings change
1870 ap.updateAnnotation();
1871 // removed paintAlignment(true) here:
1872 // updateAnnotation calls paintAlignment already, so don't need to call
1875 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1879 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1880 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1890 public void abovePIDColour_actionPerformed(boolean selected)
1892 SequenceGroup sg = getGroup();
1900 sg.cs.setConsensus(AAFrequency.calculate(
1901 sg.getSequences(ap.av.getHiddenRepSequences()),
1902 sg.getStartRes(), sg.getEndRes() + 1));
1904 int threshold = SliderPanel.setPIDSliderSource(ap,
1905 sg.getGroupColourScheme(), getGroup().getName());
1907 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1909 SliderPanel.showPIDSlider();
1912 // remove PIDColouring
1914 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1915 SliderPanel.hidePIDSlider();
1917 modifyPID.setEnabled(selected);
1923 * Open a panel where the user can choose which types of sequence annotation
1928 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1930 // todo correct way to guard against opening a duplicate panel?
1931 new AnnotationChooser(ap);
1940 public void conservationMenuItem_actionPerformed(boolean selected)
1942 SequenceGroup sg = getGroup();
1950 // JBPNote: Conservation name shouldn't be i18n translated
1951 Conservation c = new Conservation("Group",
1952 sg.getSequences(ap.av.getHiddenRepSequences()),
1953 sg.getStartRes(), sg.getEndRes() + 1);
1956 c.verdict(false, ap.av.getConsPercGaps());
1957 sg.cs.setConservation(c);
1959 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1961 SliderPanel.showConservationSlider();
1964 // remove ConservationColouring
1966 sg.cs.setConservation(null);
1967 SliderPanel.hideConservationSlider();
1969 modifyConservation.setEnabled(selected);
1975 * Shows a dialog where group name and description may be edited
1977 protected void groupName_actionPerformed()
1979 SequenceGroup sg = getGroup();
1980 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1981 sg.getDescription(),
1982 MessageManager.getString("label.group_name"),
1983 MessageManager.getString("label.group_description"));
1984 dialog.showDialog(ap.alignFrame,
1985 MessageManager.getString("label.edit_group_name_description"),
1991 sg.setName(dialog.getName());
1992 sg.setDescription(dialog.getDescription());
1999 * Get selection group - adding it to the alignment if necessary.
2001 * @return sequence group to operate on
2003 SequenceGroup getGroup()
2005 SequenceGroup sg = ap.av.getSelectionGroup();
2006 // this method won't add a new group if it already exists
2009 ap.av.getAlignment().addGroup(sg);
2016 * Shows a dialog where the sequence name and description may be edited. If a
2017 * name containing spaces is entered, these are converted to underscores, with a
2020 void sequenceName_actionPerformed()
2022 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2023 sequence.getDescription(),
2024 MessageManager.getString("label.sequence_name"),
2025 MessageManager.getString("label.sequence_description"));
2026 dialog.showDialog(ap.alignFrame,
2027 MessageManager.getString(
2028 "label.edit_sequence_name_description"),
2034 if (dialog.getName() != null)
2036 if (dialog.getName().indexOf(" ") > -1)
2038 JvOptionPane.showMessageDialog(ap,
2039 MessageManager.getString(
2040 "label.spaces_converted_to_underscores"),
2041 MessageManager.getString(
2042 "label.no_spaces_allowed_sequence_name"),
2043 JvOptionPane.WARNING_MESSAGE);
2045 sequence.setName(dialog.getName().replace(' ', '_'));
2046 ap.paintAlignment(false, false);
2048 sequence.setDescription(dialog.getDescription());
2049 ap.av.firePropertyChange("alignment", null,
2050 ap.av.getAlignment().getSequences());
2061 void unGroupMenuItem_actionPerformed()
2063 SequenceGroup sg = ap.av.getSelectionGroup();
2064 ap.av.getAlignment().deleteGroup(sg);
2065 ap.av.setSelectionGroup(null);
2069 void createGroupMenuItem_actionPerformed()
2071 getGroup(); // implicitly creates group - note - should apply defaults / use
2072 // standard alignment window logic for this
2077 * Offers a colour chooser and sets the selected colour as the group outline
2079 protected void outline_actionPerformed()
2081 String title = MessageManager
2082 .getString("label.select_outline_colour");
2083 ColourChooserListener listener = new ColourChooserListener()
2086 public void colourSelected(Color c)
2088 getGroup().setOutlineColour(c);
2092 JalviewColourChooser.showColourChooser(Desktop.getDesktop(),
2093 title, Color.BLUE, listener);
2102 public void showBoxes_actionPerformed()
2104 getGroup().setDisplayBoxes(showBoxes.isSelected());
2114 public void showText_actionPerformed()
2116 getGroup().setDisplayText(showText.isSelected());
2126 public void showColourText_actionPerformed()
2128 getGroup().setColourText(showColourText.isSelected());
2132 void hideSequences(boolean representGroup)
2134 ap.av.hideSequences(sequence, representGroup);
2137 public void copy_actionPerformed()
2139 ap.alignFrame.copy_actionPerformed();
2142 public void cut_actionPerformed()
2144 ap.alignFrame.cut_actionPerformed();
2147 void changeCase(ActionEvent e)
2149 Object source = e.getSource();
2150 SequenceGroup sg = ap.av.getSelectionGroup();
2154 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2155 sg.getStartRes(), sg.getEndRes() + 1);
2160 if (source == toggle)
2162 description = MessageManager.getString("label.toggle_case");
2163 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2165 else if (source == upperCase)
2167 description = MessageManager.getString("label.to_upper_case");
2168 caseChange = ChangeCaseCommand.TO_UPPER;
2172 description = MessageManager.getString("label.to_lower_case");
2173 caseChange = ChangeCaseCommand.TO_LOWER;
2176 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2177 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2178 startEnd, caseChange);
2180 ap.alignFrame.addHistoryItem(caseCommand);
2182 ap.av.firePropertyChange("alignment", null,
2183 ap.av.getAlignment().getSequences());
2188 public void outputText_actionPerformed(ActionEvent e)
2190 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2191 cap.setForInput(null);
2192 Desktop.addInternalFrame(cap, MessageManager
2193 .formatMessage("label.alignment_output_command", new Object[]
2194 { e.getActionCommand() }), 600, 500);
2196 String[] omitHidden = null;
2198 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2199 // or we simply trust the user wants
2200 // wysiwig behaviour
2202 FileFormatI fileFormat = FileFormats.getInstance()
2203 .forName(e.getActionCommand());
2205 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2208 public void sequenceFeature_actionPerformed()
2210 SequenceGroup sg = ap.av.getSelectionGroup();
2216 List<SequenceI> seqs = new ArrayList<>();
2217 List<SequenceFeature> features = new ArrayList<>();
2220 * assemble dataset sequences, and template new sequence features,
2221 * for the amend features dialog
2223 int gSize = sg.getSize();
2224 for (int i = 0; i < gSize; i++)
2226 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2227 int end = sg.findEndRes(sg.getSequenceAt(i));
2230 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2231 features.add(new SequenceFeature(null, null, start, end, null));
2236 * an entirely gapped region will generate empty lists of sequence / features
2238 if (!seqs.isEmpty())
2240 new FeatureEditor(ap, seqs, features, true).showDialog();
2244 public void textColour_actionPerformed()
2246 SequenceGroup sg = getGroup();
2249 new TextColourChooser().chooseColour(ap, sg);
2254 * Shows a dialog where sequence characters may be edited. Any changes are
2255 * applied, and added as an available 'Undo' item in the edit commands
2258 public void editSequence_actionPerformed()
2260 SequenceGroup sg = ap.av.getSelectionGroup();
2262 SequenceI seq = sequence;
2267 seq = sg.getSequenceAt(0);
2270 EditNameDialog dialog = new EditNameDialog(
2271 seq.getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
2272 null, MessageManager.getString("label.edit_sequence"), null);
2273 dialog.showDialog(ap.alignFrame,
2274 MessageManager.getString("label.edit_sequence"),
2280 EditCommand editCommand = new EditCommand(
2281 MessageManager.getString("label.edit_sequences"),
2283 dialog.getName().replace(' ',
2284 ap.av.getGapCharacter()),
2285 sg.getSequencesAsArray(
2286 ap.av.getHiddenRepSequences()),
2287 sg.getStartRes(), sg.getEndRes() + 1,
2288 ap.av.getAlignment());
2289 ap.alignFrame.addHistoryItem(editCommand);
2290 ap.av.firePropertyChange("alignment", null,
2291 ap.av.getAlignment().getSequences());
2298 * Action on user selecting an item from the colour menu (that does not have
2299 * its bespoke action handler)
2304 public void changeColour_actionPerformed(String colourSchemeName)
2306 SequenceGroup sg = getGroup();
2308 * switch to the chosen colour scheme (or null for None)
2310 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2311 .getColourScheme(colourSchemeName, ap.av, sg,
2312 ap.av.getHiddenRepSequences());
2313 sg.setColourScheme(colourScheme);
2314 if (colourScheme instanceof Blosum62ColourScheme
2315 || colourScheme instanceof PIDColourScheme)
2317 sg.cs.setConsensus(AAFrequency.calculate(
2318 sg.getSequences(ap.av.getHiddenRepSequences()),
2319 sg.getStartRes(), sg.getEndRes() + 1));