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 JRadioButtonMenuItem();
77 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
79 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
83 JMenu sequenceMenu = new JMenu();
85 JMenuItem sequenceName = new JMenuItem();
89 JMenuItem unGroupMenuItem = new JMenuItem();
91 JMenuItem outline = new JMenuItem();
93 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
95 JMenu colourMenu = new JMenu();
97 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
99 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
101 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
103 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
105 JMenu editMenu = new JMenu();
107 JMenuItem cut = new JMenuItem();
109 JMenuItem copy = new JMenuItem();
111 JMenuItem upperCase = new JMenuItem();
113 JMenuItem lowerCase = new JMenuItem();
115 JMenuItem toggle = new JMenuItem();
117 JMenu pdbMenu = new JMenu();
119 JMenuItem pdbFromFile = new JMenuItem();
121 JMenuItem enterPDB = new JMenuItem();
123 JMenuItem discoverPDB = new JMenuItem();
125 JMenu outputMenu = new JMenu();
127 JMenuItem sequenceFeature = new JMenuItem();
129 JMenuItem textColour = new JMenuItem();
131 JMenu jMenu1 = new JMenu();
133 JMenu structureMenu = new JMenu();
135 JMenu viewStructureMenu = new JMenu();
137 // JMenu colStructureMenu = new JMenu();
138 JMenuItem editSequence = new JMenuItem();
140 // JMenuItem annotationMenuItem = new JMenuItem();
142 JMenu groupLinksMenu;
145 * Creates a new PopupMenu object.
152 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
154 this(ap, seq, links, null);
164 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links,
167 // /////////////////////////////////////////////////////////
168 // If this is activated from the sequence panel, the user may want to
169 // edit or annotate a particular residue. Therefore display the residue menu
171 // If from the IDPanel, we must display the sequence menu
172 // ////////////////////////////////////////////////////////
176 ButtonGroup colours = new ButtonGroup();
177 colours.add(noColourmenuItem);
178 colours.add(clustalColour);
179 colours.add(zappoColour);
180 colours.add(taylorColour);
181 colours.add(hydrophobicityColour);
182 colours.add(helixColour);
183 colours.add(strandColour);
184 colours.add(turnColour);
185 colours.add(buriedColour);
186 colours.add(abovePIDColour);
187 colours.add(userDefinedColour);
188 colours.add(PIDColour);
189 colours.add(BLOSUM62Colour);
190 colours.add(purinePyrimidineColour);
191 //colours.add(covariationColour);
193 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
195 JMenuItem item = new JMenuItem(
196 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
198 item.addActionListener(new java.awt.event.ActionListener()
200 public void actionPerformed(ActionEvent e)
202 outputText_actionPerformed(e);
206 outputMenu.add(item);
212 } catch (Exception e)
219 sequenceMenu.setText(sequence.getName());
222 if (seq.getDatasetSequence().getPDBId() != null
223 && seq.getDatasetSequence().getPDBId().size() > 0)
225 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
228 while (e.hasMoreElements())
230 final PDBEntry pdb = (PDBEntry) e.nextElement();
232 menuItem = new JMenuItem();
233 menuItem.setText(pdb.getId());
234 menuItem.addActionListener(new java.awt.event.ActionListener()
236 public void actionPerformed(ActionEvent e)
238 // TODO re JAL-860: optionally open dialog or provide a menu entry allowing user to open just one structure per sequence
239 new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[] { pdb })[0], null, ap);
240 // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
244 viewStructureMenu.add(menuItem);
247 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
248 * menuItem.addActionListener(new java.awt.event.ActionListener() {
249 * public void actionPerformed(ActionEvent e) {
250 * colourByStructure(pdb.getId()); } });
251 * colStructureMenu.add(menuItem);
257 //TODO: Something to check if it's an RNA
258 //like: if(seq.getAnnotation()[0].annotations[0].secondaryStructure == 'S')
259 menuItem = new JMenuItem();
260 menuItem.setText("RNA structure");
261 menuItem.addActionListener(new java.awt.event.ActionListener()
263 public void actionPerformed(ActionEvent e)
265 System.out.println("Call Varna");
270 viewStructureMenu.add(menuItem);
272 //JAN structureMenu.remove(viewStructureMenu);
273 // structureMenu.remove(colStructureMenu);
276 menuItem = new JMenuItem("Hide Sequences");
277 menuItem.addActionListener(new java.awt.event.ActionListener()
279 public void actionPerformed(ActionEvent e)
281 hideSequences(false);
286 if (ap.av.getSelectionGroup() != null
287 && ap.av.getSelectionGroup().getSize() > 1)
289 menuItem = new JMenuItem("Represent Group with " + seq.getName());
290 menuItem.addActionListener(new java.awt.event.ActionListener()
292 public void actionPerformed(ActionEvent e)
297 sequenceMenu.add(menuItem);
300 if (ap.av.hasHiddenRows)
302 final int index = ap.av.alignment.findIndex(seq);
304 if (ap.av.adjustForHiddenSeqs(index)
305 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
307 menuItem = new JMenuItem("Reveal Sequences");
308 menuItem.addActionListener(new ActionListener()
310 public void actionPerformed(ActionEvent e)
312 ap.av.showSequence(index);
313 if (ap.overviewPanel != null)
315 ap.overviewPanel.updateOverviewImage();
322 menuItem = new JMenuItem("Reveal All");
323 menuItem.addActionListener(new ActionListener()
325 public void actionPerformed(ActionEvent e)
327 ap.av.showAllHiddenSeqs();
328 if (ap.overviewPanel != null)
330 ap.overviewPanel.updateOverviewImage();
340 SequenceGroup sg = ap.av.getSelectionGroup();
344 groupName.setText("Name: "+sg.getName());
345 groupName.setText("Edit name and description of current group.");
347 if (sg.cs instanceof ZappoColourScheme)
349 zappoColour.setSelected(true);
351 else if (sg.cs instanceof TaylorColourScheme)
353 taylorColour.setSelected(true);
355 else if (sg.cs instanceof PIDColourScheme)
357 PIDColour.setSelected(true);
359 else if (sg.cs instanceof Blosum62ColourScheme)
361 BLOSUM62Colour.setSelected(true);
363 else if (sg.cs instanceof UserColourScheme)
365 userDefinedColour.setSelected(true);
367 else if (sg.cs instanceof HydrophobicColourScheme)
369 hydrophobicityColour.setSelected(true);
371 else if (sg.cs instanceof HelixColourScheme)
373 helixColour.setSelected(true);
375 else if (sg.cs instanceof StrandColourScheme)
377 strandColour.setSelected(true);
379 else if (sg.cs instanceof TurnColourScheme)
381 turnColour.setSelected(true);
383 else if (sg.cs instanceof BuriedColourScheme)
385 buriedColour.setSelected(true);
387 else if (sg.cs instanceof ClustalxColourScheme)
389 clustalColour.setSelected(true);
391 else if (sg.cs instanceof PurinePyrimidineColourScheme)
393 purinePyrimidineColour.setSelected(true);
395 /* else if (sg.cs instanceof CovariationColourScheme)
397 covariationColour.setSelected(true);
401 noColourmenuItem.setSelected(true);
404 if (sg.cs != null && sg.cs.conservationApplied())
406 conservationMenuItem.setSelected(true);
408 displayNonconserved.setSelected(sg.getShowNonconserved());
409 showText.setSelected(sg.getDisplayText());
410 showColourText.setSelected(sg.getColourText());
411 showBoxes.setSelected(sg.getDisplayBoxes());
412 // add any groupURLs to the groupURL submenu and make it visible
413 if (groupLinks != null && groupLinks.size() > 0)
415 buildGroupURLMenu(sg, groupLinks);
417 // Add a 'show all structures' for the current selection
418 Hashtable<String, PDBEntry> pdbe=new Hashtable<String,PDBEntry>();
419 for (SequenceI sq: ap.av.getSequenceSelection())
421 Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence().getPDBId();
423 for (PDBEntry pe: pes)
425 pdbe.put(pe.getId(), pe);
431 final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]);
432 final JMenuItem gpdbview;
433 structureMenu.add(gpdbview=new JMenuItem("View "+pdbe.size()+" structures."));
434 gpdbview.setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment.");
435 gpdbview.addActionListener(new ActionListener()
439 public void actionPerformed(ActionEvent e)
441 new AppJmol(ap, pe, ap.av.collateForPDB(pe));
448 groupMenu.setVisible(false);
449 editMenu.setVisible(false);
452 if (!ap.av.alignment.getGroups().contains(sg))
454 unGroupMenuItem.setVisible(false);
459 sequenceMenu.setVisible(false);
460 structureMenu.setVisible(false);
463 if (links != null && links.size() > 0)
466 JMenu linkMenu = new JMenu("Link");
467 Vector linkset = new Vector();
468 for (int i = 0; i < links.size(); i++)
470 String link = links.elementAt(i).toString();
471 UrlLink urlLink = null;
474 urlLink = new UrlLink(link);
475 } catch (Exception foo)
477 jalview.bin.Cache.log.error("Exception for URLLink '" + link
482 if (!urlLink.isValid())
484 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
487 final String label = urlLink.getLabel();
488 if (urlLink.isDynamic())
491 // collect matching db-refs
492 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
493 seq.getDBRef(), new String[]
494 { urlLink.getTarget() });
495 // collect id string too
496 String id = seq.getName();
497 String descr = seq.getDescription();
498 if (descr != null && descr.length() < 1)
505 for (int r = 0; r < dbr.length; r++)
507 if (id != null && dbr[r].getAccessionId().equals(id))
509 // suppress duplicate link creation for the bare sequence ID
510 // string with this link
513 // create Bare ID link for this RUL
514 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
518 for (int u = 0; u < urls.length; u += 2)
520 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
522 linkset.addElement(urls[u] + "|" + urls[u + 1]);
523 addshowLink(linkMenu, label + "|" + urls[u],
532 // create Bare ID link for this RUL
533 String[] urls = urlLink.makeUrls(id, true);
536 for (int u = 0; u < urls.length; u += 2)
538 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
540 linkset.addElement(urls[u] + "|" + urls[u + 1]);
541 addshowLink(linkMenu, label, urls[u + 1]);
546 // Create urls from description but only for URL links which are regex
548 if (descr != null && urlLink.getRegexReplace() != null)
550 // create link for this URL from description where regex matches
551 String[] urls = urlLink.makeUrls(descr, true);
554 for (int u = 0; u < urls.length; u += 2)
556 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
558 linkset.addElement(urls[u] + "|" + urls[u + 1]);
559 addshowLink(linkMenu, label, urls[u + 1]);
567 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
569 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
570 // Add a non-dynamic link
571 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
575 if (sequence != null)
577 sequenceMenu.add(linkMenu);
586 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
589 // TODO: usability: thread off the generation of group url content so root
591 // sequence only URLs
592 // ID/regex match URLs
593 groupLinksMenu = new JMenu("Group Link");
594 JMenu[] linkMenus = new JMenu[]
595 { null, new JMenu("IDS"), new JMenu("Sequences"),
596 new JMenu("IDS and Sequences") }; // three types of url that might be
598 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
599 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
600 Hashtable commonDbrefs = new Hashtable();
601 for (int sq = 0; sq < seqs.length; sq++)
604 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
605 .findPosition(sg.getEndRes());
606 // just collect ids from dataset sequence
607 // TODO: check if IDs collected from selecton group intersects with the
608 // current selection, too
609 SequenceI sqi = seqs[sq];
610 while (sqi.getDatasetSequence() != null)
612 sqi = sqi.getDatasetSequence();
614 DBRefEntry[] dbr = sqi.getDBRef();
615 if (dbr != null && dbr.length > 0)
617 for (int d = 0; d < dbr.length; d++)
619 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
620 Object[] sarray = (Object[]) commonDbrefs.get(src);
623 sarray = new Object[2];
624 sarray[0] = new int[]
626 sarray[1] = new String[seqs.length];
628 commonDbrefs.put(src, sarray);
631 if (((String[]) sarray[1])[sq] == null)
634 || (dbr[d].getMap().locateMappedRange(start, end) != null))
636 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
637 ((int[]) sarray[0])[0]++;
643 // now create group links for all distinct ID/sequence sets.
644 boolean addMenu = false; // indicates if there are any group links to give
646 for (int i = 0; i < groupLinks.size(); i++)
648 String link = groupLinks.elementAt(i).toString();
649 GroupUrlLink urlLink = null;
652 urlLink = new GroupUrlLink(link);
653 } catch (Exception foo)
655 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
660 if (!urlLink.isValid())
662 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
665 final String label = urlLink.getLabel();
666 boolean usingNames = false;
667 // Now see which parts of the group apply for this URL
668 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
669 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
670 String[] seqstr, ids; // input to makeUrl
673 int numinput = ((int[]) idset[0])[0];
674 String[] allids = ((String[]) idset[1]);
675 seqstr = new String[numinput];
676 ids = new String[numinput];
677 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
679 if (allids[sq] != null)
681 ids[idcount] = allids[sq];
682 seqstr[idcount++] = idandseqs[1][sq];
688 // just use the id/seq set
689 seqstr = idandseqs[1];
693 // and try and make the groupURL!
695 Object[] urlset = null;
698 urlset = urlLink.makeUrlStubs(ids, seqstr,
699 "FromJalview" + System.currentTimeMillis(), false);
700 } catch (UrlStringTooLongException e)
705 int type = urlLink.getGroupURLType() & 3;
706 // System.out.println(urlLink.getGroupURLType()
707 // +" "+((String[])urlset[3])[0]);
708 // first two bits ofurlLink type bitfield are sequenceids and sequences
709 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
710 addshowLink(linkMenus[type], label
711 + (((type & 1) == 1) ? ("("
712 + (usingNames ? "Names" : ltarget) + ")") : ""),
719 groupLinksMenu = new JMenu("Group Links");
720 for (int m = 0; m < linkMenus.length; m++)
722 if (linkMenus[m] != null
723 && linkMenus[m].getMenuComponentCount() > 0)
725 groupLinksMenu.add(linkMenus[m]);
729 groupMenu.add(groupLinksMenu);
734 * add a show URL menu item to the given linkMenu
738 * - menu label string
742 private void addshowLink(JMenu linkMenu, String label, final String url)
744 JMenuItem item = new JMenuItem(label);
745 item.setToolTipText("open URL: " + url);
746 item.addActionListener(new java.awt.event.ActionListener()
748 public void actionPerformed(ActionEvent e)
750 new Thread(new Runnable()
766 * add a late bound groupURL item to the given linkMenu
770 * - menu label string
771 * @param urlgenerator
772 * GroupURLLink used to generate URL
774 * Object array returned from the makeUrlStubs function.
776 private void addshowLink(JMenu linkMenu, String label,
777 final GroupUrlLink urlgenerator, final Object[] urlstub)
779 JMenuItem item = new JMenuItem(label);
780 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
781 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
790 item.addActionListener(new java.awt.event.ActionListener()
792 public void actionPerformed(ActionEvent e)
794 new Thread(new Runnable()
801 showLink(urlgenerator.constructFrom(urlstub));
802 } catch (UrlStringTooLongException e)
820 private void jbInit() throws Exception
822 groupMenu.setText("Group");
823 groupMenu.setText("Selection");
824 groupName.setText("Name");
825 groupName.addActionListener(new java.awt.event.ActionListener()
827 public void actionPerformed(ActionEvent e)
829 groupName_actionPerformed();
832 sequenceMenu.setText("Sequence");
833 sequenceName.setText("Edit Name/Description");
834 sequenceName.addActionListener(new java.awt.event.ActionListener()
836 public void actionPerformed(ActionEvent e)
838 sequenceName_actionPerformed();
841 PIDColour.setFocusPainted(false);
842 unGroupMenuItem.setText("Remove Group");
843 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
845 public void actionPerformed(ActionEvent e)
847 unGroupMenuItem_actionPerformed();
851 outline.setText("Border colour");
852 outline.addActionListener(new java.awt.event.ActionListener()
854 public void actionPerformed(ActionEvent e)
856 outline_actionPerformed();
859 nucleotideMenuItem.setText("Nucleotide");
860 nucleotideMenuItem.addActionListener(new ActionListener()
862 public void actionPerformed(ActionEvent e)
864 nucleotideMenuItem_actionPerformed();
867 colourMenu.setText("Group Colour");
868 showBoxes.setText("Boxes");
869 showBoxes.setState(true);
870 showBoxes.addActionListener(new ActionListener()
872 public void actionPerformed(ActionEvent e)
874 showBoxes_actionPerformed();
877 showText.setText("Text");
878 showText.setState(true);
879 showText.addActionListener(new ActionListener()
881 public void actionPerformed(ActionEvent e)
883 showText_actionPerformed();
886 showColourText.setText("Colour Text");
887 showColourText.addActionListener(new ActionListener()
889 public void actionPerformed(ActionEvent e)
891 showColourText_actionPerformed();
894 displayNonconserved.setText("Show Nonconserved");
895 displayNonconserved.setState(true);
896 displayNonconserved.addActionListener(new ActionListener()
898 public void actionPerformed(ActionEvent e)
900 showNonconserved_actionPerformed();
903 editMenu.setText("Edit");
905 cut.addActionListener(new ActionListener()
907 public void actionPerformed(ActionEvent e)
909 cut_actionPerformed();
912 upperCase.setText("To Upper Case");
913 upperCase.addActionListener(new ActionListener()
915 public void actionPerformed(ActionEvent e)
920 copy.setText("Copy");
921 copy.addActionListener(new ActionListener()
923 public void actionPerformed(ActionEvent e)
925 copy_actionPerformed();
928 lowerCase.setText("To Lower Case");
929 lowerCase.addActionListener(new ActionListener()
931 public void actionPerformed(ActionEvent e)
936 toggle.setText("Toggle Case");
937 toggle.addActionListener(new ActionListener()
939 public void actionPerformed(ActionEvent e)
944 pdbMenu.setText("Associate Structure with Sequence");
945 pdbFromFile.setText("From File");
946 pdbFromFile.addActionListener(new ActionListener()
948 public void actionPerformed(ActionEvent e)
950 pdbFromFile_actionPerformed();
953 enterPDB.setText("Enter PDB Id");
954 enterPDB.addActionListener(new ActionListener()
956 public void actionPerformed(ActionEvent e)
958 enterPDB_actionPerformed();
961 discoverPDB.setText("Discover PDB ids");
962 discoverPDB.addActionListener(new ActionListener()
964 public void actionPerformed(ActionEvent e)
966 discoverPDB_actionPerformed();
969 outputMenu.setText("Output to Textbox...");
970 sequenceFeature.setText("Create Sequence Feature");
971 sequenceFeature.addActionListener(new ActionListener()
973 public void actionPerformed(ActionEvent e)
975 sequenceFeature_actionPerformed();
978 textColour.setText("Text Colour");
979 textColour.addActionListener(new ActionListener()
981 public void actionPerformed(ActionEvent e)
983 textColour_actionPerformed();
986 jMenu1.setText("Group");
987 structureMenu.setText("Structure");
988 viewStructureMenu.setText("View Structure");
989 // colStructureMenu.setText("Colour By Structure");
990 editSequence.setText("Edit Sequence...");
991 editSequence.addActionListener(new ActionListener()
993 public void actionPerformed(ActionEvent actionEvent)
995 editSequence_actionPerformed(actionEvent);
999 * annotationMenuItem.setText("By Annotation");
1000 * annotationMenuItem.addActionListener(new ActionListener() { public void
1001 * actionPerformed(ActionEvent actionEvent) {
1002 * annotationMenuItem_actionPerformed(actionEvent); } });
1008 this.add(structureMenu);
1009 groupMenu.add(editMenu);
1010 groupMenu.add(outputMenu);
1011 groupMenu.add(sequenceFeature);
1012 groupMenu.add(jMenu1);
1013 sequenceMenu.add(sequenceName);
1014 colourMenu.add(textColour);
1015 colourMenu.add(noColourmenuItem);
1016 colourMenu.add(clustalColour);
1017 colourMenu.add(BLOSUM62Colour);
1018 colourMenu.add(PIDColour);
1019 colourMenu.add(zappoColour);
1020 colourMenu.add(taylorColour);
1021 colourMenu.add(hydrophobicityColour);
1022 colourMenu.add(helixColour);
1023 colourMenu.add(strandColour);
1024 colourMenu.add(turnColour);
1025 colourMenu.add(buriedColour);
1026 colourMenu.add(nucleotideMenuItem);
1027 colourMenu.add(purinePyrimidineColour);
1028 //colourMenu.add(covariationColour);
1029 colourMenu.add(userDefinedColour);
1031 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1033 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1034 .getUserColourSchemes().keys();
1036 while (userColours.hasMoreElements())
1038 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1039 item.addActionListener(new ActionListener()
1041 public void actionPerformed(ActionEvent evt)
1043 userDefinedColour_actionPerformed(evt);
1046 colourMenu.add(item);
1050 colourMenu.addSeparator();
1051 colourMenu.add(abovePIDColour);
1052 colourMenu.add(conservationMenuItem);
1053 // colourMenu.add(annotationMenuItem);
1056 editMenu.add(editSequence);
1057 editMenu.add(upperCase);
1058 editMenu.add(lowerCase);
1059 editMenu.add(toggle);
1060 pdbMenu.add(pdbFromFile);
1061 pdbMenu.add(enterPDB);
1062 pdbMenu.add(discoverPDB);
1063 jMenu1.add(groupName);
1064 jMenu1.add(unGroupMenuItem);
1065 jMenu1.add(colourMenu);
1066 jMenu1.add(showBoxes);
1067 jMenu1.add(showText);
1068 jMenu1.add(showColourText);
1069 jMenu1.add(outline);
1070 jMenu1.add(displayNonconserved);
1071 structureMenu.add(pdbMenu);
1072 structureMenu.add(viewStructureMenu);
1073 // structureMenu.add(colStructureMenu);
1074 noColourmenuItem.setText("None");
1075 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1077 public void actionPerformed(ActionEvent e)
1079 noColourmenuItem_actionPerformed();
1083 clustalColour.setText("Clustalx colours");
1084 clustalColour.addActionListener(new java.awt.event.ActionListener()
1086 public void actionPerformed(ActionEvent e)
1088 clustalColour_actionPerformed();
1091 zappoColour.setText("Zappo");
1092 zappoColour.addActionListener(new java.awt.event.ActionListener()
1094 public void actionPerformed(ActionEvent e)
1096 zappoColour_actionPerformed();
1099 taylorColour.setText("Taylor");
1100 taylorColour.addActionListener(new java.awt.event.ActionListener()
1102 public void actionPerformed(ActionEvent e)
1104 taylorColour_actionPerformed();
1107 hydrophobicityColour.setText("Hydrophobicity");
1108 hydrophobicityColour
1109 .addActionListener(new java.awt.event.ActionListener()
1111 public void actionPerformed(ActionEvent e)
1113 hydrophobicityColour_actionPerformed();
1116 helixColour.setText("Helix propensity");
1117 helixColour.addActionListener(new java.awt.event.ActionListener()
1119 public void actionPerformed(ActionEvent e)
1121 helixColour_actionPerformed();
1124 strandColour.setText("Strand propensity");
1125 strandColour.addActionListener(new java.awt.event.ActionListener()
1127 public void actionPerformed(ActionEvent e)
1129 strandColour_actionPerformed();
1132 turnColour.setText("Turn propensity");
1133 turnColour.addActionListener(new java.awt.event.ActionListener()
1135 public void actionPerformed(ActionEvent e)
1137 turnColour_actionPerformed();
1140 buriedColour.setText("Buried Index");
1141 buriedColour.addActionListener(new java.awt.event.ActionListener()
1143 public void actionPerformed(ActionEvent e)
1145 buriedColour_actionPerformed();
1148 abovePIDColour.setText("Above % Identity");
1149 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1151 public void actionPerformed(ActionEvent e)
1153 abovePIDColour_actionPerformed();
1156 userDefinedColour.setText("User Defined...");
1157 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1159 public void actionPerformed(ActionEvent e)
1161 userDefinedColour_actionPerformed(e);
1164 PIDColour.setText("Percentage Identity");
1165 PIDColour.addActionListener(new java.awt.event.ActionListener()
1167 public void actionPerformed(ActionEvent e)
1169 PIDColour_actionPerformed();
1172 BLOSUM62Colour.setText("BLOSUM62");
1173 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1175 public void actionPerformed(ActionEvent e)
1177 BLOSUM62Colour_actionPerformed();
1180 purinePyrimidineColour.setText("Purine/Pyrimidine");
1181 purinePyrimidineColour.addActionListener(new java.awt.event.ActionListener()
1183 public void actionPerformed(ActionEvent e)
1185 purinePyrimidineColour_actionPerformed();
1189 covariationColour.addActionListener(new java.awt.event.ActionListener()
1191 public void actionPerformed(ActionEvent e)
1193 covariationColour_actionPerformed();
1197 conservationMenuItem.setText("Conservation");
1198 conservationMenuItem
1199 .addActionListener(new java.awt.event.ActionListener()
1201 public void actionPerformed(ActionEvent e)
1203 conservationMenuItem_actionPerformed();
1208 protected void showNonconserved_actionPerformed()
1210 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1215 * call to refresh view after settings change
1219 ap.updateAnnotation();
1220 ap.paintAlignment(true);
1222 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1231 protected void clustalColour_actionPerformed()
1233 SequenceGroup sg = getGroup();
1234 sg.cs = new ClustalxColourScheme(
1235 sg.getSequences(ap.av.hiddenRepSequences),
1236 ap.av.alignment.getWidth());
1246 protected void zappoColour_actionPerformed()
1248 getGroup().cs = new ZappoColourScheme();
1258 protected void taylorColour_actionPerformed()
1260 getGroup().cs = new TaylorColourScheme();
1270 protected void hydrophobicityColour_actionPerformed()
1272 getGroup().cs = new HydrophobicColourScheme();
1282 protected void helixColour_actionPerformed()
1284 getGroup().cs = new HelixColourScheme();
1294 protected void strandColour_actionPerformed()
1296 getGroup().cs = new StrandColourScheme();
1306 protected void turnColour_actionPerformed()
1308 getGroup().cs = new TurnColourScheme();
1318 protected void buriedColour_actionPerformed()
1320 getGroup().cs = new BuriedColourScheme();
1330 public void nucleotideMenuItem_actionPerformed()
1332 getGroup().cs = new NucleotideColourScheme();
1336 protected void purinePyrimidineColour_actionPerformed()
1338 getGroup().cs = new PurinePyrimidineColourScheme();
1342 protected void covariationColour_actionPerformed()
1344 getGroup().cs = new CovariationColourScheme(sequence.getAnnotation()[0]);
1354 protected void abovePIDColour_actionPerformed()
1356 SequenceGroup sg = getGroup();
1362 if (abovePIDColour.isSelected())
1364 sg.cs.setConsensus(AAFrequency.calculate(
1365 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1366 sg.getEndRes() + 1));
1368 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1371 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1373 SliderPanel.showPIDSlider();
1376 // remove PIDColouring
1378 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1390 protected void userDefinedColour_actionPerformed(ActionEvent e)
1392 SequenceGroup sg = getGroup();
1394 if (e.getActionCommand().equals("User Defined..."))
1396 new UserDefinedColours(ap, sg);
1400 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1401 .getUserColourSchemes().get(e.getActionCommand());
1414 protected void PIDColour_actionPerformed()
1416 SequenceGroup sg = getGroup();
1417 sg.cs = new PIDColourScheme();
1418 sg.cs.setConsensus(AAFrequency.calculate(
1419 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1420 sg.getEndRes() + 1));
1430 protected void BLOSUM62Colour_actionPerformed()
1432 SequenceGroup sg = getGroup();
1434 sg.cs = new Blosum62ColourScheme();
1436 sg.cs.setConsensus(AAFrequency.calculate(
1437 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1438 sg.getEndRes() + 1));
1449 protected void noColourmenuItem_actionPerformed()
1451 getGroup().cs = null;
1461 protected void conservationMenuItem_actionPerformed()
1463 SequenceGroup sg = getGroup();
1469 if (conservationMenuItem.isSelected())
1471 Conservation c = new Conservation("Group",
1472 ResidueProperties.propHash, 3,
1473 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1474 sg.getEndRes() + 1);
1477 c.verdict(false, ap.av.ConsPercGaps);
1479 sg.cs.setConservation(c);
1481 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1482 SliderPanel.showConservationSlider();
1485 // remove ConservationColouring
1487 sg.cs.setConservation(null);
1493 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1495 SequenceGroup sg = getGroup();
1501 AnnotationColourGradient acg = new AnnotationColourGradient(
1502 sequence.getAnnotation()[0], null,
1503 AnnotationColourGradient.NO_THRESHOLD);
1505 acg.predefinedColours = true;
1517 protected void groupName_actionPerformed()
1520 SequenceGroup sg = getGroup();
1521 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1522 sg.getDescription(), " Group Name ",
1523 "Group Description ", "Edit Group Name/Description",
1531 sg.setName(dialog.getName());
1532 sg.setDescription(dialog.getDescription());
1537 * Get selection group - adding it to the alignment if necessary.
1539 * @return sequence group to operate on
1541 SequenceGroup getGroup()
1543 SequenceGroup sg = ap.av.getSelectionGroup();
1544 // this method won't add a new group if it already exists
1547 ap.av.alignment.addGroup(sg);
1559 void sequenceName_actionPerformed()
1561 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1562 sequence.getDescription(), " Sequence Name ",
1563 "Sequence Description ", "Edit Sequence Name/Description",
1571 if (dialog.getName() != null)
1573 if (dialog.getName().indexOf(" ") > -1)
1575 JOptionPane.showMessageDialog(ap,
1576 "Spaces have been converted to \"_\"",
1577 "No spaces allowed in Sequence Name",
1578 JOptionPane.WARNING_MESSAGE);
1581 sequence.setName(dialog.getName().replace(' ', '_'));
1582 ap.paintAlignment(false);
1585 sequence.setDescription(dialog.getDescription());
1587 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1598 void unGroupMenuItem_actionPerformed()
1600 SequenceGroup sg = ap.av.getSelectionGroup();
1601 ap.av.alignment.deleteGroup(sg);
1602 ap.av.setSelectionGroup(null);
1612 protected void outline_actionPerformed()
1614 SequenceGroup sg = getGroup();
1615 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1620 sg.setOutlineColour(col);
1632 public void showBoxes_actionPerformed()
1634 getGroup().setDisplayBoxes(showBoxes.isSelected());
1644 public void showText_actionPerformed()
1646 getGroup().setDisplayText(showText.isSelected());
1656 public void showColourText_actionPerformed()
1658 getGroup().setColourText(showColourText.isSelected());
1662 public void showLink(String url)
1666 jalview.util.BrowserLauncher.openURL(url);
1667 } catch (Exception ex)
1670 .showInternalMessageDialog(
1672 "Unixers: Couldn't find default web browser."
1673 + "\nAdd the full path to your browser in Preferences.",
1674 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1676 ex.printStackTrace();
1680 void hideSequences(boolean representGroup)
1682 SequenceGroup sg = ap.av.getSelectionGroup();
1683 if (sg == null || sg.getSize() < 1)
1685 ap.av.hideSequence(new SequenceI[]
1690 ap.av.setSelectionGroup(null);
1694 ap.av.hideRepSequences(sequence, sg);
1699 int gsize = sg.getSize();
1702 hseqs = new SequenceI[gsize];
1705 for (int i = 0; i < gsize; i++)
1707 hseqs[index++] = sg.getSequenceAt(i);
1710 ap.av.hideSequence(hseqs);
1711 // refresh(); TODO: ? needed ?
1712 ap.av.sendSelection();
1715 public void copy_actionPerformed()
1717 ap.alignFrame.copy_actionPerformed(null);
1720 public void cut_actionPerformed()
1722 ap.alignFrame.cut_actionPerformed(null);
1725 void changeCase(ActionEvent e)
1727 Object source = e.getSource();
1728 SequenceGroup sg = ap.av.getSelectionGroup();
1732 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1733 sg.getEndRes() + 1);
1738 if (source == toggle)
1740 description = "Toggle Case";
1741 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1743 else if (source == upperCase)
1745 description = "To Upper Case";
1746 caseChange = ChangeCaseCommand.TO_UPPER;
1750 description = "To Lower Case";
1751 caseChange = ChangeCaseCommand.TO_LOWER;
1754 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1755 sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1758 ap.alignFrame.addHistoryItem(caseCommand);
1760 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1766 public void outputText_actionPerformed(ActionEvent e)
1768 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1769 cap.setForInput(null);
1770 Desktop.addInternalFrame(cap,
1771 "Alignment output - " + e.getActionCommand(), 600, 500);
1773 String[] omitHidden = null;
1775 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1776 // or we simply trust the user wants
1777 // wysiwig behaviour
1778 SequenceGroup sg = ap.av.getSelectionGroup();
1779 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1780 omitHidden = ap.av.getViewAsString(true);
1781 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1782 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1785 for (int i = 0; i < nala.length; i++)
1787 AlignmentAnnotation na = nala[i];
1788 oal.addAnnotation(na);
1791 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1792 oal, omitHidden, csel, sg));
1796 public void pdbFromFile_actionPerformed()
1798 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1799 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1800 chooser.setFileView(new jalview.io.JalviewFileView());
1801 chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
1802 chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
1804 int value = chooser.showOpenDialog(null);
1806 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1808 String choice = chooser.getSelectedFile().getPath();
1809 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1810 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
1815 public void enterPDB_actionPerformed()
1817 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1818 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1820 if (id != null && id.length() > 0)
1822 PDBEntry entry = new PDBEntry();
1823 entry.setId(id.toUpperCase());
1824 sequence.getDatasetSequence().addPDBId(entry);
1828 public void discoverPDB_actionPerformed()
1831 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1833 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1834 Thread discpdb = new Thread(new Runnable()
1839 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1840 .fetchDBRefs(false);
1847 public void sequenceFeature_actionPerformed()
1849 SequenceGroup sg = ap.av.getSelectionGroup();
1855 int rsize = 0, gSize = sg.getSize();
1856 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1857 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1859 for (int i = 0; i < gSize; i++)
1861 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1862 int end = sg.findEndRes(sg.getSequenceAt(i));
1865 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1866 features[rsize] = new SequenceFeature(null, null, null, start, end,
1871 rseqs = new SequenceI[rsize];
1872 tfeatures = new SequenceFeature[rsize];
1873 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1874 System.arraycopy(features, 0, tfeatures, 0, rsize);
1875 features = tfeatures;
1877 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1878 features, true, ap))
1880 ap.alignFrame.setShowSeqFeatures(true);
1881 ap.highlightSearchResults(null);
1885 public void textColour_actionPerformed()
1887 SequenceGroup sg = getGroup();
1890 new TextColourChooser().chooseColour(ap, sg);
1894 public void colourByStructure(String pdbid)
1896 Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure(
1899 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1900 "Coloured by " + pdbid, anots);
1902 ap.av.alignment.addAnnotation(an);
1903 an.createSequenceMapping(sequence, 0, true);
1904 // an.adjustForAlignment();
1905 ap.av.alignment.setAnnotationIndex(an, 0);
1907 ap.adjustAnnotationHeight();
1909 sequence.addAlignmentAnnotation(an);
1913 public void editSequence_actionPerformed(ActionEvent actionEvent)
1915 SequenceGroup sg = ap.av.getSelectionGroup();
1919 if (sequence == null)
1920 sequence = (Sequence) sg.getSequenceAt(0);
1922 EditNameDialog dialog = new EditNameDialog(
1923 sequence.getSequenceAsString(sg.getStartRes(),
1924 sg.getEndRes() + 1), null, "Edit Sequence ", null,
1925 "Edit Sequence", ap.alignFrame);
1929 EditCommand editCommand = new EditCommand("Edit Sequences",
1930 EditCommand.REPLACE, dialog.getName().replace(' ',
1931 ap.av.getGapCharacter()),
1932 sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1933 sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1935 ap.alignFrame.addHistoryItem(editCommand);
1937 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()