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.io.FileFormatI;
42 import jalview.io.FileFormats;
43 import jalview.io.FormatAdapter;
44 import jalview.io.SequenceAnnotationReport;
45 import jalview.schemes.Blosum62ColourScheme;
46 import jalview.schemes.ColourSchemeI;
47 import jalview.schemes.ColourSchemes;
48 import jalview.schemes.PIDColourScheme;
49 import jalview.schemes.ResidueColourScheme;
50 import jalview.util.GroupUrlLink;
51 import jalview.util.GroupUrlLink.UrlStringTooLongException;
52 import jalview.util.MessageManager;
53 import jalview.util.StringUtils;
54 import jalview.util.UrlLink;
56 import java.awt.Color;
57 import java.awt.event.ActionEvent;
58 import java.awt.event.ActionListener;
59 import java.util.ArrayList;
60 import java.util.Arrays;
61 import java.util.BitSet;
62 import java.util.Collection;
63 import java.util.Collections;
64 import java.util.Hashtable;
65 import java.util.LinkedHashMap;
66 import java.util.List;
68 import java.util.SortedMap;
69 import java.util.TreeMap;
70 import java.util.Vector;
72 import javax.swing.ButtonGroup;
73 import javax.swing.JCheckBoxMenuItem;
74 import javax.swing.JColorChooser;
75 import javax.swing.JMenu;
76 import javax.swing.JMenuItem;
77 import javax.swing.JPopupMenu;
78 import javax.swing.JRadioButtonMenuItem;
81 * The popup menu that is displayed on right-click on a sequence id, or in the
84 public class PopupMenu extends JPopupMenu implements ColourChangeListener
86 JMenu groupMenu = new JMenu();
88 JMenuItem groupName = new JMenuItem();
90 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
92 protected JMenuItem modifyPID = new JMenuItem();
94 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
96 protected JRadioButtonMenuItem annotationColour;
98 protected JMenuItem modifyConservation = new JMenuItem();
102 JMenu sequenceMenu = new JMenu();
104 JMenuItem sequenceName = new JMenuItem();
106 JMenuItem sequenceDetails = new JMenuItem();
108 JMenuItem sequenceSelDetails = new JMenuItem();
110 JMenuItem makeReferenceSeq = new JMenuItem();
112 JMenuItem chooseAnnotations = new JMenuItem();
116 JMenuItem createGroupMenuItem = new JMenuItem();
118 JMenuItem unGroupMenuItem = new JMenuItem();
120 JMenuItem outline = new JMenuItem();
122 JMenu colourMenu = new JMenu();
124 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
126 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
128 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
130 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
132 JMenu editMenu = new JMenu();
134 JMenuItem cut = new JMenuItem();
136 JMenuItem copy = new JMenuItem();
138 JMenuItem upperCase = new JMenuItem();
140 JMenuItem lowerCase = new JMenuItem();
142 JMenuItem toggle = new JMenuItem();
144 JMenu pdbMenu = new JMenu();
146 JMenu outputMenu = new JMenu();
148 JMenu seqShowAnnotationsMenu = new JMenu();
150 JMenu seqHideAnnotationsMenu = new JMenu();
152 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
153 MessageManager.getString("label.add_reference_annotations"));
155 JMenu groupShowAnnotationsMenu = new JMenu();
157 JMenu groupHideAnnotationsMenu = new JMenu();
159 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
160 MessageManager.getString("label.add_reference_annotations"));
162 JMenuItem sequenceFeature = new JMenuItem();
164 JMenuItem textColour = new JMenuItem();
166 JMenu jMenu1 = new JMenu();
168 JMenuItem pdbStructureDialog = new JMenuItem();
170 JMenu rnaStructureMenu = new JMenu();
172 JMenuItem editSequence = new JMenuItem();
174 JMenu groupLinksMenu;
176 JMenuItem hideInsertions = new JMenuItem();
179 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
180 * and/or features provided. Hyperlinks may include a lookup by sequence id,
181 * or database cross-references, depending on which links are enabled in user
188 static JMenu buildLinkMenu(final SequenceI seq,
189 List<SequenceFeature> features)
191 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
193 List<String> nlinks = null;
196 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
197 UrlLink.sort(nlinks);
201 nlinks = new ArrayList<>();
204 if (features != null)
206 for (SequenceFeature sf : features)
208 if (sf.links != null)
210 for (String link : sf.links)
219 * instantiate the hyperlinklink templates from sequence data;
220 * note the order of the templates is preserved in the map
222 Map<String, List<String>> linkset = new LinkedHashMap<>();
223 for (String link : nlinks)
225 UrlLink urlLink = null;
228 urlLink = new UrlLink(link);
229 } catch (Exception foo)
231 Cache.log.error("Exception for URLLink '" + link + "'", foo);
235 if (!urlLink.isValid())
237 Cache.log.error(urlLink.getInvalidMessage());
241 urlLink.createLinksFromSeq(seq, linkset);
245 * construct menu items for the hyperlinks (still preserving
246 * the order of the sorted templates)
248 addUrlLinks(linkMenu, linkset.values());
254 * A helper method that builds menu items from the given links, with action
255 * handlers to open the link URL, and adds them to the linkMenu. Each provided
256 * link should be a list whose second item is the menu text, and whose fourth
257 * item is the URL to open when the menu item is selected.
262 static private void addUrlLinks(JMenu linkMenu,
263 Collection<List<String>> linkset)
265 for (List<String> linkstrset : linkset)
267 final String url = linkstrset.get(3);
268 JMenuItem item = new JMenuItem(linkstrset.get(1));
269 item.setToolTipText(MessageManager
270 .formatMessage("label.open_url_param", new Object[]
272 item.addActionListener(new ActionListener()
275 public void actionPerformed(ActionEvent e)
277 new Thread(new Runnable()
292 * Opens the provided url in the default web browser, or shows an error
293 * message if this fails
297 static void showLink(String url)
301 jalview.util.BrowserLauncher.openURL(url);
302 } catch (Exception ex)
304 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
305 MessageManager.getString("label.web_browser_not_found_unix"),
306 MessageManager.getString("label.web_browser_not_found"),
307 JvOptionPane.WARNING_MESSAGE);
309 ex.printStackTrace();
314 * add a late bound groupURL item to the given linkMenu
318 * - menu label string
319 * @param urlgenerator
320 * GroupURLLink used to generate URL
322 * Object array returned from the makeUrlStubs function.
324 static void addshowLink(JMenu linkMenu, String label,
325 final GroupUrlLink urlgenerator, final Object[] urlstub)
327 JMenuItem item = new JMenuItem(label);
328 item.setToolTipText(MessageManager
329 .formatMessage("label.open_url_seqs_param", new Object[]
330 { urlgenerator.getUrl_prefix(),
331 urlgenerator.getNumberInvolved(urlstub) }));
332 // TODO: put in info about what is being sent.
333 item.addActionListener(new ActionListener()
336 public void actionPerformed(ActionEvent e)
338 new Thread(new Runnable()
346 showLink(urlgenerator.constructFrom(urlstub));
347 } catch (UrlStringTooLongException e2)
360 * Creates a new PopupMenu object.
365 * non-positional features (for seq not null), or positional features
366 * at residue (for seq equal to null)
368 public PopupMenu(final AlignmentPanel ap, SequenceI seq,
369 List<SequenceFeature> features)
371 this(ap, seq, features, null);
379 * the sequence under the cursor if in the Id panel, null if in the
382 * non-positional features if in the Id panel, features at the
383 * clicked residue if in the sequence panel
386 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
387 List<SequenceFeature> features, List<String> groupLinks)
389 // /////////////////////////////////////////////////////////
390 // If this is activated from the sequence panel, the user may want to
391 // edit or annotate a particular residue. Therefore display the residue menu
393 // If from the IDPanel, we must display the sequence menu
394 // ////////////////////////////////////////////////////////
395 this.ap = alignPanel;
398 for (String ff : FileFormats.getInstance().getWritableFormats(true))
400 JMenuItem item = new JMenuItem(ff);
402 item.addActionListener(new ActionListener()
405 public void actionPerformed(ActionEvent e)
407 outputText_actionPerformed(e);
411 outputMenu.add(item);
415 * Build menus for annotation types that may be shown or hidden, and for
416 * 'reference annotations' that may be added to the alignment. First for the
417 * currently selected sequence (if there is one):
419 final List<SequenceI> selectedSequence = (seq == null
420 ? Collections.<SequenceI> emptyList()
421 : Arrays.asList(seq));
422 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
423 seqHideAnnotationsMenu, selectedSequence);
424 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
428 * And repeat for the current selection group (if there is one):
430 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
431 ? Collections.<SequenceI> emptyList()
432 : alignPanel.av.getSelectionGroup().getSequences());
433 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
434 groupHideAnnotationsMenu, selectedGroup);
435 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
441 } catch (Exception e)
449 sequenceMenu.setText(sequence.getName());
450 if (seq == alignPanel.av.getAlignment().getSeqrep())
452 makeReferenceSeq.setText(
453 MessageManager.getString("action.unmark_as_reference"));
457 makeReferenceSeq.setText(
458 MessageManager.getString("action.set_as_reference"));
461 if (!alignPanel.av.getAlignment().isNucleotide())
463 remove(rnaStructureMenu);
467 int origCount = rnaStructureMenu.getItemCount();
469 * add menu items to 2D-render any alignment or sequence secondary
470 * structure annotation
472 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
473 .getAlignmentAnnotation();
476 for (final AlignmentAnnotation aa : aas)
478 if (aa.isValidStruc() && aa.sequenceRef == null)
481 * valid alignment RNA secondary structure annotation
483 menuItem = new JMenuItem();
484 menuItem.setText(MessageManager.formatMessage(
485 "label.2d_rna_structure_line", new Object[]
487 menuItem.addActionListener(new ActionListener()
490 public void actionPerformed(ActionEvent e)
492 new AppVarna(seq, aa, alignPanel);
495 rnaStructureMenu.add(menuItem);
500 if (seq.getAnnotation() != null)
502 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
503 for (final AlignmentAnnotation aa : seqAnns)
505 if (aa.isValidStruc())
508 * valid sequence RNA secondary structure annotation
510 // TODO: make rnastrucF a bit more nice
511 menuItem = new JMenuItem();
512 menuItem.setText(MessageManager.formatMessage(
513 "label.2d_rna_sequence_name", new Object[]
515 menuItem.addActionListener(new ActionListener()
518 public void actionPerformed(ActionEvent e)
520 // TODO: VARNA does'nt print gaps in the sequence
521 new AppVarna(seq, aa, alignPanel);
524 rnaStructureMenu.add(menuItem);
528 if (rnaStructureMenu.getItemCount() == origCount)
530 remove(rnaStructureMenu);
534 menuItem = new JMenuItem(
535 MessageManager.getString("action.hide_sequences"));
536 menuItem.addActionListener(new ActionListener()
539 public void actionPerformed(ActionEvent e)
541 hideSequences(false);
546 if (alignPanel.av.getSelectionGroup() != null
547 && alignPanel.av.getSelectionGroup().getSize() > 1)
549 menuItem = new JMenuItem(MessageManager
550 .formatMessage("label.represent_group_with", new Object[]
552 menuItem.addActionListener(new ActionListener()
555 public void actionPerformed(ActionEvent e)
560 sequenceMenu.add(menuItem);
563 if (alignPanel.av.hasHiddenRows())
565 final int index = alignPanel.av.getAlignment().findIndex(seq);
567 if (alignPanel.av.adjustForHiddenSeqs(index)
568 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
570 menuItem = new JMenuItem(
571 MessageManager.getString("action.reveal_sequences"));
572 menuItem.addActionListener(new ActionListener()
575 public void actionPerformed(ActionEvent e)
577 alignPanel.av.showSequence(index);
578 if (alignPanel.overviewPanel != null)
580 alignPanel.overviewPanel.updateOverviewImage();
591 * - in the IdPanel (seq not null) if any sequence is hidden
592 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
594 if (alignPanel.av.hasHiddenRows())
596 boolean addOption = seq != null;
597 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
603 menuItem = new JMenuItem(
604 MessageManager.getString("action.reveal_all"));
605 menuItem.addActionListener(new ActionListener()
608 public void actionPerformed(ActionEvent e)
610 alignPanel.av.showAllHiddenSeqs();
611 if (alignPanel.overviewPanel != null)
613 alignPanel.overviewPanel.updateOverviewImage();
621 SequenceGroup sg = alignPanel.av.getSelectionGroup();
622 boolean isDefinedGroup = (sg != null)
623 ? alignPanel.av.getAlignment().getGroups().contains(sg)
626 if (sg != null && sg.getSize() > 0)
628 groupName.setText(MessageManager
629 .getString("label.edit_name_and_description_current_group"));
631 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
633 conservationMenuItem.setEnabled(!sg.isNucleotide());
637 if (sg.cs.conservationApplied())
639 conservationMenuItem.setSelected(true);
641 if (sg.cs.getThreshold() > 0)
643 abovePIDColour.setSelected(true);
646 modifyConservation.setEnabled(conservationMenuItem.isSelected());
647 modifyPID.setEnabled(abovePIDColour.isSelected());
648 displayNonconserved.setSelected(sg.getShowNonconserved());
649 showText.setSelected(sg.getDisplayText());
650 showColourText.setSelected(sg.getColourText());
651 showBoxes.setSelected(sg.getDisplayBoxes());
652 // add any groupURLs to the groupURL submenu and make it visible
653 if (groupLinks != null && groupLinks.size() > 0)
655 buildGroupURLMenu(sg, groupLinks);
657 // Add a 'show all structures' for the current selection
658 Hashtable<String, PDBEntry> pdbe = new Hashtable<>(), reppdb = new Hashtable<>();
660 SequenceI sqass = null;
661 for (SequenceI sq : alignPanel.av.getSequenceSelection())
663 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
664 if (pes != null && pes.size() > 0)
666 reppdb.put(pes.get(0).getId(), pes.get(0));
667 for (PDBEntry pe : pes)
669 pdbe.put(pe.getId(), pe);
679 final PDBEntry[] pe = pdbe.values()
680 .toArray(new PDBEntry[pdbe.size()]),
681 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
682 final JMenuItem gpdbview, rpdbview;
687 groupMenu.setVisible(false);
688 editMenu.setVisible(false);
693 createGroupMenuItem.setVisible(true);
694 unGroupMenuItem.setVisible(false);
695 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
699 createGroupMenuItem.setVisible(false);
700 unGroupMenuItem.setVisible(true);
701 jMenu1.setText(MessageManager.getString("action.edit_group"));
706 sequenceMenu.setVisible(false);
707 pdbStructureDialog.setVisible(false);
708 rnaStructureMenu.setVisible(false);
711 addLinks(seq, features);
715 addFeatureDetails(features);
720 * Add a link to show feature details for each sequence feature
724 protected void addFeatureDetails(List<SequenceFeature> features)
726 if (features == null || features.isEmpty())
730 JMenu details = new JMenu(
731 MessageManager.getString("label.feature_details"));
734 for (final SequenceFeature sf : features)
736 int start = sf.getBegin();
737 int end = sf.getEnd();
741 desc = String.format("%s %d", sf.getType(), start);
745 desc = String.format("%s %d-%d", sf.getType(), start, end);
747 String tooltip = desc;
748 String description = sf.getDescription();
749 if (description != null)
751 description = StringUtils.stripHtmlTags(description);
752 if (description.length() > 12)
754 desc = desc + " " + description.substring(0, 12) + "..";
758 desc = desc + " " + description;
760 tooltip = tooltip + " " + description;
762 if (sf.getFeatureGroup() != null)
764 tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
766 JMenuItem item = new JMenuItem(desc);
767 item.setToolTipText(tooltip);
768 item.addActionListener(new ActionListener()
771 public void actionPerformed(ActionEvent e)
773 showFeatureDetails(sf);
781 * Opens a panel showing a text report of feature dteails
785 protected void showFeatureDetails(SequenceFeature sf)
787 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
788 // it appears Java's CSS does not support border-collaps :-(
789 cap.addStylesheetRule("table { border-collapse: collapse;}");
790 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
791 cap.setText(sf.getDetailsReport());
793 Desktop.addInternalFrame(cap,
794 MessageManager.getString("label.feature_details"), 500, 500);
798 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
799 * When seq is not null, these are links for the sequence id, which may be to
800 * external web sites for the sequence accession, and/or links embedded in
801 * non-positional features. When seq is null, only links embedded in the
802 * provided features are added. If no links are found, the menu is not added.
807 void addLinks(final SequenceI seq, List<SequenceFeature> features)
809 JMenu linkMenu = buildLinkMenu(seq, features);
811 // only add link menu if it has entries
812 if (linkMenu.getItemCount() > 0)
814 if (sequence != null)
816 sequenceMenu.add(linkMenu);
826 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
827 * "All" is added first, followed by a separator. Then add any annotation
828 * types associated with the current selection. Separate menus are built for
829 * the selected sequence group (if any), and the selected sequence.
831 * Some annotation rows are always rendered together - these can be identified
832 * by a common graphGroup property > -1. Only one of each group will be marked
833 * as visible (to avoid duplication of the display). For such groups we add a
834 * composite type name, e.g.
836 * IUPredWS (Long), IUPredWS (Short)
840 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
841 List<SequenceI> forSequences)
843 showMenu.removeAll();
844 hideMenu.removeAll();
846 final List<String> all = Arrays
848 { MessageManager.getString("label.all") });
849 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
851 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
853 showMenu.addSeparator();
854 hideMenu.addSeparator();
856 final AlignmentAnnotation[] annotations = ap.getAlignment()
857 .getAlignmentAnnotation();
860 * Find shown/hidden annotations types, distinguished by source (calcId),
861 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
862 * the insertion order, which is the order of the annotations on the
865 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
866 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
867 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
868 AlignmentAnnotationUtils.asList(annotations), forSequences);
870 for (String calcId : hiddenTypes.keySet())
872 for (List<String> type : hiddenTypes.get(calcId))
874 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
878 // grey out 'show annotations' if none are hidden
879 showMenu.setEnabled(!hiddenTypes.isEmpty());
881 for (String calcId : shownTypes.keySet())
883 for (List<String> type : shownTypes.get(calcId))
885 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
889 // grey out 'hide annotations' if none are shown
890 hideMenu.setEnabled(!shownTypes.isEmpty());
894 * Returns a list of sequences - either the current selection group (if there
895 * is one), else the specified single sequence.
900 protected List<SequenceI> getSequenceScope(SequenceI seq)
902 List<SequenceI> forSequences = null;
903 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
904 if (selectionGroup != null && selectionGroup.getSize() > 0)
906 forSequences = selectionGroup.getSequences();
910 forSequences = seq == null ? Collections.<SequenceI> emptyList()
911 : Arrays.asList(seq);
917 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
920 * @param showOrHideMenu
922 * @param forSequences
923 * the sequences whose annotations may be shown or hidden
928 * if true this is a special label meaning 'All'
929 * @param actionIsShow
930 * if true, the select menu item action is to show the annotation
933 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
934 final List<SequenceI> forSequences, String calcId,
935 final List<String> types, final boolean allTypes,
936 final boolean actionIsShow)
938 String label = types.toString(); // [a, b, c]
939 label = label.substring(1, label.length() - 1); // a, b, c
940 final JMenuItem item = new JMenuItem(label);
941 item.setToolTipText(calcId);
942 item.addActionListener(new ActionListener()
945 public void actionPerformed(ActionEvent e)
947 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
948 types, forSequences, allTypes, actionIsShow);
952 showOrHideMenu.add(item);
955 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
958 // TODO: usability: thread off the generation of group url content so root
960 // sequence only URLs
961 // ID/regex match URLs
962 groupLinksMenu = new JMenu(
963 MessageManager.getString("action.group_link"));
964 // three types of url that might be created.
965 JMenu[] linkMenus = new JMenu[] { null,
966 new JMenu(MessageManager.getString("action.ids")),
967 new JMenu(MessageManager.getString("action.sequences")),
968 new JMenu(MessageManager.getString("action.ids_sequences")) };
970 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
971 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
972 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
973 for (int sq = 0; sq < seqs.length; sq++)
976 int start = seqs[sq].findPosition(sg.getStartRes()),
977 end = seqs[sq].findPosition(sg.getEndRes());
978 // just collect ids from dataset sequence
979 // TODO: check if IDs collected from selecton group intersects with the
980 // current selection, too
981 SequenceI sqi = seqs[sq];
982 while (sqi.getDatasetSequence() != null)
984 sqi = sqi.getDatasetSequence();
986 DBRefEntry[] dbr = sqi.getDBRefs();
987 if (dbr != null && dbr.length > 0)
989 for (int d = 0; d < dbr.length; d++)
991 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
992 Object[] sarray = commonDbrefs.get(src);
995 sarray = new Object[2];
996 sarray[0] = new int[] { 0 };
997 sarray[1] = new String[seqs.length];
999 commonDbrefs.put(src, sarray);
1002 if (((String[]) sarray[1])[sq] == null)
1004 if (!dbr[d].hasMap() || (dbr[d].getMap()
1005 .locateMappedRange(start, end) != null))
1007 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1008 ((int[]) sarray[0])[0]++;
1014 // now create group links for all distinct ID/sequence sets.
1015 boolean addMenu = false; // indicates if there are any group links to give
1017 for (String link : groupLinks)
1019 GroupUrlLink urlLink = null;
1022 urlLink = new GroupUrlLink(link);
1023 } catch (Exception foo)
1025 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
1029 if (!urlLink.isValid())
1031 Cache.log.error(urlLink.getInvalidMessage());
1034 final String label = urlLink.getLabel();
1035 boolean usingNames = false;
1036 // Now see which parts of the group apply for this URL
1037 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1038 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
1039 String[] seqstr, ids; // input to makeUrl
1042 int numinput = ((int[]) idset[0])[0];
1043 String[] allids = ((String[]) idset[1]);
1044 seqstr = new String[numinput];
1045 ids = new String[numinput];
1046 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1048 if (allids[sq] != null)
1050 ids[idcount] = allids[sq];
1051 seqstr[idcount++] = idandseqs[1][sq];
1057 // just use the id/seq set
1058 seqstr = idandseqs[1];
1062 // and try and make the groupURL!
1064 Object[] urlset = null;
1067 urlset = urlLink.makeUrlStubs(ids, seqstr,
1068 "FromJalview" + System.currentTimeMillis(), false);
1069 } catch (UrlStringTooLongException e)
1074 int type = urlLink.getGroupURLType() & 3;
1075 // first two bits ofurlLink type bitfield are sequenceids and sequences
1076 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1077 addshowLink(linkMenus[type],
1078 label + (((type & 1) == 1)
1079 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1087 groupLinksMenu = new JMenu(
1088 MessageManager.getString("action.group_link"));
1089 for (int m = 0; m < linkMenus.length; m++)
1091 if (linkMenus[m] != null
1092 && linkMenus[m].getMenuComponentCount() > 0)
1094 groupLinksMenu.add(linkMenus[m]);
1098 groupMenu.add(groupLinksMenu);
1108 private void jbInit() throws Exception
1110 groupMenu.setText(MessageManager.getString("label.selection"));
1111 groupName.setText(MessageManager.getString("label.name"));
1112 groupName.addActionListener(new ActionListener()
1115 public void actionPerformed(ActionEvent e)
1117 groupName_actionPerformed();
1120 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1121 sequenceName.setText(
1122 MessageManager.getString("label.edit_name_description"));
1123 sequenceName.addActionListener(new ActionListener()
1126 public void actionPerformed(ActionEvent e)
1128 sequenceName_actionPerformed();
1132 .setText(MessageManager.getString("action.choose_annotations"));
1133 chooseAnnotations.addActionListener(new ActionListener()
1136 public void actionPerformed(ActionEvent e)
1138 chooseAnnotations_actionPerformed(e);
1142 .setText(MessageManager.getString("label.sequence_details"));
1143 sequenceDetails.addActionListener(new ActionListener()
1146 public void actionPerformed(ActionEvent e)
1148 sequenceDetails_actionPerformed();
1152 .setText(MessageManager.getString("label.sequence_details"));
1153 sequenceSelDetails.addActionListener(new ActionListener()
1156 public void actionPerformed(ActionEvent e)
1158 sequenceSelectionDetails_actionPerformed();
1163 .setText(MessageManager.getString("action.remove_group"));
1164 unGroupMenuItem.addActionListener(new ActionListener()
1167 public void actionPerformed(ActionEvent e)
1169 unGroupMenuItem_actionPerformed();
1173 .setText(MessageManager.getString("action.create_group"));
1174 createGroupMenuItem.addActionListener(new ActionListener()
1177 public void actionPerformed(ActionEvent e)
1179 createGroupMenuItem_actionPerformed();
1183 outline.setText(MessageManager.getString("action.border_colour"));
1184 outline.addActionListener(new ActionListener()
1187 public void actionPerformed(ActionEvent e)
1189 outline_actionPerformed();
1192 showBoxes.setText(MessageManager.getString("action.boxes"));
1193 showBoxes.setState(true);
1194 showBoxes.addActionListener(new ActionListener()
1197 public void actionPerformed(ActionEvent e)
1199 showBoxes_actionPerformed();
1202 showText.setText(MessageManager.getString("action.text"));
1203 showText.setState(true);
1204 showText.addActionListener(new ActionListener()
1207 public void actionPerformed(ActionEvent e)
1209 showText_actionPerformed();
1212 showColourText.setText(MessageManager.getString("label.colour_text"));
1213 showColourText.addActionListener(new ActionListener()
1216 public void actionPerformed(ActionEvent e)
1218 showColourText_actionPerformed();
1222 .setText(MessageManager.getString("label.show_non_conserved"));
1223 displayNonconserved.setState(true);
1224 displayNonconserved.addActionListener(new ActionListener()
1227 public void actionPerformed(ActionEvent e)
1229 showNonconserved_actionPerformed();
1232 editMenu.setText(MessageManager.getString("action.edit"));
1233 cut.setText(MessageManager.getString("action.cut"));
1234 cut.addActionListener(new ActionListener()
1237 public void actionPerformed(ActionEvent e)
1239 cut_actionPerformed();
1242 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1243 upperCase.addActionListener(new ActionListener()
1246 public void actionPerformed(ActionEvent e)
1251 copy.setText(MessageManager.getString("action.copy"));
1252 copy.addActionListener(new ActionListener()
1255 public void actionPerformed(ActionEvent e)
1257 copy_actionPerformed();
1260 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1261 lowerCase.addActionListener(new ActionListener()
1264 public void actionPerformed(ActionEvent e)
1269 toggle.setText(MessageManager.getString("label.toggle_case"));
1270 toggle.addActionListener(new ActionListener()
1273 public void actionPerformed(ActionEvent e)
1279 MessageManager.getString("label.out_to_textbox") + "...");
1280 seqShowAnnotationsMenu
1281 .setText(MessageManager.getString("label.show_annotations"));
1282 seqHideAnnotationsMenu
1283 .setText(MessageManager.getString("label.hide_annotations"));
1284 groupShowAnnotationsMenu
1285 .setText(MessageManager.getString("label.show_annotations"));
1286 groupHideAnnotationsMenu
1287 .setText(MessageManager.getString("label.hide_annotations"));
1288 sequenceFeature.setText(
1289 MessageManager.getString("label.create_sequence_feature"));
1290 sequenceFeature.addActionListener(new ActionListener()
1293 public void actionPerformed(ActionEvent e)
1295 sequenceFeature_actionPerformed();
1298 jMenu1.setText(MessageManager.getString("label.group"));
1299 pdbStructureDialog.setText(
1300 MessageManager.getString("label.show_pdbstruct_dialog"));
1301 pdbStructureDialog.addActionListener(new ActionListener()
1304 public void actionPerformed(ActionEvent actionEvent)
1306 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1307 if (ap.av.getSelectionGroup() != null)
1309 selectedSeqs = ap.av.getSequenceSelection();
1311 new StructureChooser(selectedSeqs, sequence, ap);
1316 .setText(MessageManager.getString("label.view_rna_structure"));
1318 // colStructureMenu.setText("Colour By Structure");
1319 editSequence.setText(
1320 MessageManager.getString("label.edit_sequence") + "...");
1321 editSequence.addActionListener(new ActionListener()
1324 public void actionPerformed(ActionEvent actionEvent)
1326 editSequence_actionPerformed(actionEvent);
1329 makeReferenceSeq.setText(
1330 MessageManager.getString("label.mark_as_representative"));
1331 makeReferenceSeq.addActionListener(new ActionListener()
1335 public void actionPerformed(ActionEvent actionEvent)
1337 makeReferenceSeq_actionPerformed(actionEvent);
1342 .setText(MessageManager.getString("label.hide_insertions"));
1343 hideInsertions.addActionListener(new ActionListener()
1347 public void actionPerformed(ActionEvent e)
1349 hideInsertions_actionPerformed(e);
1353 groupMenu.add(sequenceSelDetails);
1356 add(rnaStructureMenu);
1357 add(pdbStructureDialog);
1358 if (sequence != null)
1360 add(hideInsertions);
1362 // annotations configuration panel suppressed for now
1363 // groupMenu.add(chooseAnnotations);
1366 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1367 * (if a selection group is in force).
1369 sequenceMenu.add(seqShowAnnotationsMenu);
1370 sequenceMenu.add(seqHideAnnotationsMenu);
1371 sequenceMenu.add(seqAddReferenceAnnotations);
1372 groupMenu.add(groupShowAnnotationsMenu);
1373 groupMenu.add(groupHideAnnotationsMenu);
1374 groupMenu.add(groupAddReferenceAnnotations);
1375 groupMenu.add(editMenu);
1376 groupMenu.add(outputMenu);
1377 groupMenu.add(sequenceFeature);
1378 groupMenu.add(createGroupMenuItem);
1379 groupMenu.add(unGroupMenuItem);
1380 groupMenu.add(jMenu1);
1381 sequenceMenu.add(sequenceName);
1382 sequenceMenu.add(sequenceDetails);
1383 sequenceMenu.add(makeReferenceSeq);
1390 editMenu.add(editSequence);
1391 editMenu.add(upperCase);
1392 editMenu.add(lowerCase);
1393 editMenu.add(toggle);
1394 // JBPNote: These shouldn't be added here - should appear in a generic
1395 // 'apply web service to this sequence menu'
1396 // pdbMenu.add(RNAFold);
1397 // pdbMenu.add(ContraFold);
1398 jMenu1.add(groupName);
1399 jMenu1.add(colourMenu);
1400 jMenu1.add(showBoxes);
1401 jMenu1.add(showText);
1402 jMenu1.add(showColourText);
1403 jMenu1.add(outline);
1404 jMenu1.add(displayNonconserved);
1408 * Constructs the entries for the colour menu
1410 protected void initColourMenu()
1412 colourMenu.setText(MessageManager.getString("label.group_colour"));
1413 textColour.setText(MessageManager.getString("label.text_colour"));
1414 textColour.addActionListener(new ActionListener()
1417 public void actionPerformed(ActionEvent e)
1419 textColour_actionPerformed();
1423 abovePIDColour.setText(
1424 MessageManager.getString("label.above_identity_threshold"));
1425 abovePIDColour.addActionListener(new ActionListener()
1428 public void actionPerformed(ActionEvent e)
1430 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1435 MessageManager.getString("label.modify_identity_threshold"));
1436 modifyPID.addActionListener(new ActionListener()
1439 public void actionPerformed(ActionEvent e)
1441 modifyPID_actionPerformed();
1445 conservationMenuItem
1446 .setText(MessageManager.getString("action.by_conservation"));
1447 conservationMenuItem.addActionListener(new ActionListener()
1450 public void actionPerformed(ActionEvent e)
1452 conservationMenuItem_actionPerformed(
1453 conservationMenuItem.isSelected());
1457 annotationColour = new JRadioButtonMenuItem(
1458 MessageManager.getString("action.by_annotation"));
1459 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1460 annotationColour.setEnabled(false);
1461 annotationColour.setToolTipText(
1462 MessageManager.getString("label.by_annotation_tooltip"));
1464 modifyConservation.setText(MessageManager
1465 .getString("label.modify_conservation_threshold"));
1466 modifyConservation.addActionListener(new ActionListener()
1469 public void actionPerformed(ActionEvent e)
1471 modifyConservation_actionPerformed();
1477 * Builds the group colour sub-menu, including any user-defined colours which
1478 * were loaded at startup or during the Jalview session
1480 protected void buildColourMenu()
1482 SequenceGroup sg = ap.av.getSelectionGroup();
1486 * popup menu with no sequence group scope
1490 colourMenu.removeAll();
1491 colourMenu.add(textColour);
1492 colourMenu.addSeparator();
1494 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1496 bg.add(annotationColour);
1497 colourMenu.add(annotationColour);
1499 colourMenu.addSeparator();
1500 colourMenu.add(conservationMenuItem);
1501 colourMenu.add(modifyConservation);
1502 colourMenu.add(abovePIDColour);
1503 colourMenu.add(modifyPID);
1506 protected void modifyConservation_actionPerformed()
1508 SequenceGroup sg = getGroup();
1511 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1512 SliderPanel.showConservationSlider();
1516 protected void modifyPID_actionPerformed()
1518 SequenceGroup sg = getGroup();
1521 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1523 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1524 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1525 SliderPanel.showPIDSlider();
1530 * Check for any annotations on the underlying dataset sequences (for the
1531 * current selection group) which are not 'on the alignment'.If any are found,
1532 * enable the option to add them to the alignment. The criteria for 'on the
1533 * alignment' is finding an alignment annotation on the alignment, matched on
1534 * calcId, label and sequenceRef.
1536 * A tooltip is also constructed that displays the source (calcId) and type
1537 * (label) of the annotations that can be added.
1540 * @param forSequences
1542 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1543 List<SequenceI> forSequences)
1545 menuItem.setEnabled(false);
1548 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1549 * Using TreeMap means calcIds are shown in alphabetical order.
1551 SortedMap<String, String> tipEntries = new TreeMap<>();
1552 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1553 AlignmentI al = this.ap.av.getAlignment();
1554 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1556 if (!candidates.isEmpty())
1558 StringBuilder tooltip = new StringBuilder(64);
1559 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1562 * Found annotations that could be added. Enable the menu item, and
1563 * configure its tooltip and action.
1565 menuItem.setEnabled(true);
1566 for (String calcId : tipEntries.keySet())
1568 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1570 String tooltipText = JvSwingUtils.wrapTooltip(true,
1571 tooltip.toString());
1572 menuItem.setToolTipText(tooltipText);
1574 menuItem.addActionListener(new ActionListener()
1577 public void actionPerformed(ActionEvent e)
1579 addReferenceAnnotations_actionPerformed(candidates);
1586 * Add annotations to the sequences and to the alignment.
1589 * a map whose keys are sequences on the alignment, and values a list
1590 * of annotations to add to each sequence
1592 protected void addReferenceAnnotations_actionPerformed(
1593 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1595 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1596 final AlignmentI alignment = this.ap.getAlignment();
1597 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1602 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1604 if (!ap.av.getAlignment().hasSeqrep())
1606 // initialise the display flags so the user sees something happen
1607 ap.av.setDisplayReferenceSeq(true);
1608 ap.av.setColourByReferenceSeq(true);
1609 ap.av.getAlignment().setSeqrep(sequence);
1613 if (ap.av.getAlignment().getSeqrep() == sequence)
1615 ap.av.getAlignment().setSeqrep(null);
1619 ap.av.getAlignment().setSeqrep(sequence);
1625 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1627 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1628 BitSet inserts = new BitSet();
1630 boolean markedPopup = false;
1631 // mark inserts in current selection
1632 if (ap.av.getSelectionGroup() != null)
1634 // mark just the columns in the selection group to be hidden
1635 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1636 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1638 // now clear columns without gaps
1639 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1645 inserts.and(sq.getInsertionsAsBits());
1647 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1648 ap.av.getSelectionGroup().getEndRes());
1651 // now mark for sequence under popup if we haven't already done it
1652 else if (!markedPopup && sequence != null)
1654 inserts.or(sequence.getInsertionsAsBits());
1656 // and set hidden columns accordingly
1657 hidden.hideColumns(inserts);
1662 protected void sequenceSelectionDetails_actionPerformed()
1664 createSequenceDetailsReport(ap.av.getSequenceSelection());
1667 protected void sequenceDetails_actionPerformed()
1669 createSequenceDetailsReport(new SequenceI[] { sequence });
1672 public void createSequenceDetailsReport(SequenceI[] sequences)
1674 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1675 StringBuilder contents = new StringBuilder(128);
1676 for (SequenceI seq : sequences)
1678 contents.append("<p><h2>" + MessageManager.formatMessage(
1679 "label.create_sequence_details_report_annotation_for",
1681 { seq.getDisplayId(true) }) + "</h2></p><p>");
1682 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
1683 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1684 contents.append("</p>");
1686 cap.setText("<html>" + contents.toString() + "</html>");
1688 Desktop.addInternalFrame(cap,
1689 MessageManager.formatMessage("label.sequence_details_for",
1690 (sequences.length == 1 ? new Object[]
1691 { sequences[0].getDisplayId(true) }
1694 .getString("label.selection") })),
1699 protected void showNonconserved_actionPerformed()
1701 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1706 * call to refresh view after settings change
1710 ap.updateAnnotation();
1711 // removed paintAlignment(true) here:
1712 // updateAnnotation calls paintAlignment already, so don't need to call
1715 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1719 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1720 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1730 public void abovePIDColour_actionPerformed(boolean selected)
1732 SequenceGroup sg = getGroup();
1740 sg.cs.setConsensus(AAFrequency.calculate(
1741 sg.getSequences(ap.av.getHiddenRepSequences()),
1742 sg.getStartRes(), sg.getEndRes() + 1));
1744 int threshold = SliderPanel.setPIDSliderSource(ap,
1745 sg.getGroupColourScheme(), getGroup().getName());
1747 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1749 SliderPanel.showPIDSlider();
1752 // remove PIDColouring
1754 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1755 SliderPanel.hidePIDSlider();
1757 modifyPID.setEnabled(selected);
1763 * Open a panel where the user can choose which types of sequence annotation
1768 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1770 // todo correct way to guard against opening a duplicate panel?
1771 new AnnotationChooser(ap);
1780 public void conservationMenuItem_actionPerformed(boolean selected)
1782 SequenceGroup sg = getGroup();
1790 // JBPNote: Conservation name shouldn't be i18n translated
1791 Conservation c = new Conservation("Group",
1792 sg.getSequences(ap.av.getHiddenRepSequences()),
1793 sg.getStartRes(), sg.getEndRes() + 1);
1796 c.verdict(false, ap.av.getConsPercGaps());
1797 sg.cs.setConservation(c);
1799 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1801 SliderPanel.showConservationSlider();
1804 // remove ConservationColouring
1806 sg.cs.setConservation(null);
1807 SliderPanel.hideConservationSlider();
1809 modifyConservation.setEnabled(selected);
1820 protected void groupName_actionPerformed()
1823 SequenceGroup sg = getGroup();
1824 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1825 sg.getDescription(),
1826 " " + MessageManager.getString("label.group_name") + " ",
1827 MessageManager.getString("label.group_description") + " ",
1828 MessageManager.getString("label.edit_group_name_description"),
1836 sg.setName(dialog.getName());
1837 sg.setDescription(dialog.getDescription());
1842 * Get selection group - adding it to the alignment if necessary.
1844 * @return sequence group to operate on
1846 SequenceGroup getGroup()
1848 SequenceGroup sg = ap.av.getSelectionGroup();
1849 // this method won't add a new group if it already exists
1852 ap.av.getAlignment().addGroup(sg);
1864 void sequenceName_actionPerformed()
1866 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1867 sequence.getDescription(),
1868 " " + MessageManager.getString("label.sequence_name")
1870 MessageManager.getString("label.sequence_description") + " ",
1871 MessageManager.getString(
1872 "label.edit_sequence_name_description"),
1880 if (dialog.getName() != null)
1882 if (dialog.getName().indexOf(" ") > -1)
1884 JvOptionPane.showMessageDialog(ap,
1886 .getString("label.spaces_converted_to_backslashes"),
1888 .getString("label.no_spaces_allowed_sequence_name"),
1889 JvOptionPane.WARNING_MESSAGE);
1892 sequence.setName(dialog.getName().replace(' ', '_'));
1893 ap.paintAlignment(false, false);
1896 sequence.setDescription(dialog.getDescription());
1898 ap.av.firePropertyChange("alignment", null,
1899 ap.av.getAlignment().getSequences());
1909 void unGroupMenuItem_actionPerformed()
1911 SequenceGroup sg = ap.av.getSelectionGroup();
1912 ap.av.getAlignment().deleteGroup(sg);
1913 ap.av.setSelectionGroup(null);
1917 void createGroupMenuItem_actionPerformed()
1919 getGroup(); // implicitly creates group - note - should apply defaults / use
1920 // standard alignment window logic for this
1930 protected void outline_actionPerformed()
1932 SequenceGroup sg = getGroup();
1933 Color col = JColorChooser.showDialog(this,
1934 MessageManager.getString("label.select_outline_colour"),
1939 sg.setOutlineColour(col);
1951 public void showBoxes_actionPerformed()
1953 getGroup().setDisplayBoxes(showBoxes.isSelected());
1963 public void showText_actionPerformed()
1965 getGroup().setDisplayText(showText.isSelected());
1975 public void showColourText_actionPerformed()
1977 getGroup().setColourText(showColourText.isSelected());
1981 void hideSequences(boolean representGroup)
1983 ap.av.hideSequences(sequence, representGroup);
1986 public void copy_actionPerformed()
1988 ap.alignFrame.copy_actionPerformed(null);
1991 public void cut_actionPerformed()
1993 ap.alignFrame.cut_actionPerformed(null);
1996 void changeCase(ActionEvent e)
1998 Object source = e.getSource();
1999 SequenceGroup sg = ap.av.getSelectionGroup();
2003 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2004 sg.getStartRes(), sg.getEndRes() + 1);
2009 if (source == toggle)
2011 description = MessageManager.getString("label.toggle_case");
2012 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2014 else if (source == upperCase)
2016 description = MessageManager.getString("label.to_upper_case");
2017 caseChange = ChangeCaseCommand.TO_UPPER;
2021 description = MessageManager.getString("label.to_lower_case");
2022 caseChange = ChangeCaseCommand.TO_LOWER;
2025 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2026 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2027 startEnd, caseChange);
2029 ap.alignFrame.addHistoryItem(caseCommand);
2031 ap.av.firePropertyChange("alignment", null,
2032 ap.av.getAlignment().getSequences());
2037 public void outputText_actionPerformed(ActionEvent e)
2039 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2040 cap.setForInput(null);
2041 Desktop.addInternalFrame(cap, MessageManager
2042 .formatMessage("label.alignment_output_command", new Object[]
2043 { e.getActionCommand() }), 600, 500);
2045 String[] omitHidden = null;
2047 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2048 // or we simply trust the user wants
2049 // wysiwig behaviour
2051 FileFormatI fileFormat = FileFormats.getInstance()
2052 .forName(e.getActionCommand());
2054 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2057 public void sequenceFeature_actionPerformed()
2059 SequenceGroup sg = ap.av.getSelectionGroup();
2065 List<SequenceI> seqs = new ArrayList<>();
2066 List<SequenceFeature> features = new ArrayList<>();
2069 * assemble dataset sequences, and template new sequence features,
2070 * for the amend features dialog
2072 int gSize = sg.getSize();
2073 for (int i = 0; i < gSize; i++)
2075 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2076 int end = sg.findEndRes(sg.getSequenceAt(i));
2079 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2080 features.add(new SequenceFeature(null, null, start, end, null));
2085 * an entirely gapped region will generate empty lists of sequence / features
2087 if (!seqs.isEmpty())
2089 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer()
2090 .amendFeatures(seqs, features, true, ap))
2092 ap.alignFrame.setShowSeqFeatures(true);
2093 ap.av.setSearchResults(null); // clear highlighting
2094 ap.repaint(); // draw new/amended features
2099 public void textColour_actionPerformed()
2101 SequenceGroup sg = getGroup();
2104 new TextColourChooser().chooseColour(ap, sg);
2108 public void colourByStructure(String pdbid)
2110 Annotation[] anots = ap.av.getStructureSelectionManager()
2111 .colourSequenceFromStructure(sequence, pdbid);
2113 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2114 "Coloured by " + pdbid, anots);
2116 ap.av.getAlignment().addAnnotation(an);
2117 an.createSequenceMapping(sequence, 0, true);
2118 // an.adjustForAlignment();
2119 ap.av.getAlignment().setAnnotationIndex(an, 0);
2121 ap.adjustAnnotationHeight();
2123 sequence.addAlignmentAnnotation(an);
2127 public void editSequence_actionPerformed(ActionEvent actionEvent)
2129 SequenceGroup sg = ap.av.getSelectionGroup();
2133 if (sequence == null)
2135 sequence = sg.getSequenceAt(0);
2138 EditNameDialog dialog = new EditNameDialog(
2139 sequence.getSequenceAsString(sg.getStartRes(),
2140 sg.getEndRes() + 1),
2141 null, MessageManager.getString("label.edit_sequence"), null,
2142 MessageManager.getString("label.edit_sequence"),
2147 EditCommand editCommand = new EditCommand(
2148 MessageManager.getString("label.edit_sequences"),
2150 dialog.getName().replace(' ', ap.av.getGapCharacter()),
2151 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2152 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2154 ap.alignFrame.addHistoryItem(editCommand);
2156 ap.av.firePropertyChange("alignment", null,
2157 ap.av.getAlignment().getSequences());
2163 * Action on user selecting an item from the colour menu (that does not have
2164 * its bespoke action handler)
2169 public void changeColour_actionPerformed(String colourSchemeName)
2171 SequenceGroup sg = getGroup();
2173 * switch to the chosen colour scheme (or null for None)
2175 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2176 .getColourScheme(colourSchemeName, ap.av, sg,
2177 ap.av.getHiddenRepSequences());
2178 sg.setColourScheme(colourScheme);
2179 if (colourScheme instanceof Blosum62ColourScheme
2180 || colourScheme instanceof PIDColourScheme)
2182 sg.cs.setConsensus(AAFrequency.calculate(
2183 sg.getSequences(ap.av.getHiddenRepSequences()),
2184 sg.getStartRes(), sg.getEndRes() + 1));