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.gui.JalviewColourChooser.ColourChooserListener;
42 import jalview.io.FileFormatI;
43 import jalview.io.FileFormats;
44 import jalview.io.FormatAdapter;
45 import jalview.io.SequenceAnnotationReport;
46 import jalview.schemes.Blosum62ColourScheme;
47 import jalview.schemes.ColourSchemeI;
48 import jalview.schemes.ColourSchemes;
49 import jalview.schemes.PIDColourScheme;
50 import jalview.schemes.ResidueColourScheme;
51 import jalview.util.GroupUrlLink;
52 import jalview.util.GroupUrlLink.UrlStringTooLongException;
53 import jalview.util.MessageManager;
54 import jalview.util.Platform;
55 import jalview.util.StringUtils;
56 import jalview.util.UrlLink;
58 import java.awt.BorderLayout;
59 import java.awt.Color;
60 import java.awt.event.ActionEvent;
61 import java.awt.event.ActionListener;
62 import java.util.ArrayList;
63 import java.util.Arrays;
64 import java.util.BitSet;
65 import java.util.Collection;
66 import java.util.Collections;
67 import java.util.Hashtable;
68 import java.util.LinkedHashMap;
69 import java.util.List;
71 import java.util.SortedMap;
72 import java.util.TreeMap;
73 import java.util.Vector;
75 import javax.swing.ButtonGroup;
76 import javax.swing.JCheckBoxMenuItem;
77 import javax.swing.JInternalFrame;
78 import javax.swing.JLabel;
79 import javax.swing.JMenu;
80 import javax.swing.JMenuItem;
81 import javax.swing.JPanel;
82 import javax.swing.JPopupMenu;
83 import javax.swing.JRadioButtonMenuItem;
84 import javax.swing.JScrollPane;
90 * @version $Revision: 1.118 $
92 public class PopupMenu extends JPopupMenu implements ColourChangeListener
94 JMenu groupMenu = new JMenu();
96 JMenuItem groupName = new JMenuItem();
98 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
100 protected JMenuItem modifyPID = new JMenuItem();
102 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
104 protected JRadioButtonMenuItem annotationColour;
106 protected JMenuItem modifyConservation = new JMenuItem();
110 JMenu sequenceMenu = new JMenu();
112 JMenuItem sequenceName = new JMenuItem();
114 JMenuItem sequenceDetails = new JMenuItem();
116 JMenuItem sequenceSelDetails = new JMenuItem();
118 JMenuItem makeReferenceSeq = new JMenuItem();
120 JMenuItem chooseAnnotations = new JMenuItem();
124 JMenuItem createGroupMenuItem = new JMenuItem();
126 JMenuItem unGroupMenuItem = new JMenuItem();
128 JMenuItem outline = new JMenuItem();
130 JMenu colourMenu = new JMenu();
132 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
134 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
136 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
138 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
140 JMenu editMenu = new JMenu();
142 JMenuItem cut = new JMenuItem();
144 JMenuItem copy = new JMenuItem();
146 JMenuItem upperCase = new JMenuItem();
148 JMenuItem lowerCase = new JMenuItem();
150 JMenuItem toggle = new JMenuItem();
152 JMenu pdbMenu = new JMenu();
154 JMenu outputMenu = new JMenu();
156 JMenu seqShowAnnotationsMenu = new JMenu();
158 JMenu seqHideAnnotationsMenu = new JMenu();
160 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
161 MessageManager.getString("label.add_reference_annotations"));
163 JMenu groupShowAnnotationsMenu = new JMenu();
165 JMenu groupHideAnnotationsMenu = new JMenu();
167 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
168 MessageManager.getString("label.add_reference_annotations"));
170 JMenuItem sequenceFeature = new JMenuItem();
172 JMenuItem textColour = new JMenuItem();
174 JMenu jMenu1 = new JMenu();
176 JMenuItem pdbStructureDialog = new JMenuItem();
178 JMenu rnaStructureMenu = new JMenu();
180 JMenuItem editSequence = new JMenuItem();
182 JMenu groupLinksMenu;
184 JMenuItem hideInsertions = new JMenuItem();
187 * Creates a new PopupMenu object.
192 * non-positional features (for seq not null), or positional features
193 * at residue (for seq equal to null)
195 public PopupMenu(final AlignmentPanel ap, SequenceI seq,
196 List<SequenceFeature> features)
198 this(ap, seq, features, null);
206 * the sequence under the cursor if in the Id panel, null if in the
209 * non-positional features if in the Id panel, features at the
210 * clicked residue if in the sequence panel
213 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
214 List<SequenceFeature> features, List<String> groupLinks)
216 // /////////////////////////////////////////////////////////
217 // If this is activated from the sequence panel, the user may want to
218 // edit or annotate a particular residue. Therefore display the residue menu
220 // If from the IDPanel, we must display the sequence menu
221 // ////////////////////////////////////////////////////////
222 this.ap = alignPanel;
225 for (String ff : FileFormats.getInstance().getWritableFormats(true))
227 JMenuItem item = new JMenuItem(ff);
229 item.addActionListener(new ActionListener()
232 public void actionPerformed(ActionEvent e)
234 outputText_actionPerformed(e);
238 outputMenu.add(item);
242 * Build menus for annotation types that may be shown or hidden, and for
243 * 'reference annotations' that may be added to the alignment. First for the
244 * currently selected sequence (if there is one):
246 final List<SequenceI> selectedSequence = (seq == null
247 ? Collections.<SequenceI> emptyList()
248 : Arrays.asList(seq));
249 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
250 seqHideAnnotationsMenu, selectedSequence);
251 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
255 * And repeat for the current selection group (if there is one):
257 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
258 ? Collections.<SequenceI> emptyList()
259 : alignPanel.av.getSelectionGroup().getSequences());
260 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
261 groupHideAnnotationsMenu, selectedGroup);
262 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
268 } catch (Exception e)
276 sequenceMenu.setText(sequence.getName());
277 if (seq == alignPanel.av.getAlignment().getSeqrep())
279 makeReferenceSeq.setText(
280 MessageManager.getString("action.unmark_as_reference"));
284 makeReferenceSeq.setText(
285 MessageManager.getString("action.set_as_reference"));
288 if (!alignPanel.av.getAlignment().isNucleotide())
290 remove(rnaStructureMenu);
294 int origCount = rnaStructureMenu.getItemCount();
296 * add menu items to 2D-render any alignment or sequence secondary
297 * structure annotation
299 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
300 .getAlignmentAnnotation();
303 for (final AlignmentAnnotation aa : aas)
305 if (aa.isValidStruc() && aa.sequenceRef == null)
308 * valid alignment RNA secondary structure annotation
310 menuItem = new JMenuItem();
311 menuItem.setText(MessageManager.formatMessage(
312 "label.2d_rna_structure_line", new Object[]
314 menuItem.addActionListener(new ActionListener()
317 public void actionPerformed(ActionEvent e)
319 new AppVarna(seq, aa, alignPanel);
322 rnaStructureMenu.add(menuItem);
327 if (seq.getAnnotation() != null)
329 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
330 for (final AlignmentAnnotation aa : seqAnns)
332 if (aa.isValidStruc())
335 * valid sequence RNA secondary structure annotation
337 // TODO: make rnastrucF a bit more nice
338 menuItem = new JMenuItem();
339 menuItem.setText(MessageManager.formatMessage(
340 "label.2d_rna_sequence_name", new Object[]
342 menuItem.addActionListener(new ActionListener()
345 public void actionPerformed(ActionEvent e)
347 // TODO: VARNA does'nt print gaps in the sequence
348 new AppVarna(seq, aa, alignPanel);
351 rnaStructureMenu.add(menuItem);
355 if (rnaStructureMenu.getItemCount() == origCount)
357 remove(rnaStructureMenu);
361 menuItem = new JMenuItem(
362 MessageManager.getString("action.hide_sequences"));
363 menuItem.addActionListener(new ActionListener()
366 public void actionPerformed(ActionEvent e)
368 hideSequences(false);
373 if (alignPanel.av.getSelectionGroup() != null
374 && alignPanel.av.getSelectionGroup().getSize() > 1)
376 menuItem = new JMenuItem(MessageManager
377 .formatMessage("label.represent_group_with", new Object[]
379 menuItem.addActionListener(new ActionListener()
382 public void actionPerformed(ActionEvent e)
387 sequenceMenu.add(menuItem);
390 if (alignPanel.av.hasHiddenRows())
392 final int index = alignPanel.av.getAlignment().findIndex(seq);
394 if (alignPanel.av.adjustForHiddenSeqs(index)
395 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
397 menuItem = new JMenuItem(
398 MessageManager.getString("action.reveal_sequences"));
399 menuItem.addActionListener(new ActionListener()
402 public void actionPerformed(ActionEvent e)
404 alignPanel.av.showSequence(index);
405 if (alignPanel.overviewPanel != null)
407 alignPanel.overviewPanel.updateOverviewImage();
418 * - in the IdPanel (seq not null) if any sequence is hidden
419 * - in the IdPanel or SeqPanel if all sequences are hidden (seq is null)
421 if (alignPanel.av.hasHiddenRows())
423 boolean addOption = seq != null;
424 if (!addOption && alignPanel.av.getAlignment().getHeight() == 0)
430 menuItem = new JMenuItem(
431 MessageManager.getString("action.reveal_all"));
432 menuItem.addActionListener(new ActionListener()
435 public void actionPerformed(ActionEvent e)
437 alignPanel.av.showAllHiddenSeqs();
438 if (alignPanel.overviewPanel != null)
440 alignPanel.overviewPanel.updateOverviewImage();
448 SequenceGroup sg = alignPanel.av.getSelectionGroup();
449 boolean isDefinedGroup = (sg != null)
450 ? alignPanel.av.getAlignment().getGroups().contains(sg)
453 if (sg != null && sg.getSize() > 0)
455 groupName.setText(MessageManager
456 .getString("label.edit_name_and_description_current_group"));
458 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
460 conservationMenuItem.setEnabled(!sg.isNucleotide());
464 if (sg.cs.conservationApplied())
466 conservationMenuItem.setSelected(true);
468 if (sg.cs.getThreshold() > 0)
470 abovePIDColour.setSelected(true);
473 modifyConservation.setEnabled(conservationMenuItem.isSelected());
474 modifyPID.setEnabled(abovePIDColour.isSelected());
475 displayNonconserved.setSelected(sg.getShowNonconserved());
476 showText.setSelected(sg.getDisplayText());
477 showColourText.setSelected(sg.getColourText());
478 showBoxes.setSelected(sg.getDisplayBoxes());
479 // add any groupURLs to the groupURL submenu and make it visible
480 if (groupLinks != null && groupLinks.size() > 0)
482 buildGroupURLMenu(sg, groupLinks);
484 // Add a 'show all structures' for the current selection
485 Hashtable<String, PDBEntry> pdbe = new Hashtable<>(), reppdb = new Hashtable<>();
487 SequenceI sqass = null;
488 for (SequenceI sq : alignPanel.av.getSequenceSelection())
490 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
491 if (pes != null && pes.size() > 0)
493 reppdb.put(pes.get(0).getId(), pes.get(0));
494 for (PDBEntry pe : pes)
496 pdbe.put(pe.getId(), pe);
506 final PDBEntry[] pe = pdbe.values()
507 .toArray(new PDBEntry[pdbe.size()]),
508 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
509 final JMenuItem gpdbview, rpdbview;
514 groupMenu.setVisible(false);
515 editMenu.setVisible(false);
520 createGroupMenuItem.setVisible(true);
521 unGroupMenuItem.setVisible(false);
522 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
526 createGroupMenuItem.setVisible(false);
527 unGroupMenuItem.setVisible(true);
528 jMenu1.setText(MessageManager.getString("action.edit_group"));
533 sequenceMenu.setVisible(false);
534 pdbStructureDialog.setVisible(false);
535 rnaStructureMenu.setVisible(false);
538 addLinks(seq, features);
542 addFeatureDetails(features);
547 * Add a link to show feature details for each sequence feature
551 protected void addFeatureDetails(List<SequenceFeature> features)
553 if (features == null || features.isEmpty())
557 JMenu details = new JMenu(
558 MessageManager.getString("label.feature_details"));
561 for (final SequenceFeature sf : features)
563 int start = sf.getBegin();
564 int end = sf.getEnd();
568 desc = String.format("%s %d", sf.getType(), start);
572 desc = String.format("%s %d-%d", sf.getType(), start, end);
574 String tooltip = desc;
575 String description = sf.getDescription();
576 if (description != null)
578 description = StringUtils.stripHtmlTags(description);
579 if (description.length() > 12)
581 desc = desc + " " + description.substring(0, 12) + "..";
585 desc = desc + " " + description;
587 tooltip = tooltip + " " + description;
589 if (sf.getFeatureGroup() != null)
591 tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
593 JMenuItem item = new JMenuItem(desc);
594 item.setToolTipText(tooltip);
595 item.addActionListener(new ActionListener()
598 public void actionPerformed(ActionEvent e)
600 showFeatureDetails(sf);
608 * Opens a panel showing a text report of feature dteails
612 protected void showFeatureDetails(SequenceFeature sf)
614 JInternalFrame details;
615 if (/** @j2sNative true || */ false)
617 details = new JInternalFrame();
618 JPanel panel = new JPanel(new BorderLayout());
619 panel.setOpaque(true);
620 panel.setBackground(Color.white);
621 // TODO JAL-3026 set style of table correctly for feature details
622 JLabel reprt = new JLabel(MessageManager.formatMessage("label.html_content",
624 { sf.getDetailsReport()}));
625 reprt.setBackground(Color.WHITE);
626 reprt.setOpaque(true);
627 panel.add(reprt,BorderLayout.CENTER);
628 details.setContentPane(panel);
633 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
634 // it appears Java's CSS does not support border-collaps :-(
635 cap.addStylesheetRule("table { border-collapse: collapse;}");
636 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
637 cap.setText(sf.getDetailsReport());
640 Desktop.addInternalFrame(details,
641 MessageManager.getString("label.feature_details"), 500, 500);
645 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
646 * When seq is not null, these are links for the sequence id, which may be to
647 * external web sites for the sequence accession, and/or links embedded in
648 * non-positional features. When seq is null, only links embedded in the
649 * provided features are added.
654 void addLinks(final SequenceI seq, List<SequenceFeature> features)
656 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
658 List<String> nlinks = null;
661 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
665 nlinks = new ArrayList<>();
668 if (features != null)
670 for (SequenceFeature sf : features)
672 if (sf.links != null)
674 for (String link : sf.links)
682 Map<String, List<String>> linkset = new LinkedHashMap<>();
684 for (String link : nlinks)
686 UrlLink urlLink = null;
689 urlLink = new UrlLink(link);
690 } catch (Exception foo)
692 Cache.log.error("Exception for URLLink '" + link + "'", foo);
696 if (!urlLink.isValid())
698 Cache.log.error(urlLink.getInvalidMessage());
702 urlLink.createLinksFromSeq(seq, linkset);
705 addshowLinks(linkMenu, linkset.values());
707 // only add link menu if it has entries
708 if (linkMenu.getItemCount() > 0)
710 if (sequence != null)
712 sequenceMenu.add(linkMenu);
722 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
723 * "All" is added first, followed by a separator. Then add any annotation
724 * types associated with the current selection. Separate menus are built for
725 * the selected sequence group (if any), and the selected sequence.
727 * Some annotation rows are always rendered together - these can be identified
728 * by a common graphGroup property > -1. Only one of each group will be marked
729 * as visible (to avoid duplication of the display). For such groups we add a
730 * composite type name, e.g.
732 * IUPredWS (Long), IUPredWS (Short)
736 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
737 List<SequenceI> forSequences)
739 showMenu.removeAll();
740 hideMenu.removeAll();
742 final List<String> all = Arrays
744 { MessageManager.getString("label.all") });
745 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
747 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
749 showMenu.addSeparator();
750 hideMenu.addSeparator();
752 final AlignmentAnnotation[] annotations = ap.getAlignment()
753 .getAlignmentAnnotation();
756 * Find shown/hidden annotations types, distinguished by source (calcId),
757 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
758 * the insertion order, which is the order of the annotations on the
761 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
762 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
763 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
764 AlignmentAnnotationUtils.asList(annotations), forSequences);
766 for (String calcId : hiddenTypes.keySet())
768 for (List<String> type : hiddenTypes.get(calcId))
770 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
774 // grey out 'show annotations' if none are hidden
775 showMenu.setEnabled(!hiddenTypes.isEmpty());
777 for (String calcId : shownTypes.keySet())
779 for (List<String> type : shownTypes.get(calcId))
781 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
785 // grey out 'hide annotations' if none are shown
786 hideMenu.setEnabled(!shownTypes.isEmpty());
790 * Returns a list of sequences - either the current selection group (if there
791 * is one), else the specified single sequence.
796 protected List<SequenceI> getSequenceScope(SequenceI seq)
798 List<SequenceI> forSequences = null;
799 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
800 if (selectionGroup != null && selectionGroup.getSize() > 0)
802 forSequences = selectionGroup.getSequences();
806 forSequences = seq == null ? Collections.<SequenceI> emptyList()
807 : Arrays.asList(seq);
813 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
816 * @param showOrHideMenu
818 * @param forSequences
819 * the sequences whose annotations may be shown or hidden
824 * if true this is a special label meaning 'All'
825 * @param actionIsShow
826 * if true, the select menu item action is to show the annotation
829 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
830 final List<SequenceI> forSequences, String calcId,
831 final List<String> types, final boolean allTypes,
832 final boolean actionIsShow)
834 String label = types.toString(); // [a, b, c]
835 label = label.substring(1, label.length() - 1); // a, b, c
836 final JMenuItem item = new JMenuItem(label);
837 item.setToolTipText(calcId);
838 item.addActionListener(new ActionListener()
841 public void actionPerformed(ActionEvent e)
843 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
844 types, forSequences, allTypes, actionIsShow);
848 showOrHideMenu.add(item);
851 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
854 // TODO: usability: thread off the generation of group url content so root
856 // sequence only URLs
857 // ID/regex match URLs
858 groupLinksMenu = new JMenu(
859 MessageManager.getString("action.group_link"));
860 // three types of url that might be created.
861 JMenu[] linkMenus = new JMenu[] { null,
862 new JMenu(MessageManager.getString("action.ids")),
863 new JMenu(MessageManager.getString("action.sequences")),
864 new JMenu(MessageManager.getString("action.ids_sequences")) };
866 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
867 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
868 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
869 for (int sq = 0; sq < seqs.length; sq++)
872 int start = seqs[sq].findPosition(sg.getStartRes()),
873 end = seqs[sq].findPosition(sg.getEndRes());
874 // just collect ids from dataset sequence
875 // TODO: check if IDs collected from selecton group intersects with the
876 // current selection, too
877 SequenceI sqi = seqs[sq];
878 while (sqi.getDatasetSequence() != null)
880 sqi = sqi.getDatasetSequence();
882 List<DBRefEntry> dbr = sqi.getDBRefs();
884 if (dbr != null && (nd = dbr.size()) > 0)
886 for (int d = 0; d < nd; d++)
888 DBRefEntry e = dbr.get(d);
889 String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
890 Object[] sarray = commonDbrefs.get(src);
893 sarray = new Object[2];
894 sarray[0] = new int[] { 0 };
895 sarray[1] = new String[seqs.length];
897 commonDbrefs.put(src, sarray);
900 if (((String[]) sarray[1])[sq] == null)
902 if (!e.hasMap() || (e.getMap()
903 .locateMappedRange(start, end) != null))
905 ((String[]) sarray[1])[sq] = e.getAccessionId();
906 ((int[]) sarray[0])[0]++;
912 // now create group links for all distinct ID/sequence sets.
913 boolean addMenu = false; // indicates if there are any group links to give
915 for (String link : groupLinks)
917 GroupUrlLink urlLink = null;
920 urlLink = new GroupUrlLink(link);
921 } catch (Exception foo)
923 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
927 if (!urlLink.isValid())
929 Cache.log.error(urlLink.getInvalidMessage());
932 final String label = urlLink.getLabel();
933 boolean usingNames = false;
934 // Now see which parts of the group apply for this URL
935 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
936 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
937 String[] seqstr, ids; // input to makeUrl
940 int numinput = ((int[]) idset[0])[0];
941 String[] allids = ((String[]) idset[1]);
942 seqstr = new String[numinput];
943 ids = new String[numinput];
944 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
946 if (allids[sq] != null)
948 ids[idcount] = allids[sq];
949 seqstr[idcount++] = idandseqs[1][sq];
955 // just use the id/seq set
956 seqstr = idandseqs[1];
960 // and try and make the groupURL!
962 Object[] urlset = null;
965 urlset = urlLink.makeUrlStubs(ids, seqstr,
966 "FromJalview" + System.currentTimeMillis(), false);
967 } catch (UrlStringTooLongException e)
972 int type = urlLink.getGroupURLType() & 3;
973 // first two bits ofurlLink type bitfield are sequenceids and sequences
974 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
975 addshowLink(linkMenus[type],
976 label + (((type & 1) == 1)
977 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
985 groupLinksMenu = new JMenu(
986 MessageManager.getString("action.group_link"));
987 for (int m = 0; m < linkMenus.length; m++)
989 if (linkMenus[m] != null
990 && linkMenus[m].getMenuComponentCount() > 0)
992 groupLinksMenu.add(linkMenus[m]);
996 groupMenu.add(groupLinksMenu);
1000 private void addshowLinks(JMenu linkMenu,
1001 Collection<List<String>> linkset)
1003 for (List<String> linkstrset : linkset)
1005 // split linkstr into label and url
1006 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
1011 * add a show URL menu item to the given linkMenu
1015 * - menu label string
1019 private void addshowLink(JMenu linkMenu, String label, final String url)
1021 JMenuItem item = new JMenuItem(label);
1022 item.setToolTipText(MessageManager.formatMessage("label.open_url_param",
1025 item.addActionListener(new ActionListener()
1028 public void actionPerformed(ActionEvent e)
1030 new Thread(new Runnable()
1047 * add a late bound groupURL item to the given linkMenu
1051 * - menu label string
1052 * @param urlgenerator
1053 * GroupURLLink used to generate URL
1055 * Object array returned from the makeUrlStubs function.
1057 private void addshowLink(JMenu linkMenu, String label,
1058 final GroupUrlLink urlgenerator, final Object[] urlstub)
1060 JMenuItem item = new JMenuItem(label);
1061 item.setToolTipText(MessageManager
1062 .formatMessage("label.open_url_seqs_param", new Object[]
1063 { urlgenerator.getUrl_prefix(),
1064 urlgenerator.getNumberInvolved(urlstub) }));
1065 // TODO: put in info about what is being sent.
1066 item.addActionListener(new ActionListener()
1069 public void actionPerformed(ActionEvent e)
1071 new Thread(new Runnable()
1079 showLink(urlgenerator.constructFrom(urlstub));
1080 } catch (UrlStringTooLongException e2)
1098 private void jbInit() throws Exception
1100 groupMenu.setText(MessageManager.getString("label.selection"));
1101 groupName.setText(MessageManager.getString("label.name"));
1102 groupName.addActionListener(new ActionListener()
1105 public void actionPerformed(ActionEvent e)
1107 groupName_actionPerformed();
1110 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1111 sequenceName.setText(
1112 MessageManager.getString("label.edit_name_description"));
1113 sequenceName.addActionListener(new ActionListener()
1116 public void actionPerformed(ActionEvent e)
1118 sequenceName_actionPerformed();
1122 .setText(MessageManager.getString("action.choose_annotations"));
1123 chooseAnnotations.addActionListener(new ActionListener()
1126 public void actionPerformed(ActionEvent e)
1128 chooseAnnotations_actionPerformed(e);
1132 .setText(MessageManager.getString("label.sequence_details"));
1133 sequenceDetails.addActionListener(new ActionListener()
1136 public void actionPerformed(ActionEvent e)
1138 sequenceDetails_actionPerformed();
1142 .setText(MessageManager.getString("label.sequence_details"));
1143 sequenceSelDetails.addActionListener(new ActionListener()
1146 public void actionPerformed(ActionEvent e)
1148 sequenceSelectionDetails_actionPerformed();
1153 .setText(MessageManager.getString("action.remove_group"));
1154 unGroupMenuItem.addActionListener(new ActionListener()
1157 public void actionPerformed(ActionEvent e)
1159 unGroupMenuItem_actionPerformed();
1163 .setText(MessageManager.getString("action.create_group"));
1164 createGroupMenuItem.addActionListener(new ActionListener()
1167 public void actionPerformed(ActionEvent e)
1169 createGroupMenuItem_actionPerformed();
1173 outline.setText(MessageManager.getString("action.border_colour"));
1174 outline.addActionListener(new ActionListener()
1177 public void actionPerformed(ActionEvent e)
1179 outline_actionPerformed();
1182 showBoxes.setText(MessageManager.getString("action.boxes"));
1183 showBoxes.setState(true);
1184 showBoxes.addActionListener(new ActionListener()
1187 public void actionPerformed(ActionEvent e)
1189 showBoxes_actionPerformed();
1192 showText.setText(MessageManager.getString("action.text"));
1193 showText.setState(true);
1194 showText.addActionListener(new ActionListener()
1197 public void actionPerformed(ActionEvent e)
1199 showText_actionPerformed();
1202 showColourText.setText(MessageManager.getString("label.colour_text"));
1203 showColourText.addActionListener(new ActionListener()
1206 public void actionPerformed(ActionEvent e)
1208 showColourText_actionPerformed();
1212 .setText(MessageManager.getString("label.show_non_conserved"));
1213 displayNonconserved.setState(true);
1214 displayNonconserved.addActionListener(new ActionListener()
1217 public void actionPerformed(ActionEvent e)
1219 showNonconserved_actionPerformed();
1222 editMenu.setText(MessageManager.getString("action.edit"));
1223 cut.setText(MessageManager.getString("action.cut"));
1224 cut.addActionListener(new ActionListener()
1227 public void actionPerformed(ActionEvent e)
1229 cut_actionPerformed();
1232 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1233 upperCase.addActionListener(new ActionListener()
1236 public void actionPerformed(ActionEvent e)
1241 copy.setText(MessageManager.getString("action.copy"));
1242 copy.addActionListener(new ActionListener()
1245 public void actionPerformed(ActionEvent e)
1247 copy_actionPerformed();
1250 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1251 lowerCase.addActionListener(new ActionListener()
1254 public void actionPerformed(ActionEvent e)
1259 toggle.setText(MessageManager.getString("label.toggle_case"));
1260 toggle.addActionListener(new ActionListener()
1263 public void actionPerformed(ActionEvent e)
1269 MessageManager.getString("label.out_to_textbox") + "...");
1270 seqShowAnnotationsMenu
1271 .setText(MessageManager.getString("label.show_annotations"));
1272 seqHideAnnotationsMenu
1273 .setText(MessageManager.getString("label.hide_annotations"));
1274 groupShowAnnotationsMenu
1275 .setText(MessageManager.getString("label.show_annotations"));
1276 groupHideAnnotationsMenu
1277 .setText(MessageManager.getString("label.hide_annotations"));
1278 sequenceFeature.setText(
1279 MessageManager.getString("label.create_sequence_feature"));
1280 sequenceFeature.addActionListener(new ActionListener()
1283 public void actionPerformed(ActionEvent e)
1285 sequenceFeature_actionPerformed();
1288 jMenu1.setText(MessageManager.getString("label.group"));
1289 pdbStructureDialog.setText(
1290 MessageManager.getString("label.show_pdbstruct_dialog"));
1291 pdbStructureDialog.addActionListener(new ActionListener()
1294 public void actionPerformed(ActionEvent actionEvent)
1296 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1297 if (ap.av.getSelectionGroup() != null)
1299 selectedSeqs = ap.av.getSequenceSelection();
1301 new StructureChooser(selectedSeqs, sequence, ap);
1306 .setText(MessageManager.getString("label.view_rna_structure"));
1308 // colStructureMenu.setText("Colour By Structure");
1309 editSequence.setText(
1310 MessageManager.getString("label.edit_sequence") + "...");
1311 editSequence.addActionListener(new ActionListener()
1314 public void actionPerformed(ActionEvent actionEvent)
1316 editSequence_actionPerformed();
1319 makeReferenceSeq.setText(
1320 MessageManager.getString("label.mark_as_representative"));
1321 makeReferenceSeq.addActionListener(new ActionListener()
1325 public void actionPerformed(ActionEvent actionEvent)
1327 makeReferenceSeq_actionPerformed(actionEvent);
1332 .setText(MessageManager.getString("label.hide_insertions"));
1333 hideInsertions.addActionListener(new ActionListener()
1337 public void actionPerformed(ActionEvent e)
1339 hideInsertions_actionPerformed(e);
1343 groupMenu.add(sequenceSelDetails);
1346 add(rnaStructureMenu);
1347 add(pdbStructureDialog);
1348 if (sequence != null)
1350 add(hideInsertions);
1352 // annotations configuration panel suppressed for now
1353 // groupMenu.add(chooseAnnotations);
1356 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1357 * (if a selection group is in force).
1359 sequenceMenu.add(seqShowAnnotationsMenu);
1360 sequenceMenu.add(seqHideAnnotationsMenu);
1361 sequenceMenu.add(seqAddReferenceAnnotations);
1362 groupMenu.add(groupShowAnnotationsMenu);
1363 groupMenu.add(groupHideAnnotationsMenu);
1364 groupMenu.add(groupAddReferenceAnnotations);
1365 groupMenu.add(editMenu);
1366 groupMenu.add(outputMenu);
1367 groupMenu.add(sequenceFeature);
1368 groupMenu.add(createGroupMenuItem);
1369 groupMenu.add(unGroupMenuItem);
1370 groupMenu.add(jMenu1);
1371 sequenceMenu.add(sequenceName);
1372 sequenceMenu.add(sequenceDetails);
1373 sequenceMenu.add(makeReferenceSeq);
1380 editMenu.add(editSequence);
1381 editMenu.add(upperCase);
1382 editMenu.add(lowerCase);
1383 editMenu.add(toggle);
1384 // JBPNote: These shouldn't be added here - should appear in a generic
1385 // 'apply web service to this sequence menu'
1386 // pdbMenu.add(RNAFold);
1387 // pdbMenu.add(ContraFold);
1388 jMenu1.add(groupName);
1389 jMenu1.add(colourMenu);
1390 jMenu1.add(showBoxes);
1391 jMenu1.add(showText);
1392 jMenu1.add(showColourText);
1393 jMenu1.add(outline);
1394 jMenu1.add(displayNonconserved);
1398 * Constructs the entries for the colour menu
1400 protected void initColourMenu()
1402 colourMenu.setText(MessageManager.getString("label.group_colour"));
1403 textColour.setText(MessageManager.getString("label.text_colour"));
1404 textColour.addActionListener(new ActionListener()
1407 public void actionPerformed(ActionEvent e)
1409 textColour_actionPerformed();
1413 abovePIDColour.setText(
1414 MessageManager.getString("label.above_identity_threshold"));
1415 abovePIDColour.addActionListener(new ActionListener()
1418 public void actionPerformed(ActionEvent e)
1420 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1425 MessageManager.getString("label.modify_identity_threshold"));
1426 modifyPID.addActionListener(new ActionListener()
1429 public void actionPerformed(ActionEvent e)
1431 modifyPID_actionPerformed();
1435 conservationMenuItem
1436 .setText(MessageManager.getString("action.by_conservation"));
1437 conservationMenuItem.addActionListener(new ActionListener()
1440 public void actionPerformed(ActionEvent e)
1442 conservationMenuItem_actionPerformed(
1443 conservationMenuItem.isSelected());
1447 annotationColour = new JRadioButtonMenuItem(
1448 MessageManager.getString("action.by_annotation"));
1449 annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
1450 annotationColour.setEnabled(false);
1451 annotationColour.setToolTipText(
1452 MessageManager.getString("label.by_annotation_tooltip"));
1454 modifyConservation.setText(MessageManager
1455 .getString("label.modify_conservation_threshold"));
1456 modifyConservation.addActionListener(new ActionListener()
1459 public void actionPerformed(ActionEvent e)
1461 modifyConservation_actionPerformed();
1467 * Builds the group colour sub-menu, including any user-defined colours which
1468 * were loaded at startup or during the Jalview session
1470 protected void buildColourMenu()
1472 SequenceGroup sg = ap.av.getSelectionGroup();
1476 * popup menu with no sequence group scope
1480 colourMenu.removeAll();
1481 colourMenu.add(textColour);
1482 colourMenu.addSeparator();
1484 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, sg,
1486 bg.add(annotationColour);
1487 colourMenu.add(annotationColour);
1489 colourMenu.addSeparator();
1490 colourMenu.add(conservationMenuItem);
1491 colourMenu.add(modifyConservation);
1492 colourMenu.add(abovePIDColour);
1493 colourMenu.add(modifyPID);
1496 protected void modifyConservation_actionPerformed()
1498 SequenceGroup sg = getGroup();
1501 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1502 SliderPanel.showConservationSlider();
1506 protected void modifyPID_actionPerformed()
1508 SequenceGroup sg = getGroup();
1511 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1513 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1514 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1515 SliderPanel.showPIDSlider();
1520 * Check for any annotations on the underlying dataset sequences (for the
1521 * current selection group) which are not 'on the alignment'.If any are found,
1522 * enable the option to add them to the alignment. The criteria for 'on the
1523 * alignment' is finding an alignment annotation on the alignment, matched on
1524 * calcId, label and sequenceRef.
1526 * A tooltip is also constructed that displays the source (calcId) and type
1527 * (label) of the annotations that can be added.
1530 * @param forSequences
1532 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1533 List<SequenceI> forSequences)
1535 menuItem.setEnabled(false);
1538 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1539 * Using TreeMap means calcIds are shown in alphabetical order.
1541 SortedMap<String, String> tipEntries = new TreeMap<>();
1542 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1543 AlignmentI al = this.ap.av.getAlignment();
1544 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1546 if (!candidates.isEmpty())
1548 StringBuilder tooltip = new StringBuilder(64);
1549 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1552 * Found annotations that could be added. Enable the menu item, and
1553 * configure its tooltip and action.
1555 menuItem.setEnabled(true);
1556 for (String calcId : tipEntries.keySet())
1558 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1560 String tooltipText = JvSwingUtils.wrapTooltip(true,
1561 tooltip.toString());
1562 menuItem.setToolTipText(tooltipText);
1564 menuItem.addActionListener(new ActionListener()
1567 public void actionPerformed(ActionEvent e)
1569 addReferenceAnnotations_actionPerformed(candidates);
1576 * Add annotations to the sequences and to the alignment.
1579 * a map whose keys are sequences on the alignment, and values a list
1580 * of annotations to add to each sequence
1582 protected void addReferenceAnnotations_actionPerformed(
1583 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1585 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1586 final AlignmentI alignment = this.ap.getAlignment();
1587 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1592 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1594 if (!ap.av.getAlignment().hasSeqrep())
1596 // initialise the display flags so the user sees something happen
1597 ap.av.setDisplayReferenceSeq(true);
1598 ap.av.setColourByReferenceSeq(true);
1599 ap.av.getAlignment().setSeqrep(sequence);
1603 if (ap.av.getAlignment().getSeqrep() == sequence)
1605 ap.av.getAlignment().setSeqrep(null);
1609 ap.av.getAlignment().setSeqrep(sequence);
1615 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1617 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1618 BitSet inserts = new BitSet();
1620 boolean markedPopup = false;
1621 // mark inserts in current selection
1622 if (ap.av.getSelectionGroup() != null)
1624 // mark just the columns in the selection group to be hidden
1625 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1626 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1628 // now clear columns without gaps
1629 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1635 inserts.and(sq.getInsertionsAsBits());
1637 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1638 ap.av.getSelectionGroup().getEndRes());
1641 // now mark for sequence under popup if we haven't already done it
1642 else if (!markedPopup && sequence != null)
1644 inserts.or(sequence.getInsertionsAsBits());
1646 // and set hidden columns accordingly
1647 hidden.hideColumns(inserts);
1652 protected void sequenceSelectionDetails_actionPerformed()
1654 createSequenceDetailsReport(ap.av.getSequenceSelection());
1657 protected void sequenceDetails_actionPerformed()
1659 createSequenceDetailsReport(new SequenceI[] { sequence });
1662 public void createSequenceDetailsReport(SequenceI[] sequences)
1664 StringBuilder contents = new StringBuilder(128);
1665 contents.append("<html><body>");
1666 for (SequenceI seq : sequences)
1668 contents.append("<p><h2>" + MessageManager.formatMessage(
1669 "label.create_sequence_details_report_annotation_for",
1671 { seq.getDisplayId(true) }) + "</h2></p><p>");
1672 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
1673 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1674 contents.append("</p>");
1676 contents.append("</body></html>");
1677 String report = contents.toString();
1679 JInternalFrame frame;
1680 if (Platform.isJS())
1682 JLabel textLabel = new JLabel();
1683 textLabel.setText(report);
1684 textLabel.setBackground(Color.WHITE);
1685 JPanel pane = new JPanel(new BorderLayout());
1686 ((JPanel) pane).setOpaque(true);
1687 pane.setBackground(Color.WHITE);
1688 ((JPanel) pane).add(textLabel, BorderLayout.NORTH);
1689 frame = new JInternalFrame();
1690 frame.getContentPane().add(new JScrollPane(pane));
1694 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1695 cap.setText(report);
1699 Desktop.addInternalFrame(frame,
1700 MessageManager.formatMessage("label.sequence_details_for",
1701 (sequences.length == 1 ? new Object[]
1702 { sequences[0].getDisplayId(true) }
1705 .getString("label.selection") })),
1709 protected void showNonconserved_actionPerformed()
1711 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1716 * call to refresh view after settings change
1720 ap.updateAnnotation();
1721 // removed paintAlignment(true) here:
1722 // updateAnnotation calls paintAlignment already, so don't need to call
1725 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1729 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1730 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1740 public void abovePIDColour_actionPerformed(boolean selected)
1742 SequenceGroup sg = getGroup();
1750 sg.cs.setConsensus(AAFrequency.calculate(
1751 sg.getSequences(ap.av.getHiddenRepSequences()),
1752 sg.getStartRes(), sg.getEndRes() + 1));
1754 int threshold = SliderPanel.setPIDSliderSource(ap,
1755 sg.getGroupColourScheme(), getGroup().getName());
1757 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1759 SliderPanel.showPIDSlider();
1762 // remove PIDColouring
1764 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1765 SliderPanel.hidePIDSlider();
1767 modifyPID.setEnabled(selected);
1773 * Open a panel where the user can choose which types of sequence annotation
1778 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1780 // todo correct way to guard against opening a duplicate panel?
1781 new AnnotationChooser(ap);
1790 public void conservationMenuItem_actionPerformed(boolean selected)
1792 SequenceGroup sg = getGroup();
1800 // JBPNote: Conservation name shouldn't be i18n translated
1801 Conservation c = new Conservation("Group",
1802 sg.getSequences(ap.av.getHiddenRepSequences()),
1803 sg.getStartRes(), sg.getEndRes() + 1);
1806 c.verdict(false, ap.av.getConsPercGaps());
1807 sg.cs.setConservation(c);
1809 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1811 SliderPanel.showConservationSlider();
1814 // remove ConservationColouring
1816 sg.cs.setConservation(null);
1817 SliderPanel.hideConservationSlider();
1819 modifyConservation.setEnabled(selected);
1825 * Shows a dialog where group name and description may be edited
1827 protected void groupName_actionPerformed()
1829 SequenceGroup sg = getGroup();
1830 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1831 sg.getDescription(),
1832 MessageManager.getString("label.group_name"),
1833 MessageManager.getString("label.group_description"));
1834 dialog.showDialog(ap.alignFrame,
1835 MessageManager.getString("label.edit_group_name_description"),
1841 sg.setName(dialog.getName());
1842 sg.setDescription(dialog.getDescription());
1849 * Get selection group - adding it to the alignment if necessary.
1851 * @return sequence group to operate on
1853 SequenceGroup getGroup()
1855 SequenceGroup sg = ap.av.getSelectionGroup();
1856 // this method won't add a new group if it already exists
1859 ap.av.getAlignment().addGroup(sg);
1866 * Shows a dialog where sequence name and description may be edited
1868 void sequenceName_actionPerformed()
1870 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1871 sequence.getDescription(),
1872 MessageManager.getString("label.sequence_name"),
1873 MessageManager.getString("label.sequence_description"));
1874 dialog.showDialog(ap.alignFrame,
1875 MessageManager.getString(
1876 "label.edit_sequence_name_description"),
1882 if (dialog.getName() != null)
1884 if (dialog.getName().indexOf(" ") > -1)
1886 JvOptionPane.showMessageDialog(ap,
1887 MessageManager.getString(
1888 "label.spaces_converted_to_underscores"),
1889 MessageManager.getString(
1890 "label.no_spaces_allowed_sequence_name"),
1891 JvOptionPane.WARNING_MESSAGE);
1893 sequence.setName(dialog.getName().replace(' ', '_'));
1894 ap.paintAlignment(false, false);
1896 sequence.setDescription(dialog.getDescription());
1897 ap.av.firePropertyChange("alignment", null,
1898 ap.av.getAlignment().getSequences());
1909 void unGroupMenuItem_actionPerformed()
1911 SequenceGroup sg = ap.av.getSelectionGroup();
1912 ap.av.getAlignment().deleteGroup(sg);
1913 ap.av.setSelectionGroup(null);
1917 void createGroupMenuItem_actionPerformed()
1919 getGroup(); // implicitly creates group - note - should apply defaults / use
1920 // standard alignment window logic for this
1925 * Offers a colour chooser and sets the selected colour as the group outline
1927 protected void outline_actionPerformed()
1929 String title = MessageManager
1930 .getString("label.select_outline_colour");
1931 ColourChooserListener listener = new ColourChooserListener()
1934 public void colourSelected(Color c)
1936 getGroup().setOutlineColour(c);
1940 JalviewColourChooser.showColourChooser(Desktop.getDesktop(),
1941 title, Color.BLUE, listener);
1950 public void showBoxes_actionPerformed()
1952 getGroup().setDisplayBoxes(showBoxes.isSelected());
1962 public void showText_actionPerformed()
1964 getGroup().setDisplayText(showText.isSelected());
1974 public void showColourText_actionPerformed()
1976 getGroup().setColourText(showColourText.isSelected());
1980 public void showLink(String url)
1984 jalview.util.BrowserLauncher.openURL(url);
1985 } catch (Exception ex)
1987 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1988 MessageManager.getString("label.web_browser_not_found_unix"),
1989 MessageManager.getString("label.web_browser_not_found"),
1990 JvOptionPane.WARNING_MESSAGE);
1992 ex.printStackTrace();
1996 void hideSequences(boolean representGroup)
1998 ap.av.hideSequences(sequence, representGroup);
2001 public void copy_actionPerformed()
2003 ap.alignFrame.copy_actionPerformed();
2006 public void cut_actionPerformed()
2008 ap.alignFrame.cut_actionPerformed();
2011 void changeCase(ActionEvent e)
2013 Object source = e.getSource();
2014 SequenceGroup sg = ap.av.getSelectionGroup();
2018 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2019 sg.getStartRes(), sg.getEndRes() + 1);
2024 if (source == toggle)
2026 description = MessageManager.getString("label.toggle_case");
2027 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2029 else if (source == upperCase)
2031 description = MessageManager.getString("label.to_upper_case");
2032 caseChange = ChangeCaseCommand.TO_UPPER;
2036 description = MessageManager.getString("label.to_lower_case");
2037 caseChange = ChangeCaseCommand.TO_LOWER;
2040 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2041 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2042 startEnd, caseChange);
2044 ap.alignFrame.addHistoryItem(caseCommand);
2046 ap.av.firePropertyChange("alignment", null,
2047 ap.av.getAlignment().getSequences());
2052 public void outputText_actionPerformed(ActionEvent e)
2054 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2055 cap.setForInput(null);
2056 Desktop.addInternalFrame(cap, MessageManager
2057 .formatMessage("label.alignment_output_command", new Object[]
2058 { e.getActionCommand() }), 600, 500);
2060 String[] omitHidden = null;
2062 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2063 // or we simply trust the user wants
2064 // wysiwig behaviour
2066 FileFormatI fileFormat = FileFormats.getInstance()
2067 .forName(e.getActionCommand());
2069 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2072 public void sequenceFeature_actionPerformed()
2074 SequenceGroup sg = ap.av.getSelectionGroup();
2080 List<SequenceI> seqs = new ArrayList<>();
2081 List<SequenceFeature> features = new ArrayList<>();
2084 * assemble dataset sequences, and template new sequence features,
2085 * for the amend features dialog
2087 int gSize = sg.getSize();
2088 for (int i = 0; i < gSize; i++)
2090 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2091 int end = sg.findEndRes(sg.getSequenceAt(i));
2094 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2095 features.add(new SequenceFeature(null, null, start, end, null));
2100 * an entirely gapped region will generate empty lists of sequence / features
2102 if (!seqs.isEmpty())
2104 new FeatureEditor(ap, seqs, features, true).showDialog();
2108 public void textColour_actionPerformed()
2110 SequenceGroup sg = getGroup();
2113 new TextColourChooser().chooseColour(ap, sg);
2117 public void colourByStructure(String pdbid)
2119 Annotation[] anots = ap.av.getStructureSelectionManager()
2120 .colourSequenceFromStructure(sequence, pdbid);
2122 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2123 "Coloured by " + pdbid, anots);
2125 ap.av.getAlignment().addAnnotation(an);
2126 an.createSequenceMapping(sequence, 0, true);
2127 // an.adjustForAlignment();
2128 ap.av.getAlignment().setAnnotationIndex(an, 0);
2130 ap.adjustAnnotationHeight();
2132 sequence.addAlignmentAnnotation(an);
2137 * Shows a dialog where sequence characters may be edited. Any changes are
2138 * applied, and added as an available 'Undo' item in the edit commands
2141 public void editSequence_actionPerformed()
2143 SequenceGroup sg = ap.av.getSelectionGroup();
2147 if (sequence == null)
2149 sequence = sg.getSequenceAt(0);
2152 EditNameDialog dialog = new EditNameDialog(
2153 sequence.getSequenceAsString(sg.getStartRes(),
2154 sg.getEndRes() + 1),
2155 null, MessageManager.getString("label.edit_sequence"), null);
2156 dialog.showDialog(ap.alignFrame,
2157 MessageManager.getString("label.edit_sequence"),
2163 EditCommand editCommand = new EditCommand(
2164 MessageManager.getString("label.edit_sequences"),
2166 dialog.getName().replace(' ',
2167 ap.av.getGapCharacter()),
2168 sg.getSequencesAsArray(
2169 ap.av.getHiddenRepSequences()),
2170 sg.getStartRes(), sg.getEndRes() + 1,
2171 ap.av.getAlignment());
2172 ap.alignFrame.addHistoryItem(editCommand);
2173 ap.av.firePropertyChange("alignment", null,
2174 ap.av.getAlignment().getSequences());
2181 * Action on user selecting an item from the colour menu (that does not have
2182 * its bespoke action handler)
2187 public void changeColour_actionPerformed(String colourSchemeName)
2189 SequenceGroup sg = getGroup();
2191 * switch to the chosen colour scheme (or null for None)
2193 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2194 .getColourScheme(colourSchemeName, ap.av, sg,
2195 ap.av.getHiddenRepSequences());
2196 sg.setColourScheme(colourScheme);
2197 if (colourScheme instanceof Blosum62ColourScheme
2198 || colourScheme instanceof PIDColourScheme)
2200 sg.cs.setConsensus(AAFrequency.calculate(
2201 sg.getSequences(ap.av.getHiddenRepSequences()),
2202 sg.getStartRes(), sg.getEndRes() + 1));