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.FileFormat;
42 import jalview.io.FileFormatI;
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.JOptionPane;
83 import javax.swing.JPopupMenu;
84 import javax.swing.JRadioButtonMenuItem;
90 * @version $Revision: 1.118 $
92 public class PopupMenu extends JPopupMenu
94 JMenu groupMenu = new JMenu();
96 JMenuItem groupName = new JMenuItem();
98 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
100 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
102 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
104 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
106 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
108 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
110 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
112 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
114 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
116 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
118 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
120 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
122 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
124 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
126 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
128 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
132 JMenu sequenceMenu = new JMenu();
134 JMenuItem sequenceName = new JMenuItem();
136 JMenuItem sequenceDetails = new JMenuItem();
138 JMenuItem sequenceSelDetails = new JMenuItem();
140 JMenuItem makeReferenceSeq = new JMenuItem();
142 JMenuItem chooseAnnotations = new JMenuItem();
146 JMenuItem createGroupMenuItem = new JMenuItem();
148 JMenuItem unGroupMenuItem = new JMenuItem();
150 JMenuItem outline = new JMenuItem();
152 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
154 JMenu colourMenu = new JMenu();
156 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
158 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
160 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
162 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
164 JMenu editMenu = new JMenu();
166 JMenuItem cut = new JMenuItem();
168 JMenuItem copy = new JMenuItem();
170 JMenuItem upperCase = new JMenuItem();
172 JMenuItem lowerCase = new JMenuItem();
174 JMenuItem toggle = new JMenuItem();
176 JMenu pdbMenu = new JMenu();
178 JMenu outputMenu = new JMenu();
180 JMenu seqShowAnnotationsMenu = new JMenu();
182 JMenu seqHideAnnotationsMenu = new JMenu();
184 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
185 MessageManager.getString("label.add_reference_annotations"));
187 JMenu groupShowAnnotationsMenu = new JMenu();
189 JMenu groupHideAnnotationsMenu = new JMenu();
191 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
192 MessageManager.getString("label.add_reference_annotations"));
194 JMenuItem sequenceFeature = new JMenuItem();
196 JMenuItem textColour = new JMenuItem();
198 JMenu jMenu1 = new JMenu();
200 JMenuItem pdbStructureDialog = new JMenuItem();
202 JMenu rnaStructureMenu = new JMenu();
204 JMenuItem editSequence = new JMenuItem();
206 JMenu groupLinksMenu;
208 JMenuItem hideInsertions = new JMenuItem();
211 * Creates a new PopupMenu object.
218 public PopupMenu(final AlignmentPanel ap, Sequence seq, List<String> links)
220 this(ap, seq, links, null);
230 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
231 List<String> links, List<String> groupLinks)
233 // /////////////////////////////////////////////////////////
234 // If this is activated from the sequence panel, the user may want to
235 // edit or annotate a particular residue. Therefore display the residue menu
237 // If from the IDPanel, we must display the sequence menu
238 // ////////////////////////////////////////////////////////
242 ButtonGroup colours = new ButtonGroup();
243 colours.add(noColourmenuItem);
244 colours.add(clustalColour);
245 colours.add(zappoColour);
246 colours.add(taylorColour);
247 colours.add(hydrophobicityColour);
248 colours.add(helixColour);
249 colours.add(strandColour);
250 colours.add(turnColour);
251 colours.add(buriedColour);
252 colours.add(abovePIDColour);
253 colours.add(userDefinedColour);
254 colours.add(PIDColour);
255 colours.add(BLOSUM62Colour);
256 colours.add(purinePyrimidineColour);
257 colours.add(RNAInteractionColour);
259 for (String ff : FileFormat.getWritableFormats(true))
261 JMenuItem item = new JMenuItem(ff);
263 item.addActionListener(new java.awt.event.ActionListener()
266 public void actionPerformed(ActionEvent e)
268 outputText_actionPerformed(e);
272 outputMenu.add(item);
276 * Build menus for annotation types that may be shown or hidden, and for
277 * 'reference annotations' that may be added to the alignment. First for the
278 * currently selected sequence (if there is one):
280 final List<SequenceI> selectedSequence = (seq == null ? Collections
281 .<SequenceI> emptyList() : Arrays.asList(seq));
282 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
283 seqHideAnnotationsMenu, selectedSequence);
284 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
288 * And repeat for the current selection group (if there is one):
290 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
291 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
293 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
294 groupHideAnnotationsMenu, selectedGroup);
295 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
301 } catch (Exception e)
309 sequenceMenu.setText(sequence.getName());
310 if (seq == ap.av.getAlignment().getSeqrep())
312 makeReferenceSeq.setText(MessageManager
313 .getString("action.unmark_as_reference"));
317 makeReferenceSeq.setText(MessageManager
318 .getString("action.set_as_reference"));
321 if (!ap.av.getAlignment().isNucleotide())
323 remove(rnaStructureMenu);
327 int origCount = rnaStructureMenu.getItemCount();
329 * add menu items to 2D-render any alignment or sequence secondary
330 * structure annotation
332 AlignmentAnnotation[] aas = ap.av.getAlignment()
333 .getAlignmentAnnotation();
336 for (final AlignmentAnnotation aa : aas)
338 if (aa.isValidStruc() && aa.sequenceRef == null)
341 * valid alignment RNA secondary structure annotation
343 menuItem = new JMenuItem();
344 menuItem.setText(MessageManager.formatMessage(
345 "label.2d_rna_structure_line",
346 new Object[] { aa.label }));
347 menuItem.addActionListener(new java.awt.event.ActionListener()
350 public void actionPerformed(ActionEvent e)
352 new AppVarna(seq, aa, ap);
355 rnaStructureMenu.add(menuItem);
360 if (seq.getAnnotation() != null)
362 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
363 for (final AlignmentAnnotation aa : seqAnns)
365 if (aa.isValidStruc())
368 * valid sequence RNA secondary structure annotation
370 // TODO: make rnastrucF a bit more nice
371 menuItem = new JMenuItem();
372 menuItem.setText(MessageManager.formatMessage(
373 "label.2d_rna_sequence_name",
374 new Object[] { seq.getName() }));
375 menuItem.addActionListener(new java.awt.event.ActionListener()
378 public void actionPerformed(ActionEvent e)
380 // TODO: VARNA does'nt print gaps in the sequence
381 new AppVarna(seq, aa, ap);
384 rnaStructureMenu.add(menuItem);
388 if (rnaStructureMenu.getItemCount() == origCount)
390 remove(rnaStructureMenu);
394 menuItem = new JMenuItem(
395 MessageManager.getString("action.hide_sequences"));
396 menuItem.addActionListener(new java.awt.event.ActionListener()
399 public void actionPerformed(ActionEvent e)
401 hideSequences(false);
406 if (ap.av.getSelectionGroup() != null
407 && ap.av.getSelectionGroup().getSize() > 1)
409 menuItem = new JMenuItem(MessageManager.formatMessage(
410 "label.represent_group_with",
411 new Object[] { seq.getName() }));
412 menuItem.addActionListener(new java.awt.event.ActionListener()
415 public void actionPerformed(ActionEvent e)
420 sequenceMenu.add(menuItem);
423 if (ap.av.hasHiddenRows())
425 final int index = ap.av.getAlignment().findIndex(seq);
427 if (ap.av.adjustForHiddenSeqs(index)
428 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
430 menuItem = new JMenuItem(
431 MessageManager.getString("action.reveal_sequences"));
432 menuItem.addActionListener(new ActionListener()
435 public void actionPerformed(ActionEvent e)
437 ap.av.showSequence(index);
438 if (ap.overviewPanel != null)
440 ap.overviewPanel.updateOverviewImage();
448 // for the case when no sequences are even visible
449 if (ap.av.hasHiddenRows())
452 menuItem = new JMenuItem(
453 MessageManager.getString("action.reveal_all"));
454 menuItem.addActionListener(new ActionListener()
457 public void actionPerformed(ActionEvent e)
459 ap.av.showAllHiddenSeqs();
460 if (ap.overviewPanel != null)
462 ap.overviewPanel.updateOverviewImage();
472 SequenceGroup sg = ap.av.getSelectionGroup();
473 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
474 .getGroups().contains(sg) : false;
476 if (sg != null && sg.getSize() > 0)
478 groupName.setText(MessageManager
479 .getString("label.edit_name_and_description_current_group"));
481 if (sg.cs instanceof ZappoColourScheme)
483 zappoColour.setSelected(true);
485 else if (sg.cs instanceof TaylorColourScheme)
487 taylorColour.setSelected(true);
489 else if (sg.cs instanceof PIDColourScheme)
491 PIDColour.setSelected(true);
493 else if (sg.cs instanceof Blosum62ColourScheme)
495 BLOSUM62Colour.setSelected(true);
497 else if (sg.cs instanceof UserColourScheme)
499 userDefinedColour.setSelected(true);
501 else if (sg.cs instanceof HydrophobicColourScheme)
503 hydrophobicityColour.setSelected(true);
505 else if (sg.cs instanceof HelixColourScheme)
507 helixColour.setSelected(true);
509 else if (sg.cs instanceof StrandColourScheme)
511 strandColour.setSelected(true);
513 else if (sg.cs instanceof TurnColourScheme)
515 turnColour.setSelected(true);
517 else if (sg.cs instanceof BuriedColourScheme)
519 buriedColour.setSelected(true);
521 else if (sg.cs instanceof ClustalxColourScheme)
523 clustalColour.setSelected(true);
525 else if (sg.cs instanceof PurinePyrimidineColourScheme)
527 purinePyrimidineColour.setSelected(true);
531 * else if (sg.cs instanceof CovariationColourScheme) {
532 * covariationColour.setSelected(true); }
536 noColourmenuItem.setSelected(true);
539 if (sg.cs != null && sg.cs.conservationApplied())
541 conservationMenuItem.setSelected(true);
543 displayNonconserved.setSelected(sg.getShowNonconserved());
544 showText.setSelected(sg.getDisplayText());
545 showColourText.setSelected(sg.getColourText());
546 showBoxes.setSelected(sg.getDisplayBoxes());
547 // add any groupURLs to the groupURL submenu and make it visible
548 if (groupLinks != null && groupLinks.size() > 0)
550 buildGroupURLMenu(sg, groupLinks);
552 // Add a 'show all structures' for the current selection
553 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
554 SequenceI sqass = null;
555 for (SequenceI sq : ap.av.getSequenceSelection())
557 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
558 if (pes != null && pes.size() > 0)
560 reppdb.put(pes.get(0).getId(), pes.get(0));
561 for (PDBEntry pe : pes)
563 pdbe.put(pe.getId(), pe);
573 final PDBEntry[] pe = pdbe.values().toArray(
574 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
575 new PDBEntry[reppdb.size()]);
576 final JMenuItem gpdbview, rpdbview;
581 groupMenu.setVisible(false);
582 editMenu.setVisible(false);
587 createGroupMenuItem.setVisible(true);
588 unGroupMenuItem.setVisible(false);
589 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
593 createGroupMenuItem.setVisible(false);
594 unGroupMenuItem.setVisible(true);
595 jMenu1.setText(MessageManager.getString("action.edit_group"));
600 sequenceMenu.setVisible(false);
601 pdbStructureDialog.setVisible(false);
602 rnaStructureMenu.setVisible(false);
605 if (links != null && links.size() > 0)
607 addFeatureLinks(seq, links);
612 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
617 void addFeatureLinks(final SequenceI seq, List<String> links)
619 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
620 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
622 for (String link : links)
624 UrlLink urlLink = null;
627 urlLink = new UrlLink(link);
628 } catch (Exception foo)
630 Cache.log.error("Exception for URLLink '" + link + "'", foo);
634 if (!urlLink.isValid())
636 Cache.log.error(urlLink.getInvalidMessage());
640 urlLink.createLinksFromSeq(seq, linkset);
643 addshowLinks(linkMenu, linkset.values());
645 // disable link menu if there are no valid entries
646 if (linkMenu.getItemCount() > 0)
648 linkMenu.setEnabled(true);
652 linkMenu.setEnabled(false);
655 if (sequence != null)
657 sequenceMenu.add(linkMenu);
669 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
670 * "All" is added first, followed by a separator. Then add any annotation
671 * types associated with the current selection. Separate menus are built for
672 * the selected sequence group (if any), and the selected sequence.
674 * Some annotation rows are always rendered together - these can be identified
675 * by a common graphGroup property > -1. Only one of each group will be marked
676 * as visible (to avoid duplication of the display). For such groups we add a
677 * composite type name, e.g.
679 * IUPredWS (Long), IUPredWS (Short)
683 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
684 List<SequenceI> forSequences)
686 showMenu.removeAll();
687 hideMenu.removeAll();
689 final List<String> all = Arrays.asList(new String[] { MessageManager
690 .getString("label.all") });
691 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
692 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
694 showMenu.addSeparator();
695 hideMenu.addSeparator();
697 final AlignmentAnnotation[] annotations = ap.getAlignment()
698 .getAlignmentAnnotation();
701 * Find shown/hidden annotations types, distinguished by source (calcId),
702 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
703 * the insertion order, which is the order of the annotations on the
706 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
707 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
708 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
709 AlignmentAnnotationUtils.asList(annotations), forSequences);
711 for (String calcId : hiddenTypes.keySet())
713 for (List<String> type : hiddenTypes.get(calcId))
715 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
719 // grey out 'show annotations' if none are hidden
720 showMenu.setEnabled(!hiddenTypes.isEmpty());
722 for (String calcId : shownTypes.keySet())
724 for (List<String> type : shownTypes.get(calcId))
726 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
730 // grey out 'hide annotations' if none are shown
731 hideMenu.setEnabled(!shownTypes.isEmpty());
735 * Returns a list of sequences - either the current selection group (if there
736 * is one), else the specified single sequence.
741 protected List<SequenceI> getSequenceScope(SequenceI seq)
743 List<SequenceI> forSequences = null;
744 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
745 if (selectionGroup != null && selectionGroup.getSize() > 0)
747 forSequences = selectionGroup.getSequences();
751 forSequences = seq == null ? Collections.<SequenceI> emptyList()
752 : Arrays.asList(seq);
758 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
761 * @param showOrHideMenu
763 * @param forSequences
764 * the sequences whose annotations may be shown or hidden
769 * if true this is a special label meaning 'All'
770 * @param actionIsShow
771 * if true, the select menu item action is to show the annotation
774 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
775 final List<SequenceI> forSequences, String calcId,
776 final List<String> types, final boolean allTypes,
777 final boolean actionIsShow)
779 String label = types.toString(); // [a, b, c]
780 label = label.substring(1, label.length() - 1); // a, b, c
781 final JMenuItem item = new JMenuItem(label);
782 item.setToolTipText(calcId);
783 item.addActionListener(new java.awt.event.ActionListener()
786 public void actionPerformed(ActionEvent e)
788 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
789 types, forSequences, allTypes, actionIsShow);
793 showOrHideMenu.add(item);
796 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
799 // TODO: usability: thread off the generation of group url content so root
801 // sequence only URLs
802 // ID/regex match URLs
803 groupLinksMenu = new JMenu(
804 MessageManager.getString("action.group_link"));
805 // three types of url that might be created.
806 JMenu[] linkMenus = new JMenu[] { null,
807 new JMenu(MessageManager.getString("action.ids")),
808 new JMenu(MessageManager.getString("action.sequences")),
809 new JMenu(MessageManager.getString("action.ids_sequences")) };
811 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
812 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
813 Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
814 for (int sq = 0; sq < seqs.length; sq++)
817 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
818 .findPosition(sg.getEndRes());
819 // just collect ids from dataset sequence
820 // TODO: check if IDs collected from selecton group intersects with the
821 // current selection, too
822 SequenceI sqi = seqs[sq];
823 while (sqi.getDatasetSequence() != null)
825 sqi = sqi.getDatasetSequence();
827 DBRefEntry[] dbr = sqi.getDBRefs();
828 if (dbr != null && dbr.length > 0)
830 for (int d = 0; d < dbr.length; d++)
832 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
833 Object[] sarray = commonDbrefs.get(src);
836 sarray = new Object[2];
837 sarray[0] = new int[] { 0 };
838 sarray[1] = new String[seqs.length];
840 commonDbrefs.put(src, sarray);
843 if (((String[]) sarray[1])[sq] == null)
846 || (dbr[d].getMap().locateMappedRange(start, end) != null))
848 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
849 ((int[]) sarray[0])[0]++;
855 // now create group links for all distinct ID/sequence sets.
856 boolean addMenu = false; // indicates if there are any group links to give
858 for (String link : groupLinks)
860 GroupUrlLink urlLink = null;
863 urlLink = new GroupUrlLink(link);
864 } catch (Exception foo)
866 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
870 if (!urlLink.isValid())
872 Cache.log.error(urlLink.getInvalidMessage());
875 final String label = urlLink.getLabel();
876 boolean usingNames = false;
877 // Now see which parts of the group apply for this URL
878 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
879 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
880 String[] seqstr, ids; // input to makeUrl
883 int numinput = ((int[]) idset[0])[0];
884 String[] allids = ((String[]) idset[1]);
885 seqstr = new String[numinput];
886 ids = new String[numinput];
887 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
889 if (allids[sq] != null)
891 ids[idcount] = allids[sq];
892 seqstr[idcount++] = idandseqs[1][sq];
898 // just use the id/seq set
899 seqstr = idandseqs[1];
903 // and try and make the groupURL!
905 Object[] urlset = null;
908 urlset = urlLink.makeUrlStubs(ids, seqstr,
909 "FromJalview" + System.currentTimeMillis(), false);
910 } catch (UrlStringTooLongException e)
915 int type = urlLink.getGroupURLType() & 3;
916 // first two bits ofurlLink type bitfield are sequenceids and sequences
917 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
918 addshowLink(linkMenus[type], label
919 + (((type & 1) == 1) ? ("("
920 + (usingNames ? "Names" : ltarget) + ")") : ""),
927 groupLinksMenu = new JMenu(
928 MessageManager.getString("action.group_link"));
929 for (int m = 0; m < linkMenus.length; m++)
931 if (linkMenus[m] != null
932 && linkMenus[m].getMenuComponentCount() > 0)
934 groupLinksMenu.add(linkMenus[m]);
938 groupMenu.add(groupLinksMenu);
942 private void addshowLinks(JMenu linkMenu, Collection<List<String>> linkset)
944 for (List<String> linkstrset : linkset)
946 // split linkstr into label and url
947 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
952 * add a show URL menu item to the given linkMenu
956 * - menu label string
960 private void addshowLink(JMenu linkMenu, String label, final String url)
962 JMenuItem item = new JMenuItem(label);
963 item.setToolTipText(MessageManager.formatMessage(
964 "label.open_url_param", new Object[] { url }));
965 item.addActionListener(new java.awt.event.ActionListener()
968 public void actionPerformed(ActionEvent e)
970 new Thread(new Runnable()
987 * add a late bound groupURL item to the given linkMenu
991 * - menu label string
992 * @param urlgenerator
993 * GroupURLLink used to generate URL
995 * Object array returned from the makeUrlStubs function.
997 private void addshowLink(JMenu linkMenu, String label,
998 final GroupUrlLink urlgenerator, final Object[] urlstub)
1000 JMenuItem item = new JMenuItem(label);
1001 item.setToolTipText(MessageManager.formatMessage(
1002 "label.open_url_seqs_param",
1003 new Object[] { urlgenerator.getUrl_prefix(),
1004 urlgenerator.getNumberInvolved(urlstub) }));
1005 // TODO: put in info about what is being sent.
1006 item.addActionListener(new ActionListener()
1009 public void actionPerformed(ActionEvent e)
1011 new Thread(new Runnable()
1019 showLink(urlgenerator.constructFrom(urlstub));
1020 } catch (UrlStringTooLongException e2)
1038 private void jbInit() throws Exception
1040 groupMenu.setText(MessageManager.getString("label.selection"));
1041 groupName.setText(MessageManager.getString("label.name"));
1042 groupName.addActionListener(new java.awt.event.ActionListener()
1045 public void actionPerformed(ActionEvent e)
1047 groupName_actionPerformed();
1050 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1051 sequenceName.setText(MessageManager
1052 .getString("label.edit_name_description"));
1053 sequenceName.addActionListener(new java.awt.event.ActionListener()
1056 public void actionPerformed(ActionEvent e)
1058 sequenceName_actionPerformed();
1061 chooseAnnotations.setText(MessageManager
1062 .getString("action.choose_annotations"));
1063 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1066 public void actionPerformed(ActionEvent e)
1068 chooseAnnotations_actionPerformed(e);
1071 sequenceDetails.setText(MessageManager
1072 .getString("label.sequence_details"));
1073 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1076 public void actionPerformed(ActionEvent e)
1078 sequenceDetails_actionPerformed();
1081 sequenceSelDetails.setText(MessageManager
1082 .getString("label.sequence_details"));
1084 .addActionListener(new java.awt.event.ActionListener()
1087 public void actionPerformed(ActionEvent e)
1089 sequenceSelectionDetails_actionPerformed();
1092 PIDColour.setFocusPainted(false);
1094 .setText(MessageManager.getString("action.remove_group"));
1095 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1098 public void actionPerformed(ActionEvent e)
1100 unGroupMenuItem_actionPerformed();
1103 createGroupMenuItem.setText(MessageManager
1104 .getString("action.create_group"));
1106 .addActionListener(new java.awt.event.ActionListener()
1109 public void actionPerformed(ActionEvent e)
1111 createGroupMenuItem_actionPerformed();
1115 outline.setText(MessageManager.getString("action.border_colour"));
1116 outline.addActionListener(new java.awt.event.ActionListener()
1119 public void actionPerformed(ActionEvent e)
1121 outline_actionPerformed();
1125 .setText(MessageManager.getString("label.nucleotide"));
1126 nucleotideMenuItem.addActionListener(new ActionListener()
1129 public void actionPerformed(ActionEvent e)
1131 nucleotideMenuItem_actionPerformed();
1134 colourMenu.setText(MessageManager.getString("label.group_colour"));
1135 showBoxes.setText(MessageManager.getString("action.boxes"));
1136 showBoxes.setState(true);
1137 showBoxes.addActionListener(new ActionListener()
1140 public void actionPerformed(ActionEvent e)
1142 showBoxes_actionPerformed();
1145 showText.setText(MessageManager.getString("action.text"));
1146 showText.setState(true);
1147 showText.addActionListener(new ActionListener()
1150 public void actionPerformed(ActionEvent e)
1152 showText_actionPerformed();
1155 showColourText.setText(MessageManager.getString("label.colour_text"));
1156 showColourText.addActionListener(new ActionListener()
1159 public void actionPerformed(ActionEvent e)
1161 showColourText_actionPerformed();
1164 displayNonconserved.setText(MessageManager
1165 .getString("label.show_non_conversed"));
1166 displayNonconserved.setState(true);
1167 displayNonconserved.addActionListener(new ActionListener()
1170 public void actionPerformed(ActionEvent e)
1172 showNonconserved_actionPerformed();
1175 editMenu.setText(MessageManager.getString("action.edit"));
1176 cut.setText(MessageManager.getString("action.cut"));
1177 cut.addActionListener(new ActionListener()
1180 public void actionPerformed(ActionEvent e)
1182 cut_actionPerformed();
1185 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1186 upperCase.addActionListener(new ActionListener()
1189 public void actionPerformed(ActionEvent e)
1194 copy.setText(MessageManager.getString("action.copy"));
1195 copy.addActionListener(new ActionListener()
1198 public void actionPerformed(ActionEvent e)
1200 copy_actionPerformed();
1203 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1204 lowerCase.addActionListener(new ActionListener()
1207 public void actionPerformed(ActionEvent e)
1212 toggle.setText(MessageManager.getString("label.toggle_case"));
1213 toggle.addActionListener(new ActionListener()
1216 public void actionPerformed(ActionEvent e)
1221 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1223 seqShowAnnotationsMenu.setText(MessageManager
1224 .getString("label.show_annotations"));
1225 seqHideAnnotationsMenu.setText(MessageManager
1226 .getString("label.hide_annotations"));
1227 groupShowAnnotationsMenu.setText(MessageManager
1228 .getString("label.show_annotations"));
1229 groupHideAnnotationsMenu.setText(MessageManager
1230 .getString("label.hide_annotations"));
1231 sequenceFeature.setText(MessageManager
1232 .getString("label.create_sequence_feature"));
1233 sequenceFeature.addActionListener(new ActionListener()
1236 public void actionPerformed(ActionEvent e)
1238 sequenceFeature_actionPerformed();
1241 textColour.setText(MessageManager.getString("label.text_colour"));
1242 textColour.addActionListener(new ActionListener()
1245 public void actionPerformed(ActionEvent e)
1247 textColour_actionPerformed();
1250 jMenu1.setText(MessageManager.getString("label.group"));
1251 pdbStructureDialog.setText(MessageManager
1252 .getString("label.show_pdbstruct_dialog"));
1253 pdbStructureDialog.addActionListener(new ActionListener()
1256 public void actionPerformed(ActionEvent actionEvent)
1258 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1259 if (ap.av.getSelectionGroup() != null)
1261 selectedSeqs = ap.av.getSequenceSelection();
1263 new StructureChooser(selectedSeqs, sequence, ap);
1267 rnaStructureMenu.setText(MessageManager
1268 .getString("label.view_rna_structure"));
1270 // colStructureMenu.setText("Colour By Structure");
1271 editSequence.setText(MessageManager.getString("label.edit_sequence")
1273 editSequence.addActionListener(new ActionListener()
1276 public void actionPerformed(ActionEvent actionEvent)
1278 editSequence_actionPerformed(actionEvent);
1281 makeReferenceSeq.setText(MessageManager
1282 .getString("label.mark_as_representative"));
1283 makeReferenceSeq.addActionListener(new ActionListener()
1287 public void actionPerformed(ActionEvent actionEvent)
1289 makeReferenceSeq_actionPerformed(actionEvent);
1293 hideInsertions.setText(MessageManager
1294 .getString("label.hide_insertions"));
1295 hideInsertions.addActionListener(new ActionListener()
1299 public void actionPerformed(ActionEvent e)
1301 hideInsertions_actionPerformed(e);
1305 * annotationMenuItem.setText("By Annotation");
1306 * annotationMenuItem.addActionListener(new ActionListener() { public void
1307 * actionPerformed(ActionEvent actionEvent) {
1308 * annotationMenuItem_actionPerformed(actionEvent); } });
1310 groupMenu.add(sequenceSelDetails);
1313 add(rnaStructureMenu);
1314 add(pdbStructureDialog);
1315 if (sequence != null)
1317 add(hideInsertions);
1319 // annotations configuration panel suppressed for now
1320 // groupMenu.add(chooseAnnotations);
1323 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1324 * (if a selection group is in force).
1326 sequenceMenu.add(seqShowAnnotationsMenu);
1327 sequenceMenu.add(seqHideAnnotationsMenu);
1328 sequenceMenu.add(seqAddReferenceAnnotations);
1329 groupMenu.add(groupShowAnnotationsMenu);
1330 groupMenu.add(groupHideAnnotationsMenu);
1331 groupMenu.add(groupAddReferenceAnnotations);
1332 groupMenu.add(editMenu);
1333 groupMenu.add(outputMenu);
1334 groupMenu.add(sequenceFeature);
1335 groupMenu.add(createGroupMenuItem);
1336 groupMenu.add(unGroupMenuItem);
1337 groupMenu.add(jMenu1);
1338 sequenceMenu.add(sequenceName);
1339 sequenceMenu.add(sequenceDetails);
1340 sequenceMenu.add(makeReferenceSeq);
1341 colourMenu.add(textColour);
1342 colourMenu.add(noColourmenuItem);
1343 colourMenu.add(clustalColour);
1344 colourMenu.add(BLOSUM62Colour);
1345 colourMenu.add(PIDColour);
1346 colourMenu.add(zappoColour);
1347 colourMenu.add(taylorColour);
1348 colourMenu.add(hydrophobicityColour);
1349 colourMenu.add(helixColour);
1350 colourMenu.add(strandColour);
1351 colourMenu.add(turnColour);
1352 colourMenu.add(buriedColour);
1353 colourMenu.add(nucleotideMenuItem);
1354 if (ap.getAlignment().isNucleotide())
1356 // JBPNote - commented since the colourscheme isn't functional
1357 colourMenu.add(purinePyrimidineColour);
1359 colourMenu.add(userDefinedColour);
1361 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1363 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1364 .getUserColourSchemes().keys();
1366 while (userColours.hasMoreElements())
1368 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1369 item.addActionListener(new ActionListener()
1372 public void actionPerformed(ActionEvent evt)
1374 userDefinedColour_actionPerformed(evt);
1377 colourMenu.add(item);
1381 colourMenu.addSeparator();
1382 colourMenu.add(abovePIDColour);
1383 colourMenu.add(conservationMenuItem);
1386 editMenu.add(editSequence);
1387 editMenu.add(upperCase);
1388 editMenu.add(lowerCase);
1389 editMenu.add(toggle);
1390 // JBPNote: These shouldn't be added here - should appear in a generic
1391 // 'apply web service to this sequence menu'
1392 // pdbMenu.add(RNAFold);
1393 // pdbMenu.add(ContraFold);
1394 jMenu1.add(groupName);
1395 jMenu1.add(colourMenu);
1396 jMenu1.add(showBoxes);
1397 jMenu1.add(showText);
1398 jMenu1.add(showColourText);
1399 jMenu1.add(outline);
1400 jMenu1.add(displayNonconserved);
1401 noColourmenuItem.setText(MessageManager.getString("label.none"));
1402 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1405 public void actionPerformed(ActionEvent e)
1407 noColourmenuItem_actionPerformed();
1411 clustalColour.setText(MessageManager
1412 .getString("label.clustalx_colours"));
1413 clustalColour.addActionListener(new java.awt.event.ActionListener()
1416 public void actionPerformed(ActionEvent e)
1418 clustalColour_actionPerformed();
1421 zappoColour.setText(MessageManager.getString("label.zappo"));
1422 zappoColour.addActionListener(new java.awt.event.ActionListener()
1425 public void actionPerformed(ActionEvent e)
1427 zappoColour_actionPerformed();
1430 taylorColour.setText(MessageManager.getString("label.taylor"));
1431 taylorColour.addActionListener(new java.awt.event.ActionListener()
1434 public void actionPerformed(ActionEvent e)
1436 taylorColour_actionPerformed();
1439 hydrophobicityColour.setText(MessageManager
1440 .getString("label.hydrophobicity"));
1441 hydrophobicityColour
1442 .addActionListener(new java.awt.event.ActionListener()
1445 public void actionPerformed(ActionEvent e)
1447 hydrophobicityColour_actionPerformed();
1450 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1451 helixColour.addActionListener(new java.awt.event.ActionListener()
1454 public void actionPerformed(ActionEvent e)
1456 helixColour_actionPerformed();
1459 strandColour.setText(MessageManager
1460 .getString("label.strand_propensity"));
1461 strandColour.addActionListener(new java.awt.event.ActionListener()
1464 public void actionPerformed(ActionEvent e)
1466 strandColour_actionPerformed();
1469 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1470 turnColour.addActionListener(new java.awt.event.ActionListener()
1473 public void actionPerformed(ActionEvent e)
1475 turnColour_actionPerformed();
1478 buriedColour.setText(MessageManager.getString("label.buried_index"));
1479 buriedColour.addActionListener(new java.awt.event.ActionListener()
1482 public void actionPerformed(ActionEvent e)
1484 buriedColour_actionPerformed();
1487 abovePIDColour.setText(MessageManager
1488 .getString("label.above_identity_percentage"));
1489 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1492 public void actionPerformed(ActionEvent e)
1494 abovePIDColour_actionPerformed();
1497 userDefinedColour.setText(MessageManager
1498 .getString("action.user_defined"));
1499 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1502 public void actionPerformed(ActionEvent e)
1504 userDefinedColour_actionPerformed(e);
1508 .setText(MessageManager.getString("label.percentage_identity"));
1509 PIDColour.addActionListener(new java.awt.event.ActionListener()
1512 public void actionPerformed(ActionEvent e)
1514 PIDColour_actionPerformed();
1517 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1518 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1521 public void actionPerformed(ActionEvent e)
1523 BLOSUM62Colour_actionPerformed();
1526 purinePyrimidineColour.setText(MessageManager
1527 .getString("label.purine_pyrimidine"));
1528 purinePyrimidineColour
1529 .addActionListener(new java.awt.event.ActionListener()
1532 public void actionPerformed(ActionEvent e)
1534 purinePyrimidineColour_actionPerformed();
1539 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1540 * public void actionPerformed(ActionEvent e) {
1541 * covariationColour_actionPerformed(); } });
1544 conservationMenuItem.setText(MessageManager
1545 .getString("label.conservation"));
1546 conservationMenuItem
1547 .addActionListener(new java.awt.event.ActionListener()
1550 public void actionPerformed(ActionEvent e)
1552 conservationMenuItem_actionPerformed();
1558 * Check for any annotations on the underlying dataset sequences (for the
1559 * current selection group) which are not 'on the alignment'.If any are found,
1560 * enable the option to add them to the alignment. The criteria for 'on the
1561 * alignment' is finding an alignment annotation on the alignment, matched on
1562 * calcId, label and sequenceRef.
1564 * A tooltip is also constructed that displays the source (calcId) and type
1565 * (label) of the annotations that can be added.
1568 * @param forSequences
1570 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1571 List<SequenceI> forSequences)
1573 menuItem.setEnabled(false);
1576 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1577 * Using TreeMap means calcIds are shown in alphabetical order.
1579 Map<String, String> tipEntries = new TreeMap<String, String>();
1580 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1581 AlignmentI al = this.ap.av.getAlignment();
1582 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1583 tipEntries, candidates, al);
1584 if (!candidates.isEmpty())
1586 StringBuilder tooltip = new StringBuilder(64);
1587 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1590 * Found annotations that could be added. Enable the menu item, and
1591 * configure its tooltip and action.
1593 menuItem.setEnabled(true);
1594 for (String calcId : tipEntries.keySet())
1596 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1598 String tooltipText = JvSwingUtils.wrapTooltip(true,
1599 tooltip.toString());
1600 menuItem.setToolTipText(tooltipText);
1602 menuItem.addActionListener(new ActionListener()
1605 public void actionPerformed(ActionEvent e)
1607 addReferenceAnnotations_actionPerformed(candidates);
1614 * Add annotations to the sequences and to the alignment.
1617 * a map whose keys are sequences on the alignment, and values a list
1618 * of annotations to add to each sequence
1620 protected void addReferenceAnnotations_actionPerformed(
1621 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1623 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1624 final AlignmentI alignment = this.ap.getAlignment();
1625 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1630 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1632 if (!ap.av.getAlignment().hasSeqrep())
1634 // initialise the display flags so the user sees something happen
1635 ap.av.setDisplayReferenceSeq(true);
1636 ap.av.setColourByReferenceSeq(true);
1637 ap.av.getAlignment().setSeqrep(sequence);
1641 if (ap.av.getAlignment().getSeqrep() == sequence)
1643 ap.av.getAlignment().setSeqrep(null);
1647 ap.av.getAlignment().setSeqrep(sequence);
1653 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1655 if (sequence != null)
1657 ColumnSelection cs = ap.av.getColumnSelection();
1660 cs = new ColumnSelection();
1662 cs.hideInsertionsFor(sequence);
1663 ap.av.setColumnSelection(cs);
1668 protected void sequenceSelectionDetails_actionPerformed()
1670 createSequenceDetailsReport(ap.av.getSequenceSelection());
1673 protected void sequenceDetails_actionPerformed()
1675 createSequenceDetailsReport(new SequenceI[] { sequence });
1678 public void createSequenceDetailsReport(SequenceI[] sequences)
1680 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1681 StringBuilder contents = new StringBuilder(128);
1682 for (SequenceI seq : sequences)
1684 contents.append("<p><h2>"
1687 "label.create_sequence_details_report_annotation_for",
1688 new Object[] { seq.getDisplayId(true) })
1690 new SequenceAnnotationReport(null)
1691 .createSequenceAnnotationReport(
1696 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1697 .getSeqPanel().seqCanvas.fr.getMinMax()
1699 contents.append("</p>");
1701 cap.setText("<html>" + contents.toString() + "</html>");
1703 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1704 "label.sequence_details_for",
1705 (sequences.length == 1 ? new Object[] { sequences[0]
1706 .getDisplayId(true) } : new Object[] { MessageManager
1707 .getString("label.selection") })), 500, 400);
1711 protected void showNonconserved_actionPerformed()
1713 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1718 * call to refresh view after settings change
1722 ap.updateAnnotation();
1723 ap.paintAlignment(true);
1725 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1734 protected void clustalColour_actionPerformed()
1736 SequenceGroup sg = getGroup();
1737 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1747 protected void zappoColour_actionPerformed()
1749 getGroup().cs = new ZappoColourScheme();
1759 protected void taylorColour_actionPerformed()
1761 getGroup().cs = new TaylorColourScheme();
1771 protected void hydrophobicityColour_actionPerformed()
1773 getGroup().cs = new HydrophobicColourScheme();
1783 protected void helixColour_actionPerformed()
1785 getGroup().cs = new HelixColourScheme();
1795 protected void strandColour_actionPerformed()
1797 getGroup().cs = new StrandColourScheme();
1807 protected void turnColour_actionPerformed()
1809 getGroup().cs = new TurnColourScheme();
1819 protected void buriedColour_actionPerformed()
1821 getGroup().cs = new BuriedColourScheme();
1831 public void nucleotideMenuItem_actionPerformed()
1833 getGroup().cs = new NucleotideColourScheme();
1837 protected void purinePyrimidineColour_actionPerformed()
1839 getGroup().cs = new PurinePyrimidineColourScheme();
1844 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1845 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1853 protected void abovePIDColour_actionPerformed()
1855 SequenceGroup sg = getGroup();
1861 if (abovePIDColour.isSelected())
1863 sg.cs.setConsensus(AAFrequency.calculate(
1864 sg.getSequences(ap.av.getHiddenRepSequences()),
1865 sg.getStartRes(), sg.getEndRes() + 1));
1867 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1870 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1872 SliderPanel.showPIDSlider();
1875 // remove PIDColouring
1877 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1889 protected void userDefinedColour_actionPerformed(ActionEvent e)
1891 SequenceGroup sg = getGroup();
1893 if (e.getSource().equals(userDefinedColour))
1895 new UserDefinedColours(ap, sg);
1899 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1900 .getUserColourSchemes().get(e.getActionCommand());
1908 * Open a panel where the user can choose which types of sequence annotation
1913 protected void chooseAnnotations_actionPerformed(ActionEvent e)
1915 // todo correct way to guard against opening a duplicate panel?
1916 new AnnotationChooser(ap);
1925 protected void PIDColour_actionPerformed()
1927 SequenceGroup sg = getGroup();
1928 sg.cs = new PIDColourScheme();
1929 sg.cs.setConsensus(AAFrequency.calculate(
1930 sg.getSequences(ap.av.getHiddenRepSequences()),
1931 sg.getStartRes(), sg.getEndRes() + 1));
1941 protected void BLOSUM62Colour_actionPerformed()
1943 SequenceGroup sg = getGroup();
1945 sg.cs = new Blosum62ColourScheme();
1947 sg.cs.setConsensus(AAFrequency.calculate(
1948 sg.getSequences(ap.av.getHiddenRepSequences()),
1949 sg.getStartRes(), sg.getEndRes() + 1));
1960 protected void noColourmenuItem_actionPerformed()
1962 getGroup().cs = null;
1972 protected void conservationMenuItem_actionPerformed()
1974 SequenceGroup sg = getGroup();
1980 if (conservationMenuItem.isSelected())
1982 // JBPNote: Conservation name shouldn't be i18n translated
1983 Conservation c = new Conservation("Group", sg.getSequences(ap.av
1984 .getHiddenRepSequences()), sg.getStartRes(),
1985 sg.getEndRes() + 1);
1988 c.verdict(false, ap.av.getConsPercGaps());
1990 sg.cs.setConservation(c);
1992 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1993 SliderPanel.showConservationSlider();
1996 // remove ConservationColouring
1998 sg.cs.setConservation(null);
2004 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2006 SequenceGroup sg = getGroup();
2012 AnnotationColourGradient acg = new AnnotationColourGradient(
2013 sequence.getAnnotation()[0], null,
2014 AnnotationColourGradient.NO_THRESHOLD);
2016 acg.setPredefinedColours(true);
2028 protected void groupName_actionPerformed()
2031 SequenceGroup sg = getGroup();
2032 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2033 sg.getDescription(), " "
2034 + MessageManager.getString("label.group_name") + " ",
2035 MessageManager.getString("label.group_description") + " ",
2036 MessageManager.getString("label.edit_group_name_description"),
2044 sg.setName(dialog.getName());
2045 sg.setDescription(dialog.getDescription());
2050 * Get selection group - adding it to the alignment if necessary.
2052 * @return sequence group to operate on
2054 SequenceGroup getGroup()
2056 SequenceGroup sg = ap.av.getSelectionGroup();
2057 // this method won't add a new group if it already exists
2060 ap.av.getAlignment().addGroup(sg);
2072 void sequenceName_actionPerformed()
2074 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2075 sequence.getDescription(),
2076 " " + MessageManager.getString("label.sequence_name")
2078 MessageManager.getString("label.sequence_description") + " ",
2080 .getString("label.edit_sequence_name_description"),
2088 if (dialog.getName() != null)
2090 if (dialog.getName().indexOf(" ") > -1)
2096 .getString("label.spaces_converted_to_backslashes"),
2098 .getString("label.no_spaces_allowed_sequence_name"),
2099 JvOptionPane.WARNING_MESSAGE);
2102 sequence.setName(dialog.getName().replace(' ', '_'));
2103 ap.paintAlignment(false);
2106 sequence.setDescription(dialog.getDescription());
2108 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2119 void unGroupMenuItem_actionPerformed()
2121 SequenceGroup sg = ap.av.getSelectionGroup();
2122 ap.av.getAlignment().deleteGroup(sg);
2123 ap.av.setSelectionGroup(null);
2127 void createGroupMenuItem_actionPerformed()
2129 getGroup(); // implicitly creates group - note - should apply defaults / use
2130 // standard alignment window logic for this
2140 protected void outline_actionPerformed()
2142 SequenceGroup sg = getGroup();
2143 Color col = JColorChooser.showDialog(this,
2144 MessageManager.getString("label.select_outline_colour"),
2149 sg.setOutlineColour(col);
2161 public void showBoxes_actionPerformed()
2163 getGroup().setDisplayBoxes(showBoxes.isSelected());
2173 public void showText_actionPerformed()
2175 getGroup().setDisplayText(showText.isSelected());
2185 public void showColourText_actionPerformed()
2187 getGroup().setColourText(showColourText.isSelected());
2191 public void showLink(String url)
2195 jalview.util.BrowserLauncher.openURL(url);
2196 } catch (Exception ex)
2198 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
2199 MessageManager.getString("label.web_browser_not_found_unix"),
2200 MessageManager.getString("label.web_browser_not_found"),
2201 JvOptionPane.WARNING_MESSAGE);
2203 ex.printStackTrace();
2207 void hideSequences(boolean representGroup)
2209 ap.av.hideSequences(sequence, representGroup);
2212 public void copy_actionPerformed()
2214 ap.alignFrame.copy_actionPerformed(null);
2217 public void cut_actionPerformed()
2219 ap.alignFrame.cut_actionPerformed(null);
2222 void changeCase(ActionEvent e)
2224 Object source = e.getSource();
2225 SequenceGroup sg = ap.av.getSelectionGroup();
2229 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2230 sg.getStartRes(), sg.getEndRes() + 1);
2235 if (source == toggle)
2237 description = MessageManager.getString("label.toggle_case");
2238 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2240 else if (source == upperCase)
2242 description = MessageManager.getString("label.to_upper_case");
2243 caseChange = ChangeCaseCommand.TO_UPPER;
2247 description = MessageManager.getString("label.to_lower_case");
2248 caseChange = ChangeCaseCommand.TO_LOWER;
2251 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2252 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2253 startEnd, caseChange);
2255 ap.alignFrame.addHistoryItem(caseCommand);
2257 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2263 public void outputText_actionPerformed(ActionEvent e)
2265 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2266 cap.setForInput(null);
2267 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2268 "label.alignment_output_command",
2269 new Object[] { e.getActionCommand() }), 600, 500);
2271 String[] omitHidden = null;
2273 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2274 // or we simply trust the user wants
2275 // wysiwig behaviour
2277 FileFormatI fileFormat = FileFormat.forName(e.getActionCommand());
2278 cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
2281 public void sequenceFeature_actionPerformed()
2283 SequenceGroup sg = ap.av.getSelectionGroup();
2289 int rsize = 0, gSize = sg.getSize();
2290 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2291 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2293 for (int i = 0; i < gSize; i++)
2295 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2296 int end = sg.findEndRes(sg.getSequenceAt(i));
2299 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2300 features[rsize] = new SequenceFeature(null, null, null, start, end,
2305 rseqs = new SequenceI[rsize];
2306 tfeatures = new SequenceFeature[rsize];
2307 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2308 System.arraycopy(features, 0, tfeatures, 0, rsize);
2309 features = tfeatures;
2311 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2312 features, true, ap))
2314 ap.alignFrame.setShowSeqFeatures(true);
2315 ap.highlightSearchResults(null);
2319 public void textColour_actionPerformed()
2321 SequenceGroup sg = getGroup();
2324 new TextColourChooser().chooseColour(ap, sg);
2328 public void colourByStructure(String pdbid)
2330 Annotation[] anots = ap.av.getStructureSelectionManager()
2331 .colourSequenceFromStructure(sequence, pdbid);
2333 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2334 "Coloured by " + pdbid, anots);
2336 ap.av.getAlignment().addAnnotation(an);
2337 an.createSequenceMapping(sequence, 0, true);
2338 // an.adjustForAlignment();
2339 ap.av.getAlignment().setAnnotationIndex(an, 0);
2341 ap.adjustAnnotationHeight();
2343 sequence.addAlignmentAnnotation(an);
2347 public void editSequence_actionPerformed(ActionEvent actionEvent)
2349 SequenceGroup sg = ap.av.getSelectionGroup();
2353 if (sequence == null)
2355 sequence = sg.getSequenceAt(0);
2358 EditNameDialog dialog = new EditNameDialog(
2359 sequence.getSequenceAsString(sg.getStartRes(),
2360 sg.getEndRes() + 1), null,
2361 MessageManager.getString("label.edit_sequence"), null,
2362 MessageManager.getString("label.edit_sequence"),
2367 EditCommand editCommand = new EditCommand(
2368 MessageManager.getString("label.edit_sequences"),
2369 Action.REPLACE, dialog.getName().replace(' ',
2370 ap.av.getGapCharacter()),
2371 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2372 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2374 ap.alignFrame.addHistoryItem(editCommand);
2376 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()