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.Color;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.BitSet;
29 import java.util.Collection;
30 import java.util.Collections;
31 import java.util.Hashtable;
32 import java.util.LinkedHashMap;
33 import java.util.List;
35 import java.util.Objects;
36 import java.util.SortedMap;
37 import java.util.TreeMap;
38 import java.util.Vector;
40 import javax.swing.ButtonGroup;
41 import javax.swing.JCheckBoxMenuItem;
42 import javax.swing.JColorChooser;
43 import javax.swing.JMenu;
44 import javax.swing.JMenuItem;
45 import javax.swing.JPopupMenu;
46 import javax.swing.JRadioButtonMenuItem;
48 import jalview.analysis.AAFrequency;
49 import jalview.analysis.AlignmentAnnotationUtils;
50 import jalview.analysis.AlignmentUtils;
51 import jalview.analysis.Conservation;
52 import jalview.api.AlignViewportI;
53 import jalview.bin.Cache;
54 import jalview.commands.ChangeCaseCommand;
55 import jalview.commands.EditCommand;
56 import jalview.commands.EditCommand.Action;
57 import jalview.datamodel.AlignmentAnnotation;
58 import jalview.datamodel.AlignmentI;
59 import jalview.datamodel.DBRefEntry;
60 import jalview.datamodel.HiddenColumns;
61 import jalview.datamodel.MappedFeatures;
62 import jalview.datamodel.PDBEntry;
63 import jalview.datamodel.ResidueCount;
64 import jalview.datamodel.SequenceFeature;
65 import jalview.datamodel.SequenceGroup;
66 import jalview.datamodel.SequenceI;
67 import jalview.gui.ColourMenuHelper.ColourChangeListener;
68 import jalview.io.CountReader;
69 import jalview.io.FileFormatI;
70 import jalview.io.FileFormats;
71 import jalview.io.FormatAdapter;
72 import jalview.io.SequenceAnnotationReport;
73 import jalview.schemes.Blosum62ColourScheme;
74 import jalview.schemes.ColourSchemeI;
75 import jalview.schemes.ColourSchemes;
76 import jalview.schemes.PIDColourScheme;
77 import jalview.schemes.ResidueColourScheme;
78 import jalview.util.Comparison;
79 import jalview.util.GroupUrlLink;
80 import jalview.util.GroupUrlLink.UrlStringTooLongException;
81 import jalview.util.MessageManager;
82 import jalview.util.StringUtils;
83 import jalview.util.UrlLink;
84 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
86 import java.io.IOException;
87 import java.net.MalformedURLException;
90 * The popup menu that is displayed on right-click on a sequence id, or in the
93 public class PopupMenu extends JPopupMenu implements ColourChangeListener
96 * maximum length of feature description to include in popup menu item text
98 private static final int FEATURE_DESC_MAX = 40;
101 * true for ID Panel menu, false for alignment panel menu
103 private final boolean forIdPanel;
105 private final AlignmentPanel ap;
108 * the sequence under the cursor when clicked
109 * (additional sequences may be selected)
111 private final SequenceI sequence;
113 JMenu groupMenu = new JMenu();
115 JMenuItem groupName = new JMenuItem();
117 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
119 protected JMenuItem modifyPID = new JMenuItem();
121 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
123 protected JRadioButtonMenuItem annotationColour;
125 protected JMenuItem modifyConservation = new JMenuItem();
127 JMenu sequenceMenu = new JMenu();
129 JMenuItem makeReferenceSeq = new JMenuItem();
131 JMenuItem createGroupMenuItem = new JMenuItem();
133 JMenuItem unGroupMenuItem = new JMenuItem();
135 JMenu colourMenu = new JMenu();
137 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
139 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
141 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
143 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
145 JMenu editMenu = new JMenu();
147 JMenuItem upperCase = new JMenuItem();
149 JMenuItem lowerCase = new JMenuItem();
151 JMenuItem toggle = new JMenuItem();
153 JMenu outputMenu = new JMenu();
155 JMenu seqShowAnnotationsMenu = new JMenu();
157 JMenu seqHideAnnotationsMenu = new JMenu();
159 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
160 MessageManager.getString("label.add_reference_annotations"));
162 JMenu groupShowAnnotationsMenu = new JMenu();
164 JMenu groupHideAnnotationsMenu = new JMenu();
166 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
167 MessageManager.getString("label.add_reference_annotations"));
169 JMenuItem textColour = new JMenuItem();
171 JMenu editGroupMenu = new JMenu();
173 JMenuItem chooseStructure = new JMenuItem();
175 JMenu rnaStructureMenu = new JMenu();
178 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
179 * and/or features provided. Hyperlinks may include a lookup by sequence id,
180 * or database cross-references, depending on which links are enabled in user
187 protected static JMenu buildLinkMenu(final SequenceI seq,
188 List<SequenceFeature> features)
190 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
192 List<String> nlinks = null;
195 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
196 UrlLink.sort(nlinks);
200 nlinks = new ArrayList<>();
203 if (features != null)
205 for (SequenceFeature sf : features)
207 if (sf.links != null)
209 for (String link : sf.links)
218 * instantiate the hyperlinklink templates from sequence data;
219 * note the order of the templates is preserved in the map
221 Map<String, List<String>> linkset = new LinkedHashMap<>();
222 for (String link : nlinks)
224 UrlLink urlLink = null;
227 urlLink = new UrlLink(link);
228 } catch (Exception foo)
230 Cache.log.error("Exception for URLLink '" + link + "'", foo);
234 if (!urlLink.isValid())
236 Cache.log.error(urlLink.getInvalidMessage());
240 urlLink.createLinksFromSeq(seq, linkset);
244 * construct menu items for the hyperlinks (still preserving
245 * the order of the sorted templates)
247 addUrlLinks(linkMenu, linkset.values());
253 * A helper method that builds menu items from the given links, with action
254 * handlers to open the link URL, and adds them to the linkMenu. Each provided
255 * link should be a list whose second item is the menu text, and whose fourth
256 * item is the URL to open when the menu item is selected.
261 static private void addUrlLinks(JMenu linkMenu,
262 Collection<List<String>> linkset)
264 for (List<String> linkstrset : linkset)
266 final String url = linkstrset.get(3);
267 JMenuItem item = new JMenuItem(linkstrset.get(1));
268 item.setToolTipText(MessageManager
269 .formatMessage("label.open_url_param", new Object[]
271 item.addActionListener(new ActionListener()
274 public void actionPerformed(ActionEvent e)
276 new Thread(new Runnable()
291 * Opens the provided url in the default web browser, or shows an error
292 * message if this fails
296 static void showLink(String url)
300 jalview.util.BrowserLauncher.openURL(url);
301 } catch (Exception ex)
303 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
304 MessageManager.getString("label.web_browser_not_found_unix"),
305 MessageManager.getString("label.web_browser_not_found"),
306 JvOptionPane.WARNING_MESSAGE);
308 ex.printStackTrace();
313 * add a late bound groupURL item to the given linkMenu
317 * - menu label string
318 * @param urlgenerator
319 * GroupURLLink used to generate URL
321 * Object array returned from the makeUrlStubs function.
323 static void addshowLink(JMenu linkMenu, String label,
324 final GroupUrlLink urlgenerator, final Object[] urlstub)
326 JMenuItem item = new JMenuItem(label);
327 item.setToolTipText(MessageManager
328 .formatMessage("label.open_url_seqs_param", new Object[]
329 { urlgenerator.getUrl_prefix(),
330 urlgenerator.getNumberInvolved(urlstub) }));
331 // TODO: put in info about what is being sent.
332 item.addActionListener(new ActionListener()
335 public void actionPerformed(ActionEvent e)
337 new Thread(new Runnable()
345 showLink(urlgenerator.constructFrom(urlstub));
346 } catch (UrlStringTooLongException e2)
359 * Constructor for a PopupMenu for a click in the alignment panel (on a residue)
362 * the panel in which the mouse is clicked
364 * the sequence under the mouse
365 * @throws NullPointerException
368 public PopupMenu(final AlignmentPanel ap, SequenceI seq, int column)
370 this(false, ap, seq, column, null);
374 * Constructor for a PopupMenu for a click in the sequence id panel
377 * the panel in which the mouse is clicked
379 * the sequence under the mouse click
381 * templates for sequence external links
382 * @throws NullPointerException
385 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
386 List<String> groupLinks)
388 this(true, alignPanel, seq, -1, groupLinks);
392 * Private constructor that constructs a popup menu for either sequence ID
393 * Panel, or alignment context
399 * aligned column position (0...)
402 private PopupMenu(boolean fromIdPanel,
403 final AlignmentPanel alignPanel,
404 final SequenceI seq, final int column, List<String> groupLinks)
406 Objects.requireNonNull(seq);
407 this.forIdPanel = fromIdPanel;
408 this.ap = alignPanel;
411 for (String ff : FileFormats.getInstance().getWritableFormats(true))
413 JMenuItem item = new JMenuItem(ff);
415 item.addActionListener(new ActionListener()
418 public void actionPerformed(ActionEvent e)
420 outputText_actionPerformed(e);
424 outputMenu.add(item);
428 * Build menus for annotation types that may be shown or hidden, and for
429 * 'reference annotations' that may be added to the alignment. First for the
430 * currently selected sequence (if there is one):
432 final List<SequenceI> selectedSequence = (forIdPanel && seq != null
434 : Collections.<SequenceI> emptyList());
435 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
436 seqHideAnnotationsMenu, selectedSequence);
437 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
441 * And repeat for the current selection group (if there is one):
443 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
444 ? Collections.<SequenceI> emptyList()
445 : alignPanel.av.getSelectionGroup().getSequences());
446 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
447 groupHideAnnotationsMenu, selectedGroup);
448 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
454 } catch (Exception e)
462 sequenceMenu.setText(sequence.getName());
463 if (seq == alignPanel.av.getAlignment().getSeqrep())
465 makeReferenceSeq.setText(
466 MessageManager.getString("action.unmark_as_reference"));
470 makeReferenceSeq.setText(
471 MessageManager.getString("action.set_as_reference"));
474 if (!alignPanel.av.getAlignment().isNucleotide())
476 remove(rnaStructureMenu);
480 int origCount = rnaStructureMenu.getItemCount();
482 * add menu items to 2D-render any alignment or sequence secondary
483 * structure annotation
485 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
486 .getAlignmentAnnotation();
489 for (final AlignmentAnnotation aa : aas)
491 if (aa.isValidStruc() && aa.sequenceRef == null)
494 * valid alignment RNA secondary structure annotation
496 menuItem = new JMenuItem();
497 menuItem.setText(MessageManager.formatMessage(
498 "label.2d_rna_structure_line", new Object[]
500 menuItem.addActionListener(new ActionListener()
503 public void actionPerformed(ActionEvent e)
505 new AppVarna(seq, aa, alignPanel);
508 rnaStructureMenu.add(menuItem);
513 if (seq.getAnnotation() != null)
515 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
516 for (final AlignmentAnnotation aa : seqAnns)
518 if (aa.isValidStruc())
521 * valid sequence RNA secondary structure annotation
523 // TODO: make rnastrucF a bit more nice
524 menuItem = new JMenuItem();
525 menuItem.setText(MessageManager.formatMessage(
526 "label.2d_rna_sequence_name", new Object[]
528 menuItem.addActionListener(new ActionListener()
531 public void actionPerformed(ActionEvent e)
533 // TODO: VARNA does'nt print gaps in the sequence
534 new AppVarna(seq, aa, alignPanel);
537 rnaStructureMenu.add(menuItem);
541 if (rnaStructureMenu.getItemCount() == origCount)
543 remove(rnaStructureMenu);
547 if (seq.hasHMMProfile())
549 menuItem = new JMenuItem(MessageManager
550 .getString("action.add_background_frequencies"));
551 menuItem.addActionListener(new ActionListener()
554 public void actionPerformed(ActionEvent e)
558 ResidueCount counts = CountReader.getBackgroundFrequencies(ap,
562 seq.getHMM().setBackgroundFrequencies(counts);
563 ap.alignFrame.buildColourMenu();
565 } catch (MalformedURLException e1)
567 e1.printStackTrace();
568 } catch (IOException e1)
570 e1.printStackTrace();
577 menuItem = new JMenuItem(
578 MessageManager.getString("action.hide_sequences"));
579 menuItem.addActionListener(new ActionListener()
582 public void actionPerformed(ActionEvent e)
584 hideSequences(false);
589 if (alignPanel.av.getSelectionGroup() != null
590 && alignPanel.av.getSelectionGroup().getSize() > 1)
592 menuItem = new JMenuItem(MessageManager
593 .formatMessage("label.represent_group_with", new Object[]
595 menuItem.addActionListener(new ActionListener()
598 public void actionPerformed(ActionEvent e)
603 sequenceMenu.add(menuItem);
606 if (alignPanel.av.hasHiddenRows())
608 final int index = alignPanel.av.getAlignment().findIndex(seq);
610 if (alignPanel.av.adjustForHiddenSeqs(index)
611 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
613 menuItem = new JMenuItem(
614 MessageManager.getString("action.reveal_sequences"));
615 menuItem.addActionListener(new ActionListener()
618 public void actionPerformed(ActionEvent e)
620 alignPanel.av.showSequence(index);
621 if (alignPanel.overviewPanel != null)
623 alignPanel.overviewPanel.updateOverviewImage();
634 * - in the IdPanel (seq not null) if any sequence is hidden
635 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
637 if (alignPanel.av.hasHiddenRows())
639 boolean addOption = seq != null;
640 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
646 JMenuItem menuItem = new JMenuItem(
647 MessageManager.getString("action.reveal_all"));
648 menuItem.addActionListener(new ActionListener()
651 public void actionPerformed(ActionEvent e)
653 alignPanel.av.showAllHiddenSeqs();
654 if (alignPanel.overviewPanel != null)
656 alignPanel.overviewPanel.updateOverviewImage();
664 SequenceGroup sg = alignPanel.av.getSelectionGroup();
665 boolean isDefinedGroup = (sg != null)
666 ? alignPanel.av.getAlignment().getGroups().contains(sg)
669 if (sg != null && sg.getSize() > 0)
671 groupName.setText(MessageManager
672 .getString("label.edit_name_and_description_current_group"));
674 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
676 conservationMenuItem.setEnabled(!sg.isNucleotide());
680 if (sg.cs.conservationApplied())
682 conservationMenuItem.setSelected(true);
684 if (sg.cs.getThreshold() > 0)
686 abovePIDColour.setSelected(true);
689 modifyConservation.setEnabled(conservationMenuItem.isSelected());
690 modifyPID.setEnabled(abovePIDColour.isSelected());
691 displayNonconserved.setSelected(sg.getShowNonconserved());
692 showText.setSelected(sg.getDisplayText());
693 showColourText.setSelected(sg.getColourText());
694 showBoxes.setSelected(sg.getDisplayBoxes());
695 // add any groupURLs to the groupURL submenu and make it visible
696 if (groupLinks != null && groupLinks.size() > 0)
698 buildGroupURLMenu(sg, groupLinks);
700 // Add a 'show all structures' for the current selection
701 Hashtable<String, PDBEntry> pdbe = new Hashtable<>();
702 Hashtable<String, PDBEntry> reppdb = new Hashtable<>();
704 SequenceI sqass = null;
705 for (SequenceI sq : alignPanel.av.getSequenceSelection())
707 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
708 if (pes != null && pes.size() > 0)
710 reppdb.put(pes.get(0).getId(), pes.get(0));
711 for (PDBEntry pe : pes)
713 pdbe.put(pe.getId(), pe);
723 final PDBEntry[] pe = pdbe.values()
724 .toArray(new PDBEntry[pdbe.size()]),
725 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
726 final JMenuItem gpdbview, rpdbview;
731 groupMenu.setVisible(false);
732 editMenu.setVisible(false);
737 createGroupMenuItem.setVisible(true);
738 unGroupMenuItem.setVisible(false);
739 editGroupMenu.setText(MessageManager.getString("action.edit_new_group"));
743 createGroupMenuItem.setVisible(false);
744 unGroupMenuItem.setVisible(true);
745 editGroupMenu.setText(MessageManager.getString("action.edit_group"));
750 sequenceMenu.setVisible(false);
751 chooseStructure.setVisible(false);
752 rnaStructureMenu.setVisible(false);
755 addLinksAndFeatures(seq, column);
761 * <li>configured sequence database links (ID panel popup menu)</li>
762 * <li>non-positional feature links (ID panel popup menu)</li>
763 * <li>positional feature links (alignment panel popup menu)</li>
764 * <li>feature details links (alignment panel popup menu)</li>
766 * If this panel is also showed complementary (CDS/protein) features, then links
767 * to their feature details are also added.
772 void addLinksAndFeatures(final SequenceI seq, final int column)
774 List<SequenceFeature> features = null;
777 features = sequence.getFeatures().getNonPositionalFeatures();
781 features = ap.getFeatureRenderer().findFeaturesAtColumn(sequence,
785 addLinks(seq, features);
789 addFeatureDetails(features, seq, column);
794 * Add a menu item to show feature details for each sequence feature. Any
795 * linked 'virtual' features (CDS/protein) are also optionally found and
802 protected void addFeatureDetails(List<SequenceFeature> features,
803 final SequenceI seq, final int column)
806 * add features in CDS/protein complement at the corresponding
807 * position if configured to do so
809 MappedFeatures mf = null;
810 if (ap.av.isShowComplementFeatures())
812 if (!Comparison.isGap(sequence.getCharAt(column)))
814 AlignViewportI complement = ap.getAlignViewport()
815 .getCodingComplement();
816 AlignFrame af = Desktop.getAlignFrameFor(complement);
817 FeatureRendererModel fr2 = af.getFeatureRenderer();
818 int seqPos = sequence.findPosition(column);
819 mf = fr2.findComplementFeaturesAtResidue(sequence, seqPos);
823 if (features.isEmpty() && mf == null)
826 * no features to show at this position
831 JMenu details = new JMenu(
832 MessageManager.getString("label.feature_details"));
835 String name = seq.getName();
836 for (final SequenceFeature sf : features)
838 addFeatureDetailsMenuItem(details, name, sf, null);
843 for (final SequenceFeature sf : mf.features)
845 addFeatureDetailsMenuItem(details, name, sf, mf);
851 * A helper method to add one menu item whose action is to show details for
852 * one feature. The menu text includes feature description, but this may be
860 void addFeatureDetailsMenuItem(JMenu details, final String seqName,
861 final SequenceFeature sf, MappedFeatures mf)
863 int start = sf.getBegin();
864 int end = sf.getEnd();
868 * show local rather than linked feature coordinates
870 int[] beginRange = mf.getMappedPositions(start, start);
871 start = beginRange[0];
872 int[] endRange = mf.getMappedPositions(end, end);
873 end = endRange[endRange.length - 1];
875 StringBuilder desc = new StringBuilder();
876 desc.append(sf.getType()).append(" ").append(String.valueOf(start));
879 desc.append(sf.isContactFeature() ? ":" : "-");
880 desc.append(String.valueOf(end));
882 String description = sf.getDescription();
883 if (description != null)
886 description = StringUtils.stripHtmlTags(description);
889 * truncate overlong descriptions unless they contain an href
890 * (as truncation could leave corrupted html)
892 boolean hasLink = description.indexOf("a href") > -1;
893 if (description.length() > FEATURE_DESC_MAX && !hasLink)
895 description = description.substring(0, FEATURE_DESC_MAX) + "...";
897 desc.append(description);
899 String featureGroup = sf.getFeatureGroup();
900 if (featureGroup != null)
902 desc.append(" (").append(featureGroup).append(")");
904 String htmlText = JvSwingUtils.wrapTooltip(true, desc.toString());
905 JMenuItem item = new JMenuItem(htmlText);
906 item.addActionListener(new ActionListener()
909 public void actionPerformed(ActionEvent e)
911 showFeatureDetails(sf, seqName, mf);
918 * Opens a panel showing a text report of feature details
924 protected void showFeatureDetails(SequenceFeature sf, String seqName,
927 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
928 // it appears Java's CSS does not support border-collapse :-(
929 cap.addStylesheetRule("table { border-collapse: collapse;}");
930 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
931 cap.setText(sf.getDetailsReport(seqName, mf));
933 Desktop.addInternalFrame(cap,
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 DBRefEntry[] dbr = sqi.getDBRefs();
1127 if (dbr != null && dbr.length > 0)
1129 for (int d = 0; d < dbr.length; d++)
1131 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1132 Object[] sarray = commonDbrefs.get(src);
1135 sarray = new Object[2];
1136 sarray[0] = new int[] { 0 };
1137 sarray[1] = new String[seqs.length];
1139 commonDbrefs.put(src, sarray);
1142 if (((String[]) sarray[1])[sq] == null)
1144 if (!dbr[d].hasMap() || (dbr[d].getMap()
1145 .locateMappedRange(start, end) != null))
1147 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1148 ((int[]) sarray[0])[0]++;
1154 // now create group links for all distinct ID/sequence sets.
1155 boolean addMenu = false; // indicates if there are any group links to give
1157 for (String link : groupLinks)
1159 GroupUrlLink urlLink = null;
1162 urlLink = new GroupUrlLink(link);
1163 } catch (Exception foo)
1165 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
1169 if (!urlLink.isValid())
1171 Cache.log.error(urlLink.getInvalidMessage());
1174 final String label = urlLink.getLabel();
1175 boolean usingNames = false;
1176 // Now see which parts of the group apply for this URL
1177 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1178 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
1179 String[] seqstr, ids; // input to makeUrl
1182 int numinput = ((int[]) idset[0])[0];
1183 String[] allids = ((String[]) idset[1]);
1184 seqstr = new String[numinput];
1185 ids = new String[numinput];
1186 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1188 if (allids[sq] != null)
1190 ids[idcount] = allids[sq];
1191 seqstr[idcount++] = idandseqs[1][sq];
1197 // just use the id/seq set
1198 seqstr = idandseqs[1];
1202 // and try and make the groupURL!
1204 Object[] urlset = null;
1207 urlset = urlLink.makeUrlStubs(ids, seqstr,
1208 "FromJalview" + System.currentTimeMillis(), false);
1209 } catch (UrlStringTooLongException e)
1214 int type = urlLink.getGroupURLType() & 3;
1215 // first two bits ofurlLink type bitfield are sequenceids and sequences
1216 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1217 addshowLink(linkMenus[type],
1218 label + (((type & 1) == 1)
1219 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1227 groupLinksMenu = new JMenu(
1228 MessageManager.getString("action.group_link"));
1229 for (int m = 0; m < linkMenus.length; m++)
1231 if (linkMenus[m] != null
1232 && linkMenus[m].getMenuComponentCount() > 0)
1234 groupLinksMenu.add(linkMenus[m]);
1238 groupMenu.add(groupLinksMenu);
1248 private void jbInit() throws Exception
1250 groupMenu.setText(MessageManager.getString("label.selection"));
1251 groupName.setText(MessageManager.getString("label.name"));
1252 groupName.addActionListener(new ActionListener()
1255 public void actionPerformed(ActionEvent e)
1257 groupName_actionPerformed();
1260 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1262 JMenuItem sequenceName = new JMenuItem(
1263 MessageManager.getString("label.edit_name_description"));
1264 sequenceName.addActionListener(new ActionListener()
1267 public void actionPerformed(ActionEvent e)
1269 sequenceName_actionPerformed();
1272 JMenuItem chooseAnnotations = new JMenuItem(
1273 MessageManager.getString("action.choose_annotations"));
1274 chooseAnnotations.addActionListener(new ActionListener()
1277 public void actionPerformed(ActionEvent e)
1279 chooseAnnotations_actionPerformed(e);
1282 JMenuItem sequenceDetails = new JMenuItem(
1283 MessageManager.getString("label.sequence_details"));
1284 sequenceDetails.addActionListener(new ActionListener()
1287 public void actionPerformed(ActionEvent e)
1289 createSequenceDetailsReport(new SequenceI[] { sequence });
1292 JMenuItem sequenceSelDetails = new JMenuItem(
1293 MessageManager.getString("label.sequence_details"));
1294 sequenceSelDetails.addActionListener(new ActionListener()
1297 public void actionPerformed(ActionEvent e)
1299 createSequenceDetailsReport(ap.av.getSequenceSelection());
1304 .setText(MessageManager.getString("action.remove_group"));
1305 unGroupMenuItem.addActionListener(new ActionListener()
1308 public void actionPerformed(ActionEvent e)
1310 unGroupMenuItem_actionPerformed();
1314 .setText(MessageManager.getString("action.create_group"));
1315 createGroupMenuItem.addActionListener(new ActionListener()
1318 public void actionPerformed(ActionEvent e)
1320 createGroupMenuItem_actionPerformed();
1324 JMenuItem outline = new JMenuItem(
1325 MessageManager.getString("action.border_colour"));
1326 outline.addActionListener(new ActionListener()
1329 public void actionPerformed(ActionEvent e)
1331 outline_actionPerformed();
1334 showBoxes.setText(MessageManager.getString("action.boxes"));
1335 showBoxes.setState(true);
1336 showBoxes.addActionListener(new ActionListener()
1339 public void actionPerformed(ActionEvent e)
1341 showBoxes_actionPerformed();
1344 showText.setText(MessageManager.getString("action.text"));
1345 showText.setState(true);
1346 showText.addActionListener(new ActionListener()
1349 public void actionPerformed(ActionEvent e)
1351 showText_actionPerformed();
1354 showColourText.setText(MessageManager.getString("label.colour_text"));
1355 showColourText.addActionListener(new ActionListener()
1358 public void actionPerformed(ActionEvent e)
1360 showColourText_actionPerformed();
1364 .setText(MessageManager.getString("label.show_non_conserved"));
1365 displayNonconserved.setState(true);
1366 displayNonconserved.addActionListener(new ActionListener()
1369 public void actionPerformed(ActionEvent e)
1371 showNonconserved_actionPerformed();
1374 editMenu.setText(MessageManager.getString("action.edit"));
1375 JMenuItem cut = new JMenuItem(MessageManager.getString("action.cut"));
1376 cut.addActionListener(new ActionListener()
1379 public void actionPerformed(ActionEvent e)
1381 cut_actionPerformed();
1384 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1385 upperCase.addActionListener(new ActionListener()
1388 public void actionPerformed(ActionEvent e)
1393 JMenuItem copy = new JMenuItem(MessageManager.getString("action.copy"));
1394 copy.addActionListener(new ActionListener()
1397 public void actionPerformed(ActionEvent e)
1399 copy_actionPerformed();
1402 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1403 lowerCase.addActionListener(new ActionListener()
1406 public void actionPerformed(ActionEvent e)
1411 toggle.setText(MessageManager.getString("label.toggle_case"));
1412 toggle.addActionListener(new ActionListener()
1415 public void actionPerformed(ActionEvent e)
1421 MessageManager.getString("label.out_to_textbox") + "...");
1422 seqShowAnnotationsMenu
1423 .setText(MessageManager.getString("label.show_annotations"));
1424 seqHideAnnotationsMenu
1425 .setText(MessageManager.getString("label.hide_annotations"));
1426 groupShowAnnotationsMenu
1427 .setText(MessageManager.getString("label.show_annotations"));
1428 groupHideAnnotationsMenu
1429 .setText(MessageManager.getString("label.hide_annotations"));
1430 JMenuItem sequenceFeature = new JMenuItem(
1431 MessageManager.getString("label.create_sequence_feature"));
1432 sequenceFeature.addActionListener(new ActionListener()
1435 public void actionPerformed(ActionEvent e)
1437 sequenceFeature_actionPerformed();
1440 editGroupMenu.setText(MessageManager.getString("label.group"));
1441 chooseStructure.setText(
1442 MessageManager.getString("label.show_pdbstruct_dialog"));
1443 chooseStructure.addActionListener(new ActionListener()
1446 public void actionPerformed(ActionEvent actionEvent)
1448 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1449 if (ap.av.getSelectionGroup() != null)
1451 selectedSeqs = ap.av.getSequenceSelection();
1453 new StructureChooser(selectedSeqs, sequence, ap);
1458 .setText(MessageManager.getString("label.view_rna_structure"));
1460 // colStructureMenu.setText("Colour By Structure");
1461 JMenuItem editSequence = new JMenuItem(
1462 MessageManager.getString("label.edit_sequence") + "...");
1463 editSequence.addActionListener(new ActionListener()
1466 public void actionPerformed(ActionEvent actionEvent)
1468 editSequence_actionPerformed(actionEvent);
1471 makeReferenceSeq.setText(
1472 MessageManager.getString("label.mark_as_representative"));
1473 makeReferenceSeq.addActionListener(new ActionListener()
1477 public void actionPerformed(ActionEvent actionEvent)
1479 makeReferenceSeq_actionPerformed(actionEvent);
1484 groupMenu.add(sequenceSelDetails);
1487 add(rnaStructureMenu);
1488 add(chooseStructure);
1491 JMenuItem hideInsertions = new JMenuItem(
1492 MessageManager.getString("label.hide_insertions"));
1493 hideInsertions.addActionListener(new ActionListener()
1497 public void actionPerformed(ActionEvent e)
1499 hideInsertions_actionPerformed(e);
1502 add(hideInsertions);
1504 // annotations configuration panel suppressed for now
1505 // groupMenu.add(chooseAnnotations);
1508 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1509 * (if a selection group is in force).
1511 sequenceMenu.add(seqShowAnnotationsMenu);
1512 sequenceMenu.add(seqHideAnnotationsMenu);
1513 sequenceMenu.add(seqAddReferenceAnnotations);
1514 groupMenu.add(groupShowAnnotationsMenu);
1515 groupMenu.add(groupHideAnnotationsMenu);
1516 groupMenu.add(groupAddReferenceAnnotations);
1517 groupMenu.add(editMenu);
1518 groupMenu.add(outputMenu);
1519 groupMenu.add(sequenceFeature);
1520 groupMenu.add(createGroupMenuItem);
1521 groupMenu.add(unGroupMenuItem);
1522 groupMenu.add(editGroupMenu);
1523 sequenceMenu.add(sequenceName);
1524 sequenceMenu.add(sequenceDetails);
1525 sequenceMenu.add(makeReferenceSeq);
1532 editMenu.add(editSequence);
1533 editMenu.add(upperCase);
1534 editMenu.add(lowerCase);
1535 editMenu.add(toggle);
1536 editGroupMenu.add(groupName);
1537 editGroupMenu.add(colourMenu);
1538 editGroupMenu.add(showBoxes);
1539 editGroupMenu.add(showText);
1540 editGroupMenu.add(showColourText);
1541 editGroupMenu.add(outline);
1542 editGroupMenu.add(displayNonconserved);
1546 * Constructs the entries for the colour menu
1548 protected void initColourMenu()
1550 colourMenu.setText(MessageManager.getString("label.group_colour"));
1551 textColour.setText(MessageManager.getString("label.text_colour"));
1552 textColour.addActionListener(new ActionListener()
1555 public void actionPerformed(ActionEvent e)
1557 textColour_actionPerformed();
1561 abovePIDColour.setText(
1562 MessageManager.getString("label.above_identity_threshold"));
1563 abovePIDColour.addActionListener(new ActionListener()
1566 public void actionPerformed(ActionEvent e)
1568 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1573 MessageManager.getString("label.modify_identity_threshold"));
1574 modifyPID.addActionListener(new ActionListener()
1577 public void actionPerformed(ActionEvent e)
1579 modifyPID_actionPerformed();
1583 conservationMenuItem
1584 .setText(MessageManager.getString("action.by_conservation"));
1585 conservationMenuItem.addActionListener(new ActionListener()
1588 public void actionPerformed(ActionEvent e)
1590 conservationMenuItem_actionPerformed(
1591 conservationMenuItem.isSelected());
1595 annotationColour = new JRadioButtonMenuItem(
1596 MessageManager.getString("action.by_annotation"));
1597 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1598 annotationColour.setEnabled(false);
1599 annotationColour.setToolTipText(
1600 MessageManager.getString("label.by_annotation_tooltip"));
1602 modifyConservation.setText(MessageManager
1603 .getString("label.modify_conservation_threshold"));
1604 modifyConservation.addActionListener(new ActionListener()
1607 public void actionPerformed(ActionEvent e)
1609 modifyConservation_actionPerformed();
1615 * Builds the group colour sub-menu, including any user-defined colours which
1616 * were loaded at startup or during the Jalview session
1618 protected void buildColourMenu()
1620 SequenceGroup sg = ap.av.getSelectionGroup();
1624 * popup menu with no sequence group scope
1628 colourMenu.removeAll();
1629 colourMenu.add(textColour);
1630 colourMenu.addSeparator();
1632 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1634 bg.add(annotationColour);
1635 colourMenu.add(annotationColour);
1637 colourMenu.addSeparator();
1638 colourMenu.add(conservationMenuItem);
1639 colourMenu.add(modifyConservation);
1640 colourMenu.add(abovePIDColour);
1641 colourMenu.add(modifyPID);
1644 protected void modifyConservation_actionPerformed()
1646 SequenceGroup sg = getGroup();
1649 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1650 SliderPanel.showConservationSlider();
1654 protected void modifyPID_actionPerformed()
1656 SequenceGroup sg = getGroup();
1659 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1661 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1662 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1663 SliderPanel.showPIDSlider();
1668 * Check for any annotations on the underlying dataset sequences (for the
1669 * current selection group) which are not 'on the alignment'.If any are found,
1670 * enable the option to add them to the alignment. The criteria for 'on the
1671 * alignment' is finding an alignment annotation on the alignment, matched on
1672 * calcId, label and sequenceRef.
1674 * A tooltip is also constructed that displays the source (calcId) and type
1675 * (label) of the annotations that can be added.
1678 * @param forSequences
1680 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1681 List<SequenceI> forSequences)
1683 menuItem.setEnabled(false);
1686 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1687 * Using TreeMap means calcIds are shown in alphabetical order.
1689 SortedMap<String, String> tipEntries = new TreeMap<>();
1690 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1691 AlignmentI al = this.ap.av.getAlignment();
1692 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1694 if (!candidates.isEmpty())
1696 StringBuilder tooltip = new StringBuilder(64);
1697 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1700 * Found annotations that could be added. Enable the menu item, and
1701 * configure its tooltip and action.
1703 menuItem.setEnabled(true);
1704 for (String calcId : tipEntries.keySet())
1706 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1708 String tooltipText = JvSwingUtils.wrapTooltip(true,
1709 tooltip.toString());
1710 menuItem.setToolTipText(tooltipText);
1712 menuItem.addActionListener(new ActionListener()
1715 public void actionPerformed(ActionEvent e)
1717 addReferenceAnnotations_actionPerformed(candidates);
1724 * Add annotations to the sequences and to the alignment.
1727 * a map whose keys are sequences on the alignment, and values a list
1728 * of annotations to add to each sequence
1730 protected void addReferenceAnnotations_actionPerformed(
1731 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1733 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1734 final AlignmentI alignment = this.ap.getAlignment();
1735 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1740 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1742 if (!ap.av.getAlignment().hasSeqrep())
1744 // initialise the display flags so the user sees something happen
1745 ap.av.setDisplayReferenceSeq(true);
1746 ap.av.setColourByReferenceSeq(true);
1747 ap.av.getAlignment().setSeqrep(sequence);
1751 if (ap.av.getAlignment().getSeqrep() == sequence)
1753 ap.av.getAlignment().setSeqrep(null);
1757 ap.av.getAlignment().setSeqrep(sequence);
1763 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1765 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1766 BitSet inserts = new BitSet();
1768 boolean markedPopup = false;
1769 // mark inserts in current selection
1770 if (ap.av.getSelectionGroup() != null)
1772 // mark just the columns in the selection group to be hidden
1773 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1774 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1776 // now clear columns without gaps
1777 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1783 inserts.and(sq.getInsertionsAsBits());
1785 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1786 ap.av.getSelectionGroup().getEndRes());
1789 // now mark for sequence under popup if we haven't already done it
1790 else if (!markedPopup && sequence != null)
1792 inserts.or(sequence.getInsertionsAsBits());
1794 // and set hidden columns accordingly
1795 hidden.hideColumns(inserts);
1800 protected void sequenceSelectionDetails_actionPerformed()
1802 createSequenceDetailsReport(ap.av.getSequenceSelection());
1805 public void createSequenceDetailsReport(SequenceI[] sequences)
1807 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1808 StringBuilder contents = new StringBuilder(128);
1809 for (SequenceI seq : sequences)
1811 contents.append("<p><h2>" + MessageManager.formatMessage(
1812 "label.create_sequence_details_report_annotation_for",
1814 { seq.getDisplayId(true) }) + "</h2></p><p>");
1815 new SequenceAnnotationReport(false).createSequenceAnnotationReport(
1816 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1817 contents.append("</p>");
1819 cap.setText("<html>" + contents.toString() + "</html>");
1821 Desktop.addInternalFrame(cap,
1822 MessageManager.formatMessage("label.sequence_details_for",
1823 (sequences.length == 1 ? new Object[]
1824 { sequences[0].getDisplayId(true) }
1827 .getString("label.selection") })),
1832 protected void showNonconserved_actionPerformed()
1834 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1839 * call to refresh view after settings change
1843 ap.updateAnnotation();
1844 // removed paintAlignment(true) here:
1845 // updateAnnotation calls paintAlignment already, so don't need to call
1848 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1852 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1853 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1863 public void abovePIDColour_actionPerformed(boolean selected)
1865 SequenceGroup sg = getGroup();
1873 sg.cs.setConsensus(AAFrequency.calculate(
1874 sg.getSequences(ap.av.getHiddenRepSequences()),
1875 sg.getStartRes(), sg.getEndRes() + 1));
1877 int threshold = SliderPanel.setPIDSliderSource(ap,
1878 sg.getGroupColourScheme(), getGroup().getName());
1880 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1882 SliderPanel.showPIDSlider();
1885 // remove PIDColouring
1887 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1888 SliderPanel.hidePIDSlider();
1890 modifyPID.setEnabled(selected);
1896 * Open a panel where the user can choose which types of sequence annotation
1901 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1903 // todo correct way to guard against opening a duplicate panel?
1904 new AnnotationChooser(ap);
1913 public void conservationMenuItem_actionPerformed(boolean selected)
1915 SequenceGroup sg = getGroup();
1923 // JBPNote: Conservation name shouldn't be i18n translated
1924 Conservation c = new Conservation("Group",
1925 sg.getSequences(ap.av.getHiddenRepSequences()),
1926 sg.getStartRes(), sg.getEndRes() + 1);
1929 c.verdict(false, ap.av.getConsPercGaps());
1930 sg.cs.setConservation(c);
1932 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1934 SliderPanel.showConservationSlider();
1937 // remove ConservationColouring
1939 sg.cs.setConservation(null);
1940 SliderPanel.hideConservationSlider();
1942 modifyConservation.setEnabled(selected);
1953 protected void groupName_actionPerformed()
1956 SequenceGroup sg = getGroup();
1957 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1958 sg.getDescription(),
1959 " " + MessageManager.getString("label.group_name") + " ",
1960 MessageManager.getString("label.group_description") + " ",
1961 MessageManager.getString("label.edit_group_name_description"),
1969 sg.setName(dialog.getName());
1970 sg.setDescription(dialog.getDescription());
1975 * Get selection group - adding it to the alignment if necessary.
1977 * @return sequence group to operate on
1979 SequenceGroup getGroup()
1981 SequenceGroup sg = ap.av.getSelectionGroup();
1982 // this method won't add a new group if it already exists
1985 ap.av.getAlignment().addGroup(sg);
1992 * Shows a dialog where the sequence name and description may be edited. If a
1993 * name containing spaces is entered, these are converted to underscores, with a
1996 void sequenceName_actionPerformed()
1998 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1999 sequence.getDescription(),
2000 " " + MessageManager.getString("label.sequence_name")
2002 MessageManager.getString("label.sequence_description") + " ",
2003 MessageManager.getString(
2004 "label.edit_sequence_name_description"),
2012 String name = dialog.getName();
2015 if (name.indexOf(" ") > -1)
2017 JvOptionPane.showMessageDialog(ap,
2019 .getString("label.spaces_converted_to_backslashes"),
2021 .getString("label.no_spaces_allowed_sequence_name"),
2022 JvOptionPane.WARNING_MESSAGE);
2023 name = name.replace(' ', '_');
2026 sequence.setName(name);
2027 ap.paintAlignment(false, false);
2030 sequence.setDescription(dialog.getDescription());
2032 ap.av.firePropertyChange("alignment", null,
2033 ap.av.getAlignment().getSequences());
2043 void unGroupMenuItem_actionPerformed()
2045 SequenceGroup sg = ap.av.getSelectionGroup();
2046 ap.av.getAlignment().deleteGroup(sg);
2047 ap.av.setSelectionGroup(null);
2051 void createGroupMenuItem_actionPerformed()
2053 getGroup(); // implicitly creates group - note - should apply defaults / use
2054 // standard alignment window logic for this
2064 protected void outline_actionPerformed()
2066 SequenceGroup sg = getGroup();
2067 Color col = JColorChooser.showDialog(this,
2068 MessageManager.getString("label.select_outline_colour"),
2073 sg.setOutlineColour(col);
2085 public void showBoxes_actionPerformed()
2087 getGroup().setDisplayBoxes(showBoxes.isSelected());
2097 public void showText_actionPerformed()
2099 getGroup().setDisplayText(showText.isSelected());
2109 public void showColourText_actionPerformed()
2111 getGroup().setColourText(showColourText.isSelected());
2115 void hideSequences(boolean representGroup)
2117 ap.av.hideSequences(sequence, representGroup);
2120 public void copy_actionPerformed()
2122 ap.alignFrame.copy_actionPerformed(null);
2125 public void cut_actionPerformed()
2127 ap.alignFrame.cut_actionPerformed(null);
2130 void changeCase(ActionEvent e)
2132 Object source = e.getSource();
2133 SequenceGroup sg = ap.av.getSelectionGroup();
2137 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2138 sg.getStartRes(), sg.getEndRes() + 1);
2143 if (source == toggle)
2145 description = MessageManager.getString("label.toggle_case");
2146 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2148 else if (source == upperCase)
2150 description = MessageManager.getString("label.to_upper_case");
2151 caseChange = ChangeCaseCommand.TO_UPPER;
2155 description = MessageManager.getString("label.to_lower_case");
2156 caseChange = ChangeCaseCommand.TO_LOWER;
2159 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2160 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2161 startEnd, caseChange);
2163 ap.alignFrame.addHistoryItem(caseCommand);
2165 ap.av.firePropertyChange("alignment", null,
2166 ap.av.getAlignment().getSequences());
2171 public void outputText_actionPerformed(ActionEvent e)
2173 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2174 cap.setForInput(null);
2175 Desktop.addInternalFrame(cap, MessageManager
2176 .formatMessage("label.alignment_output_command", new Object[]
2177 { e.getActionCommand() }), 600, 500);
2179 String[] omitHidden = null;
2181 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2182 // or we simply trust the user wants
2183 // wysiwig behaviour
2185 FileFormatI fileFormat = FileFormats.getInstance()
2186 .forName(e.getActionCommand());
2188 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2191 public void sequenceFeature_actionPerformed()
2193 SequenceGroup sg = ap.av.getSelectionGroup();
2199 List<SequenceI> seqs = new ArrayList<>();
2200 List<SequenceFeature> features = new ArrayList<>();
2203 * assemble dataset sequences, and template new sequence features,
2204 * for the amend features dialog
2206 int gSize = sg.getSize();
2207 for (int i = 0; i < gSize; i++)
2209 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2210 int end = sg.findEndRes(sg.getSequenceAt(i));
2213 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2214 features.add(new SequenceFeature(null, null, start, end, null));
2219 * an entirely gapped region will generate empty lists of sequence / features
2221 if (!seqs.isEmpty())
2223 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer()
2224 .amendFeatures(seqs, features, true, ap))
2226 ap.alignFrame.setShowSeqFeatures(true);
2227 ap.av.setSearchResults(null); // clear highlighting
2228 ap.repaint(); // draw new/amended features
2233 public void textColour_actionPerformed()
2235 SequenceGroup sg = getGroup();
2238 new TextColourChooser().chooseColour(ap, sg);
2242 public void editSequence_actionPerformed(ActionEvent actionEvent)
2244 SequenceGroup sg = ap.av.getSelectionGroup();
2246 SequenceI seq = sequence;
2251 seq = sg.getSequenceAt(0);
2254 EditNameDialog dialog = new EditNameDialog(
2255 seq.getSequenceAsString(sg.getStartRes(),
2256 sg.getEndRes() + 1),
2257 null, MessageManager.getString("label.edit_sequence"), null,
2258 MessageManager.getString("label.edit_sequence"),
2263 EditCommand editCommand = new EditCommand(
2264 MessageManager.getString("label.edit_sequences"),
2266 dialog.getName().replace(' ', ap.av.getGapCharacter()),
2267 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2268 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2270 ap.alignFrame.addHistoryItem(editCommand);
2272 ap.av.firePropertyChange("alignment", null,
2273 ap.av.getAlignment().getSequences());
2279 * Action on user selecting an item from the colour menu (that does not have
2280 * its bespoke action handler)
2285 public void changeColour_actionPerformed(String colourSchemeName)
2287 SequenceGroup sg = getGroup();
2289 * switch to the chosen colour scheme (or null for None)
2291 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2292 .getColourScheme(colourSchemeName, ap.av, sg,
2293 ap.av.getHiddenRepSequences());
2294 sg.setColourScheme(colourScheme);
2295 if (colourScheme instanceof Blosum62ColourScheme
2296 || colourScheme instanceof PIDColourScheme)
2298 sg.cs.setConsensus(AAFrequency.calculate(
2299 sg.getSequences(ap.av.getHiddenRepSequences()),
2300 sg.getStartRes(), sg.getEndRes() + 1));