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.bin.Cache;
28 import jalview.commands.ChangeCaseCommand;
29 import jalview.commands.EditCommand;
30 import jalview.commands.EditCommand.Action;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.Annotation;
34 import jalview.datamodel.DBRefEntry;
35 import jalview.datamodel.HiddenColumns;
36 import jalview.datamodel.PDBEntry;
37 import jalview.datamodel.SequenceFeature;
38 import jalview.datamodel.SequenceGroup;
39 import jalview.datamodel.SequenceI;
40 import jalview.gui.ColourMenuHelper.ColourChangeListener;
41 import jalview.gui.JalviewColourChooser.ColourChooserListener;
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.GroupUrlLink;
52 import jalview.util.GroupUrlLink.UrlStringTooLongException;
53 import jalview.util.MessageManager;
54 import jalview.util.Platform;
55 import jalview.util.StringUtils;
56 import jalview.util.UrlLink;
58 import java.awt.BorderLayout;
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.SortedMap;
72 import java.util.TreeMap;
73 import java.util.Vector;
75 import javax.swing.ButtonGroup;
76 import javax.swing.JCheckBoxMenuItem;
77 import javax.swing.JInternalFrame;
78 import javax.swing.JLabel;
79 import javax.swing.JMenu;
80 import javax.swing.JMenuItem;
81 import javax.swing.JPanel;
82 import javax.swing.JPopupMenu;
83 import javax.swing.JRadioButtonMenuItem;
84 import javax.swing.JScrollPane;
87 * The popup menu that is displayed on right-click on a sequence id, or in the
90 public class PopupMenu extends JPopupMenu implements ColourChangeListener
92 JMenu groupMenu = new JMenu();
94 JMenuItem groupName = new JMenuItem();
96 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
98 protected JMenuItem modifyPID = new JMenuItem();
100 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
102 protected JRadioButtonMenuItem annotationColour;
104 protected JMenuItem modifyConservation = new JMenuItem();
108 JMenu sequenceMenu = new JMenu();
110 JMenuItem sequenceName = new JMenuItem();
112 JMenuItem sequenceDetails = new JMenuItem();
114 JMenuItem sequenceSelDetails = new JMenuItem();
116 JMenuItem makeReferenceSeq = new JMenuItem();
118 JMenuItem chooseAnnotations = new JMenuItem();
122 JMenuItem createGroupMenuItem = new JMenuItem();
124 JMenuItem unGroupMenuItem = new JMenuItem();
126 JMenuItem outline = new JMenuItem();
128 JMenu colourMenu = new JMenu();
130 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
132 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
134 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
136 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
138 JMenu editMenu = new JMenu();
140 JMenuItem cut = new JMenuItem();
142 JMenuItem copy = new JMenuItem();
144 JMenuItem upperCase = new JMenuItem();
146 JMenuItem lowerCase = new JMenuItem();
148 JMenuItem toggle = new JMenuItem();
150 JMenu pdbMenu = new JMenu();
152 JMenu outputMenu = new JMenu();
154 JMenu seqShowAnnotationsMenu = new JMenu();
156 JMenu seqHideAnnotationsMenu = new JMenu();
158 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
159 MessageManager.getString("label.add_reference_annotations"));
161 JMenu groupShowAnnotationsMenu = new JMenu();
163 JMenu groupHideAnnotationsMenu = new JMenu();
165 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
166 MessageManager.getString("label.add_reference_annotations"));
168 JMenuItem sequenceFeature = new JMenuItem();
170 JMenuItem textColour = new JMenuItem();
172 JMenu jMenu1 = new JMenu();
174 JMenuItem pdbStructureDialog = new JMenuItem();
176 JMenu rnaStructureMenu = new JMenu();
178 JMenuItem editSequence = new JMenuItem();
180 JMenu groupLinksMenu;
182 JMenuItem hideInsertions = new JMenuItem();
185 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
186 * and/or features provided. Hyperlinks may include a lookup by sequence id,
187 * or database cross-references, depending on which links are enabled in user
194 static JMenu buildLinkMenu(final SequenceI seq,
195 List<SequenceFeature> features)
197 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
199 List<String> nlinks = null;
202 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
203 UrlLink.sort(nlinks);
207 nlinks = new ArrayList<>();
210 if (features != null)
212 for (SequenceFeature sf : features)
214 if (sf.links != null)
216 for (String link : sf.links)
225 * instantiate the hyperlinklink templates from sequence data;
226 * note the order of the templates is preserved in the map
228 Map<String, List<String>> linkset = new LinkedHashMap<>();
229 for (String link : nlinks)
231 UrlLink urlLink = null;
234 urlLink = new UrlLink(link);
235 } catch (Exception foo)
237 Cache.log.error("Exception for URLLink '" + link + "'", foo);
241 if (!urlLink.isValid())
243 Cache.log.error(urlLink.getInvalidMessage());
247 urlLink.createLinksFromSeq(seq, linkset);
251 * construct menu items for the hyperlinks (still preserving
252 * the order of the sorted templates)
254 addUrlLinks(linkMenu, linkset.values());
260 * A helper method that builds menu items from the given links, with action
261 * handlers to open the link URL, and adds them to the linkMenu. Each provided
262 * link should be a list whose second item is the menu text, and whose fourth
263 * item is the URL to open when the menu item is selected.
268 static private void addUrlLinks(JMenu linkMenu,
269 Collection<List<String>> linkset)
271 for (List<String> linkstrset : linkset)
273 final String url = linkstrset.get(3);
274 JMenuItem item = new JMenuItem(linkstrset.get(1));
275 item.setToolTipText(MessageManager
276 .formatMessage("label.open_url_param", new Object[]
278 item.addActionListener(new ActionListener()
281 public void actionPerformed(ActionEvent e)
283 new Thread(new Runnable()
298 * Opens the provided url in the default web browser, or shows an error
299 * message if this fails
303 static void showLink(String url)
307 Platform.openURL(url);
308 } catch (Exception ex)
310 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
311 MessageManager.getString("label.web_browser_not_found_unix"),
312 MessageManager.getString("label.web_browser_not_found"),
313 JvOptionPane.WARNING_MESSAGE);
315 ex.printStackTrace();
320 * For the popup menu on the idPanel.
322 * Add a late bound groupURL item to the given linkMenu
326 * - menu label string
327 * @param urlgenerator
328 * GroupURLLink used to generate URL
330 * Object array returned from the makeUrlStubs function.
332 static void addshowLink(JMenu linkMenu, String label,
333 final GroupUrlLink urlgenerator, final Object[] urlstub)
335 JMenuItem item = new JMenuItem(label);
336 item.setToolTipText(MessageManager
337 .formatMessage("label.open_url_seqs_param", new Object[]
338 { urlgenerator.getUrl_prefix(),
339 urlgenerator.getNumberInvolved(urlstub) }));
340 // TODO: put in info about what is being sent.
341 item.addActionListener(new ActionListener()
344 public void actionPerformed(ActionEvent e)
346 new Thread(new Runnable()
354 // Object[] { int[] { number of matches seqs },
355 // boolean[] { which matched },
356 // StringBuffer[] { segment generated from inputs },
360 // TODO bug: urlstub is { int[], boolean[] } but constructFrom
361 // requires something else.
363 showLink(urlgenerator.constructFrom(urlstub));
364 } catch (UrlStringTooLongException e2)
377 * Creates a new PopupMenu object.
382 * non-positional features (for seq not null), or positional features
383 * at residue (for seq equal to null)
385 public PopupMenu(final AlignmentPanel ap, SequenceI seq,
386 List<SequenceFeature> features)
388 this(ap, seq, features, null);
396 * the sequence under the cursor if in the Id panel, null if in the
399 * non-positional features if in the Id panel, features at the
400 * clicked residue if in the sequence panel
402 * not implemented -- empty list
404 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
405 List<SequenceFeature> features, List<String> groupLinks)
407 // /////////////////////////////////////////////////////////
408 // If this is activated from the sequence panel, the user may want to
409 // edit or annotate a particular residue. Therefore display the residue menu
411 // If from the IDPanel, we must display the sequence menu
412 // ////////////////////////////////////////////////////////
413 this.ap = alignPanel;
416 for (String ff : FileFormats.getInstance().getWritableFormats(true))
418 JMenuItem item = new JMenuItem(ff);
420 item.addActionListener(new ActionListener()
423 public void actionPerformed(ActionEvent e)
425 outputText_actionPerformed(e);
429 outputMenu.add(item);
433 * Build menus for annotation types that may be shown or hidden, and for
434 * 'reference annotations' that may be added to the alignment. First for the
435 * currently selected sequence (if there is one):
437 final List<SequenceI> selectedSequence = (seq == null
438 ? Collections.<SequenceI> emptyList()
439 : Arrays.asList(seq));
440 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
441 seqHideAnnotationsMenu, selectedSequence);
442 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
446 * And repeat for the current selection group (if there is one):
448 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
449 ? Collections.<SequenceI> emptyList()
450 : alignPanel.av.getSelectionGroup().getSequences());
451 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
452 groupHideAnnotationsMenu, selectedGroup);
453 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
459 } catch (Exception e)
467 sequenceMenu.setText(sequence.getName());
468 if (seq == alignPanel.av.getAlignment().getSeqrep())
470 makeReferenceSeq.setText(
471 MessageManager.getString("action.unmark_as_reference"));
475 makeReferenceSeq.setText(
476 MessageManager.getString("action.set_as_reference"));
479 if (!alignPanel.av.getAlignment().isNucleotide())
481 remove(rnaStructureMenu);
485 int origCount = rnaStructureMenu.getItemCount();
487 * add menu items to 2D-render any alignment or sequence secondary
488 * structure annotation
490 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
491 .getAlignmentAnnotation();
494 for (final AlignmentAnnotation aa : aas)
496 if (aa.isValidStruc() && aa.sequenceRef == null)
499 * valid alignment RNA secondary structure annotation
501 menuItem = new JMenuItem();
502 menuItem.setText(MessageManager.formatMessage(
503 "label.2d_rna_structure_line", new Object[]
505 menuItem.addActionListener(new ActionListener()
508 public void actionPerformed(ActionEvent e)
510 new AppVarna(seq, aa, alignPanel);
513 rnaStructureMenu.add(menuItem);
518 if (seq.getAnnotation() != null)
520 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
521 for (final AlignmentAnnotation aa : seqAnns)
523 if (aa.isValidStruc())
526 * valid sequence RNA secondary structure annotation
528 // TODO: make rnastrucF a bit more nice
529 menuItem = new JMenuItem();
530 menuItem.setText(MessageManager.formatMessage(
531 "label.2d_rna_sequence_name", new Object[]
533 menuItem.addActionListener(new ActionListener()
536 public void actionPerformed(ActionEvent e)
538 // TODO: VARNA does'nt print gaps in the sequence
539 new AppVarna(seq, aa, alignPanel);
542 rnaStructureMenu.add(menuItem);
546 if (rnaStructureMenu.getItemCount() == origCount)
548 remove(rnaStructureMenu);
552 menuItem = new JMenuItem(
553 MessageManager.getString("action.hide_sequences"));
554 menuItem.addActionListener(new ActionListener()
557 public void actionPerformed(ActionEvent e)
559 hideSequences(false);
564 if (alignPanel.av.getSelectionGroup() != null
565 && alignPanel.av.getSelectionGroup().getSize() > 1)
567 menuItem = new JMenuItem(MessageManager
568 .formatMessage("label.represent_group_with", new Object[]
570 menuItem.addActionListener(new ActionListener()
573 public void actionPerformed(ActionEvent e)
578 sequenceMenu.add(menuItem);
581 if (alignPanel.av.hasHiddenRows())
583 final int index = alignPanel.av.getAlignment().findIndex(seq);
585 if (alignPanel.av.adjustForHiddenSeqs(index)
586 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
588 menuItem = new JMenuItem(
589 MessageManager.getString("action.reveal_sequences"));
590 menuItem.addActionListener(new ActionListener()
593 public void actionPerformed(ActionEvent e)
595 alignPanel.av.showSequence(index);
596 if (alignPanel.overviewPanel != null)
598 alignPanel.overviewPanel.updateOverviewImage();
609 * - in the IdPanel (seq not null) if any sequence is hidden
610 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
612 if (alignPanel.av.hasHiddenRows())
614 boolean addOption = seq != null;
615 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
621 menuItem = new JMenuItem(
622 MessageManager.getString("action.reveal_all"));
623 menuItem.addActionListener(new ActionListener()
626 public void actionPerformed(ActionEvent e)
628 alignPanel.av.showAllHiddenSeqs();
629 if (alignPanel.overviewPanel != null)
631 alignPanel.overviewPanel.updateOverviewImage();
639 SequenceGroup sg = alignPanel.av.getSelectionGroup();
640 boolean isDefinedGroup = (sg != null)
641 ? alignPanel.av.getAlignment().getGroups().contains(sg)
644 if (sg != null && sg.getSize() > 0)
646 groupName.setText(MessageManager
647 .getString("label.edit_name_and_description_current_group"));
649 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
651 conservationMenuItem.setEnabled(!sg.isNucleotide());
655 if (sg.cs.conservationApplied())
657 conservationMenuItem.setSelected(true);
659 if (sg.cs.getThreshold() > 0)
661 abovePIDColour.setSelected(true);
664 modifyConservation.setEnabled(conservationMenuItem.isSelected());
665 modifyPID.setEnabled(abovePIDColour.isSelected());
666 displayNonconserved.setSelected(sg.getShowNonconserved());
667 showText.setSelected(sg.getDisplayText());
668 showColourText.setSelected(sg.getColourText());
669 showBoxes.setSelected(sg.getDisplayBoxes());
670 // add any groupURLs to the groupURL submenu and make it visible
671 if (groupLinks != null && groupLinks.size() > 0)
673 // not implemented -- empty list
674 buildGroupURLMenu(sg, groupLinks);
676 // Add a 'show all structures' for the current selection
677 Hashtable<String, PDBEntry> pdbe = new Hashtable<>(), reppdb = new Hashtable<>();
679 SequenceI sqass = null;
680 for (SequenceI sq : alignPanel.av.getSequenceSelection())
682 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
683 if (pes != null && pes.size() > 0)
685 reppdb.put(pes.get(0).getId(), pes.get(0));
686 for (PDBEntry pe : pes)
688 pdbe.put(pe.getId(), pe);
698 final PDBEntry[] pe = pdbe.values()
699 .toArray(new PDBEntry[pdbe.size()]),
700 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
701 final JMenuItem gpdbview, rpdbview;
706 groupMenu.setVisible(false);
707 editMenu.setVisible(false);
712 createGroupMenuItem.setVisible(true);
713 unGroupMenuItem.setVisible(false);
714 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
718 createGroupMenuItem.setVisible(false);
719 unGroupMenuItem.setVisible(true);
720 jMenu1.setText(MessageManager.getString("action.edit_group"));
725 sequenceMenu.setVisible(false);
726 pdbStructureDialog.setVisible(false);
727 rnaStructureMenu.setVisible(false);
730 addLinks(seq, features);
734 addFeatureDetails(features);
739 * Add a link to show feature details for each sequence feature
743 protected void addFeatureDetails(List<SequenceFeature> features)
745 if (features == null || features.isEmpty())
749 JMenu details = new JMenu(
750 MessageManager.getString("label.feature_details"));
753 for (final SequenceFeature sf : features)
755 int start = sf.getBegin();
756 int end = sf.getEnd();
760 desc = String.format("%s %d", sf.getType(), start);
764 desc = String.format("%s %d-%d", sf.getType(), start, end);
766 String tooltip = desc;
767 String description = sf.getDescription();
768 if (description != null)
770 description = StringUtils.stripHtmlTags(description);
771 if (description.length() > 12)
773 desc = desc + " " + description.substring(0, 12) + "..";
777 desc = desc + " " + description;
779 tooltip = tooltip + " " + description;
781 if (sf.getFeatureGroup() != null)
783 tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
785 JMenuItem item = new JMenuItem(desc);
786 item.setToolTipText(tooltip);
787 item.addActionListener(new ActionListener()
790 public void actionPerformed(ActionEvent e)
792 showFeatureDetails(sf);
800 * Opens a panel showing a text report of feature dteails
804 protected void showFeatureDetails(SequenceFeature sf)
806 JInternalFrame details;
809 details = new JInternalFrame();
810 JPanel panel = new JPanel(new BorderLayout());
811 panel.setOpaque(true);
812 panel.setBackground(Color.white);
813 // TODO JAL-3026 set style of table correctly for feature details
814 JLabel reprt = new JLabel(MessageManager
815 .formatMessage("label.html_content", new Object[]
816 { sf.getDetailsReport() }));
817 reprt.setBackground(Color.WHITE);
818 reprt.setOpaque(true);
819 panel.add(reprt, BorderLayout.CENTER);
820 details.setContentPane(panel);
830 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
831 // it appears Java's CSS does not support border-collaps :-(
832 cap.addStylesheetRule("table { border-collapse: collapse;}");
833 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
834 cap.setText(sf.getDetailsReport());
837 Desktop.addInternalFrame(details,
838 MessageManager.getString("label.feature_details"), 500, 500);
842 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
843 * When seq is not null, these are links for the sequence id, which may be to
844 * external web sites for the sequence accession, and/or links embedded in
845 * non-positional features. When seq is null, only links embedded in the
846 * provided features are added. If no links are found, the menu is not added.
851 void addLinks(final SequenceI seq, List<SequenceFeature> features)
853 JMenu linkMenu = buildLinkMenu(seq, features);
855 // only add link menu if it has entries
856 if (linkMenu.getItemCount() > 0)
858 if (sequence != null)
860 sequenceMenu.add(linkMenu);
870 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
871 * "All" is added first, followed by a separator. Then add any annotation
872 * types associated with the current selection. Separate menus are built for
873 * the selected sequence group (if any), and the selected sequence.
875 * Some annotation rows are always rendered together - these can be identified
876 * by a common graphGroup property > -1. Only one of each group will be marked
877 * as visible (to avoid duplication of the display). For such groups we add a
878 * composite type name, e.g.
880 * IUPredWS (Long), IUPredWS (Short)
884 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
885 List<SequenceI> forSequences)
887 showMenu.removeAll();
888 hideMenu.removeAll();
890 final List<String> all = Arrays
892 { MessageManager.getString("label.all") });
893 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
895 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
897 showMenu.addSeparator();
898 hideMenu.addSeparator();
900 final AlignmentAnnotation[] annotations = ap.getAlignment()
901 .getAlignmentAnnotation();
904 * Find shown/hidden annotations types, distinguished by source (calcId),
905 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
906 * the insertion order, which is the order of the annotations on the
909 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
910 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
911 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
912 AlignmentAnnotationUtils.asList(annotations), forSequences);
914 for (String calcId : hiddenTypes.keySet())
916 for (List<String> type : hiddenTypes.get(calcId))
918 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
922 // grey out 'show annotations' if none are hidden
923 showMenu.setEnabled(!hiddenTypes.isEmpty());
925 for (String calcId : shownTypes.keySet())
927 for (List<String> type : shownTypes.get(calcId))
929 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
933 // grey out 'hide annotations' if none are shown
934 hideMenu.setEnabled(!shownTypes.isEmpty());
938 * Returns a list of sequences - either the current selection group (if there
939 * is one), else the specified single sequence.
944 protected List<SequenceI> getSequenceScope(SequenceI seq)
946 List<SequenceI> forSequences = null;
947 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
948 if (selectionGroup != null && selectionGroup.getSize() > 0)
950 forSequences = selectionGroup.getSequences();
954 forSequences = seq == null ? Collections.<SequenceI> emptyList()
955 : Arrays.asList(seq);
961 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
964 * @param showOrHideMenu
966 * @param forSequences
967 * the sequences whose annotations may be shown or hidden
972 * if true this is a special label meaning 'All'
973 * @param actionIsShow
974 * if true, the select menu item action is to show the annotation
977 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
978 final List<SequenceI> forSequences, String calcId,
979 final List<String> types, final boolean allTypes,
980 final boolean actionIsShow)
982 String label = types.toString(); // [a, b, c]
983 label = label.substring(1, label.length() - 1); // a, b, c
984 final JMenuItem item = new JMenuItem(label);
985 item.setToolTipText(calcId);
986 item.addActionListener(new ActionListener()
989 public void actionPerformed(ActionEvent e)
991 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
992 types, forSequences, allTypes, actionIsShow);
996 showOrHideMenu.add(item);
1003 * not implemented -- empty list
1005 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
1008 // TODO: usability: thread off the generation of group url content so root
1009 // menu appears asap
1010 // sequence only URLs
1011 // ID/regex match URLs
1012 groupLinksMenu = new JMenu(
1013 MessageManager.getString("action.group_link"));
1014 // three types of url that might be created.
1015 JMenu[] linkMenus = new JMenu[] { null,
1016 new JMenu(MessageManager.getString("action.ids")),
1017 new JMenu(MessageManager.getString("action.sequences")),
1018 new JMenu(MessageManager.getString("action.ids_sequences")) };
1020 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1021 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1022 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
1023 for (int sq = 0; sq < seqs.length; sq++)
1026 int start = seqs[sq].findPosition(sg.getStartRes()),
1027 end = seqs[sq].findPosition(sg.getEndRes());
1028 // just collect ids from dataset sequence
1029 // TODO: check if IDs collected from selecton group intersects with the
1030 // current selection, too
1031 SequenceI sqi = seqs[sq];
1032 while (sqi.getDatasetSequence() != null)
1034 sqi = sqi.getDatasetSequence();
1036 List<DBRefEntry> dbr = sqi.getDBRefs();
1038 if (dbr != null && (nd = dbr.size()) > 0)
1040 for (int d = 0; d < nd; d++)
1042 DBRefEntry e = dbr.get(d);
1043 String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1044 Object[] sarray = commonDbrefs.get(src);
1047 sarray = new Object[2];
1048 sarray[0] = new int[] { 0 };
1049 sarray[1] = new String[seqs.length];
1051 commonDbrefs.put(src, sarray);
1054 if (((String[]) sarray[1])[sq] == null)
1056 if (!e.hasMap() || (e.getMap()
1057 .locateMappedRange(start, end) != null))
1059 ((String[]) sarray[1])[sq] = e.getAccessionId();
1060 ((int[]) sarray[0])[0]++;
1066 if (groupLinks.size() == 0)
1070 // now create group links for all distinct ID/sequence sets.
1071 boolean addMenu = false; // indicates if there are any group links to give
1074 // not implmeented -- empty list
1075 for (String link : groupLinks)
1077 GroupUrlLink urlLink = null;
1080 urlLink = new GroupUrlLink(link);
1081 } catch (Exception foo)
1083 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
1087 if (!urlLink.isValid())
1089 Cache.log.error(urlLink.getInvalidMessage());
1092 final String label = urlLink.getLabel();
1093 boolean usingNames = false;
1094 // Now see which parts of the group apply for this URL
1095 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1096 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
1097 String[] seqstr, ids; // input to makeUrl
1100 int numinput = ((int[]) idset[0])[0];
1101 String[] allids = ((String[]) idset[1]);
1102 seqstr = new String[numinput];
1103 ids = new String[numinput];
1104 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1106 if (allids[sq] != null)
1108 ids[idcount] = allids[sq];
1109 seqstr[idcount++] = idandseqs[1][sq];
1115 // just use the id/seq set
1116 seqstr = idandseqs[1];
1120 // and try and make the groupURL!
1122 Object[] urlset = null;
1125 urlset = urlLink.makeUrlStubs(ids, seqstr,
1126 "FromJalview" + System.currentTimeMillis(), false);
1127 // { int[], boolean[] } only here
1128 } catch (UrlStringTooLongException e)
1133 int type = urlLink.getGroupURLType() & 3;
1134 // first two bits ofurlLink type bitfield are sequenceids and sequences
1135 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1136 addshowLink(linkMenus[type],
1137 label + (((type & 1) == 1)
1138 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1146 groupLinksMenu = new JMenu(
1147 MessageManager.getString("action.group_link"));
1148 for (int m = 0; m < linkMenus.length; m++)
1150 if (linkMenus[m] != null
1151 && linkMenus[m].getMenuComponentCount() > 0)
1153 groupLinksMenu.add(linkMenus[m]);
1156 groupMenu.add(groupLinksMenu);
1166 private void jbInit() throws Exception
1168 groupMenu.setText(MessageManager.getString("label.selection"));
1169 groupName.setText(MessageManager.getString("label.name"));
1170 groupName.addActionListener(new ActionListener()
1173 public void actionPerformed(ActionEvent e)
1175 groupName_actionPerformed();
1178 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1179 sequenceName.setText(
1180 MessageManager.getString("label.edit_name_description"));
1181 sequenceName.addActionListener(new ActionListener()
1184 public void actionPerformed(ActionEvent e)
1186 sequenceName_actionPerformed();
1190 .setText(MessageManager.getString("action.choose_annotations"));
1191 chooseAnnotations.addActionListener(new ActionListener()
1194 public void actionPerformed(ActionEvent e)
1196 chooseAnnotations_actionPerformed(e);
1200 .setText(MessageManager.getString("label.sequence_details"));
1201 sequenceDetails.addActionListener(new ActionListener()
1204 public void actionPerformed(ActionEvent e)
1206 sequenceDetails_actionPerformed();
1210 .setText(MessageManager.getString("label.sequence_details"));
1211 sequenceSelDetails.addActionListener(new ActionListener()
1214 public void actionPerformed(ActionEvent e)
1216 sequenceSelectionDetails_actionPerformed();
1221 .setText(MessageManager.getString("action.remove_group"));
1222 unGroupMenuItem.addActionListener(new ActionListener()
1225 public void actionPerformed(ActionEvent e)
1227 unGroupMenuItem_actionPerformed();
1231 .setText(MessageManager.getString("action.create_group"));
1232 createGroupMenuItem.addActionListener(new ActionListener()
1235 public void actionPerformed(ActionEvent e)
1237 createGroupMenuItem_actionPerformed();
1241 outline.setText(MessageManager.getString("action.border_colour"));
1242 outline.addActionListener(new ActionListener()
1245 public void actionPerformed(ActionEvent e)
1247 outline_actionPerformed();
1250 showBoxes.setText(MessageManager.getString("action.boxes"));
1251 showBoxes.setState(true);
1252 showBoxes.addActionListener(new ActionListener()
1255 public void actionPerformed(ActionEvent e)
1257 showBoxes_actionPerformed();
1260 showText.setText(MessageManager.getString("action.text"));
1261 showText.setState(true);
1262 showText.addActionListener(new ActionListener()
1265 public void actionPerformed(ActionEvent e)
1267 showText_actionPerformed();
1270 showColourText.setText(MessageManager.getString("label.colour_text"));
1271 showColourText.addActionListener(new ActionListener()
1274 public void actionPerformed(ActionEvent e)
1276 showColourText_actionPerformed();
1280 .setText(MessageManager.getString("label.show_non_conserved"));
1281 displayNonconserved.setState(true);
1282 displayNonconserved.addActionListener(new ActionListener()
1285 public void actionPerformed(ActionEvent e)
1287 showNonconserved_actionPerformed();
1290 editMenu.setText(MessageManager.getString("action.edit"));
1291 cut.setText(MessageManager.getString("action.cut"));
1292 cut.addActionListener(new ActionListener()
1295 public void actionPerformed(ActionEvent e)
1297 cut_actionPerformed();
1300 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1301 upperCase.addActionListener(new ActionListener()
1304 public void actionPerformed(ActionEvent e)
1309 copy.setText(MessageManager.getString("action.copy"));
1310 copy.addActionListener(new ActionListener()
1313 public void actionPerformed(ActionEvent e)
1315 copy_actionPerformed();
1318 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1319 lowerCase.addActionListener(new ActionListener()
1322 public void actionPerformed(ActionEvent e)
1327 toggle.setText(MessageManager.getString("label.toggle_case"));
1328 toggle.addActionListener(new ActionListener()
1331 public void actionPerformed(ActionEvent e)
1337 MessageManager.getString("label.out_to_textbox") + "...");
1338 seqShowAnnotationsMenu
1339 .setText(MessageManager.getString("label.show_annotations"));
1340 seqHideAnnotationsMenu
1341 .setText(MessageManager.getString("label.hide_annotations"));
1342 groupShowAnnotationsMenu
1343 .setText(MessageManager.getString("label.show_annotations"));
1344 groupHideAnnotationsMenu
1345 .setText(MessageManager.getString("label.hide_annotations"));
1346 sequenceFeature.setText(
1347 MessageManager.getString("label.create_sequence_feature"));
1348 sequenceFeature.addActionListener(new ActionListener()
1351 public void actionPerformed(ActionEvent e)
1353 sequenceFeature_actionPerformed();
1356 jMenu1.setText(MessageManager.getString("label.group"));
1357 pdbStructureDialog.setText(
1358 MessageManager.getString("label.show_pdbstruct_dialog"));
1359 pdbStructureDialog.addActionListener(new ActionListener()
1362 public void actionPerformed(ActionEvent actionEvent)
1364 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1365 if (ap.av.getSelectionGroup() != null)
1367 selectedSeqs = ap.av.getSequenceSelection();
1369 new StructureChooser(selectedSeqs, sequence, ap);
1374 .setText(MessageManager.getString("label.view_rna_structure"));
1376 // colStructureMenu.setText("Colour By Structure");
1377 editSequence.setText(
1378 MessageManager.getString("label.edit_sequence") + "...");
1379 editSequence.addActionListener(new ActionListener()
1382 public void actionPerformed(ActionEvent actionEvent)
1384 editSequence_actionPerformed();
1387 makeReferenceSeq.setText(
1388 MessageManager.getString("label.mark_as_representative"));
1389 makeReferenceSeq.addActionListener(new ActionListener()
1393 public void actionPerformed(ActionEvent actionEvent)
1395 makeReferenceSeq_actionPerformed(actionEvent);
1400 .setText(MessageManager.getString("label.hide_insertions"));
1401 hideInsertions.addActionListener(new ActionListener()
1405 public void actionPerformed(ActionEvent e)
1407 hideInsertions_actionPerformed(e);
1411 groupMenu.add(sequenceSelDetails);
1414 add(rnaStructureMenu);
1415 add(pdbStructureDialog);
1416 if (sequence != null)
1418 add(hideInsertions);
1420 // annotations configuration panel suppressed for now
1421 // groupMenu.add(chooseAnnotations);
1424 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1425 * (if a selection group is in force).
1427 sequenceMenu.add(seqShowAnnotationsMenu);
1428 sequenceMenu.add(seqHideAnnotationsMenu);
1429 sequenceMenu.add(seqAddReferenceAnnotations);
1430 groupMenu.add(groupShowAnnotationsMenu);
1431 groupMenu.add(groupHideAnnotationsMenu);
1432 groupMenu.add(groupAddReferenceAnnotations);
1433 groupMenu.add(editMenu);
1434 groupMenu.add(outputMenu);
1435 groupMenu.add(sequenceFeature);
1436 groupMenu.add(createGroupMenuItem);
1437 groupMenu.add(unGroupMenuItem);
1438 groupMenu.add(jMenu1);
1439 sequenceMenu.add(sequenceName);
1440 sequenceMenu.add(sequenceDetails);
1441 sequenceMenu.add(makeReferenceSeq);
1448 editMenu.add(editSequence);
1449 editMenu.add(upperCase);
1450 editMenu.add(lowerCase);
1451 editMenu.add(toggle);
1452 // JBPNote: These shouldn't be added here - should appear in a generic
1453 // 'apply web service to this sequence menu'
1454 // pdbMenu.add(RNAFold);
1455 // pdbMenu.add(ContraFold);
1456 jMenu1.add(groupName);
1457 jMenu1.add(colourMenu);
1458 jMenu1.add(showBoxes);
1459 jMenu1.add(showText);
1460 jMenu1.add(showColourText);
1461 jMenu1.add(outline);
1462 jMenu1.add(displayNonconserved);
1466 * Constructs the entries for the colour menu
1468 protected void initColourMenu()
1470 colourMenu.setText(MessageManager.getString("label.group_colour"));
1471 textColour.setText(MessageManager.getString("label.text_colour"));
1472 textColour.addActionListener(new ActionListener()
1475 public void actionPerformed(ActionEvent e)
1477 textColour_actionPerformed();
1481 abovePIDColour.setText(
1482 MessageManager.getString("label.above_identity_threshold"));
1483 abovePIDColour.addActionListener(new ActionListener()
1486 public void actionPerformed(ActionEvent e)
1488 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1493 MessageManager.getString("label.modify_identity_threshold"));
1494 modifyPID.addActionListener(new ActionListener()
1497 public void actionPerformed(ActionEvent e)
1499 modifyPID_actionPerformed();
1503 conservationMenuItem
1504 .setText(MessageManager.getString("action.by_conservation"));
1505 conservationMenuItem.addActionListener(new ActionListener()
1508 public void actionPerformed(ActionEvent e)
1510 conservationMenuItem_actionPerformed(
1511 conservationMenuItem.isSelected());
1515 annotationColour = new JRadioButtonMenuItem(
1516 MessageManager.getString("action.by_annotation"));
1517 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1518 annotationColour.setEnabled(false);
1519 annotationColour.setToolTipText(
1520 MessageManager.getString("label.by_annotation_tooltip"));
1522 modifyConservation.setText(MessageManager
1523 .getString("label.modify_conservation_threshold"));
1524 modifyConservation.addActionListener(new ActionListener()
1527 public void actionPerformed(ActionEvent e)
1529 modifyConservation_actionPerformed();
1535 * Builds the group colour sub-menu, including any user-defined colours which
1536 * were loaded at startup or during the Jalview session
1538 protected void buildColourMenu()
1540 SequenceGroup sg = ap.av.getSelectionGroup();
1544 * popup menu with no sequence group scope
1548 colourMenu.removeAll();
1549 colourMenu.add(textColour);
1550 colourMenu.addSeparator();
1552 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1554 bg.add(annotationColour);
1555 colourMenu.add(annotationColour);
1557 colourMenu.addSeparator();
1558 colourMenu.add(conservationMenuItem);
1559 colourMenu.add(modifyConservation);
1560 colourMenu.add(abovePIDColour);
1561 colourMenu.add(modifyPID);
1564 protected void modifyConservation_actionPerformed()
1566 SequenceGroup sg = getGroup();
1569 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1570 SliderPanel.showConservationSlider();
1574 protected void modifyPID_actionPerformed()
1576 SequenceGroup sg = getGroup();
1579 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1581 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1582 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1583 SliderPanel.showPIDSlider();
1588 * Check for any annotations on the underlying dataset sequences (for the
1589 * current selection group) which are not 'on the alignment'.If any are found,
1590 * enable the option to add them to the alignment. The criteria for 'on the
1591 * alignment' is finding an alignment annotation on the alignment, matched on
1592 * calcId, label and sequenceRef.
1594 * A tooltip is also constructed that displays the source (calcId) and type
1595 * (label) of the annotations that can be added.
1598 * @param forSequences
1600 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1601 List<SequenceI> forSequences)
1603 menuItem.setEnabled(false);
1606 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1607 * Using TreeMap means calcIds are shown in alphabetical order.
1609 SortedMap<String, String> tipEntries = new TreeMap<>();
1610 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1611 AlignmentI al = this.ap.av.getAlignment();
1612 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1614 if (!candidates.isEmpty())
1616 StringBuilder tooltip = new StringBuilder(64);
1617 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1620 * Found annotations that could be added. Enable the menu item, and
1621 * configure its tooltip and action.
1623 menuItem.setEnabled(true);
1624 for (String calcId : tipEntries.keySet())
1626 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1628 String tooltipText = JvSwingUtils.wrapTooltip(true,
1629 tooltip.toString());
1630 menuItem.setToolTipText(tooltipText);
1632 menuItem.addActionListener(new ActionListener()
1635 public void actionPerformed(ActionEvent e)
1637 addReferenceAnnotations_actionPerformed(candidates);
1644 * Add annotations to the sequences and to the alignment.
1647 * a map whose keys are sequences on the alignment, and values a list
1648 * of annotations to add to each sequence
1650 protected void addReferenceAnnotations_actionPerformed(
1651 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1653 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1654 final AlignmentI alignment = this.ap.getAlignment();
1655 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1660 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1662 if (!ap.av.getAlignment().hasSeqrep())
1664 // initialise the display flags so the user sees something happen
1665 ap.av.setDisplayReferenceSeq(true);
1666 ap.av.setColourByReferenceSeq(true);
1667 ap.av.getAlignment().setSeqrep(sequence);
1671 if (ap.av.getAlignment().getSeqrep() == sequence)
1673 ap.av.getAlignment().setSeqrep(null);
1677 ap.av.getAlignment().setSeqrep(sequence);
1683 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1685 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1686 BitSet inserts = new BitSet();
1688 boolean markedPopup = false;
1689 // mark inserts in current selection
1690 if (ap.av.getSelectionGroup() != null)
1692 // mark just the columns in the selection group to be hidden
1693 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1694 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1696 // now clear columns without gaps
1697 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1703 inserts.and(sq.getInsertionsAsBits());
1705 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1706 ap.av.getSelectionGroup().getEndRes());
1709 // now mark for sequence under popup if we haven't already done it
1710 else if (!markedPopup && sequence != null)
1712 inserts.or(sequence.getInsertionsAsBits());
1714 // and set hidden columns accordingly
1715 hidden.hideColumns(inserts);
1720 protected void sequenceSelectionDetails_actionPerformed()
1722 createSequenceDetailsReport(ap.av.getSequenceSelection());
1725 protected void sequenceDetails_actionPerformed()
1727 createSequenceDetailsReport(new SequenceI[] { sequence });
1730 public void createSequenceDetailsReport(SequenceI[] sequences)
1732 StringBuilder contents = new StringBuilder(128);
1733 contents.append("<html><body>");
1734 for (SequenceI seq : sequences)
1736 contents.append("<p><h2>" + MessageManager.formatMessage(
1737 "label.create_sequence_details_report_annotation_for",
1739 { seq.getDisplayId(true) }) + "</h2></p><p>");
1740 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
1741 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1742 contents.append("</p>");
1744 contents.append("</body></html>");
1745 String report = contents.toString();
1747 JInternalFrame frame;
1748 if (Platform.isJS())
1750 JLabel textLabel = new JLabel();
1751 textLabel.setText(report);
1752 textLabel.setBackground(Color.WHITE);
1753 JPanel pane = new JPanel(new BorderLayout());
1754 pane.setOpaque(true);
1755 pane.setBackground(Color.WHITE);
1756 pane.add(textLabel, BorderLayout.NORTH);
1757 frame = new JInternalFrame();
1758 frame.getContentPane().add(new JScrollPane(pane));
1767 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1768 cap.setText(report);
1772 Desktop.addInternalFrame(frame,
1773 MessageManager.formatMessage("label.sequence_details_for",
1774 (sequences.length == 1 ? new Object[]
1775 { sequences[0].getDisplayId(true) }
1778 .getString("label.selection") })),
1782 protected void showNonconserved_actionPerformed()
1784 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1789 * call to refresh view after settings change
1793 ap.updateAnnotation();
1794 // removed paintAlignment(true) here:
1795 // updateAnnotation calls paintAlignment already, so don't need to call
1798 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1802 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1803 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1813 public void abovePIDColour_actionPerformed(boolean selected)
1815 SequenceGroup sg = getGroup();
1823 sg.cs.setConsensus(AAFrequency.calculate(
1824 sg.getSequences(ap.av.getHiddenRepSequences()),
1825 sg.getStartRes(), sg.getEndRes() + 1));
1827 int threshold = SliderPanel.setPIDSliderSource(ap,
1828 sg.getGroupColourScheme(), getGroup().getName());
1830 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1832 SliderPanel.showPIDSlider();
1835 // remove PIDColouring
1837 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1838 SliderPanel.hidePIDSlider();
1840 modifyPID.setEnabled(selected);
1846 * Open a panel where the user can choose which types of sequence annotation
1851 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1853 // todo correct way to guard against opening a duplicate panel?
1854 new AnnotationChooser(ap);
1863 public void conservationMenuItem_actionPerformed(boolean selected)
1865 SequenceGroup sg = getGroup();
1873 // JBPNote: Conservation name shouldn't be i18n translated
1874 Conservation c = new Conservation("Group",
1875 sg.getSequences(ap.av.getHiddenRepSequences()),
1876 sg.getStartRes(), sg.getEndRes() + 1);
1879 c.verdict(false, ap.av.getConsPercGaps());
1880 sg.cs.setConservation(c);
1882 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1884 SliderPanel.showConservationSlider();
1887 // remove ConservationColouring
1889 sg.cs.setConservation(null);
1890 SliderPanel.hideConservationSlider();
1892 modifyConservation.setEnabled(selected);
1898 * Shows a dialog where group name and description may be edited
1900 protected void groupName_actionPerformed()
1902 SequenceGroup sg = getGroup();
1903 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1904 sg.getDescription(),
1905 MessageManager.getString("label.group_name"),
1906 MessageManager.getString("label.group_description"));
1907 dialog.showDialog(ap.alignFrame,
1908 MessageManager.getString("label.edit_group_name_description"),
1914 sg.setName(dialog.getName());
1915 sg.setDescription(dialog.getDescription());
1922 * Get selection group - adding it to the alignment if necessary.
1924 * @return sequence group to operate on
1926 SequenceGroup getGroup()
1928 SequenceGroup sg = ap.av.getSelectionGroup();
1929 // this method won't add a new group if it already exists
1932 ap.av.getAlignment().addGroup(sg);
1939 * Shows a dialog where sequence name and description may be edited
1941 void sequenceName_actionPerformed()
1943 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1944 sequence.getDescription(),
1945 MessageManager.getString("label.sequence_name"),
1946 MessageManager.getString("label.sequence_description"));
1947 dialog.showDialog(ap.alignFrame,
1948 MessageManager.getString(
1949 "label.edit_sequence_name_description"),
1955 if (dialog.getName() != null)
1957 if (dialog.getName().indexOf(" ") > -1)
1959 JvOptionPane.showMessageDialog(ap,
1960 MessageManager.getString(
1961 "label.spaces_converted_to_underscores"),
1962 MessageManager.getString(
1963 "label.no_spaces_allowed_sequence_name"),
1964 JvOptionPane.WARNING_MESSAGE);
1966 sequence.setName(dialog.getName().replace(' ', '_'));
1967 ap.paintAlignment(false, false);
1969 sequence.setDescription(dialog.getDescription());
1970 ap.av.firePropertyChange("alignment", null,
1971 ap.av.getAlignment().getSequences());
1982 void unGroupMenuItem_actionPerformed()
1984 SequenceGroup sg = ap.av.getSelectionGroup();
1985 ap.av.getAlignment().deleteGroup(sg);
1986 ap.av.setSelectionGroup(null);
1990 void createGroupMenuItem_actionPerformed()
1992 getGroup(); // implicitly creates group - note - should apply defaults / use
1993 // standard alignment window logic for this
1998 * Offers a colour chooser and sets the selected colour as the group outline
2000 protected void outline_actionPerformed()
2002 String title = MessageManager
2003 .getString("label.select_outline_colour");
2004 ColourChooserListener listener = new ColourChooserListener()
2007 public void colourSelected(Color c)
2009 getGroup().setOutlineColour(c);
2013 JalviewColourChooser.showColourChooser(Desktop.getDesktopPane(),
2014 title, Color.BLUE, listener);
2023 public void showBoxes_actionPerformed()
2025 getGroup().setDisplayBoxes(showBoxes.isSelected());
2035 public void showText_actionPerformed()
2037 getGroup().setDisplayText(showText.isSelected());
2047 public void showColourText_actionPerformed()
2049 getGroup().setColourText(showColourText.isSelected());
2053 void hideSequences(boolean representGroup)
2055 ap.av.hideSequences(sequence, representGroup);
2058 public void copy_actionPerformed()
2060 ap.alignFrame.copy_actionPerformed();
2063 public void cut_actionPerformed()
2065 ap.alignFrame.cut_actionPerformed();
2068 void changeCase(ActionEvent e)
2070 Object source = e.getSource();
2071 SequenceGroup sg = ap.av.getSelectionGroup();
2075 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2076 sg.getStartRes(), sg.getEndRes() + 1);
2081 if (source == toggle)
2083 description = MessageManager.getString("label.toggle_case");
2084 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2086 else if (source == upperCase)
2088 description = MessageManager.getString("label.to_upper_case");
2089 caseChange = ChangeCaseCommand.TO_UPPER;
2093 description = MessageManager.getString("label.to_lower_case");
2094 caseChange = ChangeCaseCommand.TO_LOWER;
2097 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2098 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2099 startEnd, caseChange);
2101 ap.alignFrame.addHistoryItem(caseCommand);
2103 ap.av.firePropertyChange("alignment", null,
2104 ap.av.getAlignment().getSequences());
2109 public void outputText_actionPerformed(ActionEvent e)
2111 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2112 cap.setForInput(null);
2113 Desktop.addInternalFrame(cap, MessageManager
2114 .formatMessage("label.alignment_output_command", new Object[]
2115 { e.getActionCommand() }), 600, 500);
2117 String[] omitHidden = null;
2119 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2120 // or we simply trust the user wants
2121 // wysiwig behaviour
2123 FileFormatI fileFormat = FileFormats.getInstance()
2124 .forName(e.getActionCommand());
2126 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2129 public void sequenceFeature_actionPerformed()
2131 SequenceGroup sg = ap.av.getSelectionGroup();
2137 List<SequenceI> seqs = new ArrayList<>();
2138 List<SequenceFeature> features = new ArrayList<>();
2141 * assemble dataset sequences, and template new sequence features,
2142 * for the amend features dialog
2144 int gSize = sg.getSize();
2145 for (int i = 0; i < gSize; i++)
2147 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2148 int end = sg.findEndRes(sg.getSequenceAt(i));
2151 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2152 features.add(new SequenceFeature(null, null, start, end, null));
2157 * an entirely gapped region will generate empty lists of sequence / features
2159 if (!seqs.isEmpty())
2161 new FeatureEditor(ap, seqs, features, true).showDialog();
2165 public void textColour_actionPerformed()
2167 SequenceGroup sg = getGroup();
2170 new TextColourChooser().chooseColour(ap, sg);
2174 public void colourByStructure(String pdbid)
2176 Annotation[] anots = ap.av.getStructureSelectionManager()
2177 .colourSequenceFromStructure(sequence, pdbid);
2179 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2180 "Coloured by " + pdbid, anots);
2182 ap.av.getAlignment().addAnnotation(an);
2183 an.createSequenceMapping(sequence, 0, true);
2184 // an.adjustForAlignment();
2185 ap.av.getAlignment().setAnnotationIndex(an, 0);
2187 ap.adjustAnnotationHeight();
2189 sequence.addAlignmentAnnotation(an);
2194 * Shows a dialog where sequence characters may be edited. Any changes are
2195 * applied, and added as an available 'Undo' item in the edit commands
2198 public void editSequence_actionPerformed()
2200 SequenceGroup sg = ap.av.getSelectionGroup();
2204 if (sequence == null)
2206 sequence = sg.getSequenceAt(0);
2209 EditNameDialog dialog = new EditNameDialog(
2210 sequence.getSequenceAsString(sg.getStartRes(),
2211 sg.getEndRes() + 1),
2212 null, MessageManager.getString("label.edit_sequence"), null);
2213 dialog.showDialog(ap.alignFrame,
2214 MessageManager.getString("label.edit_sequence"),
2220 EditCommand editCommand = new EditCommand(
2221 MessageManager.getString("label.edit_sequences"),
2223 dialog.getName().replace(' ',
2224 ap.av.getGapCharacter()),
2225 sg.getSequencesAsArray(
2226 ap.av.getHiddenRepSequences()),
2227 sg.getStartRes(), sg.getEndRes() + 1,
2228 ap.av.getAlignment());
2229 ap.alignFrame.addHistoryItem(editCommand);
2230 ap.av.firePropertyChange("alignment", null,
2231 ap.av.getAlignment().getSequences());
2238 * Action on user selecting an item from the colour menu (that does not have
2239 * its bespoke action handler)
2244 public void changeColour_actionPerformed(String colourSchemeName)
2246 SequenceGroup sg = getGroup();
2248 * switch to the chosen colour scheme (or null for None)
2250 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2251 .getColourScheme(colourSchemeName, ap.av, sg,
2252 ap.av.getHiddenRepSequences());
2253 sg.setColourScheme(colourScheme);
2254 if (colourScheme instanceof Blosum62ColourScheme
2255 || colourScheme instanceof PIDColourScheme)
2257 sg.cs.setConsensus(AAFrequency.calculate(
2258 sg.getSequences(ap.av.getHiddenRepSequences()),
2259 sg.getStartRes(), sg.getEndRes() + 1));