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 jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.api.AlignViewportI;
28 import jalview.bin.Cache;
29 import jalview.commands.ChangeCaseCommand;
30 import jalview.commands.EditCommand;
31 import jalview.commands.EditCommand.Action;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.DBRefEntry;
35 import jalview.datamodel.HiddenColumns;
36 import jalview.datamodel.MappedFeatures;
37 import jalview.datamodel.PDBEntry;
38 import jalview.datamodel.SequenceFeature;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.gui.ColourMenuHelper.ColourChangeListener;
42 import jalview.io.FileFormatI;
43 import jalview.io.FileFormats;
44 import jalview.io.FormatAdapter;
45 import jalview.io.SequenceAnnotationReport;
46 import jalview.schemes.Blosum62ColourScheme;
47 import jalview.schemes.ColourSchemeI;
48 import jalview.schemes.ColourSchemes;
49 import jalview.schemes.PIDColourScheme;
50 import jalview.schemes.ResidueColourScheme;
51 import jalview.util.Comparison;
52 import jalview.util.GroupUrlLink;
53 import jalview.util.GroupUrlLink.UrlStringTooLongException;
54 import jalview.util.MessageManager;
55 import jalview.util.StringUtils;
56 import jalview.util.UrlLink;
57 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
59 import java.awt.Color;
60 import java.awt.event.ActionEvent;
61 import java.awt.event.ActionListener;
62 import java.util.ArrayList;
63 import java.util.Arrays;
64 import java.util.BitSet;
65 import java.util.Collection;
66 import java.util.Collections;
67 import java.util.Hashtable;
68 import java.util.LinkedHashMap;
69 import java.util.List;
71 import java.util.Objects;
72 import java.util.SortedMap;
73 import java.util.TreeMap;
74 import java.util.Vector;
76 import javax.swing.ButtonGroup;
77 import javax.swing.JCheckBoxMenuItem;
78 import javax.swing.JColorChooser;
79 import javax.swing.JMenu;
80 import javax.swing.JMenuItem;
81 import javax.swing.JPopupMenu;
82 import javax.swing.JRadioButtonMenuItem;
85 * The popup menu that is displayed on right-click on a sequence id, or in the
88 public class PopupMenu extends JPopupMenu implements ColourChangeListener
91 * true for ID Panel menu, false for alignment panel menu
93 private final boolean forIdPanel;
95 private final AlignmentPanel ap;
98 * the sequence under the cursor when clicked
99 * (additional sequences may be selected)
101 private final SequenceI sequence;
103 JMenu groupMenu = new JMenu();
105 JMenuItem groupName = new JMenuItem();
107 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
109 protected JMenuItem modifyPID = new JMenuItem();
111 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
113 protected JRadioButtonMenuItem annotationColour;
115 protected JMenuItem modifyConservation = new JMenuItem();
117 JMenu sequenceMenu = new JMenu();
119 JMenuItem makeReferenceSeq = new JMenuItem();
121 JMenuItem createGroupMenuItem = new JMenuItem();
123 JMenuItem unGroupMenuItem = new JMenuItem();
125 JMenu colourMenu = new JMenu();
127 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
129 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
131 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
133 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
135 JMenu editMenu = new JMenu();
137 JMenuItem upperCase = new JMenuItem();
139 JMenuItem lowerCase = new JMenuItem();
141 JMenuItem toggle = new JMenuItem();
143 JMenu outputMenu = new JMenu();
145 JMenu seqShowAnnotationsMenu = new JMenu();
147 JMenu seqHideAnnotationsMenu = new JMenu();
149 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
150 MessageManager.getString("label.add_reference_annotations"));
152 JMenu groupShowAnnotationsMenu = new JMenu();
154 JMenu groupHideAnnotationsMenu = new JMenu();
156 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
157 MessageManager.getString("label.add_reference_annotations"));
159 JMenuItem textColour = new JMenuItem();
161 JMenu editGroupMenu = new JMenu();
163 JMenuItem chooseStructure = new JMenuItem();
165 JMenu rnaStructureMenu = new JMenu();
168 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
169 * and/or features provided. Hyperlinks may include a lookup by sequence id,
170 * or database cross-references, depending on which links are enabled in user
177 protected static JMenu buildLinkMenu(final SequenceI seq,
178 List<SequenceFeature> features)
180 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
182 List<String> nlinks = null;
185 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
186 UrlLink.sort(nlinks);
190 nlinks = new ArrayList<>();
193 if (features != null)
195 for (SequenceFeature sf : features)
197 if (sf.links != null)
199 for (String link : sf.links)
208 * instantiate the hyperlinklink templates from sequence data;
209 * note the order of the templates is preserved in the map
211 Map<String, List<String>> linkset = new LinkedHashMap<>();
212 for (String link : nlinks)
214 UrlLink urlLink = null;
217 urlLink = new UrlLink(link);
218 } catch (Exception foo)
220 Cache.log.error("Exception for URLLink '" + link + "'", foo);
224 if (!urlLink.isValid())
226 Cache.log.error(urlLink.getInvalidMessage());
230 urlLink.createLinksFromSeq(seq, linkset);
234 * construct menu items for the hyperlinks (still preserving
235 * the order of the sorted templates)
237 addUrlLinks(linkMenu, linkset.values());
243 * A helper method that builds menu items from the given links, with action
244 * handlers to open the link URL, and adds them to the linkMenu. Each provided
245 * link should be a list whose second item is the menu text, and whose fourth
246 * item is the URL to open when the menu item is selected.
251 static private void addUrlLinks(JMenu linkMenu,
252 Collection<List<String>> linkset)
254 for (List<String> linkstrset : linkset)
256 final String url = linkstrset.get(3);
257 JMenuItem item = new JMenuItem(linkstrset.get(1));
258 item.setToolTipText(MessageManager
259 .formatMessage("label.open_url_param", new Object[]
261 item.addActionListener(new ActionListener()
264 public void actionPerformed(ActionEvent e)
266 new Thread(new Runnable()
281 * Opens the provided url in the default web browser, or shows an error
282 * message if this fails
286 static void showLink(String url)
290 jalview.util.BrowserLauncher.openURL(url);
291 } catch (Exception ex)
293 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
294 MessageManager.getString("label.web_browser_not_found_unix"),
295 MessageManager.getString("label.web_browser_not_found"),
296 JvOptionPane.WARNING_MESSAGE);
298 ex.printStackTrace();
303 * add a late bound groupURL item to the given linkMenu
307 * - menu label string
308 * @param urlgenerator
309 * GroupURLLink used to generate URL
311 * Object array returned from the makeUrlStubs function.
313 static void addshowLink(JMenu linkMenu, String label,
314 final GroupUrlLink urlgenerator, final Object[] urlstub)
316 JMenuItem item = new JMenuItem(label);
317 item.setToolTipText(MessageManager
318 .formatMessage("label.open_url_seqs_param", new Object[]
319 { urlgenerator.getUrl_prefix(),
320 urlgenerator.getNumberInvolved(urlstub) }));
321 // TODO: put in info about what is being sent.
322 item.addActionListener(new ActionListener()
325 public void actionPerformed(ActionEvent e)
327 new Thread(new Runnable()
335 showLink(urlgenerator.constructFrom(urlstub));
336 } catch (UrlStringTooLongException e2)
349 * Constructor for a PopupMenu for a click in the alignment panel (on a residue)
352 * the panel in which the mouse is clicked
354 * the sequence under the mouse
355 * @throws NullPointerException
358 public PopupMenu(final AlignmentPanel ap, SequenceI seq, int column)
360 this(false, ap, seq, column, null);
364 * Constructor for a PopupMenu for a click in the sequence id panel
367 * the panel in which the mouse is clicked
369 * the sequence under the mouse click
371 * templates for sequence external links
372 * @throws NullPointerException
375 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
376 List<String> groupLinks)
378 this(true, alignPanel, seq, -1, groupLinks);
382 * Private constructor that constructs a popup menu for either sequence ID
383 * Panel, or alignment context
389 * aligned column position (0...)
392 private PopupMenu(boolean fromIdPanel,
393 final AlignmentPanel alignPanel,
394 final SequenceI seq, final int column, List<String> groupLinks)
396 Objects.requireNonNull(seq);
397 this.forIdPanel = fromIdPanel;
398 this.ap = alignPanel;
401 for (String ff : FileFormats.getInstance().getWritableFormats(true))
403 JMenuItem item = new JMenuItem(ff);
405 item.addActionListener(new ActionListener()
408 public void actionPerformed(ActionEvent e)
410 outputText_actionPerformed(e);
414 outputMenu.add(item);
418 * Build menus for annotation types that may be shown or hidden, and for
419 * 'reference annotations' that may be added to the alignment. First for the
420 * currently selected sequence (if there is one):
422 final List<SequenceI> selectedSequence = (forIdPanel && seq != null
424 : Collections.<SequenceI> emptyList());
425 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
426 seqHideAnnotationsMenu, selectedSequence);
427 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
431 * And repeat for the current selection group (if there is one):
433 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
434 ? Collections.<SequenceI> emptyList()
435 : alignPanel.av.getSelectionGroup().getSequences());
436 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
437 groupHideAnnotationsMenu, selectedGroup);
438 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
444 } catch (Exception e)
452 sequenceMenu.setText(sequence.getName());
453 if (seq == alignPanel.av.getAlignment().getSeqrep())
455 makeReferenceSeq.setText(
456 MessageManager.getString("action.unmark_as_reference"));
460 makeReferenceSeq.setText(
461 MessageManager.getString("action.set_as_reference"));
464 if (!alignPanel.av.getAlignment().isNucleotide())
466 remove(rnaStructureMenu);
470 int origCount = rnaStructureMenu.getItemCount();
472 * add menu items to 2D-render any alignment or sequence secondary
473 * structure annotation
475 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
476 .getAlignmentAnnotation();
479 for (final AlignmentAnnotation aa : aas)
481 if (aa.isValidStruc() && aa.sequenceRef == null)
484 * valid alignment RNA secondary structure annotation
486 menuItem = new JMenuItem();
487 menuItem.setText(MessageManager.formatMessage(
488 "label.2d_rna_structure_line", new Object[]
490 menuItem.addActionListener(new ActionListener()
493 public void actionPerformed(ActionEvent e)
495 new AppVarna(seq, aa, alignPanel);
498 rnaStructureMenu.add(menuItem);
503 if (seq.getAnnotation() != null)
505 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
506 for (final AlignmentAnnotation aa : seqAnns)
508 if (aa.isValidStruc())
511 * valid sequence RNA secondary structure annotation
513 // TODO: make rnastrucF a bit more nice
514 menuItem = new JMenuItem();
515 menuItem.setText(MessageManager.formatMessage(
516 "label.2d_rna_sequence_name", new Object[]
518 menuItem.addActionListener(new ActionListener()
521 public void actionPerformed(ActionEvent e)
523 // TODO: VARNA does'nt print gaps in the sequence
524 new AppVarna(seq, aa, alignPanel);
527 rnaStructureMenu.add(menuItem);
531 if (rnaStructureMenu.getItemCount() == origCount)
533 remove(rnaStructureMenu);
537 menuItem = new JMenuItem(
538 MessageManager.getString("action.hide_sequences"));
539 menuItem.addActionListener(new ActionListener()
542 public void actionPerformed(ActionEvent e)
544 hideSequences(false);
549 if (alignPanel.av.getSelectionGroup() != null
550 && alignPanel.av.getSelectionGroup().getSize() > 1)
552 menuItem = new JMenuItem(MessageManager
553 .formatMessage("label.represent_group_with", new Object[]
555 menuItem.addActionListener(new ActionListener()
558 public void actionPerformed(ActionEvent e)
563 sequenceMenu.add(menuItem);
566 if (alignPanel.av.hasHiddenRows())
568 final int index = alignPanel.av.getAlignment().findIndex(seq);
570 if (alignPanel.av.adjustForHiddenSeqs(index)
571 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
573 menuItem = new JMenuItem(
574 MessageManager.getString("action.reveal_sequences"));
575 menuItem.addActionListener(new ActionListener()
578 public void actionPerformed(ActionEvent e)
580 alignPanel.av.showSequence(index);
581 if (alignPanel.overviewPanel != null)
583 alignPanel.overviewPanel.updateOverviewImage();
594 * - in the IdPanel (seq not null) if any sequence is hidden
595 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
597 if (alignPanel.av.hasHiddenRows())
599 boolean addOption = seq != null;
600 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
606 JMenuItem menuItem = new JMenuItem(
607 MessageManager.getString("action.reveal_all"));
608 menuItem.addActionListener(new ActionListener()
611 public void actionPerformed(ActionEvent e)
613 alignPanel.av.showAllHiddenSeqs();
614 if (alignPanel.overviewPanel != null)
616 alignPanel.overviewPanel.updateOverviewImage();
624 SequenceGroup sg = alignPanel.av.getSelectionGroup();
625 boolean isDefinedGroup = (sg != null)
626 ? alignPanel.av.getAlignment().getGroups().contains(sg)
629 if (sg != null && sg.getSize() > 0)
631 groupName.setText(MessageManager
632 .getString("label.edit_name_and_description_current_group"));
634 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
636 conservationMenuItem.setEnabled(!sg.isNucleotide());
640 if (sg.cs.conservationApplied())
642 conservationMenuItem.setSelected(true);
644 if (sg.cs.getThreshold() > 0)
646 abovePIDColour.setSelected(true);
649 modifyConservation.setEnabled(conservationMenuItem.isSelected());
650 modifyPID.setEnabled(abovePIDColour.isSelected());
651 displayNonconserved.setSelected(sg.getShowNonconserved());
652 showText.setSelected(sg.getDisplayText());
653 showColourText.setSelected(sg.getColourText());
654 showBoxes.setSelected(sg.getDisplayBoxes());
655 // add any groupURLs to the groupURL submenu and make it visible
656 if (groupLinks != null && groupLinks.size() > 0)
658 buildGroupURLMenu(sg, groupLinks);
660 // Add a 'show all structures' for the current selection
661 Hashtable<String, PDBEntry> pdbe = new Hashtable<>(), reppdb = new Hashtable<>();
663 SequenceI sqass = null;
664 for (SequenceI sq : alignPanel.av.getSequenceSelection())
666 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
667 if (pes != null && pes.size() > 0)
669 reppdb.put(pes.get(0).getId(), pes.get(0));
670 for (PDBEntry pe : pes)
672 pdbe.put(pe.getId(), pe);
682 final PDBEntry[] pe = pdbe.values()
683 .toArray(new PDBEntry[pdbe.size()]),
684 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
685 final JMenuItem gpdbview, rpdbview;
690 groupMenu.setVisible(false);
691 editMenu.setVisible(false);
696 createGroupMenuItem.setVisible(true);
697 unGroupMenuItem.setVisible(false);
698 editGroupMenu.setText(MessageManager.getString("action.edit_new_group"));
702 createGroupMenuItem.setVisible(false);
703 unGroupMenuItem.setVisible(true);
704 editGroupMenu.setText(MessageManager.getString("action.edit_group"));
709 sequenceMenu.setVisible(false);
710 chooseStructure.setVisible(false);
711 rnaStructureMenu.setVisible(false);
714 addLinksAndFeatures(seq, column);
720 * <li>configured sequence database links (ID panel popup menu)</li>
721 * <li>non-positional feature links (ID panel popup menu)</li>
722 * <li>positional feature links (alignment panel popup menu)</li>
723 * <li>feature details links (alignment panel popup menu)</li>
725 * If this panel is also showed complementary (CDS/protein) features, then links
726 * to their feature details are also added.
731 void addLinksAndFeatures(final SequenceI seq, final int column)
733 List<SequenceFeature> features = null;
736 features = sequence.getFeatures().getNonPositionalFeatures();
740 features = ap.getFeatureRenderer().findFeaturesAtColumn(sequence,
744 addLinks(seq, features);
748 addFeatureDetails(features, seq, column);
753 * Add a link to show feature details for each sequence feature
759 protected void addFeatureDetails(List<SequenceFeature> features,
760 SequenceI seq, int column)
763 * add features in CDS/protein complement at the corresponding
764 * position if configured to do so
766 MappedFeatures mf = null;
767 if (ap.av.isShowComplementFeatures())
769 if (!Comparison.isGap(sequence.getCharAt(column)))
771 AlignViewportI complement = ap.getAlignViewport()
772 .getCodingComplement();
773 AlignFrame af = Desktop.getAlignFrameFor(complement);
774 FeatureRendererModel fr2 = af.getFeatureRenderer();
775 int seqPos = sequence.findPosition(column);
776 mf = fr2.findComplementFeaturesAtResidue(sequence, seqPos);
780 if (features.isEmpty() && mf == null)
783 * no features to show at this position
788 JMenu details = new JMenu(
789 MessageManager.getString("label.feature_details"));
792 String name = seq.getName();
793 for (final SequenceFeature sf : features)
795 addFeatureDetailsMenuItem(details, name, sf);
800 name = mf.fromSeq == seq ? mf.mapping.getTo().getName()
801 : mf.fromSeq.getName();
802 for (final SequenceFeature sf : mf.features)
804 addFeatureDetailsMenuItem(details, name, sf);
810 * A helper method to add one menu item whose action is to show details for one
817 void addFeatureDetailsMenuItem(JMenu details, final String seqName,
818 final SequenceFeature sf)
820 int start = sf.getBegin();
821 int end = sf.getEnd();
825 desc = String.format("%s %d", sf.getType(), start);
829 desc = String.format("%s %d-%d", sf.getType(), start, end);
831 String tooltip = desc;
832 String description = sf.getDescription();
833 if (description != null)
835 description = StringUtils.stripHtmlTags(description);
836 if (description.length() > 12)
838 desc = desc + " " + description.substring(0, 12) + "..";
842 desc = desc + " " + description;
844 tooltip = tooltip + " " + description;
846 if (sf.getFeatureGroup() != null)
848 tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
850 JMenuItem item = new JMenuItem(desc);
851 item.setToolTipText(tooltip);
852 item.addActionListener(new ActionListener()
855 public void actionPerformed(ActionEvent e)
857 showFeatureDetails(seqName, sf);
864 * Opens a panel showing a text report of feature dteails
870 protected void showFeatureDetails(String seqName, SequenceFeature sf)
872 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
873 // it appears Java's CSS does not support border-collapse :-(
874 cap.addStylesheetRule("table { border-collapse: collapse;}");
875 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
876 cap.setText(sf.getDetailsReport(seqName));
878 Desktop.addInternalFrame(cap,
879 MessageManager.getString("label.feature_details"), 500, 500);
883 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
884 * When seq is not null, these are links for the sequence id, which may be to
885 * external web sites for the sequence accession, and/or links embedded in
886 * non-positional features. When seq is null, only links embedded in the
887 * provided features are added. If no links are found, the menu is not added.
892 void addLinks(final SequenceI seq, List<SequenceFeature> features)
894 JMenu linkMenu = buildLinkMenu(forIdPanel ? seq : null, features);
896 // only add link menu if it has entries
897 if (linkMenu.getItemCount() > 0)
901 sequenceMenu.add(linkMenu);
911 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
912 * "All" is added first, followed by a separator. Then add any annotation
913 * types associated with the current selection. Separate menus are built for
914 * the selected sequence group (if any), and the selected sequence.
916 * Some annotation rows are always rendered together - these can be identified
917 * by a common graphGroup property > -1. Only one of each group will be marked
918 * as visible (to avoid duplication of the display). For such groups we add a
919 * composite type name, e.g.
921 * IUPredWS (Long), IUPredWS (Short)
925 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
926 List<SequenceI> forSequences)
928 showMenu.removeAll();
929 hideMenu.removeAll();
931 final List<String> all = Arrays
933 { MessageManager.getString("label.all") });
934 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
936 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
938 showMenu.addSeparator();
939 hideMenu.addSeparator();
941 final AlignmentAnnotation[] annotations = ap.getAlignment()
942 .getAlignmentAnnotation();
945 * Find shown/hidden annotations types, distinguished by source (calcId),
946 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
947 * the insertion order, which is the order of the annotations on the
950 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
951 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
952 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
953 AlignmentAnnotationUtils.asList(annotations), forSequences);
955 for (String calcId : hiddenTypes.keySet())
957 for (List<String> type : hiddenTypes.get(calcId))
959 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
963 // grey out 'show annotations' if none are hidden
964 showMenu.setEnabled(!hiddenTypes.isEmpty());
966 for (String calcId : shownTypes.keySet())
968 for (List<String> type : shownTypes.get(calcId))
970 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
974 // grey out 'hide annotations' if none are shown
975 hideMenu.setEnabled(!shownTypes.isEmpty());
979 * Returns a list of sequences - either the current selection group (if there
980 * is one), else the specified single sequence.
985 protected List<SequenceI> getSequenceScope(SequenceI seq)
987 List<SequenceI> forSequences = null;
988 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
989 if (selectionGroup != null && selectionGroup.getSize() > 0)
991 forSequences = selectionGroup.getSequences();
995 forSequences = seq == null ? Collections.<SequenceI> emptyList()
996 : Arrays.asList(seq);
1002 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1005 * @param showOrHideMenu
1006 * the menu to add to
1007 * @param forSequences
1008 * the sequences whose annotations may be shown or hidden
1013 * if true this is a special label meaning 'All'
1014 * @param actionIsShow
1015 * if true, the select menu item action is to show the annotation
1018 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
1019 final List<SequenceI> forSequences, String calcId,
1020 final List<String> types, final boolean allTypes,
1021 final boolean actionIsShow)
1023 String label = types.toString(); // [a, b, c]
1024 label = label.substring(1, label.length() - 1); // a, b, c
1025 final JMenuItem item = new JMenuItem(label);
1026 item.setToolTipText(calcId);
1027 item.addActionListener(new ActionListener()
1030 public void actionPerformed(ActionEvent e)
1032 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1033 types, forSequences, allTypes, actionIsShow);
1037 showOrHideMenu.add(item);
1040 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
1043 // TODO: usability: thread off the generation of group url content so root
1044 // menu appears asap
1045 // sequence only URLs
1046 // ID/regex match URLs
1047 JMenu groupLinksMenu = new JMenu(
1048 MessageManager.getString("action.group_link"));
1049 // three types of url that might be created.
1050 JMenu[] linkMenus = new JMenu[] { null,
1051 new JMenu(MessageManager.getString("action.ids")),
1052 new JMenu(MessageManager.getString("action.sequences")),
1053 new JMenu(MessageManager.getString("action.ids_sequences")) };
1055 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1056 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1057 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
1058 for (int sq = 0; sq < seqs.length; sq++)
1061 int start = seqs[sq].findPosition(sg.getStartRes()),
1062 end = seqs[sq].findPosition(sg.getEndRes());
1063 // just collect ids from dataset sequence
1064 // TODO: check if IDs collected from selecton group intersects with the
1065 // current selection, too
1066 SequenceI sqi = seqs[sq];
1067 while (sqi.getDatasetSequence() != null)
1069 sqi = sqi.getDatasetSequence();
1071 DBRefEntry[] dbr = sqi.getDBRefs();
1072 if (dbr != null && dbr.length > 0)
1074 for (int d = 0; d < dbr.length; d++)
1076 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1077 Object[] sarray = commonDbrefs.get(src);
1080 sarray = new Object[2];
1081 sarray[0] = new int[] { 0 };
1082 sarray[1] = new String[seqs.length];
1084 commonDbrefs.put(src, sarray);
1087 if (((String[]) sarray[1])[sq] == null)
1089 if (!dbr[d].hasMap() || (dbr[d].getMap()
1090 .locateMappedRange(start, end) != null))
1092 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1093 ((int[]) sarray[0])[0]++;
1099 // now create group links for all distinct ID/sequence sets.
1100 boolean addMenu = false; // indicates if there are any group links to give
1102 for (String link : groupLinks)
1104 GroupUrlLink urlLink = null;
1107 urlLink = new GroupUrlLink(link);
1108 } catch (Exception foo)
1110 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
1114 if (!urlLink.isValid())
1116 Cache.log.error(urlLink.getInvalidMessage());
1119 final String label = urlLink.getLabel();
1120 boolean usingNames = false;
1121 // Now see which parts of the group apply for this URL
1122 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1123 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
1124 String[] seqstr, ids; // input to makeUrl
1127 int numinput = ((int[]) idset[0])[0];
1128 String[] allids = ((String[]) idset[1]);
1129 seqstr = new String[numinput];
1130 ids = new String[numinput];
1131 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1133 if (allids[sq] != null)
1135 ids[idcount] = allids[sq];
1136 seqstr[idcount++] = idandseqs[1][sq];
1142 // just use the id/seq set
1143 seqstr = idandseqs[1];
1147 // and try and make the groupURL!
1149 Object[] urlset = null;
1152 urlset = urlLink.makeUrlStubs(ids, seqstr,
1153 "FromJalview" + System.currentTimeMillis(), false);
1154 } catch (UrlStringTooLongException e)
1159 int type = urlLink.getGroupURLType() & 3;
1160 // first two bits ofurlLink type bitfield are sequenceids and sequences
1161 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1162 addshowLink(linkMenus[type],
1163 label + (((type & 1) == 1)
1164 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1172 groupLinksMenu = new JMenu(
1173 MessageManager.getString("action.group_link"));
1174 for (int m = 0; m < linkMenus.length; m++)
1176 if (linkMenus[m] != null
1177 && linkMenus[m].getMenuComponentCount() > 0)
1179 groupLinksMenu.add(linkMenus[m]);
1183 groupMenu.add(groupLinksMenu);
1193 private void jbInit() throws Exception
1195 groupMenu.setText(MessageManager.getString("label.selection"));
1196 groupName.setText(MessageManager.getString("label.name"));
1197 groupName.addActionListener(new ActionListener()
1200 public void actionPerformed(ActionEvent e)
1202 groupName_actionPerformed();
1205 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1207 JMenuItem sequenceName = new JMenuItem(
1208 MessageManager.getString("label.edit_name_description"));
1209 sequenceName.addActionListener(new ActionListener()
1212 public void actionPerformed(ActionEvent e)
1214 sequenceName_actionPerformed();
1217 JMenuItem chooseAnnotations = new JMenuItem(
1218 MessageManager.getString("action.choose_annotations"));
1219 chooseAnnotations.addActionListener(new ActionListener()
1222 public void actionPerformed(ActionEvent e)
1224 chooseAnnotations_actionPerformed(e);
1227 JMenuItem sequenceDetails = new JMenuItem(
1228 MessageManager.getString("label.sequence_details"));
1229 sequenceDetails.addActionListener(new ActionListener()
1232 public void actionPerformed(ActionEvent e)
1234 createSequenceDetailsReport(new SequenceI[] { sequence });
1237 JMenuItem sequenceSelDetails = new JMenuItem(
1238 MessageManager.getString("label.sequence_details"));
1239 sequenceSelDetails.addActionListener(new ActionListener()
1242 public void actionPerformed(ActionEvent e)
1244 createSequenceDetailsReport(ap.av.getSequenceSelection());
1249 .setText(MessageManager.getString("action.remove_group"));
1250 unGroupMenuItem.addActionListener(new ActionListener()
1253 public void actionPerformed(ActionEvent e)
1255 unGroupMenuItem_actionPerformed();
1259 .setText(MessageManager.getString("action.create_group"));
1260 createGroupMenuItem.addActionListener(new ActionListener()
1263 public void actionPerformed(ActionEvent e)
1265 createGroupMenuItem_actionPerformed();
1269 JMenuItem outline = new JMenuItem(
1270 MessageManager.getString("action.border_colour"));
1271 outline.addActionListener(new ActionListener()
1274 public void actionPerformed(ActionEvent e)
1276 outline_actionPerformed();
1279 showBoxes.setText(MessageManager.getString("action.boxes"));
1280 showBoxes.setState(true);
1281 showBoxes.addActionListener(new ActionListener()
1284 public void actionPerformed(ActionEvent e)
1286 showBoxes_actionPerformed();
1289 showText.setText(MessageManager.getString("action.text"));
1290 showText.setState(true);
1291 showText.addActionListener(new ActionListener()
1294 public void actionPerformed(ActionEvent e)
1296 showText_actionPerformed();
1299 showColourText.setText(MessageManager.getString("label.colour_text"));
1300 showColourText.addActionListener(new ActionListener()
1303 public void actionPerformed(ActionEvent e)
1305 showColourText_actionPerformed();
1309 .setText(MessageManager.getString("label.show_non_conserved"));
1310 displayNonconserved.setState(true);
1311 displayNonconserved.addActionListener(new ActionListener()
1314 public void actionPerformed(ActionEvent e)
1316 showNonconserved_actionPerformed();
1319 editMenu.setText(MessageManager.getString("action.edit"));
1320 JMenuItem cut = new JMenuItem(MessageManager.getString("action.cut"));
1321 cut.addActionListener(new ActionListener()
1324 public void actionPerformed(ActionEvent e)
1326 cut_actionPerformed();
1329 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1330 upperCase.addActionListener(new ActionListener()
1333 public void actionPerformed(ActionEvent e)
1338 JMenuItem copy = new JMenuItem(MessageManager.getString("action.copy"));
1339 copy.addActionListener(new ActionListener()
1342 public void actionPerformed(ActionEvent e)
1344 copy_actionPerformed();
1347 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1348 lowerCase.addActionListener(new ActionListener()
1351 public void actionPerformed(ActionEvent e)
1356 toggle.setText(MessageManager.getString("label.toggle_case"));
1357 toggle.addActionListener(new ActionListener()
1360 public void actionPerformed(ActionEvent e)
1366 MessageManager.getString("label.out_to_textbox") + "...");
1367 seqShowAnnotationsMenu
1368 .setText(MessageManager.getString("label.show_annotations"));
1369 seqHideAnnotationsMenu
1370 .setText(MessageManager.getString("label.hide_annotations"));
1371 groupShowAnnotationsMenu
1372 .setText(MessageManager.getString("label.show_annotations"));
1373 groupHideAnnotationsMenu
1374 .setText(MessageManager.getString("label.hide_annotations"));
1375 JMenuItem sequenceFeature = new JMenuItem(
1376 MessageManager.getString("label.create_sequence_feature"));
1377 sequenceFeature.addActionListener(new ActionListener()
1380 public void actionPerformed(ActionEvent e)
1382 sequenceFeature_actionPerformed();
1385 editGroupMenu.setText(MessageManager.getString("label.group"));
1386 chooseStructure.setText(
1387 MessageManager.getString("label.show_pdbstruct_dialog"));
1388 chooseStructure.addActionListener(new ActionListener()
1391 public void actionPerformed(ActionEvent actionEvent)
1393 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1394 if (ap.av.getSelectionGroup() != null)
1396 selectedSeqs = ap.av.getSequenceSelection();
1398 new StructureChooser(selectedSeqs, sequence, ap);
1403 .setText(MessageManager.getString("label.view_rna_structure"));
1405 // colStructureMenu.setText("Colour By Structure");
1406 JMenuItem editSequence = new JMenuItem(
1407 MessageManager.getString("label.edit_sequence") + "...");
1408 editSequence.addActionListener(new ActionListener()
1411 public void actionPerformed(ActionEvent actionEvent)
1413 editSequence_actionPerformed(actionEvent);
1416 makeReferenceSeq.setText(
1417 MessageManager.getString("label.mark_as_representative"));
1418 makeReferenceSeq.addActionListener(new ActionListener()
1422 public void actionPerformed(ActionEvent actionEvent)
1424 makeReferenceSeq_actionPerformed(actionEvent);
1429 groupMenu.add(sequenceSelDetails);
1432 add(rnaStructureMenu);
1433 add(chooseStructure);
1436 JMenuItem hideInsertions = new JMenuItem(
1437 MessageManager.getString("label.hide_insertions"));
1438 hideInsertions.addActionListener(new ActionListener()
1442 public void actionPerformed(ActionEvent e)
1444 hideInsertions_actionPerformed(e);
1447 add(hideInsertions);
1449 // annotations configuration panel suppressed for now
1450 // groupMenu.add(chooseAnnotations);
1453 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1454 * (if a selection group is in force).
1456 sequenceMenu.add(seqShowAnnotationsMenu);
1457 sequenceMenu.add(seqHideAnnotationsMenu);
1458 sequenceMenu.add(seqAddReferenceAnnotations);
1459 groupMenu.add(groupShowAnnotationsMenu);
1460 groupMenu.add(groupHideAnnotationsMenu);
1461 groupMenu.add(groupAddReferenceAnnotations);
1462 groupMenu.add(editMenu);
1463 groupMenu.add(outputMenu);
1464 groupMenu.add(sequenceFeature);
1465 groupMenu.add(createGroupMenuItem);
1466 groupMenu.add(unGroupMenuItem);
1467 groupMenu.add(editGroupMenu);
1468 sequenceMenu.add(sequenceName);
1469 sequenceMenu.add(sequenceDetails);
1470 sequenceMenu.add(makeReferenceSeq);
1477 editMenu.add(editSequence);
1478 editMenu.add(upperCase);
1479 editMenu.add(lowerCase);
1480 editMenu.add(toggle);
1481 editGroupMenu.add(groupName);
1482 editGroupMenu.add(colourMenu);
1483 editGroupMenu.add(showBoxes);
1484 editGroupMenu.add(showText);
1485 editGroupMenu.add(showColourText);
1486 editGroupMenu.add(outline);
1487 editGroupMenu.add(displayNonconserved);
1491 * Constructs the entries for the colour menu
1493 protected void initColourMenu()
1495 colourMenu.setText(MessageManager.getString("label.group_colour"));
1496 textColour.setText(MessageManager.getString("label.text_colour"));
1497 textColour.addActionListener(new ActionListener()
1500 public void actionPerformed(ActionEvent e)
1502 textColour_actionPerformed();
1506 abovePIDColour.setText(
1507 MessageManager.getString("label.above_identity_threshold"));
1508 abovePIDColour.addActionListener(new ActionListener()
1511 public void actionPerformed(ActionEvent e)
1513 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1518 MessageManager.getString("label.modify_identity_threshold"));
1519 modifyPID.addActionListener(new ActionListener()
1522 public void actionPerformed(ActionEvent e)
1524 modifyPID_actionPerformed();
1528 conservationMenuItem
1529 .setText(MessageManager.getString("action.by_conservation"));
1530 conservationMenuItem.addActionListener(new ActionListener()
1533 public void actionPerformed(ActionEvent e)
1535 conservationMenuItem_actionPerformed(
1536 conservationMenuItem.isSelected());
1540 annotationColour = new JRadioButtonMenuItem(
1541 MessageManager.getString("action.by_annotation"));
1542 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1543 annotationColour.setEnabled(false);
1544 annotationColour.setToolTipText(
1545 MessageManager.getString("label.by_annotation_tooltip"));
1547 modifyConservation.setText(MessageManager
1548 .getString("label.modify_conservation_threshold"));
1549 modifyConservation.addActionListener(new ActionListener()
1552 public void actionPerformed(ActionEvent e)
1554 modifyConservation_actionPerformed();
1560 * Builds the group colour sub-menu, including any user-defined colours which
1561 * were loaded at startup or during the Jalview session
1563 protected void buildColourMenu()
1565 SequenceGroup sg = ap.av.getSelectionGroup();
1569 * popup menu with no sequence group scope
1573 colourMenu.removeAll();
1574 colourMenu.add(textColour);
1575 colourMenu.addSeparator();
1577 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1579 bg.add(annotationColour);
1580 colourMenu.add(annotationColour);
1582 colourMenu.addSeparator();
1583 colourMenu.add(conservationMenuItem);
1584 colourMenu.add(modifyConservation);
1585 colourMenu.add(abovePIDColour);
1586 colourMenu.add(modifyPID);
1589 protected void modifyConservation_actionPerformed()
1591 SequenceGroup sg = getGroup();
1594 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1595 SliderPanel.showConservationSlider();
1599 protected void modifyPID_actionPerformed()
1601 SequenceGroup sg = getGroup();
1604 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1606 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1607 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1608 SliderPanel.showPIDSlider();
1613 * Check for any annotations on the underlying dataset sequences (for the
1614 * current selection group) which are not 'on the alignment'.If any are found,
1615 * enable the option to add them to the alignment. The criteria for 'on the
1616 * alignment' is finding an alignment annotation on the alignment, matched on
1617 * calcId, label and sequenceRef.
1619 * A tooltip is also constructed that displays the source (calcId) and type
1620 * (label) of the annotations that can be added.
1623 * @param forSequences
1625 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1626 List<SequenceI> forSequences)
1628 menuItem.setEnabled(false);
1631 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1632 * Using TreeMap means calcIds are shown in alphabetical order.
1634 SortedMap<String, String> tipEntries = new TreeMap<>();
1635 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1636 AlignmentI al = this.ap.av.getAlignment();
1637 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1639 if (!candidates.isEmpty())
1641 StringBuilder tooltip = new StringBuilder(64);
1642 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1645 * Found annotations that could be added. Enable the menu item, and
1646 * configure its tooltip and action.
1648 menuItem.setEnabled(true);
1649 for (String calcId : tipEntries.keySet())
1651 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1653 String tooltipText = JvSwingUtils.wrapTooltip(true,
1654 tooltip.toString());
1655 menuItem.setToolTipText(tooltipText);
1657 menuItem.addActionListener(new ActionListener()
1660 public void actionPerformed(ActionEvent e)
1662 addReferenceAnnotations_actionPerformed(candidates);
1669 * Add annotations to the sequences and to the alignment.
1672 * a map whose keys are sequences on the alignment, and values a list
1673 * of annotations to add to each sequence
1675 protected void addReferenceAnnotations_actionPerformed(
1676 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1678 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1679 final AlignmentI alignment = this.ap.getAlignment();
1680 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1685 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1687 if (!ap.av.getAlignment().hasSeqrep())
1689 // initialise the display flags so the user sees something happen
1690 ap.av.setDisplayReferenceSeq(true);
1691 ap.av.setColourByReferenceSeq(true);
1692 ap.av.getAlignment().setSeqrep(sequence);
1696 if (ap.av.getAlignment().getSeqrep() == sequence)
1698 ap.av.getAlignment().setSeqrep(null);
1702 ap.av.getAlignment().setSeqrep(sequence);
1708 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1710 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1711 BitSet inserts = new BitSet();
1713 boolean markedPopup = false;
1714 // mark inserts in current selection
1715 if (ap.av.getSelectionGroup() != null)
1717 // mark just the columns in the selection group to be hidden
1718 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1719 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1721 // now clear columns without gaps
1722 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1728 inserts.and(sq.getInsertionsAsBits());
1730 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1731 ap.av.getSelectionGroup().getEndRes());
1734 // now mark for sequence under popup if we haven't already done it
1735 else if (!markedPopup && sequence != null)
1737 inserts.or(sequence.getInsertionsAsBits());
1739 // and set hidden columns accordingly
1740 hidden.hideColumns(inserts);
1745 protected void sequenceSelectionDetails_actionPerformed()
1747 createSequenceDetailsReport(ap.av.getSequenceSelection());
1750 public void createSequenceDetailsReport(SequenceI[] sequences)
1752 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1753 StringBuilder contents = new StringBuilder(128);
1754 for (SequenceI seq : sequences)
1756 contents.append("<p><h2>" + MessageManager.formatMessage(
1757 "label.create_sequence_details_report_annotation_for",
1759 { seq.getDisplayId(true) }) + "</h2></p><p>");
1760 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
1761 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1762 contents.append("</p>");
1764 cap.setText("<html>" + contents.toString() + "</html>");
1766 Desktop.addInternalFrame(cap,
1767 MessageManager.formatMessage("label.sequence_details_for",
1768 (sequences.length == 1 ? new Object[]
1769 { sequences[0].getDisplayId(true) }
1772 .getString("label.selection") })),
1777 protected void showNonconserved_actionPerformed()
1779 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1784 * call to refresh view after settings change
1788 ap.updateAnnotation();
1789 // removed paintAlignment(true) here:
1790 // updateAnnotation calls paintAlignment already, so don't need to call
1793 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1797 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1798 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1808 public void abovePIDColour_actionPerformed(boolean selected)
1810 SequenceGroup sg = getGroup();
1818 sg.cs.setConsensus(AAFrequency.calculate(
1819 sg.getSequences(ap.av.getHiddenRepSequences()),
1820 sg.getStartRes(), sg.getEndRes() + 1));
1822 int threshold = SliderPanel.setPIDSliderSource(ap,
1823 sg.getGroupColourScheme(), getGroup().getName());
1825 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1827 SliderPanel.showPIDSlider();
1830 // remove PIDColouring
1832 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1833 SliderPanel.hidePIDSlider();
1835 modifyPID.setEnabled(selected);
1841 * Open a panel where the user can choose which types of sequence annotation
1846 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1848 // todo correct way to guard against opening a duplicate panel?
1849 new AnnotationChooser(ap);
1858 public void conservationMenuItem_actionPerformed(boolean selected)
1860 SequenceGroup sg = getGroup();
1868 // JBPNote: Conservation name shouldn't be i18n translated
1869 Conservation c = new Conservation("Group",
1870 sg.getSequences(ap.av.getHiddenRepSequences()),
1871 sg.getStartRes(), sg.getEndRes() + 1);
1874 c.verdict(false, ap.av.getConsPercGaps());
1875 sg.cs.setConservation(c);
1877 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1879 SliderPanel.showConservationSlider();
1882 // remove ConservationColouring
1884 sg.cs.setConservation(null);
1885 SliderPanel.hideConservationSlider();
1887 modifyConservation.setEnabled(selected);
1898 protected void groupName_actionPerformed()
1901 SequenceGroup sg = getGroup();
1902 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1903 sg.getDescription(),
1904 " " + MessageManager.getString("label.group_name") + " ",
1905 MessageManager.getString("label.group_description") + " ",
1906 MessageManager.getString("label.edit_group_name_description"),
1914 sg.setName(dialog.getName());
1915 sg.setDescription(dialog.getDescription());
1920 * Get selection group - adding it to the alignment if necessary.
1922 * @return sequence group to operate on
1924 SequenceGroup getGroup()
1926 SequenceGroup sg = ap.av.getSelectionGroup();
1927 // this method won't add a new group if it already exists
1930 ap.av.getAlignment().addGroup(sg);
1937 * Shows a dialog where the sequence name and description may be edited. If a
1938 * name containing spaces is entered, these are converted to underscores, with a
1941 void sequenceName_actionPerformed()
1943 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1944 sequence.getDescription(),
1945 " " + MessageManager.getString("label.sequence_name")
1947 MessageManager.getString("label.sequence_description") + " ",
1948 MessageManager.getString(
1949 "label.edit_sequence_name_description"),
1957 String name = dialog.getName();
1960 if (name.indexOf(" ") > -1)
1962 JvOptionPane.showMessageDialog(ap,
1964 .getString("label.spaces_converted_to_backslashes"),
1966 .getString("label.no_spaces_allowed_sequence_name"),
1967 JvOptionPane.WARNING_MESSAGE);
1968 name = name.replace(' ', '_');
1971 sequence.setName(name);
1972 ap.paintAlignment(false, false);
1975 sequence.setDescription(dialog.getDescription());
1977 ap.av.firePropertyChange("alignment", null,
1978 ap.av.getAlignment().getSequences());
1988 void unGroupMenuItem_actionPerformed()
1990 SequenceGroup sg = ap.av.getSelectionGroup();
1991 ap.av.getAlignment().deleteGroup(sg);
1992 ap.av.setSelectionGroup(null);
1996 void createGroupMenuItem_actionPerformed()
1998 getGroup(); // implicitly creates group - note - should apply defaults / use
1999 // standard alignment window logic for this
2009 protected void outline_actionPerformed()
2011 SequenceGroup sg = getGroup();
2012 Color col = JColorChooser.showDialog(this,
2013 MessageManager.getString("label.select_outline_colour"),
2018 sg.setOutlineColour(col);
2030 public void showBoxes_actionPerformed()
2032 getGroup().setDisplayBoxes(showBoxes.isSelected());
2042 public void showText_actionPerformed()
2044 getGroup().setDisplayText(showText.isSelected());
2054 public void showColourText_actionPerformed()
2056 getGroup().setColourText(showColourText.isSelected());
2060 void hideSequences(boolean representGroup)
2062 ap.av.hideSequences(sequence, representGroup);
2065 public void copy_actionPerformed()
2067 ap.alignFrame.copy_actionPerformed(null);
2070 public void cut_actionPerformed()
2072 ap.alignFrame.cut_actionPerformed(null);
2075 void changeCase(ActionEvent e)
2077 Object source = e.getSource();
2078 SequenceGroup sg = ap.av.getSelectionGroup();
2082 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2083 sg.getStartRes(), sg.getEndRes() + 1);
2088 if (source == toggle)
2090 description = MessageManager.getString("label.toggle_case");
2091 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2093 else if (source == upperCase)
2095 description = MessageManager.getString("label.to_upper_case");
2096 caseChange = ChangeCaseCommand.TO_UPPER;
2100 description = MessageManager.getString("label.to_lower_case");
2101 caseChange = ChangeCaseCommand.TO_LOWER;
2104 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2105 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2106 startEnd, caseChange);
2108 ap.alignFrame.addHistoryItem(caseCommand);
2110 ap.av.firePropertyChange("alignment", null,
2111 ap.av.getAlignment().getSequences());
2116 public void outputText_actionPerformed(ActionEvent e)
2118 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2119 cap.setForInput(null);
2120 Desktop.addInternalFrame(cap, MessageManager
2121 .formatMessage("label.alignment_output_command", new Object[]
2122 { e.getActionCommand() }), 600, 500);
2124 String[] omitHidden = null;
2126 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2127 // or we simply trust the user wants
2128 // wysiwig behaviour
2130 FileFormatI fileFormat = FileFormats.getInstance()
2131 .forName(e.getActionCommand());
2133 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2136 public void sequenceFeature_actionPerformed()
2138 SequenceGroup sg = ap.av.getSelectionGroup();
2144 List<SequenceI> seqs = new ArrayList<>();
2145 List<SequenceFeature> features = new ArrayList<>();
2148 * assemble dataset sequences, and template new sequence features,
2149 * for the amend features dialog
2151 int gSize = sg.getSize();
2152 for (int i = 0; i < gSize; i++)
2154 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2155 int end = sg.findEndRes(sg.getSequenceAt(i));
2158 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2159 features.add(new SequenceFeature(null, null, start, end, null));
2164 * an entirely gapped region will generate empty lists of sequence / features
2166 if (!seqs.isEmpty())
2168 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer()
2169 .amendFeatures(seqs, features, true, ap))
2171 ap.alignFrame.setShowSeqFeatures(true);
2172 ap.av.setSearchResults(null); // clear highlighting
2173 ap.repaint(); // draw new/amended features
2178 public void textColour_actionPerformed()
2180 SequenceGroup sg = getGroup();
2183 new TextColourChooser().chooseColour(ap, sg);
2187 public void editSequence_actionPerformed(ActionEvent actionEvent)
2189 SequenceGroup sg = ap.av.getSelectionGroup();
2191 SequenceI seq = sequence;
2196 seq = sg.getSequenceAt(0);
2199 EditNameDialog dialog = new EditNameDialog(
2200 seq.getSequenceAsString(sg.getStartRes(),
2201 sg.getEndRes() + 1),
2202 null, MessageManager.getString("label.edit_sequence"), null,
2203 MessageManager.getString("label.edit_sequence"),
2208 EditCommand editCommand = new EditCommand(
2209 MessageManager.getString("label.edit_sequences"),
2211 dialog.getName().replace(' ', ap.av.getGapCharacter()),
2212 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2213 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2215 ap.alignFrame.addHistoryItem(editCommand);
2217 ap.av.firePropertyChange("alignment", null,
2218 ap.av.getAlignment().getSequences());
2224 * Action on user selecting an item from the colour menu (that does not have
2225 * its bespoke action handler)
2230 public void changeColour_actionPerformed(String colourSchemeName)
2232 SequenceGroup sg = getGroup();
2234 * switch to the chosen colour scheme (or null for None)
2236 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2237 .getColourScheme(colourSchemeName, ap.av, sg,
2238 ap.av.getHiddenRepSequences());
2239 sg.setColourScheme(colourScheme);
2240 if (colourScheme instanceof Blosum62ColourScheme
2241 || colourScheme instanceof PIDColourScheme)
2243 sg.cs.setConsensus(AAFrequency.calculate(
2244 sg.getSequences(ap.av.getHiddenRepSequences()),
2245 sg.getStartRes(), sg.getEndRes() + 1));