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.util.GroupUrlLink;
51 import jalview.util.GroupUrlLink.UrlStringTooLongException;
52 import jalview.util.MessageManager;
53 import jalview.util.Platform;
54 import jalview.util.StringUtils;
55 import jalview.util.UrlLink;
57 import java.awt.BorderLayout;
58 import java.awt.Color;
59 import java.awt.event.ActionEvent;
60 import java.awt.event.ActionListener;
61 import java.util.ArrayList;
62 import java.util.Arrays;
63 import java.util.BitSet;
64 import java.util.Collection;
65 import java.util.Collections;
66 import java.util.Hashtable;
67 import java.util.LinkedHashMap;
68 import java.util.List;
70 import java.util.SortedMap;
71 import java.util.TreeMap;
72 import java.util.Vector;
74 import javax.swing.JCheckBoxMenuItem;
75 import javax.swing.JInternalFrame;
76 import javax.swing.JLabel;
77 import javax.swing.JMenu;
78 import javax.swing.JMenuItem;
79 import javax.swing.JPanel;
80 import javax.swing.JPopupMenu;
81 import javax.swing.JScrollPane;
87 * @version $Revision: 1.118 $
89 public class PopupMenu extends JPopupMenu implements ColourChangeListener
91 JMenu groupMenu = new JMenu();
93 JMenuItem groupName = new JMenuItem();
95 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
97 protected JMenuItem modifyPID = new JMenuItem();
99 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
101 protected JMenuItem modifyConservation = new JMenuItem();
105 JMenu sequenceMenu = new JMenu();
107 JMenuItem sequenceName = new JMenuItem();
109 JMenuItem sequenceDetails = new JMenuItem();
111 JMenuItem sequenceSelDetails = new JMenuItem();
113 JMenuItem makeReferenceSeq = new JMenuItem();
115 JMenuItem chooseAnnotations = new JMenuItem();
119 JMenuItem createGroupMenuItem = new JMenuItem();
121 JMenuItem unGroupMenuItem = new JMenuItem();
123 JMenuItem outline = new JMenuItem();
125 JMenu colourMenu = new JMenu();
127 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
129 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
131 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
133 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
135 JMenu editMenu = new JMenu();
137 JMenuItem cut = new JMenuItem();
139 JMenuItem copy = new JMenuItem();
141 JMenuItem upperCase = new JMenuItem();
143 JMenuItem lowerCase = new JMenuItem();
145 JMenuItem toggle = new JMenuItem();
147 JMenu pdbMenu = new JMenu();
149 JMenu outputMenu = new JMenu();
151 JMenu seqShowAnnotationsMenu = new JMenu();
153 JMenu seqHideAnnotationsMenu = new JMenu();
155 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
156 MessageManager.getString("label.add_reference_annotations"));
158 JMenu groupShowAnnotationsMenu = new JMenu();
160 JMenu groupHideAnnotationsMenu = new JMenu();
162 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
163 MessageManager.getString("label.add_reference_annotations"));
165 JMenuItem sequenceFeature = new JMenuItem();
167 JMenuItem textColour = new JMenuItem();
169 JMenu jMenu1 = new JMenu();
171 JMenuItem pdbStructureDialog = new JMenuItem();
173 JMenu rnaStructureMenu = new JMenu();
175 JMenuItem editSequence = new JMenuItem();
177 JMenu groupLinksMenu;
179 JMenuItem hideInsertions = new JMenuItem();
182 * Creates a new PopupMenu object.
187 * non-positional features (for seq not null), or positional features
188 * at residue (for seq equal to null)
190 public PopupMenu(final AlignmentPanel ap, SequenceI seq,
191 List<SequenceFeature> features)
193 this(ap, seq, features, null);
201 * the sequence under the cursor if in the Id panel, null if in the
204 * non-positional features if in the Id panel, features at the
205 * clicked residue if in the sequence panel
208 public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
209 List<SequenceFeature> features, List<String> groupLinks)
211 // /////////////////////////////////////////////////////////
212 // If this is activated from the sequence panel, the user may want to
213 // edit or annotate a particular residue. Therefore display the residue menu
215 // If from the IDPanel, we must display the sequence menu
216 // ////////////////////////////////////////////////////////
217 this.ap = alignPanel;
220 for (String ff : FileFormats.getInstance().getWritableFormats(true))
222 JMenuItem item = new JMenuItem(ff);
224 item.addActionListener(new ActionListener()
227 public void actionPerformed(ActionEvent e)
229 outputText_actionPerformed(e);
233 outputMenu.add(item);
237 * Build menus for annotation types that may be shown or hidden, and for
238 * 'reference annotations' that may be added to the alignment. First for the
239 * currently selected sequence (if there is one):
241 final List<SequenceI> selectedSequence = (seq == null
242 ? Collections.<SequenceI> emptyList()
243 : Arrays.asList(seq));
244 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
245 seqHideAnnotationsMenu, selectedSequence);
246 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
250 * And repeat for the current selection group (if there is one):
252 final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
253 ? Collections.<SequenceI> emptyList()
254 : alignPanel.av.getSelectionGroup().getSequences());
255 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
256 groupHideAnnotationsMenu, selectedGroup);
257 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
263 } catch (Exception e)
271 sequenceMenu.setText(sequence.getName());
272 if (seq == alignPanel.av.getAlignment().getSeqrep())
274 makeReferenceSeq.setText(
275 MessageManager.getString("action.unmark_as_reference"));
279 makeReferenceSeq.setText(
280 MessageManager.getString("action.set_as_reference"));
283 if (!alignPanel.av.getAlignment().isNucleotide())
285 remove(rnaStructureMenu);
289 int origCount = rnaStructureMenu.getItemCount();
291 * add menu items to 2D-render any alignment or sequence secondary
292 * structure annotation
294 AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
295 .getAlignmentAnnotation();
298 for (final AlignmentAnnotation aa : aas)
300 if (aa.isValidStruc() && aa.sequenceRef == null)
303 * valid alignment RNA secondary structure annotation
305 menuItem = new JMenuItem();
306 menuItem.setText(MessageManager.formatMessage(
307 "label.2d_rna_structure_line", new Object[]
309 menuItem.addActionListener(new ActionListener()
312 public void actionPerformed(ActionEvent e)
314 new AppVarna(seq, aa, alignPanel);
317 rnaStructureMenu.add(menuItem);
322 if (seq.getAnnotation() != null)
324 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
325 for (final AlignmentAnnotation aa : seqAnns)
327 if (aa.isValidStruc())
330 * valid sequence RNA secondary structure annotation
332 // TODO: make rnastrucF a bit more nice
333 menuItem = new JMenuItem();
334 menuItem.setText(MessageManager.formatMessage(
335 "label.2d_rna_sequence_name", new Object[]
337 menuItem.addActionListener(new ActionListener()
340 public void actionPerformed(ActionEvent e)
342 // TODO: VARNA does'nt print gaps in the sequence
343 new AppVarna(seq, aa, alignPanel);
346 rnaStructureMenu.add(menuItem);
350 if (rnaStructureMenu.getItemCount() == origCount)
352 remove(rnaStructureMenu);
356 menuItem = new JMenuItem(
357 MessageManager.getString("action.hide_sequences"));
358 menuItem.addActionListener(new ActionListener()
361 public void actionPerformed(ActionEvent e)
363 hideSequences(false);
368 if (alignPanel.av.getSelectionGroup() != null
369 && alignPanel.av.getSelectionGroup().getSize() > 1)
371 menuItem = new JMenuItem(MessageManager
372 .formatMessage("label.represent_group_with", new Object[]
374 menuItem.addActionListener(new ActionListener()
377 public void actionPerformed(ActionEvent e)
382 sequenceMenu.add(menuItem);
385 if (alignPanel.av.hasHiddenRows())
387 final int index = alignPanel.av.getAlignment().findIndex(seq);
389 if (alignPanel.av.adjustForHiddenSeqs(index)
390 - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
392 menuItem = new JMenuItem(
393 MessageManager.getString("action.reveal_sequences"));
394 menuItem.addActionListener(new ActionListener()
397 public void actionPerformed(ActionEvent e)
399 alignPanel.av.showSequence(index);
400 if (alignPanel.overviewPanel != null)
402 alignPanel.overviewPanel.updateOverviewImage();
410 // for the case when no sequences are even visible
411 if (alignPanel.av.hasHiddenRows())
414 menuItem = new JMenuItem(
415 MessageManager.getString("action.reveal_all"));
416 menuItem.addActionListener(new ActionListener()
419 public void actionPerformed(ActionEvent e)
421 alignPanel.av.showAllHiddenSeqs();
422 if (alignPanel.overviewPanel != null)
424 alignPanel.overviewPanel.updateOverviewImage();
433 SequenceGroup sg = alignPanel.av.getSelectionGroup();
434 boolean isDefinedGroup = (sg != null)
435 ? alignPanel.av.getAlignment().getGroups().contains(sg)
438 if (sg != null && sg.getSize() > 0)
440 groupName.setText(MessageManager
441 .getString("label.edit_name_and_description_current_group"));
443 ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
445 conservationMenuItem.setEnabled(!sg.isNucleotide());
449 if (sg.cs.conservationApplied())
451 conservationMenuItem.setSelected(true);
453 if (sg.cs.getThreshold() > 0)
455 abovePIDColour.setSelected(true);
458 modifyConservation.setEnabled(conservationMenuItem.isSelected());
459 modifyPID.setEnabled(abovePIDColour.isSelected());
460 displayNonconserved.setSelected(sg.getShowNonconserved());
461 showText.setSelected(sg.getDisplayText());
462 showColourText.setSelected(sg.getColourText());
463 showBoxes.setSelected(sg.getDisplayBoxes());
464 // add any groupURLs to the groupURL submenu and make it visible
465 if (groupLinks != null && groupLinks.size() > 0)
467 buildGroupURLMenu(sg, groupLinks);
469 // Add a 'show all structures' for the current selection
470 Hashtable<String, PDBEntry> pdbe = new Hashtable<>(), reppdb = new Hashtable<>();
472 SequenceI sqass = null;
473 for (SequenceI sq : alignPanel.av.getSequenceSelection())
475 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
476 if (pes != null && pes.size() > 0)
478 reppdb.put(pes.get(0).getId(), pes.get(0));
479 for (PDBEntry pe : pes)
481 pdbe.put(pe.getId(), pe);
491 final PDBEntry[] pe = pdbe.values()
492 .toArray(new PDBEntry[pdbe.size()]),
493 pr = reppdb.values().toArray(new PDBEntry[reppdb.size()]);
494 final JMenuItem gpdbview, rpdbview;
499 groupMenu.setVisible(false);
500 editMenu.setVisible(false);
505 createGroupMenuItem.setVisible(true);
506 unGroupMenuItem.setVisible(false);
507 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
511 createGroupMenuItem.setVisible(false);
512 unGroupMenuItem.setVisible(true);
513 jMenu1.setText(MessageManager.getString("action.edit_group"));
518 sequenceMenu.setVisible(false);
519 pdbStructureDialog.setVisible(false);
520 rnaStructureMenu.setVisible(false);
523 addLinks(seq, features);
527 addFeatureDetails(features);
532 * Add a link to show feature details for each sequence feature
536 protected void addFeatureDetails(List<SequenceFeature> features)
538 if (features == null || features.isEmpty())
542 JMenu details = new JMenu(
543 MessageManager.getString("label.feature_details"));
546 for (final SequenceFeature sf : features)
548 int start = sf.getBegin();
549 int end = sf.getEnd();
553 desc = String.format("%s %d", sf.getType(), start);
557 desc = String.format("%s %d-%d", sf.getType(), start, end);
559 String tooltip = desc;
560 String description = sf.getDescription();
561 if (description != null)
563 description = StringUtils.stripHtmlTags(description);
564 if (description.length() > 12)
566 desc = desc + " " + description.substring(0, 12) + "..";
570 desc = desc + " " + description;
572 tooltip = tooltip + " " + description;
574 if (sf.getFeatureGroup() != null)
576 tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")");
578 JMenuItem item = new JMenuItem(desc);
579 item.setToolTipText(tooltip);
580 item.addActionListener(new ActionListener()
583 public void actionPerformed(ActionEvent e)
585 showFeatureDetails(sf);
593 * Opens a panel showing a text report of feature dteails
597 protected void showFeatureDetails(SequenceFeature sf)
599 JInternalFrame details;
600 if (/** @j2sNative true || */ false)
602 details = new JInternalFrame();
603 JPanel panel = new JPanel(new BorderLayout());
604 panel.setOpaque(true);
605 panel.setBackground(Color.white);
606 // TODO JAL-3026 set style of table correctly for feature details
607 JLabel reprt = new JLabel(MessageManager.formatMessage("label.html_content",
609 { sf.getDetailsReport()}));
610 reprt.setBackground(Color.WHITE);
611 reprt.setOpaque(true);
612 panel.add(reprt,BorderLayout.CENTER);
613 details.setContentPane(panel);
618 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
619 // it appears Java's CSS does not support border-collaps :-(
620 cap.addStylesheetRule("table { border-collapse: collapse;}");
621 cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
622 cap.setText(sf.getDetailsReport());
625 Desktop.addInternalFrame(details,
626 MessageManager.getString("label.feature_details"), 500, 500);
630 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
631 * When seq is not null, these are links for the sequence id, which may be to
632 * external web sites for the sequence accession, and/or links embedded in
633 * non-positional features. When seq is null, only links embedded in the
634 * provided features are added.
639 void addLinks(final SequenceI seq, List<SequenceFeature> features)
641 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
643 List<String> nlinks = null;
646 nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
650 nlinks = new ArrayList<>();
653 if (features != null)
655 for (SequenceFeature sf : features)
657 if (sf.links != null)
659 for (String link : sf.links)
667 Map<String, List<String>> linkset = new LinkedHashMap<>();
669 for (String link : nlinks)
671 UrlLink urlLink = null;
674 urlLink = new UrlLink(link);
675 } catch (Exception foo)
677 Cache.log.error("Exception for URLLink '" + link + "'", foo);
681 if (!urlLink.isValid())
683 Cache.log.error(urlLink.getInvalidMessage());
687 urlLink.createLinksFromSeq(seq, linkset);
690 addshowLinks(linkMenu, linkset.values());
692 // only add link menu if it has entries
693 if (linkMenu.getItemCount() > 0)
695 if (sequence != null)
697 sequenceMenu.add(linkMenu);
707 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
708 * "All" is added first, followed by a separator. Then add any annotation
709 * types associated with the current selection. Separate menus are built for
710 * the selected sequence group (if any), and the selected sequence.
712 * Some annotation rows are always rendered together - these can be identified
713 * by a common graphGroup property > -1. Only one of each group will be marked
714 * as visible (to avoid duplication of the display). For such groups we add a
715 * composite type name, e.g.
717 * IUPredWS (Long), IUPredWS (Short)
721 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
722 List<SequenceI> forSequences)
724 showMenu.removeAll();
725 hideMenu.removeAll();
727 final List<String> all = Arrays
729 { MessageManager.getString("label.all") });
730 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true,
732 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
734 showMenu.addSeparator();
735 hideMenu.addSeparator();
737 final AlignmentAnnotation[] annotations = ap.getAlignment()
738 .getAlignmentAnnotation();
741 * Find shown/hidden annotations types, distinguished by source (calcId),
742 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
743 * the insertion order, which is the order of the annotations on the
746 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<>();
747 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<>();
748 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
749 AlignmentAnnotationUtils.asList(annotations), forSequences);
751 for (String calcId : hiddenTypes.keySet())
753 for (List<String> type : hiddenTypes.get(calcId))
755 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
759 // grey out 'show annotations' if none are hidden
760 showMenu.setEnabled(!hiddenTypes.isEmpty());
762 for (String calcId : shownTypes.keySet())
764 for (List<String> type : shownTypes.get(calcId))
766 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
770 // grey out 'hide annotations' if none are shown
771 hideMenu.setEnabled(!shownTypes.isEmpty());
775 * Returns a list of sequences - either the current selection group (if there
776 * is one), else the specified single sequence.
781 protected List<SequenceI> getSequenceScope(SequenceI seq)
783 List<SequenceI> forSequences = null;
784 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
785 if (selectionGroup != null && selectionGroup.getSize() > 0)
787 forSequences = selectionGroup.getSequences();
791 forSequences = seq == null ? Collections.<SequenceI> emptyList()
792 : Arrays.asList(seq);
798 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
801 * @param showOrHideMenu
803 * @param forSequences
804 * the sequences whose annotations may be shown or hidden
809 * if true this is a special label meaning 'All'
810 * @param actionIsShow
811 * if true, the select menu item action is to show the annotation
814 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
815 final List<SequenceI> forSequences, String calcId,
816 final List<String> types, final boolean allTypes,
817 final boolean actionIsShow)
819 String label = types.toString(); // [a, b, c]
820 label = label.substring(1, label.length() - 1); // a, b, c
821 final JMenuItem item = new JMenuItem(label);
822 item.setToolTipText(calcId);
823 item.addActionListener(new ActionListener()
826 public void actionPerformed(ActionEvent e)
828 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
829 types, forSequences, allTypes, actionIsShow);
833 showOrHideMenu.add(item);
836 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
839 // TODO: usability: thread off the generation of group url content so root
841 // sequence only URLs
842 // ID/regex match URLs
843 groupLinksMenu = new JMenu(
844 MessageManager.getString("action.group_link"));
845 // three types of url that might be created.
846 JMenu[] linkMenus = new JMenu[] { null,
847 new JMenu(MessageManager.getString("action.ids")),
848 new JMenu(MessageManager.getString("action.sequences")),
849 new JMenu(MessageManager.getString("action.ids_sequences")) };
851 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
852 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
853 Hashtable<String, Object[]> commonDbrefs = new Hashtable<>();
854 for (int sq = 0; sq < seqs.length; sq++)
857 int start = seqs[sq].findPosition(sg.getStartRes()),
858 end = seqs[sq].findPosition(sg.getEndRes());
859 // just collect ids from dataset sequence
860 // TODO: check if IDs collected from selecton group intersects with the
861 // current selection, too
862 SequenceI sqi = seqs[sq];
863 while (sqi.getDatasetSequence() != null)
865 sqi = sqi.getDatasetSequence();
867 List<DBRefEntry> dbr = sqi.getDBRefs();
869 if (dbr != null && (nd = dbr.size()) > 0)
871 for (int d = 0; d < nd; d++)
873 DBRefEntry e = dbr.get(d);
874 String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
875 Object[] sarray = commonDbrefs.get(src);
878 sarray = new Object[2];
879 sarray[0] = new int[] { 0 };
880 sarray[1] = new String[seqs.length];
882 commonDbrefs.put(src, sarray);
885 if (((String[]) sarray[1])[sq] == null)
887 if (!e.hasMap() || (e.getMap()
888 .locateMappedRange(start, end) != null))
890 ((String[]) sarray[1])[sq] = e.getAccessionId();
891 ((int[]) sarray[0])[0]++;
897 // now create group links for all distinct ID/sequence sets.
898 boolean addMenu = false; // indicates if there are any group links to give
900 for (String link : groupLinks)
902 GroupUrlLink urlLink = null;
905 urlLink = new GroupUrlLink(link);
906 } catch (Exception foo)
908 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
912 if (!urlLink.isValid())
914 Cache.log.error(urlLink.getInvalidMessage());
917 final String label = urlLink.getLabel();
918 boolean usingNames = false;
919 // Now see which parts of the group apply for this URL
920 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
921 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
922 String[] seqstr, ids; // input to makeUrl
925 int numinput = ((int[]) idset[0])[0];
926 String[] allids = ((String[]) idset[1]);
927 seqstr = new String[numinput];
928 ids = new String[numinput];
929 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
931 if (allids[sq] != null)
933 ids[idcount] = allids[sq];
934 seqstr[idcount++] = idandseqs[1][sq];
940 // just use the id/seq set
941 seqstr = idandseqs[1];
945 // and try and make the groupURL!
947 Object[] urlset = null;
950 urlset = urlLink.makeUrlStubs(ids, seqstr,
951 "FromJalview" + System.currentTimeMillis(), false);
952 } catch (UrlStringTooLongException e)
957 int type = urlLink.getGroupURLType() & 3;
958 // first two bits ofurlLink type bitfield are sequenceids and sequences
959 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
960 addshowLink(linkMenus[type],
961 label + (((type & 1) == 1)
962 ? ("(" + (usingNames ? "Names" : ltarget) + ")")
970 groupLinksMenu = new JMenu(
971 MessageManager.getString("action.group_link"));
972 for (int m = 0; m < linkMenus.length; m++)
974 if (linkMenus[m] != null
975 && linkMenus[m].getMenuComponentCount() > 0)
977 groupLinksMenu.add(linkMenus[m]);
981 groupMenu.add(groupLinksMenu);
985 private void addshowLinks(JMenu linkMenu,
986 Collection<List<String>> linkset)
988 for (List<String> linkstrset : linkset)
990 // split linkstr into label and url
991 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
996 * add a show URL menu item to the given linkMenu
1000 * - menu label string
1004 private void addshowLink(JMenu linkMenu, String label, final String url)
1006 JMenuItem item = new JMenuItem(label);
1007 item.setToolTipText(MessageManager.formatMessage("label.open_url_param",
1010 item.addActionListener(new ActionListener()
1013 public void actionPerformed(ActionEvent e)
1015 new Thread(new Runnable()
1032 * add a late bound groupURL item to the given linkMenu
1036 * - menu label string
1037 * @param urlgenerator
1038 * GroupURLLink used to generate URL
1040 * Object array returned from the makeUrlStubs function.
1042 private void addshowLink(JMenu linkMenu, String label,
1043 final GroupUrlLink urlgenerator, final Object[] urlstub)
1045 JMenuItem item = new JMenuItem(label);
1046 item.setToolTipText(MessageManager
1047 .formatMessage("label.open_url_seqs_param", new Object[]
1048 { urlgenerator.getUrl_prefix(),
1049 urlgenerator.getNumberInvolved(urlstub) }));
1050 // TODO: put in info about what is being sent.
1051 item.addActionListener(new ActionListener()
1054 public void actionPerformed(ActionEvent e)
1056 new Thread(new Runnable()
1064 showLink(urlgenerator.constructFrom(urlstub));
1065 } catch (UrlStringTooLongException e2)
1083 private void jbInit() throws Exception
1085 groupMenu.setText(MessageManager.getString("label.selection"));
1086 groupName.setText(MessageManager.getString("label.name"));
1087 groupName.addActionListener(new ActionListener()
1090 public void actionPerformed(ActionEvent e)
1092 groupName_actionPerformed();
1095 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1096 sequenceName.setText(
1097 MessageManager.getString("label.edit_name_description"));
1098 sequenceName.addActionListener(new ActionListener()
1101 public void actionPerformed(ActionEvent e)
1103 sequenceName_actionPerformed();
1107 .setText(MessageManager.getString("action.choose_annotations"));
1108 chooseAnnotations.addActionListener(new ActionListener()
1111 public void actionPerformed(ActionEvent e)
1113 chooseAnnotations_actionPerformed(e);
1117 .setText(MessageManager.getString("label.sequence_details"));
1118 sequenceDetails.addActionListener(new ActionListener()
1121 public void actionPerformed(ActionEvent e)
1123 sequenceDetails_actionPerformed();
1127 .setText(MessageManager.getString("label.sequence_details"));
1128 sequenceSelDetails.addActionListener(new ActionListener()
1131 public void actionPerformed(ActionEvent e)
1133 sequenceSelectionDetails_actionPerformed();
1138 .setText(MessageManager.getString("action.remove_group"));
1139 unGroupMenuItem.addActionListener(new ActionListener()
1142 public void actionPerformed(ActionEvent e)
1144 unGroupMenuItem_actionPerformed();
1148 .setText(MessageManager.getString("action.create_group"));
1149 createGroupMenuItem.addActionListener(new ActionListener()
1152 public void actionPerformed(ActionEvent e)
1154 createGroupMenuItem_actionPerformed();
1158 outline.setText(MessageManager.getString("action.border_colour"));
1159 outline.addActionListener(new ActionListener()
1162 public void actionPerformed(ActionEvent e)
1164 outline_actionPerformed();
1167 showBoxes.setText(MessageManager.getString("action.boxes"));
1168 showBoxes.setState(true);
1169 showBoxes.addActionListener(new ActionListener()
1172 public void actionPerformed(ActionEvent e)
1174 showBoxes_actionPerformed();
1177 showText.setText(MessageManager.getString("action.text"));
1178 showText.setState(true);
1179 showText.addActionListener(new ActionListener()
1182 public void actionPerformed(ActionEvent e)
1184 showText_actionPerformed();
1187 showColourText.setText(MessageManager.getString("label.colour_text"));
1188 showColourText.addActionListener(new ActionListener()
1191 public void actionPerformed(ActionEvent e)
1193 showColourText_actionPerformed();
1197 .setText(MessageManager.getString("label.show_non_conserved"));
1198 displayNonconserved.setState(true);
1199 displayNonconserved.addActionListener(new ActionListener()
1202 public void actionPerformed(ActionEvent e)
1204 showNonconserved_actionPerformed();
1207 editMenu.setText(MessageManager.getString("action.edit"));
1208 cut.setText(MessageManager.getString("action.cut"));
1209 cut.addActionListener(new ActionListener()
1212 public void actionPerformed(ActionEvent e)
1214 cut_actionPerformed();
1217 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1218 upperCase.addActionListener(new ActionListener()
1221 public void actionPerformed(ActionEvent e)
1226 copy.setText(MessageManager.getString("action.copy"));
1227 copy.addActionListener(new ActionListener()
1230 public void actionPerformed(ActionEvent e)
1232 copy_actionPerformed();
1235 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1236 lowerCase.addActionListener(new ActionListener()
1239 public void actionPerformed(ActionEvent e)
1244 toggle.setText(MessageManager.getString("label.toggle_case"));
1245 toggle.addActionListener(new ActionListener()
1248 public void actionPerformed(ActionEvent e)
1254 MessageManager.getString("label.out_to_textbox") + "...");
1255 seqShowAnnotationsMenu
1256 .setText(MessageManager.getString("label.show_annotations"));
1257 seqHideAnnotationsMenu
1258 .setText(MessageManager.getString("label.hide_annotations"));
1259 groupShowAnnotationsMenu
1260 .setText(MessageManager.getString("label.show_annotations"));
1261 groupHideAnnotationsMenu
1262 .setText(MessageManager.getString("label.hide_annotations"));
1263 sequenceFeature.setText(
1264 MessageManager.getString("label.create_sequence_feature"));
1265 sequenceFeature.addActionListener(new ActionListener()
1268 public void actionPerformed(ActionEvent e)
1270 sequenceFeature_actionPerformed();
1273 jMenu1.setText(MessageManager.getString("label.group"));
1274 pdbStructureDialog.setText(
1275 MessageManager.getString("label.show_pdbstruct_dialog"));
1276 pdbStructureDialog.addActionListener(new ActionListener()
1279 public void actionPerformed(ActionEvent actionEvent)
1281 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1282 if (ap.av.getSelectionGroup() != null)
1284 selectedSeqs = ap.av.getSequenceSelection();
1286 new StructureChooser(selectedSeqs, sequence, ap);
1291 .setText(MessageManager.getString("label.view_rna_structure"));
1293 // colStructureMenu.setText("Colour By Structure");
1294 editSequence.setText(
1295 MessageManager.getString("label.edit_sequence") + "...");
1296 editSequence.addActionListener(new ActionListener()
1299 public void actionPerformed(ActionEvent actionEvent)
1301 editSequence_actionPerformed();
1304 makeReferenceSeq.setText(
1305 MessageManager.getString("label.mark_as_representative"));
1306 makeReferenceSeq.addActionListener(new ActionListener()
1310 public void actionPerformed(ActionEvent actionEvent)
1312 makeReferenceSeq_actionPerformed(actionEvent);
1317 .setText(MessageManager.getString("label.hide_insertions"));
1318 hideInsertions.addActionListener(new ActionListener()
1322 public void actionPerformed(ActionEvent e)
1324 hideInsertions_actionPerformed(e);
1328 groupMenu.add(sequenceSelDetails);
1331 add(rnaStructureMenu);
1332 add(pdbStructureDialog);
1333 if (sequence != null)
1335 add(hideInsertions);
1337 // annotations configuration panel suppressed for now
1338 // groupMenu.add(chooseAnnotations);
1341 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1342 * (if a selection group is in force).
1344 sequenceMenu.add(seqShowAnnotationsMenu);
1345 sequenceMenu.add(seqHideAnnotationsMenu);
1346 sequenceMenu.add(seqAddReferenceAnnotations);
1347 groupMenu.add(groupShowAnnotationsMenu);
1348 groupMenu.add(groupHideAnnotationsMenu);
1349 groupMenu.add(groupAddReferenceAnnotations);
1350 groupMenu.add(editMenu);
1351 groupMenu.add(outputMenu);
1352 groupMenu.add(sequenceFeature);
1353 groupMenu.add(createGroupMenuItem);
1354 groupMenu.add(unGroupMenuItem);
1355 groupMenu.add(jMenu1);
1356 sequenceMenu.add(sequenceName);
1357 sequenceMenu.add(sequenceDetails);
1358 sequenceMenu.add(makeReferenceSeq);
1365 editMenu.add(editSequence);
1366 editMenu.add(upperCase);
1367 editMenu.add(lowerCase);
1368 editMenu.add(toggle);
1369 // JBPNote: These shouldn't be added here - should appear in a generic
1370 // 'apply web service to this sequence menu'
1371 // pdbMenu.add(RNAFold);
1372 // pdbMenu.add(ContraFold);
1373 jMenu1.add(groupName);
1374 jMenu1.add(colourMenu);
1375 jMenu1.add(showBoxes);
1376 jMenu1.add(showText);
1377 jMenu1.add(showColourText);
1378 jMenu1.add(outline);
1379 jMenu1.add(displayNonconserved);
1383 * Constructs the entries for the colour menu
1385 protected void initColourMenu()
1387 colourMenu.setText(MessageManager.getString("label.group_colour"));
1388 textColour.setText(MessageManager.getString("label.text_colour"));
1389 textColour.addActionListener(new ActionListener()
1392 public void actionPerformed(ActionEvent e)
1394 textColour_actionPerformed();
1398 abovePIDColour.setText(
1399 MessageManager.getString("label.above_identity_threshold"));
1400 abovePIDColour.addActionListener(new ActionListener()
1403 public void actionPerformed(ActionEvent e)
1405 abovePIDColour_actionPerformed(abovePIDColour.isSelected());
1410 MessageManager.getString("label.modify_identity_threshold"));
1411 modifyPID.addActionListener(new ActionListener()
1414 public void actionPerformed(ActionEvent e)
1416 modifyPID_actionPerformed();
1420 conservationMenuItem
1421 .setText(MessageManager.getString("action.by_conservation"));
1422 conservationMenuItem.addActionListener(new ActionListener()
1425 public void actionPerformed(ActionEvent e)
1427 conservationMenuItem_actionPerformed(
1428 conservationMenuItem.isSelected());
1432 modifyConservation.setText(MessageManager
1433 .getString("label.modify_conservation_threshold"));
1434 modifyConservation.addActionListener(new ActionListener()
1437 public void actionPerformed(ActionEvent e)
1439 modifyConservation_actionPerformed();
1445 * Builds the group colour sub-menu, including any user-defined colours which
1446 * were loaded at startup or during the Jalview session
1448 protected void buildColourMenu()
1450 SequenceGroup sg = ap.av.getSelectionGroup();
1454 * popup menu with no sequence group scope
1458 colourMenu.removeAll();
1459 colourMenu.add(textColour);
1460 colourMenu.addSeparator();
1462 ColourMenuHelper.addMenuItems(colourMenu, this, sg, false);
1464 colourMenu.addSeparator();
1465 colourMenu.add(conservationMenuItem);
1466 colourMenu.add(modifyConservation);
1467 colourMenu.add(abovePIDColour);
1468 colourMenu.add(modifyPID);
1471 protected void modifyConservation_actionPerformed()
1473 SequenceGroup sg = getGroup();
1476 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1477 SliderPanel.showConservationSlider();
1481 protected void modifyPID_actionPerformed()
1483 SequenceGroup sg = getGroup();
1486 // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1488 // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1489 SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup().getName());
1490 SliderPanel.showPIDSlider();
1495 * Check for any annotations on the underlying dataset sequences (for the
1496 * current selection group) which are not 'on the alignment'.If any are found,
1497 * enable the option to add them to the alignment. The criteria for 'on the
1498 * alignment' is finding an alignment annotation on the alignment, matched on
1499 * calcId, label and sequenceRef.
1501 * A tooltip is also constructed that displays the source (calcId) and type
1502 * (label) of the annotations that can be added.
1505 * @param forSequences
1507 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1508 List<SequenceI> forSequences)
1510 menuItem.setEnabled(false);
1513 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1514 * Using TreeMap means calcIds are shown in alphabetical order.
1516 SortedMap<String, String> tipEntries = new TreeMap<>();
1517 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
1518 AlignmentI al = this.ap.av.getAlignment();
1519 AlignmentUtils.findAddableReferenceAnnotations(forSequences, tipEntries,
1521 if (!candidates.isEmpty())
1523 StringBuilder tooltip = new StringBuilder(64);
1524 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1527 * Found annotations that could be added. Enable the menu item, and
1528 * configure its tooltip and action.
1530 menuItem.setEnabled(true);
1531 for (String calcId : tipEntries.keySet())
1533 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1535 String tooltipText = JvSwingUtils.wrapTooltip(true,
1536 tooltip.toString());
1537 menuItem.setToolTipText(tooltipText);
1539 menuItem.addActionListener(new ActionListener()
1542 public void actionPerformed(ActionEvent e)
1544 addReferenceAnnotations_actionPerformed(candidates);
1551 * Add annotations to the sequences and to the alignment.
1554 * a map whose keys are sequences on the alignment, and values a list
1555 * of annotations to add to each sequence
1557 protected void addReferenceAnnotations_actionPerformed(
1558 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1560 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1561 final AlignmentI alignment = this.ap.getAlignment();
1562 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1567 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1569 if (!ap.av.getAlignment().hasSeqrep())
1571 // initialise the display flags so the user sees something happen
1572 ap.av.setDisplayReferenceSeq(true);
1573 ap.av.setColourByReferenceSeq(true);
1574 ap.av.getAlignment().setSeqrep(sequence);
1578 if (ap.av.getAlignment().getSeqrep() == sequence)
1580 ap.av.getAlignment().setSeqrep(null);
1584 ap.av.getAlignment().setSeqrep(sequence);
1590 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1592 HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
1593 BitSet inserts = new BitSet();
1595 boolean markedPopup = false;
1596 // mark inserts in current selection
1597 if (ap.av.getSelectionGroup() != null)
1599 // mark just the columns in the selection group to be hidden
1600 inserts.set(ap.av.getSelectionGroup().getStartRes(),
1601 ap.av.getSelectionGroup().getEndRes() + 1); // TODO why +1?
1603 // now clear columns without gaps
1604 for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
1610 inserts.and(sq.getInsertionsAsBits());
1612 hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
1613 ap.av.getSelectionGroup().getEndRes());
1616 // now mark for sequence under popup if we haven't already done it
1617 else if (!markedPopup && sequence != null)
1619 inserts.or(sequence.getInsertionsAsBits());
1621 // and set hidden columns accordingly
1622 hidden.hideColumns(inserts);
1627 protected void sequenceSelectionDetails_actionPerformed()
1629 createSequenceDetailsReport(ap.av.getSequenceSelection());
1632 protected void sequenceDetails_actionPerformed()
1634 createSequenceDetailsReport(new SequenceI[] { sequence });
1637 public void createSequenceDetailsReport(SequenceI[] sequences)
1639 StringBuilder contents = new StringBuilder(128);
1640 contents.append("<html><body>");
1641 for (SequenceI seq : sequences)
1643 contents.append("<p><h2>" + MessageManager.formatMessage(
1644 "label.create_sequence_details_report_annotation_for",
1646 { seq.getDisplayId(true) }) + "</h2></p><p>");
1647 new SequenceAnnotationReport(null).createSequenceAnnotationReport(
1648 contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr);
1649 contents.append("</p>");
1651 contents.append("</body></html>");
1652 String report = contents.toString();
1654 JInternalFrame frame;
1655 if (Platform.isJS())
1657 JLabel textLabel = new JLabel();
1658 textLabel.setText(report);
1659 textLabel.setBackground(Color.WHITE);
1660 JPanel pane = new JPanel(new BorderLayout());
1661 ((JPanel) pane).setOpaque(true);
1662 pane.setBackground(Color.WHITE);
1663 ((JPanel) pane).add(textLabel, BorderLayout.NORTH);
1664 frame = new JInternalFrame();
1665 frame.getContentPane().add(new JScrollPane(pane));
1669 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1670 cap.setText(report);
1674 Desktop.addInternalFrame(frame,
1675 MessageManager.formatMessage("label.sequence_details_for",
1676 (sequences.length == 1 ? new Object[]
1677 { sequences[0].getDisplayId(true) }
1680 .getString("label.selection") })),
1684 protected void showNonconserved_actionPerformed()
1686 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1691 * call to refresh view after settings change
1695 ap.updateAnnotation();
1696 // removed paintAlignment(true) here:
1697 // updateAnnotation calls paintAlignment already, so don't need to call
1700 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1704 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1705 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1715 public void abovePIDColour_actionPerformed(boolean selected)
1717 SequenceGroup sg = getGroup();
1725 sg.cs.setConsensus(AAFrequency.calculate(
1726 sg.getSequences(ap.av.getHiddenRepSequences()),
1727 sg.getStartRes(), sg.getEndRes() + 1));
1729 int threshold = SliderPanel.setPIDSliderSource(ap,
1730 sg.getGroupColourScheme(), getGroup().getName());
1732 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1734 SliderPanel.showPIDSlider();
1737 // remove PIDColouring
1739 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1740 SliderPanel.hidePIDSlider();
1742 modifyPID.setEnabled(selected);
1748 * Open a panel where the user can choose which types of sequence annotation
1753 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1755 // todo correct way to guard against opening a duplicate panel?
1756 new AnnotationChooser(ap);
1765 public void conservationMenuItem_actionPerformed(boolean selected)
1767 SequenceGroup sg = getGroup();
1775 // JBPNote: Conservation name shouldn't be i18n translated
1776 Conservation c = new Conservation("Group",
1777 sg.getSequences(ap.av.getHiddenRepSequences()),
1778 sg.getStartRes(), sg.getEndRes() + 1);
1781 c.verdict(false, ap.av.getConsPercGaps());
1782 sg.cs.setConservation(c);
1784 SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
1786 SliderPanel.showConservationSlider();
1789 // remove ConservationColouring
1791 sg.cs.setConservation(null);
1792 SliderPanel.hideConservationSlider();
1794 modifyConservation.setEnabled(selected);
1800 * Shows a dialog where group name and description may be edited
1802 protected void groupName_actionPerformed()
1804 SequenceGroup sg = getGroup();
1805 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1806 sg.getDescription(),
1807 MessageManager.getString("label.group_name"),
1808 MessageManager.getString("label.group_description"));
1809 dialog.showDialog(ap.alignFrame,
1810 MessageManager.getString("label.edit_group_name_description"),
1816 sg.setName(dialog.getName());
1817 sg.setDescription(dialog.getDescription());
1824 * Get selection group - adding it to the alignment if necessary.
1826 * @return sequence group to operate on
1828 SequenceGroup getGroup()
1830 SequenceGroup sg = ap.av.getSelectionGroup();
1831 // this method won't add a new group if it already exists
1834 ap.av.getAlignment().addGroup(sg);
1841 * Shows a dialog where sequence name and description may be edited
1843 void sequenceName_actionPerformed()
1845 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1846 sequence.getDescription(),
1847 MessageManager.getString("label.sequence_name"),
1848 MessageManager.getString("label.sequence_description"));
1849 dialog.showDialog(ap.alignFrame,
1850 MessageManager.getString(
1851 "label.edit_sequence_name_description"),
1857 if (dialog.getName() != null)
1859 if (dialog.getName().indexOf(" ") > -1)
1861 JvOptionPane.showMessageDialog(ap,
1862 MessageManager.getString(
1863 "label.spaces_converted_to_underscores"),
1864 MessageManager.getString(
1865 "label.no_spaces_allowed_sequence_name"),
1866 JvOptionPane.WARNING_MESSAGE);
1868 sequence.setName(dialog.getName().replace(' ', '_'));
1869 ap.paintAlignment(false, false);
1871 sequence.setDescription(dialog.getDescription());
1872 ap.av.firePropertyChange("alignment", null,
1873 ap.av.getAlignment().getSequences());
1884 void unGroupMenuItem_actionPerformed()
1886 SequenceGroup sg = ap.av.getSelectionGroup();
1887 ap.av.getAlignment().deleteGroup(sg);
1888 ap.av.setSelectionGroup(null);
1892 void createGroupMenuItem_actionPerformed()
1894 getGroup(); // implicitly creates group - note - should apply defaults / use
1895 // standard alignment window logic for this
1900 * Offers a colour chooser and sets the selected colour as the group outline
1902 protected void outline_actionPerformed()
1904 String title = MessageManager
1905 .getString("label.select_outline_colour");
1906 ColourChooserListener listener = new ColourChooserListener()
1909 public void colourSelected(Color c)
1911 getGroup().setOutlineColour(c);
1915 JalviewColourChooser.showColourChooser(Desktop.getDesktop(),
1916 title, Color.BLUE, listener);
1925 public void showBoxes_actionPerformed()
1927 getGroup().setDisplayBoxes(showBoxes.isSelected());
1937 public void showText_actionPerformed()
1939 getGroup().setDisplayText(showText.isSelected());
1949 public void showColourText_actionPerformed()
1951 getGroup().setColourText(showColourText.isSelected());
1955 public void showLink(String url)
1959 jalview.util.BrowserLauncher.openURL(url);
1960 } catch (Exception ex)
1962 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1963 MessageManager.getString("label.web_browser_not_found_unix"),
1964 MessageManager.getString("label.web_browser_not_found"),
1965 JvOptionPane.WARNING_MESSAGE);
1967 ex.printStackTrace();
1971 void hideSequences(boolean representGroup)
1973 ap.av.hideSequences(sequence, representGroup);
1976 public void copy_actionPerformed()
1978 ap.alignFrame.copy_actionPerformed(null);
1981 public void cut_actionPerformed()
1983 ap.alignFrame.cut_actionPerformed(null);
1986 void changeCase(ActionEvent e)
1988 Object source = e.getSource();
1989 SequenceGroup sg = ap.av.getSelectionGroup();
1993 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
1994 sg.getStartRes(), sg.getEndRes() + 1);
1999 if (source == toggle)
2001 description = MessageManager.getString("label.toggle_case");
2002 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2004 else if (source == upperCase)
2006 description = MessageManager.getString("label.to_upper_case");
2007 caseChange = ChangeCaseCommand.TO_UPPER;
2011 description = MessageManager.getString("label.to_lower_case");
2012 caseChange = ChangeCaseCommand.TO_LOWER;
2015 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2016 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2017 startEnd, caseChange);
2019 ap.alignFrame.addHistoryItem(caseCommand);
2021 ap.av.firePropertyChange("alignment", null,
2022 ap.av.getAlignment().getSequences());
2027 public void outputText_actionPerformed(ActionEvent e)
2029 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2030 cap.setForInput(null);
2031 Desktop.addInternalFrame(cap, MessageManager
2032 .formatMessage("label.alignment_output_command", new Object[]
2033 { e.getActionCommand() }), 600, 500);
2035 String[] omitHidden = null;
2037 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2038 // or we simply trust the user wants
2039 // wysiwig behaviour
2041 FileFormatI fileFormat = FileFormats.getInstance()
2042 .forName(e.getActionCommand());
2044 new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2047 public void sequenceFeature_actionPerformed()
2049 SequenceGroup sg = ap.av.getSelectionGroup();
2055 List<SequenceI> seqs = new ArrayList<>();
2056 List<SequenceFeature> features = new ArrayList<>();
2059 * assemble dataset sequences, and template new sequence features,
2060 * for the amend features dialog
2062 int gSize = sg.getSize();
2063 for (int i = 0; i < gSize; i++)
2065 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2066 int end = sg.findEndRes(sg.getSequenceAt(i));
2069 seqs.add(sg.getSequenceAt(i).getDatasetSequence());
2070 features.add(new SequenceFeature(null, null, start, end, null));
2075 * an entirely gapped region will generate empty lists of sequence / features
2077 if (!seqs.isEmpty())
2079 new FeatureEditor(ap, seqs, features, true).showDialog();
2083 public void textColour_actionPerformed()
2085 SequenceGroup sg = getGroup();
2088 new TextColourChooser().chooseColour(ap, sg);
2092 public void colourByStructure(String pdbid)
2094 Annotation[] anots = ap.av.getStructureSelectionManager()
2095 .colourSequenceFromStructure(sequence, pdbid);
2097 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2098 "Coloured by " + pdbid, anots);
2100 ap.av.getAlignment().addAnnotation(an);
2101 an.createSequenceMapping(sequence, 0, true);
2102 // an.adjustForAlignment();
2103 ap.av.getAlignment().setAnnotationIndex(an, 0);
2105 ap.adjustAnnotationHeight();
2107 sequence.addAlignmentAnnotation(an);
2112 * Shows a dialog where sequence characters may be edited. Any changes are
2113 * applied, and added as an available 'Undo' item in the edit commands
2116 public void editSequence_actionPerformed()
2118 SequenceGroup sg = ap.av.getSelectionGroup();
2122 if (sequence == null)
2124 sequence = sg.getSequenceAt(0);
2127 EditNameDialog dialog = new EditNameDialog(
2128 sequence.getSequenceAsString(sg.getStartRes(),
2129 sg.getEndRes() + 1),
2130 null, MessageManager.getString("label.edit_sequence"), null);
2131 dialog.showDialog(ap.alignFrame,
2132 MessageManager.getString("label.edit_sequence"),
2138 EditCommand editCommand = new EditCommand(
2139 MessageManager.getString("label.edit_sequences"),
2141 dialog.getName().replace(' ',
2142 ap.av.getGapCharacter()),
2143 sg.getSequencesAsArray(
2144 ap.av.getHiddenRepSequences()),
2145 sg.getStartRes(), sg.getEndRes() + 1,
2146 ap.av.getAlignment());
2147 ap.alignFrame.addHistoryItem(editCommand);
2148 ap.av.firePropertyChange("alignment", null,
2149 ap.av.getAlignment().getSequences());
2156 * Action on user selecting an item from the colour menu (that does not have
2157 * its bespoke action handler)
2162 public void changeColour_actionPerformed(String colourSchemeName)
2164 SequenceGroup sg = getGroup();
2166 * switch to the chosen colour scheme (or null for None)
2168 ColourSchemeI colourScheme = ColourSchemes.getInstance()
2169 .getColourScheme(colourSchemeName, sg,
2170 ap.av.getHiddenRepSequences());
2171 sg.setColourScheme(colourScheme);
2172 if (colourScheme instanceof Blosum62ColourScheme
2173 || colourScheme instanceof PIDColourScheme)
2175 sg.cs.setConsensus(AAFrequency.calculate(
2176 sg.getSequences(ap.av.getHiddenRepSequences()),
2177 sg.getStartRes(), sg.getEndRes() + 1));