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.
803 * Some annotation rows are always rendered together - these can be identified
804 * by a common graphGroup property > -1. Only one of each group will be marked
805 * as visible (to avoid duplication of the display). For such groups we add a
806 * composite type name, e.g.
808 * IUPredWS (Long), IUPredWS (Short)
810 protected void buildAnnotationTypesMenus()
812 showAnnotationsMenu.removeAll();
813 hideAnnotationsMenu.removeAll();
814 final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
815 addAnnotationTypeToShowHide(showAnnotationsMenu,
818 addAnnotationTypeToShowHide(hideAnnotationsMenu, all, true,
820 showAnnotationsMenu.addSeparator();
821 hideAnnotationsMenu.addSeparator();
823 final AlignmentAnnotation[] annotations = ap.getAlignment()
824 .getAlignmentAnnotation();
825 BitSet visibleGraphGroups = PopupMenu
826 .getVisibleLineGraphGroups(annotations);
828 List<List<String>> shownTypes = new ArrayList<List<String>>();
829 List<List<String>> hiddenTypes = new ArrayList<List<String>>();
830 PopupMenu.getAnnotationTypesForShowHide(shownTypes, hiddenTypes,
831 visibleGraphGroups, annotations, ap.av.getSelectionGroup());
833 for (List<String> types : hiddenTypes)
835 addAnnotationTypeToShowHide(showAnnotationsMenu, types, false, true);
838 for (List<String> types : shownTypes)
840 addAnnotationTypeToShowHide(hideAnnotationsMenu, types, false, false);
845 * Helper method to populate lists of annotation types for the Show/Hide
846 * Annotations menus. If sequenceGroup is not null, this is restricted to
847 * annotations which are associated with sequences in the selection group.
849 * If an annotation row is currently visible, its type (label) is added (once
850 * only per type), to the shownTypes list. If it is currently hidden, it is
851 * added to the hiddenTypesList.
853 * For rows that belong to a line graph group, so are always rendered
856 * <li>Treat all rows in the group as visible, if at least one of them is</li>
857 * <li>Build a comma-separated label with all the types that belong to the
863 * @param visibleGraphGroups
865 * @param sequenceGroup
867 public static void getAnnotationTypesForShowHide(
868 List<List<String>> shownTypes, List<List<String>> hiddenTypes,
869 BitSet visibleGraphGroups,
870 AlignmentAnnotation[] annotations, SequenceGroup sequenceGroup)
872 // lookup table, key = graph group, value = list of types in the group
873 Map<Integer, List<String>> groupLabels = new LinkedHashMap<Integer, List<String>>();
875 List<String> addedToShown = new ArrayList<String>();
876 List<String> addedToHidden = new ArrayList<String>();
878 for (AlignmentAnnotation aa : annotations)
881 if (sequenceGroup == null
882 || (aa.sequenceRef != null && sequenceGroup.getSequences()
883 .contains(aa.sequenceRef)))
886 * Build a 'composite label' for types in line graph groups.
888 final List<String> labelAsList = new ArrayList<String>();
889 labelAsList.add(aa.label);
890 if (aa.graph == AlignmentAnnotation.LINE_GRAPH
891 && aa.graphGroup > -1)
893 if (groupLabels.containsKey(aa.graphGroup))
895 if (!groupLabels.get(aa.graphGroup).contains(aa.label))
897 groupLabels.get(aa.graphGroup).add(aa.label);
902 groupLabels.put(aa.graphGroup, labelAsList);
905 else if (aa.visible && !addedToShown.contains(aa.label))
907 shownTypes.add(labelAsList);
908 addedToShown.add(aa.label);
912 if (!aa.visible && !addedToHidden.contains(aa.label))
914 hiddenTypes.add(labelAsList);
915 addedToHidden.add(aa.label);
921 * finally add the 'composite group labels' to the appropriate lists,
922 * depending on whether the group is identified as visible or hidden
924 for (int group : groupLabels.keySet())
926 final List<String> groupLabel = groupLabels.get(group);
927 if (visibleGraphGroups.get(group))
929 if (!shownTypes.contains(groupLabel))
931 shownTypes.add(groupLabel);
934 else if (!hiddenTypes.contains(groupLabel))
936 hiddenTypes.add(groupLabel);
942 * Returns a BitSet (possibly empty) of those graphGroups for line graph
943 * annotations, which have at least one member annotation row marked visible.
944 * The logic is that only one row in the group is marked visible, but when it
945 * is drawn, so are all the other rows in the same group.
947 * This lookup set allows us to check whether rows marked not visible are in
950 * @see AnnotationRenderer#drawComponent
954 public static BitSet getVisibleLineGraphGroups(
955 AlignmentAnnotation[] annotations)
957 // todo move to a utility class
958 BitSet result = new BitSet();
959 for (AlignmentAnnotation ann : annotations)
961 if (ann.graph == AlignmentAnnotation.LINE_GRAPH && ann.visible)
963 int gg = ann.graphGroup;
974 * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
977 * @param showOrHideMenu
982 * if true this is a special label meaning 'All'
983 * @param actionIsShow
984 * if true, the select menu item action is to show the annotation
987 protected void addAnnotationTypeToShowHide(JMenu showOrHideMenu,
988 final Collection<String> types, final boolean allTypes,
989 final boolean actionIsShow)
991 String label = types.toString(); // [a, b, c]
992 label = label.substring(1, label.length() - 1);
993 final JMenuItem item = new JMenuItem(label);
994 item.addActionListener(new java.awt.event.ActionListener()
997 public void actionPerformed(ActionEvent e)
999 showHideAnnotation_actionPerformed(types, allTypes, actionIsShow);
1002 showOrHideMenu.add(item);
1006 * Action on selecting a list of annotation type (or the 'all types' values)
1007 * to show or hide for the selection.
1013 protected void showHideAnnotation_actionPerformed(
1014 Collection<String> types,
1015 boolean anyType, boolean doShow)
1017 for (AlignmentAnnotation aa : ap.getAlignment()
1018 .getAlignmentAnnotation())
1020 if (anyType || types.contains(aa.label))
1022 if ((aa.sequenceRef != null)
1023 && ap.av.getSelectionGroup().getSequences()
1024 .contains(aa.sequenceRef))
1026 aa.visible = doShow;
1033 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
1036 // TODO: usability: thread off the generation of group url content so root
1037 // menu appears asap
1038 // sequence only URLs
1039 // ID/regex match URLs
1040 groupLinksMenu = new JMenu(
1041 MessageManager.getString("action.group_link"));
1042 JMenu[] linkMenus = new JMenu[]
1043 { null, new JMenu(MessageManager.getString("action.ids")),
1044 new JMenu(MessageManager.getString("action.sequences")),
1045 new JMenu(MessageManager.getString("action.ids_sequences")) }; // three
1052 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
1053 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
1054 Hashtable commonDbrefs = new Hashtable();
1055 for (int sq = 0; sq < seqs.length; sq++)
1058 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
1059 .findPosition(sg.getEndRes());
1060 // just collect ids from dataset sequence
1061 // TODO: check if IDs collected from selecton group intersects with the
1062 // current selection, too
1063 SequenceI sqi = seqs[sq];
1064 while (sqi.getDatasetSequence() != null)
1066 sqi = sqi.getDatasetSequence();
1068 DBRefEntry[] dbr = sqi.getDBRef();
1069 if (dbr != null && dbr.length > 0)
1071 for (int d = 0; d < dbr.length; d++)
1073 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
1074 Object[] sarray = (Object[]) commonDbrefs.get(src);
1077 sarray = new Object[2];
1078 sarray[0] = new int[]
1080 sarray[1] = new String[seqs.length];
1082 commonDbrefs.put(src, sarray);
1085 if (((String[]) sarray[1])[sq] == null)
1087 if (!dbr[d].hasMap()
1088 || (dbr[d].getMap().locateMappedRange(start, end) != null))
1090 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
1091 ((int[]) sarray[0])[0]++;
1097 // now create group links for all distinct ID/sequence sets.
1098 boolean addMenu = false; // indicates if there are any group links to give
1100 for (int i = 0; i < groupLinks.size(); i++)
1102 String link = groupLinks.elementAt(i).toString();
1103 GroupUrlLink urlLink = null;
1106 urlLink = new GroupUrlLink(link);
1107 } catch (Exception foo)
1109 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
1114 if (!urlLink.isValid())
1116 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
1119 final String label = urlLink.getLabel();
1120 boolean usingNames = false;
1121 // Now see which parts of the group apply for this URL
1122 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
1123 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
1124 String[] seqstr, ids; // input to makeUrl
1127 int numinput = ((int[]) idset[0])[0];
1128 String[] allids = ((String[]) idset[1]);
1129 seqstr = new String[numinput];
1130 ids = new String[numinput];
1131 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
1133 if (allids[sq] != null)
1135 ids[idcount] = allids[sq];
1136 seqstr[idcount++] = idandseqs[1][sq];
1142 // just use the id/seq set
1143 seqstr = idandseqs[1];
1147 // and try and make the groupURL!
1149 Object[] urlset = null;
1152 urlset = urlLink.makeUrlStubs(ids, seqstr,
1153 "FromJalview" + System.currentTimeMillis(), false);
1154 } catch (UrlStringTooLongException e)
1159 int type = urlLink.getGroupURLType() & 3;
1160 // System.out.println(urlLink.getGroupURLType()
1161 // +" "+((String[])urlset[3])[0]);
1162 // first two bits ofurlLink type bitfield are sequenceids and sequences
1163 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
1164 addshowLink(linkMenus[type], label
1165 + (((type & 1) == 1) ? ("("
1166 + (usingNames ? "Names" : ltarget) + ")") : ""),
1173 groupLinksMenu = new JMenu(
1174 MessageManager.getString("action.group_link"));
1175 for (int m = 0; m < linkMenus.length; m++)
1177 if (linkMenus[m] != null
1178 && linkMenus[m].getMenuComponentCount() > 0)
1180 groupLinksMenu.add(linkMenus[m]);
1184 groupMenu.add(groupLinksMenu);
1189 * add a show URL menu item to the given linkMenu
1193 * - menu label string
1197 private void addshowLink(JMenu linkMenu, String label, final String url)
1199 JMenuItem item = new JMenuItem(label);
1200 item.setToolTipText(MessageManager.formatMessage(
1201 "label.open_url_param", new String[]
1203 item.addActionListener(new java.awt.event.ActionListener()
1206 public void actionPerformed(ActionEvent e)
1208 new Thread(new Runnable()
1225 * add a late bound groupURL item to the given linkMenu
1229 * - menu label string
1230 * @param urlgenerator
1231 * GroupURLLink used to generate URL
1233 * Object array returned from the makeUrlStubs function.
1235 private void addshowLink(JMenu linkMenu, String label,
1236 final GroupUrlLink urlgenerator, final Object[] urlstub)
1238 JMenuItem item = new JMenuItem(label);
1239 item.setToolTipText(MessageManager.formatMessage(
1240 "label.open_url_seqs_param",
1242 { urlgenerator.getUrl_prefix(),
1243 urlgenerator.getNumberInvolved(urlstub) }));
1244 // TODO: put in info about what is being sent.
1245 item.addActionListener(new java.awt.event.ActionListener()
1248 public void actionPerformed(ActionEvent e)
1250 new Thread(new Runnable()
1258 showLink(urlgenerator.constructFrom(urlstub));
1259 } catch (UrlStringTooLongException e)
1277 private void jbInit() throws Exception
1279 groupMenu.setText(MessageManager.getString("label.group"));
1280 groupMenu.setText(MessageManager.getString("label.selection"));
1281 groupName.setText(MessageManager.getString("label.name"));
1282 groupName.addActionListener(new java.awt.event.ActionListener()
1285 public void actionPerformed(ActionEvent e)
1287 groupName_actionPerformed();
1290 sequenceMenu.setText(MessageManager.getString("label.sequence"));
1291 sequenceName.setText(MessageManager
1292 .getString("label.edit_name_description"));
1293 sequenceName.addActionListener(new java.awt.event.ActionListener()
1296 public void actionPerformed(ActionEvent e)
1298 sequenceName_actionPerformed();
1301 chooseAnnotations.setText(MessageManager
1302 .getString("label.choose_annotations") + "...");
1303 chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
1306 public void actionPerformed(ActionEvent e)
1308 chooseAnnotations_actionPerformed(e);
1311 sequenceDetails.setText(MessageManager
1312 .getString("label.sequence_details") + "...");
1313 sequenceDetails.addActionListener(new java.awt.event.ActionListener()
1316 public void actionPerformed(ActionEvent e)
1318 sequenceDetails_actionPerformed();
1321 sequenceSelDetails.setText(MessageManager
1322 .getString("label.sequence_details") + "...");
1324 .addActionListener(new java.awt.event.ActionListener()
1327 public void actionPerformed(ActionEvent e)
1329 sequenceSelectionDetails_actionPerformed();
1332 PIDColour.setFocusPainted(false);
1334 .setText(MessageManager.getString("action.remove_group"));
1335 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
1338 public void actionPerformed(ActionEvent e)
1340 unGroupMenuItem_actionPerformed();
1343 createGroupMenuItem.setText(MessageManager
1344 .getString("action.create_group"));
1346 .addActionListener(new java.awt.event.ActionListener()
1349 public void actionPerformed(ActionEvent e)
1351 createGroupMenuItem_actionPerformed();
1355 outline.setText(MessageManager.getString("action.border_colour"));
1356 outline.addActionListener(new java.awt.event.ActionListener()
1359 public void actionPerformed(ActionEvent e)
1361 outline_actionPerformed();
1365 .setText(MessageManager.getString("label.nucleotide"));
1366 nucleotideMenuItem.addActionListener(new ActionListener()
1369 public void actionPerformed(ActionEvent e)
1371 nucleotideMenuItem_actionPerformed();
1374 colourMenu.setText(MessageManager.getString("label.group_colour"));
1375 showBoxes.setText(MessageManager.getString("action.boxes"));
1376 showBoxes.setState(true);
1377 showBoxes.addActionListener(new ActionListener()
1380 public void actionPerformed(ActionEvent e)
1382 showBoxes_actionPerformed();
1385 showText.setText(MessageManager.getString("action.text"));
1386 showText.setState(true);
1387 showText.addActionListener(new ActionListener()
1390 public void actionPerformed(ActionEvent e)
1392 showText_actionPerformed();
1395 showColourText.setText(MessageManager.getString("label.colour_text"));
1396 showColourText.addActionListener(new ActionListener()
1399 public void actionPerformed(ActionEvent e)
1401 showColourText_actionPerformed();
1404 displayNonconserved.setText(MessageManager
1405 .getString("label.show_non_conversed"));
1406 displayNonconserved.setState(true);
1407 displayNonconserved.addActionListener(new ActionListener()
1410 public void actionPerformed(ActionEvent e)
1412 showNonconserved_actionPerformed();
1415 editMenu.setText(MessageManager.getString("action.edit"));
1416 cut.setText(MessageManager.getString("action.cut"));
1417 cut.addActionListener(new ActionListener()
1420 public void actionPerformed(ActionEvent e)
1422 cut_actionPerformed();
1425 upperCase.setText(MessageManager.getString("label.to_upper_case"));
1426 upperCase.addActionListener(new ActionListener()
1429 public void actionPerformed(ActionEvent e)
1434 copy.setText(MessageManager.getString("action.copy"));
1435 copy.addActionListener(new ActionListener()
1438 public void actionPerformed(ActionEvent e)
1440 copy_actionPerformed();
1443 lowerCase.setText(MessageManager.getString("label.to_lower_case"));
1444 lowerCase.addActionListener(new ActionListener()
1447 public void actionPerformed(ActionEvent e)
1452 toggle.setText(MessageManager.getString("label.toggle_case"));
1453 toggle.addActionListener(new ActionListener()
1456 public void actionPerformed(ActionEvent e)
1461 pdbMenu.setText(MessageManager
1462 .getString("label.associate_structure_with_sequence"));
1463 pdbFromFile.setText(MessageManager.getString("label.from_file"));
1464 pdbFromFile.addActionListener(new ActionListener()
1467 public void actionPerformed(ActionEvent e)
1469 pdbFromFile_actionPerformed();
1472 // RNAFold.setText("From RNA Fold with predict2D");
1473 // RNAFold.addActionListener(new ActionListener()
1475 // public void actionPerformed(ActionEvent e)
1478 // RNAFold_actionPerformed();
1479 // } catch (Exception e1) {
1480 // // TODO Auto-generated catch block
1481 // e1.printStackTrace();
1485 // ContraFold.setText("From Contra Fold with predict2D");
1486 // ContraFold.addActionListener(new ActionListener()
1488 // public void actionPerformed(ActionEvent e)
1491 // ContraFold_actionPerformed();
1492 // } catch (Exception e1) {
1493 // // TODO Auto-generated catch block
1494 // e1.printStackTrace();
1498 enterPDB.setText(MessageManager.getString("label.enter_pdb_id"));
1499 enterPDB.addActionListener(new ActionListener()
1502 public void actionPerformed(ActionEvent e)
1504 enterPDB_actionPerformed();
1507 discoverPDB.setText(MessageManager.getString("label.discover_pdb_ids"));
1508 discoverPDB.addActionListener(new ActionListener()
1511 public void actionPerformed(ActionEvent e)
1513 discoverPDB_actionPerformed();
1516 outputMenu.setText(MessageManager.getString("label.out_to_textbox")
1518 showAnnotationsMenu.setText(MessageManager
1519 .getString("label.show_annotations"));
1520 hideAnnotationsMenu.setText(MessageManager
1521 .getString("label.hide_annotations"));
1522 sequenceFeature.setText(MessageManager
1523 .getString("label.create_sequence_feature"));
1524 sequenceFeature.addActionListener(new ActionListener()
1527 public void actionPerformed(ActionEvent e)
1529 sequenceFeature_actionPerformed();
1532 textColour.setText(MessageManager.getString("label.text_colour"));
1533 textColour.addActionListener(new ActionListener()
1536 public void actionPerformed(ActionEvent e)
1538 textColour_actionPerformed();
1541 jMenu1.setText(MessageManager.getString("label.group"));
1542 structureMenu.setText(MessageManager.getString("label.structure"));
1543 viewStructureMenu.setText(MessageManager
1544 .getString("label.view_structure"));
1545 // colStructureMenu.setText("Colour By Structure");
1546 editSequence.setText(MessageManager.getString("label.edit_sequence")
1548 editSequence.addActionListener(new ActionListener()
1551 public void actionPerformed(ActionEvent actionEvent)
1553 editSequence_actionPerformed(actionEvent);
1558 * annotationMenuItem.setText("By Annotation");
1559 * annotationMenuItem.addActionListener(new ActionListener() { public void
1560 * actionPerformed(ActionEvent actionEvent) {
1561 * annotationMenuItem_actionPerformed(actionEvent); } });
1563 groupMenu.add(sequenceSelDetails);
1566 this.add(structureMenu);
1567 // groupMenu.add(chooseAnnotations);
1568 groupMenu.add(showAnnotationsMenu);
1569 groupMenu.add(hideAnnotationsMenu);
1570 groupMenu.add(editMenu);
1571 groupMenu.add(outputMenu);
1572 groupMenu.add(sequenceFeature);
1573 groupMenu.add(createGroupMenuItem);
1574 groupMenu.add(unGroupMenuItem);
1575 groupMenu.add(jMenu1);
1576 sequenceMenu.add(sequenceName);
1577 sequenceMenu.add(sequenceDetails);
1578 colourMenu.add(textColour);
1579 colourMenu.add(noColourmenuItem);
1580 colourMenu.add(clustalColour);
1581 colourMenu.add(BLOSUM62Colour);
1582 colourMenu.add(PIDColour);
1583 colourMenu.add(zappoColour);
1584 colourMenu.add(taylorColour);
1585 colourMenu.add(hydrophobicityColour);
1586 colourMenu.add(helixColour);
1587 colourMenu.add(strandColour);
1588 colourMenu.add(turnColour);
1589 colourMenu.add(buriedColour);
1590 colourMenu.add(nucleotideMenuItem);
1591 if (ap.getAlignment().isNucleotide())
1593 // JBPNote - commented since the colourscheme isn't functional
1594 // colourMenu.add(RNAInteractionColour);
1595 colourMenu.add(purinePyrimidineColour);
1597 // colourMenu.add(covariationColour);
1598 colourMenu.add(userDefinedColour);
1600 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1602 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1603 .getUserColourSchemes().keys();
1605 while (userColours.hasMoreElements())
1607 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1608 item.addActionListener(new ActionListener()
1611 public void actionPerformed(ActionEvent evt)
1613 userDefinedColour_actionPerformed(evt);
1616 colourMenu.add(item);
1620 colourMenu.addSeparator();
1621 colourMenu.add(abovePIDColour);
1622 colourMenu.add(conservationMenuItem);
1623 // colourMenu.add(annotationMenuItem);
1626 editMenu.add(editSequence);
1627 editMenu.add(upperCase);
1628 editMenu.add(lowerCase);
1629 editMenu.add(toggle);
1630 pdbMenu.add(pdbFromFile);
1631 // JBPNote: These shouldn't be added here - should appear in a generic
1632 // 'apply web service to this sequence menu'
1633 // pdbMenu.add(RNAFold);
1634 // pdbMenu.add(ContraFold);
1635 pdbMenu.add(enterPDB);
1636 pdbMenu.add(discoverPDB);
1637 jMenu1.add(groupName);
1638 jMenu1.add(colourMenu);
1639 jMenu1.add(showBoxes);
1640 jMenu1.add(showText);
1641 jMenu1.add(showColourText);
1642 jMenu1.add(outline);
1643 jMenu1.add(displayNonconserved);
1644 structureMenu.add(pdbMenu);
1645 structureMenu.add(viewStructureMenu);
1646 // structureMenu.add(colStructureMenu);
1647 noColourmenuItem.setText(MessageManager.getString("label.none"));
1648 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1651 public void actionPerformed(ActionEvent e)
1653 noColourmenuItem_actionPerformed();
1657 clustalColour.setText(MessageManager
1658 .getString("label.clustalx_colours"));
1659 clustalColour.addActionListener(new java.awt.event.ActionListener()
1662 public void actionPerformed(ActionEvent e)
1664 clustalColour_actionPerformed();
1667 zappoColour.setText(MessageManager.getString("label.zappo"));
1668 zappoColour.addActionListener(new java.awt.event.ActionListener()
1671 public void actionPerformed(ActionEvent e)
1673 zappoColour_actionPerformed();
1676 taylorColour.setText(MessageManager.getString("label.taylor"));
1677 taylorColour.addActionListener(new java.awt.event.ActionListener()
1680 public void actionPerformed(ActionEvent e)
1682 taylorColour_actionPerformed();
1685 hydrophobicityColour.setText(MessageManager
1686 .getString("label.hydrophobicity"));
1687 hydrophobicityColour
1688 .addActionListener(new java.awt.event.ActionListener()
1691 public void actionPerformed(ActionEvent e)
1693 hydrophobicityColour_actionPerformed();
1696 helixColour.setText(MessageManager.getString("label.helix_propensity"));
1697 helixColour.addActionListener(new java.awt.event.ActionListener()
1700 public void actionPerformed(ActionEvent e)
1702 helixColour_actionPerformed();
1705 strandColour.setText(MessageManager
1706 .getString("label.strand_propensity"));
1707 strandColour.addActionListener(new java.awt.event.ActionListener()
1710 public void actionPerformed(ActionEvent e)
1712 strandColour_actionPerformed();
1715 turnColour.setText(MessageManager.getString("label.turn_propensity"));
1716 turnColour.addActionListener(new java.awt.event.ActionListener()
1719 public void actionPerformed(ActionEvent e)
1721 turnColour_actionPerformed();
1724 buriedColour.setText(MessageManager.getString("label.buried_index"));
1725 buriedColour.addActionListener(new java.awt.event.ActionListener()
1728 public void actionPerformed(ActionEvent e)
1730 buriedColour_actionPerformed();
1733 abovePIDColour.setText(MessageManager
1734 .getString("label.above_identity_percentage"));
1735 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1738 public void actionPerformed(ActionEvent e)
1740 abovePIDColour_actionPerformed();
1743 userDefinedColour.setText(MessageManager
1744 .getString("action.user_defined"));
1745 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1748 public void actionPerformed(ActionEvent e)
1750 userDefinedColour_actionPerformed(e);
1754 .setText(MessageManager.getString("label.percentage_identity"));
1755 PIDColour.addActionListener(new java.awt.event.ActionListener()
1758 public void actionPerformed(ActionEvent e)
1760 PIDColour_actionPerformed();
1763 BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
1764 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1767 public void actionPerformed(ActionEvent e)
1769 BLOSUM62Colour_actionPerformed();
1772 purinePyrimidineColour.setText(MessageManager
1773 .getString("label.purine_pyrimidine"));
1774 purinePyrimidineColour
1775 .addActionListener(new java.awt.event.ActionListener()
1778 public void actionPerformed(ActionEvent e)
1780 purinePyrimidineColour_actionPerformed();
1785 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1786 * public void actionPerformed(ActionEvent e) {
1787 * covariationColour_actionPerformed(); } });
1790 conservationMenuItem.setText(MessageManager
1791 .getString("label.conservation"));
1792 conservationMenuItem
1793 .addActionListener(new java.awt.event.ActionListener()
1796 public void actionPerformed(ActionEvent e)
1798 conservationMenuItem_actionPerformed();
1803 protected void sequenceSelectionDetails_actionPerformed()
1805 createSequenceDetailsReport(ap.av.getSequenceSelection());
1808 protected void sequenceDetails_actionPerformed()
1810 createSequenceDetailsReport(new SequenceI[]
1814 public void createSequenceDetailsReport(SequenceI[] sequences)
1816 CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
1817 StringBuffer contents = new StringBuffer();
1818 for (SequenceI seq : sequences)
1820 contents.append("<p><h2>"
1823 "label.create_sequence_details_report_annotation_for",
1825 { seq.getDisplayId(true) }) + "</h2></p><p>");
1826 new SequenceAnnotationReport(null)
1827 .createSequenceAnnotationReport(
1833 (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr.minmax
1835 contents.append("</p>");
1837 cap.setText("<html>" + contents.toString() + "</html>");
1839 Desktop.instance.addInternalFrame(cap, MessageManager.formatMessage(
1840 "label.sequece_details_for",
1841 (sequences.length == 1 ? new String[]
1842 { sequences[0].getDisplayId(true) } : new String[]
1843 { MessageManager.getString("label.selection") })), 500, 400);
1847 protected void showNonconserved_actionPerformed()
1849 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1854 * call to refresh view after settings change
1858 ap.updateAnnotation();
1859 ap.paintAlignment(true);
1861 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1870 protected void clustalColour_actionPerformed()
1872 SequenceGroup sg = getGroup();
1873 sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
1883 protected void zappoColour_actionPerformed()
1885 getGroup().cs = new ZappoColourScheme();
1895 protected void taylorColour_actionPerformed()
1897 getGroup().cs = new TaylorColourScheme();
1907 protected void hydrophobicityColour_actionPerformed()
1909 getGroup().cs = new HydrophobicColourScheme();
1919 protected void helixColour_actionPerformed()
1921 getGroup().cs = new HelixColourScheme();
1931 protected void strandColour_actionPerformed()
1933 getGroup().cs = new StrandColourScheme();
1943 protected void turnColour_actionPerformed()
1945 getGroup().cs = new TurnColourScheme();
1955 protected void buriedColour_actionPerformed()
1957 getGroup().cs = new BuriedColourScheme();
1967 public void nucleotideMenuItem_actionPerformed()
1969 getGroup().cs = new NucleotideColourScheme();
1973 protected void purinePyrimidineColour_actionPerformed()
1975 getGroup().cs = new PurinePyrimidineColourScheme();
1980 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1981 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1989 protected void abovePIDColour_actionPerformed()
1991 SequenceGroup sg = getGroup();
1997 if (abovePIDColour.isSelected())
1999 sg.cs.setConsensus(AAFrequency.calculate(
2000 sg.getSequences(ap.av.getHiddenRepSequences()),
2001 sg.getStartRes(), sg.getEndRes() + 1));
2003 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
2006 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
2008 SliderPanel.showPIDSlider();
2011 // remove PIDColouring
2013 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
2025 protected void userDefinedColour_actionPerformed(ActionEvent e)
2027 SequenceGroup sg = getGroup();
2029 if (e.getSource().equals(userDefinedColour))
2031 new UserDefinedColours(ap, sg);
2035 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2036 .getUserColourSchemes().get(e.getActionCommand());
2044 * Open a panel where the user can choose which types of sequence annotation
2049 protected void chooseAnnotations_actionPerformed(ActionEvent e)
2051 // todo correct way to guard against opening a duplicate panel?
2052 new AnnotationChooser(ap);
2061 protected void PIDColour_actionPerformed()
2063 SequenceGroup sg = getGroup();
2064 sg.cs = new PIDColourScheme();
2065 sg.cs.setConsensus(AAFrequency.calculate(
2066 sg.getSequences(ap.av.getHiddenRepSequences()),
2067 sg.getStartRes(), sg.getEndRes() + 1));
2077 protected void BLOSUM62Colour_actionPerformed()
2079 SequenceGroup sg = getGroup();
2081 sg.cs = new Blosum62ColourScheme();
2083 sg.cs.setConsensus(AAFrequency.calculate(
2084 sg.getSequences(ap.av.getHiddenRepSequences()),
2085 sg.getStartRes(), sg.getEndRes() + 1));
2096 protected void noColourmenuItem_actionPerformed()
2098 getGroup().cs = null;
2108 protected void conservationMenuItem_actionPerformed()
2110 SequenceGroup sg = getGroup();
2116 if (conservationMenuItem.isSelected())
2118 // JBPNote: Conservation name shouldn't be i18n translated
2119 Conservation c = new Conservation("Group",
2120 ResidueProperties.propHash, 3, sg.getSequences(ap.av
2121 .getHiddenRepSequences()), sg.getStartRes(),
2122 sg.getEndRes() + 1);
2125 c.verdict(false, ap.av.getConsPercGaps());
2127 sg.cs.setConservation(c);
2129 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
2130 SliderPanel.showConservationSlider();
2133 // remove ConservationColouring
2135 sg.cs.setConservation(null);
2141 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
2143 SequenceGroup sg = getGroup();
2149 AnnotationColourGradient acg = new AnnotationColourGradient(
2150 sequence.getAnnotation()[0], null,
2151 AnnotationColourGradient.NO_THRESHOLD);
2153 acg.setPredefinedColours(true);
2165 protected void groupName_actionPerformed()
2168 SequenceGroup sg = getGroup();
2169 EditNameDialog dialog = new EditNameDialog(sg.getName(),
2170 sg.getDescription(), " "
2171 + MessageManager.getString("label.group_name") + " ",
2172 MessageManager.getString("label.group_description") + " ",
2173 MessageManager.getString("label.edit_group_name_description"),
2181 sg.setName(dialog.getName());
2182 sg.setDescription(dialog.getDescription());
2187 * Get selection group - adding it to the alignment if necessary.
2189 * @return sequence group to operate on
2191 SequenceGroup getGroup()
2193 SequenceGroup sg = ap.av.getSelectionGroup();
2194 // this method won't add a new group if it already exists
2197 ap.av.getAlignment().addGroup(sg);
2209 void sequenceName_actionPerformed()
2211 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
2212 sequence.getDescription(),
2213 " " + MessageManager.getString("label.sequence_name")
2215 MessageManager.getString("label.sequence_description") + " ",
2217 .getString("label.edit_sequence_name_description"),
2225 if (dialog.getName() != null)
2227 if (dialog.getName().indexOf(" ") > -1)
2233 .getString("label.spaces_converted_to_backslashes"),
2235 .getString("label.no_spaces_allowed_sequence_name"),
2236 JOptionPane.WARNING_MESSAGE);
2239 sequence.setName(dialog.getName().replace(' ', '_'));
2240 ap.paintAlignment(false);
2243 sequence.setDescription(dialog.getDescription());
2245 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2256 void unGroupMenuItem_actionPerformed()
2258 SequenceGroup sg = ap.av.getSelectionGroup();
2259 ap.av.getAlignment().deleteGroup(sg);
2260 ap.av.setSelectionGroup(null);
2264 void createGroupMenuItem_actionPerformed()
2266 getGroup(); // implicitly creates group - note - should apply defaults / use
2267 // standard alignment window logic for this
2277 protected void outline_actionPerformed()
2279 SequenceGroup sg = getGroup();
2280 Color col = JColorChooser.showDialog(this,
2281 MessageManager.getString("label.select_outline_colour"),
2286 sg.setOutlineColour(col);
2298 public void showBoxes_actionPerformed()
2300 getGroup().setDisplayBoxes(showBoxes.isSelected());
2310 public void showText_actionPerformed()
2312 getGroup().setDisplayText(showText.isSelected());
2322 public void showColourText_actionPerformed()
2324 getGroup().setColourText(showColourText.isSelected());
2328 public void showLink(String url)
2332 jalview.util.BrowserLauncher.openURL(url);
2333 } catch (Exception ex)
2335 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2336 MessageManager.getString("label.web_browser_not_found_unix"),
2337 MessageManager.getString("label.web_browser_not_found"),
2338 JOptionPane.WARNING_MESSAGE);
2340 ex.printStackTrace();
2344 void hideSequences(boolean representGroup)
2346 SequenceGroup sg = ap.av.getSelectionGroup();
2347 if (sg == null || sg.getSize() < 1)
2349 ap.av.hideSequence(new SequenceI[]
2354 ap.av.setSelectionGroup(null);
2358 ap.av.hideRepSequences(sequence, sg);
2363 int gsize = sg.getSize();
2366 hseqs = new SequenceI[gsize];
2369 for (int i = 0; i < gsize; i++)
2371 hseqs[index++] = sg.getSequenceAt(i);
2374 ap.av.hideSequence(hseqs);
2375 // refresh(); TODO: ? needed ?
2376 ap.av.sendSelection();
2379 public void copy_actionPerformed()
2381 ap.alignFrame.copy_actionPerformed(null);
2384 public void cut_actionPerformed()
2386 ap.alignFrame.cut_actionPerformed(null);
2389 void changeCase(ActionEvent e)
2391 Object source = e.getSource();
2392 SequenceGroup sg = ap.av.getSelectionGroup();
2396 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
2397 sg.getEndRes() + 1);
2402 if (source == toggle)
2404 description = MessageManager.getString("label.toggle_case");
2405 caseChange = ChangeCaseCommand.TOGGLE_CASE;
2407 else if (source == upperCase)
2409 description = MessageManager.getString("label.to_upper_case");
2410 caseChange = ChangeCaseCommand.TO_UPPER;
2414 description = MessageManager.getString("label.to_lower_case");
2415 caseChange = ChangeCaseCommand.TO_LOWER;
2418 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
2419 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2420 startEnd, caseChange);
2422 ap.alignFrame.addHistoryItem(caseCommand);
2424 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
2430 public void outputText_actionPerformed(ActionEvent e)
2432 CutAndPasteTransfer cap = new CutAndPasteTransfer();
2433 cap.setForInput(null);
2434 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
2435 "label.alignment_output_command", new String[]
2436 { e.getActionCommand() }), 600, 500);
2438 String[] omitHidden = null;
2440 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
2441 // or we simply trust the user wants
2442 // wysiwig behaviour
2444 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
2448 public void pdbFromFile_actionPerformed()
2450 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
2451 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
2452 chooser.setFileView(new jalview.io.JalviewFileView());
2453 chooser.setDialogTitle(MessageManager.formatMessage(
2454 "label.select_pdb_file_for", new String[]
2455 { sequence.getDisplayId(false) }));
2456 chooser.setToolTipText(MessageManager.formatMessage(
2457 "label.load_pdb_file_associate_with_sequence", new String[]
2458 { sequence.getDisplayId(false) }));
2460 int value = chooser.showOpenDialog(null);
2462 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
2464 String choice = chooser.getSelectedFile().getPath();
2465 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2466 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
2467 jalview.io.AppletFormatAdapter.FILE, sequence, true);
2472 // JBNote: commented out - these won't be instantiated here...!
2473 // public void RNAFold_actionPerformed() throws Exception
2475 // Predict2D P2D = new Predict2D();
2476 // P2D.getStructure2DFromRNAFold("toto");
2479 // public void ContraFold_actionPerformed() throws Exception
2481 // Predict2D P2D = new Predict2D();
2482 // P2D.getStructure2DFromContraFold("toto");
2484 public void enterPDB_actionPerformed()
2486 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
2487 MessageManager.getString("label.enter_pdb_id"),
2488 MessageManager.getString("label.enter_pdb_id"),
2489 JOptionPane.QUESTION_MESSAGE);
2491 if (id != null && id.length() > 0)
2493 PDBEntry entry = new PDBEntry();
2494 entry.setId(id.toUpperCase());
2495 sequence.getDatasetSequence().addPDBId(entry);
2499 public void discoverPDB_actionPerformed()
2502 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
2504 : ap.av.getSequenceSelection());
2505 Thread discpdb = new Thread(new Runnable()
2511 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
2512 .fetchDBRefs(false);
2519 public void sequenceFeature_actionPerformed()
2521 SequenceGroup sg = ap.av.getSelectionGroup();
2527 int rsize = 0, gSize = sg.getSize();
2528 SequenceI[] rseqs, seqs = new SequenceI[gSize];
2529 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
2531 for (int i = 0; i < gSize; i++)
2533 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
2534 int end = sg.findEndRes(sg.getSequenceAt(i));
2537 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
2538 features[rsize] = new SequenceFeature(null, null, null, start, end,
2543 rseqs = new SequenceI[rsize];
2544 tfeatures = new SequenceFeature[rsize];
2545 System.arraycopy(seqs, 0, rseqs, 0, rsize);
2546 System.arraycopy(features, 0, tfeatures, 0, rsize);
2547 features = tfeatures;
2549 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
2550 features, true, ap))
2552 ap.alignFrame.setShowSeqFeatures(true);
2553 ap.highlightSearchResults(null);
2557 public void textColour_actionPerformed()
2559 SequenceGroup sg = getGroup();
2562 new TextColourChooser().chooseColour(ap, sg);
2566 public void colourByStructure(String pdbid)
2568 Annotation[] anots = ap.av.getStructureSelectionManager()
2569 .colourSequenceFromStructure(sequence, pdbid);
2571 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
2572 "Coloured by " + pdbid, anots);
2574 ap.av.getAlignment().addAnnotation(an);
2575 an.createSequenceMapping(sequence, 0, true);
2576 // an.adjustForAlignment();
2577 ap.av.getAlignment().setAnnotationIndex(an, 0);
2579 ap.adjustAnnotationHeight();
2581 sequence.addAlignmentAnnotation(an);
2585 public void editSequence_actionPerformed(ActionEvent actionEvent)
2587 SequenceGroup sg = ap.av.getSelectionGroup();
2591 if (sequence == null)
2592 sequence = sg.getSequenceAt(0);
2594 EditNameDialog dialog = new EditNameDialog(
2595 sequence.getSequenceAsString(sg.getStartRes(),
2596 sg.getEndRes() + 1), null,
2597 MessageManager.getString("label.edit_sequence"), null,
2598 MessageManager.getString("label.edit_sequence"),
2603 EditCommand editCommand = new EditCommand(
2604 MessageManager.getString("label.edit_sequences"),
2605 EditCommand.REPLACE, dialog.getName().replace(' ',
2606 ap.av.getGapCharacter()),
2607 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
2608 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
2610 ap.alignFrame.addHistoryItem(editCommand);
2612 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()