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();
161 JMenuItem textColour = new JMenuItem();
163 JMenu jMenu1 = new JMenu();
165 JMenuItem pdbStructureDialog = new JMenuItem();
167 JMenu rnaStructureMenu = new JMenu();
169 JMenuItem editSequence = new JMenuItem();
171 JMenu groupLinksMenu;
173 JMenuItem hideInsertions = new JMenuItem();
176 * Creates a new PopupMenu object.
181 * non-positional features (for seq not null), or positional features
182 * at residue (for seq equal to null)
184 public PopupMenu(final AlignmentPanel ap, SequenceI seq,
185 List<SequenceFeature> features)
187 this(ap, seq, features, null);
195 * the sequence under the cursor if in the Id panel, null if in the
198 * non-positional features if in the Id panel, features at the
199 * clicked residue if in the sequence panel
202 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
203 List<SequenceFeature> features, List<String> groupLinks)
205 // /////////////////////////////////////////////////////////
206 // If this is activated from the sequence panel, the user may want to
207 // edit or annotate a particular residue. Therefore display the residue menu
209 // If from the IDPanel, we must display the sequence menu
210 // ////////////////////////////////////////////////////////
211 this.ap = alignPanel;
214 for (String ff : FileFormats.getInstance().getWritableFormats(true))
216 JMenuItem item = new JMenuItem(ff);
218 item.addActionListener(new ActionListener()
221 public void actionPerformed(ActionEvent e)
223 outputText_actionPerformed(e);
227 outputMenu.add(item);
231 * Build menus for annotation types that may be shown or hidden, and for
232 * 'reference annotations' that may be added to the alignment. First for the
233 * currently selected sequence (if there is one):
235 final List<SequenceI> selectedSequence = (seq == null
236 ? Collections.<SequenceI> emptyList()
237 : Arrays.asList(seq));
238 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
239 seqHideAnnotationsMenu, selectedSequence);
240 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
244 * And repeat for the current selection group (if there is one):
246 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
247 ? Collections.<SequenceI> emptyList()
248 : alignPanel.av.getSelectionGroup().getSequences());
249 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
250 groupHideAnnotationsMenu, selectedGroup);
251 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
257 } catch (Exception e)
265 sequenceMenu.setText(sequence.getName());
266 if (seq == alignPanel.av.getAlignment().getSeqrep())
268 makeReferenceSeq.setText(
269 MessageManager.getString("action.unmark_as_reference"));
273 makeReferenceSeq.setText(
274 MessageManager.getString("action.set_as_reference"));
277 if (!alignPanel.av.getAlignment().isNucleotide())
279 remove(rnaStructureMenu);
283 int origCount = rnaStructureMenu.getItemCount();
285 * add menu items to 2D-render any alignment or sequence secondary
286 * structure annotation
288 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
289 .getAlignmentAnnotation();
292 for (final AlignmentAnnotation aa : aas)
294 if (aa.isValidStruc() && aa.sequenceRef == null)
297 * valid alignment RNA secondary structure annotation
299 menuItem = new JMenuItem();
300 menuItem.setText(MessageManager.formatMessage(
301 "label.2d_rna_structure_line", new Object[]
303 menuItem.addActionListener(new ActionListener()
306 public void actionPerformed(ActionEvent e)
308 new AppVarna(seq, aa, alignPanel);
311 rnaStructureMenu.add(menuItem);
316 if (seq.getAnnotation() != null)
318 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
319 for (final AlignmentAnnotation aa : seqAnns)
321 if (aa.isValidStruc())
324 * valid sequence RNA secondary structure annotation
326 // TODO: make rnastrucF a bit more nice
327 menuItem = new JMenuItem();
328 menuItem.setText(MessageManager.formatMessage(
329 "label.2d_rna_sequence_name", new Object[]
331 menuItem.addActionListener(new ActionListener()
334 public void actionPerformed(ActionEvent e)
336 // TODO: VARNA does'nt print gaps in the sequence
337 new AppVarna(seq, aa, alignPanel);
340 rnaStructureMenu.add(menuItem);
344 if (rnaStructureMenu.getItemCount() == origCount)
346 remove(rnaStructureMenu);
350 menuItem = new JMenuItem(
351 MessageManager.getString("action.hide_sequences"));
352 menuItem.addActionListener(new ActionListener()
355 public void actionPerformed(ActionEvent e)
357 hideSequences(false);
362 if (alignPanel.av.getSelectionGroup() != null
363 && alignPanel.av.getSelectionGroup().getSize() > 1)
365 menuItem = new JMenuItem(MessageManager
366 .formatMessage("label.represent_group_with", new Object[]
368 menuItem.addActionListener(new ActionListener()
371 public void actionPerformed(ActionEvent e)
376 sequenceMenu.add(menuItem);
379 if (alignPanel.av.hasHiddenRows())
381 final int index = alignPanel.av.getAlignment().findIndex(seq);
383 if (alignPanel.av.adjustForHiddenSeqs(index)
384 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
386 menuItem = new JMenuItem(
387 MessageManager.getString("action.reveal_sequences"));
388 menuItem.addActionListener(new ActionListener()
391 public void actionPerformed(ActionEvent e)
393 alignPanel.av.showSequence(index);
394 if (alignPanel.overviewPanel != null)
396 alignPanel.overviewPanel.updateOverviewImage();
404 // for the case when no sequences are even visible
405 if (alignPanel.av.hasHiddenRows())
408 menuItem = new JMenuItem(
409 MessageManager.getString("action.reveal_all"));
410 menuItem.addActionListener(new ActionListener()
413 public void actionPerformed(ActionEvent e)
415 alignPanel.av.showAllHiddenSeqs();
416 if (alignPanel.overviewPanel != null)
418 alignPanel.overviewPanel.updateOverviewImage();
427 SequenceGroup sg = alignPanel.av.getSelectionGroup();
428 boolean isDefinedGroup = (sg != null)
429 ? alignPanel.av.getAlignment().getGroups().contains(sg)
432 if (sg != null && sg.getSize() > 0)
434 groupName.setText(MessageManager
435 .getString("label.edit_name_and_description_current_group"));
437 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
439 conservationMenuItem.setEnabled(!sg.isNucleotide());
443 if (sg.cs.conservationApplied())
445 conservationMenuItem.setSelected(true);
447 if (sg.cs.getThreshold() > 0)
449 abovePIDColour.setSelected(true);
452 modifyConservation.setEnabled(conservationMenuItem.isSelected());
453 modifyPID.setEnabled(abovePIDColour.isSelected());
454 displayNonconserved.setSelected(sg.getShowNonconserved());
455 showText.setSelected(sg.getDisplayText());
456 showColourText.setSelected(sg.getColourText());
457 showBoxes.setSelected(sg.getDisplayBoxes());
458 // add any groupURLs to the groupURL submenu and make it visible
459 if (groupLinks != null && groupLinks.size() > 0)
461 buildGroupURLMenu(sg, groupLinks);
463 // Add a 'show all structures' for the current selection
464 Hashtable<String, PDBEntry> pdbe = new Hashtable<>(), reppdb = new Hashtable<>();
466 SequenceI sqass = null;
467 for (SequenceI sq : alignPanel.av.getSequenceSelection())
469 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
470 if (pes != null && pes.size() > 0)
472 reppdb.put(pes.get(0).getId(), pes.get(0));
473 for (PDBEntry pe : pes)
475 pdbe.put(pe.getId(), pe);
485 final PDBEntry[] pe = pdbe.values()
486 .toArray(new PDBEntry[pdbe.size()]),
487 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
488 final JMenuItem gpdbview, rpdbview;
493 groupMenu.setVisible(false);
494 editMenu.setVisible(false);
499 createGroupMenuItem.setVisible(true);
500 unGroupMenuItem.setVisible(false);
501 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
505 createGroupMenuItem.setVisible(false);
506 unGroupMenuItem.setVisible(true);
507 jMenu1.setText(MessageManager.getString("action.edit_group"));
512 sequenceMenu.setVisible(false);
513 pdbStructureDialog.setVisible(false);
514 rnaStructureMenu.setVisible(false);
517 addLinks(seq, features);
521 addFeatureDetails(features);
526 * Add a link to show feature details for each sequence feature
530 protected void addFeatureDetails(List<SequenceFeature> features)
532 if (features == null || features.isEmpty())
536 JMenu details = new JMenu(
537 MessageManager.getString("label.feature_details"));
540 for (final SequenceFeature sf : features)
542 int start = sf.getBegin();
543 int end = sf.getEnd();
547 desc = String.format("%s %d", sf.getType(), start);
551 desc = String.format("%s %d-%d", sf.getType(), start, end);
553 String tooltip = desc;
554 String description = sf.getDescription();
555 if (description != null)
557 description = StringUtils.stripHtmlTags(description);
558 if (description.length() > 12)
560 desc = desc + " " + description.substring(0, 12) + "..";
564 desc = desc + " " + description;
566 tooltip = tooltip + " " + description;
568 if (sf.getFeatureGroup() != null)
570 tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
572 JMenuItem item = new JMenuItem(desc);
573 item.setToolTipText(tooltip);
574 item.addActionListener(new ActionListener()
577 public void actionPerformed(ActionEvent e)
579 showFeatureDetails(sf);
587 * Opens a panel showing a text report of feature dteails
591 protected void showFeatureDetails(SequenceFeature sf)
593 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
594 // it appears Java's CSS does not support border-collaps :-(
595 cap.addStylesheetRule("table { border-collapse: collapse;}");
596 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
597 cap.setText(sf.getDetailsReport());
599 Desktop.addInternalFrame(cap,
600 MessageManager.getString("label.feature_details"), 500, 500);
604 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
605 * When seq is not null, these are links for the sequence id, which may be to
606 * external web sites for the sequence accession, and/or links embedded in
607 * non-positional features. When seq is null, only links embedded in the
608 * provided features are added.
613 void addLinks(final SequenceI seq, List<SequenceFeature> features)
615 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
617 List<String> nlinks = null;
620 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
624 nlinks = new ArrayList<>();
627 if (features != null)
629 for (SequenceFeature sf : features)
631 if (sf.links != null)
633 for (String link : sf.links)
641 Map<String, List<String>> linkset = new LinkedHashMap<>();
643 for (String link : nlinks)
645 UrlLink urlLink = null;
648 urlLink = new UrlLink(link);
649 } catch (Exception foo)
651 Cache.log.error("Exception for URLLink '" + link + "'", foo);
655 if (!urlLink.isValid())
657 Cache.log.error(urlLink.getInvalidMessage());
661 urlLink.createLinksFromSeq(seq, linkset);
664 addshowLinks(linkMenu, linkset.values());
666 // only add link menu if it has entries
667 if (linkMenu.getItemCount() > 0)
669 if (sequence != null)
671 sequenceMenu.add(linkMenu);
681 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
682 * "All" is added first, followed by a separator. Then add any annotation
683 * types associated with the current selection. Separate menus are built for
684 * the selected sequence group (if any), and the selected sequence.
686 * Some annotation rows are always rendered together - these can be identified
687 * by a common graphGroup property > -1. Only one of each group will be marked
688 * as visible (to avoid duplication of the display). For such groups we add a
689 * composite type name, e.g.
691 * IUPredWS (Long), IUPredWS (Short)
695 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
696 List<SequenceI> forSequences)
698 showMenu.removeAll();
699 hideMenu.removeAll();
701 final List<String> all = Arrays
703 { MessageManager.getString("label.all") });
704 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
706 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
708 showMenu.addSeparator();
709 hideMenu.addSeparator();
711 final AlignmentAnnotation[] annotations = ap.getAlignment()
712 .getAlignmentAnnotation();
715 * Find shown/hidden annotations types, distinguished by source (calcId),
716 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
717 * the insertion order, which is the order of the annotations on the
720 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
721 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
722 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
723 AlignmentAnnotationUtils.asList(annotations), forSequences);
725 for (String calcId : hiddenTypes.keySet())
727 for (List<String> type : hiddenTypes.get(calcId))
729 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
733 // grey out 'show annotations' if none are hidden
734 showMenu.setEnabled(!hiddenTypes.isEmpty());
736 for (String calcId : shownTypes.keySet())
738 for (List<String> type : shownTypes.get(calcId))
740 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
744 // grey out 'hide annotations' if none are shown
745 hideMenu.setEnabled(!shownTypes.isEmpty());
749 * Returns a list of sequences - either the current selection group (if there
750 * is one), else the specified single sequence.
755 protected List<SequenceI> getSequenceScope(SequenceI seq)
757 List<SequenceI> forSequences = null;
758 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
759 if (selectionGroup != null && selectionGroup.getSize() > 0)
761 forSequences = selectionGroup.getSequences();
765 forSequences = seq == null ? Collections.<SequenceI> emptyList()
766 : Arrays.asList(seq);
772 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
775 * @param showOrHideMenu
777 * @param forSequences
778 * the sequences whose annotations may be shown or hidden
783 * if true this is a special label meaning 'All'
784 * @param actionIsShow
785 * if true, the select menu item action is to show the annotation
788 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
789 final List<SequenceI> forSequences, String calcId,
790 final List<String> types, final boolean allTypes,
791 final boolean actionIsShow)
793 String label = types.toString(); // [a, b, c]
794 label = label.substring(1, label.length() - 1); // a, b, c
795 final JMenuItem item = new JMenuItem(label);
796 item.setToolTipText(calcId);
797 item.addActionListener(new ActionListener()
800 public void actionPerformed(ActionEvent e)
802 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
803 types, forSequences, allTypes, actionIsShow);
807 showOrHideMenu.add(item);
810 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
813 // TODO: usability: thread off the generation of group url content so root
815 // sequence only URLs
816 // ID/regex match URLs
817 groupLinksMenu = new JMenu(
818 MessageManager.getString("action.group_link"));
819 // three types of url that might be created.
820 JMenu[] linkMenus = new JMenu[] { null,
821 new JMenu(MessageManager.getString("action.ids")),
822 new JMenu(MessageManager.getString("action.sequences")),
823 new JMenu(MessageManager.getString("action.ids_sequences")) };
825 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
826 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
827 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
828 for (int sq = 0; sq < seqs.length; sq++)
831 int start = seqs[sq].findPosition(sg.getStartRes()),
832 end = seqs[sq].findPosition(sg.getEndRes());
833 // just collect ids from dataset sequence
834 // TODO: check if IDs collected from selecton group intersects with the
835 // current selection, too
836 SequenceI sqi = seqs[sq];
837 while (sqi.getDatasetSequence() != null)
839 sqi = sqi.getDatasetSequence();
841 DBRefEntry[] dbr = sqi.getDBRefs();
842 if (dbr != null && dbr.length > 0)
844 for (int d = 0; d < dbr.length; d++)
846 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
847 Object[] sarray = commonDbrefs.get(src);
850 sarray = new Object[2];
851 sarray[0] = new int[] { 0 };
852 sarray[1] = new String[seqs.length];
854 commonDbrefs.put(src, sarray);
857 if (((String[]) sarray[1])[sq] == null)
859 if (!dbr[d].hasMap() || (dbr[d].getMap()
860 .locateMappedRange(start, end) != null))
862 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
863 ((int[]) sarray[0])[0]++;
869 // now create group links for all distinct ID/sequence sets.
870 boolean addMenu = false; // indicates if there are any group links to give
872 for (String link : groupLinks)
874 GroupUrlLink urlLink = null;
877 urlLink = new GroupUrlLink(link);
878 } catch (Exception foo)
880 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
884 if (!urlLink.isValid())
886 Cache.log.error(urlLink.getInvalidMessage());
889 final String label = urlLink.getLabel();
890 boolean usingNames = false;
891 // Now see which parts of the group apply for this URL
892 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
893 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
894 String[] seqstr, ids; // input to makeUrl
897 int numinput = ((int[]) idset[0])[0];
898 String[] allids = ((String[]) idset[1]);
899 seqstr = new String[numinput];
900 ids = new String[numinput];
901 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
903 if (allids[sq] != null)
905 ids[idcount] = allids[sq];
906 seqstr[idcount++] = idandseqs[1][sq];
912 // just use the id/seq set
913 seqstr = idandseqs[1];
917 // and try and make the groupURL!
919 Object[] urlset = null;
922 urlset = urlLink.makeUrlStubs(ids, seqstr,
923 "FromJalview" + System.currentTimeMillis(), false);
924 } catch (UrlStringTooLongException e)
929 int type = urlLink.getGroupURLType() & 3;
930 // first two bits ofurlLink type bitfield are sequenceids and sequences
931 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
932 addshowLink(linkMenus[type],
933 label + (((type & 1) == 1)
934 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
942 groupLinksMenu = new JMenu(
943 MessageManager.getString("action.group_link"));
944 for (int m = 0; m < linkMenus.length; m++)
946 if (linkMenus[m] != null
947 && linkMenus[m].getMenuComponentCount() > 0)
949 groupLinksMenu.add(linkMenus[m]);
953 groupMenu.add(groupLinksMenu);
957 private void addshowLinks(JMenu linkMenu,
958 Collection<List<String>> linkset)
960 for (List<String> linkstrset : linkset)
962 // split linkstr into label and url
963 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
968 * add a show URL menu item to the given linkMenu
972 * - menu label string
976 private void addshowLink(JMenu linkMenu, String label, final String url)
978 JMenuItem item = new JMenuItem(label);
979 item.setToolTipText(MessageManager.formatMessage("label.open_url_param",
982 item.addActionListener(new ActionListener()
985 public void actionPerformed(ActionEvent e)
987 new Thread(new Runnable()
1004 * add a late bound groupURL item to the given linkMenu
1008 * - menu label string
1009 * @param urlgenerator
1010 * GroupURLLink used to generate URL
1012 * Object array returned from the makeUrlStubs function.
1014 private void addshowLink(JMenu linkMenu, String label,
1015 final GroupUrlLink urlgenerator, final Object[] urlstub)
1017 JMenuItem item = new JMenuItem(label);
1018 item.setToolTipText(MessageManager
1019 .formatMessage("label.open_url_seqs_param", new Object[]
1020 { urlgenerator.getUrl_prefix(),
1021 urlgenerator.getNumberInvolved(urlstub) }));
1022 // TODO: put in info about what is being sent.
1023 item.addActionListener(new ActionListener()
1026 public void actionPerformed(ActionEvent e)
1028 new Thread(new Runnable()
1036 showLink(urlgenerator.constructFrom(urlstub));
1037 } catch (UrlStringTooLongException e2)
1055 private void jbInit() throws Exception
1057 groupMenu.setText(MessageManager.getString("label.selection"));
1058 groupName.setText(MessageManager.getString("label.name"));
1059 groupName.addActionListener(new ActionListener()
1062 public void actionPerformed(ActionEvent e)
1064 groupName_actionPerformed();
1067 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1068 sequenceName.setText(
1069 MessageManager.getString("label.edit_name_description"));
1070 sequenceName.addActionListener(new ActionListener()
1073 public void actionPerformed(ActionEvent e)
1075 sequenceName_actionPerformed();
1079 .setText(MessageManager.getString("action.choose_annotations"));
1080 chooseAnnotations.addActionListener(new ActionListener()
1083 public void actionPerformed(ActionEvent e)
1085 chooseAnnotations_actionPerformed(e);
1089 .setText(MessageManager.getString("label.sequence_details"));
1090 sequenceDetails.addActionListener(new ActionListener()
1093 public void actionPerformed(ActionEvent e)
1095 sequenceDetails_actionPerformed();
1099 .setText(MessageManager.getString("label.sequence_details"));
1100 sequenceSelDetails.addActionListener(new ActionListener()
1103 public void actionPerformed(ActionEvent e)
1105 sequenceSelectionDetails_actionPerformed();
1110 .setText(MessageManager.getString("action.remove_group"));
1111 unGroupMenuItem.addActionListener(new ActionListener()
1114 public void actionPerformed(ActionEvent e)
1116 unGroupMenuItem_actionPerformed();
1120 .setText(MessageManager.getString("action.create_group"));
1121 createGroupMenuItem.addActionListener(new ActionListener()
1124 public void actionPerformed(ActionEvent e)
1126 createGroupMenuItem_actionPerformed();
1130 outline.setText(MessageManager.getString("action.border_colour"));
1131 outline.addActionListener(new ActionListener()
1134 public void actionPerformed(ActionEvent e)
1136 outline_actionPerformed();
1139 showBoxes.setText(MessageManager.getString("action.boxes"));
1140 showBoxes.setState(true);
1141 showBoxes.addActionListener(new ActionListener()
1144 public void actionPerformed(ActionEvent e)
1146 showBoxes_actionPerformed();
1149 showText.setText(MessageManager.getString("action.text"));
1150 showText.setState(true);
1151 showText.addActionListener(new ActionListener()
1154 public void actionPerformed(ActionEvent e)
1156 showText_actionPerformed();
1159 showColourText.setText(MessageManager.getString("label.colour_text"));
1160 showColourText.addActionListener(new ActionListener()
1163 public void actionPerformed(ActionEvent e)
1165 showColourText_actionPerformed();
1169 .setText(MessageManager.getString("label.show_non_conserved"));
1170 displayNonconserved.setState(true);
1171 displayNonconserved.addActionListener(new ActionListener()
1174 public void actionPerformed(ActionEvent e)
1176 showNonconserved_actionPerformed();
1179 editMenu.setText(MessageManager.getString("action.edit"));
1180 cut.setText(MessageManager.getString("action.cut"));
1181 cut.addActionListener(new ActionListener()
1184 public void actionPerformed(ActionEvent e)
1186 cut_actionPerformed();
1189 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1190 upperCase.addActionListener(new ActionListener()
1193 public void actionPerformed(ActionEvent e)
1198 copy.setText(MessageManager.getString("action.copy"));
1199 copy.addActionListener(new ActionListener()
1202 public void actionPerformed(ActionEvent e)
1204 copy_actionPerformed();
1207 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1208 lowerCase.addActionListener(new ActionListener()
1211 public void actionPerformed(ActionEvent e)
1216 toggle.setText(MessageManager.getString("label.toggle_case"));
1217 toggle.addActionListener(new ActionListener()
1220 public void actionPerformed(ActionEvent e)
1226 MessageManager.getString("label.out_to_textbox") + "...");
1227 seqShowAnnotationsMenu
1228 .setText(MessageManager.getString("label.show_annotations"));
1229 seqHideAnnotationsMenu
1230 .setText(MessageManager.getString("label.hide_annotations"));
1231 groupShowAnnotationsMenu
1232 .setText(MessageManager.getString("label.show_annotations"));
1233 groupHideAnnotationsMenu
1234 .setText(MessageManager.getString("label.hide_annotations"));
1235 sequenceFeature.setText(
1236 MessageManager.getString("label.create_sequence_feature"));
1237 sequenceFeature.addActionListener(new ActionListener()
1240 public void actionPerformed(ActionEvent e)
1242 sequenceFeature_actionPerformed();
1245 jMenu1.setText(MessageManager.getString("label.group"));
1246 pdbStructureDialog.setText(
1247 MessageManager.getString("label.show_pdbstruct_dialog"));
1248 pdbStructureDialog.addActionListener(new ActionListener()
1251 public void actionPerformed(ActionEvent actionEvent)
1253 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1254 if (ap.av.getSelectionGroup() != null)
1256 selectedSeqs = ap.av.getSequenceSelection();
1258 new StructureChooser(selectedSeqs, sequence, ap);
1263 .setText(MessageManager.getString("label.view_rna_structure"));
1265 // colStructureMenu.setText("Colour By Structure");
1266 editSequence.setText(
1267 MessageManager.getString("label.edit_sequence") + "...");
1268 editSequence.addActionListener(new ActionListener()
1271 public void actionPerformed(ActionEvent actionEvent)
1273 editSequence_actionPerformed(actionEvent);
1276 makeReferenceSeq.setText(
1277 MessageManager.getString("label.mark_as_representative"));
1278 makeReferenceSeq.addActionListener(new ActionListener()
1282 public void actionPerformed(ActionEvent actionEvent)
1284 makeReferenceSeq_actionPerformed(actionEvent);
1289 .setText(MessageManager.getString("label.hide_insertions"));
1290 hideInsertions.addActionListener(new ActionListener()
1294 public void actionPerformed(ActionEvent e)
1296 hideInsertions_actionPerformed(e);
1300 groupMenu.add(sequenceSelDetails);
1303 add(rnaStructureMenu);
1304 add(pdbStructureDialog);
1305 if (sequence != null)
1307 add(hideInsertions);
1309 // annotations configuration panel suppressed for now
1310 // groupMenu.add(chooseAnnotations);
1313 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1314 * (if a selection group is in force).
1316 sequenceMenu.add(seqShowAnnotationsMenu);
1317 sequenceMenu.add(seqHideAnnotationsMenu);
1318 sequenceMenu.add(seqAddReferenceAnnotations);
1319 groupMenu.add(groupShowAnnotationsMenu);
1320 groupMenu.add(groupHideAnnotationsMenu);
1321 groupMenu.add(groupAddReferenceAnnotations);
1322 groupMenu.add(editMenu);
1323 groupMenu.add(outputMenu);
1324 groupMenu.add(sequenceFeature);
1325 groupMenu.add(createGroupMenuItem);
1326 groupMenu.add(unGroupMenuItem);
1327 groupMenu.add(jMenu1);
1328 sequenceMenu.add(sequenceName);
1329 sequenceMenu.add(sequenceDetails);
1330 sequenceMenu.add(makeReferenceSeq);
1337 editMenu.add(editSequence);
1338 editMenu.add(upperCase);
1339 editMenu.add(lowerCase);
1340 editMenu.add(toggle);
1341 // JBPNote: These shouldn't be added here - should appear in a generic
1342 // 'apply web service to this sequence menu'
1343 // pdbMenu.add(RNAFold);
1344 // pdbMenu.add(ContraFold);
1345 jMenu1.add(groupName);
1346 jMenu1.add(colourMenu);
1347 jMenu1.add(showBoxes);
1348 jMenu1.add(showText);
1349 jMenu1.add(showColourText);
1350 jMenu1.add(outline);
1351 jMenu1.add(displayNonconserved);
1355 * Constructs the entries for the colour menu
1357 protected void initColourMenu()
1359 colourMenu.setText(MessageManager.getString("label.group_colour"));
1360 textColour.setText(MessageManager.getString("label.text_colour"));
1361 textColour.addActionListener(new ActionListener()
1364 public void actionPerformed(ActionEvent e)
1366 textColour_actionPerformed();
1370 abovePIDColour.setText(
1371 MessageManager.getString("label.above_identity_threshold"));
1372 abovePIDColour.addActionListener(new ActionListener()
1375 public void actionPerformed(ActionEvent e)
1377 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1382 MessageManager.getString("label.modify_identity_threshold"));
1383 modifyPID.addActionListener(new ActionListener()
1386 public void actionPerformed(ActionEvent e)
1388 modifyPID_actionPerformed();
1392 conservationMenuItem
1393 .setText(MessageManager.getString("action.by_conservation"));
1394 conservationMenuItem.addActionListener(new ActionListener()
1397 public void actionPerformed(ActionEvent e)
1399 conservationMenuItem_actionPerformed(
1400 conservationMenuItem.isSelected());
1404 modifyConservation.setText(MessageManager
1405 .getString("label.modify_conservation_threshold"));
1406 modifyConservation.addActionListener(new ActionListener()
1409 public void actionPerformed(ActionEvent e)
1411 modifyConservation_actionPerformed();
1417 * Builds the group colour sub-menu, including any user-defined colours which
1418 * were loaded at startup or during the Jalview session
1420 protected void buildColourMenu()
1422 SequenceGroup sg = ap.av.getSelectionGroup();
1426 * popup menu with no sequence group scope
1430 colourMenu.removeAll();
1431 colourMenu.add(textColour);
1432 colourMenu.addSeparator();
1434 ColourMenuHelper.addMenuItems(colourMenu, this, sg);
1436 colourMenu.addSeparator();
1437 colourMenu.add(conservationMenuItem);
1438 colourMenu.add(modifyConservation);
1439 colourMenu.add(abovePIDColour);
1440 colourMenu.add(modifyPID);
1443 protected void modifyConservation_actionPerformed()
1445 SequenceGroup sg = getGroup();
1448 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1449 SliderPanel.showConservationSlider();
1453 protected void modifyPID_actionPerformed()
1455 SequenceGroup sg = getGroup();
1458 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1460 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1461 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1462 SliderPanel.showPIDSlider();
1467 * Check for any annotations on the underlying dataset sequences (for the
1468 * current selection group) which are not 'on the alignment'.If any are found,
1469 * enable the option to add them to the alignment. The criteria for 'on the
1470 * alignment' is finding an alignment annotation on the alignment, matched on
1471 * calcId, label and sequenceRef.
1473 * A tooltip is also constructed that displays the source (calcId) and type
1474 * (label) of the annotations that can be added.
1477 * @param forSequences
1479 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1480 List<SequenceI> forSequences)
1482 menuItem.setEnabled(false);
1485 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1486 * Using TreeMap means calcIds are shown in alphabetical order.
1488 SortedMap<String, String> tipEntries = new TreeMap<>();
1489 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1490 AlignmentI al = this.ap.av.getAlignment();
1491 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1493 if (!candidates.isEmpty())
1495 StringBuilder tooltip = new StringBuilder(64);
1496 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1499 * Found annotations that could be added. Enable the menu item, and
1500 * configure its tooltip and action.
1502 menuItem.setEnabled(true);
1503 for (String calcId : tipEntries.keySet())
1505 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1507 String tooltipText = JvSwingUtils.wrapTooltip(true,
1508 tooltip.toString());
1509 menuItem.setToolTipText(tooltipText);
1511 menuItem.addActionListener(new ActionListener()
1514 public void actionPerformed(ActionEvent e)
1516 addReferenceAnnotations_actionPerformed(candidates);
1523 * Add annotations to the sequences and to the alignment.
1526 * a map whose keys are sequences on the alignment, and values a list
1527 * of annotations to add to each sequence
1529 protected void addReferenceAnnotations_actionPerformed(
1530 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1532 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1533 final AlignmentI alignment = this.ap.getAlignment();
1534 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1539 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1541 if (!ap.av.getAlignment().hasSeqrep())
1543 // initialise the display flags so the user sees something happen
1544 ap.av.setDisplayReferenceSeq(true);
1545 ap.av.setColourByReferenceSeq(true);
1546 ap.av.getAlignment().setSeqrep(sequence);
1550 if (ap.av.getAlignment().getSeqrep() == sequence)
1552 ap.av.getAlignment().setSeqrep(null);
1556 ap.av.getAlignment().setSeqrep(sequence);
1562 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1564 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1565 BitSet inserts = new BitSet();
1567 boolean markedPopup = false;
1568 // mark inserts in current selection
1569 if (ap.av.getSelectionGroup() != null)
1571 // mark just the columns in the selection group to be hidden
1572 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1573 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1575 // now clear columns without gaps
1576 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1582 inserts.and(sq.getInsertionsAsBits());
1584 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1585 ap.av.getSelectionGroup().getEndRes());
1588 // now mark for sequence under popup if we haven't already done it
1589 else if (!markedPopup && sequence != null)
1591 inserts.or(sequence.getInsertionsAsBits());
1593 // and set hidden columns accordingly
1594 hidden.hideColumns(inserts);
1599 protected void sequenceSelectionDetails_actionPerformed()
1601 createSequenceDetailsReport(ap.av.getSequenceSelection());
1604 protected void sequenceDetails_actionPerformed()
1606 createSequenceDetailsReport(new SequenceI[] { sequence });
1609 public void createSequenceDetailsReport(SequenceI[] sequences)
1611 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1612 StringBuilder contents = new StringBuilder(128);
1613 for (SequenceI seq : sequences)
1615 contents.append("<p><h2>" + MessageManager.formatMessage(
1616 "label.create_sequence_details_report_annotation_for",
1618 { seq.getDisplayId(true) }) + "</h2></p><p>");
1619 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
1620 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1621 contents.append("</p>");
1623 cap.setText("<html>" + contents.toString() + "</html>");
1625 Desktop.addInternalFrame(cap,
1626 MessageManager.formatMessage("label.sequence_details_for",
1627 (sequences.length == 1 ? new Object[]
1628 { sequences[0].getDisplayId(true) }
1631 .getString("label.selection") })),
1636 protected void showNonconserved_actionPerformed()
1638 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1643 * call to refresh view after settings change
1647 ap.updateAnnotation();
1648 // removed paintAlignment(true) here:
1649 // updateAnnotation calls paintAlignment already, so don't need to call
1652 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1656 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1657 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1667 public void abovePIDColour_actionPerformed(boolean selected)
1669 SequenceGroup sg = getGroup();
1677 sg.cs.setConsensus(AAFrequency.calculate(
1678 sg.getSequences(ap.av.getHiddenRepSequences()),
1679 sg.getStartRes(), sg.getEndRes() + 1));
1681 int threshold = SliderPanel.setPIDSliderSource(ap,
1682 sg.getGroupColourScheme(), getGroup().getName());
1684 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1686 SliderPanel.showPIDSlider();
1689 // remove PIDColouring
1691 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1692 SliderPanel.hidePIDSlider();
1694 modifyPID.setEnabled(selected);
1700 * Open a panel where the user can choose which types of sequence annotation
1705 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1707 // todo correct way to guard against opening a duplicate panel?
1708 new AnnotationChooser(ap);
1717 public void conservationMenuItem_actionPerformed(boolean selected)
1719 SequenceGroup sg = getGroup();
1727 // JBPNote: Conservation name shouldn't be i18n translated
1728 Conservation c = new Conservation("Group",
1729 sg.getSequences(ap.av.getHiddenRepSequences()),
1730 sg.getStartRes(), sg.getEndRes() + 1);
1733 c.verdict(false, ap.av.getConsPercGaps());
1734 sg.cs.setConservation(c);
1736 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1738 SliderPanel.showConservationSlider();
1741 // remove ConservationColouring
1743 sg.cs.setConservation(null);
1744 SliderPanel.hideConservationSlider();
1746 modifyConservation.setEnabled(selected);
1757 protected void groupName_actionPerformed()
1760 SequenceGroup sg = getGroup();
1761 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1762 sg.getDescription(),
1763 " " + MessageManager.getString("label.group_name") + " ",
1764 MessageManager.getString("label.group_description") + " ",
1765 MessageManager.getString("label.edit_group_name_description"),
1773 sg.setName(dialog.getName());
1774 sg.setDescription(dialog.getDescription());
1779 * Get selection group - adding it to the alignment if necessary.
1781 * @return sequence group to operate on
1783 SequenceGroup getGroup()
1785 SequenceGroup sg = ap.av.getSelectionGroup();
1786 // this method won't add a new group if it already exists
1789 ap.av.getAlignment().addGroup(sg);
1801 void sequenceName_actionPerformed()
1803 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1804 sequence.getDescription(),
1805 " " + MessageManager.getString("label.sequence_name")
1807 MessageManager.getString("label.sequence_description") + " ",
1808 MessageManager.getString(
1809 "label.edit_sequence_name_description"),
1817 if (dialog.getName() != null)
1819 if (dialog.getName().indexOf(" ") > -1)
1821 JvOptionPane.showMessageDialog(ap,
1823 .getString("label.spaces_converted_to_backslashes"),
1825 .getString("label.no_spaces_allowed_sequence_name"),
1826 JvOptionPane.WARNING_MESSAGE);
1829 sequence.setName(dialog.getName().replace(' ', '_'));
1830 ap.paintAlignment(false, false);
1833 sequence.setDescription(dialog.getDescription());
1835 ap.av.firePropertyChange("alignment", null,
1836 ap.av.getAlignment().getSequences());
1846 void unGroupMenuItem_actionPerformed()
1848 SequenceGroup sg = ap.av.getSelectionGroup();
1849 ap.av.getAlignment().deleteGroup(sg);
1850 ap.av.setSelectionGroup(null);
1854 void createGroupMenuItem_actionPerformed()
1856 getGroup(); // implicitly creates group - note - should apply defaults / use
1857 // standard alignment window logic for this
1867 protected void outline_actionPerformed()
1869 SequenceGroup sg = getGroup();
1870 Color col = JColorChooser.showDialog(this,
1871 MessageManager.getString("label.select_outline_colour"),
1876 sg.setOutlineColour(col);
1888 public void showBoxes_actionPerformed()
1890 getGroup().setDisplayBoxes(showBoxes.isSelected());
1900 public void showText_actionPerformed()
1902 getGroup().setDisplayText(showText.isSelected());
1912 public void showColourText_actionPerformed()
1914 getGroup().setColourText(showColourText.isSelected());
1918 public void showLink(String url)
1922 jalview.util.BrowserLauncher.openURL(url);
1923 } catch (Exception ex)
1925 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1926 MessageManager.getString("label.web_browser_not_found_unix"),
1927 MessageManager.getString("label.web_browser_not_found"),
1928 JvOptionPane.WARNING_MESSAGE);
1930 ex.printStackTrace();
1934 void hideSequences(boolean representGroup)
1936 ap.av.hideSequences(sequence, representGroup);
1939 public void copy_actionPerformed()
1941 ap.alignFrame.copy_actionPerformed(null);
1944 public void cut_actionPerformed()
1946 ap.alignFrame.cut_actionPerformed(null);
1949 void changeCase(ActionEvent e)
1951 Object source = e.getSource();
1952 SequenceGroup sg = ap.av.getSelectionGroup();
1956 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
1957 sg.getStartRes(), sg.getEndRes() + 1);
1962 if (source == toggle)
1964 description = MessageManager.getString("label.toggle_case");
1965 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1967 else if (source == upperCase)
1969 description = MessageManager.getString("label.to_upper_case");
1970 caseChange = ChangeCaseCommand.TO_UPPER;
1974 description = MessageManager.getString("label.to_lower_case");
1975 caseChange = ChangeCaseCommand.TO_LOWER;
1978 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1979 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
1980 startEnd, caseChange);
1982 ap.alignFrame.addHistoryItem(caseCommand);
1984 ap.av.firePropertyChange("alignment", null,
1985 ap.av.getAlignment().getSequences());
1990 public void outputText_actionPerformed(ActionEvent e)
1992 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1993 cap.setForInput(null);
1994 Desktop.addInternalFrame(cap, MessageManager
1995 .formatMessage("label.alignment_output_command", new Object[]
1996 { e.getActionCommand() }), 600, 500);
1998 String[] omitHidden = null;
2000 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2001 // or we simply trust the user wants
2002 // wysiwig behaviour
2004 FileFormatI fileFormat = FileFormats.getInstance()
2005 .forName(e.getActionCommand());
2007 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2010 public void sequenceFeature_actionPerformed()
2012 SequenceGroup sg = ap.av.getSelectionGroup();
2018 List<SequenceI> seqs = new ArrayList<>();
2019 List<SequenceFeature> features = new ArrayList<>();
2022 * assemble dataset sequences, and template new sequence features,
2023 * for the amend features dialog
2025 int gSize = sg.getSize();
2026 for (int i = 0; i < gSize; i++)
2028 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2029 int end = sg.findEndRes(sg.getSequenceAt(i));
2032 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2033 features.add(new SequenceFeature(null, null, start, end, null));
2038 * an entirely gapped region will generate empty lists of sequence / features
2040 if (!seqs.isEmpty())
2042 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer()
2043 .amendFeatures(seqs, features, true, ap))
2045 ap.alignFrame.setShowSeqFeatures(true);
2046 ap.av.setSearchResults(null); // clear highlighting
2047 ap.repaint(); // draw new/amended features
2052 public void textColour_actionPerformed()
2054 SequenceGroup sg = getGroup();
2057 new TextColourChooser().chooseColour(ap, sg);
2061 public void colourByStructure(String pdbid)
2063 Annotation[] anots = ap.av.getStructureSelectionManager()
2064 .colourSequenceFromStructure(sequence, pdbid);
2066 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2067 "Coloured by " + pdbid, anots);
2069 ap.av.getAlignment().addAnnotation(an);
2070 an.createSequenceMapping(sequence, 0, true);
2071 // an.adjustForAlignment();
2072 ap.av.getAlignment().setAnnotationIndex(an, 0);
2074 ap.adjustAnnotationHeight();
2076 sequence.addAlignmentAnnotation(an);
2080 public void editSequence_actionPerformed(ActionEvent actionEvent)
2082 SequenceGroup sg = ap.av.getSelectionGroup();
2086 if (sequence == null)
2088 sequence = sg.getSequenceAt(0);
2091 EditNameDialog dialog = new EditNameDialog(
2092 sequence.getSequenceAsString(sg.getStartRes(),
2093 sg.getEndRes() + 1),
2094 null, MessageManager.getString("label.edit_sequence"), null,
2095 MessageManager.getString("label.edit_sequence"),
2100 EditCommand editCommand = new EditCommand(
2101 MessageManager.getString("label.edit_sequences"),
2103 dialog.getName().replace(' ', ap.av.getGapCharacter()),
2104 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2105 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2107 ap.alignFrame.addHistoryItem(editCommand);
2109 ap.av.firePropertyChange("alignment", null,
2110 ap.av.getAlignment().getSequences());
2116 * Action on user selecting an item from the colour menu (that does not have
2117 * its bespoke action handler)
2122 public void changeColour_actionPerformed(String colourSchemeName)
2124 SequenceGroup sg = getGroup();
2126 * switch to the chosen colour scheme (or null for None)
2128 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2129 .getColourScheme(colourSchemeName, sg,
2130 ap.av.getHiddenRepSequences());
2131 sg.setColourScheme(colourScheme);
2132 if (colourScheme instanceof Blosum62ColourScheme
2133 || colourScheme instanceof PIDColourScheme)
2135 sg.cs.setConsensus(AAFrequency.calculate(
2136 sg.getSequences(ap.av.getHiddenRepSequences()),
2137 sg.getStartRes(), sg.getEndRes() + 1));