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.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.JCheckBoxMenuItem;
72 import javax.swing.JColorChooser;
73 import javax.swing.JMenu;
74 import javax.swing.JMenuItem;
75 import javax.swing.JPopupMenu;
81 * @version $Revision: 1.118 $
83 public class PopupMenu extends JPopupMenu implements ColourChangeListener
85 JMenu groupMenu = new JMenu();
87 JMenuItem groupName = new JMenuItem();
89 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
91 protected JMenuItem modifyPID = new JMenuItem();
93 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
95 protected JMenuItem modifyConservation = new JMenuItem();
99 JMenu sequenceMenu = new JMenu();
101 JMenuItem sequenceName = new JMenuItem();
103 JMenuItem sequenceDetails = new JMenuItem();
105 JMenuItem sequenceSelDetails = new JMenuItem();
107 JMenuItem makeReferenceSeq = new JMenuItem();
109 JMenuItem chooseAnnotations = new JMenuItem();
113 JMenuItem createGroupMenuItem = new JMenuItem();
115 JMenuItem unGroupMenuItem = new JMenuItem();
117 JMenuItem outline = new JMenuItem();
119 JMenu colourMenu = new JMenu();
121 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
123 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
125 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
127 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
129 JMenu editMenu = new JMenu();
131 JMenuItem cut = new JMenuItem();
133 JMenuItem copy = new JMenuItem();
135 JMenuItem upperCase = new JMenuItem();
137 JMenuItem lowerCase = new JMenuItem();
139 JMenuItem toggle = new JMenuItem();
141 JMenu pdbMenu = new JMenu();
143 JMenu outputMenu = new JMenu();
145 JMenu seqShowAnnotationsMenu = new JMenu();
147 JMenu seqHideAnnotationsMenu = new JMenu();
149 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
150 MessageManager.getString("label.add_reference_annotations"));
152 JMenu groupShowAnnotationsMenu = new JMenu();
154 JMenu groupHideAnnotationsMenu = new JMenu();
156 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
157 MessageManager.getString("label.add_reference_annotations"));
159 JMenuItem sequenceFeature = new JMenuItem();
162 JMenuItem textColour = new JMenuItem();
164 JMenu jMenu1 = new JMenu();
166 JMenuItem pdbStructureDialog = new JMenuItem();
168 JMenu rnaStructureMenu = new JMenu();
170 JMenuItem editSequence = new JMenuItem();
172 JMenu groupLinksMenu;
174 JMenuItem hideInsertions = new JMenuItem();
177 * Creates a new PopupMenu object.
182 * non-positional features (for seq not null), or positional features
183 * at residue (for seq equal to null)
185 public PopupMenu(final AlignmentPanel ap, SequenceI seq,
186 List<SequenceFeature> features)
188 this(ap, seq, features, null);
196 * the sequence under the cursor if in the Id panel, null if in the
199 * non-positional features if in the Id panel, features at the
200 * clicked residue if in the sequence panel
203 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
204 List<SequenceFeature> features, List<String> groupLinks)
206 // /////////////////////////////////////////////////////////
207 // If this is activated from the sequence panel, the user may want to
208 // edit or annotate a particular residue. Therefore display the residue menu
210 // If from the IDPanel, we must display the sequence menu
211 // ////////////////////////////////////////////////////////
212 this.ap = alignPanel;
215 for (String ff : FileFormats.getInstance().getWritableFormats(true))
217 JMenuItem item = new JMenuItem(ff);
219 item.addActionListener(new ActionListener()
222 public void actionPerformed(ActionEvent e)
224 outputText_actionPerformed(e);
228 outputMenu.add(item);
232 * Build menus for annotation types that may be shown or hidden, and for
233 * 'reference annotations' that may be added to the alignment. First for the
234 * currently selected sequence (if there is one):
236 final List<SequenceI> selectedSequence = (seq == null
237 ? Collections.<SequenceI> emptyList() : Arrays.asList(seq));
239 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
240 seqHideAnnotationsMenu, selectedSequence);
241 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
245 * And repeat for the current selection group (if there is one):
247 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
248 ? Collections.<SequenceI> emptyList()
249 : alignPanel.av.getSelectionGroup().getSequences());
250 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
251 groupHideAnnotationsMenu, selectedGroup);
252 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
258 } catch (Exception e)
266 sequenceMenu.setText(sequence.getName());
267 if (seq == alignPanel.av.getAlignment().getSeqrep())
269 makeReferenceSeq.setText(
270 MessageManager.getString("action.unmark_as_reference"));
274 makeReferenceSeq.setText(
275 MessageManager.getString("action.set_as_reference"));
278 if (!alignPanel.av.getAlignment().isNucleotide())
280 remove(rnaStructureMenu);
284 int origCount = rnaStructureMenu.getItemCount();
286 * add menu items to 2D-render any alignment or sequence secondary
287 * structure annotation
289 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
290 .getAlignmentAnnotation();
293 for (final AlignmentAnnotation aa : aas)
295 if (aa.isValidStruc() && aa.sequenceRef == null)
298 * valid alignment RNA secondary structure annotation
300 menuItem = new JMenuItem();
301 menuItem.setText(MessageManager.formatMessage(
302 "label.2d_rna_structure_line", new Object[]
304 menuItem.addActionListener(new ActionListener()
307 public void actionPerformed(ActionEvent e)
309 new AppVarna(seq, aa, alignPanel);
312 rnaStructureMenu.add(menuItem);
317 if (seq.getAnnotation() != null)
319 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
320 for (final AlignmentAnnotation aa : seqAnns)
322 if (aa.isValidStruc())
325 * valid sequence RNA secondary structure annotation
327 // TODO: make rnastrucF a bit more nice
328 menuItem = new JMenuItem();
329 menuItem.setText(MessageManager.formatMessage(
330 "label.2d_rna_sequence_name", new Object[]
332 menuItem.addActionListener(new ActionListener()
335 public void actionPerformed(ActionEvent e)
337 // TODO: VARNA does'nt print gaps in the sequence
338 new AppVarna(seq, aa, alignPanel);
341 rnaStructureMenu.add(menuItem);
345 if (rnaStructureMenu.getItemCount() == origCount)
347 remove(rnaStructureMenu);
351 menuItem = new JMenuItem(
352 MessageManager.getString("action.hide_sequences"));
353 menuItem.addActionListener(new ActionListener()
356 public void actionPerformed(ActionEvent e)
358 hideSequences(false);
363 if (sequence.isHMMConsensusSequence())
365 JMenuItem selectHMM = new JCheckBoxMenuItem();
366 selectHMM.setText(MessageManager.getString("label.select_hmm"));
367 selectHMM.addActionListener(new ActionListener()
370 public void actionPerformed(ActionEvent e)
372 selectHMM_actionPerformed(sequence);
378 if (alignPanel.av.getSelectionGroup() != null
379 && alignPanel.av.getSelectionGroup().getSize() > 1)
381 menuItem = new JMenuItem(MessageManager
382 .formatMessage("label.represent_group_with", new Object[]
384 menuItem.addActionListener(new ActionListener()
387 public void actionPerformed(ActionEvent e)
392 sequenceMenu.add(menuItem);
395 if (alignPanel.av.hasHiddenRows())
397 final int index = alignPanel.av.getAlignment().findIndex(seq);
399 if (alignPanel.av.adjustForHiddenSeqs(index)
400 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
402 menuItem = new JMenuItem(
403 MessageManager.getString("action.reveal_sequences"));
404 menuItem.addActionListener(new ActionListener()
407 public void actionPerformed(ActionEvent e)
409 alignPanel.av.showSequence(index);
410 if (alignPanel.overviewPanel != null)
412 alignPanel.overviewPanel.updateOverviewImage();
420 // for the case when no sequences are even visible
421 if (alignPanel.av.hasHiddenRows())
424 menuItem = new JMenuItem(
425 MessageManager.getString("action.reveal_all"));
426 menuItem.addActionListener(new ActionListener()
429 public void actionPerformed(ActionEvent e)
431 alignPanel.av.showAllHiddenSeqs();
432 if (alignPanel.overviewPanel != null)
434 alignPanel.overviewPanel.updateOverviewImage();
443 SequenceGroup sg = alignPanel.av.getSelectionGroup();
444 boolean isDefinedGroup = (sg != null)
445 ? alignPanel.av.getAlignment().getGroups().contains(sg)
448 if (sg != null && sg.getSize() > 0)
450 groupName.setText(MessageManager
451 .getString("label.edit_name_and_description_current_group"));
453 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
455 conservationMenuItem.setEnabled(!sg.isNucleotide());
459 if (sg.cs.conservationApplied())
461 conservationMenuItem.setSelected(true);
463 if (sg.cs.getThreshold() > 0)
465 abovePIDColour.setSelected(true);
468 modifyConservation.setEnabled(conservationMenuItem.isSelected());
469 modifyPID.setEnabled(abovePIDColour.isSelected());
470 displayNonconserved.setSelected(sg.getShowNonconserved());
471 showText.setSelected(sg.getDisplayText());
472 showColourText.setSelected(sg.getColourText());
473 showBoxes.setSelected(sg.getDisplayBoxes());
474 // add any groupURLs to the groupURL submenu and make it visible
475 if (groupLinks != null && groupLinks.size() > 0)
477 buildGroupURLMenu(sg, groupLinks);
479 // Add a 'show all structures' for the current selection
480 Hashtable<String, PDBEntry> pdbe = new Hashtable<>();
481 Hashtable<String, PDBEntry> reppdb = new Hashtable<>();
483 SequenceI sqass = null;
484 for (SequenceI sq : alignPanel.av.getSequenceSelection())
486 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
487 if (pes != null && pes.size() > 0)
489 reppdb.put(pes.get(0).getId(), pes.get(0));
490 for (PDBEntry pe : pes)
492 pdbe.put(pe.getId(), pe);
502 final PDBEntry[] pe = pdbe.values()
503 .toArray(new PDBEntry[pdbe.size()]),
504 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
505 final JMenuItem gpdbview, rpdbview;
510 groupMenu.setVisible(false);
511 editMenu.setVisible(false);
516 createGroupMenuItem.setVisible(true);
517 unGroupMenuItem.setVisible(false);
518 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
522 createGroupMenuItem.setVisible(false);
523 unGroupMenuItem.setVisible(true);
524 jMenu1.setText(MessageManager.getString("action.edit_group"));
529 sequenceMenu.setVisible(false);
530 pdbStructureDialog.setVisible(false);
531 rnaStructureMenu.setVisible(false);
534 addLinks(seq, features);
538 addFeatureDetails(features);
543 * Add a link to show feature details for each sequence feature
547 protected void addFeatureDetails(List<SequenceFeature> features)
549 if (features == null || features.isEmpty())
553 JMenu details = new JMenu(
554 MessageManager.getString("label.feature_details"));
557 for (final SequenceFeature sf : features)
559 int start = sf.getBegin();
560 int end = sf.getEnd();
564 desc = String.format("%s %d", sf.getType(), start);
568 desc = String.format("%s %d-%d", sf.getType(), start, end);
570 String tooltip = desc;
571 String description = sf.getDescription();
572 if (description != null)
574 description = StringUtils.stripHtmlTags(description);
575 if (description.length() > 12)
577 desc = desc + " " + description.substring(0, 12) + "..";
581 desc = desc + " " + description;
583 tooltip = tooltip + " " + description;
585 if (sf.getFeatureGroup() != null)
587 tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
589 JMenuItem item = new JMenuItem(desc);
590 item.setToolTipText(tooltip);
591 item.addActionListener(new ActionListener()
594 public void actionPerformed(ActionEvent e)
596 showFeatureDetails(sf);
604 * Opens a panel showing a text report of feature dteails
608 protected void showFeatureDetails(SequenceFeature sf)
610 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
611 // it appears Java's CSS does not support border-collaps :-(
612 cap.addStylesheetRule("table { border-collapse: collapse;}");
613 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
614 cap.setText(sf.getDetailsReport());
616 Desktop.addInternalFrame(cap,
617 MessageManager.getString("label.feature_details"), 500, 500);
621 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
622 * When seq is not null, these are links for the sequence id, which may be to
623 * external web sites for the sequence accession, and/or links embedded in
624 * non-positional features. When seq is null, only links embedded in the
625 * provided features are added.
630 void addLinks(final SequenceI seq, List<SequenceFeature> features)
632 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
634 List<String> nlinks = null;
637 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
641 nlinks = new ArrayList<>();
644 if (features != null)
646 for (SequenceFeature sf : features)
648 if (sf.links != null)
650 for (String link : sf.links)
658 Map<String, List<String>> linkset = new LinkedHashMap<>();
660 for (String link : nlinks)
662 UrlLink urlLink = null;
665 urlLink = new UrlLink(link);
666 } catch (Exception foo)
668 Cache.log.error("Exception for URLLink '" + link + "'", foo);
672 if (!urlLink.isValid())
674 Cache.log.error(urlLink.getInvalidMessage());
678 urlLink.createLinksFromSeq(seq, linkset);
681 addshowLinks(linkMenu, linkset.values());
683 // only add link menu if it has entries
684 if (linkMenu.getItemCount() > 0)
686 if (sequence != null)
688 sequenceMenu.add(linkMenu);
698 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
699 * "All" is added first, followed by a separator. Then add any annotation
700 * types associated with the current selection. Separate menus are built for
701 * the selected sequence group (if any), and the selected sequence.
703 * Some annotation rows are always rendered together - these can be identified
704 * by a common graphGroup property > -1. Only one of each group will be marked
705 * as visible (to avoid duplication of the display). For such groups we add a
706 * composite type name, e.g.
708 * IUPredWS (Long), IUPredWS (Short)
712 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
713 List<SequenceI> forSequences)
715 showMenu.removeAll();
716 hideMenu.removeAll();
718 final List<String> all = Arrays
720 { MessageManager.getString("label.all") });
721 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
723 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
725 showMenu.addSeparator();
726 hideMenu.addSeparator();
728 final AlignmentAnnotation[] annotations = ap.getAlignment()
729 .getAlignmentAnnotation();
732 * Find shown/hidden annotations types, distinguished by source (calcId),
733 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
734 * the insertion order, which is the order of the annotations on the
737 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
738 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
739 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
740 AlignmentAnnotationUtils.asList(annotations), forSequences);
742 for (String calcId : hiddenTypes.keySet())
744 for (List<String> type : hiddenTypes.get(calcId))
746 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
750 // grey out 'show annotations' if none are hidden
751 showMenu.setEnabled(!hiddenTypes.isEmpty());
753 for (String calcId : shownTypes.keySet())
755 for (List<String> type : shownTypes.get(calcId))
757 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
761 // grey out 'hide annotations' if none are shown
762 hideMenu.setEnabled(!shownTypes.isEmpty());
766 * Returns a list of sequences - either the current selection group (if there
767 * is one), else the specified single sequence.
772 protected List<SequenceI> getSequenceScope(SequenceI seq)
774 List<SequenceI> forSequences = null;
775 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
776 if (selectionGroup != null && selectionGroup.getSize() > 0)
778 forSequences = selectionGroup.getSequences();
782 forSequences = seq == null ? Collections.<SequenceI> emptyList()
783 : Arrays.asList(seq);
789 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
792 * @param showOrHideMenu
794 * @param forSequences
795 * the sequences whose annotations may be shown or hidden
800 * if true this is a special label meaning 'All'
801 * @param actionIsShow
802 * if true, the select menu item action is to show the annotation
805 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
806 final List<SequenceI> forSequences, String calcId,
807 final List<String> types, final boolean allTypes,
808 final boolean actionIsShow)
810 String label = types.toString(); // [a, b, c]
811 label = label.substring(1, label.length() - 1); // a, b, c
812 final JMenuItem item = new JMenuItem(label);
813 item.setToolTipText(calcId);
814 item.addActionListener(new ActionListener()
817 public void actionPerformed(ActionEvent e)
819 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
820 types, forSequences, allTypes, actionIsShow);
824 showOrHideMenu.add(item);
827 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
830 // TODO: usability: thread off the generation of group url content so root
832 // sequence only URLs
833 // ID/regex match URLs
834 groupLinksMenu = new JMenu(
835 MessageManager.getString("action.group_link"));
836 // three types of url that might be created.
837 JMenu[] linkMenus = new JMenu[] { null,
838 new JMenu(MessageManager.getString("action.ids")),
839 new JMenu(MessageManager.getString("action.sequences")),
840 new JMenu(MessageManager.getString("action.ids_sequences")) };
842 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
843 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
844 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
845 for (int sq = 0; sq < seqs.length; sq++)
848 int start = seqs[sq].findPosition(sg.getStartRes()),
849 end = seqs[sq].findPosition(sg.getEndRes());
850 // just collect ids from dataset sequence
851 // TODO: check if IDs collected from selecton group intersects with the
852 // current selection, too
853 SequenceI sqi = seqs[sq];
854 while (sqi.getDatasetSequence() != null)
856 sqi = sqi.getDatasetSequence();
858 DBRefEntry[] dbr = sqi.getDBRefs();
859 if (dbr != null && dbr.length > 0)
861 for (int d = 0; d < dbr.length; d++)
863 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
864 Object[] sarray = commonDbrefs.get(src);
867 sarray = new Object[2];
868 sarray[0] = new int[] { 0 };
869 sarray[1] = new String[seqs.length];
871 commonDbrefs.put(src, sarray);
874 if (((String[]) sarray[1])[sq] == null)
876 if (!dbr[d].hasMap() || (dbr[d].getMap()
877 .locateMappedRange(start, end) != null))
879 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
880 ((int[]) sarray[0])[0]++;
886 // now create group links for all distinct ID/sequence sets.
887 boolean addMenu = false; // indicates if there are any group links to give
889 for (String link : groupLinks)
891 GroupUrlLink urlLink = null;
894 urlLink = new GroupUrlLink(link);
895 } catch (Exception foo)
897 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
901 if (!urlLink.isValid())
903 Cache.log.error(urlLink.getInvalidMessage());
906 final String label = urlLink.getLabel();
907 boolean usingNames = false;
908 // Now see which parts of the group apply for this URL
909 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
910 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
911 String[] seqstr, ids; // input to makeUrl
914 int numinput = ((int[]) idset[0])[0];
915 String[] allids = ((String[]) idset[1]);
916 seqstr = new String[numinput];
917 ids = new String[numinput];
918 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
920 if (allids[sq] != null)
922 ids[idcount] = allids[sq];
923 seqstr[idcount++] = idandseqs[1][sq];
929 // just use the id/seq set
930 seqstr = idandseqs[1];
934 // and try and make the groupURL!
936 Object[] urlset = null;
939 urlset = urlLink.makeUrlStubs(ids, seqstr,
940 "FromJalview" + System.currentTimeMillis(), false);
941 } catch (UrlStringTooLongException e)
946 int type = urlLink.getGroupURLType() & 3;
947 // first two bits ofurlLink type bitfield are sequenceids and sequences
948 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
949 addshowLink(linkMenus[type],
950 label + (((type & 1) == 1)
951 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
959 groupLinksMenu = new JMenu(
960 MessageManager.getString("action.group_link"));
961 for (int m = 0; m < linkMenus.length; m++)
963 if (linkMenus[m] != null
964 && linkMenus[m].getMenuComponentCount() > 0)
966 groupLinksMenu.add(linkMenus[m]);
970 groupMenu.add(groupLinksMenu);
974 private void addshowLinks(JMenu linkMenu,
975 Collection<List<String>> linkset)
977 for (List<String> linkstrset : linkset)
979 // split linkstr into label and url
980 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
985 * add a show URL menu item to the given linkMenu
989 * - menu label string
993 private void addshowLink(JMenu linkMenu, String label, final String url)
995 JMenuItem item = new JMenuItem(label);
996 item.setToolTipText(MessageManager.formatMessage("label.open_url_param",
999 item.addActionListener(new ActionListener()
1002 public void actionPerformed(ActionEvent e)
1004 new Thread(new Runnable()
1021 * add a late bound groupURL item to the given linkMenu
1025 * - menu label string
1026 * @param urlgenerator
1027 * GroupURLLink used to generate URL
1029 * Object array returned from the makeUrlStubs function.
1031 private void addshowLink(JMenu linkMenu, String label,
1032 final GroupUrlLink urlgenerator, final Object[] urlstub)
1034 JMenuItem item = new JMenuItem(label);
1035 item.setToolTipText(MessageManager
1036 .formatMessage("label.open_url_seqs_param", new Object[]
1037 { urlgenerator.getUrl_prefix(),
1038 urlgenerator.getNumberInvolved(urlstub) }));
1039 // TODO: put in info about what is being sent.
1040 item.addActionListener(new ActionListener()
1043 public void actionPerformed(ActionEvent e)
1045 new Thread(new Runnable()
1053 showLink(urlgenerator.constructFrom(urlstub));
1054 } catch (UrlStringTooLongException e2)
1072 private void jbInit() throws Exception
1074 groupMenu.setText(MessageManager.getString("label.selection"));
1075 groupName.setText(MessageManager.getString("label.name"));
1076 groupName.addActionListener(new ActionListener()
1079 public void actionPerformed(ActionEvent e)
1081 groupName_actionPerformed();
1084 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1085 sequenceName.setText(
1086 MessageManager.getString("label.edit_name_description"));
1087 sequenceName.addActionListener(new ActionListener()
1090 public void actionPerformed(ActionEvent e)
1092 sequenceName_actionPerformed();
1096 .setText(MessageManager.getString("action.choose_annotations"));
1097 chooseAnnotations.addActionListener(new ActionListener()
1100 public void actionPerformed(ActionEvent e)
1102 chooseAnnotations_actionPerformed(e);
1106 .setText(MessageManager.getString("label.sequence_details"));
1107 sequenceDetails.addActionListener(new ActionListener()
1110 public void actionPerformed(ActionEvent e)
1112 sequenceDetails_actionPerformed();
1116 .setText(MessageManager.getString("label.sequence_details"));
1117 sequenceSelDetails.addActionListener(new ActionListener()
1120 public void actionPerformed(ActionEvent e)
1122 sequenceSelectionDetails_actionPerformed();
1127 .setText(MessageManager.getString("action.remove_group"));
1128 unGroupMenuItem.addActionListener(new ActionListener()
1131 public void actionPerformed(ActionEvent e)
1133 unGroupMenuItem_actionPerformed();
1137 .setText(MessageManager.getString("action.create_group"));
1138 createGroupMenuItem.addActionListener(new ActionListener()
1141 public void actionPerformed(ActionEvent e)
1143 createGroupMenuItem_actionPerformed();
1147 outline.setText(MessageManager.getString("action.border_colour"));
1148 outline.addActionListener(new ActionListener()
1151 public void actionPerformed(ActionEvent e)
1153 outline_actionPerformed();
1156 showBoxes.setText(MessageManager.getString("action.boxes"));
1157 showBoxes.setState(true);
1158 showBoxes.addActionListener(new ActionListener()
1161 public void actionPerformed(ActionEvent e)
1163 showBoxes_actionPerformed();
1166 showText.setText(MessageManager.getString("action.text"));
1167 showText.setState(true);
1168 showText.addActionListener(new ActionListener()
1171 public void actionPerformed(ActionEvent e)
1173 showText_actionPerformed();
1176 showColourText.setText(MessageManager.getString("label.colour_text"));
1177 showColourText.addActionListener(new ActionListener()
1180 public void actionPerformed(ActionEvent e)
1182 showColourText_actionPerformed();
1186 .setText(MessageManager.getString("label.show_non_conserved"));
1187 displayNonconserved.setState(true);
1188 displayNonconserved.addActionListener(new ActionListener()
1191 public void actionPerformed(ActionEvent e)
1193 showNonconserved_actionPerformed();
1196 editMenu.setText(MessageManager.getString("action.edit"));
1197 cut.setText(MessageManager.getString("action.cut"));
1198 cut.addActionListener(new ActionListener()
1201 public void actionPerformed(ActionEvent e)
1203 cut_actionPerformed();
1206 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1207 upperCase.addActionListener(new ActionListener()
1210 public void actionPerformed(ActionEvent e)
1215 copy.setText(MessageManager.getString("action.copy"));
1216 copy.addActionListener(new ActionListener()
1219 public void actionPerformed(ActionEvent e)
1221 copy_actionPerformed();
1224 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1225 lowerCase.addActionListener(new ActionListener()
1228 public void actionPerformed(ActionEvent e)
1233 toggle.setText(MessageManager.getString("label.toggle_case"));
1234 toggle.addActionListener(new ActionListener()
1237 public void actionPerformed(ActionEvent e)
1243 MessageManager.getString("label.out_to_textbox") + "...");
1244 seqShowAnnotationsMenu
1245 .setText(MessageManager.getString("label.show_annotations"));
1246 seqHideAnnotationsMenu
1247 .setText(MessageManager.getString("label.hide_annotations"));
1248 groupShowAnnotationsMenu
1249 .setText(MessageManager.getString("label.show_annotations"));
1250 groupHideAnnotationsMenu
1251 .setText(MessageManager.getString("label.hide_annotations"));
1252 sequenceFeature.setText(
1253 MessageManager.getString("label.create_sequence_feature"));
1254 sequenceFeature.addActionListener(new ActionListener()
1257 public void actionPerformed(ActionEvent e)
1259 sequenceFeature_actionPerformed();
1262 jMenu1.setText(MessageManager.getString("label.group"));
1263 pdbStructureDialog.setText(
1264 MessageManager.getString("label.show_pdbstruct_dialog"));
1265 pdbStructureDialog.addActionListener(new ActionListener()
1268 public void actionPerformed(ActionEvent actionEvent)
1270 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1271 if (ap.av.getSelectionGroup() != null)
1273 selectedSeqs = ap.av.getSequenceSelection();
1275 new StructureChooser(selectedSeqs, sequence, ap);
1280 .setText(MessageManager.getString("label.view_rna_structure"));
1282 // colStructureMenu.setText("Colour By Structure");
1283 editSequence.setText(
1284 MessageManager.getString("label.edit_sequence") + "...");
1285 editSequence.addActionListener(new ActionListener()
1288 public void actionPerformed(ActionEvent actionEvent)
1290 editSequence_actionPerformed(actionEvent);
1293 makeReferenceSeq.setText(
1294 MessageManager.getString("label.mark_as_representative"));
1295 makeReferenceSeq.addActionListener(new ActionListener()
1299 public void actionPerformed(ActionEvent actionEvent)
1301 makeReferenceSeq_actionPerformed(actionEvent);
1306 .setText(MessageManager.getString("label.hide_insertions"));
1307 hideInsertions.addActionListener(new ActionListener()
1311 public void actionPerformed(ActionEvent e)
1313 hideInsertions_actionPerformed(e);
1317 groupMenu.add(sequenceSelDetails);
1320 add(rnaStructureMenu);
1321 add(pdbStructureDialog);
1322 if (sequence != null)
1324 add(hideInsertions);
1326 // annotations configuration panel suppressed for now
1327 // groupMenu.add(chooseAnnotations);
1330 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1331 * (if a selection group is in force).
1333 sequenceMenu.add(seqShowAnnotationsMenu);
1334 sequenceMenu.add(seqHideAnnotationsMenu);
1335 sequenceMenu.add(seqAddReferenceAnnotations);
1336 groupMenu.add(groupShowAnnotationsMenu);
1337 groupMenu.add(groupHideAnnotationsMenu);
1338 groupMenu.add(groupAddReferenceAnnotations);
1339 groupMenu.add(editMenu);
1340 groupMenu.add(outputMenu);
1341 groupMenu.add(sequenceFeature);
1342 groupMenu.add(createGroupMenuItem);
1343 groupMenu.add(unGroupMenuItem);
1344 groupMenu.add(jMenu1);
1345 sequenceMenu.add(sequenceName);
1346 sequenceMenu.add(sequenceDetails);
1347 sequenceMenu.add(makeReferenceSeq);
1354 editMenu.add(editSequence);
1355 editMenu.add(upperCase);
1356 editMenu.add(lowerCase);
1357 editMenu.add(toggle);
1358 // JBPNote: These shouldn't be added here - should appear in a generic
1359 // 'apply web service to this sequence menu'
1360 // pdbMenu.add(RNAFold);
1361 // pdbMenu.add(ContraFold);
1362 jMenu1.add(groupName);
1363 jMenu1.add(colourMenu);
1364 jMenu1.add(showBoxes);
1365 jMenu1.add(showText);
1366 jMenu1.add(showColourText);
1367 jMenu1.add(outline);
1368 jMenu1.add(displayNonconserved);
1371 protected void selectHMM_actionPerformed(SequenceI seq)
1373 // TODO move this to Viewport
1374 if (seq.isHMMConsensusSequence())
1376 ap.alignFrame.setSelectedHMMSequence(seq);
1381 * Constructs the entries for the colour menu
1383 protected void initColourMenu()
1385 colourMenu.setText(MessageManager.getString("label.group_colour"));
1386 textColour.setText(MessageManager.getString("label.text_colour"));
1387 textColour.addActionListener(new ActionListener()
1390 public void actionPerformed(ActionEvent e)
1392 textColour_actionPerformed();
1396 abovePIDColour.setText(
1397 MessageManager.getString("label.above_identity_threshold"));
1398 abovePIDColour.addActionListener(new ActionListener()
1401 public void actionPerformed(ActionEvent e)
1403 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1408 MessageManager.getString("label.modify_identity_threshold"));
1409 modifyPID.addActionListener(new ActionListener()
1412 public void actionPerformed(ActionEvent e)
1414 modifyPID_actionPerformed();
1418 conservationMenuItem
1419 .setText(MessageManager.getString("action.by_conservation"));
1420 conservationMenuItem.addActionListener(new ActionListener()
1423 public void actionPerformed(ActionEvent e)
1425 conservationMenuItem_actionPerformed(
1426 conservationMenuItem.isSelected());
1430 modifyConservation.setText(MessageManager
1431 .getString("label.modify_conservation_threshold"));
1432 modifyConservation.addActionListener(new ActionListener()
1435 public void actionPerformed(ActionEvent e)
1437 modifyConservation_actionPerformed();
1443 * Builds the group colour sub-menu, including any user-defined colours which
1444 * were loaded at startup or during the Jalview session
1446 protected void buildColourMenu()
1448 SequenceGroup sg = ap.av.getSelectionGroup();
1452 * popup menu with no sequence group scope
1456 colourMenu.removeAll();
1457 colourMenu.add(textColour);
1458 colourMenu.addSeparator();
1460 ColourMenuHelper.addMenuItems(colourMenu, this, sg, false);
1462 colourMenu.addSeparator();
1463 colourMenu.add(conservationMenuItem);
1464 colourMenu.add(modifyConservation);
1465 colourMenu.add(abovePIDColour);
1466 colourMenu.add(modifyPID);
1469 protected void modifyConservation_actionPerformed()
1471 SequenceGroup sg = getGroup();
1474 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1475 SliderPanel.showConservationSlider();
1479 protected void modifyPID_actionPerformed()
1481 SequenceGroup sg = getGroup();
1484 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1486 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1487 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1488 SliderPanel.showPIDSlider();
1493 * Check for any annotations on the underlying dataset sequences (for the
1494 * current selection group) which are not 'on the alignment'.If any are found,
1495 * enable the option to add them to the alignment. The criteria for 'on the
1496 * alignment' is finding an alignment annotation on the alignment, matched on
1497 * calcId, label and sequenceRef.
1499 * A tooltip is also constructed that displays the source (calcId) and type
1500 * (label) of the annotations that can be added.
1503 * @param forSequences
1505 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1506 List<SequenceI> forSequences)
1508 menuItem.setEnabled(false);
1511 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1512 * Using TreeMap means calcIds are shown in alphabetical order.
1514 SortedMap<String, String> tipEntries = new TreeMap<>();
1515 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1516 AlignmentI al = this.ap.av.getAlignment();
1517 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1519 if (!candidates.isEmpty())
1521 StringBuilder tooltip = new StringBuilder(64);
1522 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1525 * Found annotations that could be added. Enable the menu item, and
1526 * configure its tooltip and action.
1528 menuItem.setEnabled(true);
1529 for (String calcId : tipEntries.keySet())
1531 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1533 String tooltipText = JvSwingUtils.wrapTooltip(true,
1534 tooltip.toString());
1535 menuItem.setToolTipText(tooltipText);
1537 menuItem.addActionListener(new ActionListener()
1540 public void actionPerformed(ActionEvent e)
1542 addReferenceAnnotations_actionPerformed(candidates);
1549 * Add annotations to the sequences and to the alignment.
1552 * a map whose keys are sequences on the alignment, and values a list
1553 * of annotations to add to each sequence
1555 protected void addReferenceAnnotations_actionPerformed(
1556 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1558 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1559 final AlignmentI alignment = this.ap.getAlignment();
1560 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1565 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1567 if (!ap.av.getAlignment().hasSeqrep())
1569 // initialise the display flags so the user sees something happen
1570 ap.av.setDisplayReferenceSeq(true);
1571 ap.av.setColourByReferenceSeq(true);
1572 ap.av.getAlignment().setSeqrep(sequence);
1576 if (ap.av.getAlignment().getSeqrep() == sequence)
1578 ap.av.getAlignment().setSeqrep(null);
1582 ap.av.getAlignment().setSeqrep(sequence);
1588 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1590 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1591 BitSet inserts = new BitSet();
1593 boolean markedPopup = false;
1594 // mark inserts in current selection
1595 if (ap.av.getSelectionGroup() != null)
1597 // mark just the columns in the selection group to be hidden
1598 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1599 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1601 // now clear columns without gaps
1602 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1608 inserts.and(sq.getInsertionsAsBits());
1610 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1611 ap.av.getSelectionGroup().getEndRes());
1614 // now mark for sequence under popup if we haven't already done it
1615 else if (!markedPopup && sequence != null)
1617 inserts.or(sequence.getInsertionsAsBits());
1619 // and set hidden columns accordingly
1620 hidden.hideColumns(inserts);
1625 protected void sequenceSelectionDetails_actionPerformed()
1627 createSequenceDetailsReport(ap.av.getSequenceSelection());
1630 protected void sequenceDetails_actionPerformed()
1632 createSequenceDetailsReport(new SequenceI[] { sequence });
1635 public void createSequenceDetailsReport(SequenceI[] sequences)
1637 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1638 StringBuilder contents = new StringBuilder(128);
1639 for (SequenceI seq : sequences)
1641 contents.append("<p><h2>" + MessageManager.formatMessage(
1642 "label.create_sequence_details_report_annotation_for",
1644 { seq.getDisplayId(true) }) + "</h2></p><p>");
1645 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
1646 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1647 contents.append("</p>");
1649 cap.setText("<html>" + contents.toString() + "</html>");
1651 Desktop.addInternalFrame(cap,
1652 MessageManager.formatMessage("label.sequence_details_for",
1653 (sequences.length == 1 ? new Object[]
1654 { sequences[0].getDisplayId(true) }
1657 .getString("label.selection") })),
1662 protected void showNonconserved_actionPerformed()
1664 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1669 * call to refresh view after settings change
1673 ap.updateAnnotation();
1674 // removed paintAlignment(true) here:
1675 // updateAnnotation calls paintAlignment already, so don't need to call
1678 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1682 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1683 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1693 public void abovePIDColour_actionPerformed(boolean selected)
1695 SequenceGroup sg = getGroup();
1703 sg.cs.setConsensus(AAFrequency.calculate(
1704 sg.getSequences(ap.av.getHiddenRepSequences()),
1705 sg.getStartRes(), sg.getEndRes() + 1));
1707 int threshold = SliderPanel.setPIDSliderSource(ap,
1708 sg.getGroupColourScheme(), getGroup().getName());
1710 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1712 SliderPanel.showPIDSlider();
1715 // remove PIDColouring
1717 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1718 SliderPanel.hidePIDSlider();
1720 modifyPID.setEnabled(selected);
1726 * Open a panel where the user can choose which types of sequence annotation
1731 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1733 // todo correct way to guard against opening a duplicate panel?
1734 new AnnotationChooser(ap);
1743 public void conservationMenuItem_actionPerformed(boolean selected)
1745 SequenceGroup sg = getGroup();
1753 // JBPNote: Conservation name shouldn't be i18n translated
1754 Conservation c = new Conservation("Group",
1755 sg.getSequences(ap.av.getHiddenRepSequences()),
1756 sg.getStartRes(), sg.getEndRes() + 1);
1759 c.verdict(false, ap.av.getConsPercGaps());
1760 sg.cs.setConservation(c);
1762 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1764 SliderPanel.showConservationSlider();
1767 // remove ConservationColouring
1769 sg.cs.setConservation(null);
1770 SliderPanel.hideConservationSlider();
1772 modifyConservation.setEnabled(selected);
1783 protected void groupName_actionPerformed()
1786 SequenceGroup sg = getGroup();
1787 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1788 sg.getDescription(),
1789 " " + MessageManager.getString("label.group_name") + " ",
1790 MessageManager.getString("label.group_description") + " ",
1791 MessageManager.getString("label.edit_group_name_description"),
1799 sg.setName(dialog.getName());
1800 sg.setDescription(dialog.getDescription());
1805 * Get selection group - adding it to the alignment if necessary.
1807 * @return sequence group to operate on
1809 SequenceGroup getGroup()
1811 SequenceGroup sg = ap.av.getSelectionGroup();
1812 // this method won't add a new group if it already exists
1815 ap.av.getAlignment().addGroup(sg);
1827 void sequenceName_actionPerformed()
1829 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1830 sequence.getDescription(),
1831 " " + MessageManager.getString("label.sequence_name")
1833 MessageManager.getString("label.sequence_description") + " ",
1834 MessageManager.getString(
1835 "label.edit_sequence_name_description"),
1843 if (dialog.getName() != null)
1845 if (dialog.getName().indexOf(" ") > -1)
1847 JvOptionPane.showMessageDialog(ap,
1849 .getString("label.spaces_converted_to_backslashes"),
1851 .getString("label.no_spaces_allowed_sequence_name"),
1852 JvOptionPane.WARNING_MESSAGE);
1855 sequence.setName(dialog.getName().replace(' ', '_'));
1856 ap.paintAlignment(false, false);
1859 sequence.setDescription(dialog.getDescription());
1861 ap.av.firePropertyChange("alignment", null,
1862 ap.av.getAlignment().getSequences());
1872 void unGroupMenuItem_actionPerformed()
1874 SequenceGroup sg = ap.av.getSelectionGroup();
1875 ap.av.getAlignment().deleteGroup(sg);
1876 ap.av.setSelectionGroup(null);
1880 void createGroupMenuItem_actionPerformed()
1882 getGroup(); // implicitly creates group - note - should apply defaults / use
1883 // standard alignment window logic for this
1893 protected void outline_actionPerformed()
1895 SequenceGroup sg = getGroup();
1896 Color col = JColorChooser.showDialog(this,
1897 MessageManager.getString("label.select_outline_colour"),
1902 sg.setOutlineColour(col);
1914 public void showBoxes_actionPerformed()
1916 getGroup().setDisplayBoxes(showBoxes.isSelected());
1926 public void showText_actionPerformed()
1928 getGroup().setDisplayText(showText.isSelected());
1938 public void showColourText_actionPerformed()
1940 getGroup().setColourText(showColourText.isSelected());
1944 public void showLink(String url)
1948 jalview.util.BrowserLauncher.openURL(url);
1949 } catch (Exception ex)
1951 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1952 MessageManager.getString("label.web_browser_not_found_unix"),
1953 MessageManager.getString("label.web_browser_not_found"),
1954 JvOptionPane.WARNING_MESSAGE);
1956 ex.printStackTrace();
1960 void hideSequences(boolean representGroup)
1962 ap.av.hideSequences(sequence, representGroup);
1965 public void copy_actionPerformed()
1967 ap.alignFrame.copy_actionPerformed(null);
1970 public void cut_actionPerformed()
1972 ap.alignFrame.cut_actionPerformed(null);
1975 void changeCase(ActionEvent e)
1977 Object source = e.getSource();
1978 SequenceGroup sg = ap.av.getSelectionGroup();
1982 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
1983 sg.getStartRes(), sg.getEndRes() + 1);
1988 if (source == toggle)
1990 description = MessageManager.getString("label.toggle_case");
1991 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1993 else if (source == upperCase)
1995 description = MessageManager.getString("label.to_upper_case");
1996 caseChange = ChangeCaseCommand.TO_UPPER;
2000 description = MessageManager.getString("label.to_lower_case");
2001 caseChange = ChangeCaseCommand.TO_LOWER;
2004 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2005 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2006 startEnd, caseChange);
2008 ap.alignFrame.addHistoryItem(caseCommand);
2010 ap.av.firePropertyChange("alignment", null,
2011 ap.av.getAlignment().getSequences());
2016 public void outputText_actionPerformed(ActionEvent e)
2018 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2019 cap.setForInput(null);
2020 Desktop.addInternalFrame(cap, MessageManager
2021 .formatMessage("label.alignment_output_command", new Object[]
2022 { e.getActionCommand() }), 600, 500);
2024 String[] omitHidden = null;
2026 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2027 // or we simply trust the user wants
2028 // wysiwig behaviour
2030 FileFormatI fileFormat = FileFormats.getInstance()
2031 .forName(e.getActionCommand());
2033 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2036 public void sequenceFeature_actionPerformed()
2038 SequenceGroup sg = ap.av.getSelectionGroup();
2044 List<SequenceI> seqs = new ArrayList<>();
2045 List<SequenceFeature> features = new ArrayList<>();
2048 * assemble dataset sequences, and template new sequence features,
2049 * for the amend features dialog
2051 int gSize = sg.getSize();
2052 for (int i = 0; i < gSize; i++)
2054 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2055 int end = sg.findEndRes(sg.getSequenceAt(i));
2058 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2059 features.add(new SequenceFeature(null, null, start, end, null));
2064 * an entirely gapped region will generate empty lists of sequence / features
2066 if (!seqs.isEmpty())
2068 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer()
2069 .amendFeatures(seqs, features, true, ap))
2071 ap.alignFrame.setShowSeqFeatures(true);
2072 ap.av.setSearchResults(null); // clear highlighting
2073 ap.repaint(); // draw new/amended features
2078 public void textColour_actionPerformed()
2080 SequenceGroup sg = getGroup();
2083 new TextColourChooser().chooseColour(ap, sg);
2087 public void colourByStructure(String pdbid)
2089 Annotation[] anots = ap.av.getStructureSelectionManager()
2090 .colourSequenceFromStructure(sequence, pdbid);
2092 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2093 "Coloured by " + pdbid, anots);
2095 ap.av.getAlignment().addAnnotation(an);
2096 an.createSequenceMapping(sequence, 0, true);
2097 // an.adjustForAlignment();
2098 ap.av.getAlignment().setAnnotationIndex(an, 0);
2100 ap.adjustAnnotationHeight();
2102 sequence.addAlignmentAnnotation(an);
2106 public void editSequence_actionPerformed(ActionEvent actionEvent)
2108 SequenceGroup sg = ap.av.getSelectionGroup();
2112 if (sequence == null)
2114 sequence = sg.getSequenceAt(0);
2117 EditNameDialog dialog = new EditNameDialog(
2118 sequence.getSequenceAsString(sg.getStartRes(),
2119 sg.getEndRes() + 1),
2120 null, MessageManager.getString("label.edit_sequence"), null,
2121 MessageManager.getString("label.edit_sequence"),
2126 EditCommand editCommand = new EditCommand(
2127 MessageManager.getString("label.edit_sequences"),
2129 dialog.getName().replace(' ', ap.av.getGapCharacter()),
2130 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2131 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2133 ap.alignFrame.addHistoryItem(editCommand);
2135 ap.av.firePropertyChange("alignment", null,
2136 ap.av.getAlignment().getSequences());
2142 * Action on user selecting an item from the colour menu (that does not have
2143 * its bespoke action handler)
2148 public void changeColour_actionPerformed(String colourSchemeName)
2150 SequenceGroup sg = getGroup();
2152 * switch to the chosen colour scheme (or null for None)
2154 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2155 .getColourScheme(colourSchemeName, sg,
2156 ap.av.getHiddenRepSequences());
2157 sg.setColourScheme(colourScheme);
2158 if (colourScheme instanceof Blosum62ColourScheme
2159 || colourScheme instanceof PIDColourScheme)
2161 sg.cs.setConsensus(AAFrequency.calculate(
2162 sg.getSequences(ap.av.getHiddenRepSequences()),
2163 sg.getStartRes(), sg.getEndRes() + 1));