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 start = beginRange[0];
842 int[] endRange = mf.getMappedPositions(end, end);
843 end = endRange[endRange.length - 1];
845 StringBuilder desc = new StringBuilder();
846 desc.append(sf.getType()).append(" ").append(String.valueOf(start));
849 desc.append(sf.isContactFeature() ? ":" : "-");
850 desc.append(String.valueOf(end));
852 String description = sf.getDescription();
853 if (description != null)
856 description = StringUtils.stripHtmlTags(description);
859 * truncate overlong descriptions unless they contain an href
860 * (as truncation could leave corrupted html)
862 boolean hasLink = description.indexOf("a href") > -1;
863 if (description.length() > FEATURE_DESC_MAX && !hasLink)
865 description = description.substring(0, FEATURE_DESC_MAX) + "...";
867 desc.append(description);
869 String featureGroup = sf.getFeatureGroup();
870 if (featureGroup != null)
872 desc.append(" (").append(featureGroup).append(")");
874 String htmlText = JvSwingUtils.wrapTooltip(true, desc.toString());
875 JMenuItem item = new JMenuItem(htmlText);
876 item.addActionListener(new ActionListener()
879 public void actionPerformed(ActionEvent e)
881 showFeatureDetails(sf, seqName, mf);
888 * Opens a panel showing a text report of feature details
894 protected void showFeatureDetails(SequenceFeature sf, String seqName,
897 JInternalFrame details;
900 details = new JInternalFrame();
901 JPanel panel = new JPanel(new BorderLayout());
902 panel.setOpaque(true);
903 panel.setBackground(Color.white);
904 // TODO JAL-3026 set style of table correctly for feature details
905 JLabel reprt = new JLabel(MessageManager
906 .formatMessage("label.html_content", new Object[]
907 { sf.getDetailsReport(seqName, mf) }));
908 reprt.setBackground(Color.WHITE);
909 reprt.setOpaque(true);
910 panel.add(reprt, BorderLayout.CENTER);
911 details.setContentPane(panel);
921 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
922 // it appears Java's CSS does not support border-collapse :-(
923 cap.addStylesheetRule("table { border-collapse: collapse;}");
924 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
925 cap.setText(sf.getDetailsReport(seqName, mf));
928 Desktop.addInternalFrame(details,
929 MessageManager.getString("label.feature_details"), 500, 500);
933 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
934 * When seq is not null, these are links for the sequence id, which may be to
935 * external web sites for the sequence accession, and/or links embedded in
936 * non-positional features. When seq is null, only links embedded in the
937 * provided features are added. If no links are found, the menu is not added.
942 void addLinks(final SequenceI seq, List<SequenceFeature> features)
944 JMenu linkMenu = buildLinkMenu(forIdPanel ? seq : null, features);
946 // only add link menu if it has entries
947 if (linkMenu.getItemCount() > 0)
951 sequenceMenu.add(linkMenu);
961 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
962 * "All" is added first, followed by a separator. Then add any annotation
963 * types associated with the current selection. Separate menus are built for
964 * the selected sequence group (if any), and the selected sequence.
966 * Some annotation rows are always rendered together - these can be identified
967 * by a common graphGroup property > -1. Only one of each group will be marked
968 * as visible (to avoid duplication of the display). For such groups we add a
969 * composite type name, e.g.
971 * IUPredWS (Long), IUPredWS (Short)
975 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
976 List<SequenceI> forSequences)
978 showMenu.removeAll();
979 hideMenu.removeAll();
981 final List<String> all = Arrays
983 { MessageManager.getString("label.all") });
984 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
986 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
988 showMenu.addSeparator();
989 hideMenu.addSeparator();
991 final AlignmentAnnotation[] annotations = ap.getAlignment()
992 .getAlignmentAnnotation();
995 * Find shown/hidden annotations types, distinguished by source (calcId),
996 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
997 * the insertion order, which is the order of the annotations on the
1000 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
1001 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
1002 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1003 AlignmentAnnotationUtils.asList(annotations), forSequences);
1005 for (String calcId : hiddenTypes.keySet())
1007 for (List<String> type : hiddenTypes.get(calcId))
1009 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1013 // grey out 'show annotations' if none are hidden
1014 showMenu.setEnabled(!hiddenTypes.isEmpty());
1016 for (String calcId : shownTypes.keySet())
1018 for (List<String> type : shownTypes.get(calcId))
1020 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1024 // grey out 'hide annotations' if none are shown
1025 hideMenu.setEnabled(!shownTypes.isEmpty());
1029 * Returns a list of sequences - either the current selection group (if there
1030 * is one), else the specified single sequence.
1035 protected List<SequenceI> getSequenceScope(SequenceI seq)
1037 List<SequenceI> forSequences = null;
1038 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
1039 if (selectionGroup != null && selectionGroup.getSize() > 0)
1041 forSequences = selectionGroup.getSequences();
1045 forSequences = seq == null ? Collections.<SequenceI> emptyList()
1046 : Arrays.asList(seq);
1048 return forSequences;
1052 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1055 * @param showOrHideMenu
1056 * the menu to add to
1057 * @param forSequences
1058 * the sequences whose annotations may be shown or hidden
1063 * if true this is a special label meaning 'All'
1064 * @param actionIsShow
1065 * if true, the select menu item action is to show the annotation
1068 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
1069 final List<SequenceI> forSequences, String calcId,
1070 final List<String> types, final boolean allTypes,
1071 final boolean actionIsShow)
1073 String label = types.toString(); // [a, b, c]
1074 label = label.substring(1, label.length() - 1); // a, b, c
1075 final JMenuItem item = new JMenuItem(label);
1076 item.setToolTipText(calcId);
1077 item.addActionListener(new ActionListener()
1080 public void actionPerformed(ActionEvent e)
1082 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1083 types, forSequences, allTypes, actionIsShow);
1087 showOrHideMenu.add(item);
1090 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
1093 // TODO: usability: thread off the generation of group url content so root
1094 // menu appears asap
1095 // sequence only URLs
1096 // ID/regex match URLs
1097 JMenu groupLinksMenu = new JMenu(
1098 MessageManager.getString("action.group_link"));
1099 // three types of url that might be created.
1100 JMenu[] linkMenus = new JMenu[] { null,
1101 new JMenu(MessageManager.getString("action.ids")),
1102 new JMenu(MessageManager.getString("action.sequences")),
1103 new JMenu(MessageManager.getString("action.ids_sequences")) };
1105 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1106 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1107 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
1108 for (int sq = 0; sq < seqs.length; sq++)
1111 int start = seqs[sq].findPosition(sg.getStartRes()),
1112 end = seqs[sq].findPosition(sg.getEndRes());
1113 // just collect ids from dataset sequence
1114 // TODO: check if IDs collected from selecton group intersects with the
1115 // current selection, too
1116 SequenceI sqi = seqs[sq];
1117 while (sqi.getDatasetSequence() != null)
1119 sqi = sqi.getDatasetSequence();
1121 List<DBRefEntry> dbr = sqi.getDBRefs();
1123 if (dbr != null && (nd = dbr.size()) > 0)
1125 for (int d = 0; d < nd; d++)
1127 DBRefEntry e = dbr.get(d);
1128 String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1129 Object[] sarray = commonDbrefs.get(src);
1132 sarray = new Object[2];
1133 sarray[0] = new int[] { 0 };
1134 sarray[1] = new String[seqs.length];
1136 commonDbrefs.put(src, sarray);
1139 if (((String[]) sarray[1])[sq] == null)
1141 if (!e.hasMap() || (e.getMap()
1142 .locateMappedRange(start, end) != null))
1144 ((String[]) sarray[1])[sq] = e.getAccessionId();
1145 ((int[]) sarray[0])[0]++;
1151 // now create group links for all distinct ID/sequence sets.
1152 boolean addMenu = false; // indicates if there are any group links to give
1154 for (String link : groupLinks)
1156 GroupUrlLink urlLink = null;
1159 urlLink = new GroupUrlLink(link);
1160 } catch (Exception foo)
1162 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
1165 if (!urlLink.isValid())
1167 Cache.log.error(urlLink.getInvalidMessage());
1170 final String label = urlLink.getLabel();
1171 boolean usingNames = false;
1172 // Now see which parts of the group apply for this URL
1173 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1174 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
1175 String[] seqstr, ids; // input to makeUrl
1178 int numinput = ((int[]) idset[0])[0];
1179 String[] allids = ((String[]) idset[1]);
1180 seqstr = new String[numinput];
1181 ids = new String[numinput];
1182 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1184 if (allids[sq] != null)
1186 ids[idcount] = allids[sq];
1187 seqstr[idcount++] = idandseqs[1][sq];
1193 // just use the id/seq set
1194 seqstr = idandseqs[1];
1198 // and try and make the groupURL!
1200 Object[] urlset = null;
1203 urlset = urlLink.makeUrlStubs(ids, seqstr,
1204 "FromJalview" + System.currentTimeMillis(), false);
1205 } catch (UrlStringTooLongException e)
1210 int type = urlLink.getGroupURLType() & 3;
1211 // first two bits ofurlLink type bitfield are sequenceids and sequences
1212 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1213 addshowLink(linkMenus[type],
1214 label + (((type & 1) == 1)
1215 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1223 groupLinksMenu = new JMenu(
1224 MessageManager.getString("action.group_link"));
1225 for (int m = 0; m < linkMenus.length; m++)
1227 if (linkMenus[m] != null
1228 && linkMenus[m].getMenuComponentCount() > 0)
1230 groupLinksMenu.add(linkMenus[m]);
1234 groupMenu.add(groupLinksMenu);
1244 private void jbInit() throws Exception
1246 groupMenu.setText(MessageManager.getString("label.selection"));
1247 groupName.setText(MessageManager.getString("label.name"));
1248 groupName.addActionListener(new ActionListener()
1251 public void actionPerformed(ActionEvent e)
1253 groupName_actionPerformed();
1256 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1258 JMenuItem sequenceName = new JMenuItem(
1259 MessageManager.getString("label.edit_name_description"));
1260 sequenceName.addActionListener(new ActionListener()
1263 public void actionPerformed(ActionEvent e)
1265 sequenceName_actionPerformed();
1268 JMenuItem chooseAnnotations = new JMenuItem(
1269 MessageManager.getString("action.choose_annotations"));
1270 chooseAnnotations.addActionListener(new ActionListener()
1273 public void actionPerformed(ActionEvent e)
1275 chooseAnnotations_actionPerformed(e);
1278 JMenuItem sequenceDetails = new JMenuItem(
1279 MessageManager.getString("label.sequence_details"));
1280 sequenceDetails.addActionListener(new ActionListener()
1283 public void actionPerformed(ActionEvent e)
1285 createSequenceDetailsReport(new SequenceI[] { sequence });
1288 JMenuItem sequenceSelDetails = new JMenuItem(
1289 MessageManager.getString("label.sequence_details"));
1290 sequenceSelDetails.addActionListener(new ActionListener()
1293 public void actionPerformed(ActionEvent e)
1295 createSequenceDetailsReport(ap.av.getSequenceSelection());
1300 .setText(MessageManager.getString("action.remove_group"));
1301 unGroupMenuItem.addActionListener(new ActionListener()
1304 public void actionPerformed(ActionEvent e)
1306 unGroupMenuItem_actionPerformed();
1310 .setText(MessageManager.getString("action.create_group"));
1311 createGroupMenuItem.addActionListener(new ActionListener()
1314 public void actionPerformed(ActionEvent e)
1316 createGroupMenuItem_actionPerformed();
1320 JMenuItem outline = new JMenuItem(
1321 MessageManager.getString("action.border_colour"));
1322 outline.addActionListener(new ActionListener()
1325 public void actionPerformed(ActionEvent e)
1327 outline_actionPerformed();
1330 showBoxes.setText(MessageManager.getString("action.boxes"));
1331 showBoxes.setState(true);
1332 showBoxes.addActionListener(new ActionListener()
1335 public void actionPerformed(ActionEvent e)
1337 showBoxes_actionPerformed();
1340 showText.setText(MessageManager.getString("action.text"));
1341 showText.setState(true);
1342 showText.addActionListener(new ActionListener()
1345 public void actionPerformed(ActionEvent e)
1347 showText_actionPerformed();
1350 showColourText.setText(MessageManager.getString("label.colour_text"));
1351 showColourText.addActionListener(new ActionListener()
1354 public void actionPerformed(ActionEvent e)
1356 showColourText_actionPerformed();
1360 .setText(MessageManager.getString("label.show_non_conserved"));
1361 displayNonconserved.setState(true);
1362 displayNonconserved.addActionListener(new ActionListener()
1365 public void actionPerformed(ActionEvent e)
1367 showNonconserved_actionPerformed();
1370 editMenu.setText(MessageManager.getString("action.edit"));
1371 JMenuItem cut = new JMenuItem(MessageManager.getString("action.cut"));
1372 cut.addActionListener(new ActionListener()
1375 public void actionPerformed(ActionEvent e)
1377 cut_actionPerformed();
1380 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1381 upperCase.addActionListener(new ActionListener()
1384 public void actionPerformed(ActionEvent e)
1389 JMenuItem copy = new JMenuItem(MessageManager.getString("action.copy"));
1390 copy.addActionListener(new ActionListener()
1393 public void actionPerformed(ActionEvent e)
1395 copy_actionPerformed();
1398 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1399 lowerCase.addActionListener(new ActionListener()
1402 public void actionPerformed(ActionEvent e)
1407 toggle.setText(MessageManager.getString("label.toggle_case"));
1408 toggle.addActionListener(new ActionListener()
1411 public void actionPerformed(ActionEvent e)
1417 MessageManager.getString("label.out_to_textbox") + "...");
1418 seqShowAnnotationsMenu
1419 .setText(MessageManager.getString("label.show_annotations"));
1420 seqHideAnnotationsMenu
1421 .setText(MessageManager.getString("label.hide_annotations"));
1422 groupShowAnnotationsMenu
1423 .setText(MessageManager.getString("label.show_annotations"));
1424 groupHideAnnotationsMenu
1425 .setText(MessageManager.getString("label.hide_annotations"));
1426 JMenuItem sequenceFeature = new JMenuItem(
1427 MessageManager.getString("label.create_sequence_feature"));
1428 sequenceFeature.addActionListener(new ActionListener()
1431 public void actionPerformed(ActionEvent e)
1433 sequenceFeature_actionPerformed();
1436 editGroupMenu.setText(MessageManager.getString("label.group"));
1437 chooseStructure.setText(
1438 MessageManager.getString("label.show_pdbstruct_dialog"));
1439 chooseStructure.addActionListener(new ActionListener()
1442 public void actionPerformed(ActionEvent actionEvent)
1444 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1445 if (ap.av.getSelectionGroup() != null)
1447 selectedSeqs = ap.av.getSequenceSelection();
1449 new StructureChooser(selectedSeqs, sequence, ap);
1454 .setText(MessageManager.getString("label.view_rna_structure"));
1456 // colStructureMenu.setText("Colour By Structure");
1457 JMenuItem editSequence = new JMenuItem(
1458 MessageManager.getString("label.edit_sequence") + "...");
1459 editSequence.addActionListener(new ActionListener()
1462 public void actionPerformed(ActionEvent actionEvent)
1464 editSequence_actionPerformed();
1467 makeReferenceSeq.setText(
1468 MessageManager.getString("label.mark_as_representative"));
1469 makeReferenceSeq.addActionListener(new ActionListener()
1473 public void actionPerformed(ActionEvent actionEvent)
1475 makeReferenceSeq_actionPerformed(actionEvent);
1480 groupMenu.add(sequenceSelDetails);
1483 add(rnaStructureMenu);
1484 add(chooseStructure);
1487 JMenuItem hideInsertions = new JMenuItem(
1488 MessageManager.getString("label.hide_insertions"));
1489 hideInsertions.addActionListener(new ActionListener()
1493 public void actionPerformed(ActionEvent e)
1495 hideInsertions_actionPerformed(e);
1498 add(hideInsertions);
1500 // annotations configuration panel suppressed for now
1501 // groupMenu.add(chooseAnnotations);
1504 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1505 * (if a selection group is in force).
1507 sequenceMenu.add(seqShowAnnotationsMenu);
1508 sequenceMenu.add(seqHideAnnotationsMenu);
1509 sequenceMenu.add(seqAddReferenceAnnotations);
1510 groupMenu.add(groupShowAnnotationsMenu);
1511 groupMenu.add(groupHideAnnotationsMenu);
1512 groupMenu.add(groupAddReferenceAnnotations);
1513 groupMenu.add(editMenu);
1514 groupMenu.add(outputMenu);
1515 groupMenu.add(sequenceFeature);
1516 groupMenu.add(createGroupMenuItem);
1517 groupMenu.add(unGroupMenuItem);
1518 groupMenu.add(editGroupMenu);
1519 sequenceMenu.add(sequenceName);
1520 sequenceMenu.add(sequenceDetails);
1521 sequenceMenu.add(makeReferenceSeq);
1528 editMenu.add(editSequence);
1529 editMenu.add(upperCase);
1530 editMenu.add(lowerCase);
1531 editMenu.add(toggle);
1532 editGroupMenu.add(groupName);
1533 editGroupMenu.add(colourMenu);
1534 editGroupMenu.add(showBoxes);
1535 editGroupMenu.add(showText);
1536 editGroupMenu.add(showColourText);
1537 editGroupMenu.add(outline);
1538 editGroupMenu.add(displayNonconserved);
1542 * Constructs the entries for the colour menu
1544 protected void initColourMenu()
1546 colourMenu.setText(MessageManager.getString("label.group_colour"));
1547 textColour.setText(MessageManager.getString("label.text_colour"));
1548 textColour.addActionListener(new ActionListener()
1551 public void actionPerformed(ActionEvent e)
1553 textColour_actionPerformed();
1557 abovePIDColour.setText(
1558 MessageManager.getString("label.above_identity_threshold"));
1559 abovePIDColour.addActionListener(new ActionListener()
1562 public void actionPerformed(ActionEvent e)
1564 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1569 MessageManager.getString("label.modify_identity_threshold"));
1570 modifyPID.addActionListener(new ActionListener()
1573 public void actionPerformed(ActionEvent e)
1575 modifyPID_actionPerformed();
1579 conservationMenuItem
1580 .setText(MessageManager.getString("action.by_conservation"));
1581 conservationMenuItem.addActionListener(new ActionListener()
1584 public void actionPerformed(ActionEvent e)
1586 conservationMenuItem_actionPerformed(
1587 conservationMenuItem.isSelected());
1591 annotationColour = new JRadioButtonMenuItem(
1592 MessageManager.getString("action.by_annotation"));
1593 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1594 annotationColour.setEnabled(false);
1595 annotationColour.setToolTipText(
1596 MessageManager.getString("label.by_annotation_tooltip"));
1598 modifyConservation.setText(MessageManager
1599 .getString("label.modify_conservation_threshold"));
1600 modifyConservation.addActionListener(new ActionListener()
1603 public void actionPerformed(ActionEvent e)
1605 modifyConservation_actionPerformed();
1611 * Builds the group colour sub-menu, including any user-defined colours which
1612 * were loaded at startup or during the Jalview session
1614 protected void buildColourMenu()
1616 SequenceGroup sg = ap.av.getSelectionGroup();
1620 * popup menu with no sequence group scope
1624 colourMenu.removeAll();
1625 colourMenu.add(textColour);
1626 colourMenu.addSeparator();
1628 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1630 bg.add(annotationColour);
1631 colourMenu.add(annotationColour);
1633 colourMenu.addSeparator();
1634 colourMenu.add(conservationMenuItem);
1635 colourMenu.add(modifyConservation);
1636 colourMenu.add(abovePIDColour);
1637 colourMenu.add(modifyPID);
1640 protected void modifyConservation_actionPerformed()
1642 SequenceGroup sg = getGroup();
1645 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1646 SliderPanel.showConservationSlider();
1650 protected void modifyPID_actionPerformed()
1652 SequenceGroup sg = getGroup();
1655 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1657 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1658 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1659 SliderPanel.showPIDSlider();
1664 * Check for any annotations on the underlying dataset sequences (for the
1665 * current selection group) which are not 'on the alignment'.If any are found,
1666 * enable the option to add them to the alignment. The criteria for 'on the
1667 * alignment' is finding an alignment annotation on the alignment, matched on
1668 * calcId, label and sequenceRef.
1670 * A tooltip is also constructed that displays the source (calcId) and type
1671 * (label) of the annotations that can be added.
1674 * @param forSequences
1676 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1677 List<SequenceI> forSequences)
1679 menuItem.setEnabled(false);
1682 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1683 * Using TreeMap means calcIds are shown in alphabetical order.
1685 SortedMap<String, String> tipEntries = new TreeMap<>();
1686 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1687 AlignmentI al = this.ap.av.getAlignment();
1688 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1690 if (!candidates.isEmpty())
1692 StringBuilder tooltip = new StringBuilder(64);
1693 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1696 * Found annotations that could be added. Enable the menu item, and
1697 * configure its tooltip and action.
1699 menuItem.setEnabled(true);
1700 for (String calcId : tipEntries.keySet())
1702 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1704 String tooltipText = JvSwingUtils.wrapTooltip(true,
1705 tooltip.toString());
1706 menuItem.setToolTipText(tooltipText);
1708 menuItem.addActionListener(new ActionListener()
1711 public void actionPerformed(ActionEvent e)
1713 addReferenceAnnotations_actionPerformed(candidates);
1720 * Add annotations to the sequences and to the alignment.
1723 * a map whose keys are sequences on the alignment, and values a list
1724 * of annotations to add to each sequence
1726 protected void addReferenceAnnotations_actionPerformed(
1727 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1729 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1730 final AlignmentI alignment = this.ap.getAlignment();
1731 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1736 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1738 if (!ap.av.getAlignment().hasSeqrep())
1740 // initialise the display flags so the user sees something happen
1741 ap.av.setDisplayReferenceSeq(true);
1742 ap.av.setColourByReferenceSeq(true);
1743 ap.av.getAlignment().setSeqrep(sequence);
1747 if (ap.av.getAlignment().getSeqrep() == sequence)
1749 ap.av.getAlignment().setSeqrep(null);
1753 ap.av.getAlignment().setSeqrep(sequence);
1759 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1761 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1762 BitSet inserts = new BitSet();
1764 boolean markedPopup = false;
1765 // mark inserts in current selection
1766 if (ap.av.getSelectionGroup() != null)
1768 // mark just the columns in the selection group to be hidden
1769 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1770 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1772 // now clear columns without gaps
1773 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1779 inserts.and(sq.getInsertionsAsBits());
1781 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1782 ap.av.getSelectionGroup().getEndRes());
1785 // now mark for sequence under popup if we haven't already done it
1786 else if (!markedPopup && sequence != null)
1788 inserts.or(sequence.getInsertionsAsBits());
1790 // and set hidden columns accordingly
1791 hidden.hideColumns(inserts);
1796 protected void sequenceSelectionDetails_actionPerformed()
1798 createSequenceDetailsReport(ap.av.getSequenceSelection());
1801 public void createSequenceDetailsReport(SequenceI[] sequences)
1803 StringBuilder contents = new StringBuilder(128);
1804 contents.append("<html><body>");
1805 for (SequenceI seq : sequences)
1807 contents.append("<p><h2>" + MessageManager.formatMessage(
1808 "label.create_sequence_details_report_annotation_for",
1810 { seq.getDisplayId(true) }) + "</h2></p><p>");
1811 new SequenceAnnotationReport(false).createSequenceAnnotationReport(
1812 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1813 contents.append("</p>");
1815 contents.append("</body></html>");
1816 String report = contents.toString();
1818 JInternalFrame frame;
1819 if (Platform.isJS())
1821 JLabel textLabel = new JLabel();
1822 textLabel.setText(report);
1823 textLabel.setBackground(Color.WHITE);
1824 JPanel pane = new JPanel(new BorderLayout());
1825 pane.setOpaque(true);
1826 pane.setBackground(Color.WHITE);
1827 pane.add(textLabel, BorderLayout.NORTH);
1828 frame = new JInternalFrame();
1829 frame.getContentPane().add(new JScrollPane(pane));
1838 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1839 cap.setText(report);
1843 Desktop.addInternalFrame(frame,
1844 MessageManager.formatMessage("label.sequence_details_for",
1845 (sequences.length == 1 ? new Object[]
1846 { sequences[0].getDisplayId(true) }
1849 .getString("label.selection") })),
1853 protected void showNonconserved_actionPerformed()
1855 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1860 * call to refresh view after settings change
1864 ap.updateAnnotation();
1865 // removed paintAlignment(true) here:
1866 // updateAnnotation calls paintAlignment already, so don't need to call
1869 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1873 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1874 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1884 public void abovePIDColour_actionPerformed(boolean selected)
1886 SequenceGroup sg = getGroup();
1894 sg.cs.setConsensus(AAFrequency.calculate(
1895 sg.getSequences(ap.av.getHiddenRepSequences()),
1896 sg.getStartRes(), sg.getEndRes() + 1));
1898 int threshold = SliderPanel.setPIDSliderSource(ap,
1899 sg.getGroupColourScheme(), getGroup().getName());
1901 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1903 SliderPanel.showPIDSlider();
1906 // remove PIDColouring
1908 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1909 SliderPanel.hidePIDSlider();
1911 modifyPID.setEnabled(selected);
1917 * Open a panel where the user can choose which types of sequence annotation
1922 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1924 // todo correct way to guard against opening a duplicate panel?
1925 new AnnotationChooser(ap);
1934 public void conservationMenuItem_actionPerformed(boolean selected)
1936 SequenceGroup sg = getGroup();
1944 // JBPNote: Conservation name shouldn't be i18n translated
1945 Conservation c = new Conservation("Group",
1946 sg.getSequences(ap.av.getHiddenRepSequences()),
1947 sg.getStartRes(), sg.getEndRes() + 1);
1950 c.verdict(false, ap.av.getConsPercGaps());
1951 sg.cs.setConservation(c);
1953 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1955 SliderPanel.showConservationSlider();
1958 // remove ConservationColouring
1960 sg.cs.setConservation(null);
1961 SliderPanel.hideConservationSlider();
1963 modifyConservation.setEnabled(selected);
1969 * Shows a dialog where group name and description may be edited
1971 protected void groupName_actionPerformed()
1973 SequenceGroup sg = getGroup();
1974 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1975 sg.getDescription(),
1976 MessageManager.getString("label.group_name"),
1977 MessageManager.getString("label.group_description"));
1978 dialog.showDialog(ap.alignFrame,
1979 MessageManager.getString("label.edit_group_name_description"),
1985 sg.setName(dialog.getName());
1986 sg.setDescription(dialog.getDescription());
1993 * Get selection group - adding it to the alignment if necessary.
1995 * @return sequence group to operate on
1997 SequenceGroup getGroup()
1999 SequenceGroup sg = ap.av.getSelectionGroup();
2000 // this method won't add a new group if it already exists
2003 ap.av.getAlignment().addGroup(sg);
2010 * Shows a dialog where the sequence name and description may be edited. If a
2011 * name containing spaces is entered, these are converted to underscores, with a
2014 void sequenceName_actionPerformed()
2016 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2017 sequence.getDescription(),
2018 MessageManager.getString("label.sequence_name"),
2019 MessageManager.getString("label.sequence_description"));
2020 dialog.showDialog(ap.alignFrame,
2021 MessageManager.getString(
2022 "label.edit_sequence_name_description"),
2028 if (dialog.getName() != null)
2030 if (dialog.getName().indexOf(" ") > -1)
2032 JvOptionPane.showMessageDialog(ap,
2033 MessageManager.getString(
2034 "label.spaces_converted_to_underscores"),
2035 MessageManager.getString(
2036 "label.no_spaces_allowed_sequence_name"),
2037 JvOptionPane.WARNING_MESSAGE);
2039 sequence.setName(dialog.getName().replace(' ', '_'));
2040 ap.paintAlignment(false, false);
2042 sequence.setDescription(dialog.getDescription());
2043 ap.av.firePropertyChange("alignment", null,
2044 ap.av.getAlignment().getSequences());
2055 void unGroupMenuItem_actionPerformed()
2057 SequenceGroup sg = ap.av.getSelectionGroup();
2058 ap.av.getAlignment().deleteGroup(sg);
2059 ap.av.setSelectionGroup(null);
2063 void createGroupMenuItem_actionPerformed()
2065 getGroup(); // implicitly creates group - note - should apply defaults / use
2066 // standard alignment window logic for this
2071 * Offers a colour chooser and sets the selected colour as the group outline
2073 protected void outline_actionPerformed()
2075 String title = MessageManager
2076 .getString("label.select_outline_colour");
2077 ColourChooserListener listener = new ColourChooserListener()
2080 public void colourSelected(Color c)
2082 getGroup().setOutlineColour(c);
2086 JalviewColourChooser.showColourChooser(Desktop.getDesktop(),
2087 title, Color.BLUE, listener);
2096 public void showBoxes_actionPerformed()
2098 getGroup().setDisplayBoxes(showBoxes.isSelected());
2108 public void showText_actionPerformed()
2110 getGroup().setDisplayText(showText.isSelected());
2120 public void showColourText_actionPerformed()
2122 getGroup().setColourText(showColourText.isSelected());
2126 void hideSequences(boolean representGroup)
2128 ap.av.hideSequences(sequence, representGroup);
2131 public void copy_actionPerformed()
2133 ap.alignFrame.copy_actionPerformed();
2136 public void cut_actionPerformed()
2138 ap.alignFrame.cut_actionPerformed();
2141 void changeCase(ActionEvent e)
2143 Object source = e.getSource();
2144 SequenceGroup sg = ap.av.getSelectionGroup();
2148 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2149 sg.getStartRes(), sg.getEndRes() + 1);
2154 if (source == toggle)
2156 description = MessageManager.getString("label.toggle_case");
2157 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2159 else if (source == upperCase)
2161 description = MessageManager.getString("label.to_upper_case");
2162 caseChange = ChangeCaseCommand.TO_UPPER;
2166 description = MessageManager.getString("label.to_lower_case");
2167 caseChange = ChangeCaseCommand.TO_LOWER;
2170 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2171 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2172 startEnd, caseChange);
2174 ap.alignFrame.addHistoryItem(caseCommand);
2176 ap.av.firePropertyChange("alignment", null,
2177 ap.av.getAlignment().getSequences());
2182 public void outputText_actionPerformed(ActionEvent e)
2184 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2185 cap.setForInput(null);
2186 Desktop.addInternalFrame(cap, MessageManager
2187 .formatMessage("label.alignment_output_command", new Object[]
2188 { e.getActionCommand() }), 600, 500);
2190 String[] omitHidden = null;
2192 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2193 // or we simply trust the user wants
2194 // wysiwig behaviour
2196 FileFormatI fileFormat = FileFormats.getInstance()
2197 .forName(e.getActionCommand());
2199 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2202 public void sequenceFeature_actionPerformed()
2204 SequenceGroup sg = ap.av.getSelectionGroup();
2210 List<SequenceI> seqs = new ArrayList<>();
2211 List<SequenceFeature> features = new ArrayList<>();
2214 * assemble dataset sequences, and template new sequence features,
2215 * for the amend features dialog
2217 int gSize = sg.getSize();
2218 for (int i = 0; i < gSize; i++)
2220 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2221 int end = sg.findEndRes(sg.getSequenceAt(i));
2224 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2225 features.add(new SequenceFeature(null, null, start, end, null));
2230 * an entirely gapped region will generate empty lists of sequence / features
2232 if (!seqs.isEmpty())
2234 new FeatureEditor(ap, seqs, features, true).showDialog();
2238 public void textColour_actionPerformed()
2240 SequenceGroup sg = getGroup();
2243 new TextColourChooser().chooseColour(ap, sg);
2248 * Shows a dialog where sequence characters may be edited. Any changes are
2249 * applied, and added as an available 'Undo' item in the edit commands
2252 public void editSequence_actionPerformed()
2254 SequenceGroup sg = ap.av.getSelectionGroup();
2256 SequenceI seq = sequence;
2261 seq = sg.getSequenceAt(0);
2264 EditNameDialog dialog = new EditNameDialog(
2265 seq.getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
2266 null, MessageManager.getString("label.edit_sequence"), null);
2267 dialog.showDialog(ap.alignFrame,
2268 MessageManager.getString("label.edit_sequence"),
2274 EditCommand editCommand = new EditCommand(
2275 MessageManager.getString("label.edit_sequences"),
2277 dialog.getName().replace(' ',
2278 ap.av.getGapCharacter()),
2279 sg.getSequencesAsArray(
2280 ap.av.getHiddenRepSequences()),
2281 sg.getStartRes(), sg.getEndRes() + 1,
2282 ap.av.getAlignment());
2283 ap.alignFrame.addHistoryItem(editCommand);
2284 ap.av.firePropertyChange("alignment", null,
2285 ap.av.getAlignment().getSequences());
2292 * Action on user selecting an item from the colour menu (that does not have
2293 * its bespoke action handler)
2298 public void changeColour_actionPerformed(String colourSchemeName)
2300 SequenceGroup sg = getGroup();
2302 * switch to the chosen colour scheme (or null for None)
2304 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2305 .getColourScheme(colourSchemeName, ap.av, sg,
2306 ap.av.getHiddenRepSequences());
2307 sg.setColourScheme(colourScheme);
2308 if (colourScheme instanceof Blosum62ColourScheme
2309 || colourScheme instanceof PIDColourScheme)
2311 sg.cs.setConsensus(AAFrequency.calculate(
2312 sg.getSequences(ap.av.getHiddenRepSequences()),
2313 sg.getStartRes(), sg.getEndRes() + 1));