2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.bin.Cache;
28 import jalview.commands.ChangeCaseCommand;
29 import jalview.commands.EditCommand;
30 import jalview.commands.EditCommand.Action;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.Annotation;
34 import jalview.datamodel.ColumnSelection;
35 import jalview.datamodel.DBRefEntry;
36 import jalview.datamodel.PDBEntry;
37 import jalview.datamodel.Sequence;
38 import jalview.datamodel.SequenceFeature;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.io.FormatAdapter;
42 import jalview.io.SequenceAnnotationReport;
43 import jalview.schemes.AnnotationColourGradient;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.BuriedColourScheme;
46 import jalview.schemes.ClustalxColourScheme;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.HydrophobicColourScheme;
49 import jalview.schemes.NucleotideColourScheme;
50 import jalview.schemes.PIDColourScheme;
51 import jalview.schemes.PurinePyrimidineColourScheme;
52 import jalview.schemes.StrandColourScheme;
53 import jalview.schemes.TaylorColourScheme;
54 import jalview.schemes.TurnColourScheme;
55 import jalview.schemes.UserColourScheme;
56 import jalview.schemes.ZappoColourScheme;
57 import jalview.util.GroupUrlLink;
58 import jalview.util.GroupUrlLink.UrlStringTooLongException;
59 import jalview.util.MessageManager;
60 import jalview.util.UrlLink;
62 import java.awt.Color;
63 import java.awt.event.ActionEvent;
64 import java.awt.event.ActionListener;
65 import java.util.Arrays;
66 import java.util.Collection;
67 import java.util.Collections;
68 import java.util.Hashtable;
69 import java.util.LinkedHashMap;
70 import java.util.List;
72 import java.util.TreeMap;
73 import java.util.Vector;
75 import javax.swing.ButtonGroup;
76 import javax.swing.JCheckBoxMenuItem;
77 import javax.swing.JColorChooser;
78 import javax.swing.JMenu;
79 import javax.swing.JMenuItem;
80 import javax.swing.JOptionPane;
81 import javax.swing.JPopupMenu;
82 import javax.swing.JRadioButtonMenuItem;
88 * @version $Revision: 1.118 $
90 public class PopupMenu extends JPopupMenu
92 JMenu groupMenu = new JMenu();
94 JMenuItem groupName = new JMenuItem();
96 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
98 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
100 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
102 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
104 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
106 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
108 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
110 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
112 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
114 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
116 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
118 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
120 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
122 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
124 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
126 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
130 JMenu sequenceMenu = new JMenu();
132 JMenuItem sequenceName = new JMenuItem();
134 JMenuItem sequenceDetails = new JMenuItem();
136 JMenuItem sequenceSelDetails = new JMenuItem();
138 JMenuItem makeReferenceSeq = new JMenuItem();
140 JMenuItem chooseAnnotations = new JMenuItem();
144 JMenuItem createGroupMenuItem = new JMenuItem();
146 JMenuItem unGroupMenuItem = new JMenuItem();
148 JMenuItem outline = new JMenuItem();
150 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
152 JMenu colourMenu = new JMenu();
154 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
156 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
158 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
160 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
162 JMenu editMenu = new JMenu();
164 JMenuItem cut = new JMenuItem();
166 JMenuItem copy = new JMenuItem();
168 JMenuItem upperCase = new JMenuItem();
170 JMenuItem lowerCase = new JMenuItem();
172 JMenuItem toggle = new JMenuItem();
174 JMenu pdbMenu = new JMenu();
176 JMenu outputMenu = new JMenu();
178 JMenu seqShowAnnotationsMenu = new JMenu();
180 JMenu seqHideAnnotationsMenu = new JMenu();
182 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
183 MessageManager.getString("label.add_reference_annotations"));
185 JMenu groupShowAnnotationsMenu = new JMenu();
187 JMenu groupHideAnnotationsMenu = new JMenu();
189 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
190 MessageManager.getString("label.add_reference_annotations"));
192 JMenuItem sequenceFeature = new JMenuItem();
194 JMenuItem textColour = new JMenuItem();
196 JMenu jMenu1 = new JMenu();
198 JMenuItem pdbStructureDialog = new JMenuItem();
200 JMenu rnaStructureMenu = new JMenu();
202 JMenuItem editSequence = new JMenuItem();
204 JMenu groupLinksMenu;
206 JMenuItem hideInsertions = new JMenuItem();
209 * Creates a new PopupMenu object.
216 public PopupMenu(final AlignmentPanel ap, Sequence seq, List<String> links)
218 this(ap, seq, links, null);
228 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
229 List<String> links, List<String> groupLinks)
231 // /////////////////////////////////////////////////////////
232 // If this is activated from the sequence panel, the user may want to
233 // edit or annotate a particular residue. Therefore display the residue menu
235 // If from the IDPanel, we must display the sequence menu
236 // ////////////////////////////////////////////////////////
240 ButtonGroup colours = new ButtonGroup();
241 colours.add(noColourmenuItem);
242 colours.add(clustalColour);
243 colours.add(zappoColour);
244 colours.add(taylorColour);
245 colours.add(hydrophobicityColour);
246 colours.add(helixColour);
247 colours.add(strandColour);
248 colours.add(turnColour);
249 colours.add(buriedColour);
250 colours.add(abovePIDColour);
251 colours.add(userDefinedColour);
252 colours.add(PIDColour);
253 colours.add(BLOSUM62Colour);
254 colours.add(purinePyrimidineColour);
255 colours.add(RNAInteractionColour);
257 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
259 JMenuItem item = new JMenuItem(
260 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
262 item.addActionListener(new java.awt.event.ActionListener()
265 public void actionPerformed(ActionEvent e)
267 outputText_actionPerformed(e);
271 outputMenu.add(item);
275 * Build menus for annotation types that may be shown or hidden, and for
276 * 'reference annotations' that may be added to the alignment. First for the
277 * currently selected sequence (if there is one):
279 final List<SequenceI> selectedSequence = (seq == null ? Collections
280 .<SequenceI> emptyList() : Arrays.asList(seq));
281 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
282 seqHideAnnotationsMenu, selectedSequence);
283 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
287 * And repeat for the current selection group (if there is one):
289 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
290 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
292 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
293 groupHideAnnotationsMenu, selectedGroup);
294 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
300 } catch (Exception e)
308 sequenceMenu.setText(sequence.getName());
309 if (seq == ap.av.getAlignment().getSeqrep())
311 makeReferenceSeq.setText(MessageManager
312 .getString("action.unmark_as_reference"));
316 makeReferenceSeq.setText(MessageManager
317 .getString("action.set_as_reference"));
320 if (!ap.av.getAlignment().isNucleotide())
322 remove(rnaStructureMenu);
326 int origCount = rnaStructureMenu.getItemCount();
328 * add menu items to 2D-render any alignment or sequence secondary
329 * structure annotation
331 AlignmentAnnotation[] aas = ap.av.getAlignment()
332 .getAlignmentAnnotation();
335 for (final AlignmentAnnotation aa : aas)
337 if (aa.isValidStruc() && aa.sequenceRef == null)
340 * valid alignment RNA secondary structure annotation
342 menuItem = new JMenuItem();
343 menuItem.setText(MessageManager.formatMessage(
344 "label.2d_rna_structure_line",
345 new Object[] { aa.label }));
346 menuItem.addActionListener(new java.awt.event.ActionListener()
349 public void actionPerformed(ActionEvent e)
351 new AppVarna(seq, aa, ap);
354 rnaStructureMenu.add(menuItem);
359 if (seq.getAnnotation() != null)
361 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
362 for (final AlignmentAnnotation aa : seqAnns)
364 if (aa.isValidStruc())
367 * valid sequence RNA secondary structure annotation
369 // TODO: make rnastrucF a bit more nice
370 menuItem = new JMenuItem();
371 menuItem.setText(MessageManager.formatMessage(
372 "label.2d_rna_sequence_name",
373 new Object[] { seq.getName() }));
374 menuItem.addActionListener(new java.awt.event.ActionListener()
377 public void actionPerformed(ActionEvent e)
379 // TODO: VARNA does'nt print gaps in the sequence
380 new AppVarna(seq, aa, ap);
383 rnaStructureMenu.add(menuItem);
387 if (rnaStructureMenu.getItemCount() == origCount)
389 remove(rnaStructureMenu);
393 menuItem = new JMenuItem(
394 MessageManager.getString("action.hide_sequences"));
395 menuItem.addActionListener(new java.awt.event.ActionListener()
398 public void actionPerformed(ActionEvent e)
400 hideSequences(false);
405 if (ap.av.getSelectionGroup() != null
406 && ap.av.getSelectionGroup().getSize() > 1)
408 menuItem = new JMenuItem(MessageManager.formatMessage(
409 "label.represent_group_with",
410 new Object[] { seq.getName() }));
411 menuItem.addActionListener(new java.awt.event.ActionListener()
414 public void actionPerformed(ActionEvent e)
419 sequenceMenu.add(menuItem);
422 if (ap.av.hasHiddenRows())
424 final int index = ap.av.getAlignment().findIndex(seq);
426 if (ap.av.adjustForHiddenSeqs(index)
427 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
429 menuItem = new JMenuItem(
430 MessageManager.getString("action.reveal_sequences"));
431 menuItem.addActionListener(new ActionListener()
434 public void actionPerformed(ActionEvent e)
436 ap.av.showSequence(index);
437 if (ap.overviewPanel != null)
439 ap.overviewPanel.updateOverviewImage();
447 // for the case when no sequences are even visible
448 if (ap.av.hasHiddenRows())
451 menuItem = new JMenuItem(
452 MessageManager.getString("action.reveal_all"));
453 menuItem.addActionListener(new ActionListener()
456 public void actionPerformed(ActionEvent e)
458 ap.av.showAllHiddenSeqs();
459 if (ap.overviewPanel != null)
461 ap.overviewPanel.updateOverviewImage();
471 SequenceGroup sg = ap.av.getSelectionGroup();
472 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
473 .getGroups().contains(sg) : false;
475 if (sg != null && sg.getSize() > 0)
477 groupName.setText(MessageManager
478 .getString("label.edit_name_and_description_current_group"));
480 if (sg.cs instanceof ZappoColourScheme)
482 zappoColour.setSelected(true);
484 else if (sg.cs instanceof TaylorColourScheme)
486 taylorColour.setSelected(true);
488 else if (sg.cs instanceof PIDColourScheme)
490 PIDColour.setSelected(true);
492 else if (sg.cs instanceof Blosum62ColourScheme)
494 BLOSUM62Colour.setSelected(true);
496 else if (sg.cs instanceof UserColourScheme)
498 userDefinedColour.setSelected(true);
500 else if (sg.cs instanceof HydrophobicColourScheme)
502 hydrophobicityColour.setSelected(true);
504 else if (sg.cs instanceof HelixColourScheme)
506 helixColour.setSelected(true);
508 else if (sg.cs instanceof StrandColourScheme)
510 strandColour.setSelected(true);
512 else if (sg.cs instanceof TurnColourScheme)
514 turnColour.setSelected(true);
516 else if (sg.cs instanceof BuriedColourScheme)
518 buriedColour.setSelected(true);
520 else if (sg.cs instanceof ClustalxColourScheme)
522 clustalColour.setSelected(true);
524 else if (sg.cs instanceof PurinePyrimidineColourScheme)
526 purinePyrimidineColour.setSelected(true);
530 * else if (sg.cs instanceof CovariationColourScheme) {
531 * covariationColour.setSelected(true); }
535 noColourmenuItem.setSelected(true);
538 if (sg.cs != null && sg.cs.conservationApplied())
540 conservationMenuItem.setSelected(true);
542 displayNonconserved.setSelected(sg.getShowNonconserved());
543 showText.setSelected(sg.getDisplayText());
544 showColourText.setSelected(sg.getColourText());
545 showBoxes.setSelected(sg.getDisplayBoxes());
546 // add any groupURLs to the groupURL submenu and make it visible
547 if (groupLinks != null && groupLinks.size() > 0)
549 buildGroupURLMenu(sg, groupLinks);
551 // Add a 'show all structures' for the current selection
552 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
553 SequenceI sqass = null;
554 for (SequenceI sq : ap.av.getSequenceSelection())
556 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
557 if (pes != null && pes.size() > 0)
559 reppdb.put(pes.get(0).getId(), pes.get(0));
560 for (PDBEntry pe : pes)
562 pdbe.put(pe.getId(), pe);
572 final PDBEntry[] pe = pdbe.values().toArray(
573 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
574 new PDBEntry[reppdb.size()]);
575 final JMenuItem gpdbview, rpdbview;
580 groupMenu.setVisible(false);
581 editMenu.setVisible(false);
586 createGroupMenuItem.setVisible(true);
587 unGroupMenuItem.setVisible(false);
588 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
592 createGroupMenuItem.setVisible(false);
593 unGroupMenuItem.setVisible(true);
594 jMenu1.setText(MessageManager.getString("action.edit_group"));
599 sequenceMenu.setVisible(false);
600 pdbStructureDialog.setVisible(false);
601 rnaStructureMenu.setVisible(false);
604 if (links != null && links.size() > 0)
606 addFeatureLinks(seq, links);
611 * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
616 void addFeatureLinks(final SequenceI seq, List<String> links)
618 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
619 Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
621 for (String link : links)
623 UrlLink urlLink = null;
626 urlLink = new UrlLink(link);
627 } catch (Exception foo)
629 Cache.log.error("Exception for URLLink '" + link + "'", foo);
633 if (!urlLink.isValid())
635 Cache.log.error(urlLink.getInvalidMessage());
639 urlLink.createLinksFromSeq(seq, linkset);
642 addshowLinks(linkMenu, linkset.values());
644 // disable link menu if there are no valid entries
645 if (linkMenu.getItemCount() > 0)
647 linkMenu.setEnabled(true);
651 linkMenu.setEnabled(false);
654 if (sequence != null)
656 sequenceMenu.add(linkMenu);
668 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
669 * "All" is added first, followed by a separator. Then add any annotation
670 * types associated with the current selection. Separate menus are built for
671 * the selected sequence group (if any), and the selected sequence.
673 * Some annotation rows are always rendered together - these can be identified
674 * by a common graphGroup property > -1. Only one of each group will be marked
675 * as visible (to avoid duplication of the display). For such groups we add a
676 * composite type name, e.g.
678 * IUPredWS (Long), IUPredWS (Short)
682 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
683 List<SequenceI> forSequences)
685 showMenu.removeAll();
686 hideMenu.removeAll();
688 final List<String> all = Arrays.asList(new String[] { MessageManager
689 .getString("label.all") });
690 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
691 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
693 showMenu.addSeparator();
694 hideMenu.addSeparator();
696 final AlignmentAnnotation[] annotations = ap.getAlignment()
697 .getAlignmentAnnotation();
700 * Find shown/hidden annotations types, distinguished by source (calcId),
701 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
702 * the insertion order, which is the order of the annotations on the
705 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
706 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
707 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
708 AlignmentAnnotationUtils.asList(annotations), forSequences);
710 for (String calcId : hiddenTypes.keySet())
712 for (List<String> type : hiddenTypes.get(calcId))
714 addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
718 // grey out 'show annotations' if none are hidden
719 showMenu.setEnabled(!hiddenTypes.isEmpty());
721 for (String calcId : shownTypes.keySet())
723 for (List<String> type : shownTypes.get(calcId))
725 addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
729 // grey out 'hide annotations' if none are shown
730 hideMenu.setEnabled(!shownTypes.isEmpty());
734 * Returns a list of sequences - either the current selection group (if there
735 * is one), else the specified single sequence.
740 protected List<SequenceI> getSequenceScope(SequenceI seq)
742 List<SequenceI> forSequences = null;
743 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
744 if (selectionGroup != null && selectionGroup.getSize() > 0)
746 forSequences = selectionGroup.getSequences();
750 forSequences = seq == null ? Collections.<SequenceI> emptyList()
751 : Arrays.asList(seq);
757 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
760 * @param showOrHideMenu
762 * @param forSequences
763 * the sequences whose annotations may be shown or hidden
768 * if true this is a special label meaning 'All'
769 * @param actionIsShow
770 * if true, the select menu item action is to show the annotation
773 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
774 final List<SequenceI> forSequences, String calcId,
775 final List<String> types, final boolean allTypes,
776 final boolean actionIsShow)
778 String label = types.toString(); // [a, b, c]
779 label = label.substring(1, label.length() - 1); // a, b, c
780 final JMenuItem item = new JMenuItem(label);
781 item.setToolTipText(calcId);
782 item.addActionListener(new java.awt.event.ActionListener()
785 public void actionPerformed(ActionEvent e)
787 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
788 types, forSequences, allTypes, actionIsShow);
792 showOrHideMenu.add(item);
795 private void buildGroupURLMenu(SequenceGroup sg, List<String> groupLinks)
798 // TODO: usability: thread off the generation of group url content so root
800 // sequence only URLs
801 // ID/regex match URLs
802 groupLinksMenu = new JMenu(
803 MessageManager.getString("action.group_link"));
804 // three types of url that might be created.
805 JMenu[] linkMenus = new JMenu[] { null,
806 new JMenu(MessageManager.getString("action.ids")),
807 new JMenu(MessageManager.getString("action.sequences")),
808 new JMenu(MessageManager.getString("action.ids_sequences")) };
810 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
811 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
812 Hashtable<String, Object[]> commonDbrefs = new Hashtable<String, Object[]>();
813 for (int sq = 0; sq < seqs.length; sq++)
816 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
817 .findPosition(sg.getEndRes());
818 // just collect ids from dataset sequence
819 // TODO: check if IDs collected from selecton group intersects with the
820 // current selection, too
821 SequenceI sqi = seqs[sq];
822 while (sqi.getDatasetSequence() != null)
824 sqi = sqi.getDatasetSequence();
826 DBRefEntry[] dbr = sqi.getDBRefs();
827 if (dbr != null && dbr.length > 0)
829 for (int d = 0; d < dbr.length; d++)
831 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
832 Object[] sarray = commonDbrefs.get(src);
835 sarray = new Object[2];
836 sarray[0] = new int[] { 0 };
837 sarray[1] = new String[seqs.length];
839 commonDbrefs.put(src, sarray);
842 if (((String[]) sarray[1])[sq] == null)
845 || (dbr[d].getMap().locateMappedRange(start, end) != null))
847 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
848 ((int[]) sarray[0])[0]++;
854 // now create group links for all distinct ID/sequence sets.
855 boolean addMenu = false; // indicates if there are any group links to give
857 for (String link : groupLinks)
859 GroupUrlLink urlLink = null;
862 urlLink = new GroupUrlLink(link);
863 } catch (Exception foo)
865 Cache.log.error("Exception for GroupURLLink '" + link + "'", foo);
869 if (!urlLink.isValid())
871 Cache.log.error(urlLink.getInvalidMessage());
874 final String label = urlLink.getLabel();
875 boolean usingNames = false;
876 // Now see which parts of the group apply for this URL
877 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
878 Object[] idset = commonDbrefs.get(ltarget.toUpperCase());
879 String[] seqstr, ids; // input to makeUrl
882 int numinput = ((int[]) idset[0])[0];
883 String[] allids = ((String[]) idset[1]);
884 seqstr = new String[numinput];
885 ids = new String[numinput];
886 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
888 if (allids[sq] != null)
890 ids[idcount] = allids[sq];
891 seqstr[idcount++] = idandseqs[1][sq];
897 // just use the id/seq set
898 seqstr = idandseqs[1];
902 // and try and make the groupURL!
904 Object[] urlset = null;
907 urlset = urlLink.makeUrlStubs(ids, seqstr,
908 "FromJalview" + System.currentTimeMillis(), false);
909 } catch (UrlStringTooLongException e)
914 int type = urlLink.getGroupURLType() & 3;
915 // first two bits ofurlLink type bitfield are sequenceids and sequences
916 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
917 addshowLink(linkMenus[type], label
918 + (((type & 1) == 1) ? ("("
919 + (usingNames ? "Names" : ltarget) + ")") : ""),
926 groupLinksMenu = new JMenu(
927 MessageManager.getString("action.group_link"));
928 for (int m = 0; m < linkMenus.length; m++)
930 if (linkMenus[m] != null
931 && linkMenus[m].getMenuComponentCount() > 0)
933 groupLinksMenu.add(linkMenus[m]);
937 groupMenu.add(groupLinksMenu);
941 private void addshowLinks(JMenu linkMenu, Collection<List<String>> linkset)
943 for (List<String> linkstrset : linkset)
945 // split linkstr into label and url
946 addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
951 * add a show URL menu item to the given linkMenu
955 * - menu label string
959 private void addshowLink(JMenu linkMenu, String label, final String url)
961 JMenuItem item = new JMenuItem(label);
962 item.setToolTipText(MessageManager.formatMessage(
963 "label.open_url_param", new Object[] { url }));
964 item.addActionListener(new java.awt.event.ActionListener()
967 public void actionPerformed(ActionEvent e)
969 new Thread(new Runnable()
986 * add a late bound groupURL item to the given linkMenu
990 * - menu label string
991 * @param urlgenerator
992 * GroupURLLink used to generate URL
994 * Object array returned from the makeUrlStubs function.
996 private void addshowLink(JMenu linkMenu, String label,
997 final GroupUrlLink urlgenerator, final Object[] urlstub)
999 JMenuItem item = new JMenuItem(label);
1000 item.setToolTipText(MessageManager.formatMessage(
1001 "label.open_url_seqs_param",
1002 new Object[] { urlgenerator.getUrl_prefix(),
1003 urlgenerator.getNumberInvolved(urlstub) }));
1004 // TODO: put in info about what is being sent.
1005 item.addActionListener(new ActionListener()
1008 public void actionPerformed(ActionEvent e)
1010 new Thread(new Runnable()
1018 showLink(urlgenerator.constructFrom(urlstub));
1019 } catch (UrlStringTooLongException e2)
1037 private void jbInit() throws Exception
1039 groupMenu.setText(MessageManager.getString("label.selection"));
1040 groupName.setText(MessageManager.getString("label.name"));
1041 groupName.addActionListener(new java.awt.event.ActionListener()
1044 public void actionPerformed(ActionEvent e)
1046 groupName_actionPerformed();
1049 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1050 sequenceName.setText(MessageManager
1051 .getString("label.edit_name_description"));
1052 sequenceName.addActionListener(new java.awt.event.ActionListener()
1055 public void actionPerformed(ActionEvent e)
1057 sequenceName_actionPerformed();
1060 chooseAnnotations.setText(MessageManager
1061 .getString("action.choose_annotations"));
1062 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1065 public void actionPerformed(ActionEvent e)
1067 chooseAnnotations_actionPerformed(e);
1070 sequenceDetails.setText(MessageManager
1071 .getString("label.sequence_details"));
1072 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1075 public void actionPerformed(ActionEvent e)
1077 sequenceDetails_actionPerformed();
1080 sequenceSelDetails.setText(MessageManager
1081 .getString("label.sequence_details"));
1083 .addActionListener(new java.awt.event.ActionListener()
1086 public void actionPerformed(ActionEvent e)
1088 sequenceSelectionDetails_actionPerformed();
1091 PIDColour.setFocusPainted(false);
1093 .setText(MessageManager.getString("action.remove_group"));
1094 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1097 public void actionPerformed(ActionEvent e)
1099 unGroupMenuItem_actionPerformed();
1102 createGroupMenuItem.setText(MessageManager
1103 .getString("action.create_group"));
1105 .addActionListener(new java.awt.event.ActionListener()
1108 public void actionPerformed(ActionEvent e)
1110 createGroupMenuItem_actionPerformed();
1114 outline.setText(MessageManager.getString("action.border_colour"));
1115 outline.addActionListener(new java.awt.event.ActionListener()
1118 public void actionPerformed(ActionEvent e)
1120 outline_actionPerformed();
1124 .setText(MessageManager.getString("label.nucleotide"));
1125 nucleotideMenuItem.addActionListener(new ActionListener()
1128 public void actionPerformed(ActionEvent e)
1130 nucleotideMenuItem_actionPerformed();
1133 colourMenu.setText(MessageManager.getString("label.group_colour"));
1134 showBoxes.setText(MessageManager.getString("action.boxes"));
1135 showBoxes.setState(true);
1136 showBoxes.addActionListener(new ActionListener()
1139 public void actionPerformed(ActionEvent e)
1141 showBoxes_actionPerformed();
1144 showText.setText(MessageManager.getString("action.text"));
1145 showText.setState(true);
1146 showText.addActionListener(new ActionListener()
1149 public void actionPerformed(ActionEvent e)
1151 showText_actionPerformed();
1154 showColourText.setText(MessageManager.getString("label.colour_text"));
1155 showColourText.addActionListener(new ActionListener()
1158 public void actionPerformed(ActionEvent e)
1160 showColourText_actionPerformed();
1163 displayNonconserved.setText(MessageManager
1164 .getString("label.show_non_conversed"));
1165 displayNonconserved.setState(true);
1166 displayNonconserved.addActionListener(new ActionListener()
1169 public void actionPerformed(ActionEvent e)
1171 showNonconserved_actionPerformed();
1174 editMenu.setText(MessageManager.getString("action.edit"));
1175 cut.setText(MessageManager.getString("action.cut"));
1176 cut.addActionListener(new ActionListener()
1179 public void actionPerformed(ActionEvent e)
1181 cut_actionPerformed();
1184 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1185 upperCase.addActionListener(new ActionListener()
1188 public void actionPerformed(ActionEvent e)
1193 copy.setText(MessageManager.getString("action.copy"));
1194 copy.addActionListener(new ActionListener()
1197 public void actionPerformed(ActionEvent e)
1199 copy_actionPerformed();
1202 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1203 lowerCase.addActionListener(new ActionListener()
1206 public void actionPerformed(ActionEvent e)
1211 toggle.setText(MessageManager.getString("label.toggle_case"));
1212 toggle.addActionListener(new ActionListener()
1215 public void actionPerformed(ActionEvent e)
1220 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1222 seqShowAnnotationsMenu.setText(MessageManager
1223 .getString("label.show_annotations"));
1224 seqHideAnnotationsMenu.setText(MessageManager
1225 .getString("label.hide_annotations"));
1226 groupShowAnnotationsMenu.setText(MessageManager
1227 .getString("label.show_annotations"));
1228 groupHideAnnotationsMenu.setText(MessageManager
1229 .getString("label.hide_annotations"));
1230 sequenceFeature.setText(MessageManager
1231 .getString("label.create_sequence_feature"));
1232 sequenceFeature.addActionListener(new ActionListener()
1235 public void actionPerformed(ActionEvent e)
1237 sequenceFeature_actionPerformed();
1240 textColour.setText(MessageManager.getString("label.text_colour"));
1241 textColour.addActionListener(new ActionListener()
1244 public void actionPerformed(ActionEvent e)
1246 textColour_actionPerformed();
1249 jMenu1.setText(MessageManager.getString("label.group"));
1250 pdbStructureDialog.setText(MessageManager
1251 .getString("label.show_pdbstruct_dialog"));
1252 pdbStructureDialog.addActionListener(new ActionListener()
1255 public void actionPerformed(ActionEvent actionEvent)
1257 SequenceI[] selectedSeqs = new SequenceI[] { sequence };
1258 if (ap.av.getSelectionGroup() != null)
1260 selectedSeqs = ap.av.getSequenceSelection();
1262 new StructureChooser(selectedSeqs, sequence, ap);
1266 rnaStructureMenu.setText(MessageManager
1267 .getString("label.view_rna_structure"));
1269 // colStructureMenu.setText("Colour By Structure");
1270 editSequence.setText(MessageManager.getString("label.edit_sequence")
1272 editSequence.addActionListener(new ActionListener()
1275 public void actionPerformed(ActionEvent actionEvent)
1277 editSequence_actionPerformed(actionEvent);
1280 makeReferenceSeq.setText(MessageManager
1281 .getString("label.mark_as_representative"));
1282 makeReferenceSeq.addActionListener(new ActionListener()
1286 public void actionPerformed(ActionEvent actionEvent)
1288 makeReferenceSeq_actionPerformed(actionEvent);
1292 hideInsertions.setText(MessageManager
1293 .getString("label.hide_insertions"));
1294 hideInsertions.addActionListener(new ActionListener()
1298 public void actionPerformed(ActionEvent e)
1300 hideInsertions_actionPerformed(e);
1304 * annotationMenuItem.setText("By Annotation");
1305 * annotationMenuItem.addActionListener(new ActionListener() { public void
1306 * actionPerformed(ActionEvent actionEvent) {
1307 * annotationMenuItem_actionPerformed(actionEvent); } });
1309 groupMenu.add(sequenceSelDetails);
1312 add(rnaStructureMenu);
1313 add(pdbStructureDialog);
1314 if (sequence != null)
1316 add(hideInsertions);
1318 // annotations configuration panel suppressed for now
1319 // groupMenu.add(chooseAnnotations);
1322 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1323 * (if a selection group is in force).
1325 sequenceMenu.add(seqShowAnnotationsMenu);
1326 sequenceMenu.add(seqHideAnnotationsMenu);
1327 sequenceMenu.add(seqAddReferenceAnnotations);
1328 groupMenu.add(groupShowAnnotationsMenu);
1329 groupMenu.add(groupHideAnnotationsMenu);
1330 groupMenu.add(groupAddReferenceAnnotations);
1331 groupMenu.add(editMenu);
1332 groupMenu.add(outputMenu);
1333 groupMenu.add(sequenceFeature);
1334 groupMenu.add(createGroupMenuItem);
1335 groupMenu.add(unGroupMenuItem);
1336 groupMenu.add(jMenu1);
1337 sequenceMenu.add(sequenceName);
1338 sequenceMenu.add(sequenceDetails);
1339 sequenceMenu.add(makeReferenceSeq);
1340 colourMenu.add(textColour);
1341 colourMenu.add(noColourmenuItem);
1342 colourMenu.add(clustalColour);
1343 colourMenu.add(BLOSUM62Colour);
1344 colourMenu.add(PIDColour);
1345 colourMenu.add(zappoColour);
1346 colourMenu.add(taylorColour);
1347 colourMenu.add(hydrophobicityColour);
1348 colourMenu.add(helixColour);
1349 colourMenu.add(strandColour);
1350 colourMenu.add(turnColour);
1351 colourMenu.add(buriedColour);
1352 colourMenu.add(nucleotideMenuItem);
1353 if (ap.getAlignment().isNucleotide())
1355 // JBPNote - commented since the colourscheme isn't functional
1356 colourMenu.add(purinePyrimidineColour);
1358 colourMenu.add(userDefinedColour);
1360 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1362 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1363 .getUserColourSchemes().keys();
1365 while (userColours.hasMoreElements())
1367 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1368 item.addActionListener(new ActionListener()
1371 public void actionPerformed(ActionEvent evt)
1373 userDefinedColour_actionPerformed(evt);
1376 colourMenu.add(item);
1380 colourMenu.addSeparator();
1381 colourMenu.add(abovePIDColour);
1382 colourMenu.add(conservationMenuItem);
1385 editMenu.add(editSequence);
1386 editMenu.add(upperCase);
1387 editMenu.add(lowerCase);
1388 editMenu.add(toggle);
1389 // JBPNote: These shouldn't be added here - should appear in a generic
1390 // 'apply web service to this sequence menu'
1391 // pdbMenu.add(RNAFold);
1392 // pdbMenu.add(ContraFold);
1393 jMenu1.add(groupName);
1394 jMenu1.add(colourMenu);
1395 jMenu1.add(showBoxes);
1396 jMenu1.add(showText);
1397 jMenu1.add(showColourText);
1398 jMenu1.add(outline);
1399 jMenu1.add(displayNonconserved);
1400 noColourmenuItem.setText(MessageManager.getString("label.none"));
1401 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1404 public void actionPerformed(ActionEvent e)
1406 noColourmenuItem_actionPerformed();
1410 clustalColour.setText(MessageManager
1411 .getString("label.clustalx_colours"));
1412 clustalColour.addActionListener(new java.awt.event.ActionListener()
1415 public void actionPerformed(ActionEvent e)
1417 clustalColour_actionPerformed();
1420 zappoColour.setText(MessageManager.getString("label.zappo"));
1421 zappoColour.addActionListener(new java.awt.event.ActionListener()
1424 public void actionPerformed(ActionEvent e)
1426 zappoColour_actionPerformed();
1429 taylorColour.setText(MessageManager.getString("label.taylor"));
1430 taylorColour.addActionListener(new java.awt.event.ActionListener()
1433 public void actionPerformed(ActionEvent e)
1435 taylorColour_actionPerformed();
1438 hydrophobicityColour.setText(MessageManager
1439 .getString("label.hydrophobicity"));
1440 hydrophobicityColour
1441 .addActionListener(new java.awt.event.ActionListener()
1444 public void actionPerformed(ActionEvent e)
1446 hydrophobicityColour_actionPerformed();
1449 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1450 helixColour.addActionListener(new java.awt.event.ActionListener()
1453 public void actionPerformed(ActionEvent e)
1455 helixColour_actionPerformed();
1458 strandColour.setText(MessageManager
1459 .getString("label.strand_propensity"));
1460 strandColour.addActionListener(new java.awt.event.ActionListener()
1463 public void actionPerformed(ActionEvent e)
1465 strandColour_actionPerformed();
1468 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1469 turnColour.addActionListener(new java.awt.event.ActionListener()
1472 public void actionPerformed(ActionEvent e)
1474 turnColour_actionPerformed();
1477 buriedColour.setText(MessageManager.getString("label.buried_index"));
1478 buriedColour.addActionListener(new java.awt.event.ActionListener()
1481 public void actionPerformed(ActionEvent e)
1483 buriedColour_actionPerformed();
1486 abovePIDColour.setText(MessageManager
1487 .getString("label.above_identity_percentage"));
1488 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1491 public void actionPerformed(ActionEvent e)
1493 abovePIDColour_actionPerformed();
1496 userDefinedColour.setText(MessageManager
1497 .getString("action.user_defined"));
1498 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1501 public void actionPerformed(ActionEvent e)
1503 userDefinedColour_actionPerformed(e);
1507 .setText(MessageManager.getString("label.percentage_identity"));
1508 PIDColour.addActionListener(new java.awt.event.ActionListener()
1511 public void actionPerformed(ActionEvent e)
1513 PIDColour_actionPerformed();
1516 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1517 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1520 public void actionPerformed(ActionEvent e)
1522 BLOSUM62Colour_actionPerformed();
1525 purinePyrimidineColour.setText(MessageManager
1526 .getString("label.purine_pyrimidine"));
1527 purinePyrimidineColour
1528 .addActionListener(new java.awt.event.ActionListener()
1531 public void actionPerformed(ActionEvent e)
1533 purinePyrimidineColour_actionPerformed();
1538 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1539 * public void actionPerformed(ActionEvent e) {
1540 * covariationColour_actionPerformed(); } });
1543 conservationMenuItem.setText(MessageManager
1544 .getString("label.conservation"));
1545 conservationMenuItem
1546 .addActionListener(new java.awt.event.ActionListener()
1549 public void actionPerformed(ActionEvent e)
1551 conservationMenuItem_actionPerformed();
1557 * Check for any annotations on the underlying dataset sequences (for the
1558 * current selection group) which are not 'on the alignment'.If any are found,
1559 * enable the option to add them to the alignment. The criteria for 'on the
1560 * alignment' is finding an alignment annotation on the alignment, matched on
1561 * calcId, label and sequenceRef.
1563 * A tooltip is also constructed that displays the source (calcId) and type
1564 * (label) of the annotations that can be added.
1567 * @param forSequences
1569 protected void configureReferenceAnnotationsMenu(JMenuItem menuItem,
1570 List<SequenceI> forSequences)
1572 menuItem.setEnabled(false);
1575 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1576 * Using TreeMap means calcIds are shown in alphabetical order.
1578 Map<String, String> tipEntries = new TreeMap<String, String>();
1579 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1580 AlignmentI al = this.ap.av.getAlignment();
1581 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1582 tipEntries, candidates, al);
1583 if (!candidates.isEmpty())
1585 StringBuilder tooltip = new StringBuilder(64);
1586 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1589 * Found annotations that could be added. Enable the menu item, and
1590 * configure its tooltip and action.
1592 menuItem.setEnabled(true);
1593 for (String calcId : tipEntries.keySet())
1595 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1597 String tooltipText = JvSwingUtils.wrapTooltip(true,
1598 tooltip.toString());
1599 menuItem.setToolTipText(tooltipText);
1601 menuItem.addActionListener(new ActionListener()
1604 public void actionPerformed(ActionEvent e)
1606 addReferenceAnnotations_actionPerformed(candidates);
1613 * Add annotations to the sequences and to the alignment.
1616 * a map whose keys are sequences on the alignment, and values a list
1617 * of annotations to add to each sequence
1619 protected void addReferenceAnnotations_actionPerformed(
1620 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1622 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1623 final AlignmentI alignment = this.ap.getAlignment();
1624 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1629 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1631 if (!ap.av.getAlignment().hasSeqrep())
1633 // initialise the display flags so the user sees something happen
1634 ap.av.setDisplayReferenceSeq(true);
1635 ap.av.setColourByReferenceSeq(true);
1636 ap.av.getAlignment().setSeqrep(sequence);
1640 if (ap.av.getAlignment().getSeqrep() == sequence)
1642 ap.av.getAlignment().setSeqrep(null);
1646 ap.av.getAlignment().setSeqrep(sequence);
1652 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1654 if (sequence != null)
1656 ColumnSelection cs = ap.av.getColumnSelection();
1659 cs = new ColumnSelection();
1661 cs.hideInsertionsFor(sequence);
1662 ap.av.setColumnSelection(cs);
1667 protected void sequenceSelectionDetails_actionPerformed()
1669 createSequenceDetailsReport(ap.av.getSequenceSelection());
1672 protected void sequenceDetails_actionPerformed()
1674 createSequenceDetailsReport(new SequenceI[] { sequence });
1677 public void createSequenceDetailsReport(SequenceI[] sequences)
1679 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1680 StringBuffer contents = new StringBuffer();
1681 for (SequenceI seq : sequences)
1683 contents.append("<p><h2>"
1686 "label.create_sequence_details_report_annotation_for",
1687 new Object[] { seq.getDisplayId(true) })
1689 new SequenceAnnotationReport(null)
1690 .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 JOptionPane.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 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2199 MessageManager.getString("label.web_browser_not_found_unix"),
2200 MessageManager.getString("label.web_browser_not_found"),
2201 JOptionPane.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 cap.setText(new FormatAdapter(ap).formatSequences(e.getActionCommand(),
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()