2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.Conservation;
25 import jalview.commands.ChangeCaseCommand;
26 import jalview.commands.EditCommand;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.Annotation;
29 import jalview.datamodel.DBRefEntry;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.Sequence;
32 import jalview.datamodel.SequenceFeature;
33 import jalview.datamodel.SequenceGroup;
34 import jalview.datamodel.SequenceI;
35 import jalview.io.FormatAdapter;
36 import jalview.io.SequenceAnnotationReport;
37 import jalview.renderer.AnnotationRenderer;
38 import jalview.schemes.AnnotationColourGradient;
39 import jalview.schemes.Blosum62ColourScheme;
40 import jalview.schemes.BuriedColourScheme;
41 import jalview.schemes.ClustalxColourScheme;
42 import jalview.schemes.HelixColourScheme;
43 import jalview.schemes.HydrophobicColourScheme;
44 import jalview.schemes.NucleotideColourScheme;
45 import jalview.schemes.PIDColourScheme;
46 import jalview.schemes.PurinePyrimidineColourScheme;
47 import jalview.schemes.ResidueProperties;
48 import jalview.schemes.StrandColourScheme;
49 import jalview.schemes.TaylorColourScheme;
50 import jalview.schemes.TurnColourScheme;
51 import jalview.schemes.UserColourScheme;
52 import jalview.schemes.ZappoColourScheme;
53 import jalview.util.GroupUrlLink;
54 import jalview.util.GroupUrlLink.UrlStringTooLongException;
55 import jalview.util.MessageManager;
56 import jalview.util.UrlLink;
58 import java.awt.Color;
59 import java.awt.event.ActionEvent;
60 import java.awt.event.ActionListener;
61 import java.util.ArrayList;
62 import java.util.Arrays;
63 import java.util.BitSet;
64 import java.util.Collection;
65 import java.util.Hashtable;
66 import java.util.LinkedHashMap;
67 import java.util.List;
69 import java.util.Vector;
71 import javax.swing.ButtonGroup;
72 import javax.swing.JCheckBoxMenuItem;
73 import javax.swing.JColorChooser;
74 import javax.swing.JMenu;
75 import javax.swing.JMenuItem;
76 import javax.swing.JOptionPane;
77 import javax.swing.JPopupMenu;
78 import javax.swing.JRadioButtonMenuItem;
84 * @version $Revision: 1.118 $
86 public class PopupMenu extends JPopupMenu
88 private static final String ALL_ANNOTATIONS = "All";
90 private static final String COMMA = ",";
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 // protected JRadioButtonMenuItem covariationColour = new
125 // 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 chooseAnnotations = new JMenuItem();
145 JMenuItem createGroupMenuItem = new JMenuItem();
147 JMenuItem unGroupMenuItem = new JMenuItem();
149 JMenuItem outline = new JMenuItem();
151 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
153 JMenu colourMenu = new JMenu();
155 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
157 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
159 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
161 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
163 JMenu editMenu = new JMenu();
165 JMenuItem cut = new JMenuItem();
167 JMenuItem copy = new JMenuItem();
169 JMenuItem upperCase = new JMenuItem();
171 JMenuItem lowerCase = new JMenuItem();
173 JMenuItem toggle = new JMenuItem();
175 JMenu pdbMenu = new JMenu();
177 JMenuItem pdbFromFile = new JMenuItem();
179 // JBPNote: Commented these out - Should add these services via the web
180 // services menu system.
181 // JMenuItem ContraFold = new JMenuItem();
183 // JMenuItem RNAFold = new JMenuItem();
185 JMenuItem enterPDB = new JMenuItem();
187 JMenuItem discoverPDB = new JMenuItem();
189 JMenu outputMenu = new JMenu();
191 JMenu showAnnotationsMenu = new JMenu();
193 JMenu hideAnnotationsMenu = new JMenu();
195 JMenuItem sequenceFeature = new JMenuItem();
197 JMenuItem textColour = new JMenuItem();
199 JMenu jMenu1 = new JMenu();
201 JMenu structureMenu = new JMenu();
203 JMenu viewStructureMenu = new JMenu();
205 // JMenu colStructureMenu = new JMenu();
206 JMenuItem editSequence = new JMenuItem();
208 // JMenuItem annotationMenuItem = new JMenuItem();
210 JMenu groupLinksMenu;
213 * Creates a new PopupMenu object.
220 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
222 this(ap, seq, links, null);
232 public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
233 Vector links, Vector groupLinks)
235 // /////////////////////////////////////////////////////////
236 // If this is activated from the sequence panel, the user may want to
237 // edit or annotate a particular residue. Therefore display the residue menu
239 // If from the IDPanel, we must display the sequence menu
240 // ////////////////////////////////////////////////////////
244 ButtonGroup colours = new ButtonGroup();
245 colours.add(noColourmenuItem);
246 colours.add(clustalColour);
247 colours.add(zappoColour);
248 colours.add(taylorColour);
249 colours.add(hydrophobicityColour);
250 colours.add(helixColour);
251 colours.add(strandColour);
252 colours.add(turnColour);
253 colours.add(buriedColour);
254 colours.add(abovePIDColour);
255 colours.add(userDefinedColour);
256 colours.add(PIDColour);
257 colours.add(BLOSUM62Colour);
258 colours.add(purinePyrimidineColour);
259 colours.add(RNAInteractionColour);
260 // colours.add(covariationColour);
262 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
264 JMenuItem item = new JMenuItem(
265 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
267 item.addActionListener(new java.awt.event.ActionListener()
270 public void actionPerformed(ActionEvent e)
272 outputText_actionPerformed(e);
276 outputMenu.add(item);
280 * Build menus for annotation types that may be shown or hidden.
282 buildAnnotationTypesMenus();
287 } catch (Exception e)
295 sequenceMenu.setText(sequence.getName());
297 if (seq.getDatasetSequence().getPDBId() != null
298 && seq.getDatasetSequence().getPDBId().size() > 0)
300 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
303 while (e.hasMoreElements())
305 final PDBEntry pdb = (PDBEntry) e.nextElement();
307 menuItem = new JMenuItem();
308 menuItem.setText(pdb.getId());
309 menuItem.addActionListener(new java.awt.event.ActionListener()
311 public void actionPerformed(ActionEvent e)
313 // TODO re JAL-860: optionally open dialog or provide a menu entry
314 // allowing user to open just one structure per sequence
315 // new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
316 // { pdb })[0], null, ap);
317 new StructureViewer(ap.getStructureSelectionManager())
319 ap.av.collateForPDB(new PDBEntry[]
320 { pdb })[0], null, ap);
323 viewStructureMenu.add(menuItem);
326 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
327 * menuItem.addActionListener(new java.awt.event.ActionListener() {
328 * public void actionPerformed(ActionEvent e) {
329 * colourByStructure(pdb.getId()); } });
330 * colStructureMenu.add(menuItem);
336 if (ap.av.getAlignment().isNucleotide() == false)
338 structureMenu.remove(viewStructureMenu);
340 // structureMenu.remove(colStructureMenu);
343 if (ap.av.getAlignment().isNucleotide() == true)
345 AlignmentAnnotation[] aa = ap.av.getAlignment()
346 .getAlignmentAnnotation();
347 for (int i = 0; i < aa.length; i++)
349 if (aa[i].getRNAStruc() != null)
351 final String rnastruc = aa[i].getRNAStruc();
352 final String structureLine = aa[i].label;
353 menuItem = new JMenuItem();
354 menuItem.setText(MessageManager.formatMessage(
355 "label.2d_rna_structure_line", new String[]
357 menuItem.addActionListener(new java.awt.event.ActionListener()
361 public void actionPerformed(ActionEvent e)
363 // System.out.println("1:"+structureLine);
364 System.out.println("1:sname" + seq.getName());
365 System.out.println("2:seq" + seq);
367 // System.out.println("3:"+seq.getSequenceAsString());
368 System.out.println("3:strucseq" + rnastruc);
369 // System.out.println("4:struc"+seq.getRNA());
370 System.out.println("5:name" + seq.getName());
371 System.out.println("6:ap" + ap);
372 new AppVarna(structureLine, seq, seq.getSequenceAsString(),
373 rnastruc, seq.getName(), ap);
374 // new AppVarna(seq.getName(),seq,rnastruc,seq.getRNA(),
375 // seq.getName(), ap);
376 System.out.println("end");
379 viewStructureMenu.add(menuItem);
383 // SequenceFeatures[] test = seq.getSequenceFeatures();
385 if (seq.getAnnotation() != null)
387 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
388 for (int i = 0; i < seqAnno.length; i++)
390 if (seqAnno[i].getRNAStruc() != null)
392 final String rnastruc = seqAnno[i].getRNAStruc();
394 // TODO: make rnastrucF a bit more nice
395 menuItem = new JMenuItem();
396 menuItem.setText(MessageManager.formatMessage(
397 "label.2d_rna_sequence_name", new String[]
399 menuItem.addActionListener(new java.awt.event.ActionListener()
402 public void actionPerformed(ActionEvent e)
404 // TODO: VARNA does'nt print gaps in the sequence
406 new AppVarna(seq.getName() + " structure", seq, seq
407 .getSequenceAsString(), rnastruc, seq.getName(),
411 viewStructureMenu.add(menuItem);
418 menuItem = new JMenuItem(
419 MessageManager.getString("action.hide_sequences"));
420 menuItem.addActionListener(new java.awt.event.ActionListener()
423 public void actionPerformed(ActionEvent e)
425 hideSequences(false);
430 if (ap.av.getSelectionGroup() != null
431 && ap.av.getSelectionGroup().getSize() > 1)
433 menuItem = new JMenuItem(MessageManager.formatMessage(
434 "label.represent_group_with", new String[]
436 menuItem.addActionListener(new java.awt.event.ActionListener()
439 public void actionPerformed(ActionEvent e)
444 sequenceMenu.add(menuItem);
447 if (ap.av.hasHiddenRows())
449 final int index = ap.av.getAlignment().findIndex(seq);
451 if (ap.av.adjustForHiddenSeqs(index)
452 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
454 menuItem = new JMenuItem(
455 MessageManager.getString("action.reveal_sequences"));
456 menuItem.addActionListener(new ActionListener()
459 public void actionPerformed(ActionEvent e)
461 ap.av.showSequence(index);
462 if (ap.overviewPanel != null)
464 ap.overviewPanel.updateOverviewImage();
472 // for the case when no sequences are even visible
473 if (ap.av.hasHiddenRows())
476 menuItem = new JMenuItem(
477 MessageManager.getString("action.reveal_all"));
478 menuItem.addActionListener(new ActionListener()
481 public void actionPerformed(ActionEvent e)
483 ap.av.showAllHiddenSeqs();
484 if (ap.overviewPanel != null)
486 ap.overviewPanel.updateOverviewImage();
496 SequenceGroup sg = ap.av.getSelectionGroup();
497 boolean isDefinedGroup = (sg != null) ? ap.av.getAlignment()
498 .getGroups().contains(sg) : false;
500 if (sg != null && sg.getSize() > 0)
502 groupName.setText(MessageManager.formatMessage("label.name_param",
505 groupName.setText(MessageManager
506 .getString("label.edit_name_and_description_current_group"));
508 if (sg.cs instanceof ZappoColourScheme)
510 zappoColour.setSelected(true);
512 else if (sg.cs instanceof TaylorColourScheme)
514 taylorColour.setSelected(true);
516 else if (sg.cs instanceof PIDColourScheme)
518 PIDColour.setSelected(true);
520 else if (sg.cs instanceof Blosum62ColourScheme)
522 BLOSUM62Colour.setSelected(true);
524 else if (sg.cs instanceof UserColourScheme)
526 userDefinedColour.setSelected(true);
528 else if (sg.cs instanceof HydrophobicColourScheme)
530 hydrophobicityColour.setSelected(true);
532 else if (sg.cs instanceof HelixColourScheme)
534 helixColour.setSelected(true);
536 else if (sg.cs instanceof StrandColourScheme)
538 strandColour.setSelected(true);
540 else if (sg.cs instanceof TurnColourScheme)
542 turnColour.setSelected(true);
544 else if (sg.cs instanceof BuriedColourScheme)
546 buriedColour.setSelected(true);
548 else if (sg.cs instanceof ClustalxColourScheme)
550 clustalColour.setSelected(true);
552 else if (sg.cs instanceof PurinePyrimidineColourScheme)
554 purinePyrimidineColour.setSelected(true);
558 * else if (sg.cs instanceof CovariationColourScheme) {
559 * covariationColour.setSelected(true); }
563 noColourmenuItem.setSelected(true);
566 if (sg.cs != null && sg.cs.conservationApplied())
568 conservationMenuItem.setSelected(true);
570 displayNonconserved.setSelected(sg.getShowNonconserved());
571 showText.setSelected(sg.getDisplayText());
572 showColourText.setSelected(sg.getColourText());
573 showBoxes.setSelected(sg.getDisplayBoxes());
574 // add any groupURLs to the groupURL submenu and make it visible
575 if (groupLinks != null && groupLinks.size() > 0)
577 buildGroupURLMenu(sg, groupLinks);
579 // Add a 'show all structures' for the current selection
580 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(), reppdb = new Hashtable<String, PDBEntry>();
581 SequenceI sqass = null;
582 for (SequenceI sq : ap.av.getSequenceSelection())
584 Vector<PDBEntry> pes = sq.getDatasetSequence().getPDBId();
585 if (pes != null && pes.size() > 0)
587 reppdb.put(pes.get(0).getId(), pes.get(0));
588 for (PDBEntry pe : pes)
590 pdbe.put(pe.getId(), pe);
600 final PDBEntry[] pe = pdbe.values().toArray(
601 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
602 new PDBEntry[reppdb.size()]);
603 final JMenuItem gpdbview, rpdbview;
604 if (pdbe.size() == 1)
606 structureMenu.add(gpdbview = new JMenuItem(MessageManager
607 .formatMessage("label.view_structure_for", new String[]
608 { sqass.getDisplayId(false) })));
612 structureMenu.add(gpdbview = new JMenuItem(MessageManager
613 .formatMessage("label.view_all_structures", new String[]
614 { new Integer(pdbe.size()).toString() })));
616 gpdbview.setToolTipText(MessageManager
617 .getString("label.open_new_jmol_view_with_all_structures_associated_current_selection_superimpose_using_alignment"));
618 gpdbview.addActionListener(new ActionListener()
622 public void actionPerformed(ActionEvent e)
624 new StructureViewer(ap.getStructureSelectionManager())
625 .viewStructures(ap, pe, ap.av.collateForPDB(pe));
628 if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
630 structureMenu.add(rpdbview = new JMenuItem(MessageManager
632 "label.view_all_representative_structures",
634 { new Integer(reppdb.size()).toString() })));
635 rpdbview.setToolTipText(MessageManager
636 .getString("label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment"));
637 rpdbview.addActionListener(new ActionListener()
641 public void actionPerformed(ActionEvent e)
643 new StructureViewer(ap.getStructureSelectionManager())
644 .viewStructures(ap, pr, ap.av.collateForPDB(pr));
652 groupMenu.setVisible(false);
653 editMenu.setVisible(false);
658 createGroupMenuItem.setVisible(true);
659 unGroupMenuItem.setVisible(false);
660 jMenu1.setText(MessageManager.getString("action.edit_new_group"));
664 createGroupMenuItem.setVisible(false);
665 unGroupMenuItem.setVisible(true);
666 jMenu1.setText(MessageManager.getString("action.edit_group"));
671 sequenceMenu.setVisible(false);
672 structureMenu.setVisible(false);
675 if (links != null && links.size() > 0)
678 JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
679 Vector linkset = new Vector();
680 for (int i = 0; i < links.size(); i++)
682 String link = links.elementAt(i).toString();
683 UrlLink urlLink = null;
686 urlLink = new UrlLink(link);
687 } catch (Exception foo)
689 jalview.bin.Cache.log.error("Exception for URLLink '" + link
694 if (!urlLink.isValid())
696 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
699 final String label = urlLink.getLabel();
700 if (seq != null && urlLink.isDynamic())
703 // collect matching db-refs
704 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
705 seq.getDBRef(), new String[]
706 { urlLink.getTarget() });
707 // collect id string too
708 String id = seq.getName();
709 String descr = seq.getDescription();
710 if (descr != null && descr.length() < 1)
717 for (int r = 0; r < dbr.length; r++)
719 if (id != null && dbr[r].getAccessionId().equals(id))
721 // suppress duplicate link creation for the bare sequence ID
722 // string with this link
725 // create Bare ID link for this RUL
726 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
730 for (int u = 0; u < urls.length; u += 2)
732 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
734 linkset.addElement(urls[u] + "|" + urls[u + 1]);
735 addshowLink(linkMenu, label + "|" + urls[u],
744 // create Bare ID link for this RUL
745 String[] urls = urlLink.makeUrls(id, true);
748 for (int u = 0; u < urls.length; u += 2)
750 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
752 linkset.addElement(urls[u] + "|" + urls[u + 1]);
753 addshowLink(linkMenu, label, urls[u + 1]);
758 // Create urls from description but only for URL links which are regex
760 if (descr != null && urlLink.getRegexReplace() != null)
762 // create link for this URL from description where regex matches
763 String[] urls = urlLink.makeUrls(descr, true);
766 for (int u = 0; u < urls.length; u += 2)
768 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
770 linkset.addElement(urls[u] + "|" + urls[u + 1]);
771 addshowLink(linkMenu, label, urls[u + 1]);
779 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
781 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
782 // Add a non-dynamic link
783 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
787 if (sequence != null)
789 sequenceMenu.add(linkMenu);
799 * Add annotation types to a 'Show annotations' or 'Hide annotations' menu.
800 * "All" is added first, followed by a separator. Then add any annotation
801 * types associated with the current selection. The second parameter controls
802 * whether we include only currently visible annotation types (for the Hide
803 * menu), or only currently hidden annotation types (for the Show menu).
805 * Some annotation rows are always rendered together - these can be identified
806 * by a common graphGroup property > -1. Only one of each group will be marked
807 * as visible (to avoid duplication of the display). For such groups we add a
808 * composite type name, e.g.
810 * IUPredWS (Long), IUPredWS (Short)
812 protected void buildAnnotationTypesMenus()
814 showAnnotationsMenu.removeAll();
815 hideAnnotationsMenu.removeAll();
816 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
817 addAnnotationTypeToShowHide(showAnnotationsMenu,
820 addAnnotationTypeToShowHide(hideAnnotationsMenu, all, true,
822 showAnnotationsMenu.addSeparator();
823 hideAnnotationsMenu.addSeparator();
825 final AlignmentAnnotation[] annotations = ap.getAlignment()
826 .getAlignmentAnnotation();
827 BitSet visibleGraphGroups = PopupMenu
828 .getVisibleLineGraphGroups(annotations);
830 List<List<String>> shownTypes = new ArrayList<List<String>>();
831 List<List<String>> hiddenTypes = new ArrayList<List<String>>();
832 PopupMenu.getAnnotationTypesForShowHide(shownTypes, hiddenTypes,
833 visibleGraphGroups, annotations, ap.av.getSelectionGroup());
835 for (List<String> types : hiddenTypes)
837 addAnnotationTypeToShowHide(showAnnotationsMenu, types, false, true);
840 for (List<String> types : shownTypes)
842 addAnnotationTypeToShowHide(hideAnnotationsMenu, types, false, false);
847 * Helper method to populate lists of annotation types for the Show/Hide
848 * Annotations menus. If sequenceGroup is not null, this is restricted to
849 * annotations which are associated with sequences in the selection group.
851 * If an annotation row is currently visible, its type (label) is added (once
852 * only per type), to the shownTypes list. If it is currently hidden, it is
853 * added to the hiddenTypesList.
855 * For rows that belong to a line graph group, so are always rendered
858 * <li>Treat all rows in the group as visible, if at least one of them is</li>
859 * <li>Build a comma-separated label with all the types that belong to the
865 * @param visibleGraphGroups
867 * @param sequenceGroup
869 public static void getAnnotationTypesForShowHide(
870 List<List<String>> shownTypes, List<List<String>> hiddenTypes,
871 BitSet visibleGraphGroups,
872 AlignmentAnnotation[] annotations, SequenceGroup sequenceGroup)
874 // lookup table, key = graph group, value = list of types in the group
875 Map<Integer, List<String>> groupLabels = new LinkedHashMap<Integer, List<String>>();
877 List<String> addedToShown = new ArrayList<String>();
878 List<String> addedToHidden = new ArrayList<String>();
880 for (AlignmentAnnotation aa : annotations)
883 if (sequenceGroup == null
884 || (aa.sequenceRef != null && sequenceGroup.getSequences()
885 .contains(aa.sequenceRef)))
888 * Build a 'composite label' for types in line graph groups.
890 final List<String> labelAsList = new ArrayList<String>();
891 labelAsList.add(aa.label);
892 if (aa.graph == AlignmentAnnotation.LINE_GRAPH
893 && aa.graphGroup > -1)
895 if (groupLabels.containsKey(aa.graphGroup))
897 if (!groupLabels.get(aa.graphGroup).contains(aa.label))
899 groupLabels.get(aa.graphGroup).add(aa.label);
904 groupLabels.put(aa.graphGroup, labelAsList);
907 else if (aa.visible && !addedToShown.contains(aa.label))
909 shownTypes.add(labelAsList);
910 addedToShown.add(aa.label);
914 if (!aa.visible && !addedToHidden.contains(aa.label))
916 hiddenTypes.add(labelAsList);
917 addedToHidden.add(aa.label);
923 * finally add the 'composite group labels' to the appropriate lists,
924 * depending on whether the group is identified as visible or hidden
926 for (int group : groupLabels.keySet())
928 final List<String> groupLabel = groupLabels.get(group);
929 if (visibleGraphGroups.get(group))
931 if (!shownTypes.contains(groupLabel))
933 shownTypes.add(groupLabel);
936 else if (!hiddenTypes.contains(groupLabel))
938 hiddenTypes.add(groupLabel);
944 * Returns a BitSet (possibly empty) of those graphGroups for line graph
945 * annotations, which have at least one member annotation row marked visible.
946 * The logic is that only one row in the group is marked visible, but when it
947 * is drawn, so are all the other rows in the same group.
949 * This lookup set allows us to check whether rows marked not visible are in
952 * @see AnnotationRenderer#drawComponent
956 public static BitSet getVisibleLineGraphGroups(
957 AlignmentAnnotation[] annotations)
959 // todo move to a utility class
960 BitSet result = new BitSet();
961 for (AlignmentAnnotation ann : annotations)
963 if (ann.graph == AlignmentAnnotation.LINE_GRAPH && ann.visible)
965 int gg = ann.graphGroup;
976 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
979 * @param showOrHideMenu
984 * if true this is a special label meaning 'All'
985 * @param actionIsShow
986 * if true, the select menu item action is to show the annotation
989 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
990 final Collection<String> types, final boolean allTypes,
991 final boolean actionIsShow)
993 String label = types.toString(); // [a, b, c]
994 label = label.substring(1, label.length() - 1);
995 final JMenuItem item = new JMenuItem(label);
996 item.addActionListener(new java.awt.event.ActionListener()
999 public void actionPerformed(ActionEvent e)
1001 showHideAnnotation_actionPerformed(types, allTypes, actionIsShow);
1004 showOrHideMenu.add(item);
1008 * Action on selecting a list of annotation type (or the 'all types' values)
1009 * to show or hide for the selection.
1015 protected void showHideAnnotation_actionPerformed(
1016 Collection<String> types,
1017 boolean anyType, boolean doShow)
1019 for (AlignmentAnnotation aa : ap.getAlignment()
1020 .getAlignmentAnnotation())
1022 if (anyType || types.contains(aa.label))
1024 if ((aa.sequenceRef != null)
1025 && ap.av.getSelectionGroup().getSequences()
1026 .contains(aa.sequenceRef))
1028 aa.visible = doShow;
1035 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
1038 // TODO: usability: thread off the generation of group url content so root
1039 // menu appears asap
1040 // sequence only URLs
1041 // ID/regex match URLs
1042 groupLinksMenu = new JMenu(
1043 MessageManager.getString("action.group_link"));
1044 JMenu[] linkMenus = new JMenu[]
1045 { null, new JMenu(MessageManager.getString("action.ids")),
1046 new JMenu(MessageManager.getString("action.sequences")),
1047 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
1054 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1055 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1056 Hashtable commonDbrefs = new Hashtable();
1057 for (int sq = 0; sq < seqs.length; sq++)
1060 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
1061 .findPosition(sg.getEndRes());
1062 // just collect ids from dataset sequence
1063 // TODO: check if IDs collected from selecton group intersects with the
1064 // current selection, too
1065 SequenceI sqi = seqs[sq];
1066 while (sqi.getDatasetSequence() != null)
1068 sqi = sqi.getDatasetSequence();
1070 DBRefEntry[] dbr = sqi.getDBRef();
1071 if (dbr != null && dbr.length > 0)
1073 for (int d = 0; d < dbr.length; d++)
1075 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1076 Object[] sarray = (Object[]) commonDbrefs.get(src);
1079 sarray = new Object[2];
1080 sarray[0] = new int[]
1082 sarray[1] = new String[seqs.length];
1084 commonDbrefs.put(src, sarray);
1087 if (((String[]) sarray[1])[sq] == null)
1089 if (!dbr[d].hasMap()
1090 || (dbr[d].getMap().locateMappedRange(start, end) != null))
1092 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1093 ((int[]) sarray[0])[0]++;
1099 // now create group links for all distinct ID/sequence sets.
1100 boolean addMenu = false; // indicates if there are any group links to give
1102 for (int i = 0; i < groupLinks.size(); i++)
1104 String link = groupLinks.elementAt(i).toString();
1105 GroupUrlLink urlLink = null;
1108 urlLink = new GroupUrlLink(link);
1109 } catch (Exception foo)
1111 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
1116 if (!urlLink.isValid())
1118 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
1121 final String label = urlLink.getLabel();
1122 boolean usingNames = false;
1123 // Now see which parts of the group apply for this URL
1124 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1125 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
1126 String[] seqstr, ids; // input to makeUrl
1129 int numinput = ((int[]) idset[0])[0];
1130 String[] allids = ((String[]) idset[1]);
1131 seqstr = new String[numinput];
1132 ids = new String[numinput];
1133 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1135 if (allids[sq] != null)
1137 ids[idcount] = allids[sq];
1138 seqstr[idcount++] = idandseqs[1][sq];
1144 // just use the id/seq set
1145 seqstr = idandseqs[1];
1149 // and try and make the groupURL!
1151 Object[] urlset = null;
1154 urlset = urlLink.makeUrlStubs(ids, seqstr,
1155 "FromJalview" + System.currentTimeMillis(), false);
1156 } catch (UrlStringTooLongException e)
1161 int type = urlLink.getGroupURLType() & 3;
1162 // System.out.println(urlLink.getGroupURLType()
1163 // +" "+((String[])urlset[3])[0]);
1164 // first two bits ofurlLink type bitfield are sequenceids and sequences
1165 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1166 addshowLink(linkMenus[type], label
1167 + (((type & 1) == 1) ? ("("
1168 + (usingNames ? "Names" : ltarget) + ")") : ""),
1175 groupLinksMenu = new JMenu(
1176 MessageManager.getString("action.group_link"));
1177 for (int m = 0; m < linkMenus.length; m++)
1179 if (linkMenus[m] != null
1180 && linkMenus[m].getMenuComponentCount() > 0)
1182 groupLinksMenu.add(linkMenus[m]);
1186 groupMenu.add(groupLinksMenu);
1191 * add a show URL menu item to the given linkMenu
1195 * - menu label string
1199 private void addshowLink(JMenu linkMenu, String label, final String url)
1201 JMenuItem item = new JMenuItem(label);
1202 item.setToolTipText(MessageManager.formatMessage(
1203 "label.open_url_param", new String[]
1205 item.addActionListener(new java.awt.event.ActionListener()
1208 public void actionPerformed(ActionEvent e)
1210 new Thread(new Runnable()
1227 * add a late bound groupURL item to the given linkMenu
1231 * - menu label string
1232 * @param urlgenerator
1233 * GroupURLLink used to generate URL
1235 * Object array returned from the makeUrlStubs function.
1237 private void addshowLink(JMenu linkMenu, String label,
1238 final GroupUrlLink urlgenerator, final Object[] urlstub)
1240 JMenuItem item = new JMenuItem(label);
1241 item.setToolTipText(MessageManager.formatMessage(
1242 "label.open_url_seqs_param",
1244 { urlgenerator.getUrl_prefix(),
1245 urlgenerator.getNumberInvolved(urlstub) }));
1246 // TODO: put in info about what is being sent.
1247 item.addActionListener(new java.awt.event.ActionListener()
1250 public void actionPerformed(ActionEvent e)
1252 new Thread(new Runnable()
1260 showLink(urlgenerator.constructFrom(urlstub));
1261 } catch (UrlStringTooLongException e)
1279 private void jbInit() throws Exception
1281 groupMenu.setText(MessageManager.getString("label.group"));
1282 groupMenu.setText(MessageManager.getString("label.selection"));
1283 groupName.setText(MessageManager.getString("label.name"));
1284 groupName.addActionListener(new java.awt.event.ActionListener()
1287 public void actionPerformed(ActionEvent e)
1289 groupName_actionPerformed();
1292 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1293 sequenceName.setText(MessageManager
1294 .getString("label.edit_name_description"));
1295 sequenceName.addActionListener(new java.awt.event.ActionListener()
1298 public void actionPerformed(ActionEvent e)
1300 sequenceName_actionPerformed();
1303 chooseAnnotations.setText(MessageManager
1304 .getString("label.choose_annotations") + "...");
1305 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1308 public void actionPerformed(ActionEvent e)
1310 chooseAnnotations_actionPerformed(e);
1313 sequenceDetails.setText(MessageManager
1314 .getString("label.sequence_details") + "...");
1315 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1318 public void actionPerformed(ActionEvent e)
1320 sequenceDetails_actionPerformed();
1323 sequenceSelDetails.setText(MessageManager
1324 .getString("label.sequence_details") + "...");
1326 .addActionListener(new java.awt.event.ActionListener()
1329 public void actionPerformed(ActionEvent e)
1331 sequenceSelectionDetails_actionPerformed();
1334 PIDColour.setFocusPainted(false);
1336 .setText(MessageManager.getString("action.remove_group"));
1337 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1340 public void actionPerformed(ActionEvent e)
1342 unGroupMenuItem_actionPerformed();
1345 createGroupMenuItem.setText(MessageManager
1346 .getString("action.create_group"));
1348 .addActionListener(new java.awt.event.ActionListener()
1351 public void actionPerformed(ActionEvent e)
1353 createGroupMenuItem_actionPerformed();
1357 outline.setText(MessageManager.getString("action.border_colour"));
1358 outline.addActionListener(new java.awt.event.ActionListener()
1361 public void actionPerformed(ActionEvent e)
1363 outline_actionPerformed();
1367 .setText(MessageManager.getString("label.nucleotide"));
1368 nucleotideMenuItem.addActionListener(new ActionListener()
1371 public void actionPerformed(ActionEvent e)
1373 nucleotideMenuItem_actionPerformed();
1376 colourMenu.setText(MessageManager.getString("label.group_colour"));
1377 showBoxes.setText(MessageManager.getString("action.boxes"));
1378 showBoxes.setState(true);
1379 showBoxes.addActionListener(new ActionListener()
1382 public void actionPerformed(ActionEvent e)
1384 showBoxes_actionPerformed();
1387 showText.setText(MessageManager.getString("action.text"));
1388 showText.setState(true);
1389 showText.addActionListener(new ActionListener()
1392 public void actionPerformed(ActionEvent e)
1394 showText_actionPerformed();
1397 showColourText.setText(MessageManager.getString("label.colour_text"));
1398 showColourText.addActionListener(new ActionListener()
1401 public void actionPerformed(ActionEvent e)
1403 showColourText_actionPerformed();
1406 displayNonconserved.setText(MessageManager
1407 .getString("label.show_non_conversed"));
1408 displayNonconserved.setState(true);
1409 displayNonconserved.addActionListener(new ActionListener()
1412 public void actionPerformed(ActionEvent e)
1414 showNonconserved_actionPerformed();
1417 editMenu.setText(MessageManager.getString("action.edit"));
1418 cut.setText(MessageManager.getString("action.cut"));
1419 cut.addActionListener(new ActionListener()
1422 public void actionPerformed(ActionEvent e)
1424 cut_actionPerformed();
1427 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1428 upperCase.addActionListener(new ActionListener()
1431 public void actionPerformed(ActionEvent e)
1436 copy.setText(MessageManager.getString("action.copy"));
1437 copy.addActionListener(new ActionListener()
1440 public void actionPerformed(ActionEvent e)
1442 copy_actionPerformed();
1445 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1446 lowerCase.addActionListener(new ActionListener()
1449 public void actionPerformed(ActionEvent e)
1454 toggle.setText(MessageManager.getString("label.toggle_case"));
1455 toggle.addActionListener(new ActionListener()
1458 public void actionPerformed(ActionEvent e)
1463 pdbMenu.setText(MessageManager
1464 .getString("label.associate_structure_with_sequence"));
1465 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1466 pdbFromFile.addActionListener(new ActionListener()
1469 public void actionPerformed(ActionEvent e)
1471 pdbFromFile_actionPerformed();
1474 // RNAFold.setText("From RNA Fold with predict2D");
1475 // RNAFold.addActionListener(new ActionListener()
1477 // public void actionPerformed(ActionEvent e)
1480 // RNAFold_actionPerformed();
1481 // } catch (Exception e1) {
1482 // // TODO Auto-generated catch block
1483 // e1.printStackTrace();
1487 // ContraFold.setText("From Contra Fold with predict2D");
1488 // ContraFold.addActionListener(new ActionListener()
1490 // public void actionPerformed(ActionEvent e)
1493 // ContraFold_actionPerformed();
1494 // } catch (Exception e1) {
1495 // // TODO Auto-generated catch block
1496 // e1.printStackTrace();
1500 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1501 enterPDB.addActionListener(new ActionListener()
1504 public void actionPerformed(ActionEvent e)
1506 enterPDB_actionPerformed();
1509 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1510 discoverPDB.addActionListener(new ActionListener()
1513 public void actionPerformed(ActionEvent e)
1515 discoverPDB_actionPerformed();
1518 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1520 showAnnotationsMenu.setText(MessageManager
1521 .getString("label.show_annotations"));
1522 hideAnnotationsMenu.setText(MessageManager
1523 .getString("label.hide_annotations"));
1524 sequenceFeature.setText(MessageManager
1525 .getString("label.create_sequence_feature"));
1526 sequenceFeature.addActionListener(new ActionListener()
1529 public void actionPerformed(ActionEvent e)
1531 sequenceFeature_actionPerformed();
1534 textColour.setText(MessageManager.getString("label.text_colour"));
1535 textColour.addActionListener(new ActionListener()
1538 public void actionPerformed(ActionEvent e)
1540 textColour_actionPerformed();
1543 jMenu1.setText(MessageManager.getString("label.group"));
1544 structureMenu.setText(MessageManager.getString("label.structure"));
1545 viewStructureMenu.setText(MessageManager
1546 .getString("label.view_structure"));
1547 // colStructureMenu.setText("Colour By Structure");
1548 editSequence.setText(MessageManager.getString("label.edit_sequence")
1550 editSequence.addActionListener(new ActionListener()
1553 public void actionPerformed(ActionEvent actionEvent)
1555 editSequence_actionPerformed(actionEvent);
1560 * annotationMenuItem.setText("By Annotation");
1561 * annotationMenuItem.addActionListener(new ActionListener() { public void
1562 * actionPerformed(ActionEvent actionEvent) {
1563 * annotationMenuItem_actionPerformed(actionEvent); } });
1565 groupMenu.add(sequenceSelDetails);
1568 this.add(structureMenu);
1569 // groupMenu.add(chooseAnnotations);
1570 groupMenu.add(showAnnotationsMenu);
1571 groupMenu.add(hideAnnotationsMenu);
1572 groupMenu.add(editMenu);
1573 groupMenu.add(outputMenu);
1574 groupMenu.add(sequenceFeature);
1575 groupMenu.add(createGroupMenuItem);
1576 groupMenu.add(unGroupMenuItem);
1577 groupMenu.add(jMenu1);
1578 sequenceMenu.add(sequenceName);
1579 sequenceMenu.add(sequenceDetails);
1580 colourMenu.add(textColour);
1581 colourMenu.add(noColourmenuItem);
1582 colourMenu.add(clustalColour);
1583 colourMenu.add(BLOSUM62Colour);
1584 colourMenu.add(PIDColour);
1585 colourMenu.add(zappoColour);
1586 colourMenu.add(taylorColour);
1587 colourMenu.add(hydrophobicityColour);
1588 colourMenu.add(helixColour);
1589 colourMenu.add(strandColour);
1590 colourMenu.add(turnColour);
1591 colourMenu.add(buriedColour);
1592 colourMenu.add(nucleotideMenuItem);
1593 if (ap.getAlignment().isNucleotide())
1595 // JBPNote - commented since the colourscheme isn't functional
1596 // colourMenu.add(RNAInteractionColour);
1597 colourMenu.add(purinePyrimidineColour);
1599 // colourMenu.add(covariationColour);
1600 colourMenu.add(userDefinedColour);
1602 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1604 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1605 .getUserColourSchemes().keys();
1607 while (userColours.hasMoreElements())
1609 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1610 item.addActionListener(new ActionListener()
1613 public void actionPerformed(ActionEvent evt)
1615 userDefinedColour_actionPerformed(evt);
1618 colourMenu.add(item);
1622 colourMenu.addSeparator();
1623 colourMenu.add(abovePIDColour);
1624 colourMenu.add(conservationMenuItem);
1625 // colourMenu.add(annotationMenuItem);
1628 editMenu.add(editSequence);
1629 editMenu.add(upperCase);
1630 editMenu.add(lowerCase);
1631 editMenu.add(toggle);
1632 pdbMenu.add(pdbFromFile);
1633 // JBPNote: These shouldn't be added here - should appear in a generic
1634 // 'apply web service to this sequence menu'
1635 // pdbMenu.add(RNAFold);
1636 // pdbMenu.add(ContraFold);
1637 pdbMenu.add(enterPDB);
1638 pdbMenu.add(discoverPDB);
1639 jMenu1.add(groupName);
1640 jMenu1.add(colourMenu);
1641 jMenu1.add(showBoxes);
1642 jMenu1.add(showText);
1643 jMenu1.add(showColourText);
1644 jMenu1.add(outline);
1645 jMenu1.add(displayNonconserved);
1646 structureMenu.add(pdbMenu);
1647 structureMenu.add(viewStructureMenu);
1648 // structureMenu.add(colStructureMenu);
1649 noColourmenuItem.setText(MessageManager.getString("label.none"));
1650 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1653 public void actionPerformed(ActionEvent e)
1655 noColourmenuItem_actionPerformed();
1659 clustalColour.setText(MessageManager
1660 .getString("label.clustalx_colours"));
1661 clustalColour.addActionListener(new java.awt.event.ActionListener()
1664 public void actionPerformed(ActionEvent e)
1666 clustalColour_actionPerformed();
1669 zappoColour.setText(MessageManager.getString("label.zappo"));
1670 zappoColour.addActionListener(new java.awt.event.ActionListener()
1673 public void actionPerformed(ActionEvent e)
1675 zappoColour_actionPerformed();
1678 taylorColour.setText(MessageManager.getString("label.taylor"));
1679 taylorColour.addActionListener(new java.awt.event.ActionListener()
1682 public void actionPerformed(ActionEvent e)
1684 taylorColour_actionPerformed();
1687 hydrophobicityColour.setText(MessageManager
1688 .getString("label.hydrophobicity"));
1689 hydrophobicityColour
1690 .addActionListener(new java.awt.event.ActionListener()
1693 public void actionPerformed(ActionEvent e)
1695 hydrophobicityColour_actionPerformed();
1698 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1699 helixColour.addActionListener(new java.awt.event.ActionListener()
1702 public void actionPerformed(ActionEvent e)
1704 helixColour_actionPerformed();
1707 strandColour.setText(MessageManager
1708 .getString("label.strand_propensity"));
1709 strandColour.addActionListener(new java.awt.event.ActionListener()
1712 public void actionPerformed(ActionEvent e)
1714 strandColour_actionPerformed();
1717 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1718 turnColour.addActionListener(new java.awt.event.ActionListener()
1721 public void actionPerformed(ActionEvent e)
1723 turnColour_actionPerformed();
1726 buriedColour.setText(MessageManager.getString("label.buried_index"));
1727 buriedColour.addActionListener(new java.awt.event.ActionListener()
1730 public void actionPerformed(ActionEvent e)
1732 buriedColour_actionPerformed();
1735 abovePIDColour.setText(MessageManager
1736 .getString("label.above_identity_percentage"));
1737 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1740 public void actionPerformed(ActionEvent e)
1742 abovePIDColour_actionPerformed();
1745 userDefinedColour.setText(MessageManager
1746 .getString("action.user_defined"));
1747 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1750 public void actionPerformed(ActionEvent e)
1752 userDefinedColour_actionPerformed(e);
1756 .setText(MessageManager.getString("label.percentage_identity"));
1757 PIDColour.addActionListener(new java.awt.event.ActionListener()
1760 public void actionPerformed(ActionEvent e)
1762 PIDColour_actionPerformed();
1765 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1766 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1769 public void actionPerformed(ActionEvent e)
1771 BLOSUM62Colour_actionPerformed();
1774 purinePyrimidineColour.setText(MessageManager
1775 .getString("label.purine_pyrimidine"));
1776 purinePyrimidineColour
1777 .addActionListener(new java.awt.event.ActionListener()
1780 public void actionPerformed(ActionEvent e)
1782 purinePyrimidineColour_actionPerformed();
1787 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1788 * public void actionPerformed(ActionEvent e) {
1789 * covariationColour_actionPerformed(); } });
1792 conservationMenuItem.setText(MessageManager
1793 .getString("label.conservation"));
1794 conservationMenuItem
1795 .addActionListener(new java.awt.event.ActionListener()
1798 public void actionPerformed(ActionEvent e)
1800 conservationMenuItem_actionPerformed();
1805 protected void sequenceSelectionDetails_actionPerformed()
1807 createSequenceDetailsReport(ap.av.getSequenceSelection());
1810 protected void sequenceDetails_actionPerformed()
1812 createSequenceDetailsReport(new SequenceI[]
1816 public void createSequenceDetailsReport(SequenceI[] sequences)
1818 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1819 StringBuffer contents = new StringBuffer();
1820 for (SequenceI seq : sequences)
1822 contents.append("<p><h2>"
1825 "label.create_sequence_details_report_annotation_for",
1827 { seq.getDisplayId(true) }) + "</h2></p><p>");
1828 new SequenceAnnotationReport(null)
1829 .createSequenceAnnotationReport(
1835 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr.minmax
1837 contents.append("</p>");
1839 cap.setText("<html>" + contents.toString() + "</html>");
1841 Desktop.instance.addInternalFrame(cap, MessageManager.formatMessage(
1842 "label.sequece_details_for",
1843 (sequences.length == 1 ? new String[]
1844 { sequences[0].getDisplayId(true) } : new String[]
1845 { MessageManager.getString("label.selection") })), 500, 400);
1849 protected void showNonconserved_actionPerformed()
1851 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1856 * call to refresh view after settings change
1860 ap.updateAnnotation();
1861 ap.paintAlignment(true);
1863 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1872 protected void clustalColour_actionPerformed()
1874 SequenceGroup sg = getGroup();
1875 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1885 protected void zappoColour_actionPerformed()
1887 getGroup().cs = new ZappoColourScheme();
1897 protected void taylorColour_actionPerformed()
1899 getGroup().cs = new TaylorColourScheme();
1909 protected void hydrophobicityColour_actionPerformed()
1911 getGroup().cs = new HydrophobicColourScheme();
1921 protected void helixColour_actionPerformed()
1923 getGroup().cs = new HelixColourScheme();
1933 protected void strandColour_actionPerformed()
1935 getGroup().cs = new StrandColourScheme();
1945 protected void turnColour_actionPerformed()
1947 getGroup().cs = new TurnColourScheme();
1957 protected void buriedColour_actionPerformed()
1959 getGroup().cs = new BuriedColourScheme();
1969 public void nucleotideMenuItem_actionPerformed()
1971 getGroup().cs = new NucleotideColourScheme();
1975 protected void purinePyrimidineColour_actionPerformed()
1977 getGroup().cs = new PurinePyrimidineColourScheme();
1982 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1983 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1991 protected void abovePIDColour_actionPerformed()
1993 SequenceGroup sg = getGroup();
1999 if (abovePIDColour.isSelected())
2001 sg.cs.setConsensus(AAFrequency.calculate(
2002 sg.getSequences(ap.av.getHiddenRepSequences()),
2003 sg.getStartRes(), sg.getEndRes() + 1));
2005 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
2008 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
2010 SliderPanel.showPIDSlider();
2013 // remove PIDColouring
2015 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
2027 protected void userDefinedColour_actionPerformed(ActionEvent e)
2029 SequenceGroup sg = getGroup();
2031 if (e.getSource().equals(userDefinedColour))
2033 new UserDefinedColours(ap, sg);
2037 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2038 .getUserColourSchemes().get(e.getActionCommand());
2046 * Open a panel where the user can choose which types of sequence annotation
2051 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2053 // todo correct way to guard against opening a duplicate panel?
2054 new AnnotationChooser(ap);
2063 protected void PIDColour_actionPerformed()
2065 SequenceGroup sg = getGroup();
2066 sg.cs = new PIDColourScheme();
2067 sg.cs.setConsensus(AAFrequency.calculate(
2068 sg.getSequences(ap.av.getHiddenRepSequences()),
2069 sg.getStartRes(), sg.getEndRes() + 1));
2079 protected void BLOSUM62Colour_actionPerformed()
2081 SequenceGroup sg = getGroup();
2083 sg.cs = new Blosum62ColourScheme();
2085 sg.cs.setConsensus(AAFrequency.calculate(
2086 sg.getSequences(ap.av.getHiddenRepSequences()),
2087 sg.getStartRes(), sg.getEndRes() + 1));
2098 protected void noColourmenuItem_actionPerformed()
2100 getGroup().cs = null;
2110 protected void conservationMenuItem_actionPerformed()
2112 SequenceGroup sg = getGroup();
2118 if (conservationMenuItem.isSelected())
2120 // JBPNote: Conservation name shouldn't be i18n translated
2121 Conservation c = new Conservation("Group",
2122 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2123 .getHiddenRepSequences()), sg.getStartRes(),
2124 sg.getEndRes() + 1);
2127 c.verdict(false, ap.av.getConsPercGaps());
2129 sg.cs.setConservation(c);
2131 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2132 SliderPanel.showConservationSlider();
2135 // remove ConservationColouring
2137 sg.cs.setConservation(null);
2143 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2145 SequenceGroup sg = getGroup();
2151 AnnotationColourGradient acg = new AnnotationColourGradient(
2152 sequence.getAnnotation()[0], null,
2153 AnnotationColourGradient.NO_THRESHOLD);
2155 acg.setPredefinedColours(true);
2167 protected void groupName_actionPerformed()
2170 SequenceGroup sg = getGroup();
2171 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2172 sg.getDescription(), " "
2173 + MessageManager.getString("label.group_name") + " ",
2174 MessageManager.getString("label.group_description") + " ",
2175 MessageManager.getString("label.edit_group_name_description"),
2183 sg.setName(dialog.getName());
2184 sg.setDescription(dialog.getDescription());
2189 * Get selection group - adding it to the alignment if necessary.
2191 * @return sequence group to operate on
2193 SequenceGroup getGroup()
2195 SequenceGroup sg = ap.av.getSelectionGroup();
2196 // this method won't add a new group if it already exists
2199 ap.av.getAlignment().addGroup(sg);
2211 void sequenceName_actionPerformed()
2213 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2214 sequence.getDescription(),
2215 " " + MessageManager.getString("label.sequence_name")
2217 MessageManager.getString("label.sequence_description") + " ",
2219 .getString("label.edit_sequence_name_description"),
2227 if (dialog.getName() != null)
2229 if (dialog.getName().indexOf(" ") > -1)
2235 .getString("label.spaces_converted_to_backslashes"),
2237 .getString("label.no_spaces_allowed_sequence_name"),
2238 JOptionPane.WARNING_MESSAGE);
2241 sequence.setName(dialog.getName().replace(' ', '_'));
2242 ap.paintAlignment(false);
2245 sequence.setDescription(dialog.getDescription());
2247 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2258 void unGroupMenuItem_actionPerformed()
2260 SequenceGroup sg = ap.av.getSelectionGroup();
2261 ap.av.getAlignment().deleteGroup(sg);
2262 ap.av.setSelectionGroup(null);
2266 void createGroupMenuItem_actionPerformed()
2268 getGroup(); // implicitly creates group - note - should apply defaults / use
2269 // standard alignment window logic for this
2279 protected void outline_actionPerformed()
2281 SequenceGroup sg = getGroup();
2282 Color col = JColorChooser.showDialog(this,
2283 MessageManager.getString("label.select_outline_colour"),
2288 sg.setOutlineColour(col);
2300 public void showBoxes_actionPerformed()
2302 getGroup().setDisplayBoxes(showBoxes.isSelected());
2312 public void showText_actionPerformed()
2314 getGroup().setDisplayText(showText.isSelected());
2324 public void showColourText_actionPerformed()
2326 getGroup().setColourText(showColourText.isSelected());
2330 public void showLink(String url)
2334 jalview.util.BrowserLauncher.openURL(url);
2335 } catch (Exception ex)
2337 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2338 MessageManager.getString("label.web_browser_not_found_unix"),
2339 MessageManager.getString("label.web_browser_not_found"),
2340 JOptionPane.WARNING_MESSAGE);
2342 ex.printStackTrace();
2346 void hideSequences(boolean representGroup)
2348 SequenceGroup sg = ap.av.getSelectionGroup();
2349 if (sg == null || sg.getSize() < 1)
2351 ap.av.hideSequence(new SequenceI[]
2356 ap.av.setSelectionGroup(null);
2360 ap.av.hideRepSequences(sequence, sg);
2365 int gsize = sg.getSize();
2368 hseqs = new SequenceI[gsize];
2371 for (int i = 0; i < gsize; i++)
2373 hseqs[index++] = sg.getSequenceAt(i);
2376 ap.av.hideSequence(hseqs);
2377 // refresh(); TODO: ? needed ?
2378 ap.av.sendSelection();
2381 public void copy_actionPerformed()
2383 ap.alignFrame.copy_actionPerformed(null);
2386 public void cut_actionPerformed()
2388 ap.alignFrame.cut_actionPerformed(null);
2391 void changeCase(ActionEvent e)
2393 Object source = e.getSource();
2394 SequenceGroup sg = ap.av.getSelectionGroup();
2398 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
2399 sg.getEndRes() + 1);
2404 if (source == toggle)
2406 description = MessageManager.getString("label.toggle_case");
2407 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2409 else if (source == upperCase)
2411 description = MessageManager.getString("label.to_upper_case");
2412 caseChange = ChangeCaseCommand.TO_UPPER;
2416 description = MessageManager.getString("label.to_lower_case");
2417 caseChange = ChangeCaseCommand.TO_LOWER;
2420 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2421 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2422 startEnd, caseChange);
2424 ap.alignFrame.addHistoryItem(caseCommand);
2426 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2432 public void outputText_actionPerformed(ActionEvent e)
2434 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2435 cap.setForInput(null);
2436 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2437 "label.alignment_output_command", new String[]
2438 { e.getActionCommand() }), 600, 500);
2440 String[] omitHidden = null;
2442 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2443 // or we simply trust the user wants
2444 // wysiwig behaviour
2446 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
2450 public void pdbFromFile_actionPerformed()
2452 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2453 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2454 chooser.setFileView(new jalview.io.JalviewFileView());
2455 chooser.setDialogTitle(MessageManager.formatMessage(
2456 "label.select_pdb_file_for", new String[]
2457 { sequence.getDisplayId(false) }));
2458 chooser.setToolTipText(MessageManager.formatMessage(
2459 "label.load_pdb_file_associate_with_sequence", new String[]
2460 { sequence.getDisplayId(false) }));
2462 int value = chooser.showOpenDialog(null);
2464 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2466 String choice = chooser.getSelectedFile().getPath();
2467 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2468 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2469 jalview.io.AppletFormatAdapter.FILE, sequence, true);
2474 // JBNote: commented out - these won't be instantiated here...!
2475 // public void RNAFold_actionPerformed() throws Exception
2477 // Predict2D P2D = new Predict2D();
2478 // P2D.getStructure2DFromRNAFold("toto");
2481 // public void ContraFold_actionPerformed() throws Exception
2483 // Predict2D P2D = new Predict2D();
2484 // P2D.getStructure2DFromContraFold("toto");
2486 public void enterPDB_actionPerformed()
2488 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2489 MessageManager.getString("label.enter_pdb_id"),
2490 MessageManager.getString("label.enter_pdb_id"),
2491 JOptionPane.QUESTION_MESSAGE);
2493 if (id != null && id.length() > 0)
2495 PDBEntry entry = new PDBEntry();
2496 entry.setId(id.toUpperCase());
2497 sequence.getDatasetSequence().addPDBId(entry);
2501 public void discoverPDB_actionPerformed()
2504 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2506 : ap.av.getSequenceSelection());
2507 Thread discpdb = new Thread(new Runnable()
2513 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2514 .fetchDBRefs(false);
2521 public void sequenceFeature_actionPerformed()
2523 SequenceGroup sg = ap.av.getSelectionGroup();
2529 int rsize = 0, gSize = sg.getSize();
2530 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2531 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2533 for (int i = 0; i < gSize; i++)
2535 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2536 int end = sg.findEndRes(sg.getSequenceAt(i));
2539 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2540 features[rsize] = new SequenceFeature(null, null, null, start, end,
2545 rseqs = new SequenceI[rsize];
2546 tfeatures = new SequenceFeature[rsize];
2547 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2548 System.arraycopy(features, 0, tfeatures, 0, rsize);
2549 features = tfeatures;
2551 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2552 features, true, ap))
2554 ap.alignFrame.setShowSeqFeatures(true);
2555 ap.highlightSearchResults(null);
2559 public void textColour_actionPerformed()
2561 SequenceGroup sg = getGroup();
2564 new TextColourChooser().chooseColour(ap, sg);
2568 public void colourByStructure(String pdbid)
2570 Annotation[] anots = ap.av.getStructureSelectionManager()
2571 .colourSequenceFromStructure(sequence, pdbid);
2573 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2574 "Coloured by " + pdbid, anots);
2576 ap.av.getAlignment().addAnnotation(an);
2577 an.createSequenceMapping(sequence, 0, true);
2578 // an.adjustForAlignment();
2579 ap.av.getAlignment().setAnnotationIndex(an, 0);
2581 ap.adjustAnnotationHeight();
2583 sequence.addAlignmentAnnotation(an);
2587 public void editSequence_actionPerformed(ActionEvent actionEvent)
2589 SequenceGroup sg = ap.av.getSelectionGroup();
2593 if (sequence == null)
2594 sequence = sg.getSequenceAt(0);
2596 EditNameDialog dialog = new EditNameDialog(
2597 sequence.getSequenceAsString(sg.getStartRes(),
2598 sg.getEndRes() + 1), null,
2599 MessageManager.getString("label.edit_sequence"), null,
2600 MessageManager.getString("label.edit_sequence"),
2605 EditCommand editCommand = new EditCommand(
2606 MessageManager.getString("label.edit_sequences"),
2607 EditCommand.REPLACE, dialog.getName().replace(' ',
2608 ap.av.getGapCharacter()),
2609 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2610 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2612 ap.alignFrame.addHistoryItem(editCommand);
2614 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()