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.ColumnSelection;
35 import jalview.datamodel.DBRefEntry;
36 import jalview.datamodel.PDBEntry;
37 import jalview.datamodel.Sequence;
38 import jalview.datamodel.SequenceFeature;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.io.FormatAdapter;
42 import jalview.io.SequenceAnnotationReport;
43 import jalview.schemes.AnnotationColourGradient;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.BuriedColourScheme;
46 import jalview.schemes.ClustalxColourScheme;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.HydrophobicColourScheme;
49 import jalview.schemes.NucleotideColourScheme;
50 import jalview.schemes.PIDColourScheme;
51 import jalview.schemes.PurinePyrimidineColourScheme;
52 import jalview.schemes.StrandColourScheme;
53 import jalview.schemes.TaylorColourScheme;
54 import jalview.schemes.TurnColourScheme;
55 import jalview.schemes.UserColourScheme;
56 import jalview.schemes.ZappoColourScheme;
57 import jalview.util.GroupUrlLink;
58 import jalview.util.GroupUrlLink.UrlStringTooLongException;
59 import jalview.util.MessageManager;
60 import jalview.util.UrlLink;
62 import java.awt.Color;
63 import java.awt.event.ActionEvent;
64 import java.awt.event.ActionListener;
65 import java.util.Arrays;
66 import java.util.Collection;
67 import java.util.Collections;
68 import java.util.Hashtable;
69 import java.util.LinkedHashMap;
70 import java.util.List;
72 import java.util.TreeMap;
73 import java.util.Vector;
75 import javax.swing.ButtonGroup;
76 import javax.swing.JCheckBoxMenuItem;
77 import javax.swing.JColorChooser;
78 import javax.swing.JMenu;
79 import javax.swing.JMenuItem;
80 import javax.swing.JOptionPane;
81 import javax.swing.JPopupMenu;
82 import javax.swing.JRadioButtonMenuItem;
88 * @version $Revision: 1.118 $
90 public class PopupMenu extends JPopupMenu
92 JMenu groupMenu = new JMenu();
94 JMenuItem groupName = new JMenuItem();
96 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
98 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
100 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
102 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
104 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
106 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
108 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
110 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
112 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
114 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
116 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
118 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
120 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
122 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
124 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
126 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
130 JMenu sequenceMenu = new JMenu();
132 JMenuItem sequenceName = new JMenuItem();
134 JMenuItem sequenceDetails = new JMenuItem();
136 JMenuItem sequenceSelDetails = new JMenuItem();
138 JMenuItem makeReferenceSeq = new JMenuItem();
140 JMenuItem chooseAnnotations = new JMenuItem();
144 JMenuItem createGroupMenuItem = new JMenuItem();
146 JMenuItem unGroupMenuItem = new JMenuItem();
148 JMenuItem outline = new JMenuItem();
150 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
152 JMenu colourMenu = new JMenu();
154 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
156 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
158 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
160 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
162 JMenu editMenu = new JMenu();
164 JMenuItem cut = new JMenuItem();
166 JMenuItem copy = new JMenuItem();
168 JMenuItem upperCase = new JMenuItem();
170 JMenuItem lowerCase = new JMenuItem();
172 JMenuItem toggle = new JMenuItem();
174 JMenu pdbMenu = new JMenu();
176 JMenu outputMenu = new JMenu();
178 JMenu seqShowAnnotationsMenu = new JMenu();
180 JMenu seqHideAnnotationsMenu = new JMenu();
182 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
183 MessageManager.getString("label.add_reference_annotations"));
185 JMenu groupShowAnnotationsMenu = new JMenu();
187 JMenu groupHideAnnotationsMenu = new JMenu();
189 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
190 MessageManager.getString("label.add_reference_annotations"));
192 JMenuItem sequenceFeature = new JMenuItem();
194 JMenuItem textColour = new JMenuItem();
196 JMenu jMenu1 = new JMenu();
198 JMenuItem pdbStructureDialog = new JMenuItem();
200 JMenu rnaStructureMenu = new JMenu();
202 JMenuItem editSequence = new JMenuItem();
204 JMenu groupLinksMenu;
206 JMenuItem hideInsertions = new JMenuItem();
209 * Creates a new PopupMenu object.
216 public PopupMenu(final AlignmentPanel ap, Sequence seq, List<String> links)
218 this(ap, seq, links, null);
228 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
229 List<String> links, List<String> groupLinks)
231 // /////////////////////////////////////////////////////////
232 // If this is activated from the sequence panel, the user may want to
233 // edit or annotate a particular residue. Therefore display the residue menu
235 // If from the IDPanel, we must display the sequence menu
236 // ////////////////////////////////////////////////////////
240 ButtonGroup colours = new ButtonGroup();
241 colours.add(noColourmenuItem);
242 colours.add(clustalColour);
243 colours.add(zappoColour);
244 colours.add(taylorColour);
245 colours.add(hydrophobicityColour);
246 colours.add(helixColour);
247 colours.add(strandColour);
248 colours.add(turnColour);
249 colours.add(buriedColour);
250 colours.add(abovePIDColour);
251 colours.add(userDefinedColour);
252 colours.add(PIDColour);
253 colours.add(BLOSUM62Colour);
254 colours.add(purinePyrimidineColour);
255 colours.add(RNAInteractionColour);
257 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
259 JMenuItem item = new JMenuItem(
260 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
262 item.addActionListener(new java.awt.event.ActionListener()
265 public void actionPerformed(ActionEvent e)
267 outputText_actionPerformed(e);
271 outputMenu.add(item);
275 * Build menus for annotation types that may be shown or hidden, and for
276 * 'reference annotations' that may be added to the alignment. First for the
277 * currently selected sequence (if there is one):
279 final List<SequenceI> selectedSequence = (seq == null ? Collections
280 .<SequenceI> emptyList() : Arrays.asList(seq));
281 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
282 seqHideAnnotationsMenu, selectedSequence);
283 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
287 * And repeat for the current selection group (if there is one):
289 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
290 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
292 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
293 groupHideAnnotationsMenu, selectedGroup);
294 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
300 } catch (Exception e)
308 sequenceMenu.setText(sequence.getName());
309 if (seq == ap.av.getAlignment().getSeqrep())
311 makeReferenceSeq.setText(MessageManager
312 .getString("action.unmark_as_reference"));
316 makeReferenceSeq.setText(MessageManager
317 .getString("action.set_as_reference"));
320 if (!ap.av.getAlignment().isNucleotide())
322 remove(rnaStructureMenu);
326 int origCount = rnaStructureMenu.getItemCount();
328 * add menu items to 2D-render any alignment or sequence secondary
329 * structure annotation
331 AlignmentAnnotation[] aas = ap.av.getAlignment()
332 .getAlignmentAnnotation();
335 for (final AlignmentAnnotation aa : aas)
337 if (aa.isValidStruc() && aa.sequenceRef == null)
340 * valid alignment RNA secondary structure annotation
342 menuItem = new JMenuItem();
343 menuItem.setText(MessageManager.formatMessage(
344 "label.2d_rna_structure_line",
345 new Object[] { aa.label }));
346 menuItem.addActionListener(new java.awt.event.ActionListener()
349 public void actionPerformed(ActionEvent e)
351 new AppVarna(seq, aa, ap);
354 rnaStructureMenu.add(menuItem);
359 if (seq.getAnnotation() != null)
361 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
362 for (final AlignmentAnnotation aa : seqAnns)
364 if (aa.isValidStruc())
367 * valid sequence RNA secondary structure annotation
369 // TODO: make rnastrucF a bit more nice
370 menuItem = new JMenuItem();
371 menuItem.setText(MessageManager.formatMessage(
372 "label.2d_rna_sequence_name",
373 new Object[] { seq.getName() }));
374 menuItem.addActionListener(new java.awt.event.ActionListener()
377 public void actionPerformed(ActionEvent e)
379 // TODO: VARNA does'nt print gaps in the sequence
380 new AppVarna(seq, aa, ap);
383 rnaStructureMenu.add(menuItem);
387 if (rnaStructureMenu.getItemCount() == origCount)
389 remove(rnaStructureMenu);
393 menuItem = new JMenuItem(
394 MessageManager.getString("action.hide_sequences"));
395 menuItem.addActionListener(new java.awt.event.ActionListener()
398 public void actionPerformed(ActionEvent e)
400 hideSequences(false);
405 if (ap.av.getSelectionGroup() != null
406 && ap.av.getSelectionGroup().getSize() > 1)
408 menuItem = new JMenuItem(MessageManager.formatMessage(
409 "label.represent_group_with",
410 new Object[] { seq.getName() }));
411 menuItem.addActionListener(new java.awt.event.ActionListener()
414 public void actionPerformed(ActionEvent e)
419 sequenceMenu.add(menuItem);
422 if (ap.av.hasHiddenRows())
424 final int index = ap.av.getAlignment().findIndex(seq);
426 if (ap.av.adjustForHiddenSeqs(index)
427 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
429 menuItem = new JMenuItem(
430 MessageManager.getString("action.reveal_sequences"));
431 menuItem.addActionListener(new ActionListener()
434 public void actionPerformed(ActionEvent e)
436 ap.av.showSequence(index);
437 if (ap.overviewPanel != null)
439 ap.overviewPanel.updateOverviewImage();
447 // for the case when no sequences are even visible
448 if (ap.av.hasHiddenRows())
451 menuItem = new JMenuItem(
452 MessageManager.getString("action.reveal_all"));
453 menuItem.addActionListener(new ActionListener()
456 public void actionPerformed(ActionEvent e)
458 ap.av.showAllHiddenSeqs();
459 if (ap.overviewPanel != null)
461 ap.overviewPanel.updateOverviewImage();
471 SequenceGroup sg = ap.av.getSelectionGroup();
472 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
473 .getGroups().contains(sg) : false;
475 if (sg != null && sg.getSize() > 0)
477 groupName.setText(MessageManager
478 .getString("label.edit_name_and_description_current_group"));
480 if (sg.cs instanceof ZappoColourScheme)
482 zappoColour.setSelected(true);
484 else if (sg.cs instanceof TaylorColourScheme)
486 taylorColour.setSelected(true);
488 else if (sg.cs instanceof PIDColourScheme)
490 PIDColour.setSelected(true);
492 else if (sg.cs instanceof Blosum62ColourScheme)
494 BLOSUM62Colour.setSelected(true);
496 else if (sg.cs instanceof UserColourScheme)
498 userDefinedColour.setSelected(true);
500 else if (sg.cs instanceof HydrophobicColourScheme)
502 hydrophobicityColour.setSelected(true);
504 else if (sg.cs instanceof HelixColourScheme)
506 helixColour.setSelected(true);
508 else if (sg.cs instanceof StrandColourScheme)
510 strandColour.setSelected(true);
512 else if (sg.cs instanceof TurnColourScheme)
514 turnColour.setSelected(true);
516 else if (sg.cs instanceof BuriedColourScheme)
518 buriedColour.setSelected(true);
520 else if (sg.cs instanceof ClustalxColourScheme)
522 clustalColour.setSelected(true);
524 else if (sg.cs instanceof PurinePyrimidineColourScheme)
526 purinePyrimidineColour.setSelected(true);
530 * else if (sg.cs instanceof CovariationColourScheme) {
531 * covariationColour.setSelected(true); }
535 noColourmenuItem.setSelected(true);
538 if (sg.cs != null && sg.cs.conservationApplied())
540 conservationMenuItem.setSelected(true);
542 displayNonconserved.setSelected(sg.getShowNonconserved());
543 showText.setSelected(sg.getDisplayText());
544 showColourText.setSelected(sg.getColourText());
545 showBoxes.setSelected(sg.getDisplayBoxes());
546 // add any groupURLs to the groupURL submenu and make it visible
547 if (groupLinks != null && groupLinks.size() > 0)
549 buildGroupURLMenu(sg, groupLinks);
551 // Add a 'show all structures' for the current selection
552 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
553 SequenceI sqass = null;
554 for (SequenceI sq : ap.av.getSequenceSelection())
556 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
557 if (pes != null && pes.size() > 0)
559 reppdb.put(pes.get(0).getId(), pes.get(0));
560 for (PDBEntry pe : pes)
562 pdbe.put(pe.getId(), pe);
572 final PDBEntry[] pe = pdbe.values().toArray(
573 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
574 new PDBEntry[reppdb.size()]);
575 final JMenuItem gpdbview, rpdbview;
580 groupMenu.setVisible(false);
581 editMenu.setVisible(false);
586 createGroupMenuItem.setVisible(true);
587 unGroupMenuItem.setVisible(false);
588 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
592 createGroupMenuItem.setVisible(false);
593 unGroupMenuItem.setVisible(true);
594 jMenu1.setText(MessageManager.getString("action.edit_group"));
599 sequenceMenu.setVisible(false);
600 pdbStructureDialog.setVisible(false);
601 rnaStructureMenu.setVisible(false);
604 if (links != null && links.size() > 0)
606 addFeatureLinks(seq, links);
611 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
616 void addFeatureLinks(final SequenceI seq, List<String> links)
618 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
619 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
621 for (String link : links)
623 UrlLink urlLink = null;
626 urlLink = new UrlLink(link);
627 } catch (Exception foo)
629 Cache.log.error("Exception for URLLink '" + link + "'", foo);
633 if (!urlLink.isValid())
635 Cache.log.error(urlLink.getInvalidMessage());
639 urlLink.createLinksFromSeq(seq, linkset);
642 addshowLinks(linkMenu, linkset.values());
644 if (sequence != null)
646 sequenceMenu.add(linkMenu);
657 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
658 * "All" is added first, followed by a separator. Then add any annotation
659 * types associated with the current selection. Separate menus are built for
660 * the selected sequence group (if any), and the selected sequence.
662 * Some annotation rows are always rendered together - these can be identified
663 * by a common graphGroup property > -1. Only one of each group will be marked
664 * as visible (to avoid duplication of the display). For such groups we add a
665 * composite type name, e.g.
667 * IUPredWS (Long), IUPredWS (Short)
671 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
672 List<SequenceI> forSequences)
674 showMenu.removeAll();
675 hideMenu.removeAll();
677 final List<String> all = Arrays.asList(new String[] { MessageManager
678 .getString("label.all") });
679 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
680 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
682 showMenu.addSeparator();
683 hideMenu.addSeparator();
685 final AlignmentAnnotation[] annotations = ap.getAlignment()
686 .getAlignmentAnnotation();
689 * Find shown/hidden annotations types, distinguished by source (calcId),
690 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
691 * the insertion order, which is the order of the annotations on the
694 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
695 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
696 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
697 AlignmentAnnotationUtils.asList(annotations), forSequences);
699 for (String calcId : hiddenTypes.keySet())
701 for (List<String> type : hiddenTypes.get(calcId))
703 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
707 // grey out 'show annotations' if none are hidden
708 showMenu.setEnabled(!hiddenTypes.isEmpty());
710 for (String calcId : shownTypes.keySet())
712 for (List<String> type : shownTypes.get(calcId))
714 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
718 // grey out 'hide annotations' if none are shown
719 hideMenu.setEnabled(!shownTypes.isEmpty());
723 * Returns a list of sequences - either the current selection group (if there
724 * is one), else the specified single sequence.
729 protected List<SequenceI> getSequenceScope(SequenceI seq)
731 List<SequenceI> forSequences = null;
732 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
733 if (selectionGroup != null && selectionGroup.getSize() > 0)
735 forSequences = selectionGroup.getSequences();
739 forSequences = seq == null ? Collections.<SequenceI> emptyList()
740 : Arrays.asList(seq);
746 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
749 * @param showOrHideMenu
751 * @param forSequences
752 * the sequences whose annotations may be shown or hidden
757 * if true this is a special label meaning 'All'
758 * @param actionIsShow
759 * if true, the select menu item action is to show the annotation
762 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
763 final List<SequenceI> forSequences, String calcId,
764 final List<String> types, final boolean allTypes,
765 final boolean actionIsShow)
767 String label = types.toString(); // [a, b, c]
768 label = label.substring(1, label.length() - 1); // a, b, c
769 final JMenuItem item = new JMenuItem(label);
770 item.setToolTipText(calcId);
771 item.addActionListener(new java.awt.event.ActionListener()
774 public void actionPerformed(ActionEvent e)
776 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
777 types, forSequences, allTypes, actionIsShow);
781 showOrHideMenu.add(item);
784 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
787 // TODO: usability: thread off the generation of group url content so root
789 // sequence only URLs
790 // ID/regex match URLs
791 groupLinksMenu = new JMenu(
792 MessageManager.getString("action.group_link"));
793 // three types of url that might be created.
794 JMenu[] linkMenus = new JMenu[] { null,
795 new JMenu(MessageManager.getString("action.ids")),
796 new JMenu(MessageManager.getString("action.sequences")),
797 new JMenu(MessageManager.getString("action.ids_sequences")) };
799 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
800 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
801 Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
802 for (int sq = 0; sq < seqs.length; sq++)
805 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
806 .findPosition(sg.getEndRes());
807 // just collect ids from dataset sequence
808 // TODO: check if IDs collected from selecton group intersects with the
809 // current selection, too
810 SequenceI sqi = seqs[sq];
811 while (sqi.getDatasetSequence() != null)
813 sqi = sqi.getDatasetSequence();
815 DBRefEntry[] dbr = sqi.getDBRefs();
816 if (dbr != null && dbr.length > 0)
818 for (int d = 0; d < dbr.length; d++)
820 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
821 Object[] sarray = commonDbrefs.get(src);
824 sarray = new Object[2];
825 sarray[0] = new int[] { 0 };
826 sarray[1] = new String[seqs.length];
828 commonDbrefs.put(src, sarray);
831 if (((String[]) sarray[1])[sq] == null)
834 || (dbr[d].getMap().locateMappedRange(start, end) != null))
836 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
837 ((int[]) sarray[0])[0]++;
843 // now create group links for all distinct ID/sequence sets.
844 boolean addMenu = false; // indicates if there are any group links to give
846 for (String link : groupLinks)
848 GroupUrlLink urlLink = null;
851 urlLink = new GroupUrlLink(link);
852 } catch (Exception foo)
854 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
858 if (!urlLink.isValid())
860 Cache.log.error(urlLink.getInvalidMessage());
863 final String label = urlLink.getLabel();
864 boolean usingNames = false;
865 // Now see which parts of the group apply for this URL
866 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
867 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
868 String[] seqstr, ids; // input to makeUrl
871 int numinput = ((int[]) idset[0])[0];
872 String[] allids = ((String[]) idset[1]);
873 seqstr = new String[numinput];
874 ids = new String[numinput];
875 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
877 if (allids[sq] != null)
879 ids[idcount] = allids[sq];
880 seqstr[idcount++] = idandseqs[1][sq];
886 // just use the id/seq set
887 seqstr = idandseqs[1];
891 // and try and make the groupURL!
893 Object[] urlset = null;
896 urlset = urlLink.makeUrlStubs(ids, seqstr,
897 "FromJalview" + System.currentTimeMillis(), false);
898 } catch (UrlStringTooLongException e)
903 int type = urlLink.getGroupURLType() & 3;
904 // first two bits ofurlLink type bitfield are sequenceids and sequences
905 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
906 addshowLink(linkMenus[type], label
907 + (((type & 1) == 1) ? ("("
908 + (usingNames ? "Names" : ltarget) + ")") : ""),
915 groupLinksMenu = new JMenu(
916 MessageManager.getString("action.group_link"));
917 for (int m = 0; m < linkMenus.length; m++)
919 if (linkMenus[m] != null
920 && linkMenus[m].getMenuComponentCount() > 0)
922 groupLinksMenu.add(linkMenus[m]);
926 groupMenu.add(groupLinksMenu);
930 private void addshowLinks(JMenu linkMenu, Collection<List<String>> linkset)
932 for (List<String> linkstrset : linkset)
934 // split linkstr into label and url
935 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
940 * add a show URL menu item to the given linkMenu
944 * - menu label string
948 private void addshowLink(JMenu linkMenu, String label, final String url)
950 JMenuItem item = new JMenuItem(label);
951 item.setToolTipText(MessageManager.formatMessage(
952 "label.open_url_param", new Object[] { url }));
953 item.addActionListener(new java.awt.event.ActionListener()
956 public void actionPerformed(ActionEvent e)
958 new Thread(new Runnable()
975 * add a late bound groupURL item to the given linkMenu
979 * - menu label string
980 * @param urlgenerator
981 * GroupURLLink used to generate URL
983 * Object array returned from the makeUrlStubs function.
985 private void addshowLink(JMenu linkMenu, String label,
986 final GroupUrlLink urlgenerator, final Object[] urlstub)
988 JMenuItem item = new JMenuItem(label);
989 item.setToolTipText(MessageManager.formatMessage(
990 "label.open_url_seqs_param",
991 new Object[] { urlgenerator.getUrl_prefix(),
992 urlgenerator.getNumberInvolved(urlstub) }));
993 // TODO: put in info about what is being sent.
994 item.addActionListener(new ActionListener()
997 public void actionPerformed(ActionEvent e)
999 new Thread(new Runnable()
1007 showLink(urlgenerator.constructFrom(urlstub));
1008 } catch (UrlStringTooLongException e2)
1026 private void jbInit() throws Exception
1028 groupMenu.setText(MessageManager.getString("label.selection"));
1029 groupName.setText(MessageManager.getString("label.name"));
1030 groupName.addActionListener(new java.awt.event.ActionListener()
1033 public void actionPerformed(ActionEvent e)
1035 groupName_actionPerformed();
1038 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1039 sequenceName.setText(MessageManager
1040 .getString("label.edit_name_description"));
1041 sequenceName.addActionListener(new java.awt.event.ActionListener()
1044 public void actionPerformed(ActionEvent e)
1046 sequenceName_actionPerformed();
1049 chooseAnnotations.setText(MessageManager
1050 .getString("action.choose_annotations"));
1051 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1054 public void actionPerformed(ActionEvent e)
1056 chooseAnnotations_actionPerformed(e);
1059 sequenceDetails.setText(MessageManager
1060 .getString("label.sequence_details"));
1061 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1064 public void actionPerformed(ActionEvent e)
1066 sequenceDetails_actionPerformed();
1069 sequenceSelDetails.setText(MessageManager
1070 .getString("label.sequence_details"));
1072 .addActionListener(new java.awt.event.ActionListener()
1075 public void actionPerformed(ActionEvent e)
1077 sequenceSelectionDetails_actionPerformed();
1080 PIDColour.setFocusPainted(false);
1082 .setText(MessageManager.getString("action.remove_group"));
1083 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1086 public void actionPerformed(ActionEvent e)
1088 unGroupMenuItem_actionPerformed();
1091 createGroupMenuItem.setText(MessageManager
1092 .getString("action.create_group"));
1094 .addActionListener(new java.awt.event.ActionListener()
1097 public void actionPerformed(ActionEvent e)
1099 createGroupMenuItem_actionPerformed();
1103 outline.setText(MessageManager.getString("action.border_colour"));
1104 outline.addActionListener(new java.awt.event.ActionListener()
1107 public void actionPerformed(ActionEvent e)
1109 outline_actionPerformed();
1113 .setText(MessageManager.getString("label.nucleotide"));
1114 nucleotideMenuItem.addActionListener(new ActionListener()
1117 public void actionPerformed(ActionEvent e)
1119 nucleotideMenuItem_actionPerformed();
1122 colourMenu.setText(MessageManager.getString("label.group_colour"));
1123 showBoxes.setText(MessageManager.getString("action.boxes"));
1124 showBoxes.setState(true);
1125 showBoxes.addActionListener(new ActionListener()
1128 public void actionPerformed(ActionEvent e)
1130 showBoxes_actionPerformed();
1133 showText.setText(MessageManager.getString("action.text"));
1134 showText.setState(true);
1135 showText.addActionListener(new ActionListener()
1138 public void actionPerformed(ActionEvent e)
1140 showText_actionPerformed();
1143 showColourText.setText(MessageManager.getString("label.colour_text"));
1144 showColourText.addActionListener(new ActionListener()
1147 public void actionPerformed(ActionEvent e)
1149 showColourText_actionPerformed();
1152 displayNonconserved.setText(MessageManager
1153 .getString("label.show_non_conversed"));
1154 displayNonconserved.setState(true);
1155 displayNonconserved.addActionListener(new ActionListener()
1158 public void actionPerformed(ActionEvent e)
1160 showNonconserved_actionPerformed();
1163 editMenu.setText(MessageManager.getString("action.edit"));
1164 cut.setText(MessageManager.getString("action.cut"));
1165 cut.addActionListener(new ActionListener()
1168 public void actionPerformed(ActionEvent e)
1170 cut_actionPerformed();
1173 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1174 upperCase.addActionListener(new ActionListener()
1177 public void actionPerformed(ActionEvent e)
1182 copy.setText(MessageManager.getString("action.copy"));
1183 copy.addActionListener(new ActionListener()
1186 public void actionPerformed(ActionEvent e)
1188 copy_actionPerformed();
1191 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1192 lowerCase.addActionListener(new ActionListener()
1195 public void actionPerformed(ActionEvent e)
1200 toggle.setText(MessageManager.getString("label.toggle_case"));
1201 toggle.addActionListener(new ActionListener()
1204 public void actionPerformed(ActionEvent e)
1209 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1211 seqShowAnnotationsMenu.setText(MessageManager
1212 .getString("label.show_annotations"));
1213 seqHideAnnotationsMenu.setText(MessageManager
1214 .getString("label.hide_annotations"));
1215 groupShowAnnotationsMenu.setText(MessageManager
1216 .getString("label.show_annotations"));
1217 groupHideAnnotationsMenu.setText(MessageManager
1218 .getString("label.hide_annotations"));
1219 sequenceFeature.setText(MessageManager
1220 .getString("label.create_sequence_feature"));
1221 sequenceFeature.addActionListener(new ActionListener()
1224 public void actionPerformed(ActionEvent e)
1226 sequenceFeature_actionPerformed();
1229 textColour.setText(MessageManager.getString("label.text_colour"));
1230 textColour.addActionListener(new ActionListener()
1233 public void actionPerformed(ActionEvent e)
1235 textColour_actionPerformed();
1238 jMenu1.setText(MessageManager.getString("label.group"));
1239 pdbStructureDialog.setText(MessageManager
1240 .getString("label.show_pdbstruct_dialog"));
1241 pdbStructureDialog.addActionListener(new ActionListener()
1244 public void actionPerformed(ActionEvent actionEvent)
1246 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1247 if (ap.av.getSelectionGroup() != null)
1249 selectedSeqs = ap.av.getSequenceSelection();
1251 new StructureChooser(selectedSeqs, sequence, ap);
1255 rnaStructureMenu.setText(MessageManager
1256 .getString("label.view_rna_structure"));
1258 // colStructureMenu.setText("Colour By Structure");
1259 editSequence.setText(MessageManager.getString("label.edit_sequence")
1261 editSequence.addActionListener(new ActionListener()
1264 public void actionPerformed(ActionEvent actionEvent)
1266 editSequence_actionPerformed(actionEvent);
1269 makeReferenceSeq.setText(MessageManager
1270 .getString("label.mark_as_representative"));
1271 makeReferenceSeq.addActionListener(new ActionListener()
1275 public void actionPerformed(ActionEvent actionEvent)
1277 makeReferenceSeq_actionPerformed(actionEvent);
1281 hideInsertions.setText(MessageManager
1282 .getString("label.hide_insertions"));
1283 hideInsertions.addActionListener(new ActionListener()
1287 public void actionPerformed(ActionEvent e)
1289 hideInsertions_actionPerformed(e);
1293 * annotationMenuItem.setText("By Annotation");
1294 * annotationMenuItem.addActionListener(new ActionListener() { public void
1295 * actionPerformed(ActionEvent actionEvent) {
1296 * annotationMenuItem_actionPerformed(actionEvent); } });
1298 groupMenu.add(sequenceSelDetails);
1301 add(rnaStructureMenu);
1302 add(pdbStructureDialog);
1303 if (sequence != null)
1305 add(hideInsertions);
1307 // annotations configuration panel suppressed for now
1308 // groupMenu.add(chooseAnnotations);
1311 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1312 * (if a selection group is in force).
1314 sequenceMenu.add(seqShowAnnotationsMenu);
1315 sequenceMenu.add(seqHideAnnotationsMenu);
1316 sequenceMenu.add(seqAddReferenceAnnotations);
1317 groupMenu.add(groupShowAnnotationsMenu);
1318 groupMenu.add(groupHideAnnotationsMenu);
1319 groupMenu.add(groupAddReferenceAnnotations);
1320 groupMenu.add(editMenu);
1321 groupMenu.add(outputMenu);
1322 groupMenu.add(sequenceFeature);
1323 groupMenu.add(createGroupMenuItem);
1324 groupMenu.add(unGroupMenuItem);
1325 groupMenu.add(jMenu1);
1326 sequenceMenu.add(sequenceName);
1327 sequenceMenu.add(sequenceDetails);
1328 sequenceMenu.add(makeReferenceSeq);
1329 colourMenu.add(textColour);
1330 colourMenu.add(noColourmenuItem);
1331 colourMenu.add(clustalColour);
1332 colourMenu.add(BLOSUM62Colour);
1333 colourMenu.add(PIDColour);
1334 colourMenu.add(zappoColour);
1335 colourMenu.add(taylorColour);
1336 colourMenu.add(hydrophobicityColour);
1337 colourMenu.add(helixColour);
1338 colourMenu.add(strandColour);
1339 colourMenu.add(turnColour);
1340 colourMenu.add(buriedColour);
1341 colourMenu.add(nucleotideMenuItem);
1342 if (ap.getAlignment().isNucleotide())
1344 // JBPNote - commented since the colourscheme isn't functional
1345 colourMenu.add(purinePyrimidineColour);
1347 colourMenu.add(userDefinedColour);
1349 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1351 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1352 .getUserColourSchemes().keys();
1354 while (userColours.hasMoreElements())
1356 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1357 item.addActionListener(new ActionListener()
1360 public void actionPerformed(ActionEvent evt)
1362 userDefinedColour_actionPerformed(evt);
1365 colourMenu.add(item);
1369 colourMenu.addSeparator();
1370 colourMenu.add(abovePIDColour);
1371 colourMenu.add(conservationMenuItem);
1374 editMenu.add(editSequence);
1375 editMenu.add(upperCase);
1376 editMenu.add(lowerCase);
1377 editMenu.add(toggle);
1378 // JBPNote: These shouldn't be added here - should appear in a generic
1379 // 'apply web service to this sequence menu'
1380 // pdbMenu.add(RNAFold);
1381 // pdbMenu.add(ContraFold);
1382 jMenu1.add(groupName);
1383 jMenu1.add(colourMenu);
1384 jMenu1.add(showBoxes);
1385 jMenu1.add(showText);
1386 jMenu1.add(showColourText);
1387 jMenu1.add(outline);
1388 jMenu1.add(displayNonconserved);
1389 noColourmenuItem.setText(MessageManager.getString("label.none"));
1390 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1393 public void actionPerformed(ActionEvent e)
1395 noColourmenuItem_actionPerformed();
1399 clustalColour.setText(MessageManager
1400 .getString("label.clustalx_colours"));
1401 clustalColour.addActionListener(new java.awt.event.ActionListener()
1404 public void actionPerformed(ActionEvent e)
1406 clustalColour_actionPerformed();
1409 zappoColour.setText(MessageManager.getString("label.zappo"));
1410 zappoColour.addActionListener(new java.awt.event.ActionListener()
1413 public void actionPerformed(ActionEvent e)
1415 zappoColour_actionPerformed();
1418 taylorColour.setText(MessageManager.getString("label.taylor"));
1419 taylorColour.addActionListener(new java.awt.event.ActionListener()
1422 public void actionPerformed(ActionEvent e)
1424 taylorColour_actionPerformed();
1427 hydrophobicityColour.setText(MessageManager
1428 .getString("label.hydrophobicity"));
1429 hydrophobicityColour
1430 .addActionListener(new java.awt.event.ActionListener()
1433 public void actionPerformed(ActionEvent e)
1435 hydrophobicityColour_actionPerformed();
1438 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1439 helixColour.addActionListener(new java.awt.event.ActionListener()
1442 public void actionPerformed(ActionEvent e)
1444 helixColour_actionPerformed();
1447 strandColour.setText(MessageManager
1448 .getString("label.strand_propensity"));
1449 strandColour.addActionListener(new java.awt.event.ActionListener()
1452 public void actionPerformed(ActionEvent e)
1454 strandColour_actionPerformed();
1457 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1458 turnColour.addActionListener(new java.awt.event.ActionListener()
1461 public void actionPerformed(ActionEvent e)
1463 turnColour_actionPerformed();
1466 buriedColour.setText(MessageManager.getString("label.buried_index"));
1467 buriedColour.addActionListener(new java.awt.event.ActionListener()
1470 public void actionPerformed(ActionEvent e)
1472 buriedColour_actionPerformed();
1475 abovePIDColour.setText(MessageManager
1476 .getString("label.above_identity_percentage"));
1477 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1480 public void actionPerformed(ActionEvent e)
1482 abovePIDColour_actionPerformed();
1485 userDefinedColour.setText(MessageManager
1486 .getString("action.user_defined"));
1487 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1490 public void actionPerformed(ActionEvent e)
1492 userDefinedColour_actionPerformed(e);
1496 .setText(MessageManager.getString("label.percentage_identity"));
1497 PIDColour.addActionListener(new java.awt.event.ActionListener()
1500 public void actionPerformed(ActionEvent e)
1502 PIDColour_actionPerformed();
1505 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1506 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1509 public void actionPerformed(ActionEvent e)
1511 BLOSUM62Colour_actionPerformed();
1514 purinePyrimidineColour.setText(MessageManager
1515 .getString("label.purine_pyrimidine"));
1516 purinePyrimidineColour
1517 .addActionListener(new java.awt.event.ActionListener()
1520 public void actionPerformed(ActionEvent e)
1522 purinePyrimidineColour_actionPerformed();
1527 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1528 * public void actionPerformed(ActionEvent e) {
1529 * covariationColour_actionPerformed(); } });
1532 conservationMenuItem.setText(MessageManager
1533 .getString("label.conservation"));
1534 conservationMenuItem
1535 .addActionListener(new java.awt.event.ActionListener()
1538 public void actionPerformed(ActionEvent e)
1540 conservationMenuItem_actionPerformed();
1546 * Check for any annotations on the underlying dataset sequences (for the
1547 * current selection group) which are not 'on the alignment'.If any are found,
1548 * enable the option to add them to the alignment. The criteria for 'on the
1549 * alignment' is finding an alignment annotation on the alignment, matched on
1550 * calcId, label and sequenceRef.
1552 * A tooltip is also constructed that displays the source (calcId) and type
1553 * (label) of the annotations that can be added.
1556 * @param forSequences
1558 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1559 List<SequenceI> forSequences)
1561 menuItem.setEnabled(false);
1564 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1565 * Using TreeMap means calcIds are shown in alphabetical order.
1567 Map<String, String> tipEntries = new TreeMap<String, String>();
1568 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1569 AlignmentI al = this.ap.av.getAlignment();
1570 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1571 tipEntries, candidates, al);
1572 if (!candidates.isEmpty())
1574 StringBuilder tooltip = new StringBuilder(64);
1575 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1578 * Found annotations that could be added. Enable the menu item, and
1579 * configure its tooltip and action.
1581 menuItem.setEnabled(true);
1582 for (String calcId : tipEntries.keySet())
1584 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1586 String tooltipText = JvSwingUtils.wrapTooltip(true,
1587 tooltip.toString());
1588 menuItem.setToolTipText(tooltipText);
1590 menuItem.addActionListener(new ActionListener()
1593 public void actionPerformed(ActionEvent e)
1595 addReferenceAnnotations_actionPerformed(candidates);
1602 * Add annotations to the sequences and to the alignment.
1605 * a map whose keys are sequences on the alignment, and values a list
1606 * of annotations to add to each sequence
1608 protected void addReferenceAnnotations_actionPerformed(
1609 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1611 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1612 final AlignmentI alignment = this.ap.getAlignment();
1613 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1618 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1620 if (!ap.av.getAlignment().hasSeqrep())
1622 // initialise the display flags so the user sees something happen
1623 ap.av.setDisplayReferenceSeq(true);
1624 ap.av.setColourByReferenceSeq(true);
1625 ap.av.getAlignment().setSeqrep(sequence);
1629 if (ap.av.getAlignment().getSeqrep() == sequence)
1631 ap.av.getAlignment().setSeqrep(null);
1635 ap.av.getAlignment().setSeqrep(sequence);
1641 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1643 if (sequence != null)
1645 ColumnSelection cs = ap.av.getColumnSelection();
1648 cs = new ColumnSelection();
1650 cs.hideInsertionsFor(sequence);
1651 ap.av.setColumnSelection(cs);
1656 protected void sequenceSelectionDetails_actionPerformed()
1658 createSequenceDetailsReport(ap.av.getSequenceSelection());
1661 protected void sequenceDetails_actionPerformed()
1663 createSequenceDetailsReport(new SequenceI[] { sequence });
1666 public void createSequenceDetailsReport(SequenceI[] sequences)
1668 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1669 StringBuffer contents = new StringBuffer();
1670 for (SequenceI seq : sequences)
1672 contents.append("<p><h2>"
1675 "label.create_sequence_details_report_annotation_for",
1676 new Object[] { seq.getDisplayId(true) })
1678 new SequenceAnnotationReport(null)
1679 .createSequenceAnnotationReport(
1685 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1686 .getSeqPanel().seqCanvas.fr.getMinMax()
1688 contents.append("</p>");
1690 cap.setText("<html>" + contents.toString() + "</html>");
1692 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1693 "label.sequence_details_for",
1694 (sequences.length == 1 ? new Object[] { sequences[0]
1695 .getDisplayId(true) } : new Object[] { MessageManager
1696 .getString("label.selection") })), 500, 400);
1700 protected void showNonconserved_actionPerformed()
1702 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1707 * call to refresh view after settings change
1711 ap.updateAnnotation();
1712 ap.paintAlignment(true);
1714 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1723 protected void clustalColour_actionPerformed()
1725 SequenceGroup sg = getGroup();
1726 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1736 protected void zappoColour_actionPerformed()
1738 getGroup().cs = new ZappoColourScheme();
1748 protected void taylorColour_actionPerformed()
1750 getGroup().cs = new TaylorColourScheme();
1760 protected void hydrophobicityColour_actionPerformed()
1762 getGroup().cs = new HydrophobicColourScheme();
1772 protected void helixColour_actionPerformed()
1774 getGroup().cs = new HelixColourScheme();
1784 protected void strandColour_actionPerformed()
1786 getGroup().cs = new StrandColourScheme();
1796 protected void turnColour_actionPerformed()
1798 getGroup().cs = new TurnColourScheme();
1808 protected void buriedColour_actionPerformed()
1810 getGroup().cs = new BuriedColourScheme();
1820 public void nucleotideMenuItem_actionPerformed()
1822 getGroup().cs = new NucleotideColourScheme();
1826 protected void purinePyrimidineColour_actionPerformed()
1828 getGroup().cs = new PurinePyrimidineColourScheme();
1833 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1834 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1842 protected void abovePIDColour_actionPerformed()
1844 SequenceGroup sg = getGroup();
1850 if (abovePIDColour.isSelected())
1852 sg.cs.setConsensus(AAFrequency.calculate(
1853 sg.getSequences(ap.av.getHiddenRepSequences()),
1854 sg.getStartRes(), sg.getEndRes() + 1));
1856 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1859 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1861 SliderPanel.showPIDSlider();
1864 // remove PIDColouring
1866 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1878 protected void userDefinedColour_actionPerformed(ActionEvent e)
1880 SequenceGroup sg = getGroup();
1882 if (e.getSource().equals(userDefinedColour))
1884 new UserDefinedColours(ap, sg);
1888 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1889 .getUserColourSchemes().get(e.getActionCommand());
1897 * Open a panel where the user can choose which types of sequence annotation
1902 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1904 // todo correct way to guard against opening a duplicate panel?
1905 new AnnotationChooser(ap);
1914 protected void PIDColour_actionPerformed()
1916 SequenceGroup sg = getGroup();
1917 sg.cs = new PIDColourScheme();
1918 sg.cs.setConsensus(AAFrequency.calculate(
1919 sg.getSequences(ap.av.getHiddenRepSequences()),
1920 sg.getStartRes(), sg.getEndRes() + 1));
1930 protected void BLOSUM62Colour_actionPerformed()
1932 SequenceGroup sg = getGroup();
1934 sg.cs = new Blosum62ColourScheme();
1936 sg.cs.setConsensus(AAFrequency.calculate(
1937 sg.getSequences(ap.av.getHiddenRepSequences()),
1938 sg.getStartRes(), sg.getEndRes() + 1));
1949 protected void noColourmenuItem_actionPerformed()
1951 getGroup().cs = null;
1961 protected void conservationMenuItem_actionPerformed()
1963 SequenceGroup sg = getGroup();
1969 if (conservationMenuItem.isSelected())
1971 // JBPNote: Conservation name shouldn't be i18n translated
1972 Conservation c = new Conservation("Group", 3, sg.getSequences(ap.av
1973 .getHiddenRepSequences()), sg.getStartRes(),
1974 sg.getEndRes() + 1);
1977 c.verdict(false, ap.av.getConsPercGaps());
1979 sg.cs.setConservation(c);
1981 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1982 SliderPanel.showConservationSlider();
1985 // remove ConservationColouring
1987 sg.cs.setConservation(null);
1993 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1995 SequenceGroup sg = getGroup();
2001 AnnotationColourGradient acg = new AnnotationColourGradient(
2002 sequence.getAnnotation()[0], null,
2003 AnnotationColourGradient.NO_THRESHOLD);
2005 acg.setPredefinedColours(true);
2017 protected void groupName_actionPerformed()
2020 SequenceGroup sg = getGroup();
2021 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2022 sg.getDescription(), " "
2023 + MessageManager.getString("label.group_name") + " ",
2024 MessageManager.getString("label.group_description") + " ",
2025 MessageManager.getString("label.edit_group_name_description"),
2033 sg.setName(dialog.getName());
2034 sg.setDescription(dialog.getDescription());
2039 * Get selection group - adding it to the alignment if necessary.
2041 * @return sequence group to operate on
2043 SequenceGroup getGroup()
2045 SequenceGroup sg = ap.av.getSelectionGroup();
2046 // this method won't add a new group if it already exists
2049 ap.av.getAlignment().addGroup(sg);
2061 void sequenceName_actionPerformed()
2063 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2064 sequence.getDescription(),
2065 " " + MessageManager.getString("label.sequence_name")
2067 MessageManager.getString("label.sequence_description") + " ",
2069 .getString("label.edit_sequence_name_description"),
2077 if (dialog.getName() != null)
2079 if (dialog.getName().indexOf(" ") > -1)
2085 .getString("label.spaces_converted_to_backslashes"),
2087 .getString("label.no_spaces_allowed_sequence_name"),
2088 JOptionPane.WARNING_MESSAGE);
2091 sequence.setName(dialog.getName().replace(' ', '_'));
2092 ap.paintAlignment(false);
2095 sequence.setDescription(dialog.getDescription());
2097 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2108 void unGroupMenuItem_actionPerformed()
2110 SequenceGroup sg = ap.av.getSelectionGroup();
2111 ap.av.getAlignment().deleteGroup(sg);
2112 ap.av.setSelectionGroup(null);
2116 void createGroupMenuItem_actionPerformed()
2118 getGroup(); // implicitly creates group - note - should apply defaults / use
2119 // standard alignment window logic for this
2129 protected void outline_actionPerformed()
2131 SequenceGroup sg = getGroup();
2132 Color col = JColorChooser.showDialog(this,
2133 MessageManager.getString("label.select_outline_colour"),
2138 sg.setOutlineColour(col);
2150 public void showBoxes_actionPerformed()
2152 getGroup().setDisplayBoxes(showBoxes.isSelected());
2162 public void showText_actionPerformed()
2164 getGroup().setDisplayText(showText.isSelected());
2174 public void showColourText_actionPerformed()
2176 getGroup().setColourText(showColourText.isSelected());
2180 public void showLink(String url)
2184 jalview.util.BrowserLauncher.openURL(url);
2185 } catch (Exception ex)
2187 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2188 MessageManager.getString("label.web_browser_not_found_unix"),
2189 MessageManager.getString("label.web_browser_not_found"),
2190 JOptionPane.WARNING_MESSAGE);
2192 ex.printStackTrace();
2196 void hideSequences(boolean representGroup)
2198 ap.av.hideSequences(sequence, representGroup);
2201 public void copy_actionPerformed()
2203 ap.alignFrame.copy_actionPerformed(null);
2206 public void cut_actionPerformed()
2208 ap.alignFrame.cut_actionPerformed(null);
2211 void changeCase(ActionEvent e)
2213 Object source = e.getSource();
2214 SequenceGroup sg = ap.av.getSelectionGroup();
2218 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2219 sg.getStartRes(), sg.getEndRes() + 1);
2224 if (source == toggle)
2226 description = MessageManager.getString("label.toggle_case");
2227 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2229 else if (source == upperCase)
2231 description = MessageManager.getString("label.to_upper_case");
2232 caseChange = ChangeCaseCommand.TO_UPPER;
2236 description = MessageManager.getString("label.to_lower_case");
2237 caseChange = ChangeCaseCommand.TO_LOWER;
2240 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2241 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2242 startEnd, caseChange);
2244 ap.alignFrame.addHistoryItem(caseCommand);
2246 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2252 public void outputText_actionPerformed(ActionEvent e)
2254 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2255 cap.setForInput(null);
2256 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2257 "label.alignment_output_command",
2258 new Object[] { e.getActionCommand() }), 600, 500);
2260 String[] omitHidden = null;
2262 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2263 // or we simply trust the user wants
2264 // wysiwig behaviour
2266 cap.setText(new FormatAdapter(ap).formatSequences(e.getActionCommand(),
2270 public void sequenceFeature_actionPerformed()
2272 SequenceGroup sg = ap.av.getSelectionGroup();
2278 int rsize = 0, gSize = sg.getSize();
2279 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2280 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2282 for (int i = 0; i < gSize; i++)
2284 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2285 int end = sg.findEndRes(sg.getSequenceAt(i));
2288 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2289 features[rsize] = new SequenceFeature(null, null, null, start, end,
2294 rseqs = new SequenceI[rsize];
2295 tfeatures = new SequenceFeature[rsize];
2296 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2297 System.arraycopy(features, 0, tfeatures, 0, rsize);
2298 features = tfeatures;
2300 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2301 features, true, ap))
2303 ap.alignFrame.setShowSeqFeatures(true);
2304 ap.highlightSearchResults(null);
2308 public void textColour_actionPerformed()
2310 SequenceGroup sg = getGroup();
2313 new TextColourChooser().chooseColour(ap, sg);
2317 public void colourByStructure(String pdbid)
2319 Annotation[] anots = ap.av.getStructureSelectionManager()
2320 .colourSequenceFromStructure(sequence, pdbid);
2322 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2323 "Coloured by " + pdbid, anots);
2325 ap.av.getAlignment().addAnnotation(an);
2326 an.createSequenceMapping(sequence, 0, true);
2327 // an.adjustForAlignment();
2328 ap.av.getAlignment().setAnnotationIndex(an, 0);
2330 ap.adjustAnnotationHeight();
2332 sequence.addAlignmentAnnotation(an);
2336 public void editSequence_actionPerformed(ActionEvent actionEvent)
2338 SequenceGroup sg = ap.av.getSelectionGroup();
2342 if (sequence == null)
2344 sequence = sg.getSequenceAt(0);
2347 EditNameDialog dialog = new EditNameDialog(
2348 sequence.getSequenceAsString(sg.getStartRes(),
2349 sg.getEndRes() + 1), null,
2350 MessageManager.getString("label.edit_sequence"), null,
2351 MessageManager.getString("label.edit_sequence"),
2356 EditCommand editCommand = new EditCommand(
2357 MessageManager.getString("label.edit_sequences"),
2358 Action.REPLACE, dialog.getName().replace(' ',
2359 ap.av.getGapCharacter()),
2360 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2361 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2363 ap.alignFrame.addHistoryItem(editCommand);
2365 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()