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.FileFormatI;
42 import jalview.io.FileFormats;
43 import jalview.io.FormatAdapter;
44 import jalview.io.SequenceAnnotationReport;
45 import jalview.schemes.AnnotationColourGradient;
46 import jalview.schemes.Blosum62ColourScheme;
47 import jalview.schemes.BuriedColourScheme;
48 import jalview.schemes.ClustalxColourScheme;
49 import jalview.schemes.HelixColourScheme;
50 import jalview.schemes.HydrophobicColourScheme;
51 import jalview.schemes.NucleotideColourScheme;
52 import jalview.schemes.PIDColourScheme;
53 import jalview.schemes.PurinePyrimidineColourScheme;
54 import jalview.schemes.StrandColourScheme;
55 import jalview.schemes.TaylorColourScheme;
56 import jalview.schemes.TurnColourScheme;
57 import jalview.schemes.UserColourScheme;
58 import jalview.schemes.ZappoColourScheme;
59 import jalview.util.GroupUrlLink;
60 import jalview.util.GroupUrlLink.UrlStringTooLongException;
61 import jalview.util.MessageManager;
62 import jalview.util.UrlLink;
64 import java.awt.Color;
65 import java.awt.event.ActionEvent;
66 import java.awt.event.ActionListener;
67 import java.util.Arrays;
68 import java.util.Collection;
69 import java.util.Collections;
70 import java.util.Hashtable;
71 import java.util.LinkedHashMap;
72 import java.util.List;
74 import java.util.TreeMap;
75 import java.util.Vector;
77 import javax.swing.ButtonGroup;
78 import javax.swing.JCheckBoxMenuItem;
79 import javax.swing.JColorChooser;
80 import javax.swing.JMenu;
81 import javax.swing.JMenuItem;
82 import javax.swing.JPopupMenu;
83 import javax.swing.JRadioButtonMenuItem;
89 * @version $Revision: 1.118 $
91 public class PopupMenu extends JPopupMenu
93 JMenu groupMenu = new JMenu();
95 JMenuItem groupName = new JMenuItem();
97 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
99 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
101 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
103 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
105 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
107 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
109 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
111 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
113 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
115 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
117 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
119 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
121 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
123 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
125 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
127 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
131 JMenu sequenceMenu = new JMenu();
133 JMenuItem sequenceName = new JMenuItem();
135 JMenuItem sequenceDetails = new JMenuItem();
137 JMenuItem sequenceSelDetails = new JMenuItem();
139 JMenuItem makeReferenceSeq = new JMenuItem();
141 JMenuItem chooseAnnotations = new JMenuItem();
145 JMenuItem createGroupMenuItem = new JMenuItem();
147 JMenuItem unGroupMenuItem = new JMenuItem();
149 JMenuItem outline = new JMenuItem();
151 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
153 JMenu colourMenu = new JMenu();
155 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
157 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
159 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
161 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
163 JMenu editMenu = new JMenu();
165 JMenuItem cut = new JMenuItem();
167 JMenuItem copy = new JMenuItem();
169 JMenuItem upperCase = new JMenuItem();
171 JMenuItem lowerCase = new JMenuItem();
173 JMenuItem toggle = new JMenuItem();
175 JMenu pdbMenu = new JMenu();
177 JMenu outputMenu = new JMenu();
179 JMenu seqShowAnnotationsMenu = new JMenu();
181 JMenu seqHideAnnotationsMenu = new JMenu();
183 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
184 MessageManager.getString("label.add_reference_annotations"));
186 JMenu groupShowAnnotationsMenu = new JMenu();
188 JMenu groupHideAnnotationsMenu = new JMenu();
190 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
191 MessageManager.getString("label.add_reference_annotations"));
193 JMenuItem sequenceFeature = new JMenuItem();
195 JMenuItem textColour = new JMenuItem();
197 JMenu jMenu1 = new JMenu();
199 JMenuItem pdbStructureDialog = new JMenuItem();
201 JMenu rnaStructureMenu = new JMenu();
203 JMenuItem editSequence = new JMenuItem();
205 JMenu groupLinksMenu;
207 JMenuItem hideInsertions = new JMenuItem();
210 * Creates a new PopupMenu object.
217 public PopupMenu(final AlignmentPanel ap, Sequence seq, List<String> links)
219 this(ap, seq, links, null);
229 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
230 List<String> links, List<String> groupLinks)
232 // /////////////////////////////////////////////////////////
233 // If this is activated from the sequence panel, the user may want to
234 // edit or annotate a particular residue. Therefore display the residue menu
236 // If from the IDPanel, we must display the sequence menu
237 // ////////////////////////////////////////////////////////
241 ButtonGroup colours = new ButtonGroup();
242 colours.add(noColourmenuItem);
243 colours.add(clustalColour);
244 colours.add(zappoColour);
245 colours.add(taylorColour);
246 colours.add(hydrophobicityColour);
247 colours.add(helixColour);
248 colours.add(strandColour);
249 colours.add(turnColour);
250 colours.add(buriedColour);
251 colours.add(userDefinedColour);
252 colours.add(PIDColour);
253 colours.add(BLOSUM62Colour);
254 colours.add(purinePyrimidineColour);
255 colours.add(RNAInteractionColour);
257 for (String ff : FileFormats.getInstance().getWritableFormats(true))
259 JMenuItem item = new JMenuItem(ff);
261 item.addActionListener(new java.awt.event.ActionListener()
264 public void actionPerformed(ActionEvent e)
266 outputText_actionPerformed(e);
270 outputMenu.add(item);
274 * Build menus for annotation types that may be shown or hidden, and for
275 * 'reference annotations' that may be added to the alignment. First for the
276 * currently selected sequence (if there is one):
278 final List<SequenceI> selectedSequence = (seq == null ? Collections
279 .<SequenceI> emptyList() : Arrays.asList(seq));
280 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
281 seqHideAnnotationsMenu, selectedSequence);
282 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
286 * And repeat for the current selection group (if there is one):
288 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
289 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
291 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
292 groupHideAnnotationsMenu, selectedGroup);
293 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
299 } catch (Exception e)
307 sequenceMenu.setText(sequence.getName());
308 if (seq == ap.av.getAlignment().getSeqrep())
310 makeReferenceSeq.setText(MessageManager
311 .getString("action.unmark_as_reference"));
315 makeReferenceSeq.setText(MessageManager
316 .getString("action.set_as_reference"));
319 if (!ap.av.getAlignment().isNucleotide())
321 remove(rnaStructureMenu);
325 int origCount = rnaStructureMenu.getItemCount();
327 * add menu items to 2D-render any alignment or sequence secondary
328 * structure annotation
330 AlignmentAnnotation[] aas = ap.av.getAlignment()
331 .getAlignmentAnnotation();
334 for (final AlignmentAnnotation aa : aas)
336 if (aa.isValidStruc() && aa.sequenceRef == null)
339 * valid alignment RNA secondary structure annotation
341 menuItem = new JMenuItem();
342 menuItem.setText(MessageManager.formatMessage(
343 "label.2d_rna_structure_line",
344 new Object[] { aa.label }));
345 menuItem.addActionListener(new java.awt.event.ActionListener()
348 public void actionPerformed(ActionEvent e)
350 new AppVarna(seq, aa, ap);
353 rnaStructureMenu.add(menuItem);
358 if (seq.getAnnotation() != null)
360 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
361 for (final AlignmentAnnotation aa : seqAnns)
363 if (aa.isValidStruc())
366 * valid sequence RNA secondary structure annotation
368 // TODO: make rnastrucF a bit more nice
369 menuItem = new JMenuItem();
370 menuItem.setText(MessageManager.formatMessage(
371 "label.2d_rna_sequence_name",
372 new Object[] { seq.getName() }));
373 menuItem.addActionListener(new java.awt.event.ActionListener()
376 public void actionPerformed(ActionEvent e)
378 // TODO: VARNA does'nt print gaps in the sequence
379 new AppVarna(seq, aa, ap);
382 rnaStructureMenu.add(menuItem);
386 if (rnaStructureMenu.getItemCount() == origCount)
388 remove(rnaStructureMenu);
392 menuItem = new JMenuItem(
393 MessageManager.getString("action.hide_sequences"));
394 menuItem.addActionListener(new java.awt.event.ActionListener()
397 public void actionPerformed(ActionEvent e)
399 hideSequences(false);
404 if (ap.av.getSelectionGroup() != null
405 && ap.av.getSelectionGroup().getSize() > 1)
407 menuItem = new JMenuItem(MessageManager.formatMessage(
408 "label.represent_group_with",
409 new Object[] { seq.getName() }));
410 menuItem.addActionListener(new java.awt.event.ActionListener()
413 public void actionPerformed(ActionEvent e)
418 sequenceMenu.add(menuItem);
421 if (ap.av.hasHiddenRows())
423 final int index = ap.av.getAlignment().findIndex(seq);
425 if (ap.av.adjustForHiddenSeqs(index)
426 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
428 menuItem = new JMenuItem(
429 MessageManager.getString("action.reveal_sequences"));
430 menuItem.addActionListener(new ActionListener()
433 public void actionPerformed(ActionEvent e)
435 ap.av.showSequence(index);
436 if (ap.overviewPanel != null)
438 ap.overviewPanel.updateOverviewImage();
446 // for the case when no sequences are even visible
447 if (ap.av.hasHiddenRows())
450 menuItem = new JMenuItem(
451 MessageManager.getString("action.reveal_all"));
452 menuItem.addActionListener(new ActionListener()
455 public void actionPerformed(ActionEvent e)
457 ap.av.showAllHiddenSeqs();
458 if (ap.overviewPanel != null)
460 ap.overviewPanel.updateOverviewImage();
470 SequenceGroup sg = ap.av.getSelectionGroup();
471 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
472 .getGroups().contains(sg) : false;
474 if (sg != null && sg.getSize() > 0)
476 groupName.setText(MessageManager
477 .getString("label.edit_name_and_description_current_group"));
479 if (sg.cs instanceof ZappoColourScheme)
481 zappoColour.setSelected(true);
483 else if (sg.cs instanceof TaylorColourScheme)
485 taylorColour.setSelected(true);
487 else if (sg.cs instanceof PIDColourScheme)
489 PIDColour.setSelected(true);
491 else if (sg.cs instanceof Blosum62ColourScheme)
493 BLOSUM62Colour.setSelected(true);
495 else if (sg.cs instanceof UserColourScheme)
497 userDefinedColour.setSelected(true);
499 else if (sg.cs instanceof HydrophobicColourScheme)
501 hydrophobicityColour.setSelected(true);
503 else if (sg.cs instanceof HelixColourScheme)
505 helixColour.setSelected(true);
507 else if (sg.cs instanceof StrandColourScheme)
509 strandColour.setSelected(true);
511 else if (sg.cs instanceof TurnColourScheme)
513 turnColour.setSelected(true);
515 else if (sg.cs instanceof BuriedColourScheme)
517 buriedColour.setSelected(true);
519 else if (sg.cs instanceof ClustalxColourScheme)
521 clustalColour.setSelected(true);
523 else if (sg.cs instanceof PurinePyrimidineColourScheme)
525 purinePyrimidineColour.setSelected(true);
529 * else if (sg.cs instanceof CovariationColourScheme) {
530 * covariationColour.setSelected(true); }
534 noColourmenuItem.setSelected(true);
539 if (sg.cs.conservationApplied())
541 conservationMenuItem.setSelected(true);
543 if (sg.cs.getThreshold() > 0)
545 abovePIDColour.setSelected(true);
548 displayNonconserved.setSelected(sg.getShowNonconserved());
549 showText.setSelected(sg.getDisplayText());
550 showColourText.setSelected(sg.getColourText());
551 showBoxes.setSelected(sg.getDisplayBoxes());
552 // add any groupURLs to the groupURL submenu and make it visible
553 if (groupLinks != null && groupLinks.size() > 0)
555 buildGroupURLMenu(sg, groupLinks);
557 // Add a 'show all structures' for the current selection
558 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
559 SequenceI sqass = null;
560 for (SequenceI sq : ap.av.getSequenceSelection())
562 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
563 if (pes != null && pes.size() > 0)
565 reppdb.put(pes.get(0).getId(), pes.get(0));
566 for (PDBEntry pe : pes)
568 pdbe.put(pe.getId(), pe);
578 final PDBEntry[] pe = pdbe.values().toArray(
579 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
580 new PDBEntry[reppdb.size()]);
581 final JMenuItem gpdbview, rpdbview;
586 groupMenu.setVisible(false);
587 editMenu.setVisible(false);
592 createGroupMenuItem.setVisible(true);
593 unGroupMenuItem.setVisible(false);
594 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
598 createGroupMenuItem.setVisible(false);
599 unGroupMenuItem.setVisible(true);
600 jMenu1.setText(MessageManager.getString("action.edit_group"));
605 sequenceMenu.setVisible(false);
606 pdbStructureDialog.setVisible(false);
607 rnaStructureMenu.setVisible(false);
610 if (links != null && links.size() > 0)
612 addFeatureLinks(seq, links);
617 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
622 void addFeatureLinks(final SequenceI seq, List<String> links)
624 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
625 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
627 for (String link : links)
629 UrlLink urlLink = null;
632 urlLink = new UrlLink(link);
633 } catch (Exception foo)
635 Cache.log.error("Exception for URLLink '" + link + "'", foo);
639 if (!urlLink.isValid())
641 Cache.log.error(urlLink.getInvalidMessage());
645 urlLink.createLinksFromSeq(seq, linkset);
648 addshowLinks(linkMenu, linkset.values());
650 // disable link menu if there are no valid entries
651 if (linkMenu.getItemCount() > 0)
653 linkMenu.setEnabled(true);
657 linkMenu.setEnabled(false);
660 if (sequence != null)
662 sequenceMenu.add(linkMenu);
674 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
675 * "All" is added first, followed by a separator. Then add any annotation
676 * types associated with the current selection. Separate menus are built for
677 * the selected sequence group (if any), and the selected sequence.
679 * Some annotation rows are always rendered together - these can be identified
680 * by a common graphGroup property > -1. Only one of each group will be marked
681 * as visible (to avoid duplication of the display). For such groups we add a
682 * composite type name, e.g.
684 * IUPredWS (Long), IUPredWS (Short)
688 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
689 List<SequenceI> forSequences)
691 showMenu.removeAll();
692 hideMenu.removeAll();
694 final List<String> all = Arrays.asList(new String[] { MessageManager
695 .getString("label.all") });
696 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
697 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
699 showMenu.addSeparator();
700 hideMenu.addSeparator();
702 final AlignmentAnnotation[] annotations = ap.getAlignment()
703 .getAlignmentAnnotation();
706 * Find shown/hidden annotations types, distinguished by source (calcId),
707 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
708 * the insertion order, which is the order of the annotations on the
711 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
712 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
713 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
714 AlignmentAnnotationUtils.asList(annotations), forSequences);
716 for (String calcId : hiddenTypes.keySet())
718 for (List<String> type : hiddenTypes.get(calcId))
720 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
724 // grey out 'show annotations' if none are hidden
725 showMenu.setEnabled(!hiddenTypes.isEmpty());
727 for (String calcId : shownTypes.keySet())
729 for (List<String> type : shownTypes.get(calcId))
731 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
735 // grey out 'hide annotations' if none are shown
736 hideMenu.setEnabled(!shownTypes.isEmpty());
740 * Returns a list of sequences - either the current selection group (if there
741 * is one), else the specified single sequence.
746 protected List<SequenceI> getSequenceScope(SequenceI seq)
748 List<SequenceI> forSequences = null;
749 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
750 if (selectionGroup != null && selectionGroup.getSize() > 0)
752 forSequences = selectionGroup.getSequences();
756 forSequences = seq == null ? Collections.<SequenceI> emptyList()
757 : Arrays.asList(seq);
763 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
766 * @param showOrHideMenu
768 * @param forSequences
769 * the sequences whose annotations may be shown or hidden
774 * if true this is a special label meaning 'All'
775 * @param actionIsShow
776 * if true, the select menu item action is to show the annotation
779 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
780 final List<SequenceI> forSequences, String calcId,
781 final List<String> types, final boolean allTypes,
782 final boolean actionIsShow)
784 String label = types.toString(); // [a, b, c]
785 label = label.substring(1, label.length() - 1); // a, b, c
786 final JMenuItem item = new JMenuItem(label);
787 item.setToolTipText(calcId);
788 item.addActionListener(new java.awt.event.ActionListener()
791 public void actionPerformed(ActionEvent e)
793 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
794 types, forSequences, allTypes, actionIsShow);
798 showOrHideMenu.add(item);
801 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
804 // TODO: usability: thread off the generation of group url content so root
806 // sequence only URLs
807 // ID/regex match URLs
808 groupLinksMenu = new JMenu(
809 MessageManager.getString("action.group_link"));
810 // three types of url that might be created.
811 JMenu[] linkMenus = new JMenu[] { null,
812 new JMenu(MessageManager.getString("action.ids")),
813 new JMenu(MessageManager.getString("action.sequences")),
814 new JMenu(MessageManager.getString("action.ids_sequences")) };
816 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
817 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
818 Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
819 for (int sq = 0; sq < seqs.length; sq++)
822 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
823 .findPosition(sg.getEndRes());
824 // just collect ids from dataset sequence
825 // TODO: check if IDs collected from selecton group intersects with the
826 // current selection, too
827 SequenceI sqi = seqs[sq];
828 while (sqi.getDatasetSequence() != null)
830 sqi = sqi.getDatasetSequence();
832 DBRefEntry[] dbr = sqi.getDBRefs();
833 if (dbr != null && dbr.length > 0)
835 for (int d = 0; d < dbr.length; d++)
837 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
838 Object[] sarray = commonDbrefs.get(src);
841 sarray = new Object[2];
842 sarray[0] = new int[] { 0 };
843 sarray[1] = new String[seqs.length];
845 commonDbrefs.put(src, sarray);
848 if (((String[]) sarray[1])[sq] == null)
851 || (dbr[d].getMap().locateMappedRange(start, end) != null))
853 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
854 ((int[]) sarray[0])[0]++;
860 // now create group links for all distinct ID/sequence sets.
861 boolean addMenu = false; // indicates if there are any group links to give
863 for (String link : groupLinks)
865 GroupUrlLink urlLink = null;
868 urlLink = new GroupUrlLink(link);
869 } catch (Exception foo)
871 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
875 if (!urlLink.isValid())
877 Cache.log.error(urlLink.getInvalidMessage());
880 final String label = urlLink.getLabel();
881 boolean usingNames = false;
882 // Now see which parts of the group apply for this URL
883 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
884 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
885 String[] seqstr, ids; // input to makeUrl
888 int numinput = ((int[]) idset[0])[0];
889 String[] allids = ((String[]) idset[1]);
890 seqstr = new String[numinput];
891 ids = new String[numinput];
892 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
894 if (allids[sq] != null)
896 ids[idcount] = allids[sq];
897 seqstr[idcount++] = idandseqs[1][sq];
903 // just use the id/seq set
904 seqstr = idandseqs[1];
908 // and try and make the groupURL!
910 Object[] urlset = null;
913 urlset = urlLink.makeUrlStubs(ids, seqstr,
914 "FromJalview" + System.currentTimeMillis(), false);
915 } catch (UrlStringTooLongException e)
920 int type = urlLink.getGroupURLType() & 3;
921 // first two bits ofurlLink type bitfield are sequenceids and sequences
922 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
923 addshowLink(linkMenus[type], label
924 + (((type & 1) == 1) ? ("("
925 + (usingNames ? "Names" : ltarget) + ")") : ""),
932 groupLinksMenu = new JMenu(
933 MessageManager.getString("action.group_link"));
934 for (int m = 0; m < linkMenus.length; m++)
936 if (linkMenus[m] != null
937 && linkMenus[m].getMenuComponentCount() > 0)
939 groupLinksMenu.add(linkMenus[m]);
943 groupMenu.add(groupLinksMenu);
947 private void addshowLinks(JMenu linkMenu, Collection<List<String>> linkset)
949 for (List<String> linkstrset : linkset)
951 // split linkstr into label and url
952 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
957 * add a show URL menu item to the given linkMenu
961 * - menu label string
965 private void addshowLink(JMenu linkMenu, String label, final String url)
967 JMenuItem item = new JMenuItem(label);
968 item.setToolTipText(MessageManager.formatMessage(
969 "label.open_url_param", new Object[] { url }));
970 item.addActionListener(new java.awt.event.ActionListener()
973 public void actionPerformed(ActionEvent e)
975 new Thread(new Runnable()
992 * add a late bound groupURL item to the given linkMenu
996 * - menu label string
997 * @param urlgenerator
998 * GroupURLLink used to generate URL
1000 * Object array returned from the makeUrlStubs function.
1002 private void addshowLink(JMenu linkMenu, String label,
1003 final GroupUrlLink urlgenerator, final Object[] urlstub)
1005 JMenuItem item = new JMenuItem(label);
1006 item.setToolTipText(MessageManager.formatMessage(
1007 "label.open_url_seqs_param",
1008 new Object[] { urlgenerator.getUrl_prefix(),
1009 urlgenerator.getNumberInvolved(urlstub) }));
1010 // TODO: put in info about what is being sent.
1011 item.addActionListener(new ActionListener()
1014 public void actionPerformed(ActionEvent e)
1016 new Thread(new Runnable()
1024 showLink(urlgenerator.constructFrom(urlstub));
1025 } catch (UrlStringTooLongException e2)
1043 private void jbInit() throws Exception
1045 groupMenu.setText(MessageManager.getString("label.selection"));
1046 groupName.setText(MessageManager.getString("label.name"));
1047 groupName.addActionListener(new java.awt.event.ActionListener()
1050 public void actionPerformed(ActionEvent e)
1052 groupName_actionPerformed();
1055 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1056 sequenceName.setText(MessageManager
1057 .getString("label.edit_name_description"));
1058 sequenceName.addActionListener(new java.awt.event.ActionListener()
1061 public void actionPerformed(ActionEvent e)
1063 sequenceName_actionPerformed();
1066 chooseAnnotations.setText(MessageManager
1067 .getString("action.choose_annotations"));
1068 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1071 public void actionPerformed(ActionEvent e)
1073 chooseAnnotations_actionPerformed(e);
1076 sequenceDetails.setText(MessageManager
1077 .getString("label.sequence_details"));
1078 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1081 public void actionPerformed(ActionEvent e)
1083 sequenceDetails_actionPerformed();
1086 sequenceSelDetails.setText(MessageManager
1087 .getString("label.sequence_details"));
1089 .addActionListener(new java.awt.event.ActionListener()
1092 public void actionPerformed(ActionEvent e)
1094 sequenceSelectionDetails_actionPerformed();
1097 PIDColour.setFocusPainted(false);
1099 .setText(MessageManager.getString("action.remove_group"));
1100 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1103 public void actionPerformed(ActionEvent e)
1105 unGroupMenuItem_actionPerformed();
1108 createGroupMenuItem.setText(MessageManager
1109 .getString("action.create_group"));
1111 .addActionListener(new java.awt.event.ActionListener()
1114 public void actionPerformed(ActionEvent e)
1116 createGroupMenuItem_actionPerformed();
1120 outline.setText(MessageManager.getString("action.border_colour"));
1121 outline.addActionListener(new java.awt.event.ActionListener()
1124 public void actionPerformed(ActionEvent e)
1126 outline_actionPerformed();
1130 .setText(MessageManager.getString("label.nucleotide"));
1131 nucleotideMenuItem.addActionListener(new ActionListener()
1134 public void actionPerformed(ActionEvent e)
1136 nucleotideMenuItem_actionPerformed();
1139 colourMenu.setText(MessageManager.getString("label.group_colour"));
1140 showBoxes.setText(MessageManager.getString("action.boxes"));
1141 showBoxes.setState(true);
1142 showBoxes.addActionListener(new ActionListener()
1145 public void actionPerformed(ActionEvent e)
1147 showBoxes_actionPerformed();
1150 showText.setText(MessageManager.getString("action.text"));
1151 showText.setState(true);
1152 showText.addActionListener(new ActionListener()
1155 public void actionPerformed(ActionEvent e)
1157 showText_actionPerformed();
1160 showColourText.setText(MessageManager.getString("label.colour_text"));
1161 showColourText.addActionListener(new ActionListener()
1164 public void actionPerformed(ActionEvent e)
1166 showColourText_actionPerformed();
1169 displayNonconserved.setText(MessageManager
1170 .getString("label.show_non_conversed"));
1171 displayNonconserved.setState(true);
1172 displayNonconserved.addActionListener(new ActionListener()
1175 public void actionPerformed(ActionEvent e)
1177 showNonconserved_actionPerformed();
1180 editMenu.setText(MessageManager.getString("action.edit"));
1181 cut.setText(MessageManager.getString("action.cut"));
1182 cut.addActionListener(new ActionListener()
1185 public void actionPerformed(ActionEvent e)
1187 cut_actionPerformed();
1190 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1191 upperCase.addActionListener(new ActionListener()
1194 public void actionPerformed(ActionEvent e)
1199 copy.setText(MessageManager.getString("action.copy"));
1200 copy.addActionListener(new ActionListener()
1203 public void actionPerformed(ActionEvent e)
1205 copy_actionPerformed();
1208 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1209 lowerCase.addActionListener(new ActionListener()
1212 public void actionPerformed(ActionEvent e)
1217 toggle.setText(MessageManager.getString("label.toggle_case"));
1218 toggle.addActionListener(new ActionListener()
1221 public void actionPerformed(ActionEvent e)
1226 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1228 seqShowAnnotationsMenu.setText(MessageManager
1229 .getString("label.show_annotations"));
1230 seqHideAnnotationsMenu.setText(MessageManager
1231 .getString("label.hide_annotations"));
1232 groupShowAnnotationsMenu.setText(MessageManager
1233 .getString("label.show_annotations"));
1234 groupHideAnnotationsMenu.setText(MessageManager
1235 .getString("label.hide_annotations"));
1236 sequenceFeature.setText(MessageManager
1237 .getString("label.create_sequence_feature"));
1238 sequenceFeature.addActionListener(new ActionListener()
1241 public void actionPerformed(ActionEvent e)
1243 sequenceFeature_actionPerformed();
1246 textColour.setText(MessageManager.getString("label.text_colour"));
1247 textColour.addActionListener(new ActionListener()
1250 public void actionPerformed(ActionEvent e)
1252 textColour_actionPerformed();
1255 jMenu1.setText(MessageManager.getString("label.group"));
1256 pdbStructureDialog.setText(MessageManager
1257 .getString("label.show_pdbstruct_dialog"));
1258 pdbStructureDialog.addActionListener(new ActionListener()
1261 public void actionPerformed(ActionEvent actionEvent)
1263 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1264 if (ap.av.getSelectionGroup() != null)
1266 selectedSeqs = ap.av.getSequenceSelection();
1268 new StructureChooser(selectedSeqs, sequence, ap);
1272 rnaStructureMenu.setText(MessageManager
1273 .getString("label.view_rna_structure"));
1275 // colStructureMenu.setText("Colour By Structure");
1276 editSequence.setText(MessageManager.getString("label.edit_sequence")
1278 editSequence.addActionListener(new ActionListener()
1281 public void actionPerformed(ActionEvent actionEvent)
1283 editSequence_actionPerformed(actionEvent);
1286 makeReferenceSeq.setText(MessageManager
1287 .getString("label.mark_as_representative"));
1288 makeReferenceSeq.addActionListener(new ActionListener()
1292 public void actionPerformed(ActionEvent actionEvent)
1294 makeReferenceSeq_actionPerformed(actionEvent);
1298 hideInsertions.setText(MessageManager
1299 .getString("label.hide_insertions"));
1300 hideInsertions.addActionListener(new ActionListener()
1304 public void actionPerformed(ActionEvent e)
1306 hideInsertions_actionPerformed(e);
1310 * annotationMenuItem.setText("By Annotation");
1311 * annotationMenuItem.addActionListener(new ActionListener() { public void
1312 * actionPerformed(ActionEvent actionEvent) {
1313 * annotationMenuItem_actionPerformed(actionEvent); } });
1315 groupMenu.add(sequenceSelDetails);
1318 add(rnaStructureMenu);
1319 add(pdbStructureDialog);
1320 if (sequence != null)
1322 add(hideInsertions);
1324 // annotations configuration panel suppressed for now
1325 // groupMenu.add(chooseAnnotations);
1328 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1329 * (if a selection group is in force).
1331 sequenceMenu.add(seqShowAnnotationsMenu);
1332 sequenceMenu.add(seqHideAnnotationsMenu);
1333 sequenceMenu.add(seqAddReferenceAnnotations);
1334 groupMenu.add(groupShowAnnotationsMenu);
1335 groupMenu.add(groupHideAnnotationsMenu);
1336 groupMenu.add(groupAddReferenceAnnotations);
1337 groupMenu.add(editMenu);
1338 groupMenu.add(outputMenu);
1339 groupMenu.add(sequenceFeature);
1340 groupMenu.add(createGroupMenuItem);
1341 groupMenu.add(unGroupMenuItem);
1342 groupMenu.add(jMenu1);
1343 sequenceMenu.add(sequenceName);
1344 sequenceMenu.add(sequenceDetails);
1345 sequenceMenu.add(makeReferenceSeq);
1346 colourMenu.add(textColour);
1347 colourMenu.add(noColourmenuItem);
1348 colourMenu.add(clustalColour);
1349 colourMenu.add(BLOSUM62Colour);
1350 colourMenu.add(PIDColour);
1351 colourMenu.add(zappoColour);
1352 colourMenu.add(taylorColour);
1353 colourMenu.add(hydrophobicityColour);
1354 colourMenu.add(helixColour);
1355 colourMenu.add(strandColour);
1356 colourMenu.add(turnColour);
1357 colourMenu.add(buriedColour);
1358 colourMenu.add(nucleotideMenuItem);
1359 if (ap.getAlignment().isNucleotide())
1361 // JBPNote - commented since the colourscheme isn't functional
1362 colourMenu.add(purinePyrimidineColour);
1364 colourMenu.add(userDefinedColour);
1366 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1368 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1369 .getUserColourSchemes().keys();
1371 while (userColours.hasMoreElements())
1373 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1374 item.addActionListener(new ActionListener()
1377 public void actionPerformed(ActionEvent evt)
1379 userDefinedColour_actionPerformed(evt);
1382 colourMenu.add(item);
1386 colourMenu.addSeparator();
1387 colourMenu.add(abovePIDColour);
1388 colourMenu.add(conservationMenuItem);
1391 editMenu.add(editSequence);
1392 editMenu.add(upperCase);
1393 editMenu.add(lowerCase);
1394 editMenu.add(toggle);
1395 // JBPNote: These shouldn't be added here - should appear in a generic
1396 // 'apply web service to this sequence menu'
1397 // pdbMenu.add(RNAFold);
1398 // pdbMenu.add(ContraFold);
1399 jMenu1.add(groupName);
1400 jMenu1.add(colourMenu);
1401 jMenu1.add(showBoxes);
1402 jMenu1.add(showText);
1403 jMenu1.add(showColourText);
1404 jMenu1.add(outline);
1405 jMenu1.add(displayNonconserved);
1406 noColourmenuItem.setText(MessageManager.getString("label.none"));
1407 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1410 public void actionPerformed(ActionEvent e)
1412 noColourmenuItem_actionPerformed();
1416 clustalColour.setText(MessageManager
1417 .getString("label.clustalx_colours"));
1418 clustalColour.addActionListener(new java.awt.event.ActionListener()
1421 public void actionPerformed(ActionEvent e)
1423 clustalColour_actionPerformed();
1426 zappoColour.setText(MessageManager.getString("label.zappo"));
1427 zappoColour.addActionListener(new java.awt.event.ActionListener()
1430 public void actionPerformed(ActionEvent e)
1432 zappoColour_actionPerformed();
1435 taylorColour.setText(MessageManager.getString("label.taylor"));
1436 taylorColour.addActionListener(new java.awt.event.ActionListener()
1439 public void actionPerformed(ActionEvent e)
1441 taylorColour_actionPerformed();
1444 hydrophobicityColour.setText(MessageManager
1445 .getString("label.hydrophobicity"));
1446 hydrophobicityColour
1447 .addActionListener(new java.awt.event.ActionListener()
1450 public void actionPerformed(ActionEvent e)
1452 hydrophobicityColour_actionPerformed();
1455 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1456 helixColour.addActionListener(new java.awt.event.ActionListener()
1459 public void actionPerformed(ActionEvent e)
1461 helixColour_actionPerformed();
1464 strandColour.setText(MessageManager
1465 .getString("label.strand_propensity"));
1466 strandColour.addActionListener(new java.awt.event.ActionListener()
1469 public void actionPerformed(ActionEvent e)
1471 strandColour_actionPerformed();
1474 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1475 turnColour.addActionListener(new java.awt.event.ActionListener()
1478 public void actionPerformed(ActionEvent e)
1480 turnColour_actionPerformed();
1483 buriedColour.setText(MessageManager.getString("label.buried_index"));
1484 buriedColour.addActionListener(new java.awt.event.ActionListener()
1487 public void actionPerformed(ActionEvent e)
1489 buriedColour_actionPerformed();
1492 abovePIDColour.setText(MessageManager
1493 .getString("label.above_identity_percentage"));
1494 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1497 public void actionPerformed(ActionEvent e)
1499 abovePIDColour_actionPerformed();
1502 userDefinedColour.setText(MessageManager
1503 .getString("action.user_defined"));
1504 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1507 public void actionPerformed(ActionEvent e)
1509 userDefinedColour_actionPerformed(e);
1513 .setText(MessageManager.getString("label.percentage_identity"));
1514 PIDColour.addActionListener(new java.awt.event.ActionListener()
1517 public void actionPerformed(ActionEvent e)
1519 PIDColour_actionPerformed();
1522 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1523 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1526 public void actionPerformed(ActionEvent e)
1528 BLOSUM62Colour_actionPerformed();
1531 purinePyrimidineColour.setText(MessageManager
1532 .getString("label.purine_pyrimidine"));
1533 purinePyrimidineColour
1534 .addActionListener(new java.awt.event.ActionListener()
1537 public void actionPerformed(ActionEvent e)
1539 purinePyrimidineColour_actionPerformed();
1544 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1545 * public void actionPerformed(ActionEvent e) {
1546 * covariationColour_actionPerformed(); } });
1549 conservationMenuItem.setText(MessageManager
1550 .getString("label.conservation"));
1551 conservationMenuItem
1552 .addActionListener(new java.awt.event.ActionListener()
1555 public void actionPerformed(ActionEvent e)
1557 conservationMenuItem_actionPerformed();
1563 * Check for any annotations on the underlying dataset sequences (for the
1564 * current selection group) which are not 'on the alignment'.If any are found,
1565 * enable the option to add them to the alignment. The criteria for 'on the
1566 * alignment' is finding an alignment annotation on the alignment, matched on
1567 * calcId, label and sequenceRef.
1569 * A tooltip is also constructed that displays the source (calcId) and type
1570 * (label) of the annotations that can be added.
1573 * @param forSequences
1575 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1576 List<SequenceI> forSequences)
1578 menuItem.setEnabled(false);
1581 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1582 * Using TreeMap means calcIds are shown in alphabetical order.
1584 Map<String, String> tipEntries = new TreeMap<String, String>();
1585 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1586 AlignmentI al = this.ap.av.getAlignment();
1587 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1588 tipEntries, candidates, al);
1589 if (!candidates.isEmpty())
1591 StringBuilder tooltip = new StringBuilder(64);
1592 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1595 * Found annotations that could be added. Enable the menu item, and
1596 * configure its tooltip and action.
1598 menuItem.setEnabled(true);
1599 for (String calcId : tipEntries.keySet())
1601 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1603 String tooltipText = JvSwingUtils.wrapTooltip(true,
1604 tooltip.toString());
1605 menuItem.setToolTipText(tooltipText);
1607 menuItem.addActionListener(new ActionListener()
1610 public void actionPerformed(ActionEvent e)
1612 addReferenceAnnotations_actionPerformed(candidates);
1619 * Add annotations to the sequences and to the alignment.
1622 * a map whose keys are sequences on the alignment, and values a list
1623 * of annotations to add to each sequence
1625 protected void addReferenceAnnotations_actionPerformed(
1626 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1628 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1629 final AlignmentI alignment = this.ap.getAlignment();
1630 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1635 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1637 if (!ap.av.getAlignment().hasSeqrep())
1639 // initialise the display flags so the user sees something happen
1640 ap.av.setDisplayReferenceSeq(true);
1641 ap.av.setColourByReferenceSeq(true);
1642 ap.av.getAlignment().setSeqrep(sequence);
1646 if (ap.av.getAlignment().getSeqrep() == sequence)
1648 ap.av.getAlignment().setSeqrep(null);
1652 ap.av.getAlignment().setSeqrep(sequence);
1658 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1660 if (sequence != null)
1662 ColumnSelection cs = ap.av.getColumnSelection();
1665 cs = new ColumnSelection();
1667 cs.hideInsertionsFor(sequence);
1668 ap.av.setColumnSelection(cs);
1673 protected void sequenceSelectionDetails_actionPerformed()
1675 createSequenceDetailsReport(ap.av.getSequenceSelection());
1678 protected void sequenceDetails_actionPerformed()
1680 createSequenceDetailsReport(new SequenceI[] { sequence });
1683 public void createSequenceDetailsReport(SequenceI[] sequences)
1685 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1686 StringBuilder contents = new StringBuilder(128);
1687 for (SequenceI seq : sequences)
1689 contents.append("<p><h2>"
1692 "label.create_sequence_details_report_annotation_for",
1693 new Object[] { seq.getDisplayId(true) })
1695 new SequenceAnnotationReport(null)
1696 .createSequenceAnnotationReport(
1701 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1702 .getSeqPanel().seqCanvas.fr.getMinMax()
1704 contents.append("</p>");
1706 cap.setText("<html>" + contents.toString() + "</html>");
1708 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1709 "label.sequence_details_for",
1710 (sequences.length == 1 ? new Object[] { sequences[0]
1711 .getDisplayId(true) } : new Object[] { MessageManager
1712 .getString("label.selection") })), 500, 400);
1716 protected void showNonconserved_actionPerformed()
1718 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1723 * call to refresh view after settings change
1727 ap.updateAnnotation();
1728 ap.paintAlignment(true);
1730 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1739 protected void clustalColour_actionPerformed()
1741 SequenceGroup sg = getGroup();
1742 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1752 protected void zappoColour_actionPerformed()
1754 getGroup().cs = new ZappoColourScheme();
1764 protected void taylorColour_actionPerformed()
1766 getGroup().cs = new TaylorColourScheme();
1776 protected void hydrophobicityColour_actionPerformed()
1778 getGroup().cs = new HydrophobicColourScheme();
1788 protected void helixColour_actionPerformed()
1790 getGroup().cs = new HelixColourScheme();
1800 protected void strandColour_actionPerformed()
1802 getGroup().cs = new StrandColourScheme();
1812 protected void turnColour_actionPerformed()
1814 getGroup().cs = new TurnColourScheme();
1824 protected void buriedColour_actionPerformed()
1826 getGroup().cs = new BuriedColourScheme();
1836 public void nucleotideMenuItem_actionPerformed()
1838 getGroup().cs = new NucleotideColourScheme();
1842 protected void purinePyrimidineColour_actionPerformed()
1844 getGroup().cs = new PurinePyrimidineColourScheme();
1849 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1850 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1858 protected void abovePIDColour_actionPerformed()
1860 SequenceGroup sg = getGroup();
1866 if (abovePIDColour.isSelected())
1868 sg.cs.setConsensus(AAFrequency.calculate(
1869 sg.getSequences(ap.av.getHiddenRepSequences()),
1870 sg.getStartRes(), sg.getEndRes() + 1));
1872 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1875 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1877 SliderPanel.showPIDSlider();
1880 // remove PIDColouring
1882 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1894 protected void userDefinedColour_actionPerformed(ActionEvent e)
1896 SequenceGroup sg = getGroup();
1898 if (e.getSource().equals(userDefinedColour))
1900 new UserDefinedColours(ap, sg);
1904 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1905 .getUserColourSchemes().get(e.getActionCommand());
1913 * Open a panel where the user can choose which types of sequence annotation
1918 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1920 // todo correct way to guard against opening a duplicate panel?
1921 new AnnotationChooser(ap);
1930 protected void PIDColour_actionPerformed()
1932 SequenceGroup sg = getGroup();
1933 sg.cs = new PIDColourScheme();
1934 sg.cs.setConsensus(AAFrequency.calculate(
1935 sg.getSequences(ap.av.getHiddenRepSequences()),
1936 sg.getStartRes(), sg.getEndRes() + 1));
1946 protected void BLOSUM62Colour_actionPerformed()
1948 SequenceGroup sg = getGroup();
1950 sg.cs = new Blosum62ColourScheme();
1952 sg.cs.setConsensus(AAFrequency.calculate(
1953 sg.getSequences(ap.av.getHiddenRepSequences()),
1954 sg.getStartRes(), sg.getEndRes() + 1));
1965 protected void noColourmenuItem_actionPerformed()
1967 getGroup().cs = null;
1977 protected void conservationMenuItem_actionPerformed()
1979 SequenceGroup sg = getGroup();
1985 if (conservationMenuItem.isSelected())
1987 // JBPNote: Conservation name shouldn't be i18n translated
1988 Conservation c = new Conservation("Group", sg.getSequences(ap.av
1989 .getHiddenRepSequences()), sg.getStartRes(),
1990 sg.getEndRes() + 1);
1993 c.verdict(false, ap.av.getConsPercGaps());
1995 sg.cs.setConservation(c);
1997 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1998 SliderPanel.showConservationSlider();
2001 // remove ConservationColouring
2003 sg.cs.setConservation(null);
2009 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2011 SequenceGroup sg = getGroup();
2017 AnnotationColourGradient acg = new AnnotationColourGradient(
2018 sequence.getAnnotation()[0], null,
2019 AnnotationColourGradient.NO_THRESHOLD);
2021 acg.setPredefinedColours(true);
2033 protected void groupName_actionPerformed()
2036 SequenceGroup sg = getGroup();
2037 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2038 sg.getDescription(), " "
2039 + MessageManager.getString("label.group_name") + " ",
2040 MessageManager.getString("label.group_description") + " ",
2041 MessageManager.getString("label.edit_group_name_description"),
2049 sg.setName(dialog.getName());
2050 sg.setDescription(dialog.getDescription());
2055 * Get selection group - adding it to the alignment if necessary.
2057 * @return sequence group to operate on
2059 SequenceGroup getGroup()
2061 SequenceGroup sg = ap.av.getSelectionGroup();
2062 // this method won't add a new group if it already exists
2065 ap.av.getAlignment().addGroup(sg);
2077 void sequenceName_actionPerformed()
2079 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2080 sequence.getDescription(),
2081 " " + MessageManager.getString("label.sequence_name")
2083 MessageManager.getString("label.sequence_description") + " ",
2085 .getString("label.edit_sequence_name_description"),
2093 if (dialog.getName() != null)
2095 if (dialog.getName().indexOf(" ") > -1)
2101 .getString("label.spaces_converted_to_backslashes"),
2103 .getString("label.no_spaces_allowed_sequence_name"),
2104 JvOptionPane.WARNING_MESSAGE);
2107 sequence.setName(dialog.getName().replace(' ', '_'));
2108 ap.paintAlignment(false);
2111 sequence.setDescription(dialog.getDescription());
2113 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2124 void unGroupMenuItem_actionPerformed()
2126 SequenceGroup sg = ap.av.getSelectionGroup();
2127 ap.av.getAlignment().deleteGroup(sg);
2128 ap.av.setSelectionGroup(null);
2132 void createGroupMenuItem_actionPerformed()
2134 getGroup(); // implicitly creates group - note - should apply defaults / use
2135 // standard alignment window logic for this
2145 protected void outline_actionPerformed()
2147 SequenceGroup sg = getGroup();
2148 Color col = JColorChooser.showDialog(this,
2149 MessageManager.getString("label.select_outline_colour"),
2154 sg.setOutlineColour(col);
2166 public void showBoxes_actionPerformed()
2168 getGroup().setDisplayBoxes(showBoxes.isSelected());
2178 public void showText_actionPerformed()
2180 getGroup().setDisplayText(showText.isSelected());
2190 public void showColourText_actionPerformed()
2192 getGroup().setColourText(showColourText.isSelected());
2196 public void showLink(String url)
2200 jalview.util.BrowserLauncher.openURL(url);
2201 } catch (Exception ex)
2203 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
2204 MessageManager.getString("label.web_browser_not_found_unix"),
2205 MessageManager.getString("label.web_browser_not_found"),
2206 JvOptionPane.WARNING_MESSAGE);
2208 ex.printStackTrace();
2212 void hideSequences(boolean representGroup)
2214 ap.av.hideSequences(sequence, representGroup);
2217 public void copy_actionPerformed()
2219 ap.alignFrame.copy_actionPerformed(null);
2222 public void cut_actionPerformed()
2224 ap.alignFrame.cut_actionPerformed(null);
2227 void changeCase(ActionEvent e)
2229 Object source = e.getSource();
2230 SequenceGroup sg = ap.av.getSelectionGroup();
2234 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2235 sg.getStartRes(), sg.getEndRes() + 1);
2240 if (source == toggle)
2242 description = MessageManager.getString("label.toggle_case");
2243 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2245 else if (source == upperCase)
2247 description = MessageManager.getString("label.to_upper_case");
2248 caseChange = ChangeCaseCommand.TO_UPPER;
2252 description = MessageManager.getString("label.to_lower_case");
2253 caseChange = ChangeCaseCommand.TO_LOWER;
2256 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2257 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2258 startEnd, caseChange);
2260 ap.alignFrame.addHistoryItem(caseCommand);
2262 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2268 public void outputText_actionPerformed(ActionEvent e)
2270 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2271 cap.setForInput(null);
2272 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2273 "label.alignment_output_command",
2274 new Object[] { e.getActionCommand() }), 600, 500);
2276 String[] omitHidden = null;
2278 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2279 // or we simply trust the user wants
2280 // wysiwig behaviour
2282 FileFormatI fileFormat = FileFormats.getInstance().forName(
2283 e.getActionCommand());
2284 cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2287 public void sequenceFeature_actionPerformed()
2289 SequenceGroup sg = ap.av.getSelectionGroup();
2295 int rsize = 0, gSize = sg.getSize();
2296 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2297 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2299 for (int i = 0; i < gSize; i++)
2301 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2302 int end = sg.findEndRes(sg.getSequenceAt(i));
2305 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2306 features[rsize] = new SequenceFeature(null, null, null, start, end,
2311 rseqs = new SequenceI[rsize];
2312 tfeatures = new SequenceFeature[rsize];
2313 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2314 System.arraycopy(features, 0, tfeatures, 0, rsize);
2315 features = tfeatures;
2317 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2318 features, true, ap))
2320 ap.alignFrame.setShowSeqFeatures(true);
2321 ap.highlightSearchResults(null);
2325 public void textColour_actionPerformed()
2327 SequenceGroup sg = getGroup();
2330 new TextColourChooser().chooseColour(ap, sg);
2334 public void colourByStructure(String pdbid)
2336 Annotation[] anots = ap.av.getStructureSelectionManager()
2337 .colourSequenceFromStructure(sequence, pdbid);
2339 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2340 "Coloured by " + pdbid, anots);
2342 ap.av.getAlignment().addAnnotation(an);
2343 an.createSequenceMapping(sequence, 0, true);
2344 // an.adjustForAlignment();
2345 ap.av.getAlignment().setAnnotationIndex(an, 0);
2347 ap.adjustAnnotationHeight();
2349 sequence.addAlignmentAnnotation(an);
2353 public void editSequence_actionPerformed(ActionEvent actionEvent)
2355 SequenceGroup sg = ap.av.getSelectionGroup();
2359 if (sequence == null)
2361 sequence = sg.getSequenceAt(0);
2364 EditNameDialog dialog = new EditNameDialog(
2365 sequence.getSequenceAsString(sg.getStartRes(),
2366 sg.getEndRes() + 1), null,
2367 MessageManager.getString("label.edit_sequence"), null,
2368 MessageManager.getString("label.edit_sequence"),
2373 EditCommand editCommand = new EditCommand(
2374 MessageManager.getString("label.edit_sequences"),
2375 Action.REPLACE, dialog.getName().replace(' ',
2376 ap.av.getGapCharacter()),
2377 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2378 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2380 ap.alignFrame.addHistoryItem(editCommand);
2382 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()