2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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 Sequence seq,
166 final Vector links, final Vector groupLinks)
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)
220 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
240 // allowing user to open just one structure per sequence
241 new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
242 { pdb })[0], null, ap);
243 // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
247 viewStructureMenu.add(menuItem);
250 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
251 * menuItem.addActionListener(new java.awt.event.ActionListener() {
252 * public void actionPerformed(ActionEvent e) {
253 * colourByStructure(pdb.getId()); } });
254 * colStructureMenu.add(menuItem);
260 if (ap.av.alignment.isNucleotide() == false)
262 structureMenu.remove(viewStructureMenu);
264 // structureMenu.remove(colStructureMenu);
267 if (ap.av.alignment.isNucleotide() == true)
269 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
270 for (int i = 0; i < aa.length; i++)
272 if (aa[i].getRNAStruc() != null)
274 final String rnastruc = aa[i].getRNAStruc();
276 menuItem = new JMenuItem();
277 menuItem.setText("RNA structure - consensus");
278 menuItem.addActionListener(new java.awt.event.ActionListener()
280 public void actionPerformed(ActionEvent e)
282 new AppVarna(seq.getSequenceAsString(), rnastruc, seq
286 viewStructureMenu.add(menuItem);
290 // SequenceFeatures[] test = seq.getSequenceFeatures();
292 if (seq.getAnnotation() != null)
294 AlignmentAnnotation seqAnno[] = seq.getAnnotation();
295 for (int i = 0; i < seqAnno.length; i++)
297 if (seqAnno[i].getRNAStruc() != null)
299 final String rnastruc = seqAnno[i].getRNAStruc();
301 // TODO: make rnastrucF a bit more nice
302 menuItem = new JMenuItem();
303 menuItem.setText("RNA structure - "+seq.getName());
304 menuItem.addActionListener(new java.awt.event.ActionListener()
306 public void actionPerformed(ActionEvent e)
308 // TODO: VARNA does'nt print gaps in the sequence
309 new AppVarna(seq.getSequenceAsString(), rnastruc, seq
313 viewStructureMenu.add(menuItem);
321 menuItem = new JMenuItem("Hide Sequences");
322 menuItem.addActionListener(new java.awt.event.ActionListener()
324 public void actionPerformed(ActionEvent e)
326 hideSequences(false);
331 if (ap.av.getSelectionGroup() != null
332 && ap.av.getSelectionGroup().getSize() > 1)
334 menuItem = new JMenuItem("Represent Group with " + seq.getName());
335 menuItem.addActionListener(new java.awt.event.ActionListener()
337 public void actionPerformed(ActionEvent e)
342 sequenceMenu.add(menuItem);
345 if (ap.av.hasHiddenRows)
347 final int index = ap.av.alignment.findIndex(seq);
349 if (ap.av.adjustForHiddenSeqs(index)
350 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
352 menuItem = new JMenuItem("Reveal Sequences");
353 menuItem.addActionListener(new ActionListener()
355 public void actionPerformed(ActionEvent e)
357 ap.av.showSequence(index);
358 if (ap.overviewPanel != null)
360 ap.overviewPanel.updateOverviewImage();
367 menuItem = new JMenuItem("Reveal All");
368 menuItem.addActionListener(new ActionListener()
370 public void actionPerformed(ActionEvent e)
372 ap.av.showAllHiddenSeqs();
373 if (ap.overviewPanel != null)
375 ap.overviewPanel.updateOverviewImage();
385 SequenceGroup sg = ap.av.getSelectionGroup();
389 groupName.setText("Name: " + sg.getName());
390 groupName.setText("Edit name and description of current group.");
392 if (sg.cs instanceof ZappoColourScheme)
394 zappoColour.setSelected(true);
396 else if (sg.cs instanceof TaylorColourScheme)
398 taylorColour.setSelected(true);
400 else if (sg.cs instanceof PIDColourScheme)
402 PIDColour.setSelected(true);
404 else if (sg.cs instanceof Blosum62ColourScheme)
406 BLOSUM62Colour.setSelected(true);
408 else if (sg.cs instanceof UserColourScheme)
410 userDefinedColour.setSelected(true);
412 else if (sg.cs instanceof HydrophobicColourScheme)
414 hydrophobicityColour.setSelected(true);
416 else if (sg.cs instanceof HelixColourScheme)
418 helixColour.setSelected(true);
420 else if (sg.cs instanceof StrandColourScheme)
422 strandColour.setSelected(true);
424 else if (sg.cs instanceof TurnColourScheme)
426 turnColour.setSelected(true);
428 else if (sg.cs instanceof BuriedColourScheme)
430 buriedColour.setSelected(true);
432 else if (sg.cs instanceof ClustalxColourScheme)
434 clustalColour.setSelected(true);
436 else if (sg.cs instanceof PurinePyrimidineColourScheme)
438 purinePyrimidineColour.setSelected(true);
441 * else if (sg.cs instanceof CovariationColourScheme) {
442 * covariationColour.setSelected(true); }
446 noColourmenuItem.setSelected(true);
449 if (sg.cs != null && sg.cs.conservationApplied())
451 conservationMenuItem.setSelected(true);
453 displayNonconserved.setSelected(sg.getShowNonconserved());
454 showText.setSelected(sg.getDisplayText());
455 showColourText.setSelected(sg.getColourText());
456 showBoxes.setSelected(sg.getDisplayBoxes());
457 // add any groupURLs to the groupURL submenu and make it visible
458 if (groupLinks != null && groupLinks.size() > 0)
460 buildGroupURLMenu(sg, groupLinks);
462 // Add a 'show all structures' for the current selection
463 Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>();
464 for (SequenceI sq : ap.av.getSequenceSelection())
466 Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence()
470 for (PDBEntry pe : pes)
472 pdbe.put(pe.getId(), pe);
478 final PDBEntry[] pe = pdbe.values().toArray(
479 new PDBEntry[pdbe.size()]);
480 final JMenuItem gpdbview;
481 structureMenu.add(gpdbview = new JMenuItem("View " + pdbe.size()
484 .setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment.");
485 gpdbview.addActionListener(new ActionListener()
489 public void actionPerformed(ActionEvent e)
491 new AppJmol(ap, pe, ap.av.collateForPDB(pe));
498 groupMenu.setVisible(false);
499 editMenu.setVisible(false);
502 if (!ap.av.alignment.getGroups().contains(sg))
504 unGroupMenuItem.setVisible(false);
509 sequenceMenu.setVisible(false);
510 structureMenu.setVisible(false);
513 if (links != null && links.size() > 0)
516 JMenu linkMenu = new JMenu("Link");
517 Vector linkset = new Vector();
518 for (int i = 0; i < links.size(); i++)
520 String link = links.elementAt(i).toString();
521 UrlLink urlLink = null;
524 urlLink = new UrlLink(link);
525 } catch (Exception foo)
527 jalview.bin.Cache.log.error("Exception for URLLink '" + link
532 if (!urlLink.isValid())
534 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
537 final String label = urlLink.getLabel();
538 if (urlLink.isDynamic())
541 // collect matching db-refs
542 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq
543 .getDBRef(), new String[]
544 { urlLink.getTarget() });
545 // collect id string too
546 String id = seq.getName();
547 String descr = seq.getDescription();
548 if (descr != null && descr.length() < 1)
555 for (int r = 0; r < dbr.length; r++)
557 if (id != null && dbr[r].getAccessionId().equals(id))
559 // suppress duplicate link creation for the bare sequence ID
560 // string with this link
563 // create Bare ID link for this RUL
564 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
568 for (int u = 0; u < urls.length; u += 2)
570 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
572 linkset.addElement(urls[u] + "|" + urls[u + 1]);
573 addshowLink(linkMenu, label + "|" + urls[u],
582 // create Bare ID link for this RUL
583 String[] urls = urlLink.makeUrls(id, true);
586 for (int u = 0; u < urls.length; u += 2)
588 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
590 linkset.addElement(urls[u] + "|" + urls[u + 1]);
591 addshowLink(linkMenu, label, urls[u + 1]);
596 // Create urls from description but only for URL links which are regex
598 if (descr != null && urlLink.getRegexReplace() != null)
600 // create link for this URL from description where regex matches
601 String[] urls = urlLink.makeUrls(descr, true);
604 for (int u = 0; u < urls.length; u += 2)
606 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
608 linkset.addElement(urls[u] + "|" + urls[u + 1]);
609 addshowLink(linkMenu, label, urls[u + 1]);
617 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
619 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
620 // Add a non-dynamic link
621 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
625 if (sequence != null)
627 sequenceMenu.add(linkMenu);
636 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
639 // TODO: usability: thread off the generation of group url content so root
641 // sequence only URLs
642 // ID/regex match URLs
643 groupLinksMenu = new JMenu("Group Link");
644 JMenu[] linkMenus = new JMenu[]
645 { null, new JMenu("IDS"), new JMenu("Sequences"),
646 new JMenu("IDS and Sequences") }; // three types of url that might be
648 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
649 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
650 Hashtable commonDbrefs = new Hashtable();
651 for (int sq = 0; sq < seqs.length; sq++)
654 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
655 .findPosition(sg.getEndRes());
656 // just collect ids from dataset sequence
657 // TODO: check if IDs collected from selecton group intersects with the
658 // current selection, too
659 SequenceI sqi = seqs[sq];
660 while (sqi.getDatasetSequence() != null)
662 sqi = sqi.getDatasetSequence();
664 DBRefEntry[] dbr = sqi.getDBRef();
665 if (dbr != null && dbr.length > 0)
667 for (int d = 0; d < dbr.length; d++)
669 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
670 Object[] sarray = (Object[]) commonDbrefs.get(src);
673 sarray = new Object[2];
674 sarray[0] = new int[]
676 sarray[1] = new String[seqs.length];
678 commonDbrefs.put(src, sarray);
681 if (((String[]) sarray[1])[sq] == null)
684 || (dbr[d].getMap().locateMappedRange(start, end) != null))
686 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
687 ((int[]) sarray[0])[0]++;
693 // now create group links for all distinct ID/sequence sets.
694 boolean addMenu = false; // indicates if there are any group links to give
696 for (int i = 0; i < groupLinks.size(); i++)
698 String link = groupLinks.elementAt(i).toString();
699 GroupUrlLink urlLink = null;
702 urlLink = new GroupUrlLink(link);
703 } catch (Exception foo)
705 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
710 if (!urlLink.isValid())
712 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
715 final String label = urlLink.getLabel();
716 boolean usingNames = false;
717 // Now see which parts of the group apply for this URL
718 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
719 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
720 String[] seqstr, ids; // input to makeUrl
723 int numinput = ((int[]) idset[0])[0];
724 String[] allids = ((String[]) idset[1]);
725 seqstr = new String[numinput];
726 ids = new String[numinput];
727 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
729 if (allids[sq] != null)
731 ids[idcount] = allids[sq];
732 seqstr[idcount++] = idandseqs[1][sq];
738 // just use the id/seq set
739 seqstr = idandseqs[1];
743 // and try and make the groupURL!
745 Object[] urlset = null;
748 urlset = urlLink.makeUrlStubs(ids, seqstr, "FromJalview"
749 + System.currentTimeMillis(), false);
750 } catch (UrlStringTooLongException e)
755 int type = urlLink.getGroupURLType() & 3;
756 // System.out.println(urlLink.getGroupURLType()
757 // +" "+((String[])urlset[3])[0]);
758 // first two bits ofurlLink type bitfield are sequenceids and sequences
759 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
760 addshowLink(linkMenus[type], label
761 + (((type & 1) == 1) ? ("("
762 + (usingNames ? "Names" : ltarget) + ")") : ""),
769 groupLinksMenu = new JMenu("Group Links");
770 for (int m = 0; m < linkMenus.length; m++)
772 if (linkMenus[m] != null
773 && linkMenus[m].getMenuComponentCount() > 0)
775 groupLinksMenu.add(linkMenus[m]);
779 groupMenu.add(groupLinksMenu);
784 * add a show URL menu item to the given linkMenu
788 * - menu label string
792 private void addshowLink(JMenu linkMenu, String label, final String url)
794 JMenuItem item = new JMenuItem(label);
795 item.setToolTipText("open URL: " + url);
796 item.addActionListener(new java.awt.event.ActionListener()
798 public void actionPerformed(ActionEvent e)
800 new Thread(new Runnable()
816 * add a late bound groupURL item to the given linkMenu
820 * - menu label string
821 * @param urlgenerator
822 * GroupURLLink used to generate URL
824 * Object array returned from the makeUrlStubs function.
826 private void addshowLink(JMenu linkMenu, String label,
827 final GroupUrlLink urlgenerator, final Object[] urlstub)
829 JMenuItem item = new JMenuItem(label);
830 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
831 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
840 item.addActionListener(new java.awt.event.ActionListener()
842 public void actionPerformed(ActionEvent e)
844 new Thread(new Runnable()
851 showLink(urlgenerator.constructFrom(urlstub));
852 } catch (UrlStringTooLongException e)
870 private void jbInit() throws Exception
872 groupMenu.setText("Group");
873 groupMenu.setText("Selection");
874 groupName.setText("Name");
875 groupName.addActionListener(new java.awt.event.ActionListener()
877 public void actionPerformed(ActionEvent e)
879 groupName_actionPerformed();
882 sequenceMenu.setText("Sequence");
883 sequenceName.setText("Edit Name/Description");
884 sequenceName.addActionListener(new java.awt.event.ActionListener()
886 public void actionPerformed(ActionEvent e)
888 sequenceName_actionPerformed();
891 PIDColour.setFocusPainted(false);
892 unGroupMenuItem.setText("Remove Group");
893 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
895 public void actionPerformed(ActionEvent e)
897 unGroupMenuItem_actionPerformed();
901 outline.setText("Border colour");
902 outline.addActionListener(new java.awt.event.ActionListener()
904 public void actionPerformed(ActionEvent e)
906 outline_actionPerformed();
909 nucleotideMenuItem.setText("Nucleotide");
910 nucleotideMenuItem.addActionListener(new ActionListener()
912 public void actionPerformed(ActionEvent e)
914 nucleotideMenuItem_actionPerformed();
917 colourMenu.setText("Group Colour");
918 showBoxes.setText("Boxes");
919 showBoxes.setState(true);
920 showBoxes.addActionListener(new ActionListener()
922 public void actionPerformed(ActionEvent e)
924 showBoxes_actionPerformed();
927 showText.setText("Text");
928 showText.setState(true);
929 showText.addActionListener(new ActionListener()
931 public void actionPerformed(ActionEvent e)
933 showText_actionPerformed();
936 showColourText.setText("Colour Text");
937 showColourText.addActionListener(new ActionListener()
939 public void actionPerformed(ActionEvent e)
941 showColourText_actionPerformed();
944 displayNonconserved.setText("Show Nonconserved");
945 displayNonconserved.setState(true);
946 displayNonconserved.addActionListener(new ActionListener()
948 public void actionPerformed(ActionEvent e)
950 showNonconserved_actionPerformed();
953 editMenu.setText("Edit");
955 cut.addActionListener(new ActionListener()
957 public void actionPerformed(ActionEvent e)
959 cut_actionPerformed();
962 upperCase.setText("To Upper Case");
963 upperCase.addActionListener(new ActionListener()
965 public void actionPerformed(ActionEvent e)
970 copy.setText("Copy");
971 copy.addActionListener(new ActionListener()
973 public void actionPerformed(ActionEvent e)
975 copy_actionPerformed();
978 lowerCase.setText("To Lower Case");
979 lowerCase.addActionListener(new ActionListener()
981 public void actionPerformed(ActionEvent e)
986 toggle.setText("Toggle Case");
987 toggle.addActionListener(new ActionListener()
989 public void actionPerformed(ActionEvent e)
994 pdbMenu.setText("Associate Structure with Sequence");
995 pdbFromFile.setText("From File");
996 pdbFromFile.addActionListener(new ActionListener()
998 public void actionPerformed(ActionEvent e)
1000 pdbFromFile_actionPerformed();
1003 enterPDB.setText("Enter PDB Id");
1004 enterPDB.addActionListener(new ActionListener()
1006 public void actionPerformed(ActionEvent e)
1008 enterPDB_actionPerformed();
1011 discoverPDB.setText("Discover PDB ids");
1012 discoverPDB.addActionListener(new ActionListener()
1014 public void actionPerformed(ActionEvent e)
1016 discoverPDB_actionPerformed();
1019 outputMenu.setText("Output to Textbox...");
1020 sequenceFeature.setText("Create Sequence Feature");
1021 sequenceFeature.addActionListener(new ActionListener()
1023 public void actionPerformed(ActionEvent e)
1025 sequenceFeature_actionPerformed();
1028 textColour.setText("Text Colour");
1029 textColour.addActionListener(new ActionListener()
1031 public void actionPerformed(ActionEvent e)
1033 textColour_actionPerformed();
1036 jMenu1.setText("Group");
1037 structureMenu.setText("Structure");
1038 viewStructureMenu.setText("View Structure");
1039 // colStructureMenu.setText("Colour By Structure");
1040 editSequence.setText("Edit Sequence...");
1041 editSequence.addActionListener(new ActionListener()
1043 public void actionPerformed(ActionEvent actionEvent)
1045 editSequence_actionPerformed(actionEvent);
1049 * annotationMenuItem.setText("By Annotation");
1050 * annotationMenuItem.addActionListener(new ActionListener() { public void
1051 * actionPerformed(ActionEvent actionEvent) {
1052 * annotationMenuItem_actionPerformed(actionEvent); } });
1058 this.add(structureMenu);
1059 groupMenu.add(editMenu);
1060 groupMenu.add(outputMenu);
1061 groupMenu.add(sequenceFeature);
1062 groupMenu.add(jMenu1);
1063 sequenceMenu.add(sequenceName);
1064 colourMenu.add(textColour);
1065 colourMenu.add(noColourmenuItem);
1066 colourMenu.add(clustalColour);
1067 colourMenu.add(BLOSUM62Colour);
1068 colourMenu.add(PIDColour);
1069 colourMenu.add(zappoColour);
1070 colourMenu.add(taylorColour);
1071 colourMenu.add(hydrophobicityColour);
1072 colourMenu.add(helixColour);
1073 colourMenu.add(strandColour);
1074 colourMenu.add(turnColour);
1075 colourMenu.add(buriedColour);
1076 colourMenu.add(nucleotideMenuItem);
1077 colourMenu.add(purinePyrimidineColour);
1078 // colourMenu.add(covariationColour);
1079 colourMenu.add(userDefinedColour);
1081 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1083 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1084 .getUserColourSchemes().keys();
1086 while (userColours.hasMoreElements())
1088 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1089 item.addActionListener(new ActionListener()
1091 public void actionPerformed(ActionEvent evt)
1093 userDefinedColour_actionPerformed(evt);
1096 colourMenu.add(item);
1100 colourMenu.addSeparator();
1101 colourMenu.add(abovePIDColour);
1102 colourMenu.add(conservationMenuItem);
1103 // colourMenu.add(annotationMenuItem);
1106 editMenu.add(editSequence);
1107 editMenu.add(upperCase);
1108 editMenu.add(lowerCase);
1109 editMenu.add(toggle);
1110 pdbMenu.add(pdbFromFile);
1111 pdbMenu.add(enterPDB);
1112 pdbMenu.add(discoverPDB);
1113 jMenu1.add(groupName);
1114 jMenu1.add(unGroupMenuItem);
1115 jMenu1.add(colourMenu);
1116 jMenu1.add(showBoxes);
1117 jMenu1.add(showText);
1118 jMenu1.add(showColourText);
1119 jMenu1.add(outline);
1120 jMenu1.add(displayNonconserved);
1121 structureMenu.add(pdbMenu);
1122 structureMenu.add(viewStructureMenu);
1123 // structureMenu.add(colStructureMenu);
1124 noColourmenuItem.setText("None");
1125 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1127 public void actionPerformed(ActionEvent e)
1129 noColourmenuItem_actionPerformed();
1133 clustalColour.setText("Clustalx colours");
1134 clustalColour.addActionListener(new java.awt.event.ActionListener()
1136 public void actionPerformed(ActionEvent e)
1138 clustalColour_actionPerformed();
1141 zappoColour.setText("Zappo");
1142 zappoColour.addActionListener(new java.awt.event.ActionListener()
1144 public void actionPerformed(ActionEvent e)
1146 zappoColour_actionPerformed();
1149 taylorColour.setText("Taylor");
1150 taylorColour.addActionListener(new java.awt.event.ActionListener()
1152 public void actionPerformed(ActionEvent e)
1154 taylorColour_actionPerformed();
1157 hydrophobicityColour.setText("Hydrophobicity");
1158 hydrophobicityColour
1159 .addActionListener(new java.awt.event.ActionListener()
1161 public void actionPerformed(ActionEvent e)
1163 hydrophobicityColour_actionPerformed();
1166 helixColour.setText("Helix propensity");
1167 helixColour.addActionListener(new java.awt.event.ActionListener()
1169 public void actionPerformed(ActionEvent e)
1171 helixColour_actionPerformed();
1174 strandColour.setText("Strand propensity");
1175 strandColour.addActionListener(new java.awt.event.ActionListener()
1177 public void actionPerformed(ActionEvent e)
1179 strandColour_actionPerformed();
1182 turnColour.setText("Turn propensity");
1183 turnColour.addActionListener(new java.awt.event.ActionListener()
1185 public void actionPerformed(ActionEvent e)
1187 turnColour_actionPerformed();
1190 buriedColour.setText("Buried Index");
1191 buriedColour.addActionListener(new java.awt.event.ActionListener()
1193 public void actionPerformed(ActionEvent e)
1195 buriedColour_actionPerformed();
1198 abovePIDColour.setText("Above % Identity");
1199 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1201 public void actionPerformed(ActionEvent e)
1203 abovePIDColour_actionPerformed();
1206 userDefinedColour.setText("User Defined...");
1207 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1209 public void actionPerformed(ActionEvent e)
1211 userDefinedColour_actionPerformed(e);
1214 PIDColour.setText("Percentage Identity");
1215 PIDColour.addActionListener(new java.awt.event.ActionListener()
1217 public void actionPerformed(ActionEvent e)
1219 PIDColour_actionPerformed();
1222 BLOSUM62Colour.setText("BLOSUM62");
1223 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1225 public void actionPerformed(ActionEvent e)
1227 BLOSUM62Colour_actionPerformed();
1230 purinePyrimidineColour.setText("Purine/Pyrimidine");
1231 purinePyrimidineColour
1232 .addActionListener(new java.awt.event.ActionListener()
1234 public void actionPerformed(ActionEvent e)
1236 purinePyrimidineColour_actionPerformed();
1240 * covariationColour.addActionListener(new java.awt.event.ActionListener() {
1241 * public void actionPerformed(ActionEvent e) {
1242 * covariationColour_actionPerformed(); } });
1245 conservationMenuItem.setText("Conservation");
1246 conservationMenuItem
1247 .addActionListener(new java.awt.event.ActionListener()
1249 public void actionPerformed(ActionEvent e)
1251 conservationMenuItem_actionPerformed();
1256 protected void showNonconserved_actionPerformed()
1258 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1263 * call to refresh view after settings change
1267 ap.updateAnnotation();
1268 ap.paintAlignment(true);
1270 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1279 protected void clustalColour_actionPerformed()
1281 SequenceGroup sg = getGroup();
1282 sg.cs = new ClustalxColourScheme(sg
1283 .getSequences(ap.av.hiddenRepSequences), ap.av.alignment
1294 protected void zappoColour_actionPerformed()
1296 getGroup().cs = new ZappoColourScheme();
1306 protected void taylorColour_actionPerformed()
1308 getGroup().cs = new TaylorColourScheme();
1318 protected void hydrophobicityColour_actionPerformed()
1320 getGroup().cs = new HydrophobicColourScheme();
1330 protected void helixColour_actionPerformed()
1332 getGroup().cs = new HelixColourScheme();
1342 protected void strandColour_actionPerformed()
1344 getGroup().cs = new StrandColourScheme();
1354 protected void turnColour_actionPerformed()
1356 getGroup().cs = new TurnColourScheme();
1366 protected void buriedColour_actionPerformed()
1368 getGroup().cs = new BuriedColourScheme();
1378 public void nucleotideMenuItem_actionPerformed()
1380 getGroup().cs = new NucleotideColourScheme();
1384 protected void purinePyrimidineColour_actionPerformed()
1386 getGroup().cs = new PurinePyrimidineColourScheme();
1391 * protected void covariationColour_actionPerformed() { getGroup().cs = new
1392 * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
1400 protected void abovePIDColour_actionPerformed()
1402 SequenceGroup sg = getGroup();
1408 if (abovePIDColour.isSelected())
1410 sg.cs.setConsensus(AAFrequency.calculate(sg
1411 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1414 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1417 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1419 SliderPanel.showPIDSlider();
1422 // remove PIDColouring
1424 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1436 protected void userDefinedColour_actionPerformed(ActionEvent e)
1438 SequenceGroup sg = getGroup();
1440 if (e.getActionCommand().equals("User Defined..."))
1442 new UserDefinedColours(ap, sg);
1446 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1447 .getUserColourSchemes().get(e.getActionCommand());
1460 protected void PIDColour_actionPerformed()
1462 SequenceGroup sg = getGroup();
1463 sg.cs = new PIDColourScheme();
1464 sg.cs.setConsensus(AAFrequency.calculate(sg
1465 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1476 protected void BLOSUM62Colour_actionPerformed()
1478 SequenceGroup sg = getGroup();
1480 sg.cs = new Blosum62ColourScheme();
1482 sg.cs.setConsensus(AAFrequency.calculate(sg
1483 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1495 protected void noColourmenuItem_actionPerformed()
1497 getGroup().cs = null;
1507 protected void conservationMenuItem_actionPerformed()
1509 SequenceGroup sg = getGroup();
1515 if (conservationMenuItem.isSelected())
1517 Conservation c = new Conservation("Group",
1518 ResidueProperties.propHash, 3, sg
1519 .getSequences(ap.av.hiddenRepSequences), sg
1520 .getStartRes(), sg.getEndRes() + 1);
1523 c.verdict(false, ap.av.ConsPercGaps);
1525 sg.cs.setConservation(c);
1527 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1528 SliderPanel.showConservationSlider();
1531 // remove ConservationColouring
1533 sg.cs.setConservation(null);
1539 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1541 SequenceGroup sg = getGroup();
1547 AnnotationColourGradient acg = new AnnotationColourGradient(sequence
1548 .getAnnotation()[0], null,
1549 AnnotationColourGradient.NO_THRESHOLD);
1551 acg.predefinedColours = true;
1563 protected void groupName_actionPerformed()
1566 SequenceGroup sg = getGroup();
1567 EditNameDialog dialog = new EditNameDialog(sg.getName(), sg
1568 .getDescription(), " Group Name ", "Group Description ",
1569 "Edit Group Name/Description", ap.alignFrame);
1576 sg.setName(dialog.getName());
1577 sg.setDescription(dialog.getDescription());
1582 * Get selection group - adding it to the alignment if necessary.
1584 * @return sequence group to operate on
1586 SequenceGroup getGroup()
1588 SequenceGroup sg = ap.av.getSelectionGroup();
1589 // this method won't add a new group if it already exists
1592 ap.av.alignment.addGroup(sg);
1604 void sequenceName_actionPerformed()
1606 EditNameDialog dialog = new EditNameDialog(sequence.getName(), sequence
1607 .getDescription(), " Sequence Name ",
1608 "Sequence Description ", "Edit Sequence Name/Description",
1616 if (dialog.getName() != null)
1618 if (dialog.getName().indexOf(" ") > -1)
1620 JOptionPane.showMessageDialog(ap,
1621 "Spaces have been converted to \"_\"",
1622 "No spaces allowed in Sequence Name",
1623 JOptionPane.WARNING_MESSAGE);
1626 sequence.setName(dialog.getName().replace(' ', '_'));
1627 ap.paintAlignment(false);
1630 sequence.setDescription(dialog.getDescription());
1632 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1643 void unGroupMenuItem_actionPerformed()
1645 SequenceGroup sg = ap.av.getSelectionGroup();
1646 ap.av.alignment.deleteGroup(sg);
1647 ap.av.setSelectionGroup(null);
1657 protected void outline_actionPerformed()
1659 SequenceGroup sg = getGroup();
1660 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1665 sg.setOutlineColour(col);
1677 public void showBoxes_actionPerformed()
1679 getGroup().setDisplayBoxes(showBoxes.isSelected());
1689 public void showText_actionPerformed()
1691 getGroup().setDisplayText(showText.isSelected());
1701 public void showColourText_actionPerformed()
1703 getGroup().setColourText(showColourText.isSelected());
1707 public void showLink(String url)
1711 jalview.util.BrowserLauncher.openURL(url);
1712 } catch (Exception ex)
1715 .showInternalMessageDialog(
1717 "Unixers: Couldn't find default web browser."
1718 + "\nAdd the full path to your browser in Preferences.",
1719 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1721 ex.printStackTrace();
1725 void hideSequences(boolean representGroup)
1727 SequenceGroup sg = ap.av.getSelectionGroup();
1728 if (sg == null || sg.getSize() < 1)
1730 ap.av.hideSequence(new SequenceI[]
1735 ap.av.setSelectionGroup(null);
1739 ap.av.hideRepSequences(sequence, sg);
1744 int gsize = sg.getSize();
1747 hseqs = new SequenceI[gsize];
1750 for (int i = 0; i < gsize; i++)
1752 hseqs[index++] = sg.getSequenceAt(i);
1755 ap.av.hideSequence(hseqs);
1756 // refresh(); TODO: ? needed ?
1757 ap.av.sendSelection();
1760 public void copy_actionPerformed()
1762 ap.alignFrame.copy_actionPerformed(null);
1765 public void cut_actionPerformed()
1767 ap.alignFrame.cut_actionPerformed(null);
1770 void changeCase(ActionEvent e)
1772 Object source = e.getSource();
1773 SequenceGroup sg = ap.av.getSelectionGroup();
1777 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1778 sg.getEndRes() + 1);
1783 if (source == toggle)
1785 description = "Toggle Case";
1786 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1788 else if (source == upperCase)
1790 description = "To Upper Case";
1791 caseChange = ChangeCaseCommand.TO_UPPER;
1795 description = "To Lower Case";
1796 caseChange = ChangeCaseCommand.TO_LOWER;
1799 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description, sg
1800 .getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1803 ap.alignFrame.addHistoryItem(caseCommand);
1805 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1811 public void outputText_actionPerformed(ActionEvent e)
1813 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1814 cap.setForInput(null);
1815 Desktop.addInternalFrame(cap, "Alignment output - "
1816 + e.getActionCommand(), 600, 500);
1818 String[] omitHidden = null;
1820 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1821 // or we simply trust the user wants
1822 // wysiwig behaviour
1823 SequenceGroup sg = ap.av.getSelectionGroup();
1824 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1825 omitHidden = ap.av.getViewAsString(true);
1826 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1827 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1830 for (int i = 0; i < nala.length; i++)
1832 AlignmentAnnotation na = nala[i];
1833 oal.addAnnotation(na);
1836 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1837 oal, omitHidden, csel, sg));
1841 public void pdbFromFile_actionPerformed()
1843 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1844 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1845 chooser.setFileView(new jalview.io.JalviewFileView());
1846 chooser.setDialogTitle("Select a PDB file for "
1847 + sequence.getDisplayId(false));
1849 .setToolTipText("Load a PDB file and associate it with sequence '"
1850 + sequence.getDisplayId(false) + "'");
1852 int value = chooser.showOpenDialog(null);
1854 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1856 String choice = chooser.getSelectedFile().getPath();
1857 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1858 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
1859 jalview.io.AppletFormatAdapter.FILE, sequence, true);
1864 public void enterPDB_actionPerformed()
1866 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1867 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1869 if (id != null && id.length() > 0)
1871 PDBEntry entry = new PDBEntry();
1872 entry.setId(id.toUpperCase());
1873 sequence.getDatasetSequence().addPDBId(entry);
1877 public void discoverPDB_actionPerformed()
1880 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1882 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1883 Thread discpdb = new Thread(new Runnable()
1888 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1889 .fetchDBRefs(false);
1896 public void sequenceFeature_actionPerformed()
1898 SequenceGroup sg = ap.av.getSelectionGroup();
1904 int rsize = 0, gSize = sg.getSize();
1905 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1906 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1908 for (int i = 0; i < gSize; i++)
1910 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1911 int end = sg.findEndRes(sg.getSequenceAt(i));
1914 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1915 features[rsize] = new SequenceFeature(null, null, null, start, end,
1920 rseqs = new SequenceI[rsize];
1921 tfeatures = new SequenceFeature[rsize];
1922 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1923 System.arraycopy(features, 0, tfeatures, 0, rsize);
1924 features = tfeatures;
1926 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1927 features, true, ap))
1929 ap.alignFrame.setShowSeqFeatures(true);
1930 ap.highlightSearchResults(null);
1934 public void textColour_actionPerformed()
1936 SequenceGroup sg = getGroup();
1939 new TextColourChooser().chooseColour(ap, sg);
1943 public void colourByStructure(String pdbid)
1945 Annotation[] anots = ap.av.getStructureSelectionManager()
1946 .colourSequenceFromStructure(sequence, pdbid);
1948 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1949 "Coloured by " + pdbid, anots);
1951 ap.av.alignment.addAnnotation(an);
1952 an.createSequenceMapping(sequence, 0, true);
1953 // an.adjustForAlignment();
1954 ap.av.alignment.setAnnotationIndex(an, 0);
1956 ap.adjustAnnotationHeight();
1958 sequence.addAlignmentAnnotation(an);
1962 public void editSequence_actionPerformed(ActionEvent actionEvent)
1964 SequenceGroup sg = ap.av.getSelectionGroup();
1968 if (sequence == null)
1969 sequence = (Sequence) sg.getSequenceAt(0);
1971 EditNameDialog dialog = new EditNameDialog(sequence
1972 .getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
1973 null, "Edit Sequence ", null, "Edit Sequence", ap.alignFrame);
1977 EditCommand editCommand = new EditCommand("Edit Sequences",
1978 EditCommand.REPLACE, dialog.getName().replace(' ',
1979 ap.av.getGapCharacter()), sg
1980 .getSequencesAsArray(ap.av.hiddenRepSequences), sg
1981 .getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1983 ap.alignFrame.addHistoryItem(editCommand);
1985 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()