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;
36 import java.util.Objects;
37 import java.util.SortedMap;
38 import java.util.TreeMap;
39 import java.util.Vector;
41 import javax.swing.ButtonGroup;
42 import javax.swing.JCheckBoxMenuItem;
43 import javax.swing.JInternalFrame;
44 import javax.swing.JLabel;
45 import javax.swing.JMenu;
46 import javax.swing.JMenuItem;
47 import javax.swing.JPanel;
48 import javax.swing.JPopupMenu;
49 import javax.swing.JRadioButtonMenuItem;
50 import javax.swing.JScrollPane;
52 import jalview.analysis.AAFrequency;
53 import jalview.analysis.AlignmentAnnotationUtils;
54 import jalview.analysis.AlignmentUtils;
55 import jalview.analysis.Conservation;
56 import jalview.api.AlignViewportI;
57 import jalview.bin.Cache;
58 import jalview.commands.ChangeCaseCommand;
59 import jalview.commands.EditCommand;
60 import jalview.commands.EditCommand.Action;
61 import jalview.datamodel.AlignmentAnnotation;
62 import jalview.datamodel.AlignmentI;
63 import jalview.datamodel.DBRefEntry;
64 import jalview.datamodel.HiddenColumns;
65 import jalview.datamodel.MappedFeatures;
66 import jalview.datamodel.PDBEntry;
67 import jalview.datamodel.SequenceFeature;
68 import jalview.datamodel.SequenceGroup;
69 import jalview.datamodel.SequenceI;
70 import jalview.gui.ColourMenuHelper.ColourChangeListener;
71 import jalview.gui.JalviewColourChooser.ColourChooserListener;
72 import jalview.io.FileFormatI;
73 import jalview.io.FileFormats;
74 import jalview.io.FormatAdapter;
75 import jalview.io.SequenceAnnotationReport;
76 import jalview.schemes.Blosum62ColourScheme;
77 import jalview.schemes.ColourSchemeI;
78 import jalview.schemes.ColourSchemes;
79 import jalview.schemes.PIDColourScheme;
80 import jalview.schemes.ResidueColourScheme;
81 import jalview.util.Comparison;
82 import jalview.util.GroupUrlLink;
83 import jalview.util.GroupUrlLink.UrlStringTooLongException;
84 import jalview.util.MessageManager;
85 import jalview.util.Platform;
86 import jalview.util.StringUtils;
87 import jalview.util.UrlLink;
88 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
91 * The popup menu that is displayed on right-click on a sequence id, or in the
94 public class PopupMenu extends JPopupMenu implements ColourChangeListener
97 * maximum length of feature description to include in popup menu item text
99 private static final int FEATURE_DESC_MAX = 40;
102 * true for ID Panel menu, false for alignment panel menu
104 private final boolean forIdPanel;
106 private final AlignmentPanel ap;
109 * the sequence under the cursor when clicked
110 * (additional sequences may be selected)
112 private final SequenceI sequence;
114 JMenu groupMenu = new JMenu();
116 JMenuItem groupName = new JMenuItem();
118 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
120 protected JMenuItem modifyPID = new JMenuItem();
122 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
124 protected JRadioButtonMenuItem annotationColour;
126 protected JMenuItem modifyConservation = new JMenuItem();
128 JMenu sequenceMenu = new JMenu();
130 JMenuItem makeReferenceSeq = new JMenuItem();
132 JMenuItem createGroupMenuItem = new JMenuItem();
134 JMenuItem unGroupMenuItem = new JMenuItem();
136 JMenu colourMenu = new JMenu();
138 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
140 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
142 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
144 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
146 JMenu editMenu = new JMenu();
148 JMenuItem upperCase = new JMenuItem();
150 JMenuItem lowerCase = new JMenuItem();
152 JMenuItem toggle = new JMenuItem();
154 JMenu outputMenu = new JMenu();
156 JMenu seqShowAnnotationsMenu = new JMenu();
158 JMenu seqHideAnnotationsMenu = new JMenu();
160 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
161 MessageManager.getString("label.add_reference_annotations"));
163 JMenu groupShowAnnotationsMenu = new JMenu();
165 JMenu groupHideAnnotationsMenu = new JMenu();
167 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
168 MessageManager.getString("label.add_reference_annotations"));
170 JMenuItem textColour = new JMenuItem();
172 JMenu editGroupMenu = new JMenu();
174 JMenuItem chooseStructure = new JMenuItem();
176 JMenu rnaStructureMenu = new JMenu();
179 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
180 * and/or features provided. Hyperlinks may include a lookup by sequence id,
181 * or database cross-references, depending on which links are enabled in user
188 protected static JMenu buildLinkMenu(final SequenceI seq,
189 List<SequenceFeature> features)
191 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
193 List<String> nlinks = null;
196 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
197 UrlLink.sort(nlinks);
201 nlinks = new ArrayList<>();
204 if (features != null)
206 for (SequenceFeature sf : features)
208 if (sf.links != null)
210 for (String link : sf.links)
219 * instantiate the hyperlinklink templates from sequence data;
220 * note the order of the templates is preserved in the map
222 Map<String, List<String>> linkset = new LinkedHashMap<>();
223 for (String link : nlinks)
225 UrlLink urlLink = null;
228 urlLink = new UrlLink(link);
229 } catch (Exception foo)
231 Cache.log.error("Exception for URLLink '" + link + "'", foo);
235 if (!urlLink.isValid())
237 Cache.log.error(urlLink.getInvalidMessage());
241 urlLink.createLinksFromSeq(seq, linkset);
245 * construct menu items for the hyperlinks (still preserving
246 * the order of the sorted templates)
248 addUrlLinks(linkMenu, linkset.values());
254 * A helper method that builds menu items from the given links, with action
255 * handlers to open the link URL, and adds them to the linkMenu. Each provided
256 * link should be a list whose second item is the menu text, and whose fourth
257 * item is the URL to open when the menu item is selected.
262 static private void addUrlLinks(JMenu linkMenu,
263 Collection<List<String>> linkset)
265 for (List<String> linkstrset : linkset)
267 final String url = linkstrset.get(3);
268 JMenuItem item = new JMenuItem(linkstrset.get(1));
269 item.setToolTipText(MessageManager
270 .formatMessage("label.open_url_param", new Object[]
272 item.addActionListener(new ActionListener()
275 public void actionPerformed(ActionEvent e)
277 new Thread(new Runnable()
292 * Opens the provided url in the default web browser, or shows an error
293 * message if this fails
297 static void showLink(String url)
301 jalview.util.BrowserLauncher.openURL(url);
302 } catch (Exception ex)
304 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
305 MessageManager.getString("label.web_browser_not_found_unix"),
306 MessageManager.getString("label.web_browser_not_found"),
307 JvOptionPane.WARNING_MESSAGE);
309 ex.printStackTrace();
314 * add a late bound groupURL item to the given linkMenu
318 * - menu label string
319 * @param urlgenerator
320 * GroupURLLink used to generate URL
322 * Object array returned from the makeUrlStubs function.
324 static void addshowLink(JMenu linkMenu, String label,
325 final GroupUrlLink urlgenerator, final Object[] urlstub)
327 JMenuItem item = new JMenuItem(label);
328 item.setToolTipText(MessageManager
329 .formatMessage("label.open_url_seqs_param", new Object[]
330 { urlgenerator.getUrl_prefix(),
331 urlgenerator.getNumberInvolved(urlstub) }));
332 // TODO: put in info about what is being sent.
333 item.addActionListener(new ActionListener()
336 public void actionPerformed(ActionEvent e)
338 new Thread(new Runnable()
346 showLink(urlgenerator.constructFrom(urlstub));
347 } catch (UrlStringTooLongException e2)
360 * Constructor for a PopupMenu for a click in the alignment panel (on a residue)
363 * the panel in which the mouse is clicked
365 * the sequence under the mouse
366 * @throws NullPointerException
369 public PopupMenu(final AlignmentPanel ap, SequenceI seq, int column)
371 this(false, ap, seq, column, null);
375 * Constructor for a PopupMenu for a click in the sequence id panel
378 * the panel in which the mouse is clicked
380 * the sequence under the mouse click
382 * templates for sequence external links
383 * @throws NullPointerException
386 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
387 List<String> groupLinks)
389 this(true, alignPanel, seq, -1, groupLinks);
393 * Private constructor that constructs a popup menu for either sequence ID
394 * Panel, or alignment context
400 * aligned column position (0...)
403 private PopupMenu(boolean fromIdPanel,
404 final AlignmentPanel alignPanel,
405 final SequenceI seq, final int column, List<String> groupLinks)
407 Objects.requireNonNull(seq);
408 this.forIdPanel = fromIdPanel;
409 this.ap = alignPanel;
412 for (String ff : FileFormats.getInstance().getWritableFormats(true))
414 JMenuItem item = new JMenuItem(ff);
416 item.addActionListener(new ActionListener()
419 public void actionPerformed(ActionEvent e)
421 outputText_actionPerformed(e);
425 outputMenu.add(item);
429 * Build menus for annotation types that may be shown or hidden, and for
430 * 'reference annotations' that may be added to the alignment. First for the
431 * currently selected sequence (if there is one):
433 final List<SequenceI> selectedSequence = (forIdPanel && seq != null
435 : Collections.<SequenceI> emptyList());
436 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
437 seqHideAnnotationsMenu, selectedSequence);
438 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
442 * And repeat for the current selection group (if there is one):
444 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
445 ? Collections.<SequenceI> emptyList()
446 : alignPanel.av.getSelectionGroup().getSequences());
447 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
448 groupHideAnnotationsMenu, selectedGroup);
449 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
455 } catch (Exception e)
463 sequenceMenu.setText(sequence.getName());
464 if (seq == alignPanel.av.getAlignment().getSeqrep())
466 makeReferenceSeq.setText(
467 MessageManager.getString("action.unmark_as_reference"));
471 makeReferenceSeq.setText(
472 MessageManager.getString("action.set_as_reference"));
475 if (!alignPanel.av.getAlignment().isNucleotide())
477 remove(rnaStructureMenu);
481 int origCount = rnaStructureMenu.getItemCount();
483 * add menu items to 2D-render any alignment or sequence secondary
484 * structure annotation
486 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
487 .getAlignmentAnnotation();
490 for (final AlignmentAnnotation aa : aas)
492 if (aa.isValidStruc() && aa.sequenceRef == null)
495 * valid alignment RNA secondary structure annotation
497 menuItem = new JMenuItem();
498 menuItem.setText(MessageManager.formatMessage(
499 "label.2d_rna_structure_line", new Object[]
501 menuItem.addActionListener(new ActionListener()
504 public void actionPerformed(ActionEvent e)
506 new AppVarna(seq, aa, alignPanel);
509 rnaStructureMenu.add(menuItem);
514 if (seq.getAnnotation() != null)
516 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
517 for (final AlignmentAnnotation aa : seqAnns)
519 if (aa.isValidStruc())
522 * valid sequence RNA secondary structure annotation
524 // TODO: make rnastrucF a bit more nice
525 menuItem = new JMenuItem();
526 menuItem.setText(MessageManager.formatMessage(
527 "label.2d_rna_sequence_name", new Object[]
529 menuItem.addActionListener(new ActionListener()
532 public void actionPerformed(ActionEvent e)
534 // TODO: VARNA does'nt print gaps in the sequence
535 new AppVarna(seq, aa, alignPanel);
538 rnaStructureMenu.add(menuItem);
542 if (rnaStructureMenu.getItemCount() == origCount)
544 remove(rnaStructureMenu);
548 menuItem = new JMenuItem(
549 MessageManager.getString("action.hide_sequences"));
550 menuItem.addActionListener(new ActionListener()
553 public void actionPerformed(ActionEvent e)
555 hideSequences(false);
560 if (alignPanel.av.getSelectionGroup() != null
561 && alignPanel.av.getSelectionGroup().getSize() > 1)
563 menuItem = new JMenuItem(MessageManager
564 .formatMessage("label.represent_group_with", new Object[]
566 menuItem.addActionListener(new ActionListener()
569 public void actionPerformed(ActionEvent e)
574 sequenceMenu.add(menuItem);
577 if (alignPanel.av.hasHiddenRows())
579 final int index = alignPanel.av.getAlignment().findIndex(seq);
581 if (alignPanel.av.adjustForHiddenSeqs(index)
582 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
584 menuItem = new JMenuItem(
585 MessageManager.getString("action.reveal_sequences"));
586 menuItem.addActionListener(new ActionListener()
589 public void actionPerformed(ActionEvent e)
591 alignPanel.av.showSequence(index);
592 if (alignPanel.overviewPanel != null)
594 alignPanel.overviewPanel.updateOverviewImage();
605 * - in the IdPanel (seq not null) if any sequence is hidden
606 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
608 if (alignPanel.av.hasHiddenRows())
610 boolean addOption = seq != null;
611 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
617 JMenuItem menuItem = new JMenuItem(
618 MessageManager.getString("action.reveal_all"));
619 menuItem.addActionListener(new ActionListener()
622 public void actionPerformed(ActionEvent e)
624 alignPanel.av.showAllHiddenSeqs();
625 if (alignPanel.overviewPanel != null)
627 alignPanel.overviewPanel.updateOverviewImage();
635 SequenceGroup sg = alignPanel.av.getSelectionGroup();
636 boolean isDefinedGroup = (sg != null)
637 ? alignPanel.av.getAlignment().getGroups().contains(sg)
640 if (sg != null && sg.getSize() > 0)
642 groupName.setText(MessageManager
643 .getString("label.edit_name_and_description_current_group"));
645 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
647 conservationMenuItem.setEnabled(!sg.isNucleotide());
651 if (sg.cs.conservationApplied())
653 conservationMenuItem.setSelected(true);
655 if (sg.cs.getThreshold() > 0)
657 abovePIDColour.setSelected(true);
660 modifyConservation.setEnabled(conservationMenuItem.isSelected());
661 modifyPID.setEnabled(abovePIDColour.isSelected());
662 displayNonconserved.setSelected(sg.getShowNonconserved());
663 showText.setSelected(sg.getDisplayText());
664 showColourText.setSelected(sg.getColourText());
665 showBoxes.setSelected(sg.getDisplayBoxes());
666 // add any groupURLs to the groupURL submenu and make it visible
667 if (groupLinks != null && groupLinks.size() > 0)
669 buildGroupURLMenu(sg, groupLinks);
671 // Add a 'show all structures' for the current selection
672 Hashtable<String, PDBEntry> pdbe = new Hashtable<>(), reppdb = new Hashtable<>();
674 SequenceI sqass = null;
675 for (SequenceI sq : alignPanel.av.getSequenceSelection())
677 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
678 if (pes != null && pes.size() > 0)
680 reppdb.put(pes.get(0).getId(), pes.get(0));
681 for (PDBEntry pe : pes)
683 pdbe.put(pe.getId(), pe);
693 final PDBEntry[] pe = pdbe.values()
694 .toArray(new PDBEntry[pdbe.size()]),
695 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
696 final JMenuItem gpdbview, rpdbview;
701 groupMenu.setVisible(false);
702 editMenu.setVisible(false);
707 createGroupMenuItem.setVisible(true);
708 unGroupMenuItem.setVisible(false);
709 editGroupMenu.setText(MessageManager.getString("action.edit_new_group"));
713 createGroupMenuItem.setVisible(false);
714 unGroupMenuItem.setVisible(true);
715 editGroupMenu.setText(MessageManager.getString("action.edit_group"));
720 sequenceMenu.setVisible(false);
721 chooseStructure.setVisible(false);
722 rnaStructureMenu.setVisible(false);
725 addLinksAndFeatures(seq, column);
731 * <li>configured sequence database links (ID panel popup menu)</li>
732 * <li>non-positional feature links (ID panel popup menu)</li>
733 * <li>positional feature links (alignment panel popup menu)</li>
734 * <li>feature details links (alignment panel popup menu)</li>
736 * If this panel is also showed complementary (CDS/protein) features, then links
737 * to their feature details are also added.
742 void addLinksAndFeatures(final SequenceI seq, final int column)
744 List<SequenceFeature> features = null;
747 features = sequence.getFeatures().getNonPositionalFeatures();
751 features = ap.getFeatureRenderer().findFeaturesAtColumn(sequence,
755 addLinks(seq, features);
759 addFeatureDetails(features, seq, column);
764 * Add a menu item to show feature details for each sequence feature. Any
765 * linked 'virtual' features (CDS/protein) are also optionally found and
772 protected void addFeatureDetails(List<SequenceFeature> features,
773 final SequenceI seq, final int column)
776 * add features in CDS/protein complement at the corresponding
777 * position if configured to do so
779 MappedFeatures mf = null;
780 if (ap.av.isShowComplementFeatures())
782 if (!Comparison.isGap(sequence.getCharAt(column)))
784 AlignViewportI complement = ap.getAlignViewport()
785 .getCodingComplement();
786 AlignFrame af = Desktop.getAlignFrameFor(complement);
787 FeatureRendererModel fr2 = af.getFeatureRenderer();
788 int seqPos = sequence.findPosition(column);
789 mf = fr2.findComplementFeaturesAtResidue(sequence, seqPos);
793 if (features.isEmpty() && mf == null)
796 * no features to show at this position
801 JMenu details = new JMenu(
802 MessageManager.getString("label.feature_details"));
805 String name = seq.getName();
806 for (final SequenceFeature sf : features)
808 addFeatureDetailsMenuItem(details, name, sf, null);
813 for (final SequenceFeature sf : mf.features)
815 addFeatureDetailsMenuItem(details, name, sf, mf);
821 * A helper method to add one menu item whose action is to show details for
822 * one feature. The menu text includes feature description, but this may be
830 void addFeatureDetailsMenuItem(JMenu details, final String seqName,
831 final SequenceFeature sf, MappedFeatures mf)
833 int start = sf.getBegin();
834 int end = sf.getEnd();
838 * show local rather than linked feature coordinates
840 int[] beginRange = mf.getMappedPositions(start, start);
841 int[] endRange = mf.getMappedPositions(end, end);
842 if (beginRange == null || endRange == null)
844 // e.g. variant extending to stop codon so not mappable
847 start = beginRange[0];
848 end = endRange[endRange.length - 1];
850 StringBuilder desc = new StringBuilder();
851 desc.append(sf.getType()).append(" ").append(String.valueOf(start));
854 desc.append(sf.isContactFeature() ? ":" : "-");
855 desc.append(String.valueOf(end));
857 String description = sf.getDescription();
858 if (description != null)
861 description = StringUtils.stripHtmlTags(description);
864 * truncate overlong descriptions unless they contain an href
865 * (as truncation could leave corrupted html)
867 boolean hasLink = description.indexOf("a href") > -1;
868 if (description.length() > FEATURE_DESC_MAX && !hasLink)
870 description = description.substring(0, FEATURE_DESC_MAX) + "...";
872 desc.append(description);
874 String featureGroup = sf.getFeatureGroup();
875 if (featureGroup != null)
877 desc.append(" (").append(featureGroup).append(")");
879 String htmlText = JvSwingUtils.wrapTooltip(true, desc.toString());
880 JMenuItem item = new JMenuItem(htmlText);
881 item.addActionListener(new ActionListener()
884 public void actionPerformed(ActionEvent e)
886 showFeatureDetails(sf, seqName, mf);
893 * Opens a panel showing a text report of feature details
899 protected void showFeatureDetails(SequenceFeature sf, String seqName,
902 JInternalFrame details;
905 details = new JInternalFrame();
906 JPanel panel = new JPanel(new BorderLayout());
907 panel.setOpaque(true);
908 panel.setBackground(Color.white);
909 // TODO JAL-3026 set style of table correctly for feature details
910 JLabel reprt = new JLabel(MessageManager
911 .formatMessage("label.html_content", new Object[]
912 { sf.getDetailsReport(seqName, mf) }));
913 reprt.setBackground(Color.WHITE);
914 reprt.setOpaque(true);
915 panel.add(reprt, BorderLayout.CENTER);
916 details.setContentPane(panel);
926 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
927 // it appears Java's CSS does not support border-collapse :-(
928 cap.addStylesheetRule("table { border-collapse: collapse;}");
929 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
930 cap.setText(sf.getDetailsReport(seqName, mf));
933 Desktop.addInternalFrame(details,
934 MessageManager.getString("label.feature_details"), 500, 500);
938 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
939 * When seq is not null, these are links for the sequence id, which may be to
940 * external web sites for the sequence accession, and/or links embedded in
941 * non-positional features. When seq is null, only links embedded in the
942 * provided features are added. If no links are found, the menu is not added.
947 void addLinks(final SequenceI seq, List<SequenceFeature> features)
949 JMenu linkMenu = buildLinkMenu(forIdPanel ? seq : null, features);
951 // only add link menu if it has entries
952 if (linkMenu.getItemCount() > 0)
956 sequenceMenu.add(linkMenu);
966 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
967 * "All" is added first, followed by a separator. Then add any annotation
968 * types associated with the current selection. Separate menus are built for
969 * the selected sequence group (if any), and the selected sequence.
971 * Some annotation rows are always rendered together - these can be identified
972 * by a common graphGroup property > -1. Only one of each group will be marked
973 * as visible (to avoid duplication of the display). For such groups we add a
974 * composite type name, e.g.
976 * IUPredWS (Long), IUPredWS (Short)
980 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
981 List<SequenceI> forSequences)
983 showMenu.removeAll();
984 hideMenu.removeAll();
986 final List<String> all = Arrays
988 { MessageManager.getString("label.all") });
989 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
991 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
993 showMenu.addSeparator();
994 hideMenu.addSeparator();
996 final AlignmentAnnotation[] annotations = ap.getAlignment()
997 .getAlignmentAnnotation();
1000 * Find shown/hidden annotations types, distinguished by source (calcId),
1001 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1002 * the insertion order, which is the order of the annotations on the
1005 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
1006 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
1007 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1008 AlignmentAnnotationUtils.asList(annotations), forSequences);
1010 for (String calcId : hiddenTypes.keySet())
1012 for (List<String> type : hiddenTypes.get(calcId))
1014 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1018 // grey out 'show annotations' if none are hidden
1019 showMenu.setEnabled(!hiddenTypes.isEmpty());
1021 for (String calcId : shownTypes.keySet())
1023 for (List<String> type : shownTypes.get(calcId))
1025 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1029 // grey out 'hide annotations' if none are shown
1030 hideMenu.setEnabled(!shownTypes.isEmpty());
1034 * Returns a list of sequences - either the current selection group (if there
1035 * is one), else the specified single sequence.
1040 protected List<SequenceI> getSequenceScope(SequenceI seq)
1042 List<SequenceI> forSequences = null;
1043 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
1044 if (selectionGroup != null && selectionGroup.getSize() > 0)
1046 forSequences = selectionGroup.getSequences();
1050 forSequences = seq == null ? Collections.<SequenceI> emptyList()
1051 : Arrays.asList(seq);
1053 return forSequences;
1057 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1060 * @param showOrHideMenu
1061 * the menu to add to
1062 * @param forSequences
1063 * the sequences whose annotations may be shown or hidden
1068 * if true this is a special label meaning 'All'
1069 * @param actionIsShow
1070 * if true, the select menu item action is to show the annotation
1073 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
1074 final List<SequenceI> forSequences, String calcId,
1075 final List<String> types, final boolean allTypes,
1076 final boolean actionIsShow)
1078 String label = types.toString(); // [a, b, c]
1079 label = label.substring(1, label.length() - 1); // a, b, c
1080 final JMenuItem item = new JMenuItem(label);
1081 item.setToolTipText(calcId);
1082 item.addActionListener(new ActionListener()
1085 public void actionPerformed(ActionEvent e)
1087 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1088 types, forSequences, allTypes, actionIsShow);
1092 showOrHideMenu.add(item);
1095 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
1098 // TODO: usability: thread off the generation of group url content so root
1099 // menu appears asap
1100 // sequence only URLs
1101 // ID/regex match URLs
1102 JMenu groupLinksMenu = new JMenu(
1103 MessageManager.getString("action.group_link"));
1104 // three types of url that might be created.
1105 JMenu[] linkMenus = new JMenu[] { null,
1106 new JMenu(MessageManager.getString("action.ids")),
1107 new JMenu(MessageManager.getString("action.sequences")),
1108 new JMenu(MessageManager.getString("action.ids_sequences")) };
1110 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1111 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1112 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
1113 for (int sq = 0; sq < seqs.length; sq++)
1116 int start = seqs[sq].findPosition(sg.getStartRes()),
1117 end = seqs[sq].findPosition(sg.getEndRes());
1118 // just collect ids from dataset sequence
1119 // TODO: check if IDs collected from selecton group intersects with the
1120 // current selection, too
1121 SequenceI sqi = seqs[sq];
1122 while (sqi.getDatasetSequence() != null)
1124 sqi = sqi.getDatasetSequence();
1126 List<DBRefEntry> dbr = sqi.getDBRefs();
1128 if (dbr != null && (nd = dbr.size()) > 0)
1130 for (int d = 0; d < nd; d++)
1132 DBRefEntry e = dbr.get(d);
1133 String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1134 Object[] sarray = commonDbrefs.get(src);
1137 sarray = new Object[2];
1138 sarray[0] = new int[] { 0 };
1139 sarray[1] = new String[seqs.length];
1141 commonDbrefs.put(src, sarray);
1144 if (((String[]) sarray[1])[sq] == null)
1146 if (!e.hasMap() || (e.getMap()
1147 .locateMappedRange(start, end) != null))
1149 ((String[]) sarray[1])[sq] = e.getAccessionId();
1150 ((int[]) sarray[0])[0]++;
1156 // now create group links for all distinct ID/sequence sets.
1157 boolean addMenu = false; // indicates if there are any group links to give
1159 for (String link : groupLinks)
1161 GroupUrlLink urlLink = null;
1164 urlLink = new GroupUrlLink(link);
1165 } catch (Exception foo)
1167 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
1170 if (!urlLink.isValid())
1172 Cache.log.error(urlLink.getInvalidMessage());
1175 final String label = urlLink.getLabel();
1176 boolean usingNames = false;
1177 // Now see which parts of the group apply for this URL
1178 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1179 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
1180 String[] seqstr, ids; // input to makeUrl
1183 int numinput = ((int[]) idset[0])[0];
1184 String[] allids = ((String[]) idset[1]);
1185 seqstr = new String[numinput];
1186 ids = new String[numinput];
1187 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1189 if (allids[sq] != null)
1191 ids[idcount] = allids[sq];
1192 seqstr[idcount++] = idandseqs[1][sq];
1198 // just use the id/seq set
1199 seqstr = idandseqs[1];
1203 // and try and make the groupURL!
1205 Object[] urlset = null;
1208 urlset = urlLink.makeUrlStubs(ids, seqstr,
1209 "FromJalview" + System.currentTimeMillis(), false);
1210 } catch (UrlStringTooLongException e)
1215 int type = urlLink.getGroupURLType() & 3;
1216 // first two bits ofurlLink type bitfield are sequenceids and sequences
1217 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1218 addshowLink(linkMenus[type],
1219 label + (((type & 1) == 1)
1220 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1228 groupLinksMenu = new JMenu(
1229 MessageManager.getString("action.group_link"));
1230 for (int m = 0; m < linkMenus.length; m++)
1232 if (linkMenus[m] != null
1233 && linkMenus[m].getMenuComponentCount() > 0)
1235 groupLinksMenu.add(linkMenus[m]);
1239 groupMenu.add(groupLinksMenu);
1249 private void jbInit() throws Exception
1251 groupMenu.setText(MessageManager.getString("label.selection"));
1252 groupName.setText(MessageManager.getString("label.name"));
1253 groupName.addActionListener(new ActionListener()
1256 public void actionPerformed(ActionEvent e)
1258 groupName_actionPerformed();
1261 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1263 JMenuItem sequenceName = new JMenuItem(
1264 MessageManager.getString("label.edit_name_description"));
1265 sequenceName.addActionListener(new ActionListener()
1268 public void actionPerformed(ActionEvent e)
1270 sequenceName_actionPerformed();
1273 JMenuItem chooseAnnotations = new JMenuItem(
1274 MessageManager.getString("action.choose_annotations"));
1275 chooseAnnotations.addActionListener(new ActionListener()
1278 public void actionPerformed(ActionEvent e)
1280 chooseAnnotations_actionPerformed(e);
1283 JMenuItem sequenceDetails = new JMenuItem(
1284 MessageManager.getString("label.sequence_details"));
1285 sequenceDetails.addActionListener(new ActionListener()
1288 public void actionPerformed(ActionEvent e)
1290 createSequenceDetailsReport(new SequenceI[] { sequence });
1293 JMenuItem sequenceSelDetails = new JMenuItem(
1294 MessageManager.getString("label.sequence_details"));
1295 sequenceSelDetails.addActionListener(new ActionListener()
1298 public void actionPerformed(ActionEvent e)
1300 createSequenceDetailsReport(ap.av.getSequenceSelection());
1305 .setText(MessageManager.getString("action.remove_group"));
1306 unGroupMenuItem.addActionListener(new ActionListener()
1309 public void actionPerformed(ActionEvent e)
1311 unGroupMenuItem_actionPerformed();
1315 .setText(MessageManager.getString("action.create_group"));
1316 createGroupMenuItem.addActionListener(new ActionListener()
1319 public void actionPerformed(ActionEvent e)
1321 createGroupMenuItem_actionPerformed();
1325 JMenuItem outline = new JMenuItem(
1326 MessageManager.getString("action.border_colour"));
1327 outline.addActionListener(new ActionListener()
1330 public void actionPerformed(ActionEvent e)
1332 outline_actionPerformed();
1335 showBoxes.setText(MessageManager.getString("action.boxes"));
1336 showBoxes.setState(true);
1337 showBoxes.addActionListener(new ActionListener()
1340 public void actionPerformed(ActionEvent e)
1342 showBoxes_actionPerformed();
1345 showText.setText(MessageManager.getString("action.text"));
1346 showText.setState(true);
1347 showText.addActionListener(new ActionListener()
1350 public void actionPerformed(ActionEvent e)
1352 showText_actionPerformed();
1355 showColourText.setText(MessageManager.getString("label.colour_text"));
1356 showColourText.addActionListener(new ActionListener()
1359 public void actionPerformed(ActionEvent e)
1361 showColourText_actionPerformed();
1365 .setText(MessageManager.getString("label.show_non_conserved"));
1366 displayNonconserved.setState(true);
1367 displayNonconserved.addActionListener(new ActionListener()
1370 public void actionPerformed(ActionEvent e)
1372 showNonconserved_actionPerformed();
1375 editMenu.setText(MessageManager.getString("action.edit"));
1376 JMenuItem cut = new JMenuItem(MessageManager.getString("action.cut"));
1377 cut.addActionListener(new ActionListener()
1380 public void actionPerformed(ActionEvent e)
1382 cut_actionPerformed();
1385 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1386 upperCase.addActionListener(new ActionListener()
1389 public void actionPerformed(ActionEvent e)
1394 JMenuItem copy = new JMenuItem(MessageManager.getString("action.copy"));
1395 copy.addActionListener(new ActionListener()
1398 public void actionPerformed(ActionEvent e)
1400 copy_actionPerformed();
1403 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1404 lowerCase.addActionListener(new ActionListener()
1407 public void actionPerformed(ActionEvent e)
1412 toggle.setText(MessageManager.getString("label.toggle_case"));
1413 toggle.addActionListener(new ActionListener()
1416 public void actionPerformed(ActionEvent e)
1422 MessageManager.getString("label.out_to_textbox") + "...");
1423 seqShowAnnotationsMenu
1424 .setText(MessageManager.getString("label.show_annotations"));
1425 seqHideAnnotationsMenu
1426 .setText(MessageManager.getString("label.hide_annotations"));
1427 groupShowAnnotationsMenu
1428 .setText(MessageManager.getString("label.show_annotations"));
1429 groupHideAnnotationsMenu
1430 .setText(MessageManager.getString("label.hide_annotations"));
1431 JMenuItem sequenceFeature = new JMenuItem(
1432 MessageManager.getString("label.create_sequence_feature"));
1433 sequenceFeature.addActionListener(new ActionListener()
1436 public void actionPerformed(ActionEvent e)
1438 sequenceFeature_actionPerformed();
1441 editGroupMenu.setText(MessageManager.getString("label.group"));
1442 chooseStructure.setText(
1443 MessageManager.getString("label.show_pdbstruct_dialog"));
1444 chooseStructure.addActionListener(new ActionListener()
1447 public void actionPerformed(ActionEvent actionEvent)
1449 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1450 if (ap.av.getSelectionGroup() != null)
1452 selectedSeqs = ap.av.getSequenceSelection();
1454 new StructureChooser(selectedSeqs, sequence, ap);
1459 .setText(MessageManager.getString("label.view_rna_structure"));
1461 // colStructureMenu.setText("Colour By Structure");
1462 JMenuItem editSequence = new JMenuItem(
1463 MessageManager.getString("label.edit_sequence") + "...");
1464 editSequence.addActionListener(new ActionListener()
1467 public void actionPerformed(ActionEvent actionEvent)
1469 editSequence_actionPerformed();
1472 makeReferenceSeq.setText(
1473 MessageManager.getString("label.mark_as_representative"));
1474 makeReferenceSeq.addActionListener(new ActionListener()
1478 public void actionPerformed(ActionEvent actionEvent)
1480 makeReferenceSeq_actionPerformed(actionEvent);
1485 groupMenu.add(sequenceSelDetails);
1488 add(rnaStructureMenu);
1489 add(chooseStructure);
1492 JMenuItem hideInsertions = new JMenuItem(
1493 MessageManager.getString("label.hide_insertions"));
1494 hideInsertions.addActionListener(new ActionListener()
1498 public void actionPerformed(ActionEvent e)
1500 hideInsertions_actionPerformed(e);
1503 add(hideInsertions);
1505 // annotations configuration panel suppressed for now
1506 // groupMenu.add(chooseAnnotations);
1509 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1510 * (if a selection group is in force).
1512 sequenceMenu.add(seqShowAnnotationsMenu);
1513 sequenceMenu.add(seqHideAnnotationsMenu);
1514 sequenceMenu.add(seqAddReferenceAnnotations);
1515 groupMenu.add(groupShowAnnotationsMenu);
1516 groupMenu.add(groupHideAnnotationsMenu);
1517 groupMenu.add(groupAddReferenceAnnotations);
1518 groupMenu.add(editMenu);
1519 groupMenu.add(outputMenu);
1520 groupMenu.add(sequenceFeature);
1521 groupMenu.add(createGroupMenuItem);
1522 groupMenu.add(unGroupMenuItem);
1523 groupMenu.add(editGroupMenu);
1524 sequenceMenu.add(sequenceName);
1525 sequenceMenu.add(sequenceDetails);
1526 sequenceMenu.add(makeReferenceSeq);
1533 editMenu.add(editSequence);
1534 editMenu.add(upperCase);
1535 editMenu.add(lowerCase);
1536 editMenu.add(toggle);
1537 editGroupMenu.add(groupName);
1538 editGroupMenu.add(colourMenu);
1539 editGroupMenu.add(showBoxes);
1540 editGroupMenu.add(showText);
1541 editGroupMenu.add(showColourText);
1542 editGroupMenu.add(outline);
1543 editGroupMenu.add(displayNonconserved);
1547 * Constructs the entries for the colour menu
1549 protected void initColourMenu()
1551 colourMenu.setText(MessageManager.getString("label.group_colour"));
1552 textColour.setText(MessageManager.getString("label.text_colour"));
1553 textColour.addActionListener(new ActionListener()
1556 public void actionPerformed(ActionEvent e)
1558 textColour_actionPerformed();
1562 abovePIDColour.setText(
1563 MessageManager.getString("label.above_identity_threshold"));
1564 abovePIDColour.addActionListener(new ActionListener()
1567 public void actionPerformed(ActionEvent e)
1569 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1574 MessageManager.getString("label.modify_identity_threshold"));
1575 modifyPID.addActionListener(new ActionListener()
1578 public void actionPerformed(ActionEvent e)
1580 modifyPID_actionPerformed();
1584 conservationMenuItem
1585 .setText(MessageManager.getString("action.by_conservation"));
1586 conservationMenuItem.addActionListener(new ActionListener()
1589 public void actionPerformed(ActionEvent e)
1591 conservationMenuItem_actionPerformed(
1592 conservationMenuItem.isSelected());
1596 annotationColour = new JRadioButtonMenuItem(
1597 MessageManager.getString("action.by_annotation"));
1598 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1599 annotationColour.setEnabled(false);
1600 annotationColour.setToolTipText(
1601 MessageManager.getString("label.by_annotation_tooltip"));
1603 modifyConservation.setText(MessageManager
1604 .getString("label.modify_conservation_threshold"));
1605 modifyConservation.addActionListener(new ActionListener()
1608 public void actionPerformed(ActionEvent e)
1610 modifyConservation_actionPerformed();
1616 * Builds the group colour sub-menu, including any user-defined colours which
1617 * were loaded at startup or during the Jalview session
1619 protected void buildColourMenu()
1621 SequenceGroup sg = ap.av.getSelectionGroup();
1625 * popup menu with no sequence group scope
1629 colourMenu.removeAll();
1630 colourMenu.add(textColour);
1631 colourMenu.addSeparator();
1633 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1635 bg.add(annotationColour);
1636 colourMenu.add(annotationColour);
1638 colourMenu.addSeparator();
1639 colourMenu.add(conservationMenuItem);
1640 colourMenu.add(modifyConservation);
1641 colourMenu.add(abovePIDColour);
1642 colourMenu.add(modifyPID);
1645 protected void modifyConservation_actionPerformed()
1647 SequenceGroup sg = getGroup();
1650 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1651 SliderPanel.showConservationSlider();
1655 protected void modifyPID_actionPerformed()
1657 SequenceGroup sg = getGroup();
1660 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1662 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1663 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1664 SliderPanel.showPIDSlider();
1669 * Check for any annotations on the underlying dataset sequences (for the
1670 * current selection group) which are not 'on the alignment'.If any are found,
1671 * enable the option to add them to the alignment. The criteria for 'on the
1672 * alignment' is finding an alignment annotation on the alignment, matched on
1673 * calcId, label and sequenceRef.
1675 * A tooltip is also constructed that displays the source (calcId) and type
1676 * (label) of the annotations that can be added.
1679 * @param forSequences
1681 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1682 List<SequenceI> forSequences)
1684 menuItem.setEnabled(false);
1687 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1688 * Using TreeMap means calcIds are shown in alphabetical order.
1690 SortedMap<String, String> tipEntries = new TreeMap<>();
1691 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1692 AlignmentI al = this.ap.av.getAlignment();
1693 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1695 if (!candidates.isEmpty())
1697 StringBuilder tooltip = new StringBuilder(64);
1698 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1701 * Found annotations that could be added. Enable the menu item, and
1702 * configure its tooltip and action.
1704 menuItem.setEnabled(true);
1705 for (String calcId : tipEntries.keySet())
1707 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1709 String tooltipText = JvSwingUtils.wrapTooltip(true,
1710 tooltip.toString());
1711 menuItem.setToolTipText(tooltipText);
1713 menuItem.addActionListener(new ActionListener()
1716 public void actionPerformed(ActionEvent e)
1718 addReferenceAnnotations_actionPerformed(candidates);
1725 * Add annotations to the sequences and to the alignment.
1728 * a map whose keys are sequences on the alignment, and values a list
1729 * of annotations to add to each sequence
1731 protected void addReferenceAnnotations_actionPerformed(
1732 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1734 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1735 final AlignmentI alignment = this.ap.getAlignment();
1736 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1741 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1743 if (!ap.av.getAlignment().hasSeqrep())
1745 // initialise the display flags so the user sees something happen
1746 ap.av.setDisplayReferenceSeq(true);
1747 ap.av.setColourByReferenceSeq(true);
1748 ap.av.getAlignment().setSeqrep(sequence);
1752 if (ap.av.getAlignment().getSeqrep() == sequence)
1754 ap.av.getAlignment().setSeqrep(null);
1758 ap.av.getAlignment().setSeqrep(sequence);
1764 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1766 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1767 BitSet inserts = new BitSet();
1769 boolean markedPopup = false;
1770 // mark inserts in current selection
1771 if (ap.av.getSelectionGroup() != null)
1773 // mark just the columns in the selection group to be hidden
1774 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1775 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1777 // now clear columns without gaps
1778 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1784 inserts.and(sq.getInsertionsAsBits());
1786 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1787 ap.av.getSelectionGroup().getEndRes());
1790 // now mark for sequence under popup if we haven't already done it
1791 else if (!markedPopup && sequence != null)
1793 inserts.or(sequence.getInsertionsAsBits());
1795 // and set hidden columns accordingly
1796 hidden.hideColumns(inserts);
1801 protected void sequenceSelectionDetails_actionPerformed()
1803 createSequenceDetailsReport(ap.av.getSequenceSelection());
1806 public void createSequenceDetailsReport(SequenceI[] sequences)
1808 StringBuilder contents = new StringBuilder(128);
1809 contents.append("<html><body>");
1810 for (SequenceI seq : sequences)
1812 contents.append("<p><h2>" + MessageManager.formatMessage(
1813 "label.create_sequence_details_report_annotation_for",
1815 { seq.getDisplayId(true) }) + "</h2></p><p>");
1816 new SequenceAnnotationReport(false).createSequenceAnnotationReport(
1817 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1818 contents.append("</p>");
1820 contents.append("</body></html>");
1821 String report = contents.toString();
1823 JInternalFrame frame;
1824 if (Platform.isJS())
1826 JLabel textLabel = new JLabel();
1827 textLabel.setText(report);
1828 textLabel.setBackground(Color.WHITE);
1829 JPanel pane = new JPanel(new BorderLayout());
1830 pane.setOpaque(true);
1831 pane.setBackground(Color.WHITE);
1832 pane.add(textLabel, BorderLayout.NORTH);
1833 frame = new JInternalFrame();
1834 frame.getContentPane().add(new JScrollPane(pane));
1843 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1844 cap.setText(report);
1848 Desktop.addInternalFrame(frame,
1849 MessageManager.formatMessage("label.sequence_details_for",
1850 (sequences.length == 1 ? new Object[]
1851 { sequences[0].getDisplayId(true) }
1854 .getString("label.selection") })),
1858 protected void showNonconserved_actionPerformed()
1860 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1865 * call to refresh view after settings change
1869 ap.updateAnnotation();
1870 // removed paintAlignment(true) here:
1871 // updateAnnotation calls paintAlignment already, so don't need to call
1874 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1878 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1879 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1889 public void abovePIDColour_actionPerformed(boolean selected)
1891 SequenceGroup sg = getGroup();
1899 sg.cs.setConsensus(AAFrequency.calculate(
1900 sg.getSequences(ap.av.getHiddenRepSequences()),
1901 sg.getStartRes(), sg.getEndRes() + 1));
1903 int threshold = SliderPanel.setPIDSliderSource(ap,
1904 sg.getGroupColourScheme(), getGroup().getName());
1906 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1908 SliderPanel.showPIDSlider();
1911 // remove PIDColouring
1913 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1914 SliderPanel.hidePIDSlider();
1916 modifyPID.setEnabled(selected);
1922 * Open a panel where the user can choose which types of sequence annotation
1927 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1929 // todo correct way to guard against opening a duplicate panel?
1930 new AnnotationChooser(ap);
1939 public void conservationMenuItem_actionPerformed(boolean selected)
1941 SequenceGroup sg = getGroup();
1949 // JBPNote: Conservation name shouldn't be i18n translated
1950 Conservation c = new Conservation("Group",
1951 sg.getSequences(ap.av.getHiddenRepSequences()),
1952 sg.getStartRes(), sg.getEndRes() + 1);
1955 c.verdict(false, ap.av.getConsPercGaps());
1956 sg.cs.setConservation(c);
1958 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1960 SliderPanel.showConservationSlider();
1963 // remove ConservationColouring
1965 sg.cs.setConservation(null);
1966 SliderPanel.hideConservationSlider();
1968 modifyConservation.setEnabled(selected);
1974 * Shows a dialog where group name and description may be edited
1976 protected void groupName_actionPerformed()
1978 SequenceGroup sg = getGroup();
1979 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1980 sg.getDescription(),
1981 MessageManager.getString("label.group_name"),
1982 MessageManager.getString("label.group_description"));
1983 dialog.showDialog(ap.alignFrame,
1984 MessageManager.getString("label.edit_group_name_description"),
1990 sg.setName(dialog.getName());
1991 sg.setDescription(dialog.getDescription());
1998 * Get selection group - adding it to the alignment if necessary.
2000 * @return sequence group to operate on
2002 SequenceGroup getGroup()
2004 SequenceGroup sg = ap.av.getSelectionGroup();
2005 // this method won't add a new group if it already exists
2008 ap.av.getAlignment().addGroup(sg);
2015 * Shows a dialog where the sequence name and description may be edited. If a
2016 * name containing spaces is entered, these are converted to underscores, with a
2019 void sequenceName_actionPerformed()
2021 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2022 sequence.getDescription(),
2023 MessageManager.getString("label.sequence_name"),
2024 MessageManager.getString("label.sequence_description"));
2025 dialog.showDialog(ap.alignFrame,
2026 MessageManager.getString(
2027 "label.edit_sequence_name_description"),
2033 if (dialog.getName() != null)
2035 if (dialog.getName().indexOf(" ") > -1)
2037 JvOptionPane.showMessageDialog(ap,
2038 MessageManager.getString(
2039 "label.spaces_converted_to_underscores"),
2040 MessageManager.getString(
2041 "label.no_spaces_allowed_sequence_name"),
2042 JvOptionPane.WARNING_MESSAGE);
2044 sequence.setName(dialog.getName().replace(' ', '_'));
2045 ap.paintAlignment(false, false);
2047 sequence.setDescription(dialog.getDescription());
2048 ap.av.firePropertyChange("alignment", null,
2049 ap.av.getAlignment().getSequences());
2060 void unGroupMenuItem_actionPerformed()
2062 SequenceGroup sg = ap.av.getSelectionGroup();
2063 ap.av.getAlignment().deleteGroup(sg);
2064 ap.av.setSelectionGroup(null);
2068 void createGroupMenuItem_actionPerformed()
2070 getGroup(); // implicitly creates group - note - should apply defaults / use
2071 // standard alignment window logic for this
2076 * Offers a colour chooser and sets the selected colour as the group outline
2078 protected void outline_actionPerformed()
2080 String title = MessageManager
2081 .getString("label.select_outline_colour");
2082 ColourChooserListener listener = new ColourChooserListener()
2085 public void colourSelected(Color c)
2087 getGroup().setOutlineColour(c);
2091 JalviewColourChooser.showColourChooser(Desktop.getDesktop(),
2092 title, Color.BLUE, listener);
2101 public void showBoxes_actionPerformed()
2103 getGroup().setDisplayBoxes(showBoxes.isSelected());
2113 public void showText_actionPerformed()
2115 getGroup().setDisplayText(showText.isSelected());
2125 public void showColourText_actionPerformed()
2127 getGroup().setColourText(showColourText.isSelected());
2131 void hideSequences(boolean representGroup)
2133 ap.av.hideSequences(sequence, representGroup);
2136 public void copy_actionPerformed()
2138 ap.alignFrame.copy_actionPerformed();
2141 public void cut_actionPerformed()
2143 ap.alignFrame.cut_actionPerformed();
2146 void changeCase(ActionEvent e)
2148 Object source = e.getSource();
2149 SequenceGroup sg = ap.av.getSelectionGroup();
2153 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2154 sg.getStartRes(), sg.getEndRes() + 1);
2159 if (source == toggle)
2161 description = MessageManager.getString("label.toggle_case");
2162 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2164 else if (source == upperCase)
2166 description = MessageManager.getString("label.to_upper_case");
2167 caseChange = ChangeCaseCommand.TO_UPPER;
2171 description = MessageManager.getString("label.to_lower_case");
2172 caseChange = ChangeCaseCommand.TO_LOWER;
2175 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2176 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2177 startEnd, caseChange);
2179 ap.alignFrame.addHistoryItem(caseCommand);
2181 ap.av.firePropertyChange("alignment", null,
2182 ap.av.getAlignment().getSequences());
2187 public void outputText_actionPerformed(ActionEvent e)
2189 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2190 cap.setForInput(null);
2191 Desktop.addInternalFrame(cap, MessageManager
2192 .formatMessage("label.alignment_output_command", new Object[]
2193 { e.getActionCommand() }), 600, 500);
2195 String[] omitHidden = null;
2197 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2198 // or we simply trust the user wants
2199 // wysiwig behaviour
2201 FileFormatI fileFormat = FileFormats.getInstance()
2202 .forName(e.getActionCommand());
2204 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2207 public void sequenceFeature_actionPerformed()
2209 SequenceGroup sg = ap.av.getSelectionGroup();
2215 List<SequenceI> seqs = new ArrayList<>();
2216 List<SequenceFeature> features = new ArrayList<>();
2219 * assemble dataset sequences, and template new sequence features,
2220 * for the amend features dialog
2222 int gSize = sg.getSize();
2223 for (int i = 0; i < gSize; i++)
2225 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2226 int end = sg.findEndRes(sg.getSequenceAt(i));
2229 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2230 features.add(new SequenceFeature(null, null, start, end, null));
2235 * an entirely gapped region will generate empty lists of sequence / features
2237 if (!seqs.isEmpty())
2239 new FeatureEditor(ap, seqs, features, true).showDialog();
2243 public void textColour_actionPerformed()
2245 SequenceGroup sg = getGroup();
2248 new TextColourChooser().chooseColour(ap, sg);
2253 * Shows a dialog where sequence characters may be edited. Any changes are
2254 * applied, and added as an available 'Undo' item in the edit commands
2257 public void editSequence_actionPerformed()
2259 SequenceGroup sg = ap.av.getSelectionGroup();
2261 SequenceI seq = sequence;
2266 seq = sg.getSequenceAt(0);
2269 EditNameDialog dialog = new EditNameDialog(
2270 seq.getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
2271 null, MessageManager.getString("label.edit_sequence"), null);
2272 dialog.showDialog(ap.alignFrame,
2273 MessageManager.getString("label.edit_sequence"),
2279 EditCommand editCommand = new EditCommand(
2280 MessageManager.getString("label.edit_sequences"),
2282 dialog.getName().replace(' ',
2283 ap.av.getGapCharacter()),
2284 sg.getSequencesAsArray(
2285 ap.av.getHiddenRepSequences()),
2286 sg.getStartRes(), sg.getEndRes() + 1,
2287 ap.av.getAlignment());
2288 ap.alignFrame.addHistoryItem(editCommand);
2289 ap.av.firePropertyChange("alignment", null,
2290 ap.av.getAlignment().getSequences());
2297 * Action on user selecting an item from the colour menu (that does not have
2298 * its bespoke action handler)
2303 public void changeColour_actionPerformed(String colourSchemeName)
2305 SequenceGroup sg = getGroup();
2307 * switch to the chosen colour scheme (or null for None)
2309 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2310 .getColourScheme(colourSchemeName, ap.av, sg,
2311 ap.av.getHiddenRepSequences());
2312 sg.setColourScheme(colourScheme);
2313 if (colourScheme instanceof Blosum62ColourScheme
2314 || colourScheme instanceof PIDColourScheme)
2316 sg.cs.setConsensus(AAFrequency.calculate(
2317 sg.getSequences(ap.av.getHiddenRepSequences()),
2318 sg.getStartRes(), sg.getEndRes() + 1));