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.DBRefEntry;
34 import jalview.datamodel.HiddenColumns;
35 import jalview.datamodel.PDBEntry;
36 import jalview.datamodel.SequenceFeature;
37 import jalview.datamodel.SequenceGroup;
38 import jalview.datamodel.SequenceI;
39 import jalview.gui.ColourMenuHelper.ColourChangeListener;
40 import jalview.io.FileFormatI;
41 import jalview.io.FileFormats;
42 import jalview.io.FormatAdapter;
43 import jalview.io.SequenceAnnotationReport;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.ColourSchemeI;
46 import jalview.schemes.ColourSchemes;
47 import jalview.schemes.PIDColourScheme;
48 import jalview.schemes.ResidueColourScheme;
49 import jalview.util.GroupUrlLink;
50 import jalview.util.GroupUrlLink.UrlStringTooLongException;
51 import jalview.util.MessageManager;
52 import jalview.util.StringUtils;
53 import jalview.util.UrlLink;
55 import java.awt.Color;
56 import java.awt.event.ActionEvent;
57 import java.awt.event.ActionListener;
58 import java.util.ArrayList;
59 import java.util.Arrays;
60 import java.util.BitSet;
61 import java.util.Collection;
62 import java.util.Collections;
63 import java.util.Hashtable;
64 import java.util.LinkedHashMap;
65 import java.util.List;
67 import java.util.SortedMap;
68 import java.util.TreeMap;
69 import java.util.Vector;
71 import javax.swing.ButtonGroup;
72 import javax.swing.JCheckBoxMenuItem;
73 import javax.swing.JColorChooser;
74 import javax.swing.JMenu;
75 import javax.swing.JMenuItem;
76 import javax.swing.JPopupMenu;
77 import javax.swing.JRadioButtonMenuItem;
80 * The popup menu that is displayed on right-click on a sequence id, or in the
83 public class PopupMenu extends JPopupMenu implements ColourChangeListener
86 * true for ID Panel menu, false for alignment panel menu
88 private final boolean forIdPanel;
90 private final AlignmentPanel ap;
93 * the sequence under the cursor when clicked
94 * (additional sequences may be selected)
96 private final SequenceI sequence;
98 JMenu groupMenu = new JMenu();
100 JMenuItem groupName = new JMenuItem();
102 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
104 protected JMenuItem modifyPID = new JMenuItem();
106 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
108 protected JRadioButtonMenuItem annotationColour;
110 protected JMenuItem modifyConservation = new JMenuItem();
112 JMenu sequenceMenu = new JMenu();
114 JMenuItem makeReferenceSeq = new JMenuItem();
116 JMenuItem createGroupMenuItem = new JMenuItem();
118 JMenuItem unGroupMenuItem = new JMenuItem();
120 JMenu colourMenu = new JMenu();
122 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
124 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
126 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
128 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
130 JMenu editMenu = new JMenu();
132 JMenuItem upperCase = new JMenuItem();
134 JMenuItem lowerCase = new JMenuItem();
136 JMenuItem toggle = new JMenuItem();
138 JMenu outputMenu = new JMenu();
140 JMenu seqShowAnnotationsMenu = new JMenu();
142 JMenu seqHideAnnotationsMenu = new JMenu();
144 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
145 MessageManager.getString("label.add_reference_annotations"));
147 JMenu groupShowAnnotationsMenu = new JMenu();
149 JMenu groupHideAnnotationsMenu = new JMenu();
151 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
152 MessageManager.getString("label.add_reference_annotations"));
154 JMenuItem textColour = new JMenuItem();
156 JMenu editGroupMenu = new JMenu();
158 JMenuItem chooseStructure = new JMenuItem();
160 JMenu rnaStructureMenu = new JMenu();
163 * Constructs a menu with sub-menu items for any hyperlinks for the sequence
164 * and/or features provided. Hyperlinks may include a lookup by sequence id,
165 * or database cross-references, depending on which links are enabled in user
172 protected static JMenu buildLinkMenu(final SequenceI seq,
173 List<SequenceFeature> features)
175 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
177 List<String> nlinks = null;
180 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
181 UrlLink.sort(nlinks);
185 nlinks = new ArrayList<>();
188 if (features != null)
190 for (SequenceFeature sf : features)
192 if (sf.links != null)
194 for (String link : sf.links)
203 * instantiate the hyperlinklink templates from sequence data;
204 * note the order of the templates is preserved in the map
206 Map<String, List<String>> linkset = new LinkedHashMap<>();
207 for (String link : nlinks)
209 UrlLink urlLink = null;
212 urlLink = new UrlLink(link);
213 } catch (Exception foo)
215 Cache.log.error("Exception for URLLink '" + link + "'", foo);
219 if (!urlLink.isValid())
221 Cache.log.error(urlLink.getInvalidMessage());
225 urlLink.createLinksFromSeq(seq, linkset);
229 * construct menu items for the hyperlinks (still preserving
230 * the order of the sorted templates)
232 addUrlLinks(linkMenu, linkset.values());
238 * A helper method that builds menu items from the given links, with action
239 * handlers to open the link URL, and adds them to the linkMenu. Each provided
240 * link should be a list whose second item is the menu text, and whose fourth
241 * item is the URL to open when the menu item is selected.
246 static private void addUrlLinks(JMenu linkMenu,
247 Collection<List<String>> linkset)
249 for (List<String> linkstrset : linkset)
251 final String url = linkstrset.get(3);
252 JMenuItem item = new JMenuItem(linkstrset.get(1));
253 item.setToolTipText(MessageManager
254 .formatMessage("label.open_url_param", new Object[]
256 item.addActionListener(new ActionListener()
259 public void actionPerformed(ActionEvent e)
261 new Thread(new Runnable()
276 * Opens the provided url in the default web browser, or shows an error
277 * message if this fails
281 static void showLink(String url)
285 jalview.util.BrowserLauncher.openURL(url);
286 } catch (Exception ex)
288 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
289 MessageManager.getString("label.web_browser_not_found_unix"),
290 MessageManager.getString("label.web_browser_not_found"),
291 JvOptionPane.WARNING_MESSAGE);
293 ex.printStackTrace();
298 * add a late bound groupURL item to the given linkMenu
302 * - menu label string
303 * @param urlgenerator
304 * GroupURLLink used to generate URL
306 * Object array returned from the makeUrlStubs function.
308 static void addshowLink(JMenu linkMenu, String label,
309 final GroupUrlLink urlgenerator, final Object[] urlstub)
311 JMenuItem item = new JMenuItem(label);
312 item.setToolTipText(MessageManager
313 .formatMessage("label.open_url_seqs_param", new Object[]
314 { urlgenerator.getUrl_prefix(),
315 urlgenerator.getNumberInvolved(urlstub) }));
316 // TODO: put in info about what is being sent.
317 item.addActionListener(new ActionListener()
320 public void actionPerformed(ActionEvent e)
322 new Thread(new Runnable()
330 showLink(urlgenerator.constructFrom(urlstub));
331 } catch (UrlStringTooLongException e2)
344 * Constructor for a PopupMenu for a click in the alignment panel (on a residue)
349 * sequence features overlapping the clicked residue
351 public PopupMenu(final AlignmentPanel ap, SequenceI seq,
352 List<SequenceFeature> features)
354 this(false, ap, seq, features, null);
358 * Constructor for a PopupMenu for a click in the sequence id panel
363 * non-positional features for the sequence
366 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
367 List<SequenceFeature> features, List<String> groupLinks)
369 this(true, alignPanel, seq, features, groupLinks);
373 * Private constructor that constructs a popup menu for either sequence ID
374 * Panel, or alignment context
382 private PopupMenu(boolean fromIdPanel,
383 final AlignmentPanel alignPanel,
384 final SequenceI seq, List<SequenceFeature> features,
385 List<String> groupLinks)
387 this.forIdPanel = fromIdPanel;
388 this.ap = alignPanel;
391 for (String ff : FileFormats.getInstance().getWritableFormats(true))
393 JMenuItem item = new JMenuItem(ff);
395 item.addActionListener(new ActionListener()
398 public void actionPerformed(ActionEvent e)
400 outputText_actionPerformed(e);
404 outputMenu.add(item);
408 * Build menus for annotation types that may be shown or hidden, and for
409 * 'reference annotations' that may be added to the alignment. First for the
410 * currently selected sequence (if there is one):
412 final List<SequenceI> selectedSequence = (forIdPanel
414 : Collections.<SequenceI> emptyList());
415 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
416 seqHideAnnotationsMenu, selectedSequence);
417 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
421 * And repeat for the current selection group (if there is one):
423 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
424 ? Collections.<SequenceI> emptyList()
425 : alignPanel.av.getSelectionGroup().getSequences());
426 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
427 groupHideAnnotationsMenu, selectedGroup);
428 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
434 } catch (Exception e)
442 sequenceMenu.setText(sequence.getName());
443 if (seq == alignPanel.av.getAlignment().getSeqrep())
445 makeReferenceSeq.setText(
446 MessageManager.getString("action.unmark_as_reference"));
450 makeReferenceSeq.setText(
451 MessageManager.getString("action.set_as_reference"));
454 if (!alignPanel.av.getAlignment().isNucleotide())
456 remove(rnaStructureMenu);
460 int origCount = rnaStructureMenu.getItemCount();
462 * add menu items to 2D-render any alignment or sequence secondary
463 * structure annotation
465 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
466 .getAlignmentAnnotation();
469 for (final AlignmentAnnotation aa : aas)
471 if (aa.isValidStruc() && aa.sequenceRef == null)
474 * valid alignment RNA secondary structure annotation
476 menuItem = new JMenuItem();
477 menuItem.setText(MessageManager.formatMessage(
478 "label.2d_rna_structure_line", new Object[]
480 menuItem.addActionListener(new ActionListener()
483 public void actionPerformed(ActionEvent e)
485 new AppVarna(seq, aa, alignPanel);
488 rnaStructureMenu.add(menuItem);
493 if (seq.getAnnotation() != null)
495 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
496 for (final AlignmentAnnotation aa : seqAnns)
498 if (aa.isValidStruc())
501 * valid sequence RNA secondary structure annotation
503 // TODO: make rnastrucF a bit more nice
504 menuItem = new JMenuItem();
505 menuItem.setText(MessageManager.formatMessage(
506 "label.2d_rna_sequence_name", new Object[]
508 menuItem.addActionListener(new ActionListener()
511 public void actionPerformed(ActionEvent e)
513 // TODO: VARNA does'nt print gaps in the sequence
514 new AppVarna(seq, aa, alignPanel);
517 rnaStructureMenu.add(menuItem);
521 if (rnaStructureMenu.getItemCount() == origCount)
523 remove(rnaStructureMenu);
527 menuItem = new JMenuItem(
528 MessageManager.getString("action.hide_sequences"));
529 menuItem.addActionListener(new ActionListener()
532 public void actionPerformed(ActionEvent e)
534 hideSequences(false);
539 if (alignPanel.av.getSelectionGroup() != null
540 && alignPanel.av.getSelectionGroup().getSize() > 1)
542 menuItem = new JMenuItem(MessageManager
543 .formatMessage("label.represent_group_with", new Object[]
545 menuItem.addActionListener(new ActionListener()
548 public void actionPerformed(ActionEvent e)
553 sequenceMenu.add(menuItem);
556 if (alignPanel.av.hasHiddenRows())
558 final int index = alignPanel.av.getAlignment().findIndex(seq);
560 if (alignPanel.av.adjustForHiddenSeqs(index)
561 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
563 menuItem = new JMenuItem(
564 MessageManager.getString("action.reveal_sequences"));
565 menuItem.addActionListener(new ActionListener()
568 public void actionPerformed(ActionEvent e)
570 alignPanel.av.showSequence(index);
571 if (alignPanel.overviewPanel != null)
573 alignPanel.overviewPanel.updateOverviewImage();
584 * - in the IdPanel (seq not null) if any sequence is hidden
585 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
587 if (alignPanel.av.hasHiddenRows())
589 boolean addOption = seq != null;
590 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
596 JMenuItem menuItem = new JMenuItem(
597 MessageManager.getString("action.reveal_all"));
598 menuItem.addActionListener(new ActionListener()
601 public void actionPerformed(ActionEvent e)
603 alignPanel.av.showAllHiddenSeqs();
604 if (alignPanel.overviewPanel != null)
606 alignPanel.overviewPanel.updateOverviewImage();
614 SequenceGroup sg = alignPanel.av.getSelectionGroup();
615 boolean isDefinedGroup = (sg != null)
616 ? alignPanel.av.getAlignment().getGroups().contains(sg)
619 if (sg != null && sg.getSize() > 0)
621 groupName.setText(MessageManager
622 .getString("label.edit_name_and_description_current_group"));
624 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
626 conservationMenuItem.setEnabled(!sg.isNucleotide());
630 if (sg.cs.conservationApplied())
632 conservationMenuItem.setSelected(true);
634 if (sg.cs.getThreshold() > 0)
636 abovePIDColour.setSelected(true);
639 modifyConservation.setEnabled(conservationMenuItem.isSelected());
640 modifyPID.setEnabled(abovePIDColour.isSelected());
641 displayNonconserved.setSelected(sg.getShowNonconserved());
642 showText.setSelected(sg.getDisplayText());
643 showColourText.setSelected(sg.getColourText());
644 showBoxes.setSelected(sg.getDisplayBoxes());
645 // add any groupURLs to the groupURL submenu and make it visible
646 if (groupLinks != null && groupLinks.size() > 0)
648 buildGroupURLMenu(sg, groupLinks);
650 // Add a 'show all structures' for the current selection
651 Hashtable<String, PDBEntry> pdbe = new Hashtable<>(), reppdb = new Hashtable<>();
653 SequenceI sqass = null;
654 for (SequenceI sq : alignPanel.av.getSequenceSelection())
656 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
657 if (pes != null && pes.size() > 0)
659 reppdb.put(pes.get(0).getId(), pes.get(0));
660 for (PDBEntry pe : pes)
662 pdbe.put(pe.getId(), pe);
672 final PDBEntry[] pe = pdbe.values()
673 .toArray(new PDBEntry[pdbe.size()]),
674 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
675 final JMenuItem gpdbview, rpdbview;
680 groupMenu.setVisible(false);
681 editMenu.setVisible(false);
686 createGroupMenuItem.setVisible(true);
687 unGroupMenuItem.setVisible(false);
688 editGroupMenu.setText(MessageManager.getString("action.edit_new_group"));
692 createGroupMenuItem.setVisible(false);
693 unGroupMenuItem.setVisible(true);
694 editGroupMenu.setText(MessageManager.getString("action.edit_group"));
699 sequenceMenu.setVisible(false);
700 chooseStructure.setVisible(false);
701 rnaStructureMenu.setVisible(false);
704 addLinks(seq, features);
708 addFeatureDetails(features);
713 * Add a link to show feature details for each sequence feature
717 protected void addFeatureDetails(List<SequenceFeature> features)
719 if (features == null || features.isEmpty())
723 JMenu details = new JMenu(
724 MessageManager.getString("label.feature_details"));
727 for (final SequenceFeature sf : features)
729 int start = sf.getBegin();
730 int end = sf.getEnd();
734 desc = String.format("%s %d", sf.getType(), start);
738 desc = String.format("%s %d-%d", sf.getType(), start, end);
740 String tooltip = desc;
741 String description = sf.getDescription();
742 if (description != null)
744 description = StringUtils.stripHtmlTags(description);
745 if (description.length() > 12)
747 desc = desc + " " + description.substring(0, 12) + "..";
751 desc = desc + " " + description;
753 tooltip = tooltip + " " + description;
755 if (sf.getFeatureGroup() != null)
757 tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
759 JMenuItem item = new JMenuItem(desc);
760 item.setToolTipText(tooltip);
761 item.addActionListener(new ActionListener()
764 public void actionPerformed(ActionEvent e)
766 showFeatureDetails(sf);
774 * Opens a panel showing a text report of feature dteails
778 protected void showFeatureDetails(SequenceFeature sf)
780 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
781 // it appears Java's CSS does not support border-collapse :-(
782 cap.addStylesheetRule("table { border-collapse: collapse;}");
783 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
784 cap.setText(sf.getDetailsReport(sequence));
786 Desktop.addInternalFrame(cap,
787 MessageManager.getString("label.feature_details"), 500, 500);
791 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
792 * When seq is not null, these are links for the sequence id, which may be to
793 * external web sites for the sequence accession, and/or links embedded in
794 * non-positional features. When seq is null, only links embedded in the
795 * provided features are added. If no links are found, the menu is not added.
800 void addLinks(final SequenceI seq, List<SequenceFeature> features)
802 JMenu linkMenu = buildLinkMenu(forIdPanel ? seq : null, features);
804 // only add link menu if it has entries
805 if (linkMenu.getItemCount() > 0)
809 sequenceMenu.add(linkMenu);
819 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
820 * "All" is added first, followed by a separator. Then add any annotation
821 * types associated with the current selection. Separate menus are built for
822 * the selected sequence group (if any), and the selected sequence.
824 * Some annotation rows are always rendered together - these can be identified
825 * by a common graphGroup property > -1. Only one of each group will be marked
826 * as visible (to avoid duplication of the display). For such groups we add a
827 * composite type name, e.g.
829 * IUPredWS (Long), IUPredWS (Short)
833 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
834 List<SequenceI> forSequences)
836 showMenu.removeAll();
837 hideMenu.removeAll();
839 final List<String> all = Arrays
841 { MessageManager.getString("label.all") });
842 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
844 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
846 showMenu.addSeparator();
847 hideMenu.addSeparator();
849 final AlignmentAnnotation[] annotations = ap.getAlignment()
850 .getAlignmentAnnotation();
853 * Find shown/hidden annotations types, distinguished by source (calcId),
854 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
855 * the insertion order, which is the order of the annotations on the
858 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
859 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
860 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
861 AlignmentAnnotationUtils.asList(annotations), forSequences);
863 for (String calcId : hiddenTypes.keySet())
865 for (List<String> type : hiddenTypes.get(calcId))
867 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
871 // grey out 'show annotations' if none are hidden
872 showMenu.setEnabled(!hiddenTypes.isEmpty());
874 for (String calcId : shownTypes.keySet())
876 for (List<String> type : shownTypes.get(calcId))
878 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
882 // grey out 'hide annotations' if none are shown
883 hideMenu.setEnabled(!shownTypes.isEmpty());
887 * Returns a list of sequences - either the current selection group (if there
888 * is one), else the specified single sequence.
893 protected List<SequenceI> getSequenceScope(SequenceI seq)
895 List<SequenceI> forSequences = null;
896 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
897 if (selectionGroup != null && selectionGroup.getSize() > 0)
899 forSequences = selectionGroup.getSequences();
903 forSequences = seq == null ? Collections.<SequenceI> emptyList()
904 : Arrays.asList(seq);
910 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
913 * @param showOrHideMenu
915 * @param forSequences
916 * the sequences whose annotations may be shown or hidden
921 * if true this is a special label meaning 'All'
922 * @param actionIsShow
923 * if true, the select menu item action is to show the annotation
926 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
927 final List<SequenceI> forSequences, String calcId,
928 final List<String> types, final boolean allTypes,
929 final boolean actionIsShow)
931 String label = types.toString(); // [a, b, c]
932 label = label.substring(1, label.length() - 1); // a, b, c
933 final JMenuItem item = new JMenuItem(label);
934 item.setToolTipText(calcId);
935 item.addActionListener(new ActionListener()
938 public void actionPerformed(ActionEvent e)
940 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
941 types, forSequences, allTypes, actionIsShow);
945 showOrHideMenu.add(item);
948 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
951 // TODO: usability: thread off the generation of group url content so root
953 // sequence only URLs
954 // ID/regex match URLs
955 JMenu groupLinksMenu = new JMenu(
956 MessageManager.getString("action.group_link"));
957 // three types of url that might be created.
958 JMenu[] linkMenus = new JMenu[] { null,
959 new JMenu(MessageManager.getString("action.ids")),
960 new JMenu(MessageManager.getString("action.sequences")),
961 new JMenu(MessageManager.getString("action.ids_sequences")) };
963 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
964 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
965 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
966 for (int sq = 0; sq < seqs.length; sq++)
969 int start = seqs[sq].findPosition(sg.getStartRes()),
970 end = seqs[sq].findPosition(sg.getEndRes());
971 // just collect ids from dataset sequence
972 // TODO: check if IDs collected from selecton group intersects with the
973 // current selection, too
974 SequenceI sqi = seqs[sq];
975 while (sqi.getDatasetSequence() != null)
977 sqi = sqi.getDatasetSequence();
979 DBRefEntry[] dbr = sqi.getDBRefs();
980 if (dbr != null && dbr.length > 0)
982 for (int d = 0; d < dbr.length; d++)
984 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
985 Object[] sarray = commonDbrefs.get(src);
988 sarray = new Object[2];
989 sarray[0] = new int[] { 0 };
990 sarray[1] = new String[seqs.length];
992 commonDbrefs.put(src, sarray);
995 if (((String[]) sarray[1])[sq] == null)
997 if (!dbr[d].hasMap() || (dbr[d].getMap()
998 .locateMappedRange(start, end) != null))
1000 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1001 ((int[]) sarray[0])[0]++;
1007 // now create group links for all distinct ID/sequence sets.
1008 boolean addMenu = false; // indicates if there are any group links to give
1010 for (String link : groupLinks)
1012 GroupUrlLink urlLink = null;
1015 urlLink = new GroupUrlLink(link);
1016 } catch (Exception foo)
1018 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
1022 if (!urlLink.isValid())
1024 Cache.log.error(urlLink.getInvalidMessage());
1027 final String label = urlLink.getLabel();
1028 boolean usingNames = false;
1029 // Now see which parts of the group apply for this URL
1030 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1031 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
1032 String[] seqstr, ids; // input to makeUrl
1035 int numinput = ((int[]) idset[0])[0];
1036 String[] allids = ((String[]) idset[1]);
1037 seqstr = new String[numinput];
1038 ids = new String[numinput];
1039 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1041 if (allids[sq] != null)
1043 ids[idcount] = allids[sq];
1044 seqstr[idcount++] = idandseqs[1][sq];
1050 // just use the id/seq set
1051 seqstr = idandseqs[1];
1055 // and try and make the groupURL!
1057 Object[] urlset = null;
1060 urlset = urlLink.makeUrlStubs(ids, seqstr,
1061 "FromJalview" + System.currentTimeMillis(), false);
1062 } catch (UrlStringTooLongException e)
1067 int type = urlLink.getGroupURLType() & 3;
1068 // first two bits ofurlLink type bitfield are sequenceids and sequences
1069 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1070 addshowLink(linkMenus[type],
1071 label + (((type & 1) == 1)
1072 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
1080 groupLinksMenu = new JMenu(
1081 MessageManager.getString("action.group_link"));
1082 for (int m = 0; m < linkMenus.length; m++)
1084 if (linkMenus[m] != null
1085 && linkMenus[m].getMenuComponentCount() > 0)
1087 groupLinksMenu.add(linkMenus[m]);
1091 groupMenu.add(groupLinksMenu);
1101 private void jbInit() throws Exception
1103 groupMenu.setText(MessageManager.getString("label.selection"));
1104 groupName.setText(MessageManager.getString("label.name"));
1105 groupName.addActionListener(new ActionListener()
1108 public void actionPerformed(ActionEvent e)
1110 groupName_actionPerformed();
1113 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1115 JMenuItem sequenceName = new JMenuItem(
1116 MessageManager.getString("label.edit_name_description"));
1117 sequenceName.addActionListener(new ActionListener()
1120 public void actionPerformed(ActionEvent e)
1122 sequenceName_actionPerformed();
1125 JMenuItem chooseAnnotations = new JMenuItem(
1126 MessageManager.getString("action.choose_annotations"));
1127 chooseAnnotations.addActionListener(new ActionListener()
1130 public void actionPerformed(ActionEvent e)
1132 chooseAnnotations_actionPerformed(e);
1135 JMenuItem sequenceDetails = new JMenuItem(
1136 MessageManager.getString("label.sequence_details"));
1137 sequenceDetails.addActionListener(new ActionListener()
1140 public void actionPerformed(ActionEvent e)
1142 createSequenceDetailsReport(new SequenceI[] { sequence });
1145 JMenuItem sequenceSelDetails = new JMenuItem(
1146 MessageManager.getString("label.sequence_details"));
1147 sequenceSelDetails.addActionListener(new ActionListener()
1150 public void actionPerformed(ActionEvent e)
1152 createSequenceDetailsReport(ap.av.getSequenceSelection());
1157 .setText(MessageManager.getString("action.remove_group"));
1158 unGroupMenuItem.addActionListener(new ActionListener()
1161 public void actionPerformed(ActionEvent e)
1163 unGroupMenuItem_actionPerformed();
1167 .setText(MessageManager.getString("action.create_group"));
1168 createGroupMenuItem.addActionListener(new ActionListener()
1171 public void actionPerformed(ActionEvent e)
1173 createGroupMenuItem_actionPerformed();
1177 JMenuItem outline = new JMenuItem(
1178 MessageManager.getString("action.border_colour"));
1179 outline.addActionListener(new ActionListener()
1182 public void actionPerformed(ActionEvent e)
1184 outline_actionPerformed();
1187 showBoxes.setText(MessageManager.getString("action.boxes"));
1188 showBoxes.setState(true);
1189 showBoxes.addActionListener(new ActionListener()
1192 public void actionPerformed(ActionEvent e)
1194 showBoxes_actionPerformed();
1197 showText.setText(MessageManager.getString("action.text"));
1198 showText.setState(true);
1199 showText.addActionListener(new ActionListener()
1202 public void actionPerformed(ActionEvent e)
1204 showText_actionPerformed();
1207 showColourText.setText(MessageManager.getString("label.colour_text"));
1208 showColourText.addActionListener(new ActionListener()
1211 public void actionPerformed(ActionEvent e)
1213 showColourText_actionPerformed();
1217 .setText(MessageManager.getString("label.show_non_conserved"));
1218 displayNonconserved.setState(true);
1219 displayNonconserved.addActionListener(new ActionListener()
1222 public void actionPerformed(ActionEvent e)
1224 showNonconserved_actionPerformed();
1227 editMenu.setText(MessageManager.getString("action.edit"));
1228 JMenuItem cut = new JMenuItem(MessageManager.getString("action.cut"));
1229 cut.addActionListener(new ActionListener()
1232 public void actionPerformed(ActionEvent e)
1234 cut_actionPerformed();
1237 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1238 upperCase.addActionListener(new ActionListener()
1241 public void actionPerformed(ActionEvent e)
1246 JMenuItem copy = new JMenuItem(MessageManager.getString("action.copy"));
1247 copy.addActionListener(new ActionListener()
1250 public void actionPerformed(ActionEvent e)
1252 copy_actionPerformed();
1255 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1256 lowerCase.addActionListener(new ActionListener()
1259 public void actionPerformed(ActionEvent e)
1264 toggle.setText(MessageManager.getString("label.toggle_case"));
1265 toggle.addActionListener(new ActionListener()
1268 public void actionPerformed(ActionEvent e)
1274 MessageManager.getString("label.out_to_textbox") + "...");
1275 seqShowAnnotationsMenu
1276 .setText(MessageManager.getString("label.show_annotations"));
1277 seqHideAnnotationsMenu
1278 .setText(MessageManager.getString("label.hide_annotations"));
1279 groupShowAnnotationsMenu
1280 .setText(MessageManager.getString("label.show_annotations"));
1281 groupHideAnnotationsMenu
1282 .setText(MessageManager.getString("label.hide_annotations"));
1283 JMenuItem sequenceFeature = new JMenuItem(
1284 MessageManager.getString("label.create_sequence_feature"));
1285 sequenceFeature.addActionListener(new ActionListener()
1288 public void actionPerformed(ActionEvent e)
1290 sequenceFeature_actionPerformed();
1293 editGroupMenu.setText(MessageManager.getString("label.group"));
1294 chooseStructure.setText(
1295 MessageManager.getString("label.show_pdbstruct_dialog"));
1296 chooseStructure.addActionListener(new ActionListener()
1299 public void actionPerformed(ActionEvent actionEvent)
1301 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1302 if (ap.av.getSelectionGroup() != null)
1304 selectedSeqs = ap.av.getSequenceSelection();
1306 new StructureChooser(selectedSeqs, sequence, ap);
1311 .setText(MessageManager.getString("label.view_rna_structure"));
1313 // colStructureMenu.setText("Colour By Structure");
1314 JMenuItem editSequence = new JMenuItem(
1315 MessageManager.getString("label.edit_sequence") + "...");
1316 editSequence.addActionListener(new ActionListener()
1319 public void actionPerformed(ActionEvent actionEvent)
1321 editSequence_actionPerformed(actionEvent);
1324 makeReferenceSeq.setText(
1325 MessageManager.getString("label.mark_as_representative"));
1326 makeReferenceSeq.addActionListener(new ActionListener()
1330 public void actionPerformed(ActionEvent actionEvent)
1332 makeReferenceSeq_actionPerformed(actionEvent);
1337 groupMenu.add(sequenceSelDetails);
1340 add(rnaStructureMenu);
1341 add(chooseStructure);
1344 JMenuItem hideInsertions = new JMenuItem(
1345 MessageManager.getString("label.hide_insertions"));
1346 hideInsertions.addActionListener(new ActionListener()
1350 public void actionPerformed(ActionEvent e)
1352 hideInsertions_actionPerformed(e);
1355 add(hideInsertions);
1357 // annotations configuration panel suppressed for now
1358 // groupMenu.add(chooseAnnotations);
1361 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1362 * (if a selection group is in force).
1364 sequenceMenu.add(seqShowAnnotationsMenu);
1365 sequenceMenu.add(seqHideAnnotationsMenu);
1366 sequenceMenu.add(seqAddReferenceAnnotations);
1367 groupMenu.add(groupShowAnnotationsMenu);
1368 groupMenu.add(groupHideAnnotationsMenu);
1369 groupMenu.add(groupAddReferenceAnnotations);
1370 groupMenu.add(editMenu);
1371 groupMenu.add(outputMenu);
1372 groupMenu.add(sequenceFeature);
1373 groupMenu.add(createGroupMenuItem);
1374 groupMenu.add(unGroupMenuItem);
1375 groupMenu.add(editGroupMenu);
1376 sequenceMenu.add(sequenceName);
1377 sequenceMenu.add(sequenceDetails);
1378 sequenceMenu.add(makeReferenceSeq);
1385 editMenu.add(editSequence);
1386 editMenu.add(upperCase);
1387 editMenu.add(lowerCase);
1388 editMenu.add(toggle);
1389 editGroupMenu.add(groupName);
1390 editGroupMenu.add(colourMenu);
1391 editGroupMenu.add(showBoxes);
1392 editGroupMenu.add(showText);
1393 editGroupMenu.add(showColourText);
1394 editGroupMenu.add(outline);
1395 editGroupMenu.add(displayNonconserved);
1399 * Constructs the entries for the colour menu
1401 protected void initColourMenu()
1403 colourMenu.setText(MessageManager.getString("label.group_colour"));
1404 textColour.setText(MessageManager.getString("label.text_colour"));
1405 textColour.addActionListener(new ActionListener()
1408 public void actionPerformed(ActionEvent e)
1410 textColour_actionPerformed();
1414 abovePIDColour.setText(
1415 MessageManager.getString("label.above_identity_threshold"));
1416 abovePIDColour.addActionListener(new ActionListener()
1419 public void actionPerformed(ActionEvent e)
1421 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1426 MessageManager.getString("label.modify_identity_threshold"));
1427 modifyPID.addActionListener(new ActionListener()
1430 public void actionPerformed(ActionEvent e)
1432 modifyPID_actionPerformed();
1436 conservationMenuItem
1437 .setText(MessageManager.getString("action.by_conservation"));
1438 conservationMenuItem.addActionListener(new ActionListener()
1441 public void actionPerformed(ActionEvent e)
1443 conservationMenuItem_actionPerformed(
1444 conservationMenuItem.isSelected());
1448 annotationColour = new JRadioButtonMenuItem(
1449 MessageManager.getString("action.by_annotation"));
1450 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1451 annotationColour.setEnabled(false);
1452 annotationColour.setToolTipText(
1453 MessageManager.getString("label.by_annotation_tooltip"));
1455 modifyConservation.setText(MessageManager
1456 .getString("label.modify_conservation_threshold"));
1457 modifyConservation.addActionListener(new ActionListener()
1460 public void actionPerformed(ActionEvent e)
1462 modifyConservation_actionPerformed();
1468 * Builds the group colour sub-menu, including any user-defined colours which
1469 * were loaded at startup or during the Jalview session
1471 protected void buildColourMenu()
1473 SequenceGroup sg = ap.av.getSelectionGroup();
1477 * popup menu with no sequence group scope
1481 colourMenu.removeAll();
1482 colourMenu.add(textColour);
1483 colourMenu.addSeparator();
1485 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1487 bg.add(annotationColour);
1488 colourMenu.add(annotationColour);
1490 colourMenu.addSeparator();
1491 colourMenu.add(conservationMenuItem);
1492 colourMenu.add(modifyConservation);
1493 colourMenu.add(abovePIDColour);
1494 colourMenu.add(modifyPID);
1497 protected void modifyConservation_actionPerformed()
1499 SequenceGroup sg = getGroup();
1502 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1503 SliderPanel.showConservationSlider();
1507 protected void modifyPID_actionPerformed()
1509 SequenceGroup sg = getGroup();
1512 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1514 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1515 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1516 SliderPanel.showPIDSlider();
1521 * Check for any annotations on the underlying dataset sequences (for the
1522 * current selection group) which are not 'on the alignment'.If any are found,
1523 * enable the option to add them to the alignment. The criteria for 'on the
1524 * alignment' is finding an alignment annotation on the alignment, matched on
1525 * calcId, label and sequenceRef.
1527 * A tooltip is also constructed that displays the source (calcId) and type
1528 * (label) of the annotations that can be added.
1531 * @param forSequences
1533 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1534 List<SequenceI> forSequences)
1536 menuItem.setEnabled(false);
1539 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1540 * Using TreeMap means calcIds are shown in alphabetical order.
1542 SortedMap<String, String> tipEntries = new TreeMap<>();
1543 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1544 AlignmentI al = this.ap.av.getAlignment();
1545 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1547 if (!candidates.isEmpty())
1549 StringBuilder tooltip = new StringBuilder(64);
1550 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1553 * Found annotations that could be added. Enable the menu item, and
1554 * configure its tooltip and action.
1556 menuItem.setEnabled(true);
1557 for (String calcId : tipEntries.keySet())
1559 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1561 String tooltipText = JvSwingUtils.wrapTooltip(true,
1562 tooltip.toString());
1563 menuItem.setToolTipText(tooltipText);
1565 menuItem.addActionListener(new ActionListener()
1568 public void actionPerformed(ActionEvent e)
1570 addReferenceAnnotations_actionPerformed(candidates);
1577 * Add annotations to the sequences and to the alignment.
1580 * a map whose keys are sequences on the alignment, and values a list
1581 * of annotations to add to each sequence
1583 protected void addReferenceAnnotations_actionPerformed(
1584 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1586 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1587 final AlignmentI alignment = this.ap.getAlignment();
1588 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1593 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1595 if (!ap.av.getAlignment().hasSeqrep())
1597 // initialise the display flags so the user sees something happen
1598 ap.av.setDisplayReferenceSeq(true);
1599 ap.av.setColourByReferenceSeq(true);
1600 ap.av.getAlignment().setSeqrep(sequence);
1604 if (ap.av.getAlignment().getSeqrep() == sequence)
1606 ap.av.getAlignment().setSeqrep(null);
1610 ap.av.getAlignment().setSeqrep(sequence);
1616 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1618 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1619 BitSet inserts = new BitSet();
1621 boolean markedPopup = false;
1622 // mark inserts in current selection
1623 if (ap.av.getSelectionGroup() != null)
1625 // mark just the columns in the selection group to be hidden
1626 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1627 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1629 // now clear columns without gaps
1630 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1636 inserts.and(sq.getInsertionsAsBits());
1638 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1639 ap.av.getSelectionGroup().getEndRes());
1642 // now mark for sequence under popup if we haven't already done it
1643 else if (!markedPopup && sequence != null)
1645 inserts.or(sequence.getInsertionsAsBits());
1647 // and set hidden columns accordingly
1648 hidden.hideColumns(inserts);
1653 protected void sequenceSelectionDetails_actionPerformed()
1655 createSequenceDetailsReport(ap.av.getSequenceSelection());
1658 public void createSequenceDetailsReport(SequenceI[] sequences)
1660 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1661 StringBuilder contents = new StringBuilder(128);
1662 for (SequenceI seq : sequences)
1664 contents.append("<p><h2>" + MessageManager.formatMessage(
1665 "label.create_sequence_details_report_annotation_for",
1667 { seq.getDisplayId(true) }) + "</h2></p><p>");
1668 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
1669 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1670 contents.append("</p>");
1672 cap.setText("<html>" + contents.toString() + "</html>");
1674 Desktop.addInternalFrame(cap,
1675 MessageManager.formatMessage("label.sequence_details_for",
1676 (sequences.length == 1 ? new Object[]
1677 { sequences[0].getDisplayId(true) }
1680 .getString("label.selection") })),
1685 protected void showNonconserved_actionPerformed()
1687 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1692 * call to refresh view after settings change
1696 ap.updateAnnotation();
1697 // removed paintAlignment(true) here:
1698 // updateAnnotation calls paintAlignment already, so don't need to call
1701 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1705 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1706 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1716 public void abovePIDColour_actionPerformed(boolean selected)
1718 SequenceGroup sg = getGroup();
1726 sg.cs.setConsensus(AAFrequency.calculate(
1727 sg.getSequences(ap.av.getHiddenRepSequences()),
1728 sg.getStartRes(), sg.getEndRes() + 1));
1730 int threshold = SliderPanel.setPIDSliderSource(ap,
1731 sg.getGroupColourScheme(), getGroup().getName());
1733 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1735 SliderPanel.showPIDSlider();
1738 // remove PIDColouring
1740 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1741 SliderPanel.hidePIDSlider();
1743 modifyPID.setEnabled(selected);
1749 * Open a panel where the user can choose which types of sequence annotation
1754 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1756 // todo correct way to guard against opening a duplicate panel?
1757 new AnnotationChooser(ap);
1766 public void conservationMenuItem_actionPerformed(boolean selected)
1768 SequenceGroup sg = getGroup();
1776 // JBPNote: Conservation name shouldn't be i18n translated
1777 Conservation c = new Conservation("Group",
1778 sg.getSequences(ap.av.getHiddenRepSequences()),
1779 sg.getStartRes(), sg.getEndRes() + 1);
1782 c.verdict(false, ap.av.getConsPercGaps());
1783 sg.cs.setConservation(c);
1785 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1787 SliderPanel.showConservationSlider();
1790 // remove ConservationColouring
1792 sg.cs.setConservation(null);
1793 SliderPanel.hideConservationSlider();
1795 modifyConservation.setEnabled(selected);
1806 protected void groupName_actionPerformed()
1809 SequenceGroup sg = getGroup();
1810 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1811 sg.getDescription(),
1812 " " + MessageManager.getString("label.group_name") + " ",
1813 MessageManager.getString("label.group_description") + " ",
1814 MessageManager.getString("label.edit_group_name_description"),
1822 sg.setName(dialog.getName());
1823 sg.setDescription(dialog.getDescription());
1828 * Get selection group - adding it to the alignment if necessary.
1830 * @return sequence group to operate on
1832 SequenceGroup getGroup()
1834 SequenceGroup sg = ap.av.getSelectionGroup();
1835 // this method won't add a new group if it already exists
1838 ap.av.getAlignment().addGroup(sg);
1845 * Shows a dialog where the sequence name and description may be edited. If a
1846 * name containing spaces is entered, these are converted to underscores, with a
1849 void sequenceName_actionPerformed()
1851 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1852 sequence.getDescription(),
1853 " " + MessageManager.getString("label.sequence_name")
1855 MessageManager.getString("label.sequence_description") + " ",
1856 MessageManager.getString(
1857 "label.edit_sequence_name_description"),
1865 String name = dialog.getName();
1868 if (name.indexOf(" ") > -1)
1870 JvOptionPane.showMessageDialog(ap,
1872 .getString("label.spaces_converted_to_backslashes"),
1874 .getString("label.no_spaces_allowed_sequence_name"),
1875 JvOptionPane.WARNING_MESSAGE);
1876 name = name.replace(' ', '_');
1879 sequence.setName(name);
1880 ap.paintAlignment(false, false);
1883 sequence.setDescription(dialog.getDescription());
1885 ap.av.firePropertyChange("alignment", null,
1886 ap.av.getAlignment().getSequences());
1896 void unGroupMenuItem_actionPerformed()
1898 SequenceGroup sg = ap.av.getSelectionGroup();
1899 ap.av.getAlignment().deleteGroup(sg);
1900 ap.av.setSelectionGroup(null);
1904 void createGroupMenuItem_actionPerformed()
1906 getGroup(); // implicitly creates group - note - should apply defaults / use
1907 // standard alignment window logic for this
1917 protected void outline_actionPerformed()
1919 SequenceGroup sg = getGroup();
1920 Color col = JColorChooser.showDialog(this,
1921 MessageManager.getString("label.select_outline_colour"),
1926 sg.setOutlineColour(col);
1938 public void showBoxes_actionPerformed()
1940 getGroup().setDisplayBoxes(showBoxes.isSelected());
1950 public void showText_actionPerformed()
1952 getGroup().setDisplayText(showText.isSelected());
1962 public void showColourText_actionPerformed()
1964 getGroup().setColourText(showColourText.isSelected());
1968 void hideSequences(boolean representGroup)
1970 ap.av.hideSequences(sequence, representGroup);
1973 public void copy_actionPerformed()
1975 ap.alignFrame.copy_actionPerformed(null);
1978 public void cut_actionPerformed()
1980 ap.alignFrame.cut_actionPerformed(null);
1983 void changeCase(ActionEvent e)
1985 Object source = e.getSource();
1986 SequenceGroup sg = ap.av.getSelectionGroup();
1990 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
1991 sg.getStartRes(), sg.getEndRes() + 1);
1996 if (source == toggle)
1998 description = MessageManager.getString("label.toggle_case");
1999 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2001 else if (source == upperCase)
2003 description = MessageManager.getString("label.to_upper_case");
2004 caseChange = ChangeCaseCommand.TO_UPPER;
2008 description = MessageManager.getString("label.to_lower_case");
2009 caseChange = ChangeCaseCommand.TO_LOWER;
2012 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2013 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2014 startEnd, caseChange);
2016 ap.alignFrame.addHistoryItem(caseCommand);
2018 ap.av.firePropertyChange("alignment", null,
2019 ap.av.getAlignment().getSequences());
2024 public void outputText_actionPerformed(ActionEvent e)
2026 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2027 cap.setForInput(null);
2028 Desktop.addInternalFrame(cap, MessageManager
2029 .formatMessage("label.alignment_output_command", new Object[]
2030 { e.getActionCommand() }), 600, 500);
2032 String[] omitHidden = null;
2034 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2035 // or we simply trust the user wants
2036 // wysiwig behaviour
2038 FileFormatI fileFormat = FileFormats.getInstance()
2039 .forName(e.getActionCommand());
2041 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2044 public void sequenceFeature_actionPerformed()
2046 SequenceGroup sg = ap.av.getSelectionGroup();
2052 List<SequenceI> seqs = new ArrayList<>();
2053 List<SequenceFeature> features = new ArrayList<>();
2056 * assemble dataset sequences, and template new sequence features,
2057 * for the amend features dialog
2059 int gSize = sg.getSize();
2060 for (int i = 0; i < gSize; i++)
2062 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2063 int end = sg.findEndRes(sg.getSequenceAt(i));
2066 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2067 features.add(new SequenceFeature(null, null, start, end, null));
2072 * an entirely gapped region will generate empty lists of sequence / features
2074 if (!seqs.isEmpty())
2076 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer()
2077 .amendFeatures(seqs, features, true, ap))
2079 ap.alignFrame.setShowSeqFeatures(true);
2080 ap.av.setSearchResults(null); // clear highlighting
2081 ap.repaint(); // draw new/amended features
2086 public void textColour_actionPerformed()
2088 SequenceGroup sg = getGroup();
2091 new TextColourChooser().chooseColour(ap, sg);
2095 public void editSequence_actionPerformed(ActionEvent actionEvent)
2097 SequenceGroup sg = ap.av.getSelectionGroup();
2099 SequenceI seq = sequence;
2104 seq = sg.getSequenceAt(0);
2107 EditNameDialog dialog = new EditNameDialog(
2108 seq.getSequenceAsString(sg.getStartRes(),
2109 sg.getEndRes() + 1),
2110 null, MessageManager.getString("label.edit_sequence"), null,
2111 MessageManager.getString("label.edit_sequence"),
2116 EditCommand editCommand = new EditCommand(
2117 MessageManager.getString("label.edit_sequences"),
2119 dialog.getName().replace(' ', ap.av.getGapCharacter()),
2120 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2121 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2123 ap.alignFrame.addHistoryItem(editCommand);
2125 ap.av.firePropertyChange("alignment", null,
2126 ap.av.getAlignment().getSequences());
2132 * Action on user selecting an item from the colour menu (that does not have
2133 * its bespoke action handler)
2138 public void changeColour_actionPerformed(String colourSchemeName)
2140 SequenceGroup sg = getGroup();
2142 * switch to the chosen colour scheme (or null for None)
2144 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2145 .getColourScheme(colourSchemeName, ap.av, sg,
2146 ap.av.getHiddenRepSequences());
2147 sg.setColourScheme(colourScheme);
2148 if (colourScheme instanceof Blosum62ColourScheme
2149 || colourScheme instanceof PIDColourScheme)
2151 sg.cs.setConsensus(AAFrequency.calculate(
2152 sg.getSequences(ap.av.getHiddenRepSequences()),
2153 sg.getStartRes(), sg.getEndRes() + 1));