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)
213 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();
301 menuItem = new JMenuItem("Reveal All");
302 menuItem.addActionListener(new ActionListener()
304 public void actionPerformed(ActionEvent e)
306 ap.av.showAllHiddenSeqs();
307 if (ap.overviewPanel != null)
309 ap.overviewPanel.updateOverviewImage();
319 SequenceGroup sg = ap.av.getSelectionGroup();
323 groupName.setText("Name: "+sg.getName());
324 groupName.setText("Edit name and description of current group.");
326 if (sg.cs instanceof ZappoColourScheme)
328 zappoColour.setSelected(true);
330 else if (sg.cs instanceof TaylorColourScheme)
332 taylorColour.setSelected(true);
334 else if (sg.cs instanceof PIDColourScheme)
336 PIDColour.setSelected(true);
338 else if (sg.cs instanceof Blosum62ColourScheme)
340 BLOSUM62Colour.setSelected(true);
342 else if (sg.cs instanceof UserColourScheme)
344 userDefinedColour.setSelected(true);
346 else if (sg.cs instanceof HydrophobicColourScheme)
348 hydrophobicityColour.setSelected(true);
350 else if (sg.cs instanceof HelixColourScheme)
352 helixColour.setSelected(true);
354 else if (sg.cs instanceof StrandColourScheme)
356 strandColour.setSelected(true);
358 else if (sg.cs instanceof TurnColourScheme)
360 turnColour.setSelected(true);
362 else if (sg.cs instanceof BuriedColourScheme)
364 buriedColour.setSelected(true);
366 else if (sg.cs instanceof ClustalxColourScheme)
368 clustalColour.setSelected(true);
372 noColourmenuItem.setSelected(true);
375 if (sg.cs != null && sg.cs.conservationApplied())
377 conservationMenuItem.setSelected(true);
379 displayNonconserved.setSelected(sg.getShowNonconserved());
380 showText.setSelected(sg.getDisplayText());
381 showColourText.setSelected(sg.getColourText());
382 showBoxes.setSelected(sg.getDisplayBoxes());
383 // add any groupURLs to the groupURL submenu and make it visible
384 if (groupLinks != null && groupLinks.size() > 0)
386 buildGroupURLMenu(sg, groupLinks);
388 // Add a 'show all structures' for the current selection
389 Hashtable<String, PDBEntry> pdbe=new Hashtable<String,PDBEntry>();
390 for (SequenceI sq: ap.av.getSequenceSelection())
392 Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence().getPDBId();
394 for (PDBEntry pe: pes)
396 pdbe.put(pe.getId(), pe);
402 final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]);
403 final JMenuItem gpdbview;
404 structureMenu.add(gpdbview=new JMenuItem("View "+pdbe.size()+" structures."));
405 gpdbview.setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment.");
406 gpdbview.addActionListener(new ActionListener()
410 public void actionPerformed(ActionEvent e)
412 new AppJmol(ap, pe, ap.av.collateForPDB(pe));
419 groupMenu.setVisible(false);
420 editMenu.setVisible(false);
423 if (!ap.av.alignment.getGroups().contains(sg))
425 unGroupMenuItem.setVisible(false);
430 sequenceMenu.setVisible(false);
431 structureMenu.setVisible(false);
434 if (links != null && links.size() > 0)
437 JMenu linkMenu = new JMenu("Link");
438 Vector linkset = new Vector();
439 for (int i = 0; i < links.size(); i++)
441 String link = links.elementAt(i).toString();
442 UrlLink urlLink = null;
445 urlLink = new UrlLink(link);
446 } catch (Exception foo)
448 jalview.bin.Cache.log.error("Exception for URLLink '" + link
453 if (!urlLink.isValid())
455 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
458 final String label = urlLink.getLabel();
459 if (urlLink.isDynamic())
462 // collect matching db-refs
463 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
464 seq.getDBRef(), new String[]
465 { urlLink.getTarget() });
466 // collect id string too
467 String id = seq.getName();
468 String descr = seq.getDescription();
469 if (descr != null && descr.length() < 1)
476 for (int r = 0; r < dbr.length; r++)
478 if (id != null && dbr[r].getAccessionId().equals(id))
480 // suppress duplicate link creation for the bare sequence ID
481 // string with this link
484 // create Bare ID link for this RUL
485 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
489 for (int u = 0; u < urls.length; u += 2)
491 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
493 linkset.addElement(urls[u] + "|" + urls[u + 1]);
494 addshowLink(linkMenu, label + "|" + urls[u],
503 // create Bare ID link for this RUL
504 String[] urls = urlLink.makeUrls(id, true);
507 for (int u = 0; u < urls.length; u += 2)
509 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
511 linkset.addElement(urls[u] + "|" + urls[u + 1]);
512 addshowLink(linkMenu, label, urls[u + 1]);
517 // Create urls from description but only for URL links which are regex
519 if (descr != null && urlLink.getRegexReplace() != null)
521 // create link for this URL from description where regex matches
522 String[] urls = urlLink.makeUrls(descr, true);
525 for (int u = 0; u < urls.length; u += 2)
527 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
529 linkset.addElement(urls[u] + "|" + urls[u + 1]);
530 addshowLink(linkMenu, label, urls[u + 1]);
538 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
540 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
541 // Add a non-dynamic link
542 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
546 if (sequence != null)
548 sequenceMenu.add(linkMenu);
557 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
560 // TODO: usability: thread off the generation of group url content so root
562 // sequence only URLs
563 // ID/regex match URLs
564 groupLinksMenu = new JMenu("Group Link");
565 JMenu[] linkMenus = new JMenu[]
566 { null, new JMenu("IDS"), new JMenu("Sequences"),
567 new JMenu("IDS and Sequences") }; // three types of url that might be
569 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
570 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
571 Hashtable commonDbrefs = new Hashtable();
572 for (int sq = 0; sq < seqs.length; sq++)
575 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
576 .findPosition(sg.getEndRes());
577 // just collect ids from dataset sequence
578 // TODO: check if IDs collected from selecton group intersects with the
579 // current selection, too
580 SequenceI sqi = seqs[sq];
581 while (sqi.getDatasetSequence() != null)
583 sqi = sqi.getDatasetSequence();
585 DBRefEntry[] dbr = sqi.getDBRef();
586 if (dbr != null && dbr.length > 0)
588 for (int d = 0; d < dbr.length; d++)
590 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
591 Object[] sarray = (Object[]) commonDbrefs.get(src);
594 sarray = new Object[2];
595 sarray[0] = new int[]
597 sarray[1] = new String[seqs.length];
599 commonDbrefs.put(src, sarray);
602 if (((String[]) sarray[1])[sq] == null)
605 || (dbr[d].getMap().locateMappedRange(start, end) != null))
607 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
608 ((int[]) sarray[0])[0]++;
614 // now create group links for all distinct ID/sequence sets.
615 boolean addMenu = false; // indicates if there are any group links to give
617 for (int i = 0; i < groupLinks.size(); i++)
619 String link = groupLinks.elementAt(i).toString();
620 GroupUrlLink urlLink = null;
623 urlLink = new GroupUrlLink(link);
624 } catch (Exception foo)
626 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
631 if (!urlLink.isValid())
633 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
636 final String label = urlLink.getLabel();
637 boolean usingNames = false;
638 // Now see which parts of the group apply for this URL
639 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
640 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
641 String[] seqstr, ids; // input to makeUrl
644 int numinput = ((int[]) idset[0])[0];
645 String[] allids = ((String[]) idset[1]);
646 seqstr = new String[numinput];
647 ids = new String[numinput];
648 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
650 if (allids[sq] != null)
652 ids[idcount] = allids[sq];
653 seqstr[idcount++] = idandseqs[1][sq];
659 // just use the id/seq set
660 seqstr = idandseqs[1];
664 // and try and make the groupURL!
666 Object[] urlset = null;
669 urlset = urlLink.makeUrlStubs(ids, seqstr,
670 "FromJalview" + System.currentTimeMillis(), false);
671 } catch (UrlStringTooLongException e)
676 int type = urlLink.getGroupURLType() & 3;
677 // System.out.println(urlLink.getGroupURLType()
678 // +" "+((String[])urlset[3])[0]);
679 // first two bits ofurlLink type bitfield are sequenceids and sequences
680 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
681 addshowLink(linkMenus[type], label
682 + (((type & 1) == 1) ? ("("
683 + (usingNames ? "Names" : ltarget) + ")") : ""),
690 groupLinksMenu = new JMenu("Group Links");
691 for (int m = 0; m < linkMenus.length; m++)
693 if (linkMenus[m] != null
694 && linkMenus[m].getMenuComponentCount() > 0)
696 groupLinksMenu.add(linkMenus[m]);
700 groupMenu.add(groupLinksMenu);
705 * add a show URL menu item to the given linkMenu
709 * - menu label string
713 private void addshowLink(JMenu linkMenu, String label, final String url)
715 JMenuItem item = new JMenuItem(label);
716 item.setToolTipText("open URL: " + url);
717 item.addActionListener(new java.awt.event.ActionListener()
719 public void actionPerformed(ActionEvent e)
721 new Thread(new Runnable()
737 * add a late bound groupURL item to the given linkMenu
741 * - menu label string
742 * @param urlgenerator
743 * GroupURLLink used to generate URL
745 * Object array returned from the makeUrlStubs function.
747 private void addshowLink(JMenu linkMenu, String label,
748 final GroupUrlLink urlgenerator, final Object[] urlstub)
750 JMenuItem item = new JMenuItem(label);
751 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
752 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
761 item.addActionListener(new java.awt.event.ActionListener()
763 public void actionPerformed(ActionEvent e)
765 new Thread(new Runnable()
772 showLink(urlgenerator.constructFrom(urlstub));
773 } catch (UrlStringTooLongException e)
791 private void jbInit() throws Exception
793 groupMenu.setText("Group");
794 groupMenu.setText("Selection");
795 groupName.setText("Name");
796 groupName.addActionListener(new java.awt.event.ActionListener()
798 public void actionPerformed(ActionEvent e)
800 groupName_actionPerformed();
803 sequenceMenu.setText("Sequence");
804 sequenceName.setText("Edit Name/Description");
805 sequenceName.addActionListener(new java.awt.event.ActionListener()
807 public void actionPerformed(ActionEvent e)
809 sequenceName_actionPerformed();
812 PIDColour.setFocusPainted(false);
813 unGroupMenuItem.setText("Remove Group");
814 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
816 public void actionPerformed(ActionEvent e)
818 unGroupMenuItem_actionPerformed();
822 outline.setText("Border colour");
823 outline.addActionListener(new java.awt.event.ActionListener()
825 public void actionPerformed(ActionEvent e)
827 outline_actionPerformed();
830 nucleotideMenuItem.setText("Nucleotide");
831 nucleotideMenuItem.addActionListener(new ActionListener()
833 public void actionPerformed(ActionEvent e)
835 nucleotideMenuItem_actionPerformed();
838 colourMenu.setText("Group Colour");
839 showBoxes.setText("Boxes");
840 showBoxes.setState(true);
841 showBoxes.addActionListener(new ActionListener()
843 public void actionPerformed(ActionEvent e)
845 showBoxes_actionPerformed();
848 showText.setText("Text");
849 showText.setState(true);
850 showText.addActionListener(new ActionListener()
852 public void actionPerformed(ActionEvent e)
854 showText_actionPerformed();
857 showColourText.setText("Colour Text");
858 showColourText.addActionListener(new ActionListener()
860 public void actionPerformed(ActionEvent e)
862 showColourText_actionPerformed();
865 displayNonconserved.setText("Show Nonconserved");
866 displayNonconserved.setState(true);
867 displayNonconserved.addActionListener(new ActionListener()
869 public void actionPerformed(ActionEvent e)
871 showNonconserved_actionPerformed();
874 editMenu.setText("Edit");
876 cut.addActionListener(new ActionListener()
878 public void actionPerformed(ActionEvent e)
880 cut_actionPerformed();
883 upperCase.setText("To Upper Case");
884 upperCase.addActionListener(new ActionListener()
886 public void actionPerformed(ActionEvent e)
891 copy.setText("Copy");
892 copy.addActionListener(new ActionListener()
894 public void actionPerformed(ActionEvent e)
896 copy_actionPerformed();
899 lowerCase.setText("To Lower Case");
900 lowerCase.addActionListener(new ActionListener()
902 public void actionPerformed(ActionEvent e)
907 toggle.setText("Toggle Case");
908 toggle.addActionListener(new ActionListener()
910 public void actionPerformed(ActionEvent e)
915 pdbMenu.setText("Associate Structure with Sequence");
916 pdbFromFile.setText("From File");
917 pdbFromFile.addActionListener(new ActionListener()
919 public void actionPerformed(ActionEvent e)
921 pdbFromFile_actionPerformed();
924 enterPDB.setText("Enter PDB Id");
925 enterPDB.addActionListener(new ActionListener()
927 public void actionPerformed(ActionEvent e)
929 enterPDB_actionPerformed();
932 discoverPDB.setText("Discover PDB ids");
933 discoverPDB.addActionListener(new ActionListener()
935 public void actionPerformed(ActionEvent e)
937 discoverPDB_actionPerformed();
940 outputMenu.setText("Output to Textbox...");
941 sequenceFeature.setText("Create Sequence Feature");
942 sequenceFeature.addActionListener(new ActionListener()
944 public void actionPerformed(ActionEvent e)
946 sequenceFeature_actionPerformed();
949 textColour.setText("Text Colour");
950 textColour.addActionListener(new ActionListener()
952 public void actionPerformed(ActionEvent e)
954 textColour_actionPerformed();
957 jMenu1.setText("Group");
958 structureMenu.setText("Structure");
959 viewStructureMenu.setText("View Structure");
960 // colStructureMenu.setText("Colour By Structure");
961 editSequence.setText("Edit Sequence...");
962 editSequence.addActionListener(new ActionListener()
964 public void actionPerformed(ActionEvent actionEvent)
966 editSequence_actionPerformed(actionEvent);
970 * annotationMenuItem.setText("By Annotation");
971 * annotationMenuItem.addActionListener(new ActionListener() { public void
972 * actionPerformed(ActionEvent actionEvent) {
973 * annotationMenuItem_actionPerformed(actionEvent); } });
979 this.add(structureMenu);
980 groupMenu.add(editMenu);
981 groupMenu.add(outputMenu);
982 groupMenu.add(sequenceFeature);
983 groupMenu.add(jMenu1);
984 sequenceMenu.add(sequenceName);
985 colourMenu.add(textColour);
986 colourMenu.add(noColourmenuItem);
987 colourMenu.add(clustalColour);
988 colourMenu.add(BLOSUM62Colour);
989 colourMenu.add(PIDColour);
990 colourMenu.add(zappoColour);
991 colourMenu.add(taylorColour);
992 colourMenu.add(hydrophobicityColour);
993 colourMenu.add(helixColour);
994 colourMenu.add(strandColour);
995 colourMenu.add(turnColour);
996 colourMenu.add(buriedColour);
997 colourMenu.add(nucleotideMenuItem);
998 colourMenu.add(userDefinedColour);
1000 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1002 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1003 .getUserColourSchemes().keys();
1005 while (userColours.hasMoreElements())
1007 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1008 item.addActionListener(new ActionListener()
1010 public void actionPerformed(ActionEvent evt)
1012 userDefinedColour_actionPerformed(evt);
1015 colourMenu.add(item);
1019 colourMenu.addSeparator();
1020 colourMenu.add(abovePIDColour);
1021 colourMenu.add(conservationMenuItem);
1022 // colourMenu.add(annotationMenuItem);
1025 editMenu.add(editSequence);
1026 editMenu.add(upperCase);
1027 editMenu.add(lowerCase);
1028 editMenu.add(toggle);
1029 pdbMenu.add(pdbFromFile);
1030 pdbMenu.add(enterPDB);
1031 pdbMenu.add(discoverPDB);
1032 jMenu1.add(groupName);
1033 jMenu1.add(unGroupMenuItem);
1034 jMenu1.add(colourMenu);
1035 jMenu1.add(showBoxes);
1036 jMenu1.add(showText);
1037 jMenu1.add(showColourText);
1038 jMenu1.add(outline);
1039 jMenu1.add(displayNonconserved);
1040 structureMenu.add(pdbMenu);
1041 structureMenu.add(viewStructureMenu);
1042 // structureMenu.add(colStructureMenu);
1043 noColourmenuItem.setText("None");
1044 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1046 public void actionPerformed(ActionEvent e)
1048 noColourmenuItem_actionPerformed();
1052 clustalColour.setText("Clustalx colours");
1053 clustalColour.addActionListener(new java.awt.event.ActionListener()
1055 public void actionPerformed(ActionEvent e)
1057 clustalColour_actionPerformed();
1060 zappoColour.setText("Zappo");
1061 zappoColour.addActionListener(new java.awt.event.ActionListener()
1063 public void actionPerformed(ActionEvent e)
1065 zappoColour_actionPerformed();
1068 taylorColour.setText("Taylor");
1069 taylorColour.addActionListener(new java.awt.event.ActionListener()
1071 public void actionPerformed(ActionEvent e)
1073 taylorColour_actionPerformed();
1076 hydrophobicityColour.setText("Hydrophobicity");
1077 hydrophobicityColour
1078 .addActionListener(new java.awt.event.ActionListener()
1080 public void actionPerformed(ActionEvent e)
1082 hydrophobicityColour_actionPerformed();
1085 helixColour.setText("Helix propensity");
1086 helixColour.addActionListener(new java.awt.event.ActionListener()
1088 public void actionPerformed(ActionEvent e)
1090 helixColour_actionPerformed();
1093 strandColour.setText("Strand propensity");
1094 strandColour.addActionListener(new java.awt.event.ActionListener()
1096 public void actionPerformed(ActionEvent e)
1098 strandColour_actionPerformed();
1101 turnColour.setText("Turn propensity");
1102 turnColour.addActionListener(new java.awt.event.ActionListener()
1104 public void actionPerformed(ActionEvent e)
1106 turnColour_actionPerformed();
1109 buriedColour.setText("Buried Index");
1110 buriedColour.addActionListener(new java.awt.event.ActionListener()
1112 public void actionPerformed(ActionEvent e)
1114 buriedColour_actionPerformed();
1117 abovePIDColour.setText("Above % Identity");
1118 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1120 public void actionPerformed(ActionEvent e)
1122 abovePIDColour_actionPerformed();
1125 userDefinedColour.setText("User Defined...");
1126 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1128 public void actionPerformed(ActionEvent e)
1130 userDefinedColour_actionPerformed(e);
1133 PIDColour.setText("Percentage Identity");
1134 PIDColour.addActionListener(new java.awt.event.ActionListener()
1136 public void actionPerformed(ActionEvent e)
1138 PIDColour_actionPerformed();
1141 BLOSUM62Colour.setText("BLOSUM62");
1142 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1144 public void actionPerformed(ActionEvent e)
1146 BLOSUM62Colour_actionPerformed();
1149 conservationMenuItem.setText("Conservation");
1150 conservationMenuItem
1151 .addActionListener(new java.awt.event.ActionListener()
1153 public void actionPerformed(ActionEvent e)
1155 conservationMenuItem_actionPerformed();
1160 protected void showNonconserved_actionPerformed()
1162 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1167 * call to refresh view after settings change
1171 ap.updateAnnotation();
1172 ap.paintAlignment(true);
1174 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1183 protected void clustalColour_actionPerformed()
1185 SequenceGroup sg = getGroup();
1186 sg.cs = new ClustalxColourScheme(
1187 sg.getSequences(ap.av.hiddenRepSequences),
1188 ap.av.alignment.getWidth());
1198 protected void zappoColour_actionPerformed()
1200 getGroup().cs = new ZappoColourScheme();
1210 protected void taylorColour_actionPerformed()
1212 getGroup().cs = new TaylorColourScheme();
1222 protected void hydrophobicityColour_actionPerformed()
1224 getGroup().cs = new HydrophobicColourScheme();
1234 protected void helixColour_actionPerformed()
1236 getGroup().cs = new HelixColourScheme();
1246 protected void strandColour_actionPerformed()
1248 getGroup().cs = new StrandColourScheme();
1258 protected void turnColour_actionPerformed()
1260 getGroup().cs = new TurnColourScheme();
1270 protected void buriedColour_actionPerformed()
1272 getGroup().cs = new BuriedColourScheme();
1282 public void nucleotideMenuItem_actionPerformed()
1284 getGroup().cs = new NucleotideColourScheme();
1294 protected void abovePIDColour_actionPerformed()
1296 SequenceGroup sg = getGroup();
1302 if (abovePIDColour.isSelected())
1304 sg.cs.setConsensus(AAFrequency.calculate(
1305 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1306 sg.getEndRes() + 1));
1308 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1311 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1313 SliderPanel.showPIDSlider();
1316 // remove PIDColouring
1318 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1330 protected void userDefinedColour_actionPerformed(ActionEvent e)
1332 SequenceGroup sg = getGroup();
1334 if (e.getActionCommand().equals("User Defined..."))
1336 new UserDefinedColours(ap, sg);
1340 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1341 .getUserColourSchemes().get(e.getActionCommand());
1354 protected void PIDColour_actionPerformed()
1356 SequenceGroup sg = getGroup();
1357 sg.cs = new PIDColourScheme();
1358 sg.cs.setConsensus(AAFrequency.calculate(
1359 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1360 sg.getEndRes() + 1));
1370 protected void BLOSUM62Colour_actionPerformed()
1372 SequenceGroup sg = getGroup();
1374 sg.cs = new Blosum62ColourScheme();
1376 sg.cs.setConsensus(AAFrequency.calculate(
1377 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1378 sg.getEndRes() + 1));
1389 protected void noColourmenuItem_actionPerformed()
1391 getGroup().cs = null;
1401 protected void conservationMenuItem_actionPerformed()
1403 SequenceGroup sg = getGroup();
1409 if (conservationMenuItem.isSelected())
1411 Conservation c = new Conservation("Group",
1412 ResidueProperties.propHash, 3,
1413 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1414 sg.getEndRes() + 1);
1417 c.verdict(false, ap.av.ConsPercGaps);
1419 sg.cs.setConservation(c);
1421 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1422 SliderPanel.showConservationSlider();
1425 // remove ConservationColouring
1427 sg.cs.setConservation(null);
1433 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1435 SequenceGroup sg = getGroup();
1441 AnnotationColourGradient acg = new AnnotationColourGradient(
1442 sequence.getAnnotation()[0], null,
1443 AnnotationColourGradient.NO_THRESHOLD);
1445 acg.predefinedColours = true;
1457 protected void groupName_actionPerformed()
1460 SequenceGroup sg = getGroup();
1461 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1462 sg.getDescription(), " Group Name ",
1463 "Group Description ", "Edit Group Name/Description",
1471 sg.setName(dialog.getName());
1472 sg.setDescription(dialog.getDescription());
1477 * Get selection group - adding it to the alignment if necessary.
1479 * @return sequence group to operate on
1481 SequenceGroup getGroup()
1483 SequenceGroup sg = ap.av.getSelectionGroup();
1484 // this method won't add a new group if it already exists
1487 ap.av.alignment.addGroup(sg);
1499 void sequenceName_actionPerformed()
1501 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1502 sequence.getDescription(), " Sequence Name ",
1503 "Sequence Description ", "Edit Sequence Name/Description",
1511 if (dialog.getName() != null)
1513 if (dialog.getName().indexOf(" ") > -1)
1515 JOptionPane.showMessageDialog(ap,
1516 "Spaces have been converted to \"_\"",
1517 "No spaces allowed in Sequence Name",
1518 JOptionPane.WARNING_MESSAGE);
1521 sequence.setName(dialog.getName().replace(' ', '_'));
1522 ap.paintAlignment(false);
1525 sequence.setDescription(dialog.getDescription());
1527 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1538 void unGroupMenuItem_actionPerformed()
1540 SequenceGroup sg = ap.av.getSelectionGroup();
1541 ap.av.alignment.deleteGroup(sg);
1542 ap.av.setSelectionGroup(null);
1552 protected void outline_actionPerformed()
1554 SequenceGroup sg = getGroup();
1555 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1560 sg.setOutlineColour(col);
1572 public void showBoxes_actionPerformed()
1574 getGroup().setDisplayBoxes(showBoxes.isSelected());
1584 public void showText_actionPerformed()
1586 getGroup().setDisplayText(showText.isSelected());
1596 public void showColourText_actionPerformed()
1598 getGroup().setColourText(showColourText.isSelected());
1602 public void showLink(String url)
1606 jalview.util.BrowserLauncher.openURL(url);
1607 } catch (Exception ex)
1610 .showInternalMessageDialog(
1612 "Unixers: Couldn't find default web browser."
1613 + "\nAdd the full path to your browser in Preferences.",
1614 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1616 ex.printStackTrace();
1620 void hideSequences(boolean representGroup)
1622 SequenceGroup sg = ap.av.getSelectionGroup();
1623 if (sg == null || sg.getSize() < 1)
1625 ap.av.hideSequence(new SequenceI[]
1630 ap.av.setSelectionGroup(null);
1634 ap.av.hideRepSequences(sequence, sg);
1639 int gsize = sg.getSize();
1642 hseqs = new SequenceI[gsize];
1645 for (int i = 0; i < gsize; i++)
1647 hseqs[index++] = sg.getSequenceAt(i);
1650 ap.av.hideSequence(hseqs);
1651 // refresh(); TODO: ? needed ?
1652 ap.av.sendSelection();
1655 public void copy_actionPerformed()
1657 ap.alignFrame.copy_actionPerformed(null);
1660 public void cut_actionPerformed()
1662 ap.alignFrame.cut_actionPerformed(null);
1665 void changeCase(ActionEvent e)
1667 Object source = e.getSource();
1668 SequenceGroup sg = ap.av.getSelectionGroup();
1672 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1673 sg.getEndRes() + 1);
1678 if (source == toggle)
1680 description = "Toggle Case";
1681 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1683 else if (source == upperCase)
1685 description = "To Upper Case";
1686 caseChange = ChangeCaseCommand.TO_UPPER;
1690 description = "To Lower Case";
1691 caseChange = ChangeCaseCommand.TO_LOWER;
1694 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1695 sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1698 ap.alignFrame.addHistoryItem(caseCommand);
1700 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1706 public void outputText_actionPerformed(ActionEvent e)
1708 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1709 cap.setForInput(null);
1710 Desktop.addInternalFrame(cap,
1711 "Alignment output - " + e.getActionCommand(), 600, 500);
1713 String[] omitHidden = null;
1715 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1716 // or we simply trust the user wants
1717 // wysiwig behaviour
1718 SequenceGroup sg = ap.av.getSelectionGroup();
1719 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1720 omitHidden = ap.av.getViewAsString(true);
1721 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1722 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1725 for (int i = 0; i < nala.length; i++)
1727 AlignmentAnnotation na = nala[i];
1728 oal.addAnnotation(na);
1731 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1732 oal, omitHidden, csel, sg));
1736 public void pdbFromFile_actionPerformed()
1738 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1739 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1740 chooser.setFileView(new jalview.io.JalviewFileView());
1741 chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
1742 chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
1744 int value = chooser.showOpenDialog(null);
1746 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1748 String choice = chooser.getSelectedFile().getPath();
1749 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1750 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
1755 public void enterPDB_actionPerformed()
1757 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1758 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1760 if (id != null && id.length() > 0)
1762 PDBEntry entry = new PDBEntry();
1763 entry.setId(id.toUpperCase());
1764 sequence.getDatasetSequence().addPDBId(entry);
1768 public void discoverPDB_actionPerformed()
1771 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1773 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1774 Thread discpdb = new Thread(new Runnable()
1779 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1780 .fetchDBRefs(false);
1787 public void sequenceFeature_actionPerformed()
1789 SequenceGroup sg = ap.av.getSelectionGroup();
1795 int rsize = 0, gSize = sg.getSize();
1796 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1797 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1799 for (int i = 0; i < gSize; i++)
1801 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1802 int end = sg.findEndRes(sg.getSequenceAt(i));
1805 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1806 features[rsize] = new SequenceFeature(null, null, null, start, end,
1811 rseqs = new SequenceI[rsize];
1812 tfeatures = new SequenceFeature[rsize];
1813 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1814 System.arraycopy(features, 0, tfeatures, 0, rsize);
1815 features = tfeatures;
1817 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1818 features, true, ap))
1820 ap.alignFrame.setShowSeqFeatures(true);
1821 ap.highlightSearchResults(null);
1825 public void textColour_actionPerformed()
1827 SequenceGroup sg = getGroup();
1830 new TextColourChooser().chooseColour(ap, sg);
1834 public void colourByStructure(String pdbid)
1836 Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure(
1839 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1840 "Coloured by " + pdbid, anots);
1842 ap.av.alignment.addAnnotation(an);
1843 an.createSequenceMapping(sequence, 0, true);
1844 // an.adjustForAlignment();
1845 ap.av.alignment.setAnnotationIndex(an, 0);
1847 ap.adjustAnnotationHeight();
1849 sequence.addAlignmentAnnotation(an);
1853 public void editSequence_actionPerformed(ActionEvent actionEvent)
1855 SequenceGroup sg = ap.av.getSelectionGroup();
1859 if (sequence == null)
1860 sequence = (Sequence) sg.getSequenceAt(0);
1862 EditNameDialog dialog = new EditNameDialog(
1863 sequence.getSequenceAsString(sg.getStartRes(),
1864 sg.getEndRes() + 1), null, "Edit Sequence ", null,
1865 "Edit Sequence", ap.alignFrame);
1869 EditCommand editCommand = new EditCommand("Edit Sequences",
1870 EditCommand.REPLACE, dialog.getName().replace(' ',
1871 ap.av.getGapCharacter()),
1872 sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1873 sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1875 ap.alignFrame.addHistoryItem(editCommand);
1877 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()