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 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
75 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
79 JMenu sequenceMenu = new JMenu();
81 JMenuItem sequenceName = new JMenuItem();
85 JMenuItem unGroupMenuItem = new JMenuItem();
87 JMenuItem outline = new JMenuItem();
89 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
91 JMenu colourMenu = new JMenu();
93 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
95 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
97 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
99 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
101 JMenu editMenu = new JMenu();
103 JMenuItem cut = new JMenuItem();
105 JMenuItem copy = new JMenuItem();
107 JMenuItem upperCase = new JMenuItem();
109 JMenuItem lowerCase = new JMenuItem();
111 JMenuItem toggle = new JMenuItem();
113 JMenu pdbMenu = new JMenu();
115 JMenuItem pdbFromFile = new JMenuItem();
117 JMenuItem enterPDB = new JMenuItem();
119 JMenuItem discoverPDB = new JMenuItem();
121 JMenu outputMenu = new JMenu();
123 JMenuItem sequenceFeature = new JMenuItem();
125 JMenuItem textColour = new JMenuItem();
127 JMenu jMenu1 = new JMenu();
129 JMenu structureMenu = new JMenu();
131 JMenu viewStructureMenu = new JMenu();
133 // JMenu colStructureMenu = new JMenu();
134 JMenuItem editSequence = new JMenuItem();
136 // JMenuItem annotationMenuItem = new JMenuItem();
138 JMenu groupLinksMenu;
141 * Creates a new PopupMenu object.
148 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
150 this(ap, seq, links, null);
160 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links,
163 // /////////////////////////////////////////////////////////
164 // If this is activated from the sequence panel, the user may want to
165 // edit or annotate a particular residue. Therefore display the residue menu
167 // If from the IDPanel, we must display the sequence menu
168 // ////////////////////////////////////////////////////////
172 ButtonGroup colours = new ButtonGroup();
173 colours.add(noColourmenuItem);
174 colours.add(clustalColour);
175 colours.add(zappoColour);
176 colours.add(taylorColour);
177 colours.add(hydrophobicityColour);
178 colours.add(helixColour);
179 colours.add(strandColour);
180 colours.add(turnColour);
181 colours.add(buriedColour);
182 colours.add(abovePIDColour);
183 colours.add(userDefinedColour);
184 colours.add(PIDColour);
185 colours.add(BLOSUM62Colour);
187 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
189 JMenuItem item = new JMenuItem(
190 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
192 item.addActionListener(new java.awt.event.ActionListener()
194 public void actionPerformed(ActionEvent e)
196 outputText_actionPerformed(e);
200 outputMenu.add(item);
206 } catch (Exception e)
214 sequenceMenu.setText(sequence.getName());
216 if (seq.getDatasetSequence().getPDBId() != null
217 && seq.getDatasetSequence().getPDBId().size() > 0)
219 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
222 while (e.hasMoreElements())
224 final PDBEntry pdb = (PDBEntry) e.nextElement();
226 menuItem = new JMenuItem();
227 menuItem.setText(pdb.getId());
228 menuItem.addActionListener(new java.awt.event.ActionListener()
230 public void actionPerformed(ActionEvent e)
232 // TODO re JAL-860: optionally open dialog or provide a menu entry allowing user to open just one structure per sequence
233 new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[] { pdb })[0], null, ap);
234 // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
238 viewStructureMenu.add(menuItem);
241 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
242 * menuItem.addActionListener(new java.awt.event.ActionListener() {
243 * public void actionPerformed(ActionEvent e) {
244 * colourByStructure(pdb.getId()); } });
245 * colStructureMenu.add(menuItem);
251 structureMenu.remove(viewStructureMenu);
252 // structureMenu.remove(colStructureMenu);
255 menuItem = new JMenuItem("Hide Sequences");
256 menuItem.addActionListener(new java.awt.event.ActionListener()
258 public void actionPerformed(ActionEvent e)
260 hideSequences(false);
265 if (ap.av.getSelectionGroup() != null
266 && ap.av.getSelectionGroup().getSize() > 1)
268 menuItem = new JMenuItem("Represent Group with " + seq.getName());
269 menuItem.addActionListener(new java.awt.event.ActionListener()
271 public void actionPerformed(ActionEvent e)
276 sequenceMenu.add(menuItem);
279 if (ap.av.hasHiddenRows)
281 final int index = ap.av.alignment.findIndex(seq);
283 if (ap.av.adjustForHiddenSeqs(index)
284 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
286 menuItem = new JMenuItem("Reveal Sequences");
287 menuItem.addActionListener(new ActionListener()
289 public void actionPerformed(ActionEvent e)
291 ap.av.showSequence(index);
292 if (ap.overviewPanel != null)
294 ap.overviewPanel.updateOverviewImage();
302 // for the case when no sequences are even visible
303 if (ap.av.hasHiddenRows) {
305 menuItem = new JMenuItem("Reveal All");
306 menuItem.addActionListener(new ActionListener()
308 public void actionPerformed(ActionEvent e)
310 ap.av.showAllHiddenSeqs();
311 if (ap.overviewPanel != null)
313 ap.overviewPanel.updateOverviewImage();
323 SequenceGroup sg = ap.av.getSelectionGroup();
325 if (sg != null&& sg.getSize()>0)
327 groupName.setText("Name: "+sg.getName());
328 groupName.setText("Edit name and description of current group.");
330 if (sg.cs instanceof ZappoColourScheme)
332 zappoColour.setSelected(true);
334 else if (sg.cs instanceof TaylorColourScheme)
336 taylorColour.setSelected(true);
338 else if (sg.cs instanceof PIDColourScheme)
340 PIDColour.setSelected(true);
342 else if (sg.cs instanceof Blosum62ColourScheme)
344 BLOSUM62Colour.setSelected(true);
346 else if (sg.cs instanceof UserColourScheme)
348 userDefinedColour.setSelected(true);
350 else if (sg.cs instanceof HydrophobicColourScheme)
352 hydrophobicityColour.setSelected(true);
354 else if (sg.cs instanceof HelixColourScheme)
356 helixColour.setSelected(true);
358 else if (sg.cs instanceof StrandColourScheme)
360 strandColour.setSelected(true);
362 else if (sg.cs instanceof TurnColourScheme)
364 turnColour.setSelected(true);
366 else if (sg.cs instanceof BuriedColourScheme)
368 buriedColour.setSelected(true);
370 else if (sg.cs instanceof ClustalxColourScheme)
372 clustalColour.setSelected(true);
376 noColourmenuItem.setSelected(true);
379 if (sg.cs != null && sg.cs.conservationApplied())
381 conservationMenuItem.setSelected(true);
383 displayNonconserved.setSelected(sg.getShowNonconserved());
384 showText.setSelected(sg.getDisplayText());
385 showColourText.setSelected(sg.getColourText());
386 showBoxes.setSelected(sg.getDisplayBoxes());
387 // add any groupURLs to the groupURL submenu and make it visible
388 if (groupLinks != null && groupLinks.size() > 0)
390 buildGroupURLMenu(sg, groupLinks);
392 // Add a 'show all structures' for the current selection
393 Hashtable<String, PDBEntry> pdbe=new Hashtable<String,PDBEntry>();
394 for (SequenceI sq: ap.av.getSequenceSelection())
396 Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence().getPDBId();
398 for (PDBEntry pe: pes)
400 pdbe.put(pe.getId(), pe);
406 final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]);
407 final JMenuItem gpdbview;
408 structureMenu.add(gpdbview=new JMenuItem("View "+pdbe.size()+" structures."));
409 gpdbview.setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment.");
410 gpdbview.addActionListener(new ActionListener()
414 public void actionPerformed(ActionEvent e)
416 new AppJmol(ap, pe, ap.av.collateForPDB(pe));
423 groupMenu.setVisible(false);
424 editMenu.setVisible(false);
427 if (!ap.av.alignment.getGroups().contains(sg))
429 unGroupMenuItem.setVisible(false);
434 sequenceMenu.setVisible(false);
435 structureMenu.setVisible(false);
438 if (seq !=null && links != null && links.size() > 0)
441 JMenu linkMenu = new JMenu("Link");
442 Vector linkset = new Vector();
443 for (int i = 0; i < links.size(); i++)
445 String link = links.elementAt(i).toString();
446 UrlLink urlLink = null;
449 urlLink = new UrlLink(link);
450 } catch (Exception foo)
452 jalview.bin.Cache.log.error("Exception for URLLink '" + link
457 if (!urlLink.isValid())
459 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
462 final String label = urlLink.getLabel();
463 if (urlLink.isDynamic())
466 // collect matching db-refs
467 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
468 seq.getDBRef(), new String[]
469 { urlLink.getTarget() });
470 // collect id string too
471 String id = seq.getName();
472 String descr = seq.getDescription();
473 if (descr != null && descr.length() < 1)
480 for (int r = 0; r < dbr.length; r++)
482 if (id != null && dbr[r].getAccessionId().equals(id))
484 // suppress duplicate link creation for the bare sequence ID
485 // string with this link
488 // create Bare ID link for this RUL
489 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
493 for (int u = 0; u < urls.length; u += 2)
495 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
497 linkset.addElement(urls[u] + "|" + urls[u + 1]);
498 addshowLink(linkMenu, label + "|" + urls[u],
507 // create Bare ID link for this RUL
508 String[] urls = urlLink.makeUrls(id, true);
511 for (int u = 0; u < urls.length; u += 2)
513 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
515 linkset.addElement(urls[u] + "|" + urls[u + 1]);
516 addshowLink(linkMenu, label, urls[u + 1]);
521 // Create urls from description but only for URL links which are regex
523 if (descr != null && urlLink.getRegexReplace() != null)
525 // create link for this URL from description where regex matches
526 String[] urls = urlLink.makeUrls(descr, true);
529 for (int u = 0; u < urls.length; u += 2)
531 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
533 linkset.addElement(urls[u] + "|" + urls[u + 1]);
534 addshowLink(linkMenu, label, urls[u + 1]);
542 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
544 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
545 // Add a non-dynamic link
546 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
550 if (sequence != null)
552 sequenceMenu.add(linkMenu);
561 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
564 // TODO: usability: thread off the generation of group url content so root
566 // sequence only URLs
567 // ID/regex match URLs
568 groupLinksMenu = new JMenu("Group Link");
569 JMenu[] linkMenus = new JMenu[]
570 { null, new JMenu("IDS"), new JMenu("Sequences"),
571 new JMenu("IDS and Sequences") }; // three types of url that might be
573 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
574 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
575 Hashtable commonDbrefs = new Hashtable();
576 for (int sq = 0; sq < seqs.length; sq++)
579 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
580 .findPosition(sg.getEndRes());
581 // just collect ids from dataset sequence
582 // TODO: check if IDs collected from selecton group intersects with the
583 // current selection, too
584 SequenceI sqi = seqs[sq];
585 while (sqi.getDatasetSequence() != null)
587 sqi = sqi.getDatasetSequence();
589 DBRefEntry[] dbr = sqi.getDBRef();
590 if (dbr != null && dbr.length > 0)
592 for (int d = 0; d < dbr.length; d++)
594 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
595 Object[] sarray = (Object[]) commonDbrefs.get(src);
598 sarray = new Object[2];
599 sarray[0] = new int[]
601 sarray[1] = new String[seqs.length];
603 commonDbrefs.put(src, sarray);
606 if (((String[]) sarray[1])[sq] == null)
609 || (dbr[d].getMap().locateMappedRange(start, end) != null))
611 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
612 ((int[]) sarray[0])[0]++;
618 // now create group links for all distinct ID/sequence sets.
619 boolean addMenu = false; // indicates if there are any group links to give
621 for (int i = 0; i < groupLinks.size(); i++)
623 String link = groupLinks.elementAt(i).toString();
624 GroupUrlLink urlLink = null;
627 urlLink = new GroupUrlLink(link);
628 } catch (Exception foo)
630 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
635 if (!urlLink.isValid())
637 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
640 final String label = urlLink.getLabel();
641 boolean usingNames = false;
642 // Now see which parts of the group apply for this URL
643 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
644 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
645 String[] seqstr, ids; // input to makeUrl
648 int numinput = ((int[]) idset[0])[0];
649 String[] allids = ((String[]) idset[1]);
650 seqstr = new String[numinput];
651 ids = new String[numinput];
652 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
654 if (allids[sq] != null)
656 ids[idcount] = allids[sq];
657 seqstr[idcount++] = idandseqs[1][sq];
663 // just use the id/seq set
664 seqstr = idandseqs[1];
668 // and try and make the groupURL!
670 Object[] urlset = null;
673 urlset = urlLink.makeUrlStubs(ids, seqstr,
674 "FromJalview" + System.currentTimeMillis(), false);
675 } catch (UrlStringTooLongException e)
680 int type = urlLink.getGroupURLType() & 3;
681 // System.out.println(urlLink.getGroupURLType()
682 // +" "+((String[])urlset[3])[0]);
683 // first two bits ofurlLink type bitfield are sequenceids and sequences
684 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
685 addshowLink(linkMenus[type], label
686 + (((type & 1) == 1) ? ("("
687 + (usingNames ? "Names" : ltarget) + ")") : ""),
694 groupLinksMenu = new JMenu("Group Links");
695 for (int m = 0; m < linkMenus.length; m++)
697 if (linkMenus[m] != null
698 && linkMenus[m].getMenuComponentCount() > 0)
700 groupLinksMenu.add(linkMenus[m]);
704 groupMenu.add(groupLinksMenu);
709 * add a show URL menu item to the given linkMenu
713 * - menu label string
717 private void addshowLink(JMenu linkMenu, String label, final String url)
719 JMenuItem item = new JMenuItem(label);
720 item.setToolTipText("open URL: " + url);
721 item.addActionListener(new java.awt.event.ActionListener()
723 public void actionPerformed(ActionEvent e)
725 new Thread(new Runnable()
741 * add a late bound groupURL item to the given linkMenu
745 * - menu label string
746 * @param urlgenerator
747 * GroupURLLink used to generate URL
749 * Object array returned from the makeUrlStubs function.
751 private void addshowLink(JMenu linkMenu, String label,
752 final GroupUrlLink urlgenerator, final Object[] urlstub)
754 JMenuItem item = new JMenuItem(label);
755 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
756 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
765 item.addActionListener(new java.awt.event.ActionListener()
767 public void actionPerformed(ActionEvent e)
769 new Thread(new Runnable()
776 showLink(urlgenerator.constructFrom(urlstub));
777 } catch (UrlStringTooLongException e)
795 private void jbInit() throws Exception
797 groupMenu.setText("Group");
798 groupMenu.setText("Selection");
799 groupName.setText("Name");
800 groupName.addActionListener(new java.awt.event.ActionListener()
802 public void actionPerformed(ActionEvent e)
804 groupName_actionPerformed();
807 sequenceMenu.setText("Sequence");
808 sequenceName.setText("Edit Name/Description");
809 sequenceName.addActionListener(new java.awt.event.ActionListener()
811 public void actionPerformed(ActionEvent e)
813 sequenceName_actionPerformed();
816 PIDColour.setFocusPainted(false);
817 unGroupMenuItem.setText("Remove Group");
818 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
820 public void actionPerformed(ActionEvent e)
822 unGroupMenuItem_actionPerformed();
826 outline.setText("Border colour");
827 outline.addActionListener(new java.awt.event.ActionListener()
829 public void actionPerformed(ActionEvent e)
831 outline_actionPerformed();
834 nucleotideMenuItem.setText("Nucleotide");
835 nucleotideMenuItem.addActionListener(new ActionListener()
837 public void actionPerformed(ActionEvent e)
839 nucleotideMenuItem_actionPerformed();
842 colourMenu.setText("Group Colour");
843 showBoxes.setText("Boxes");
844 showBoxes.setState(true);
845 showBoxes.addActionListener(new ActionListener()
847 public void actionPerformed(ActionEvent e)
849 showBoxes_actionPerformed();
852 showText.setText("Text");
853 showText.setState(true);
854 showText.addActionListener(new ActionListener()
856 public void actionPerformed(ActionEvent e)
858 showText_actionPerformed();
861 showColourText.setText("Colour Text");
862 showColourText.addActionListener(new ActionListener()
864 public void actionPerformed(ActionEvent e)
866 showColourText_actionPerformed();
869 displayNonconserved.setText("Show Nonconserved");
870 displayNonconserved.setState(true);
871 displayNonconserved.addActionListener(new ActionListener()
873 public void actionPerformed(ActionEvent e)
875 showNonconserved_actionPerformed();
878 editMenu.setText("Edit");
880 cut.addActionListener(new ActionListener()
882 public void actionPerformed(ActionEvent e)
884 cut_actionPerformed();
887 upperCase.setText("To Upper Case");
888 upperCase.addActionListener(new ActionListener()
890 public void actionPerformed(ActionEvent e)
895 copy.setText("Copy");
896 copy.addActionListener(new ActionListener()
898 public void actionPerformed(ActionEvent e)
900 copy_actionPerformed();
903 lowerCase.setText("To Lower Case");
904 lowerCase.addActionListener(new ActionListener()
906 public void actionPerformed(ActionEvent e)
911 toggle.setText("Toggle Case");
912 toggle.addActionListener(new ActionListener()
914 public void actionPerformed(ActionEvent e)
919 pdbMenu.setText("Associate Structure with Sequence");
920 pdbFromFile.setText("From File");
921 pdbFromFile.addActionListener(new ActionListener()
923 public void actionPerformed(ActionEvent e)
925 pdbFromFile_actionPerformed();
928 enterPDB.setText("Enter PDB Id");
929 enterPDB.addActionListener(new ActionListener()
931 public void actionPerformed(ActionEvent e)
933 enterPDB_actionPerformed();
936 discoverPDB.setText("Discover PDB ids");
937 discoverPDB.addActionListener(new ActionListener()
939 public void actionPerformed(ActionEvent e)
941 discoverPDB_actionPerformed();
944 outputMenu.setText("Output to Textbox...");
945 sequenceFeature.setText("Create Sequence Feature");
946 sequenceFeature.addActionListener(new ActionListener()
948 public void actionPerformed(ActionEvent e)
950 sequenceFeature_actionPerformed();
953 textColour.setText("Text Colour");
954 textColour.addActionListener(new ActionListener()
956 public void actionPerformed(ActionEvent e)
958 textColour_actionPerformed();
961 jMenu1.setText("Group");
962 structureMenu.setText("Structure");
963 viewStructureMenu.setText("View Structure");
964 // colStructureMenu.setText("Colour By Structure");
965 editSequence.setText("Edit Sequence...");
966 editSequence.addActionListener(new ActionListener()
968 public void actionPerformed(ActionEvent actionEvent)
970 editSequence_actionPerformed(actionEvent);
974 * annotationMenuItem.setText("By Annotation");
975 * annotationMenuItem.addActionListener(new ActionListener() { public void
976 * actionPerformed(ActionEvent actionEvent) {
977 * annotationMenuItem_actionPerformed(actionEvent); } });
983 this.add(structureMenu);
984 groupMenu.add(editMenu);
985 groupMenu.add(outputMenu);
986 groupMenu.add(sequenceFeature);
987 groupMenu.add(jMenu1);
988 sequenceMenu.add(sequenceName);
989 colourMenu.add(textColour);
990 colourMenu.add(noColourmenuItem);
991 colourMenu.add(clustalColour);
992 colourMenu.add(BLOSUM62Colour);
993 colourMenu.add(PIDColour);
994 colourMenu.add(zappoColour);
995 colourMenu.add(taylorColour);
996 colourMenu.add(hydrophobicityColour);
997 colourMenu.add(helixColour);
998 colourMenu.add(strandColour);
999 colourMenu.add(turnColour);
1000 colourMenu.add(buriedColour);
1001 colourMenu.add(nucleotideMenuItem);
1002 colourMenu.add(userDefinedColour);
1004 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1006 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1007 .getUserColourSchemes().keys();
1009 while (userColours.hasMoreElements())
1011 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1012 item.addActionListener(new ActionListener()
1014 public void actionPerformed(ActionEvent evt)
1016 userDefinedColour_actionPerformed(evt);
1019 colourMenu.add(item);
1023 colourMenu.addSeparator();
1024 colourMenu.add(abovePIDColour);
1025 colourMenu.add(conservationMenuItem);
1026 // colourMenu.add(annotationMenuItem);
1029 editMenu.add(editSequence);
1030 editMenu.add(upperCase);
1031 editMenu.add(lowerCase);
1032 editMenu.add(toggle);
1033 pdbMenu.add(pdbFromFile);
1034 pdbMenu.add(enterPDB);
1035 pdbMenu.add(discoverPDB);
1036 jMenu1.add(groupName);
1037 jMenu1.add(unGroupMenuItem);
1038 jMenu1.add(colourMenu);
1039 jMenu1.add(showBoxes);
1040 jMenu1.add(showText);
1041 jMenu1.add(showColourText);
1042 jMenu1.add(outline);
1043 jMenu1.add(displayNonconserved);
1044 structureMenu.add(pdbMenu);
1045 structureMenu.add(viewStructureMenu);
1046 // structureMenu.add(colStructureMenu);
1047 noColourmenuItem.setText("None");
1048 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1050 public void actionPerformed(ActionEvent e)
1052 noColourmenuItem_actionPerformed();
1056 clustalColour.setText("Clustalx colours");
1057 clustalColour.addActionListener(new java.awt.event.ActionListener()
1059 public void actionPerformed(ActionEvent e)
1061 clustalColour_actionPerformed();
1064 zappoColour.setText("Zappo");
1065 zappoColour.addActionListener(new java.awt.event.ActionListener()
1067 public void actionPerformed(ActionEvent e)
1069 zappoColour_actionPerformed();
1072 taylorColour.setText("Taylor");
1073 taylorColour.addActionListener(new java.awt.event.ActionListener()
1075 public void actionPerformed(ActionEvent e)
1077 taylorColour_actionPerformed();
1080 hydrophobicityColour.setText("Hydrophobicity");
1081 hydrophobicityColour
1082 .addActionListener(new java.awt.event.ActionListener()
1084 public void actionPerformed(ActionEvent e)
1086 hydrophobicityColour_actionPerformed();
1089 helixColour.setText("Helix propensity");
1090 helixColour.addActionListener(new java.awt.event.ActionListener()
1092 public void actionPerformed(ActionEvent e)
1094 helixColour_actionPerformed();
1097 strandColour.setText("Strand propensity");
1098 strandColour.addActionListener(new java.awt.event.ActionListener()
1100 public void actionPerformed(ActionEvent e)
1102 strandColour_actionPerformed();
1105 turnColour.setText("Turn propensity");
1106 turnColour.addActionListener(new java.awt.event.ActionListener()
1108 public void actionPerformed(ActionEvent e)
1110 turnColour_actionPerformed();
1113 buriedColour.setText("Buried Index");
1114 buriedColour.addActionListener(new java.awt.event.ActionListener()
1116 public void actionPerformed(ActionEvent e)
1118 buriedColour_actionPerformed();
1121 abovePIDColour.setText("Above % Identity");
1122 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1124 public void actionPerformed(ActionEvent e)
1126 abovePIDColour_actionPerformed();
1129 userDefinedColour.setText("User Defined...");
1130 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1132 public void actionPerformed(ActionEvent e)
1134 userDefinedColour_actionPerformed(e);
1137 PIDColour.setText("Percentage Identity");
1138 PIDColour.addActionListener(new java.awt.event.ActionListener()
1140 public void actionPerformed(ActionEvent e)
1142 PIDColour_actionPerformed();
1145 BLOSUM62Colour.setText("BLOSUM62");
1146 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1148 public void actionPerformed(ActionEvent e)
1150 BLOSUM62Colour_actionPerformed();
1153 conservationMenuItem.setText("Conservation");
1154 conservationMenuItem
1155 .addActionListener(new java.awt.event.ActionListener()
1157 public void actionPerformed(ActionEvent e)
1159 conservationMenuItem_actionPerformed();
1164 protected void showNonconserved_actionPerformed()
1166 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1171 * call to refresh view after settings change
1175 ap.updateAnnotation();
1176 ap.paintAlignment(true);
1178 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1187 protected void clustalColour_actionPerformed()
1189 SequenceGroup sg = getGroup();
1190 sg.cs = new ClustalxColourScheme(
1191 sg.getSequences(ap.av.hiddenRepSequences),
1192 ap.av.alignment.getWidth());
1202 protected void zappoColour_actionPerformed()
1204 getGroup().cs = new ZappoColourScheme();
1214 protected void taylorColour_actionPerformed()
1216 getGroup().cs = new TaylorColourScheme();
1226 protected void hydrophobicityColour_actionPerformed()
1228 getGroup().cs = new HydrophobicColourScheme();
1238 protected void helixColour_actionPerformed()
1240 getGroup().cs = new HelixColourScheme();
1250 protected void strandColour_actionPerformed()
1252 getGroup().cs = new StrandColourScheme();
1262 protected void turnColour_actionPerformed()
1264 getGroup().cs = new TurnColourScheme();
1274 protected void buriedColour_actionPerformed()
1276 getGroup().cs = new BuriedColourScheme();
1286 public void nucleotideMenuItem_actionPerformed()
1288 getGroup().cs = new NucleotideColourScheme();
1298 protected void abovePIDColour_actionPerformed()
1300 SequenceGroup sg = getGroup();
1306 if (abovePIDColour.isSelected())
1308 sg.cs.setConsensus(AAFrequency.calculate(
1309 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1310 sg.getEndRes() + 1));
1312 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1315 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1317 SliderPanel.showPIDSlider();
1320 // remove PIDColouring
1322 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1334 protected void userDefinedColour_actionPerformed(ActionEvent e)
1336 SequenceGroup sg = getGroup();
1338 if (e.getActionCommand().equals("User Defined..."))
1340 new UserDefinedColours(ap, sg);
1344 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1345 .getUserColourSchemes().get(e.getActionCommand());
1358 protected void PIDColour_actionPerformed()
1360 SequenceGroup sg = getGroup();
1361 sg.cs = new PIDColourScheme();
1362 sg.cs.setConsensus(AAFrequency.calculate(
1363 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1364 sg.getEndRes() + 1));
1374 protected void BLOSUM62Colour_actionPerformed()
1376 SequenceGroup sg = getGroup();
1378 sg.cs = new Blosum62ColourScheme();
1380 sg.cs.setConsensus(AAFrequency.calculate(
1381 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1382 sg.getEndRes() + 1));
1393 protected void noColourmenuItem_actionPerformed()
1395 getGroup().cs = null;
1405 protected void conservationMenuItem_actionPerformed()
1407 SequenceGroup sg = getGroup();
1413 if (conservationMenuItem.isSelected())
1415 Conservation c = new Conservation("Group",
1416 ResidueProperties.propHash, 3,
1417 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1418 sg.getEndRes() + 1);
1421 c.verdict(false, ap.av.ConsPercGaps);
1423 sg.cs.setConservation(c);
1425 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1426 SliderPanel.showConservationSlider();
1429 // remove ConservationColouring
1431 sg.cs.setConservation(null);
1437 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1439 SequenceGroup sg = getGroup();
1445 AnnotationColourGradient acg = new AnnotationColourGradient(
1446 sequence.getAnnotation()[0], null,
1447 AnnotationColourGradient.NO_THRESHOLD);
1449 acg.predefinedColours = true;
1461 protected void groupName_actionPerformed()
1464 SequenceGroup sg = getGroup();
1465 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1466 sg.getDescription(), " Group Name ",
1467 "Group Description ", "Edit Group Name/Description",
1475 sg.setName(dialog.getName());
1476 sg.setDescription(dialog.getDescription());
1481 * Get selection group - adding it to the alignment if necessary.
1483 * @return sequence group to operate on
1485 SequenceGroup getGroup()
1487 SequenceGroup sg = ap.av.getSelectionGroup();
1488 // this method won't add a new group if it already exists
1491 ap.av.alignment.addGroup(sg);
1503 void sequenceName_actionPerformed()
1505 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1506 sequence.getDescription(), " Sequence Name ",
1507 "Sequence Description ", "Edit Sequence Name/Description",
1515 if (dialog.getName() != null)
1517 if (dialog.getName().indexOf(" ") > -1)
1519 JOptionPane.showMessageDialog(ap,
1520 "Spaces have been converted to \"_\"",
1521 "No spaces allowed in Sequence Name",
1522 JOptionPane.WARNING_MESSAGE);
1525 sequence.setName(dialog.getName().replace(' ', '_'));
1526 ap.paintAlignment(false);
1529 sequence.setDescription(dialog.getDescription());
1531 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1542 void unGroupMenuItem_actionPerformed()
1544 SequenceGroup sg = ap.av.getSelectionGroup();
1545 ap.av.alignment.deleteGroup(sg);
1546 ap.av.setSelectionGroup(null);
1556 protected void outline_actionPerformed()
1558 SequenceGroup sg = getGroup();
1559 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1564 sg.setOutlineColour(col);
1576 public void showBoxes_actionPerformed()
1578 getGroup().setDisplayBoxes(showBoxes.isSelected());
1588 public void showText_actionPerformed()
1590 getGroup().setDisplayText(showText.isSelected());
1600 public void showColourText_actionPerformed()
1602 getGroup().setColourText(showColourText.isSelected());
1606 public void showLink(String url)
1610 jalview.util.BrowserLauncher.openURL(url);
1611 } catch (Exception ex)
1614 .showInternalMessageDialog(
1616 "Unixers: Couldn't find default web browser."
1617 + "\nAdd the full path to your browser in Preferences.",
1618 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1620 ex.printStackTrace();
1624 void hideSequences(boolean representGroup)
1626 SequenceGroup sg = ap.av.getSelectionGroup();
1627 if (sg == null || sg.getSize() < 1)
1629 ap.av.hideSequence(new SequenceI[]
1634 ap.av.setSelectionGroup(null);
1638 ap.av.hideRepSequences(sequence, sg);
1643 int gsize = sg.getSize();
1646 hseqs = new SequenceI[gsize];
1649 for (int i = 0; i < gsize; i++)
1651 hseqs[index++] = sg.getSequenceAt(i);
1654 ap.av.hideSequence(hseqs);
1655 // refresh(); TODO: ? needed ?
1656 ap.av.sendSelection();
1659 public void copy_actionPerformed()
1661 ap.alignFrame.copy_actionPerformed(null);
1664 public void cut_actionPerformed()
1666 ap.alignFrame.cut_actionPerformed(null);
1669 void changeCase(ActionEvent e)
1671 Object source = e.getSource();
1672 SequenceGroup sg = ap.av.getSelectionGroup();
1676 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1677 sg.getEndRes() + 1);
1682 if (source == toggle)
1684 description = "Toggle Case";
1685 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1687 else if (source == upperCase)
1689 description = "To Upper Case";
1690 caseChange = ChangeCaseCommand.TO_UPPER;
1694 description = "To Lower Case";
1695 caseChange = ChangeCaseCommand.TO_LOWER;
1698 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1699 sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1702 ap.alignFrame.addHistoryItem(caseCommand);
1704 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1710 public void outputText_actionPerformed(ActionEvent e)
1712 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1713 cap.setForInput(null);
1714 Desktop.addInternalFrame(cap,
1715 "Alignment output - " + e.getActionCommand(), 600, 500);
1717 String[] omitHidden = null;
1719 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1720 // or we simply trust the user wants
1721 // wysiwig behaviour
1722 SequenceGroup sg = ap.av.getSelectionGroup();
1723 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1724 omitHidden = ap.av.getViewAsString(true);
1725 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1726 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1729 for (int i = 0; i < nala.length; i++)
1731 AlignmentAnnotation na = nala[i];
1732 oal.addAnnotation(na);
1735 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1736 oal, omitHidden, csel, sg));
1740 public void pdbFromFile_actionPerformed()
1742 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1743 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1744 chooser.setFileView(new jalview.io.JalviewFileView());
1745 chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
1746 chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
1748 int value = chooser.showOpenDialog(null);
1750 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1752 String choice = chooser.getSelectedFile().getPath();
1753 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1754 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
1759 public void enterPDB_actionPerformed()
1761 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1762 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1764 if (id != null && id.length() > 0)
1766 PDBEntry entry = new PDBEntry();
1767 entry.setId(id.toUpperCase());
1768 sequence.getDatasetSequence().addPDBId(entry);
1772 public void discoverPDB_actionPerformed()
1775 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1777 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1778 Thread discpdb = new Thread(new Runnable()
1783 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1784 .fetchDBRefs(false);
1791 public void sequenceFeature_actionPerformed()
1793 SequenceGroup sg = ap.av.getSelectionGroup();
1799 int rsize = 0, gSize = sg.getSize();
1800 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1801 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1803 for (int i = 0; i < gSize; i++)
1805 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1806 int end = sg.findEndRes(sg.getSequenceAt(i));
1809 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1810 features[rsize] = new SequenceFeature(null, null, null, start, end,
1815 rseqs = new SequenceI[rsize];
1816 tfeatures = new SequenceFeature[rsize];
1817 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1818 System.arraycopy(features, 0, tfeatures, 0, rsize);
1819 features = tfeatures;
1821 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1822 features, true, ap))
1824 ap.alignFrame.setShowSeqFeatures(true);
1825 ap.highlightSearchResults(null);
1829 public void textColour_actionPerformed()
1831 SequenceGroup sg = getGroup();
1834 new TextColourChooser().chooseColour(ap, sg);
1838 public void colourByStructure(String pdbid)
1840 Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure(
1843 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1844 "Coloured by " + pdbid, anots);
1846 ap.av.alignment.addAnnotation(an);
1847 an.createSequenceMapping(sequence, 0, true);
1848 // an.adjustForAlignment();
1849 ap.av.alignment.setAnnotationIndex(an, 0);
1851 ap.adjustAnnotationHeight();
1853 sequence.addAlignmentAnnotation(an);
1857 public void editSequence_actionPerformed(ActionEvent actionEvent)
1859 SequenceGroup sg = ap.av.getSelectionGroup();
1863 if (sequence == null)
1864 sequence = (Sequence) sg.getSequenceAt(0);
1866 EditNameDialog dialog = new EditNameDialog(
1867 sequence.getSequenceAsString(sg.getStartRes(),
1868 sg.getEndRes() + 1), null, "Edit Sequence ", null,
1869 "Edit Sequence", ap.alignFrame);
1873 EditCommand editCommand = new EditCommand("Edit Sequences",
1874 EditCommand.REPLACE, dialog.getName().replace(' ',
1875 ap.av.getGapCharacter()),
1876 sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1877 sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1879 ap.alignFrame.addHistoryItem(editCommand);
1881 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()