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.commands.ChangeCaseCommand;
28 import jalview.commands.EditCommand;
29 import jalview.commands.EditCommand.Action;
30 import jalview.datamodel.AlignmentAnnotation;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.Annotation;
33 import jalview.datamodel.ColumnSelection;
34 import jalview.datamodel.DBRefEntry;
35 import jalview.datamodel.PDBEntry;
36 import jalview.datamodel.Sequence;
37 import jalview.datamodel.SequenceFeature;
38 import jalview.datamodel.SequenceGroup;
39 import jalview.datamodel.SequenceI;
40 import jalview.io.FormatAdapter;
41 import jalview.io.SequenceAnnotationReport;
42 import jalview.schemes.AnnotationColourGradient;
43 import jalview.schemes.Blosum62ColourScheme;
44 import jalview.schemes.BuriedColourScheme;
45 import jalview.schemes.ClustalxColourScheme;
46 import jalview.schemes.HelixColourScheme;
47 import jalview.schemes.HydrophobicColourScheme;
48 import jalview.schemes.NucleotideColourScheme;
49 import jalview.schemes.PIDColourScheme;
50 import jalview.schemes.PurinePyrimidineColourScheme;
51 import jalview.schemes.ResidueProperties;
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.Collections;
67 import java.util.Hashtable;
68 import java.util.LinkedHashMap;
69 import java.util.List;
71 import java.util.TreeMap;
72 import java.util.Vector;
74 import javax.swing.ButtonGroup;
75 import javax.swing.JCheckBoxMenuItem;
76 import javax.swing.JColorChooser;
77 import javax.swing.JMenu;
78 import javax.swing.JMenuItem;
79 import javax.swing.JOptionPane;
80 import javax.swing.JPopupMenu;
81 import javax.swing.JRadioButtonMenuItem;
87 * @version $Revision: 1.118 $
89 public class PopupMenu extends JPopupMenu
91 private static final String ALL_ANNOTATIONS = "All";
93 private static final String COMMA = ",";
95 JMenu groupMenu = new JMenu();
97 JMenuItem groupName = new JMenuItem();
99 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
101 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
103 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
105 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
107 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
109 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
111 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
113 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
115 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
117 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
119 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
121 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
123 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
125 protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
127 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
129 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
133 JMenu sequenceMenu = new JMenu();
135 JMenuItem sequenceName = new JMenuItem();
137 JMenuItem sequenceDetails = new JMenuItem();
139 JMenuItem sequenceSelDetails = new JMenuItem();
141 JMenuItem makeReferenceSeq = new JMenuItem();
143 JMenuItem chooseAnnotations = new JMenuItem();
147 JMenuItem createGroupMenuItem = new JMenuItem();
149 JMenuItem unGroupMenuItem = new JMenuItem();
151 JMenuItem outline = new JMenuItem();
153 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
155 JMenu colourMenu = new JMenu();
157 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
159 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
161 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
163 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
165 JMenu editMenu = new JMenu();
167 JMenuItem cut = new JMenuItem();
169 JMenuItem copy = new JMenuItem();
171 JMenuItem upperCase = new JMenuItem();
173 JMenuItem lowerCase = new JMenuItem();
175 JMenuItem toggle = new JMenuItem();
177 JMenu pdbMenu = new JMenu();
179 JMenuItem pdbFromFile = new JMenuItem();
181 JMenuItem enterPDB = new JMenuItem();
183 JMenuItem discoverPDB = new JMenuItem();
185 JMenu outputMenu = new JMenu();
187 JMenu seqShowAnnotationsMenu = new JMenu();
189 JMenu seqHideAnnotationsMenu = new JMenu();
191 JMenuItem seqAddReferenceAnnotations = new JMenuItem(
192 MessageManager.getString("label.add_reference_annotations"));
194 JMenu groupShowAnnotationsMenu = new JMenu();
196 JMenu groupHideAnnotationsMenu = new JMenu();
198 JMenuItem groupAddReferenceAnnotations = new JMenuItem(
199 MessageManager.getString("label.add_reference_annotations"));
201 JMenuItem sequenceFeature = new JMenuItem();
203 JMenuItem textColour = new JMenuItem();
205 JMenu jMenu1 = new JMenu();
207 JMenuItem pdbStructureDialog = new JMenuItem();
209 JMenu rnaStructureMenu = new JMenu();
211 JMenuItem editSequence = new JMenuItem();
213 JMenu groupLinksMenu;
215 JMenuItem hideInsertions = new JMenuItem();
218 * Creates a new PopupMenu object.
225 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
227 this(ap, seq, links, null);
237 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
238 Vector links, Vector groupLinks)
240 // /////////////////////////////////////////////////////////
241 // If this is activated from the sequence panel, the user may want to
242 // edit or annotate a particular residue. Therefore display the residue menu
244 // If from the IDPanel, we must display the sequence menu
245 // ////////////////////////////////////////////////////////
249 ButtonGroup colours = new ButtonGroup();
250 colours.add(noColourmenuItem);
251 colours.add(clustalColour);
252 colours.add(zappoColour);
253 colours.add(taylorColour);
254 colours.add(hydrophobicityColour);
255 colours.add(helixColour);
256 colours.add(strandColour);
257 colours.add(turnColour);
258 colours.add(buriedColour);
259 colours.add(abovePIDColour);
260 colours.add(userDefinedColour);
261 colours.add(PIDColour);
262 colours.add(BLOSUM62Colour);
263 colours.add(purinePyrimidineColour);
264 colours.add(RNAInteractionColour);
266 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
268 JMenuItem item = new JMenuItem(
269 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
271 item.addActionListener(new java.awt.event.ActionListener()
274 public void actionPerformed(ActionEvent e)
276 outputText_actionPerformed(e);
280 outputMenu.add(item);
284 * Build menus for annotation types that may be shown or hidden, and for
285 * 'reference annotations' that may be added to the alignment. First for the
286 * currently selected sequence (if there is one):
288 final List<SequenceI> selectedSequence = (seq == null ? Collections
289 .<SequenceI> emptyList() : Arrays.asList(seq));
290 buildAnnotationTypesMenus(seqShowAnnotationsMenu,
291 seqHideAnnotationsMenu, selectedSequence);
292 configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
296 * And repeat for the current selection group (if there is one):
298 final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
299 .<SequenceI> emptyList() : ap.av.getSelectionGroup()
301 buildAnnotationTypesMenus(groupShowAnnotationsMenu,
302 groupHideAnnotationsMenu, selectedGroup);
303 configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
309 } catch (Exception e)
317 sequenceMenu.setText(sequence.getName());
318 if (seq == ap.av.getAlignment().getSeqrep())
320 makeReferenceSeq.setText("Unmark representative");
322 makeReferenceSeq.setText("Mark as representative");
325 if (!ap.av.getAlignment().isNucleotide())
327 remove(rnaStructureMenu);
331 int origCount = rnaStructureMenu.getItemCount();
333 * add menu items to 2D-render any alignment or sequence secondary
334 * structure annotation
336 AlignmentAnnotation[] aas = ap.av.getAlignment()
337 .getAlignmentAnnotation();
340 for (final AlignmentAnnotation aa : aas)
342 if (aa.isValidStruc() && aa.sequenceRef == null)
345 * valid alignment RNA secondary structure annotation
347 menuItem = new JMenuItem();
348 menuItem.setText(MessageManager.formatMessage(
349 "label.2d_rna_structure_line", new Object[]
351 menuItem.addActionListener(new java.awt.event.ActionListener()
354 public void actionPerformed(ActionEvent e)
356 new AppVarna(seq, aa, ap);
359 rnaStructureMenu.add(menuItem);
364 if (seq.getAnnotation() != null)
366 AlignmentAnnotation seqAnns[] = seq.getAnnotation();
367 for (final AlignmentAnnotation aa : seqAnns)
369 if (aa.isValidStruc())
372 * valid sequence RNA secondary structure annotation
374 // TODO: make rnastrucF a bit more nice
375 menuItem = new JMenuItem();
376 menuItem.setText(MessageManager.formatMessage(
377 "label.2d_rna_sequence_name", new Object[]
379 menuItem.addActionListener(new java.awt.event.ActionListener()
382 public void actionPerformed(ActionEvent e)
384 // TODO: VARNA does'nt print gaps in the sequence
385 new AppVarna(seq, aa, ap);
388 rnaStructureMenu.add(menuItem);
392 if (rnaStructureMenu.getItemCount() == origCount)
394 remove(rnaStructureMenu);
398 menuItem = new JMenuItem(
399 MessageManager.getString("action.hide_sequences"));
400 menuItem.addActionListener(new java.awt.event.ActionListener()
403 public void actionPerformed(ActionEvent e)
405 hideSequences(false);
410 if (ap.av.getSelectionGroup() != null
411 && ap.av.getSelectionGroup().getSize() > 1)
413 menuItem = new JMenuItem(MessageManager.formatMessage(
414 "label.represent_group_with", new Object[]
416 menuItem.addActionListener(new java.awt.event.ActionListener()
419 public void actionPerformed(ActionEvent e)
424 sequenceMenu.add(menuItem);
427 if (ap.av.hasHiddenRows())
429 final int index = ap.av.getAlignment().findIndex(seq);
431 if (ap.av.adjustForHiddenSeqs(index)
432 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
434 menuItem = new JMenuItem(
435 MessageManager.getString("action.reveal_sequences"));
436 menuItem.addActionListener(new ActionListener()
439 public void actionPerformed(ActionEvent e)
441 ap.av.showSequence(index);
442 if (ap.overviewPanel != null)
444 ap.overviewPanel.updateOverviewImage();
452 // for the case when no sequences are even visible
453 if (ap.av.hasHiddenRows())
456 menuItem = new JMenuItem(
457 MessageManager.getString("action.reveal_all"));
458 menuItem.addActionListener(new ActionListener()
461 public void actionPerformed(ActionEvent e)
463 ap.av.showAllHiddenSeqs();
464 if (ap.overviewPanel != null)
466 ap.overviewPanel.updateOverviewImage();
476 SequenceGroup sg = ap.av.getSelectionGroup();
477 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
478 .getGroups().contains(sg) : false;
480 if (sg != null && sg.getSize() > 0)
482 groupName.setText(MessageManager.formatMessage("label.name_param",
485 groupName.setText(MessageManager
486 .getString("label.edit_name_and_description_current_group"));
488 if (sg.cs instanceof ZappoColourScheme)
490 zappoColour.setSelected(true);
492 else if (sg.cs instanceof TaylorColourScheme)
494 taylorColour.setSelected(true);
496 else if (sg.cs instanceof PIDColourScheme)
498 PIDColour.setSelected(true);
500 else if (sg.cs instanceof Blosum62ColourScheme)
502 BLOSUM62Colour.setSelected(true);
504 else if (sg.cs instanceof UserColourScheme)
506 userDefinedColour.setSelected(true);
508 else if (sg.cs instanceof HydrophobicColourScheme)
510 hydrophobicityColour.setSelected(true);
512 else if (sg.cs instanceof HelixColourScheme)
514 helixColour.setSelected(true);
516 else if (sg.cs instanceof StrandColourScheme)
518 strandColour.setSelected(true);
520 else if (sg.cs instanceof TurnColourScheme)
522 turnColour.setSelected(true);
524 else if (sg.cs instanceof BuriedColourScheme)
526 buriedColour.setSelected(true);
528 else if (sg.cs instanceof ClustalxColourScheme)
530 clustalColour.setSelected(true);
532 else if (sg.cs instanceof PurinePyrimidineColourScheme)
534 purinePyrimidineColour.setSelected(true);
538 * else if (sg.cs instanceof CovariationColourScheme) {
539 * covariationColour.setSelected(true); }
543 noColourmenuItem.setSelected(true);
546 if (sg.cs != null && sg.cs.conservationApplied())
548 conservationMenuItem.setSelected(true);
550 displayNonconserved.setSelected(sg.getShowNonconserved());
551 showText.setSelected(sg.getDisplayText());
552 showColourText.setSelected(sg.getColourText());
553 showBoxes.setSelected(sg.getDisplayBoxes());
554 // add any groupURLs to the groupURL submenu and make it visible
555 if (groupLinks != null && groupLinks.size() > 0)
557 buildGroupURLMenu(sg, groupLinks);
559 // Add a 'show all structures' for the current selection
560 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
561 SequenceI sqass = null;
562 for (SequenceI sq : ap.av.getSequenceSelection())
564 Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
565 if (pes != null && pes.size() > 0)
567 reppdb.put(pes.get(0).getId(), pes.get(0));
568 for (PDBEntry pe : pes)
570 pdbe.put(pe.getId(), pe);
580 final PDBEntry[] pe = pdbe.values().toArray(
581 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
582 new PDBEntry[reppdb.size()]);
583 final JMenuItem gpdbview, rpdbview;
588 groupMenu.setVisible(false);
589 editMenu.setVisible(false);
594 createGroupMenuItem.setVisible(true);
595 unGroupMenuItem.setVisible(false);
596 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
600 createGroupMenuItem.setVisible(false);
601 unGroupMenuItem.setVisible(true);
602 jMenu1.setText(MessageManager.getString("action.edit_group"));
607 sequenceMenu.setVisible(false);
608 pdbStructureDialog.setVisible(false);
609 rnaStructureMenu.setVisible(false);
612 if (links != null && links.size() > 0)
615 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
616 Vector linkset = new Vector();
617 for (int i = 0; i < links.size(); i++)
619 String link = links.elementAt(i).toString();
620 UrlLink urlLink = null;
623 urlLink = new UrlLink(link);
624 } catch (Exception foo)
626 jalview.bin.Cache.log.error("Exception for URLLink '" + link
631 if (!urlLink.isValid())
633 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
636 final String label = urlLink.getLabel();
637 if (seq != null && urlLink.isDynamic())
640 // collect matching db-refs
641 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
642 seq.getDBRef(), new String[]
643 { urlLink.getTarget() });
644 // collect id string too
645 String id = seq.getName();
646 String descr = seq.getDescription();
647 if (descr != null && descr.length() < 1)
654 for (int r = 0; r < dbr.length; r++)
656 if (id != null && dbr[r].getAccessionId().equals(id))
658 // suppress duplicate link creation for the bare sequence ID
659 // string with this link
662 // create Bare ID link for this RUL
663 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
667 for (int u = 0; u < urls.length; u += 2)
669 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
671 linkset.addElement(urls[u] + "|" + urls[u + 1]);
672 addshowLink(linkMenu, label + "|" + urls[u],
681 // create Bare ID link for this RUL
682 String[] urls = urlLink.makeUrls(id, true);
685 for (int u = 0; u < urls.length; u += 2)
687 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
689 linkset.addElement(urls[u] + "|" + urls[u + 1]);
690 addshowLink(linkMenu, label, urls[u + 1]);
695 // Create urls from description but only for URL links which are regex
697 if (descr != null && urlLink.getRegexReplace() != null)
699 // create link for this URL from description where regex matches
700 String[] urls = urlLink.makeUrls(descr, true);
703 for (int u = 0; u < urls.length; u += 2)
705 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
707 linkset.addElement(urls[u] + "|" + urls[u + 1]);
708 addshowLink(linkMenu, label, urls[u + 1]);
716 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
718 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
719 // Add a non-dynamic link
720 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
724 if (sequence != null)
726 sequenceMenu.add(linkMenu);
736 * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
737 * "All" is added first, followed by a separator. Then add any annotation
738 * types associated with the current selection. Separate menus are built for
739 * the selected sequence group (if any), and the selected sequence.
741 * Some annotation rows are always rendered together - these can be identified
742 * by a common graphGroup property > -1. Only one of each group will be marked
743 * as visible (to avoid duplication of the display). For such groups we add a
744 * composite type name, e.g.
746 * IUPredWS (Long), IUPredWS (Short)
750 protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu,
751 List<SequenceI> forSequences)
753 showMenu.removeAll();
754 hideMenu.removeAll();
756 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
757 addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
758 addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
760 showMenu.addSeparator();
761 hideMenu.addSeparator();
763 final AlignmentAnnotation[] annotations = ap.getAlignment()
764 .getAlignmentAnnotation();
767 * Find shown/hidden annotations types, distinguished by source (calcId),
768 * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
769 * the insertion order, which is the order of the annotations on the
772 Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
773 Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
774 AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes,
776 AlignmentAnnotationUtils.asList(annotations),
779 for (String calcId : hiddenTypes.keySet())
781 for (List<String> type : hiddenTypes.get(calcId))
783 addAnnotationTypeToShowHide(showMenu, forSequences,
784 calcId, type, false, true);
787 // grey out 'show annotations' if none are hidden
788 showMenu.setEnabled(!hiddenTypes.isEmpty());
790 for (String calcId : shownTypes.keySet())
792 for (List<String> type : shownTypes.get(calcId))
794 addAnnotationTypeToShowHide(hideMenu, forSequences,
795 calcId, type, false, false);
798 // grey out 'hide annotations' if none are shown
799 hideMenu.setEnabled(!shownTypes.isEmpty());
803 * Returns a list of sequences - either the current selection group (if there
804 * is one), else the specified single sequence.
809 protected List<SequenceI> getSequenceScope(SequenceI seq)
811 List<SequenceI> forSequences = null;
812 final SequenceGroup selectionGroup = ap.av.getSelectionGroup();
813 if (selectionGroup != null && selectionGroup.getSize() > 0)
815 forSequences = selectionGroup.getSequences();
819 forSequences = seq == null ? Collections.<SequenceI> emptyList()
820 : Arrays.asList(seq);
826 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
829 * @param showOrHideMenu
831 * @param forSequences
832 * the sequences whose annotations may be shown or hidden
837 * if true this is a special label meaning 'All'
838 * @param actionIsShow
839 * if true, the select menu item action is to show the annotation
842 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
843 final List<SequenceI> forSequences, String calcId,
844 final List<String> types, final boolean allTypes,
845 final boolean actionIsShow)
847 String label = types.toString(); // [a, b, c]
848 label = label.substring(1, label.length() - 1); // a, b, c
849 final JMenuItem item = new JMenuItem(label);
850 item.setToolTipText(calcId);
851 item.addActionListener(new java.awt.event.ActionListener()
854 public void actionPerformed(ActionEvent e)
856 AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(), types,
857 forSequences, allTypes, actionIsShow);
861 showOrHideMenu.add(item);
864 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
867 // TODO: usability: thread off the generation of group url content so root
869 // sequence only URLs
870 // ID/regex match URLs
871 groupLinksMenu = new JMenu(
872 MessageManager.getString("action.group_link"));
873 JMenu[] linkMenus = new JMenu[]
874 { null, new JMenu(MessageManager.getString("action.ids")),
875 new JMenu(MessageManager.getString("action.sequences")),
876 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
883 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
884 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
885 Hashtable commonDbrefs = new Hashtable();
886 for (int sq = 0; sq < seqs.length; sq++)
889 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
890 .findPosition(sg.getEndRes());
891 // just collect ids from dataset sequence
892 // TODO: check if IDs collected from selecton group intersects with the
893 // current selection, too
894 SequenceI sqi = seqs[sq];
895 while (sqi.getDatasetSequence() != null)
897 sqi = sqi.getDatasetSequence();
899 DBRefEntry[] dbr = sqi.getDBRef();
900 if (dbr != null && dbr.length > 0)
902 for (int d = 0; d < dbr.length; d++)
904 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
905 Object[] sarray = (Object[]) commonDbrefs.get(src);
908 sarray = new Object[2];
909 sarray[0] = new int[]
911 sarray[1] = new String[seqs.length];
913 commonDbrefs.put(src, sarray);
916 if (((String[]) sarray[1])[sq] == null)
919 || (dbr[d].getMap().locateMappedRange(start, end) != null))
921 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
922 ((int[]) sarray[0])[0]++;
928 // now create group links for all distinct ID/sequence sets.
929 boolean addMenu = false; // indicates if there are any group links to give
931 for (int i = 0; i < groupLinks.size(); i++)
933 String link = groupLinks.elementAt(i).toString();
934 GroupUrlLink urlLink = null;
937 urlLink = new GroupUrlLink(link);
938 } catch (Exception foo)
940 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
945 if (!urlLink.isValid())
947 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
950 final String label = urlLink.getLabel();
951 boolean usingNames = false;
952 // Now see which parts of the group apply for this URL
953 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
954 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
955 String[] seqstr, ids; // input to makeUrl
958 int numinput = ((int[]) idset[0])[0];
959 String[] allids = ((String[]) idset[1]);
960 seqstr = new String[numinput];
961 ids = new String[numinput];
962 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
964 if (allids[sq] != null)
966 ids[idcount] = allids[sq];
967 seqstr[idcount++] = idandseqs[1][sq];
973 // just use the id/seq set
974 seqstr = idandseqs[1];
978 // and try and make the groupURL!
980 Object[] urlset = null;
983 urlset = urlLink.makeUrlStubs(ids, seqstr,
984 "FromJalview" + System.currentTimeMillis(), false);
985 } catch (UrlStringTooLongException e)
990 int type = urlLink.getGroupURLType() & 3;
991 // first two bits ofurlLink type bitfield are sequenceids and sequences
992 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
993 addshowLink(linkMenus[type], label
994 + (((type & 1) == 1) ? ("("
995 + (usingNames ? "Names" : ltarget) + ")") : ""),
1002 groupLinksMenu = new JMenu(
1003 MessageManager.getString("action.group_link"));
1004 for (int m = 0; m < linkMenus.length; m++)
1006 if (linkMenus[m] != null
1007 && linkMenus[m].getMenuComponentCount() > 0)
1009 groupLinksMenu.add(linkMenus[m]);
1013 groupMenu.add(groupLinksMenu);
1018 * add a show URL menu item to the given linkMenu
1022 * - menu label string
1026 private void addshowLink(JMenu linkMenu, String label, final String url)
1028 JMenuItem item = new JMenuItem(label);
1029 item.setToolTipText(MessageManager.formatMessage(
1030 "label.open_url_param", new Object[]
1032 item.addActionListener(new java.awt.event.ActionListener()
1035 public void actionPerformed(ActionEvent e)
1037 new Thread(new Runnable()
1054 * add a late bound groupURL item to the given linkMenu
1058 * - menu label string
1059 * @param urlgenerator
1060 * GroupURLLink used to generate URL
1062 * Object array returned from the makeUrlStubs function.
1064 private void addshowLink(JMenu linkMenu, String label,
1065 final GroupUrlLink urlgenerator, final Object[] urlstub)
1067 JMenuItem item = new JMenuItem(label);
1068 item.setToolTipText(MessageManager.formatMessage(
1069 "label.open_url_seqs_param",
1071 { urlgenerator.getUrl_prefix(),
1072 urlgenerator.getNumberInvolved(urlstub) }));
1073 // TODO: put in info about what is being sent.
1074 item.addActionListener(new java.awt.event.ActionListener()
1077 public void actionPerformed(ActionEvent e)
1079 new Thread(new Runnable()
1087 showLink(urlgenerator.constructFrom(urlstub));
1088 } catch (UrlStringTooLongException e)
1106 private void jbInit() throws Exception
1108 groupMenu.setText(MessageManager.getString("label.group"));
1109 groupMenu.setText(MessageManager.getString("label.selection"));
1110 groupName.setText(MessageManager.getString("label.name"));
1111 groupName.addActionListener(new java.awt.event.ActionListener()
1114 public void actionPerformed(ActionEvent e)
1116 groupName_actionPerformed();
1119 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1120 sequenceName.setText(MessageManager
1121 .getString("label.edit_name_description"));
1122 sequenceName.addActionListener(new java.awt.event.ActionListener()
1125 public void actionPerformed(ActionEvent e)
1127 sequenceName_actionPerformed();
1130 chooseAnnotations.setText(MessageManager
1131 .getString("label.choose_annotations") + "...");
1132 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1135 public void actionPerformed(ActionEvent e)
1137 chooseAnnotations_actionPerformed(e);
1140 sequenceDetails.setText(MessageManager
1141 .getString("label.sequence_details") + "...");
1142 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1145 public void actionPerformed(ActionEvent e)
1147 sequenceDetails_actionPerformed();
1150 sequenceSelDetails.setText(MessageManager
1151 .getString("label.sequence_details") + "...");
1153 .addActionListener(new java.awt.event.ActionListener()
1156 public void actionPerformed(ActionEvent e)
1158 sequenceSelectionDetails_actionPerformed();
1161 PIDColour.setFocusPainted(false);
1163 .setText(MessageManager.getString("action.remove_group"));
1164 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1167 public void actionPerformed(ActionEvent e)
1169 unGroupMenuItem_actionPerformed();
1172 createGroupMenuItem.setText(MessageManager
1173 .getString("action.create_group"));
1175 .addActionListener(new java.awt.event.ActionListener()
1178 public void actionPerformed(ActionEvent e)
1180 createGroupMenuItem_actionPerformed();
1184 outline.setText(MessageManager.getString("action.border_colour"));
1185 outline.addActionListener(new java.awt.event.ActionListener()
1188 public void actionPerformed(ActionEvent e)
1190 outline_actionPerformed();
1194 .setText(MessageManager.getString("label.nucleotide"));
1195 nucleotideMenuItem.addActionListener(new ActionListener()
1198 public void actionPerformed(ActionEvent e)
1200 nucleotideMenuItem_actionPerformed();
1203 colourMenu.setText(MessageManager.getString("label.group_colour"));
1204 showBoxes.setText(MessageManager.getString("action.boxes"));
1205 showBoxes.setState(true);
1206 showBoxes.addActionListener(new ActionListener()
1209 public void actionPerformed(ActionEvent e)
1211 showBoxes_actionPerformed();
1214 showText.setText(MessageManager.getString("action.text"));
1215 showText.setState(true);
1216 showText.addActionListener(new ActionListener()
1219 public void actionPerformed(ActionEvent e)
1221 showText_actionPerformed();
1224 showColourText.setText(MessageManager.getString("label.colour_text"));
1225 showColourText.addActionListener(new ActionListener()
1228 public void actionPerformed(ActionEvent e)
1230 showColourText_actionPerformed();
1233 displayNonconserved.setText(MessageManager
1234 .getString("label.show_non_conversed"));
1235 displayNonconserved.setState(true);
1236 displayNonconserved.addActionListener(new ActionListener()
1239 public void actionPerformed(ActionEvent e)
1241 showNonconserved_actionPerformed();
1244 editMenu.setText(MessageManager.getString("action.edit"));
1245 cut.setText(MessageManager.getString("action.cut"));
1246 cut.addActionListener(new ActionListener()
1249 public void actionPerformed(ActionEvent e)
1251 cut_actionPerformed();
1254 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1255 upperCase.addActionListener(new ActionListener()
1258 public void actionPerformed(ActionEvent e)
1263 copy.setText(MessageManager.getString("action.copy"));
1264 copy.addActionListener(new ActionListener()
1267 public void actionPerformed(ActionEvent e)
1269 copy_actionPerformed();
1272 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1273 lowerCase.addActionListener(new ActionListener()
1276 public void actionPerformed(ActionEvent e)
1281 toggle.setText(MessageManager.getString("label.toggle_case"));
1282 toggle.addActionListener(new ActionListener()
1285 public void actionPerformed(ActionEvent e)
1290 pdbMenu.setText(MessageManager
1291 .getString("label.associate_structure_with_sequence"));
1292 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1293 pdbFromFile.addActionListener(new ActionListener()
1296 public void actionPerformed(ActionEvent e)
1298 pdbFromFile_actionPerformed();
1302 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1303 enterPDB.addActionListener(new ActionListener()
1306 public void actionPerformed(ActionEvent e)
1308 enterPDB_actionPerformed();
1311 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1312 discoverPDB.addActionListener(new ActionListener()
1315 public void actionPerformed(ActionEvent e)
1317 discoverPDB_actionPerformed();
1320 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1322 seqShowAnnotationsMenu.setText(MessageManager
1323 .getString("label.show_annotations"));
1324 seqHideAnnotationsMenu.setText(MessageManager
1325 .getString("label.hide_annotations"));
1326 groupShowAnnotationsMenu.setText(MessageManager
1327 .getString("label.show_annotations"));
1328 groupHideAnnotationsMenu.setText(MessageManager
1329 .getString("label.hide_annotations"));
1330 sequenceFeature.setText(MessageManager
1331 .getString("label.create_sequence_feature"));
1332 sequenceFeature.addActionListener(new ActionListener()
1335 public void actionPerformed(ActionEvent e)
1337 sequenceFeature_actionPerformed();
1340 textColour.setText(MessageManager.getString("label.text_colour"));
1341 textColour.addActionListener(new ActionListener()
1344 public void actionPerformed(ActionEvent e)
1346 textColour_actionPerformed();
1349 jMenu1.setText(MessageManager.getString("label.group"));
1350 pdbStructureDialog.setText(MessageManager
1351 .getString("label.show_pdbstruct_dialog"));
1352 pdbStructureDialog.addActionListener(new ActionListener()
1355 public void actionPerformed(ActionEvent actionEvent)
1357 SequenceI[] selectedSeqs = new SequenceI[]
1359 if (ap.av.getSelectionGroup() != null)
1361 selectedSeqs = ap.av.getSequenceSelection();
1363 new StructureChooser(selectedSeqs, sequence, ap);
1367 rnaStructureMenu.setText(MessageManager
1368 .getString("label.view_rna_structure"));
1370 // colStructureMenu.setText("Colour By Structure");
1371 editSequence.setText(MessageManager.getString("label.edit_sequence")
1373 editSequence.addActionListener(new ActionListener()
1376 public void actionPerformed(ActionEvent actionEvent)
1378 editSequence_actionPerformed(actionEvent);
1381 makeReferenceSeq.setText(MessageManager
1382 .getString("label.mark_as_representative"));
1383 makeReferenceSeq.addActionListener(new ActionListener()
1387 public void actionPerformed(ActionEvent actionEvent)
1389 makeReferenceSeq_actionPerformed(actionEvent);
1393 hideInsertions.setText(MessageManager.getString("label.hide_insertions"));
1394 hideInsertions.addActionListener(new ActionListener()
1398 public void actionPerformed(ActionEvent e)
1400 hideInsertions_actionPerformed(e);
1404 * annotationMenuItem.setText("By Annotation");
1405 * annotationMenuItem.addActionListener(new ActionListener() { public void
1406 * actionPerformed(ActionEvent actionEvent) {
1407 * annotationMenuItem_actionPerformed(actionEvent); } });
1409 groupMenu.add(sequenceSelDetails);
1412 add(rnaStructureMenu);
1413 add(pdbStructureDialog);
1416 add(hideInsertions);
1418 // annotations configuration panel suppressed for now
1419 // groupMenu.add(chooseAnnotations);
1422 * Add show/hide annotations to the Sequence menu, and to the Selection menu
1423 * (if a selection group is in force).
1425 sequenceMenu.add(seqShowAnnotationsMenu);
1426 sequenceMenu.add(seqHideAnnotationsMenu);
1427 sequenceMenu.add(seqAddReferenceAnnotations);
1428 groupMenu.add(groupShowAnnotationsMenu);
1429 groupMenu.add(groupHideAnnotationsMenu);
1430 groupMenu.add(groupAddReferenceAnnotations);
1431 groupMenu.add(editMenu);
1432 groupMenu.add(outputMenu);
1433 groupMenu.add(sequenceFeature);
1434 groupMenu.add(createGroupMenuItem);
1435 groupMenu.add(unGroupMenuItem);
1436 groupMenu.add(jMenu1);
1437 sequenceMenu.add(sequenceName);
1438 sequenceMenu.add(sequenceDetails);
1439 sequenceMenu.add(makeReferenceSeq);
1440 colourMenu.add(textColour);
1441 colourMenu.add(noColourmenuItem);
1442 colourMenu.add(clustalColour);
1443 colourMenu.add(BLOSUM62Colour);
1444 colourMenu.add(PIDColour);
1445 colourMenu.add(zappoColour);
1446 colourMenu.add(taylorColour);
1447 colourMenu.add(hydrophobicityColour);
1448 colourMenu.add(helixColour);
1449 colourMenu.add(strandColour);
1450 colourMenu.add(turnColour);
1451 colourMenu.add(buriedColour);
1452 colourMenu.add(nucleotideMenuItem);
1453 if (ap.getAlignment().isNucleotide())
1455 // JBPNote - commented since the colourscheme isn't functional
1456 colourMenu.add(purinePyrimidineColour);
1458 colourMenu.add(userDefinedColour);
1460 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1462 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1463 .getUserColourSchemes().keys();
1465 while (userColours.hasMoreElements())
1467 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1468 item.addActionListener(new ActionListener()
1471 public void actionPerformed(ActionEvent evt)
1473 userDefinedColour_actionPerformed(evt);
1476 colourMenu.add(item);
1480 colourMenu.addSeparator();
1481 colourMenu.add(abovePIDColour);
1482 colourMenu.add(conservationMenuItem);
1485 editMenu.add(editSequence);
1486 editMenu.add(upperCase);
1487 editMenu.add(lowerCase);
1488 editMenu.add(toggle);
1489 pdbMenu.add(pdbFromFile);
1490 // JBPNote: These shouldn't be added here - should appear in a generic
1491 // 'apply web service to this sequence menu'
1492 // pdbMenu.add(RNAFold);
1493 // pdbMenu.add(ContraFold);
1494 pdbMenu.add(enterPDB);
1495 pdbMenu.add(discoverPDB);
1496 jMenu1.add(groupName);
1497 jMenu1.add(colourMenu);
1498 jMenu1.add(showBoxes);
1499 jMenu1.add(showText);
1500 jMenu1.add(showColourText);
1501 jMenu1.add(outline);
1502 jMenu1.add(displayNonconserved);
1503 noColourmenuItem.setText(MessageManager.getString("label.none"));
1504 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1507 public void actionPerformed(ActionEvent e)
1509 noColourmenuItem_actionPerformed();
1513 clustalColour.setText(MessageManager
1514 .getString("label.clustalx_colours"));
1515 clustalColour.addActionListener(new java.awt.event.ActionListener()
1518 public void actionPerformed(ActionEvent e)
1520 clustalColour_actionPerformed();
1523 zappoColour.setText(MessageManager.getString("label.zappo"));
1524 zappoColour.addActionListener(new java.awt.event.ActionListener()
1527 public void actionPerformed(ActionEvent e)
1529 zappoColour_actionPerformed();
1532 taylorColour.setText(MessageManager.getString("label.taylor"));
1533 taylorColour.addActionListener(new java.awt.event.ActionListener()
1536 public void actionPerformed(ActionEvent e)
1538 taylorColour_actionPerformed();
1541 hydrophobicityColour.setText(MessageManager
1542 .getString("label.hydrophobicity"));
1543 hydrophobicityColour
1544 .addActionListener(new java.awt.event.ActionListener()
1547 public void actionPerformed(ActionEvent e)
1549 hydrophobicityColour_actionPerformed();
1552 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1553 helixColour.addActionListener(new java.awt.event.ActionListener()
1556 public void actionPerformed(ActionEvent e)
1558 helixColour_actionPerformed();
1561 strandColour.setText(MessageManager
1562 .getString("label.strand_propensity"));
1563 strandColour.addActionListener(new java.awt.event.ActionListener()
1566 public void actionPerformed(ActionEvent e)
1568 strandColour_actionPerformed();
1571 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1572 turnColour.addActionListener(new java.awt.event.ActionListener()
1575 public void actionPerformed(ActionEvent e)
1577 turnColour_actionPerformed();
1580 buriedColour.setText(MessageManager.getString("label.buried_index"));
1581 buriedColour.addActionListener(new java.awt.event.ActionListener()
1584 public void actionPerformed(ActionEvent e)
1586 buriedColour_actionPerformed();
1589 abovePIDColour.setText(MessageManager
1590 .getString("label.above_identity_percentage"));
1591 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1594 public void actionPerformed(ActionEvent e)
1596 abovePIDColour_actionPerformed();
1599 userDefinedColour.setText(MessageManager
1600 .getString("action.user_defined"));
1601 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1604 public void actionPerformed(ActionEvent e)
1606 userDefinedColour_actionPerformed(e);
1610 .setText(MessageManager.getString("label.percentage_identity"));
1611 PIDColour.addActionListener(new java.awt.event.ActionListener()
1614 public void actionPerformed(ActionEvent e)
1616 PIDColour_actionPerformed();
1619 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1620 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1623 public void actionPerformed(ActionEvent e)
1625 BLOSUM62Colour_actionPerformed();
1628 purinePyrimidineColour.setText(MessageManager
1629 .getString("label.purine_pyrimidine"));
1630 purinePyrimidineColour
1631 .addActionListener(new java.awt.event.ActionListener()
1634 public void actionPerformed(ActionEvent e)
1636 purinePyrimidineColour_actionPerformed();
1641 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1642 * public void actionPerformed(ActionEvent e) {
1643 * covariationColour_actionPerformed(); } });
1646 conservationMenuItem.setText(MessageManager
1647 .getString("label.conservation"));
1648 conservationMenuItem
1649 .addActionListener(new java.awt.event.ActionListener()
1652 public void actionPerformed(ActionEvent e)
1654 conservationMenuItem_actionPerformed();
1660 * Check for any annotations on the underlying dataset sequences (for the
1661 * current selection group) which are not 'on the alignment'.If any are found,
1662 * enable the option to add them to the alignment. The criteria for 'on the
1663 * alignment' is finding an alignment annotation on the alignment, matched on
1664 * calcId, label and sequenceRef.
1666 * A tooltip is also constructed that displays the source (calcId) and type
1667 * (label) of the annotations that can be added.
1670 * @param forSequences
1672 protected void configureReferenceAnnotationsMenu(
1673 JMenuItem menuItem, List<SequenceI> forSequences)
1675 menuItem.setEnabled(false);
1678 * Temporary store to hold distinct calcId / type pairs for the tooltip.
1679 * Using TreeMap means calcIds are shown in alphabetical order.
1681 Map<String, String> tipEntries = new TreeMap<String, String>();
1682 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
1683 AlignmentI al = this.ap.av.getAlignment();
1684 AlignmentUtils.findAddableReferenceAnnotations(forSequences,
1685 tipEntries, candidates, al);
1686 if (!candidates.isEmpty())
1688 StringBuilder tooltip = new StringBuilder(64);
1689 tooltip.append(MessageManager.getString("label.add_annotations_for"));
1692 * Found annotations that could be added. Enable the menu item, and
1693 * configure its tooltip and action.
1695 menuItem.setEnabled(true);
1696 for (String calcId : tipEntries.keySet())
1698 tooltip.append("<br/>" + calcId + "/" + tipEntries.get(calcId));
1700 String tooltipText = JvSwingUtils.wrapTooltip(true,
1701 tooltip.toString());
1702 menuItem.setToolTipText(tooltipText);
1704 menuItem.addActionListener(new ActionListener()
1707 public void actionPerformed(ActionEvent e)
1709 addReferenceAnnotations_actionPerformed(candidates);
1716 * Add annotations to the sequences and to the alignment.
1719 * a map whose keys are sequences on the alignment, and values a list
1720 * of annotations to add to each sequence
1722 protected void addReferenceAnnotations_actionPerformed(
1723 Map<SequenceI, List<AlignmentAnnotation>> candidates)
1725 final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
1726 final AlignmentI alignment = this.ap.getAlignment();
1727 AlignmentUtils.addReferenceAnnotations(candidates, alignment,
1732 protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
1734 if (!ap.av.getAlignment().hasSeqrep())
1736 // initialise the display flags so the user sees something happen
1737 ap.av.setDisplayReferenceSeq(true);
1738 ap.av.setColourByReferenceSeq(true);
1739 ap.av.getAlignment().setSeqrep(sequence);
1743 if (ap.av.getAlignment().getSeqrep() == sequence)
1745 ap.av.getAlignment().setSeqrep(null);
1749 ap.av.getAlignment().setSeqrep(sequence);
1755 protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
1757 if (sequence != null)
1759 ColumnSelection cs = ap.av.getColumnSelection();
1762 cs = new ColumnSelection();
1764 cs.hideInsertionsFor(sequence);
1765 ap.av.setColumnSelection(cs);
1769 protected void sequenceSelectionDetails_actionPerformed()
1771 createSequenceDetailsReport(ap.av.getSequenceSelection());
1774 protected void sequenceDetails_actionPerformed()
1776 createSequenceDetailsReport(new SequenceI[]
1780 public void createSequenceDetailsReport(SequenceI[] sequences)
1782 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1783 StringBuffer contents = new StringBuffer();
1784 for (SequenceI seq : sequences)
1786 contents.append("<p><h2>"
1789 "label.create_sequence_details_report_annotation_for",
1791 { seq.getDisplayId(true) }) + "</h2></p><p>");
1792 new SequenceAnnotationReport(null)
1793 .createSequenceAnnotationReport(
1799 (ap.getSeqPanel().seqCanvas.fr != null) ? ap
1800 .getSeqPanel().seqCanvas.fr
1803 contents.append("</p>");
1805 cap.setText("<html>" + contents.toString() + "</html>");
1807 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1808 "label.sequence_details_for",
1809 (sequences.length == 1 ? new Object[]
1810 { sequences[0].getDisplayId(true) } : new Object[]
1811 { MessageManager.getString("label.selection") })), 500, 400);
1815 protected void showNonconserved_actionPerformed()
1817 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1822 * call to refresh view after settings change
1826 ap.updateAnnotation();
1827 ap.paintAlignment(true);
1829 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1838 protected void clustalColour_actionPerformed()
1840 SequenceGroup sg = getGroup();
1841 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1851 protected void zappoColour_actionPerformed()
1853 getGroup().cs = new ZappoColourScheme();
1863 protected void taylorColour_actionPerformed()
1865 getGroup().cs = new TaylorColourScheme();
1875 protected void hydrophobicityColour_actionPerformed()
1877 getGroup().cs = new HydrophobicColourScheme();
1887 protected void helixColour_actionPerformed()
1889 getGroup().cs = new HelixColourScheme();
1899 protected void strandColour_actionPerformed()
1901 getGroup().cs = new StrandColourScheme();
1911 protected void turnColour_actionPerformed()
1913 getGroup().cs = new TurnColourScheme();
1923 protected void buriedColour_actionPerformed()
1925 getGroup().cs = new BuriedColourScheme();
1935 public void nucleotideMenuItem_actionPerformed()
1937 getGroup().cs = new NucleotideColourScheme();
1941 protected void purinePyrimidineColour_actionPerformed()
1943 getGroup().cs = new PurinePyrimidineColourScheme();
1948 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1949 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1957 protected void abovePIDColour_actionPerformed()
1959 SequenceGroup sg = getGroup();
1965 if (abovePIDColour.isSelected())
1967 sg.cs.setConsensus(AAFrequency.calculate(
1968 sg.getSequences(ap.av.getHiddenRepSequences()),
1969 sg.getStartRes(), sg.getEndRes() + 1));
1971 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1974 sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1976 SliderPanel.showPIDSlider();
1979 // remove PIDColouring
1981 sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1993 protected void userDefinedColour_actionPerformed(ActionEvent e)
1995 SequenceGroup sg = getGroup();
1997 if (e.getSource().equals(userDefinedColour))
1999 new UserDefinedColours(ap, sg);
2003 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2004 .getUserColourSchemes().get(e.getActionCommand());
2012 * Open a panel where the user can choose which types of sequence annotation
2017 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2019 // todo correct way to guard against opening a duplicate panel?
2020 new AnnotationChooser(ap);
2029 protected void PIDColour_actionPerformed()
2031 SequenceGroup sg = getGroup();
2032 sg.cs = new PIDColourScheme();
2033 sg.cs.setConsensus(AAFrequency.calculate(
2034 sg.getSequences(ap.av.getHiddenRepSequences()),
2035 sg.getStartRes(), sg.getEndRes() + 1));
2045 protected void BLOSUM62Colour_actionPerformed()
2047 SequenceGroup sg = getGroup();
2049 sg.cs = new Blosum62ColourScheme();
2051 sg.cs.setConsensus(AAFrequency.calculate(
2052 sg.getSequences(ap.av.getHiddenRepSequences()),
2053 sg.getStartRes(), sg.getEndRes() + 1));
2064 protected void noColourmenuItem_actionPerformed()
2066 getGroup().cs = null;
2076 protected void conservationMenuItem_actionPerformed()
2078 SequenceGroup sg = getGroup();
2084 if (conservationMenuItem.isSelected())
2086 // JBPNote: Conservation name shouldn't be i18n translated
2087 Conservation c = new Conservation("Group",
2088 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2089 .getHiddenRepSequences()), sg.getStartRes(),
2090 sg.getEndRes() + 1);
2093 c.verdict(false, ap.av.getConsPercGaps());
2095 sg.cs.setConservation(c);
2097 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2098 SliderPanel.showConservationSlider();
2101 // remove ConservationColouring
2103 sg.cs.setConservation(null);
2109 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2111 SequenceGroup sg = getGroup();
2117 AnnotationColourGradient acg = new AnnotationColourGradient(
2118 sequence.getAnnotation()[0], null,
2119 AnnotationColourGradient.NO_THRESHOLD);
2121 acg.setPredefinedColours(true);
2133 protected void groupName_actionPerformed()
2136 SequenceGroup sg = getGroup();
2137 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2138 sg.getDescription(), " "
2139 + MessageManager.getString("label.group_name") + " ",
2140 MessageManager.getString("label.group_description") + " ",
2141 MessageManager.getString("label.edit_group_name_description"),
2149 sg.setName(dialog.getName());
2150 sg.setDescription(dialog.getDescription());
2155 * Get selection group - adding it to the alignment if necessary.
2157 * @return sequence group to operate on
2159 SequenceGroup getGroup()
2161 SequenceGroup sg = ap.av.getSelectionGroup();
2162 // this method won't add a new group if it already exists
2165 ap.av.getAlignment().addGroup(sg);
2177 void sequenceName_actionPerformed()
2179 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2180 sequence.getDescription(),
2181 " " + MessageManager.getString("label.sequence_name")
2183 MessageManager.getString("label.sequence_description") + " ",
2185 .getString("label.edit_sequence_name_description"),
2193 if (dialog.getName() != null)
2195 if (dialog.getName().indexOf(" ") > -1)
2201 .getString("label.spaces_converted_to_backslashes"),
2203 .getString("label.no_spaces_allowed_sequence_name"),
2204 JOptionPane.WARNING_MESSAGE);
2207 sequence.setName(dialog.getName().replace(' ', '_'));
2208 ap.paintAlignment(false);
2211 sequence.setDescription(dialog.getDescription());
2213 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2224 void unGroupMenuItem_actionPerformed()
2226 SequenceGroup sg = ap.av.getSelectionGroup();
2227 ap.av.getAlignment().deleteGroup(sg);
2228 ap.av.setSelectionGroup(null);
2232 void createGroupMenuItem_actionPerformed()
2234 getGroup(); // implicitly creates group - note - should apply defaults / use
2235 // standard alignment window logic for this
2245 protected void outline_actionPerformed()
2247 SequenceGroup sg = getGroup();
2248 Color col = JColorChooser.showDialog(this,
2249 MessageManager.getString("label.select_outline_colour"),
2254 sg.setOutlineColour(col);
2266 public void showBoxes_actionPerformed()
2268 getGroup().setDisplayBoxes(showBoxes.isSelected());
2278 public void showText_actionPerformed()
2280 getGroup().setDisplayText(showText.isSelected());
2290 public void showColourText_actionPerformed()
2292 getGroup().setColourText(showColourText.isSelected());
2296 public void showLink(String url)
2300 jalview.util.BrowserLauncher.openURL(url);
2301 } catch (Exception ex)
2303 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2304 MessageManager.getString("label.web_browser_not_found_unix"),
2305 MessageManager.getString("label.web_browser_not_found"),
2306 JOptionPane.WARNING_MESSAGE);
2308 ex.printStackTrace();
2312 void hideSequences(boolean representGroup)
2314 SequenceGroup sg = ap.av.getSelectionGroup();
2315 if (sg == null || sg.getSize() < 1)
2317 ap.av.hideSequence(new SequenceI[]
2322 ap.av.setSelectionGroup(null);
2326 ap.av.hideRepSequences(sequence, sg);
2331 int gsize = sg.getSize();
2332 SequenceI[] hseqs = sg.getSequences().toArray(new SequenceI[gsize]);
2334 ap.av.hideSequence(hseqs);
2335 // refresh(); TODO: ? needed ?
2336 ap.av.sendSelection();
2339 public void copy_actionPerformed()
2341 ap.alignFrame.copy_actionPerformed(null);
2344 public void cut_actionPerformed()
2346 ap.alignFrame.cut_actionPerformed(null);
2349 void changeCase(ActionEvent e)
2351 Object source = e.getSource();
2352 SequenceGroup sg = ap.av.getSelectionGroup();
2356 List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
2358 sg.getEndRes() + 1);
2363 if (source == toggle)
2365 description = MessageManager.getString("label.toggle_case");
2366 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2368 else if (source == upperCase)
2370 description = MessageManager.getString("label.to_upper_case");
2371 caseChange = ChangeCaseCommand.TO_UPPER;
2375 description = MessageManager.getString("label.to_lower_case");
2376 caseChange = ChangeCaseCommand.TO_LOWER;
2379 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2380 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2381 startEnd, caseChange);
2383 ap.alignFrame.addHistoryItem(caseCommand);
2385 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2391 public void outputText_actionPerformed(ActionEvent e)
2393 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2394 cap.setForInput(null);
2395 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2396 "label.alignment_output_command", new Object[]
2397 { e.getActionCommand() }), 600, 500);
2399 String[] omitHidden = null;
2401 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2402 // or we simply trust the user wants
2403 // wysiwig behaviour
2405 cap.setText(new FormatAdapter(ap).formatSequences(e.getActionCommand(),
2409 public void pdbFromFile_actionPerformed()
2411 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2412 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2413 chooser.setFileView(new jalview.io.JalviewFileView());
2414 chooser.setDialogTitle(MessageManager.formatMessage(
2415 "label.select_pdb_file_for", new Object[]
2416 { sequence.getDisplayId(false) }));
2417 chooser.setToolTipText(MessageManager.formatMessage(
2418 "label.load_pdb_file_associate_with_sequence", new Object[]
2419 { sequence.getDisplayId(false) }));
2421 int value = chooser.showOpenDialog(null);
2423 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2425 String choice = chooser.getSelectedFile().getPath();
2426 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2427 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2428 jalview.io.AppletFormatAdapter.FILE, sequence, true,
2435 public void enterPDB_actionPerformed()
2437 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2438 MessageManager.getString("label.enter_pdb_id"),
2439 MessageManager.getString("label.enter_pdb_id"),
2440 JOptionPane.QUESTION_MESSAGE);
2442 if (id != null && id.length() > 0)
2444 PDBEntry entry = new PDBEntry();
2445 entry.setId(id.toUpperCase());
2446 sequence.getDatasetSequence().addPDBId(entry);
2450 public void discoverPDB_actionPerformed()
2453 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2455 : ap.av.getSequenceSelection());
2456 Thread discpdb = new Thread(new Runnable()
2462 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2463 .fetchDBRefs(false);
2470 public void sequenceFeature_actionPerformed()
2472 SequenceGroup sg = ap.av.getSelectionGroup();
2478 int rsize = 0, gSize = sg.getSize();
2479 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2480 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2482 for (int i = 0; i < gSize; i++)
2484 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2485 int end = sg.findEndRes(sg.getSequenceAt(i));
2488 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2489 features[rsize] = new SequenceFeature(null, null, null, start, end,
2494 rseqs = new SequenceI[rsize];
2495 tfeatures = new SequenceFeature[rsize];
2496 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2497 System.arraycopy(features, 0, tfeatures, 0, rsize);
2498 features = tfeatures;
2500 if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2501 features, true, ap))
2503 ap.alignFrame.setShowSeqFeatures(true);
2504 ap.highlightSearchResults(null);
2508 public void textColour_actionPerformed()
2510 SequenceGroup sg = getGroup();
2513 new TextColourChooser().chooseColour(ap, sg);
2517 public void colourByStructure(String pdbid)
2519 Annotation[] anots = ap.av.getStructureSelectionManager()
2520 .colourSequenceFromStructure(sequence, pdbid);
2522 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2523 "Coloured by " + pdbid, anots);
2525 ap.av.getAlignment().addAnnotation(an);
2526 an.createSequenceMapping(sequence, 0, true);
2527 // an.adjustForAlignment();
2528 ap.av.getAlignment().setAnnotationIndex(an, 0);
2530 ap.adjustAnnotationHeight();
2532 sequence.addAlignmentAnnotation(an);
2536 public void editSequence_actionPerformed(ActionEvent actionEvent)
2538 SequenceGroup sg = ap.av.getSelectionGroup();
2542 if (sequence == null)
2544 sequence = sg.getSequenceAt(0);
2547 EditNameDialog dialog = new EditNameDialog(
2548 sequence.getSequenceAsString(sg.getStartRes(),
2549 sg.getEndRes() + 1), null,
2550 MessageManager.getString("label.edit_sequence"), null,
2551 MessageManager.getString("label.edit_sequence"),
2556 EditCommand editCommand = new EditCommand(
2557 MessageManager.getString("label.edit_sequences"),
2558 Action.REPLACE, dialog.getName().replace(' ',
2559 ap.av.getGapCharacter()),
2560 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2561 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2563 ap.alignFrame.addHistoryItem(editCommand);
2565 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()