2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 import java.awt.event.*;
28 import jalview.analysis.*;
29 import jalview.commands.*;
30 import jalview.datamodel.*;
32 import jalview.schemes.*;
33 import jalview.util.GroupUrlLink;
34 import jalview.util.GroupUrlLink.UrlStringTooLongException;
35 import jalview.util.UrlLink;
41 * @version $Revision: 1.118 $
43 public class PopupMenu extends JPopupMenu
45 JMenu groupMenu = new JMenu();
47 JMenuItem groupName = new JMenuItem();
49 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
51 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
53 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
55 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
57 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
59 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
61 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
63 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
65 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
67 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
69 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
71 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
73 protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
75 // protected JRadioButtonMenuItem covariationColour = new
76 // JRadioButtonMenuItem();
78 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
80 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
84 JMenu sequenceMenu = new JMenu();
86 JMenuItem sequenceName = new JMenuItem();
90 JMenuItem unGroupMenuItem = new JMenuItem();
92 JMenuItem outline = new JMenuItem();
94 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
96 JMenu colourMenu = new JMenu();
98 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
100 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
102 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
104 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
106 JMenu editMenu = new JMenu();
108 JMenuItem cut = new JMenuItem();
110 JMenuItem copy = new JMenuItem();
112 JMenuItem upperCase = new JMenuItem();
114 JMenuItem lowerCase = new JMenuItem();
116 JMenuItem toggle = new JMenuItem();
118 JMenu pdbMenu = new JMenu();
120 JMenuItem pdbFromFile = new JMenuItem();
122 JMenuItem enterPDB = new JMenuItem();
124 JMenuItem discoverPDB = new JMenuItem();
126 JMenu outputMenu = new JMenu();
128 JMenuItem sequenceFeature = new JMenuItem();
130 JMenuItem textColour = new JMenuItem();
132 JMenu jMenu1 = new JMenu();
134 JMenu structureMenu = new JMenu();
136 JMenu viewStructureMenu = new JMenu();
138 // JMenu colStructureMenu = new JMenu();
139 JMenuItem editSequence = new JMenuItem();
141 // JMenuItem annotationMenuItem = new JMenuItem();
143 JMenu groupLinksMenu;
146 * Creates a new PopupMenu object.
153 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
155 this(ap, seq, links, null);
165 public PopupMenu(final AlignmentPanel ap, final SequenceI seq, Vector links,
168 // /////////////////////////////////////////////////////////
169 // If this is activated from the sequence panel, the user may want to
170 // edit or annotate a particular residue. Therefore display the residue menu
172 // If from the IDPanel, we must display the sequence menu
173 // ////////////////////////////////////////////////////////
177 ButtonGroup colours = new ButtonGroup();
178 colours.add(noColourmenuItem);
179 colours.add(clustalColour);
180 colours.add(zappoColour);
181 colours.add(taylorColour);
182 colours.add(hydrophobicityColour);
183 colours.add(helixColour);
184 colours.add(strandColour);
185 colours.add(turnColour);
186 colours.add(buriedColour);
187 colours.add(abovePIDColour);
188 colours.add(userDefinedColour);
189 colours.add(PIDColour);
190 colours.add(BLOSUM62Colour);
191 colours.add(purinePyrimidineColour);
192 // colours.add(covariationColour);
194 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
196 JMenuItem item = new JMenuItem(
197 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
199 item.addActionListener(new java.awt.event.ActionListener()
201 public void actionPerformed(ActionEvent e)
203 outputText_actionPerformed(e);
207 outputMenu.add(item);
213 } catch (Exception e)
221 sequenceMenu.setText(sequence.getName());
223 if (seq.getDatasetSequence().getPDBId() != null
224 && seq.getDatasetSequence().getPDBId().size() > 0)
226 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
229 while (e.hasMoreElements())
231 final PDBEntry pdb = (PDBEntry) e.nextElement();
233 menuItem = new JMenuItem();
234 menuItem.setText(pdb.getId());
235 menuItem.addActionListener(new java.awt.event.ActionListener()
237 public void actionPerformed(ActionEvent e)
239 // TODO re JAL-860: optionally open dialog or provide a menu entry allowing user to open just one structure per sequence
240 new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[] { pdb })[0], null, ap);
241 // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
245 viewStructureMenu.add(menuItem);
248 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
249 * menuItem.addActionListener(new java.awt.event.ActionListener() {
250 * public void actionPerformed(ActionEvent e) {
251 * colourByStructure(pdb.getId()); } });
252 * colStructureMenu.add(menuItem);
258 if (ap.av.getAlignment().isNucleotide() == false)
260 structureMenu.remove(viewStructureMenu);
262 // structureMenu.remove(colStructureMenu);
265 if (ap.av.getAlignment().isNucleotide() == true)
267 AlignmentAnnotation[] aa = ap.av.getAlignment().getAlignmentAnnotation();
268 for (int i = 0; i < aa.length; i++)
270 if (aa[i].getRNAStruc() != null)
272 final String rnastruc = aa[i].getRNAStruc();
274 menuItem = new JMenuItem();
275 menuItem.setText("RNA structure - consensus");
276 menuItem.addActionListener(new java.awt.event.ActionListener()
278 public void actionPerformed(ActionEvent e)
280 new AppVarna(seq.getSequenceAsString(), rnastruc, seq
284 viewStructureMenu.add(menuItem);
288 // SequenceFeatures[] test = seq.getSequenceFeatures();
290 if (seq.getAnnotation() != null)
292 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
293 for (int i = 0; i < seqAnno.length; i++)
295 if (seqAnno[i].getRNAStruc() != null)
297 final String rnastruc = seqAnno[i].getRNAStruc();
299 // TODO: make rnastrucF a bit more nice
300 menuItem = new JMenuItem();
301 menuItem.setText("RNA structure - "+seq.getName());
302 menuItem.addActionListener(new java.awt.event.ActionListener()
304 public void actionPerformed(ActionEvent e)
306 // TODO: VARNA does'nt print gaps in the sequence
307 new AppVarna(seq.getSequenceAsString(), rnastruc, seq
311 viewStructureMenu.add(menuItem);
319 menuItem = new JMenuItem("Hide Sequences");
320 menuItem.addActionListener(new java.awt.event.ActionListener()
322 public void actionPerformed(ActionEvent e)
324 hideSequences(false);
329 if (ap.av.getSelectionGroup() != null
330 && ap.av.getSelectionGroup().getSize() > 1)
332 menuItem = new JMenuItem("Represent Group with " + seq.getName());
333 menuItem.addActionListener(new java.awt.event.ActionListener()
335 public void actionPerformed(ActionEvent e)
340 sequenceMenu.add(menuItem);
343 if (ap.av.hasHiddenRows())
345 final int index = ap.av.getAlignment().findIndex(seq);
347 if (ap.av.adjustForHiddenSeqs(index)
348 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
350 menuItem = new JMenuItem("Reveal Sequences");
351 menuItem.addActionListener(new ActionListener()
353 public void actionPerformed(ActionEvent e)
355 ap.av.showSequence(index);
356 if (ap.overviewPanel != null)
358 ap.overviewPanel.updateOverviewImage();
366 // for the case when no sequences are even visible
367 if (ap.av.hasHiddenRows()) {
369 menuItem = new JMenuItem("Reveal All");
370 menuItem.addActionListener(new ActionListener()
372 public void actionPerformed(ActionEvent e)
374 ap.av.showAllHiddenSeqs();
375 if (ap.overviewPanel != null)
377 ap.overviewPanel.updateOverviewImage();
387 SequenceGroup sg = ap.av.getSelectionGroup();
389 if (sg != null&& sg.getSize()>0)
391 groupName.setText("Name: "+sg.getName());
392 groupName.setText("Edit name and description of current group.");
394 if (sg.cs instanceof ZappoColourScheme)
396 zappoColour.setSelected(true);
398 else if (sg.cs instanceof TaylorColourScheme)
400 taylorColour.setSelected(true);
402 else if (sg.cs instanceof PIDColourScheme)
404 PIDColour.setSelected(true);
406 else if (sg.cs instanceof Blosum62ColourScheme)
408 BLOSUM62Colour.setSelected(true);
410 else if (sg.cs instanceof UserColourScheme)
412 userDefinedColour.setSelected(true);
414 else if (sg.cs instanceof HydrophobicColourScheme)
416 hydrophobicityColour.setSelected(true);
418 else if (sg.cs instanceof HelixColourScheme)
420 helixColour.setSelected(true);
422 else if (sg.cs instanceof StrandColourScheme)
424 strandColour.setSelected(true);
426 else if (sg.cs instanceof TurnColourScheme)
428 turnColour.setSelected(true);
430 else if (sg.cs instanceof BuriedColourScheme)
432 buriedColour.setSelected(true);
434 else if (sg.cs instanceof ClustalxColourScheme)
436 clustalColour.setSelected(true);
438 else if (sg.cs instanceof PurinePyrimidineColourScheme)
440 purinePyrimidineColour.setSelected(true);
443 * else if (sg.cs instanceof CovariationColourScheme) {
444 * covariationColour.setSelected(true); }
448 noColourmenuItem.setSelected(true);
451 if (sg.cs != null && sg.cs.conservationApplied())
453 conservationMenuItem.setSelected(true);
455 displayNonconserved.setSelected(sg.getShowNonconserved());
456 showText.setSelected(sg.getDisplayText());
457 showColourText.setSelected(sg.getColourText());
458 showBoxes.setSelected(sg.getDisplayBoxes());
459 // add any groupURLs to the groupURL submenu and make it visible
460 if (groupLinks != null && groupLinks.size() > 0)
462 buildGroupURLMenu(sg, groupLinks);
464 // Add a 'show all structures' for the current selection
465 Hashtable<String, PDBEntry> pdbe=new Hashtable<String,PDBEntry>();
466 SequenceI sqass=null;
467 for (SequenceI sq: ap.av.getSequenceSelection())
469 Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence().getPDBId();
471 for (PDBEntry pe: pes)
473 pdbe.put(pe.getId(), pe);
483 final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]);
484 final JMenuItem gpdbview;
487 structureMenu.add(gpdbview=new JMenuItem("View structure for "+sqass.getDisplayId(false)));
489 structureMenu.add(gpdbview=new JMenuItem("View all "+pdbe.size()+" structures."));
491 gpdbview.setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment.");
492 gpdbview.addActionListener(new ActionListener()
496 public void actionPerformed(ActionEvent e)
498 new AppJmol(ap, pe, ap.av.collateForPDB(pe));
505 groupMenu.setVisible(false);
506 editMenu.setVisible(false);
509 if (!ap.av.getAlignment().getGroups().contains(sg))
511 unGroupMenuItem.setVisible(false);
516 sequenceMenu.setVisible(false);
517 structureMenu.setVisible(false);
520 if (links != null && links.size() > 0)
523 JMenu linkMenu = new JMenu("Link");
524 Vector linkset = new Vector();
525 for (int i = 0; i < links.size(); i++)
527 String link = links.elementAt(i).toString();
528 UrlLink urlLink = null;
531 urlLink = new UrlLink(link);
532 } catch (Exception foo)
534 jalview.bin.Cache.log.error("Exception for URLLink '" + link
539 if (!urlLink.isValid())
541 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
544 final String label = urlLink.getLabel();
545 if (seq!=null && urlLink.isDynamic())
548 // collect matching db-refs
549 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
550 seq.getDBRef(), new String[]
551 { urlLink.getTarget() });
552 // collect id string too
553 String id = seq.getName();
554 String descr = seq.getDescription();
555 if (descr != null && descr.length() < 1)
562 for (int r = 0; r < dbr.length; r++)
564 if (id != null && dbr[r].getAccessionId().equals(id))
566 // suppress duplicate link creation for the bare sequence ID
567 // string with this link
570 // create Bare ID link for this RUL
571 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
575 for (int u = 0; u < urls.length; u += 2)
577 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
579 linkset.addElement(urls[u] + "|" + urls[u + 1]);
580 addshowLink(linkMenu, label + "|" + urls[u],
589 // create Bare ID link for this RUL
590 String[] urls = urlLink.makeUrls(id, true);
593 for (int u = 0; u < urls.length; u += 2)
595 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
597 linkset.addElement(urls[u] + "|" + urls[u + 1]);
598 addshowLink(linkMenu, label, urls[u + 1]);
603 // Create urls from description but only for URL links which are regex
605 if (descr != null && urlLink.getRegexReplace() != null)
607 // create link for this URL from description where regex matches
608 String[] urls = urlLink.makeUrls(descr, true);
611 for (int u = 0; u < urls.length; u += 2)
613 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
615 linkset.addElement(urls[u] + "|" + urls[u + 1]);
616 addshowLink(linkMenu, label, urls[u + 1]);
624 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
626 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
627 // Add a non-dynamic link
628 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
632 if (sequence != null)
634 sequenceMenu.add(linkMenu);
643 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
646 // TODO: usability: thread off the generation of group url content so root
648 // sequence only URLs
649 // ID/regex match URLs
650 groupLinksMenu = new JMenu("Group Link");
651 JMenu[] linkMenus = new JMenu[]
652 { null, new JMenu("IDS"), new JMenu("Sequences"),
653 new JMenu("IDS and Sequences") }; // three types of url that might be
655 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
656 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
657 Hashtable commonDbrefs = new Hashtable();
658 for (int sq = 0; sq < seqs.length; sq++)
661 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
662 .findPosition(sg.getEndRes());
663 // just collect ids from dataset sequence
664 // TODO: check if IDs collected from selecton group intersects with the
665 // current selection, too
666 SequenceI sqi = seqs[sq];
667 while (sqi.getDatasetSequence() != null)
669 sqi = sqi.getDatasetSequence();
671 DBRefEntry[] dbr = sqi.getDBRef();
672 if (dbr != null && dbr.length > 0)
674 for (int d = 0; d < dbr.length; d++)
676 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
677 Object[] sarray = (Object[]) commonDbrefs.get(src);
680 sarray = new Object[2];
681 sarray[0] = new int[]
683 sarray[1] = new String[seqs.length];
685 commonDbrefs.put(src, sarray);
688 if (((String[]) sarray[1])[sq] == null)
691 || (dbr[d].getMap().locateMappedRange(start, end) != null))
693 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
694 ((int[]) sarray[0])[0]++;
700 // now create group links for all distinct ID/sequence sets.
701 boolean addMenu = false; // indicates if there are any group links to give
703 for (int i = 0; i < groupLinks.size(); i++)
705 String link = groupLinks.elementAt(i).toString();
706 GroupUrlLink urlLink = null;
709 urlLink = new GroupUrlLink(link);
710 } catch (Exception foo)
712 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
717 if (!urlLink.isValid())
719 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
722 final String label = urlLink.getLabel();
723 boolean usingNames = false;
724 // Now see which parts of the group apply for this URL
725 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
726 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
727 String[] seqstr, ids; // input to makeUrl
730 int numinput = ((int[]) idset[0])[0];
731 String[] allids = ((String[]) idset[1]);
732 seqstr = new String[numinput];
733 ids = new String[numinput];
734 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
736 if (allids[sq] != null)
738 ids[idcount] = allids[sq];
739 seqstr[idcount++] = idandseqs[1][sq];
745 // just use the id/seq set
746 seqstr = idandseqs[1];
750 // and try and make the groupURL!
752 Object[] urlset = null;
755 urlset = urlLink.makeUrlStubs(ids, seqstr,
756 "FromJalview" + System.currentTimeMillis(), false);
757 } catch (UrlStringTooLongException e)
762 int type = urlLink.getGroupURLType() & 3;
763 // System.out.println(urlLink.getGroupURLType()
764 // +" "+((String[])urlset[3])[0]);
765 // first two bits ofurlLink type bitfield are sequenceids and sequences
766 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
767 addshowLink(linkMenus[type], label
768 + (((type & 1) == 1) ? ("("
769 + (usingNames ? "Names" : ltarget) + ")") : ""),
776 groupLinksMenu = new JMenu("Group Links");
777 for (int m = 0; m < linkMenus.length; m++)
779 if (linkMenus[m] != null
780 && linkMenus[m].getMenuComponentCount() > 0)
782 groupLinksMenu.add(linkMenus[m]);
786 groupMenu.add(groupLinksMenu);
791 * add a show URL menu item to the given linkMenu
795 * - menu label string
799 private void addshowLink(JMenu linkMenu, String label, final String url)
801 JMenuItem item = new JMenuItem(label);
802 item.setToolTipText("open URL: " + url);
803 item.addActionListener(new java.awt.event.ActionListener()
805 public void actionPerformed(ActionEvent e)
807 new Thread(new Runnable()
823 * add a late bound groupURL item to the given linkMenu
827 * - menu label string
828 * @param urlgenerator
829 * GroupURLLink used to generate URL
831 * Object array returned from the makeUrlStubs function.
833 private void addshowLink(JMenu linkMenu, String label,
834 final GroupUrlLink urlgenerator, final Object[] urlstub)
836 JMenuItem item = new JMenuItem(label);
837 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
838 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
847 item.addActionListener(new java.awt.event.ActionListener()
849 public void actionPerformed(ActionEvent e)
851 new Thread(new Runnable()
858 showLink(urlgenerator.constructFrom(urlstub));
859 } catch (UrlStringTooLongException e)
877 private void jbInit() throws Exception
879 groupMenu.setText("Group");
880 groupMenu.setText("Selection");
881 groupName.setText("Name");
882 groupName.addActionListener(new java.awt.event.ActionListener()
884 public void actionPerformed(ActionEvent e)
886 groupName_actionPerformed();
889 sequenceMenu.setText("Sequence");
890 sequenceName.setText("Edit Name/Description");
891 sequenceName.addActionListener(new java.awt.event.ActionListener()
893 public void actionPerformed(ActionEvent e)
895 sequenceName_actionPerformed();
898 PIDColour.setFocusPainted(false);
899 unGroupMenuItem.setText("Remove Group");
900 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
902 public void actionPerformed(ActionEvent e)
904 unGroupMenuItem_actionPerformed();
908 outline.setText("Border colour");
909 outline.addActionListener(new java.awt.event.ActionListener()
911 public void actionPerformed(ActionEvent e)
913 outline_actionPerformed();
916 nucleotideMenuItem.setText("Nucleotide");
917 nucleotideMenuItem.addActionListener(new ActionListener()
919 public void actionPerformed(ActionEvent e)
921 nucleotideMenuItem_actionPerformed();
924 colourMenu.setText("Group Colour");
925 showBoxes.setText("Boxes");
926 showBoxes.setState(true);
927 showBoxes.addActionListener(new ActionListener()
929 public void actionPerformed(ActionEvent e)
931 showBoxes_actionPerformed();
934 showText.setText("Text");
935 showText.setState(true);
936 showText.addActionListener(new ActionListener()
938 public void actionPerformed(ActionEvent e)
940 showText_actionPerformed();
943 showColourText.setText("Colour Text");
944 showColourText.addActionListener(new ActionListener()
946 public void actionPerformed(ActionEvent e)
948 showColourText_actionPerformed();
951 displayNonconserved.setText("Show Nonconserved");
952 displayNonconserved.setState(true);
953 displayNonconserved.addActionListener(new ActionListener()
955 public void actionPerformed(ActionEvent e)
957 showNonconserved_actionPerformed();
960 editMenu.setText("Edit");
962 cut.addActionListener(new ActionListener()
964 public void actionPerformed(ActionEvent e)
966 cut_actionPerformed();
969 upperCase.setText("To Upper Case");
970 upperCase.addActionListener(new ActionListener()
972 public void actionPerformed(ActionEvent e)
977 copy.setText("Copy");
978 copy.addActionListener(new ActionListener()
980 public void actionPerformed(ActionEvent e)
982 copy_actionPerformed();
985 lowerCase.setText("To Lower Case");
986 lowerCase.addActionListener(new ActionListener()
988 public void actionPerformed(ActionEvent e)
993 toggle.setText("Toggle Case");
994 toggle.addActionListener(new ActionListener()
996 public void actionPerformed(ActionEvent e)
1001 pdbMenu.setText("Associate Structure with Sequence");
1002 pdbFromFile.setText("From File");
1003 pdbFromFile.addActionListener(new ActionListener()
1005 public void actionPerformed(ActionEvent e)
1007 pdbFromFile_actionPerformed();
1010 enterPDB.setText("Enter PDB Id");
1011 enterPDB.addActionListener(new ActionListener()
1013 public void actionPerformed(ActionEvent e)
1015 enterPDB_actionPerformed();
1018 discoverPDB.setText("Discover PDB ids");
1019 discoverPDB.addActionListener(new ActionListener()
1021 public void actionPerformed(ActionEvent e)
1023 discoverPDB_actionPerformed();
1026 outputMenu.setText("Output to Textbox...");
1027 sequenceFeature.setText("Create Sequence Feature");
1028 sequenceFeature.addActionListener(new ActionListener()
1030 public void actionPerformed(ActionEvent e)
1032 sequenceFeature_actionPerformed();
1035 textColour.setText("Text Colour");
1036 textColour.addActionListener(new ActionListener()
1038 public void actionPerformed(ActionEvent e)
1040 textColour_actionPerformed();
1043 jMenu1.setText("Group");
1044 structureMenu.setText("Structure");
1045 viewStructureMenu.setText("View Structure");
1046 // colStructureMenu.setText("Colour By Structure");
1047 editSequence.setText("Edit Sequence...");
1048 editSequence.addActionListener(new ActionListener()
1050 public void actionPerformed(ActionEvent actionEvent)
1052 editSequence_actionPerformed(actionEvent);
1056 * annotationMenuItem.setText("By Annotation");
1057 * annotationMenuItem.addActionListener(new ActionListener() { public void
1058 * actionPerformed(ActionEvent actionEvent) {
1059 * annotationMenuItem_actionPerformed(actionEvent); } });
1065 this.add(structureMenu);
1066 groupMenu.add(editMenu);
1067 groupMenu.add(outputMenu);
1068 groupMenu.add(sequenceFeature);
1069 groupMenu.add(jMenu1);
1070 sequenceMenu.add(sequenceName);
1071 colourMenu.add(textColour);
1072 colourMenu.add(noColourmenuItem);
1073 colourMenu.add(clustalColour);
1074 colourMenu.add(BLOSUM62Colour);
1075 colourMenu.add(PIDColour);
1076 colourMenu.add(zappoColour);
1077 colourMenu.add(taylorColour);
1078 colourMenu.add(hydrophobicityColour);
1079 colourMenu.add(helixColour);
1080 colourMenu.add(strandColour);
1081 colourMenu.add(turnColour);
1082 colourMenu.add(buriedColour);
1083 colourMenu.add(nucleotideMenuItem);
1084 if (ap.getAlignment().isNucleotide()) {
1085 colourMenu.add(purinePyrimidineColour);
1087 // colourMenu.add(covariationColour);
1088 colourMenu.add(userDefinedColour);
1090 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1092 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1093 .getUserColourSchemes().keys();
1095 while (userColours.hasMoreElements())
1097 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1098 item.addActionListener(new ActionListener()
1100 public void actionPerformed(ActionEvent evt)
1102 userDefinedColour_actionPerformed(evt);
1105 colourMenu.add(item);
1109 colourMenu.addSeparator();
1110 colourMenu.add(abovePIDColour);
1111 colourMenu.add(conservationMenuItem);
1112 // colourMenu.add(annotationMenuItem);
1115 editMenu.add(editSequence);
1116 editMenu.add(upperCase);
1117 editMenu.add(lowerCase);
1118 editMenu.add(toggle);
1119 pdbMenu.add(pdbFromFile);
1120 pdbMenu.add(enterPDB);
1121 pdbMenu.add(discoverPDB);
1122 jMenu1.add(groupName);
1123 jMenu1.add(unGroupMenuItem);
1124 jMenu1.add(colourMenu);
1125 jMenu1.add(showBoxes);
1126 jMenu1.add(showText);
1127 jMenu1.add(showColourText);
1128 jMenu1.add(outline);
1129 jMenu1.add(displayNonconserved);
1130 structureMenu.add(pdbMenu);
1131 structureMenu.add(viewStructureMenu);
1132 // structureMenu.add(colStructureMenu);
1133 noColourmenuItem.setText("None");
1134 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1136 public void actionPerformed(ActionEvent e)
1138 noColourmenuItem_actionPerformed();
1142 clustalColour.setText("Clustalx colours");
1143 clustalColour.addActionListener(new java.awt.event.ActionListener()
1145 public void actionPerformed(ActionEvent e)
1147 clustalColour_actionPerformed();
1150 zappoColour.setText("Zappo");
1151 zappoColour.addActionListener(new java.awt.event.ActionListener()
1153 public void actionPerformed(ActionEvent e)
1155 zappoColour_actionPerformed();
1158 taylorColour.setText("Taylor");
1159 taylorColour.addActionListener(new java.awt.event.ActionListener()
1161 public void actionPerformed(ActionEvent e)
1163 taylorColour_actionPerformed();
1166 hydrophobicityColour.setText("Hydrophobicity");
1167 hydrophobicityColour
1168 .addActionListener(new java.awt.event.ActionListener()
1170 public void actionPerformed(ActionEvent e)
1172 hydrophobicityColour_actionPerformed();
1175 helixColour.setText("Helix propensity");
1176 helixColour.addActionListener(new java.awt.event.ActionListener()
1178 public void actionPerformed(ActionEvent e)
1180 helixColour_actionPerformed();
1183 strandColour.setText("Strand propensity");
1184 strandColour.addActionListener(new java.awt.event.ActionListener()
1186 public void actionPerformed(ActionEvent e)
1188 strandColour_actionPerformed();
1191 turnColour.setText("Turn propensity");
1192 turnColour.addActionListener(new java.awt.event.ActionListener()
1194 public void actionPerformed(ActionEvent e)
1196 turnColour_actionPerformed();
1199 buriedColour.setText("Buried Index");
1200 buriedColour.addActionListener(new java.awt.event.ActionListener()
1202 public void actionPerformed(ActionEvent e)
1204 buriedColour_actionPerformed();
1207 abovePIDColour.setText("Above % Identity");
1208 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1210 public void actionPerformed(ActionEvent e)
1212 abovePIDColour_actionPerformed();
1215 userDefinedColour.setText("User Defined...");
1216 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1218 public void actionPerformed(ActionEvent e)
1220 userDefinedColour_actionPerformed(e);
1223 PIDColour.setText("Percentage Identity");
1224 PIDColour.addActionListener(new java.awt.event.ActionListener()
1226 public void actionPerformed(ActionEvent e)
1228 PIDColour_actionPerformed();
1231 BLOSUM62Colour.setText("BLOSUM62");
1232 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1234 public void actionPerformed(ActionEvent e)
1236 BLOSUM62Colour_actionPerformed();
1239 purinePyrimidineColour.setText("Purine/Pyrimidine");
1240 purinePyrimidineColour
1241 .addActionListener(new java.awt.event.ActionListener()
1243 public void actionPerformed(ActionEvent e)
1245 purinePyrimidineColour_actionPerformed();
1249 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1250 * public void actionPerformed(ActionEvent e) {
1251 * covariationColour_actionPerformed(); } });
1254 conservationMenuItem.setText("Conservation");
1255 conservationMenuItem
1256 .addActionListener(new java.awt.event.ActionListener()
1258 public void actionPerformed(ActionEvent e)
1260 conservationMenuItem_actionPerformed();
1265 protected void showNonconserved_actionPerformed()
1267 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1272 * call to refresh view after settings change
1276 ap.updateAnnotation();
1277 ap.paintAlignment(true);
1279 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1288 protected void clustalColour_actionPerformed()
1290 SequenceGroup sg = getGroup();
1291 sg.cs = new ClustalxColourScheme(
1292 sg.getSequences(ap.av.getHiddenRepSequences()),
1293 ap.av.getAlignment().getWidth());
1303 protected void zappoColour_actionPerformed()
1305 getGroup().cs = new ZappoColourScheme();
1315 protected void taylorColour_actionPerformed()
1317 getGroup().cs = new TaylorColourScheme();
1327 protected void hydrophobicityColour_actionPerformed()
1329 getGroup().cs = new HydrophobicColourScheme();
1339 protected void helixColour_actionPerformed()
1341 getGroup().cs = new HelixColourScheme();
1351 protected void strandColour_actionPerformed()
1353 getGroup().cs = new StrandColourScheme();
1363 protected void turnColour_actionPerformed()
1365 getGroup().cs = new TurnColourScheme();
1375 protected void buriedColour_actionPerformed()
1377 getGroup().cs = new BuriedColourScheme();
1387 public void nucleotideMenuItem_actionPerformed()
1389 getGroup().cs = new NucleotideColourScheme();
1393 protected void purinePyrimidineColour_actionPerformed()
1395 getGroup().cs = new PurinePyrimidineColourScheme();
1400 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1401 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1409 protected void abovePIDColour_actionPerformed()
1411 SequenceGroup sg = getGroup();
1417 if (abovePIDColour.isSelected())
1419 sg.cs.setConsensus(AAFrequency.calculate(
1420 sg.getSequences(ap.av.getHiddenRepSequences()), sg.getStartRes(),
1421 sg.getEndRes() + 1));
1423 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1426 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1428 SliderPanel.showPIDSlider();
1431 // remove PIDColouring
1433 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1445 protected void userDefinedColour_actionPerformed(ActionEvent e)
1447 SequenceGroup sg = getGroup();
1449 if (e.getActionCommand().equals("User Defined..."))
1451 new UserDefinedColours(ap, sg);
1455 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1456 .getUserColourSchemes().get(e.getActionCommand());
1469 protected void PIDColour_actionPerformed()
1471 SequenceGroup sg = getGroup();
1472 sg.cs = new PIDColourScheme();
1473 sg.cs.setConsensus(AAFrequency.calculate(
1474 sg.getSequences(ap.av.getHiddenRepSequences()), sg.getStartRes(),
1475 sg.getEndRes() + 1));
1485 protected void BLOSUM62Colour_actionPerformed()
1487 SequenceGroup sg = getGroup();
1489 sg.cs = new Blosum62ColourScheme();
1491 sg.cs.setConsensus(AAFrequency.calculate(
1492 sg.getSequences(ap.av.getHiddenRepSequences()), sg.getStartRes(),
1493 sg.getEndRes() + 1));
1504 protected void noColourmenuItem_actionPerformed()
1506 getGroup().cs = null;
1516 protected void conservationMenuItem_actionPerformed()
1518 SequenceGroup sg = getGroup();
1524 if (conservationMenuItem.isSelected())
1526 Conservation c = new Conservation("Group",
1527 ResidueProperties.propHash, 3,
1528 sg.getSequences(ap.av.getHiddenRepSequences()), sg.getStartRes(),
1529 sg.getEndRes() + 1);
1532 c.verdict(false, ap.av.getConsPercGaps());
1534 sg.cs.setConservation(c);
1536 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1537 SliderPanel.showConservationSlider();
1540 // remove ConservationColouring
1542 sg.cs.setConservation(null);
1548 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1550 SequenceGroup sg = getGroup();
1556 AnnotationColourGradient acg = new AnnotationColourGradient(
1557 sequence.getAnnotation()[0], null,
1558 AnnotationColourGradient.NO_THRESHOLD);
1560 acg.predefinedColours = true;
1572 protected void groupName_actionPerformed()
1575 SequenceGroup sg = getGroup();
1576 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1577 sg.getDescription(), " Group Name ",
1578 "Group Description ", "Edit Group Name/Description",
1586 sg.setName(dialog.getName());
1587 sg.setDescription(dialog.getDescription());
1592 * Get selection group - adding it to the alignment if necessary.
1594 * @return sequence group to operate on
1596 SequenceGroup getGroup()
1598 SequenceGroup sg = ap.av.getSelectionGroup();
1599 // this method won't add a new group if it already exists
1602 ap.av.getAlignment().addGroup(sg);
1614 void sequenceName_actionPerformed()
1616 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1617 sequence.getDescription(), " Sequence Name ",
1618 "Sequence Description ", "Edit Sequence Name/Description",
1626 if (dialog.getName() != null)
1628 if (dialog.getName().indexOf(" ") > -1)
1630 JOptionPane.showMessageDialog(ap,
1631 "Spaces have been converted to \"_\"",
1632 "No spaces allowed in Sequence Name",
1633 JOptionPane.WARNING_MESSAGE);
1636 sequence.setName(dialog.getName().replace(' ', '_'));
1637 ap.paintAlignment(false);
1640 sequence.setDescription(dialog.getDescription());
1642 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1653 void unGroupMenuItem_actionPerformed()
1655 SequenceGroup sg = ap.av.getSelectionGroup();
1656 ap.av.getAlignment().deleteGroup(sg);
1657 ap.av.setSelectionGroup(null);
1667 protected void outline_actionPerformed()
1669 SequenceGroup sg = getGroup();
1670 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1675 sg.setOutlineColour(col);
1687 public void showBoxes_actionPerformed()
1689 getGroup().setDisplayBoxes(showBoxes.isSelected());
1699 public void showText_actionPerformed()
1701 getGroup().setDisplayText(showText.isSelected());
1711 public void showColourText_actionPerformed()
1713 getGroup().setColourText(showColourText.isSelected());
1717 public void showLink(String url)
1721 jalview.util.BrowserLauncher.openURL(url);
1722 } catch (Exception ex)
1725 .showInternalMessageDialog(
1727 "Unixers: Couldn't find default web browser."
1728 + "\nAdd the full path to your browser in Preferences.",
1729 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1731 ex.printStackTrace();
1735 void hideSequences(boolean representGroup)
1737 SequenceGroup sg = ap.av.getSelectionGroup();
1738 if (sg == null || sg.getSize() < 1)
1740 ap.av.hideSequence(new SequenceI[]
1745 ap.av.setSelectionGroup(null);
1749 ap.av.hideRepSequences(sequence, sg);
1754 int gsize = sg.getSize();
1757 hseqs = new SequenceI[gsize];
1760 for (int i = 0; i < gsize; i++)
1762 hseqs[index++] = sg.getSequenceAt(i);
1765 ap.av.hideSequence(hseqs);
1766 // refresh(); TODO: ? needed ?
1767 ap.av.sendSelection();
1770 public void copy_actionPerformed()
1772 ap.alignFrame.copy_actionPerformed(null);
1775 public void cut_actionPerformed()
1777 ap.alignFrame.cut_actionPerformed(null);
1780 void changeCase(ActionEvent e)
1782 Object source = e.getSource();
1783 SequenceGroup sg = ap.av.getSelectionGroup();
1787 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1788 sg.getEndRes() + 1);
1793 if (source == toggle)
1795 description = "Toggle Case";
1796 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1798 else if (source == upperCase)
1800 description = "To Upper Case";
1801 caseChange = ChangeCaseCommand.TO_UPPER;
1805 description = "To Lower Case";
1806 caseChange = ChangeCaseCommand.TO_LOWER;
1809 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1810 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()), startEnd,
1813 ap.alignFrame.addHistoryItem(caseCommand);
1815 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1821 public void outputText_actionPerformed(ActionEvent e)
1823 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1824 cap.setForInput(null);
1825 Desktop.addInternalFrame(cap,
1826 "Alignment output - " + e.getActionCommand(), 600, 500);
1828 String[] omitHidden = null;
1830 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1831 // or we simply trust the user wants
1832 // wysiwig behaviour
1833 SequenceGroup sg = ap.av.getSelectionGroup();
1834 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1835 omitHidden = ap.av.getViewAsString(true);
1836 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1837 AlignmentAnnotation[] nala = ap.av.getAlignment().getAlignmentAnnotation();
1840 for (int i = 0; i < nala.length; i++)
1842 AlignmentAnnotation na = nala[i];
1843 oal.addAnnotation(na);
1846 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1847 oal, omitHidden, csel, sg));
1851 public void pdbFromFile_actionPerformed()
1853 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1854 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1855 chooser.setFileView(new jalview.io.JalviewFileView());
1856 chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
1857 chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
1859 int value = chooser.showOpenDialog(null);
1861 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1863 String choice = chooser.getSelectedFile().getPath();
1864 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1865 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
1870 public void enterPDB_actionPerformed()
1872 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1873 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1875 if (id != null && id.length() > 0)
1877 PDBEntry entry = new PDBEntry();
1878 entry.setId(id.toUpperCase());
1879 sequence.getDatasetSequence().addPDBId(entry);
1883 public void discoverPDB_actionPerformed()
1886 final SequenceI[] sequences = ((ap.av.getSelectionGroup() == null) ? new SequenceI[]
1888 : ap.av.getSequenceSelection());
1889 Thread discpdb = new Thread(new Runnable()
1894 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1895 .fetchDBRefs(false);
1902 public void sequenceFeature_actionPerformed()
1904 SequenceGroup sg = ap.av.getSelectionGroup();
1910 int rsize = 0, gSize = sg.getSize();
1911 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1912 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1914 for (int i = 0; i < gSize; i++)
1916 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1917 int end = sg.findEndRes(sg.getSequenceAt(i));
1920 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1921 features[rsize] = new SequenceFeature(null, null, null, start, end,
1926 rseqs = new SequenceI[rsize];
1927 tfeatures = new SequenceFeature[rsize];
1928 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1929 System.arraycopy(features, 0, tfeatures, 0, rsize);
1930 features = tfeatures;
1932 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1933 features, true, ap))
1935 ap.alignFrame.setShowSeqFeatures(true);
1936 ap.highlightSearchResults(null);
1940 public void textColour_actionPerformed()
1942 SequenceGroup sg = getGroup();
1945 new TextColourChooser().chooseColour(ap, sg);
1949 public void colourByStructure(String pdbid)
1951 Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure(
1954 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1955 "Coloured by " + pdbid, anots);
1957 ap.av.getAlignment().addAnnotation(an);
1958 an.createSequenceMapping(sequence, 0, true);
1959 // an.adjustForAlignment();
1960 ap.av.getAlignment().setAnnotationIndex(an, 0);
1962 ap.adjustAnnotationHeight();
1964 sequence.addAlignmentAnnotation(an);
1968 public void editSequence_actionPerformed(ActionEvent actionEvent)
1970 SequenceGroup sg = ap.av.getSelectionGroup();
1974 if (sequence == null)
1975 sequence = (Sequence) sg.getSequenceAt(0);
1977 EditNameDialog dialog = new EditNameDialog(
1978 sequence.getSequenceAsString(sg.getStartRes(),
1979 sg.getEndRes() + 1), null, "Edit Sequence ", null,
1980 "Edit Sequence", ap.alignFrame);
1984 EditCommand editCommand = new EditCommand("Edit Sequences",
1985 EditCommand.REPLACE, dialog.getName().replace(' ',
1986 ap.av.getGapCharacter()),
1987 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
1988 sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
1990 ap.alignFrame.addHistoryItem(editCommand);
1992 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()