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();
165 JMenuItem textColour = new JMenuItem();
167 JMenu jMenu1 = new JMenu();
169 JMenuItem pdbStructureDialog = new JMenuItem();
171 JMenu rnaStructureMenu = new JMenu();
173 JMenuItem editSequence = new JMenuItem();
175 JMenu groupLinksMenu;
177 JMenuItem hideInsertions = new JMenuItem();
180 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
181 * and/or features provided. Hyperlinks may include a lookup by sequence id,
182 * or database cross-references, depending on which links are enabled in user
189 static JMenu buildLinkMenu(final SequenceI seq,
190 List<SequenceFeature> features)
192 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
194 List<String> nlinks = null;
197 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
198 UrlLink.sort(nlinks);
202 nlinks = new ArrayList<>();
205 if (features != null)
207 for (SequenceFeature sf : features)
209 if (sf.links != null)
211 for (String link : sf.links)
220 * instantiate the hyperlinklink templates from sequence data;
221 * note the order of the templates is preserved in the map
223 Map<String, List<String>> linkset = new LinkedHashMap<>();
224 for (String link : nlinks)
226 UrlLink urlLink = null;
229 urlLink = new UrlLink(link);
230 } catch (Exception foo)
232 Cache.log.error("Exception for URLLink '" + link + "'", foo);
236 if (!urlLink.isValid())
238 Cache.log.error(urlLink.getInvalidMessage());
242 urlLink.createLinksFromSeq(seq, linkset);
246 * construct menu items for the hyperlinks (still preserving
247 * the order of the sorted templates)
249 addUrlLinks(linkMenu, linkset.values());
255 * A helper method that builds menu items from the given links, with action
256 * handlers to open the link URL, and adds them to the linkMenu. Each provided
257 * link should be a list whose second item is the menu text, and whose fourth
258 * item is the URL to open when the menu item is selected.
263 static private void addUrlLinks(JMenu linkMenu,
264 Collection<List<String>> linkset)
266 for (List<String> linkstrset : linkset)
268 final String url = linkstrset.get(3);
269 JMenuItem item = new JMenuItem(linkstrset.get(1));
270 item.setToolTipText(MessageManager
271 .formatMessage("label.open_url_param", new Object[]
273 item.addActionListener(new ActionListener()
276 public void actionPerformed(ActionEvent e)
278 new Thread(new Runnable()
293 * Opens the provided url in the default web browser, or shows an error
294 * message if this fails
298 static void showLink(String url)
302 jalview.util.BrowserLauncher.openURL(url);
303 } catch (Exception ex)
305 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
306 MessageManager.getString("label.web_browser_not_found_unix"),
307 MessageManager.getString("label.web_browser_not_found"),
308 JvOptionPane.WARNING_MESSAGE);
310 ex.printStackTrace();
315 * add a late bound groupURL item to the given linkMenu
319 * - menu label string
320 * @param urlgenerator
321 * GroupURLLink used to generate URL
323 * Object array returned from the makeUrlStubs function.
325 static void addshowLink(JMenu linkMenu, String label,
326 final GroupUrlLink urlgenerator, final Object[] urlstub)
328 JMenuItem item = new JMenuItem(label);
329 item.setToolTipText(MessageManager
330 .formatMessage("label.open_url_seqs_param", new Object[]
331 { urlgenerator.getUrl_prefix(),
332 urlgenerator.getNumberInvolved(urlstub) }));
333 // TODO: put in info about what is being sent.
334 item.addActionListener(new ActionListener()
337 public void actionPerformed(ActionEvent e)
339 new Thread(new Runnable()
347 showLink(urlgenerator.constructFrom(urlstub));
348 } catch (UrlStringTooLongException e2)
361 * Creates a new PopupMenu object.
366 * non-positional features (for seq not null), or positional features
367 * at residue (for seq equal to null)
369 public PopupMenu(final AlignmentPanel ap, SequenceI seq,
370 List<SequenceFeature> features)
372 this(ap, seq, features, null);
380 * the sequence under the cursor if in the Id panel, null if in the
383 * non-positional features if in the Id panel, features at the
384 * clicked residue if in the sequence panel
387 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
388 List<SequenceFeature> features, List<String> groupLinks)
390 // /////////////////////////////////////////////////////////
391 // If this is activated from the sequence panel, the user may want to
392 // edit or annotate a particular residue. Therefore display the residue menu
394 // If from the IDPanel, we must display the sequence menu
395 // ////////////////////////////////////////////////////////
396 this.ap = alignPanel;
399 for (String ff : FileFormats.getInstance().getWritableFormats(true))
401 JMenuItem item = new JMenuItem(ff);
403 item.addActionListener(new ActionListener()
406 public void actionPerformed(ActionEvent e)
408 outputText_actionPerformed(e);
412 outputMenu.add(item);
416 * Build menus for annotation types that may be shown or hidden, and for
417 * 'reference annotations' that may be added to the alignment. First for the
418 * currently selected sequence (if there is one):
420 final List<SequenceI> selectedSequence = (seq == null
421 ? Collections.<SequenceI> emptyList() : Arrays.asList(seq));
423 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
424 seqHideAnnotationsMenu, selectedSequence);
425 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
429 * And repeat for the current selection group (if there is one):
431 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
432 ? Collections.<SequenceI> emptyList()
433 : alignPanel.av.getSelectionGroup().getSequences());
434 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
435 groupHideAnnotationsMenu, selectedGroup);
436 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
442 } catch (Exception e)
450 sequenceMenu.setText(sequence.getName());
451 if (seq == alignPanel.av.getAlignment().getSeqrep())
453 makeReferenceSeq.setText(
454 MessageManager.getString("action.unmark_as_reference"));
458 makeReferenceSeq.setText(
459 MessageManager.getString("action.set_as_reference"));
462 if (!alignPanel.av.getAlignment().isNucleotide())
464 remove(rnaStructureMenu);
468 int origCount = rnaStructureMenu.getItemCount();
470 * add menu items to 2D-render any alignment or sequence secondary
471 * structure annotation
473 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
474 .getAlignmentAnnotation();
477 for (final AlignmentAnnotation aa : aas)
479 if (aa.isValidStruc() && aa.sequenceRef == null)
482 * valid alignment RNA secondary structure annotation
484 menuItem = new JMenuItem();
485 menuItem.setText(MessageManager.formatMessage(
486 "label.2d_rna_structure_line", new Object[]
488 menuItem.addActionListener(new ActionListener()
491 public void actionPerformed(ActionEvent e)
493 new AppVarna(seq, aa, alignPanel);
496 rnaStructureMenu.add(menuItem);
501 if (seq.getAnnotation() != null)
503 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
504 for (final AlignmentAnnotation aa : seqAnns)
506 if (aa.isValidStruc())
509 * valid sequence RNA secondary structure annotation
511 // TODO: make rnastrucF a bit more nice
512 menuItem = new JMenuItem();
513 menuItem.setText(MessageManager.formatMessage(
514 "label.2d_rna_sequence_name", new Object[]
516 menuItem.addActionListener(new ActionListener()
519 public void actionPerformed(ActionEvent e)
521 // TODO: VARNA does'nt print gaps in the sequence
522 new AppVarna(seq, aa, alignPanel);
525 rnaStructureMenu.add(menuItem);
529 if (rnaStructureMenu.getItemCount() == origCount)
531 remove(rnaStructureMenu);
535 menuItem = new JMenuItem(
536 MessageManager.getString("action.hide_sequences"));
537 menuItem.addActionListener(new ActionListener()
540 public void actionPerformed(ActionEvent e)
542 hideSequences(false);
547 if (alignPanel.av.getSelectionGroup() != null
548 && alignPanel.av.getSelectionGroup().getSize() > 1)
550 menuItem = new JMenuItem(MessageManager
551 .formatMessage("label.represent_group_with", new Object[]
553 menuItem.addActionListener(new ActionListener()
556 public void actionPerformed(ActionEvent e)
561 sequenceMenu.add(menuItem);
564 if (alignPanel.av.hasHiddenRows())
566 final int index = alignPanel.av.getAlignment().findIndex(seq);
568 if (alignPanel.av.adjustForHiddenSeqs(index)
569 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
571 menuItem = new JMenuItem(
572 MessageManager.getString("action.reveal_sequences"));
573 menuItem.addActionListener(new ActionListener()
576 public void actionPerformed(ActionEvent e)
578 alignPanel.av.showSequence(index);
579 if (alignPanel.overviewPanel != null)
581 alignPanel.overviewPanel.updateOverviewImage();
592 * - in the IdPanel (seq not null) if any sequence is hidden
593 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
595 if (alignPanel.av.hasHiddenRows())
597 boolean addOption = seq != null;
598 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
604 menuItem = new JMenuItem(
605 MessageManager.getString("action.reveal_all"));
606 menuItem.addActionListener(new ActionListener()
609 public void actionPerformed(ActionEvent e)
611 alignPanel.av.showAllHiddenSeqs();
612 if (alignPanel.overviewPanel != null)
614 alignPanel.overviewPanel.updateOverviewImage();
622 SequenceGroup sg = alignPanel.av.getSelectionGroup();
623 boolean isDefinedGroup = (sg != null)
624 ? alignPanel.av.getAlignment().getGroups().contains(sg)
627 if (sg != null && sg.getSize() > 0)
629 groupName.setText(MessageManager
630 .getString("label.edit_name_and_description_current_group"));
632 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
634 conservationMenuItem.setEnabled(!sg.isNucleotide());
638 if (sg.cs.conservationApplied())
640 conservationMenuItem.setSelected(true);
642 if (sg.cs.getThreshold() > 0)
644 abovePIDColour.setSelected(true);
647 modifyConservation.setEnabled(conservationMenuItem.isSelected());
648 modifyPID.setEnabled(abovePIDColour.isSelected());
649 displayNonconserved.setSelected(sg.getShowNonconserved());
650 showText.setSelected(sg.getDisplayText());
651 showColourText.setSelected(sg.getColourText());
652 showBoxes.setSelected(sg.getDisplayBoxes());
653 // add any groupURLs to the groupURL submenu and make it visible
654 if (groupLinks != null && groupLinks.size() > 0)
656 buildGroupURLMenu(sg, groupLinks);
658 // Add a 'show all structures' for the current selection
659 Hashtable<String, PDBEntry> pdbe = new Hashtable<>();
660 Hashtable<String, PDBEntry> reppdb = new Hashtable<>();
662 SequenceI sqass = null;
663 for (SequenceI sq : alignPanel.av.getSequenceSelection())
665 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
666 if (pes != null && pes.size() > 0)
668 reppdb.put(pes.get(0).getId(), pes.get(0));
669 for (PDBEntry pe : pes)
671 pdbe.put(pe.getId(), pe);
681 final PDBEntry[] pe = pdbe.values()
682 .toArray(new PDBEntry[pdbe.size()]),
683 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
684 final JMenuItem gpdbview, rpdbview;
689 groupMenu.setVisible(false);
690 editMenu.setVisible(false);
695 createGroupMenuItem.setVisible(true);
696 unGroupMenuItem.setVisible(false);
697 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
701 createGroupMenuItem.setVisible(false);
702 unGroupMenuItem.setVisible(true);
703 jMenu1.setText(MessageManager.getString("action.edit_group"));
708 sequenceMenu.setVisible(false);
709 pdbStructureDialog.setVisible(false);
710 rnaStructureMenu.setVisible(false);
713 addLinks(seq, features);
717 addFeatureDetails(features);
722 * Add a link to show feature details for each sequence feature
726 protected void addFeatureDetails(List<SequenceFeature> features)
728 if (features == null || features.isEmpty())
732 JMenu details = new JMenu(
733 MessageManager.getString("label.feature_details"));
736 for (final SequenceFeature sf : features)
738 int start = sf.getBegin();
739 int end = sf.getEnd();
743 desc = String.format("%s %d", sf.getType(), start);
747 desc = String.format("%s %d-%d", sf.getType(), start, end);
749 String tooltip = desc;
750 String description = sf.getDescription();
751 if (description != null)
753 description = StringUtils.stripHtmlTags(description);
754 if (description.length() > 12)
756 desc = desc + " " + description.substring(0, 12) + "..";
760 desc = desc + " " + description;
762 tooltip = tooltip + " " + description;
764 if (sf.getFeatureGroup() != null)
766 tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
768 JMenuItem item = new JMenuItem(desc);
769 item.setToolTipText(tooltip);
770 item.addActionListener(new ActionListener()
773 public void actionPerformed(ActionEvent e)
775 showFeatureDetails(sf);
783 * Opens a panel showing a text report of feature dteails
787 protected void showFeatureDetails(SequenceFeature sf)
789 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
790 // it appears Java's CSS does not support border-collaps :-(
791 cap.addStylesheetRule("table { border-collapse: collapse;}");
792 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
793 cap.setText(sf.getDetailsReport());
795 Desktop.addInternalFrame(cap,
796 MessageManager.getString("label.feature_details"), 500, 500);
800 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
801 * When seq is not null, these are links for the sequence id, which may be to
802 * external web sites for the sequence accession, and/or links embedded in
803 * non-positional features. When seq is null, only links embedded in the
804 * provided features are added. If no links are found, the menu is not added.
809 void addLinks(final SequenceI seq, List<SequenceFeature> features)
811 JMenu linkMenu = buildLinkMenu(seq, features);
813 // only add link menu if it has entries
814 if (linkMenu.getItemCount() > 0)
816 if (sequence != null)
818 sequenceMenu.add(linkMenu);
828 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
829 * "All" is added first, followed by a separator. Then add any annotation
830 * types associated with the current selection. Separate menus are built for
831 * the selected sequence group (if any), and the selected sequence.
833 * Some annotation rows are always rendered together - these can be identified
834 * by a common graphGroup property > -1. Only one of each group will be marked
835 * as visible (to avoid duplication of the display). For such groups we add a
836 * composite type name, e.g.
838 * IUPredWS (Long), IUPredWS (Short)
842 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
843 List<SequenceI> forSequences)
845 showMenu.removeAll();
846 hideMenu.removeAll();
848 final List<String> all = Arrays
850 { MessageManager.getString("label.all") });
851 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
853 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
855 showMenu.addSeparator();
856 hideMenu.addSeparator();
858 final AlignmentAnnotation[] annotations = ap.getAlignment()
859 .getAlignmentAnnotation();
862 * Find shown/hidden annotations types, distinguished by source (calcId),
863 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
864 * the insertion order, which is the order of the annotations on the
867 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
868 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
869 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
870 AlignmentAnnotationUtils.asList(annotations), forSequences);
872 for (String calcId : hiddenTypes.keySet())
874 for (List<String> type : hiddenTypes.get(calcId))
876 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
880 // grey out 'show annotations' if none are hidden
881 showMenu.setEnabled(!hiddenTypes.isEmpty());
883 for (String calcId : shownTypes.keySet())
885 for (List<String> type : shownTypes.get(calcId))
887 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
891 // grey out 'hide annotations' if none are shown
892 hideMenu.setEnabled(!shownTypes.isEmpty());
896 * Returns a list of sequences - either the current selection group (if there
897 * is one), else the specified single sequence.
902 protected List<SequenceI> getSequenceScope(SequenceI seq)
904 List<SequenceI> forSequences = null;
905 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
906 if (selectionGroup != null && selectionGroup.getSize() > 0)
908 forSequences = selectionGroup.getSequences();
912 forSequences = seq == null ? Collections.<SequenceI> emptyList()
913 : Arrays.asList(seq);
919 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
922 * @param showOrHideMenu
924 * @param forSequences
925 * the sequences whose annotations may be shown or hidden
930 * if true this is a special label meaning 'All'
931 * @param actionIsShow
932 * if true, the select menu item action is to show the annotation
935 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
936 final List<SequenceI> forSequences, String calcId,
937 final List<String> types, final boolean allTypes,
938 final boolean actionIsShow)
940 String label = types.toString(); // [a, b, c]
941 label = label.substring(1, label.length() - 1); // a, b, c
942 final JMenuItem item = new JMenuItem(label);
943 item.setToolTipText(calcId);
944 item.addActionListener(new ActionListener()
947 public void actionPerformed(ActionEvent e)
949 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
950 types, forSequences, allTypes, actionIsShow);
954 showOrHideMenu.add(item);
957 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
960 // TODO: usability: thread off the generation of group url content so root
962 // sequence only URLs
963 // ID/regex match URLs
964 groupLinksMenu = new JMenu(
965 MessageManager.getString("action.group_link"));
966 // three types of url that might be created.
967 JMenu[] linkMenus = new JMenu[] { null,
968 new JMenu(MessageManager.getString("action.ids")),
969 new JMenu(MessageManager.getString("action.sequences")),
970 new JMenu(MessageManager.getString("action.ids_sequences")) };
972 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
973 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
974 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
975 for (int sq = 0; sq < seqs.length; sq++)
978 int start = seqs[sq].findPosition(sg.getStartRes()),
979 end = seqs[sq].findPosition(sg.getEndRes());
980 // just collect ids from dataset sequence
981 // TODO: check if IDs collected from selecton group intersects with the
982 // current selection, too
983 SequenceI sqi = seqs[sq];
984 while (sqi.getDatasetSequence() != null)
986 sqi = sqi.getDatasetSequence();
988 DBRefEntry[] dbr = sqi.getDBRefs();
989 if (dbr != null && dbr.length > 0)
991 for (int d = 0; d < dbr.length; d++)
993 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
994 Object[] sarray = commonDbrefs.get(src);
997 sarray = new Object[2];
998 sarray[0] = new int[] { 0 };
999 sarray[1] = new String[seqs.length];
1001 commonDbrefs.put(src, sarray);
1004 if (((String[]) sarray[1])[sq] == null)
1006 if (!dbr[d].hasMap() || (dbr[d].getMap()
1007 .locateMappedRange(start, end) != null))
1009 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1010 ((int[]) sarray[0])[0]++;
1016 // now create group links for all distinct ID/sequence sets.
1017 boolean addMenu = false; // indicates if there are any group links to give
1019 for (String link : groupLinks)
1021 GroupUrlLink urlLink = null;
1024 urlLink = new GroupUrlLink(link);
1025 } catch (Exception foo)
1027 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
1031 if (!urlLink.isValid())
1033 Cache.log.error(urlLink.getInvalidMessage());
1036 final String label = urlLink.getLabel();
1037 boolean usingNames = false;
1038 // Now see which parts of the group apply for this URL
1039 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1040 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
1041 String[] seqstr, ids; // input to makeUrl
1044 int numinput = ((int[]) idset[0])[0];
1045 String[] allids = ((String[]) idset[1]);
1046 seqstr = new String[numinput];
1047 ids = new String[numinput];
1048 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1050 if (allids[sq] != null)
1052 ids[idcount] = allids[sq];
1053 seqstr[idcount++] = idandseqs[1][sq];
1059 // just use the id/seq set
1060 seqstr = idandseqs[1];
1064 // and try and make the groupURL!
1066 Object[] urlset = null;
1069 urlset = urlLink.makeUrlStubs(ids, seqstr,
1070 "FromJalview" + System.currentTimeMillis(), false);
1071 } catch (UrlStringTooLongException e)
1076 int type = urlLink.getGroupURLType() & 3;
1077 // first two bits ofurlLink type bitfield are sequenceids and sequences
1078 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1079 addshowLink(linkMenus[type],
1080 label + (((type & 1) == 1)
1081 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1089 groupLinksMenu = new JMenu(
1090 MessageManager.getString("action.group_link"));
1091 for (int m = 0; m < linkMenus.length; m++)
1093 if (linkMenus[m] != null
1094 && linkMenus[m].getMenuComponentCount() > 0)
1096 groupLinksMenu.add(linkMenus[m]);
1100 groupMenu.add(groupLinksMenu);
1110 private void jbInit() throws Exception
1112 groupMenu.setText(MessageManager.getString("label.selection"));
1113 groupName.setText(MessageManager.getString("label.name"));
1114 groupName.addActionListener(new ActionListener()
1117 public void actionPerformed(ActionEvent e)
1119 groupName_actionPerformed();
1122 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1123 sequenceName.setText(
1124 MessageManager.getString("label.edit_name_description"));
1125 sequenceName.addActionListener(new ActionListener()
1128 public void actionPerformed(ActionEvent e)
1130 sequenceName_actionPerformed();
1134 .setText(MessageManager.getString("action.choose_annotations"));
1135 chooseAnnotations.addActionListener(new ActionListener()
1138 public void actionPerformed(ActionEvent e)
1140 chooseAnnotations_actionPerformed(e);
1144 .setText(MessageManager.getString("label.sequence_details"));
1145 sequenceDetails.addActionListener(new ActionListener()
1148 public void actionPerformed(ActionEvent e)
1150 sequenceDetails_actionPerformed();
1154 .setText(MessageManager.getString("label.sequence_details"));
1155 sequenceSelDetails.addActionListener(new ActionListener()
1158 public void actionPerformed(ActionEvent e)
1160 sequenceSelectionDetails_actionPerformed();
1165 .setText(MessageManager.getString("action.remove_group"));
1166 unGroupMenuItem.addActionListener(new ActionListener()
1169 public void actionPerformed(ActionEvent e)
1171 unGroupMenuItem_actionPerformed();
1175 .setText(MessageManager.getString("action.create_group"));
1176 createGroupMenuItem.addActionListener(new ActionListener()
1179 public void actionPerformed(ActionEvent e)
1181 createGroupMenuItem_actionPerformed();
1185 outline.setText(MessageManager.getString("action.border_colour"));
1186 outline.addActionListener(new ActionListener()
1189 public void actionPerformed(ActionEvent e)
1191 outline_actionPerformed();
1194 showBoxes.setText(MessageManager.getString("action.boxes"));
1195 showBoxes.setState(true);
1196 showBoxes.addActionListener(new ActionListener()
1199 public void actionPerformed(ActionEvent e)
1201 showBoxes_actionPerformed();
1204 showText.setText(MessageManager.getString("action.text"));
1205 showText.setState(true);
1206 showText.addActionListener(new ActionListener()
1209 public void actionPerformed(ActionEvent e)
1211 showText_actionPerformed();
1214 showColourText.setText(MessageManager.getString("label.colour_text"));
1215 showColourText.addActionListener(new ActionListener()
1218 public void actionPerformed(ActionEvent e)
1220 showColourText_actionPerformed();
1224 .setText(MessageManager.getString("label.show_non_conserved"));
1225 displayNonconserved.setState(true);
1226 displayNonconserved.addActionListener(new ActionListener()
1229 public void actionPerformed(ActionEvent e)
1231 showNonconserved_actionPerformed();
1234 editMenu.setText(MessageManager.getString("action.edit"));
1235 cut.setText(MessageManager.getString("action.cut"));
1236 cut.addActionListener(new ActionListener()
1239 public void actionPerformed(ActionEvent e)
1241 cut_actionPerformed();
1244 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1245 upperCase.addActionListener(new ActionListener()
1248 public void actionPerformed(ActionEvent e)
1253 copy.setText(MessageManager.getString("action.copy"));
1254 copy.addActionListener(new ActionListener()
1257 public void actionPerformed(ActionEvent e)
1259 copy_actionPerformed();
1262 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1263 lowerCase.addActionListener(new ActionListener()
1266 public void actionPerformed(ActionEvent e)
1271 toggle.setText(MessageManager.getString("label.toggle_case"));
1272 toggle.addActionListener(new ActionListener()
1275 public void actionPerformed(ActionEvent e)
1281 MessageManager.getString("label.out_to_textbox") + "...");
1282 seqShowAnnotationsMenu
1283 .setText(MessageManager.getString("label.show_annotations"));
1284 seqHideAnnotationsMenu
1285 .setText(MessageManager.getString("label.hide_annotations"));
1286 groupShowAnnotationsMenu
1287 .setText(MessageManager.getString("label.show_annotations"));
1288 groupHideAnnotationsMenu
1289 .setText(MessageManager.getString("label.hide_annotations"));
1290 sequenceFeature.setText(
1291 MessageManager.getString("label.create_sequence_feature"));
1292 sequenceFeature.addActionListener(new ActionListener()
1295 public void actionPerformed(ActionEvent e)
1297 sequenceFeature_actionPerformed();
1300 jMenu1.setText(MessageManager.getString("label.group"));
1301 pdbStructureDialog.setText(
1302 MessageManager.getString("label.show_pdbstruct_dialog"));
1303 pdbStructureDialog.addActionListener(new ActionListener()
1306 public void actionPerformed(ActionEvent actionEvent)
1308 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1309 if (ap.av.getSelectionGroup() != null)
1311 selectedSeqs = ap.av.getSequenceSelection();
1313 new StructureChooser(selectedSeqs, sequence, ap);
1318 .setText(MessageManager.getString("label.view_rna_structure"));
1320 // colStructureMenu.setText("Colour By Structure");
1321 editSequence.setText(
1322 MessageManager.getString("label.edit_sequence") + "...");
1323 editSequence.addActionListener(new ActionListener()
1326 public void actionPerformed(ActionEvent actionEvent)
1328 editSequence_actionPerformed(actionEvent);
1331 makeReferenceSeq.setText(
1332 MessageManager.getString("label.mark_as_representative"));
1333 makeReferenceSeq.addActionListener(new ActionListener()
1337 public void actionPerformed(ActionEvent actionEvent)
1339 makeReferenceSeq_actionPerformed(actionEvent);
1344 .setText(MessageManager.getString("label.hide_insertions"));
1345 hideInsertions.addActionListener(new ActionListener()
1349 public void actionPerformed(ActionEvent e)
1351 hideInsertions_actionPerformed(e);
1355 groupMenu.add(sequenceSelDetails);
1358 add(rnaStructureMenu);
1359 add(pdbStructureDialog);
1360 if (sequence != null)
1362 add(hideInsertions);
1364 // annotations configuration panel suppressed for now
1365 // groupMenu.add(chooseAnnotations);
1368 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1369 * (if a selection group is in force).
1371 sequenceMenu.add(seqShowAnnotationsMenu);
1372 sequenceMenu.add(seqHideAnnotationsMenu);
1373 sequenceMenu.add(seqAddReferenceAnnotations);
1374 groupMenu.add(groupShowAnnotationsMenu);
1375 groupMenu.add(groupHideAnnotationsMenu);
1376 groupMenu.add(groupAddReferenceAnnotations);
1377 groupMenu.add(editMenu);
1378 groupMenu.add(outputMenu);
1379 groupMenu.add(sequenceFeature);
1380 groupMenu.add(createGroupMenuItem);
1381 groupMenu.add(unGroupMenuItem);
1382 groupMenu.add(jMenu1);
1383 sequenceMenu.add(sequenceName);
1384 sequenceMenu.add(sequenceDetails);
1385 sequenceMenu.add(makeReferenceSeq);
1392 editMenu.add(editSequence);
1393 editMenu.add(upperCase);
1394 editMenu.add(lowerCase);
1395 editMenu.add(toggle);
1396 // JBPNote: These shouldn't be added here - should appear in a generic
1397 // 'apply web service to this sequence menu'
1398 // pdbMenu.add(RNAFold);
1399 // pdbMenu.add(ContraFold);
1400 jMenu1.add(groupName);
1401 jMenu1.add(colourMenu);
1402 jMenu1.add(showBoxes);
1403 jMenu1.add(showText);
1404 jMenu1.add(showColourText);
1405 jMenu1.add(outline);
1406 jMenu1.add(displayNonconserved);
1410 * Constructs the entries for the colour menu
1412 protected void initColourMenu()
1414 colourMenu.setText(MessageManager.getString("label.group_colour"));
1415 textColour.setText(MessageManager.getString("label.text_colour"));
1416 textColour.addActionListener(new ActionListener()
1419 public void actionPerformed(ActionEvent e)
1421 textColour_actionPerformed();
1425 abovePIDColour.setText(
1426 MessageManager.getString("label.above_identity_threshold"));
1427 abovePIDColour.addActionListener(new ActionListener()
1430 public void actionPerformed(ActionEvent e)
1432 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1437 MessageManager.getString("label.modify_identity_threshold"));
1438 modifyPID.addActionListener(new ActionListener()
1441 public void actionPerformed(ActionEvent e)
1443 modifyPID_actionPerformed();
1447 conservationMenuItem
1448 .setText(MessageManager.getString("action.by_conservation"));
1449 conservationMenuItem.addActionListener(new ActionListener()
1452 public void actionPerformed(ActionEvent e)
1454 conservationMenuItem_actionPerformed(
1455 conservationMenuItem.isSelected());
1459 annotationColour = new JRadioButtonMenuItem(
1460 MessageManager.getString("action.by_annotation"));
1461 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1462 annotationColour.setEnabled(false);
1463 annotationColour.setToolTipText(
1464 MessageManager.getString("label.by_annotation_tooltip"));
1466 modifyConservation.setText(MessageManager
1467 .getString("label.modify_conservation_threshold"));
1468 modifyConservation.addActionListener(new ActionListener()
1471 public void actionPerformed(ActionEvent e)
1473 modifyConservation_actionPerformed();
1479 * Builds the group colour sub-menu, including any user-defined colours which
1480 * were loaded at startup or during the Jalview session
1482 protected void buildColourMenu()
1484 SequenceGroup sg = ap.av.getSelectionGroup();
1488 * popup menu with no sequence group scope
1492 colourMenu.removeAll();
1493 colourMenu.add(textColour);
1494 colourMenu.addSeparator();
1496 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1498 bg.add(annotationColour);
1499 colourMenu.add(annotationColour);
1501 colourMenu.addSeparator();
1502 colourMenu.add(conservationMenuItem);
1503 colourMenu.add(modifyConservation);
1504 colourMenu.add(abovePIDColour);
1505 colourMenu.add(modifyPID);
1508 protected void modifyConservation_actionPerformed()
1510 SequenceGroup sg = getGroup();
1513 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1514 SliderPanel.showConservationSlider();
1518 protected void modifyPID_actionPerformed()
1520 SequenceGroup sg = getGroup();
1523 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1525 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1526 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1527 SliderPanel.showPIDSlider();
1532 * Check for any annotations on the underlying dataset sequences (for the
1533 * current selection group) which are not 'on the alignment'.If any are found,
1534 * enable the option to add them to the alignment. The criteria for 'on the
1535 * alignment' is finding an alignment annotation on the alignment, matched on
1536 * calcId, label and sequenceRef.
1538 * A tooltip is also constructed that displays the source (calcId) and type
1539 * (label) of the annotations that can be added.
1542 * @param forSequences
1544 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1545 List<SequenceI> forSequences)
1547 menuItem.setEnabled(false);
1550 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1551 * Using TreeMap means calcIds are shown in alphabetical order.
1553 SortedMap<String, String> tipEntries = new TreeMap<>();
1554 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1555 AlignmentI al = this.ap.av.getAlignment();
1556 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1558 if (!candidates.isEmpty())
1560 StringBuilder tooltip = new StringBuilder(64);
1561 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1564 * Found annotations that could be added. Enable the menu item, and
1565 * configure its tooltip and action.
1567 menuItem.setEnabled(true);
1568 for (String calcId : tipEntries.keySet())
1570 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1572 String tooltipText = JvSwingUtils.wrapTooltip(true,
1573 tooltip.toString());
1574 menuItem.setToolTipText(tooltipText);
1576 menuItem.addActionListener(new ActionListener()
1579 public void actionPerformed(ActionEvent e)
1581 addReferenceAnnotations_actionPerformed(candidates);
1588 * Add annotations to the sequences and to the alignment.
1591 * a map whose keys are sequences on the alignment, and values a list
1592 * of annotations to add to each sequence
1594 protected void addReferenceAnnotations_actionPerformed(
1595 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1597 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1598 final AlignmentI alignment = this.ap.getAlignment();
1599 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1604 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1606 if (!ap.av.getAlignment().hasSeqrep())
1608 // initialise the display flags so the user sees something happen
1609 ap.av.setDisplayReferenceSeq(true);
1610 ap.av.setColourByReferenceSeq(true);
1611 ap.av.getAlignment().setSeqrep(sequence);
1615 if (ap.av.getAlignment().getSeqrep() == sequence)
1617 ap.av.getAlignment().setSeqrep(null);
1621 ap.av.getAlignment().setSeqrep(sequence);
1627 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1629 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1630 BitSet inserts = new BitSet();
1632 boolean markedPopup = false;
1633 // mark inserts in current selection
1634 if (ap.av.getSelectionGroup() != null)
1636 // mark just the columns in the selection group to be hidden
1637 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1638 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1640 // now clear columns without gaps
1641 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1647 inserts.and(sq.getInsertionsAsBits());
1649 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1650 ap.av.getSelectionGroup().getEndRes());
1653 // now mark for sequence under popup if we haven't already done it
1654 else if (!markedPopup && sequence != null)
1656 inserts.or(sequence.getInsertionsAsBits());
1658 // and set hidden columns accordingly
1659 hidden.hideColumns(inserts);
1664 protected void sequenceSelectionDetails_actionPerformed()
1666 createSequenceDetailsReport(ap.av.getSequenceSelection());
1669 protected void sequenceDetails_actionPerformed()
1671 createSequenceDetailsReport(new SequenceI[] { sequence });
1674 public void createSequenceDetailsReport(SequenceI[] sequences)
1676 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1677 StringBuilder contents = new StringBuilder(128);
1678 for (SequenceI seq : sequences)
1680 contents.append("<p><h2>" + MessageManager.formatMessage(
1681 "label.create_sequence_details_report_annotation_for",
1683 { seq.getDisplayId(true) }) + "</h2></p><p>");
1684 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
1685 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1686 contents.append("</p>");
1688 cap.setText("<html>" + contents.toString() + "</html>");
1690 Desktop.addInternalFrame(cap,
1691 MessageManager.formatMessage("label.sequence_details_for",
1692 (sequences.length == 1 ? new Object[]
1693 { sequences[0].getDisplayId(true) }
1696 .getString("label.selection") })),
1701 protected void showNonconserved_actionPerformed()
1703 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1708 * call to refresh view after settings change
1712 ap.updateAnnotation();
1713 // removed paintAlignment(true) here:
1714 // updateAnnotation calls paintAlignment already, so don't need to call
1717 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1721 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1722 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1732 public void abovePIDColour_actionPerformed(boolean selected)
1734 SequenceGroup sg = getGroup();
1742 sg.cs.setConsensus(AAFrequency.calculate(
1743 sg.getSequences(ap.av.getHiddenRepSequences()),
1744 sg.getStartRes(), sg.getEndRes() + 1));
1746 int threshold = SliderPanel.setPIDSliderSource(ap,
1747 sg.getGroupColourScheme(), getGroup().getName());
1749 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1751 SliderPanel.showPIDSlider();
1754 // remove PIDColouring
1756 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1757 SliderPanel.hidePIDSlider();
1759 modifyPID.setEnabled(selected);
1765 * Open a panel where the user can choose which types of sequence annotation
1770 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1772 // todo correct way to guard against opening a duplicate panel?
1773 new AnnotationChooser(ap);
1782 public void conservationMenuItem_actionPerformed(boolean selected)
1784 SequenceGroup sg = getGroup();
1792 // JBPNote: Conservation name shouldn't be i18n translated
1793 Conservation c = new Conservation("Group",
1794 sg.getSequences(ap.av.getHiddenRepSequences()),
1795 sg.getStartRes(), sg.getEndRes() + 1);
1798 c.verdict(false, ap.av.getConsPercGaps());
1799 sg.cs.setConservation(c);
1801 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1803 SliderPanel.showConservationSlider();
1806 // remove ConservationColouring
1808 sg.cs.setConservation(null);
1809 SliderPanel.hideConservationSlider();
1811 modifyConservation.setEnabled(selected);
1822 protected void groupName_actionPerformed()
1825 SequenceGroup sg = getGroup();
1826 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1827 sg.getDescription(),
1828 " " + MessageManager.getString("label.group_name") + " ",
1829 MessageManager.getString("label.group_description") + " ",
1830 MessageManager.getString("label.edit_group_name_description"),
1838 sg.setName(dialog.getName());
1839 sg.setDescription(dialog.getDescription());
1844 * Get selection group - adding it to the alignment if necessary.
1846 * @return sequence group to operate on
1848 SequenceGroup getGroup()
1850 SequenceGroup sg = ap.av.getSelectionGroup();
1851 // this method won't add a new group if it already exists
1854 ap.av.getAlignment().addGroup(sg);
1866 void sequenceName_actionPerformed()
1868 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1869 sequence.getDescription(),
1870 " " + MessageManager.getString("label.sequence_name")
1872 MessageManager.getString("label.sequence_description") + " ",
1873 MessageManager.getString(
1874 "label.edit_sequence_name_description"),
1882 if (dialog.getName() != null)
1884 if (dialog.getName().indexOf(" ") > -1)
1886 JvOptionPane.showMessageDialog(ap,
1888 .getString("label.spaces_converted_to_backslashes"),
1890 .getString("label.no_spaces_allowed_sequence_name"),
1891 JvOptionPane.WARNING_MESSAGE);
1894 sequence.setName(dialog.getName().replace(' ', '_'));
1895 ap.paintAlignment(false, false);
1898 sequence.setDescription(dialog.getDescription());
1900 ap.av.firePropertyChange("alignment", null,
1901 ap.av.getAlignment().getSequences());
1911 void unGroupMenuItem_actionPerformed()
1913 SequenceGroup sg = ap.av.getSelectionGroup();
1914 ap.av.getAlignment().deleteGroup(sg);
1915 ap.av.setSelectionGroup(null);
1919 void createGroupMenuItem_actionPerformed()
1921 getGroup(); // implicitly creates group - note - should apply defaults / use
1922 // standard alignment window logic for this
1932 protected void outline_actionPerformed()
1934 SequenceGroup sg = getGroup();
1935 Color col = JColorChooser.showDialog(this,
1936 MessageManager.getString("label.select_outline_colour"),
1941 sg.setOutlineColour(col);
1953 public void showBoxes_actionPerformed()
1955 getGroup().setDisplayBoxes(showBoxes.isSelected());
1965 public void showText_actionPerformed()
1967 getGroup().setDisplayText(showText.isSelected());
1977 public void showColourText_actionPerformed()
1979 getGroup().setColourText(showColourText.isSelected());
1983 void hideSequences(boolean representGroup)
1985 ap.av.hideSequences(sequence, representGroup);
1988 public void copy_actionPerformed()
1990 ap.alignFrame.copy_actionPerformed(null);
1993 public void cut_actionPerformed()
1995 ap.alignFrame.cut_actionPerformed(null);
1998 void changeCase(ActionEvent e)
2000 Object source = e.getSource();
2001 SequenceGroup sg = ap.av.getSelectionGroup();
2005 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2006 sg.getStartRes(), sg.getEndRes() + 1);
2011 if (source == toggle)
2013 description = MessageManager.getString("label.toggle_case");
2014 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2016 else if (source == upperCase)
2018 description = MessageManager.getString("label.to_upper_case");
2019 caseChange = ChangeCaseCommand.TO_UPPER;
2023 description = MessageManager.getString("label.to_lower_case");
2024 caseChange = ChangeCaseCommand.TO_LOWER;
2027 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2028 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2029 startEnd, caseChange);
2031 ap.alignFrame.addHistoryItem(caseCommand);
2033 ap.av.firePropertyChange("alignment", null,
2034 ap.av.getAlignment().getSequences());
2039 public void outputText_actionPerformed(ActionEvent e)
2041 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2042 cap.setForInput(null);
2043 Desktop.addInternalFrame(cap, MessageManager
2044 .formatMessage("label.alignment_output_command", new Object[]
2045 { e.getActionCommand() }), 600, 500);
2047 String[] omitHidden = null;
2049 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2050 // or we simply trust the user wants
2051 // wysiwig behaviour
2053 FileFormatI fileFormat = FileFormats.getInstance()
2054 .forName(e.getActionCommand());
2056 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2059 public void sequenceFeature_actionPerformed()
2061 SequenceGroup sg = ap.av.getSelectionGroup();
2067 List<SequenceI> seqs = new ArrayList<>();
2068 List<SequenceFeature> features = new ArrayList<>();
2071 * assemble dataset sequences, and template new sequence features,
2072 * for the amend features dialog
2074 int gSize = sg.getSize();
2075 for (int i = 0; i < gSize; i++)
2077 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2078 int end = sg.findEndRes(sg.getSequenceAt(i));
2081 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2082 features.add(new SequenceFeature(null, null, start, end, null));
2087 * an entirely gapped region will generate empty lists of sequence / features
2089 if (!seqs.isEmpty())
2091 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer()
2092 .amendFeatures(seqs, features, true, ap))
2094 ap.alignFrame.setShowSeqFeatures(true);
2095 ap.av.setSearchResults(null); // clear highlighting
2096 ap.repaint(); // draw new/amended features
2101 public void textColour_actionPerformed()
2103 SequenceGroup sg = getGroup();
2106 new TextColourChooser().chooseColour(ap, sg);
2110 public void colourByStructure(String pdbid)
2112 Annotation[] anots = ap.av.getStructureSelectionManager()
2113 .colourSequenceFromStructure(sequence, pdbid);
2115 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2116 "Coloured by " + pdbid, anots);
2118 ap.av.getAlignment().addAnnotation(an);
2119 an.createSequenceMapping(sequence, 0, true);
2120 // an.adjustForAlignment();
2121 ap.av.getAlignment().setAnnotationIndex(an, 0);
2123 ap.adjustAnnotationHeight();
2125 sequence.addAlignmentAnnotation(an);
2129 public void editSequence_actionPerformed(ActionEvent actionEvent)
2131 SequenceGroup sg = ap.av.getSelectionGroup();
2135 if (sequence == null)
2137 sequence = sg.getSequenceAt(0);
2140 EditNameDialog dialog = new EditNameDialog(
2141 sequence.getSequenceAsString(sg.getStartRes(),
2142 sg.getEndRes() + 1),
2143 null, MessageManager.getString("label.edit_sequence"), null,
2144 MessageManager.getString("label.edit_sequence"),
2149 EditCommand editCommand = new EditCommand(
2150 MessageManager.getString("label.edit_sequences"),
2152 dialog.getName().replace(' ', ap.av.getGapCharacter()),
2153 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2154 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2156 ap.alignFrame.addHistoryItem(editCommand);
2158 ap.av.firePropertyChange("alignment", null,
2159 ap.av.getAlignment().getSequences());
2165 * Action on user selecting an item from the colour menu (that does not have
2166 * its bespoke action handler)
2171 public void changeColour_actionPerformed(String colourSchemeName)
2173 SequenceGroup sg = getGroup();
2175 * switch to the chosen colour scheme (or null for None)
2177 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2178 .getColourScheme(colourSchemeName, ap.av, sg,
2179 ap.av.getHiddenRepSequences());
2180 sg.setColourScheme(colourScheme);
2181 if (colourScheme instanceof Blosum62ColourScheme
2182 || colourScheme instanceof PIDColourScheme)
2184 sg.cs.setConsensus(AAFrequency.calculate(
2185 sg.getSequences(ap.av.getHiddenRepSequences()),
2186 sg.getStartRes(), sg.getEndRes() + 1));