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 structureMenu.remove(viewStructureMenu);
258 // structureMenu.remove(colStructureMenu);
261 menuItem = new JMenuItem("Hide Sequences");
262 menuItem.addActionListener(new java.awt.event.ActionListener()
264 public void actionPerformed(ActionEvent e)
266 hideSequences(false);
271 if (ap.av.getSelectionGroup() != null
272 && ap.av.getSelectionGroup().getSize() > 1)
274 menuItem = new JMenuItem("Represent Group with " + seq.getName());
275 menuItem.addActionListener(new java.awt.event.ActionListener()
277 public void actionPerformed(ActionEvent e)
282 sequenceMenu.add(menuItem);
285 if (ap.av.hasHiddenRows)
287 final int index = ap.av.alignment.findIndex(seq);
289 if (ap.av.adjustForHiddenSeqs(index)
290 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
292 menuItem = new JMenuItem("Reveal Sequences");
293 menuItem.addActionListener(new ActionListener()
295 public void actionPerformed(ActionEvent e)
297 ap.av.showSequence(index);
298 if (ap.overviewPanel != null)
300 ap.overviewPanel.updateOverviewImage();
307 menuItem = new JMenuItem("Reveal All");
308 menuItem.addActionListener(new ActionListener()
310 public void actionPerformed(ActionEvent e)
312 ap.av.showAllHiddenSeqs();
313 if (ap.overviewPanel != null)
315 ap.overviewPanel.updateOverviewImage();
325 SequenceGroup sg = ap.av.getSelectionGroup();
329 groupName.setText("Name: "+sg.getName());
330 groupName.setText("Edit name and description of current group.");
332 if (sg.cs instanceof ZappoColourScheme)
334 zappoColour.setSelected(true);
336 else if (sg.cs instanceof TaylorColourScheme)
338 taylorColour.setSelected(true);
340 else if (sg.cs instanceof PIDColourScheme)
342 PIDColour.setSelected(true);
344 else if (sg.cs instanceof Blosum62ColourScheme)
346 BLOSUM62Colour.setSelected(true);
348 else if (sg.cs instanceof UserColourScheme)
350 userDefinedColour.setSelected(true);
352 else if (sg.cs instanceof HydrophobicColourScheme)
354 hydrophobicityColour.setSelected(true);
356 else if (sg.cs instanceof HelixColourScheme)
358 helixColour.setSelected(true);
360 else if (sg.cs instanceof StrandColourScheme)
362 strandColour.setSelected(true);
364 else if (sg.cs instanceof TurnColourScheme)
366 turnColour.setSelected(true);
368 else if (sg.cs instanceof BuriedColourScheme)
370 buriedColour.setSelected(true);
372 else if (sg.cs instanceof ClustalxColourScheme)
374 clustalColour.setSelected(true);
376 else if (sg.cs instanceof PurinePyrimidineColourScheme)
378 purinePyrimidineColour.setSelected(true);
380 /* else if (sg.cs instanceof CovariationColourScheme)
382 covariationColour.setSelected(true);
386 noColourmenuItem.setSelected(true);
389 if (sg.cs != null && sg.cs.conservationApplied())
391 conservationMenuItem.setSelected(true);
393 displayNonconserved.setSelected(sg.getShowNonconserved());
394 showText.setSelected(sg.getDisplayText());
395 showColourText.setSelected(sg.getColourText());
396 showBoxes.setSelected(sg.getDisplayBoxes());
397 // add any groupURLs to the groupURL submenu and make it visible
398 if (groupLinks != null && groupLinks.size() > 0)
400 buildGroupURLMenu(sg, groupLinks);
402 // Add a 'show all structures' for the current selection
403 Hashtable<String, PDBEntry> pdbe=new Hashtable<String,PDBEntry>();
404 for (SequenceI sq: ap.av.getSequenceSelection())
406 Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence().getPDBId();
408 for (PDBEntry pe: pes)
410 pdbe.put(pe.getId(), pe);
416 final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]);
417 final JMenuItem gpdbview;
418 structureMenu.add(gpdbview=new JMenuItem("View "+pdbe.size()+" structures."));
419 gpdbview.setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment.");
420 gpdbview.addActionListener(new ActionListener()
424 public void actionPerformed(ActionEvent e)
426 new AppJmol(ap, pe, ap.av.collateForPDB(pe));
433 groupMenu.setVisible(false);
434 editMenu.setVisible(false);
437 if (!ap.av.alignment.getGroups().contains(sg))
439 unGroupMenuItem.setVisible(false);
444 sequenceMenu.setVisible(false);
445 structureMenu.setVisible(false);
448 if (links != null && links.size() > 0)
451 JMenu linkMenu = new JMenu("Link");
452 Vector linkset = new Vector();
453 for (int i = 0; i < links.size(); i++)
455 String link = links.elementAt(i).toString();
456 UrlLink urlLink = null;
459 urlLink = new UrlLink(link);
460 } catch (Exception foo)
462 jalview.bin.Cache.log.error("Exception for URLLink '" + link
467 if (!urlLink.isValid())
469 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
472 final String label = urlLink.getLabel();
473 if (urlLink.isDynamic())
476 // collect matching db-refs
477 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
478 seq.getDBRef(), new String[]
479 { urlLink.getTarget() });
480 // collect id string too
481 String id = seq.getName();
482 String descr = seq.getDescription();
483 if (descr != null && descr.length() < 1)
490 for (int r = 0; r < dbr.length; r++)
492 if (id != null && dbr[r].getAccessionId().equals(id))
494 // suppress duplicate link creation for the bare sequence ID
495 // string with this link
498 // create Bare ID link for this RUL
499 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
503 for (int u = 0; u < urls.length; u += 2)
505 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
507 linkset.addElement(urls[u] + "|" + urls[u + 1]);
508 addshowLink(linkMenu, label + "|" + urls[u],
517 // create Bare ID link for this RUL
518 String[] urls = urlLink.makeUrls(id, true);
521 for (int u = 0; u < urls.length; u += 2)
523 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
525 linkset.addElement(urls[u] + "|" + urls[u + 1]);
526 addshowLink(linkMenu, label, urls[u + 1]);
531 // Create urls from description but only for URL links which are regex
533 if (descr != null && urlLink.getRegexReplace() != null)
535 // create link for this URL from description where regex matches
536 String[] urls = urlLink.makeUrls(descr, true);
539 for (int u = 0; u < urls.length; u += 2)
541 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
543 linkset.addElement(urls[u] + "|" + urls[u + 1]);
544 addshowLink(linkMenu, label, urls[u + 1]);
552 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
554 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
555 // Add a non-dynamic link
556 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
560 if (sequence != null)
562 sequenceMenu.add(linkMenu);
571 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
574 // TODO: usability: thread off the generation of group url content so root
576 // sequence only URLs
577 // ID/regex match URLs
578 groupLinksMenu = new JMenu("Group Link");
579 JMenu[] linkMenus = new JMenu[]
580 { null, new JMenu("IDS"), new JMenu("Sequences"),
581 new JMenu("IDS and Sequences") }; // three types of url that might be
583 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
584 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
585 Hashtable commonDbrefs = new Hashtable();
586 for (int sq = 0; sq < seqs.length; sq++)
589 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
590 .findPosition(sg.getEndRes());
591 // just collect ids from dataset sequence
592 // TODO: check if IDs collected from selecton group intersects with the
593 // current selection, too
594 SequenceI sqi = seqs[sq];
595 while (sqi.getDatasetSequence() != null)
597 sqi = sqi.getDatasetSequence();
599 DBRefEntry[] dbr = sqi.getDBRef();
600 if (dbr != null && dbr.length > 0)
602 for (int d = 0; d < dbr.length; d++)
604 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
605 Object[] sarray = (Object[]) commonDbrefs.get(src);
608 sarray = new Object[2];
609 sarray[0] = new int[]
611 sarray[1] = new String[seqs.length];
613 commonDbrefs.put(src, sarray);
616 if (((String[]) sarray[1])[sq] == null)
619 || (dbr[d].getMap().locateMappedRange(start, end) != null))
621 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
622 ((int[]) sarray[0])[0]++;
628 // now create group links for all distinct ID/sequence sets.
629 boolean addMenu = false; // indicates if there are any group links to give
631 for (int i = 0; i < groupLinks.size(); i++)
633 String link = groupLinks.elementAt(i).toString();
634 GroupUrlLink urlLink = null;
637 urlLink = new GroupUrlLink(link);
638 } catch (Exception foo)
640 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
645 if (!urlLink.isValid())
647 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
650 final String label = urlLink.getLabel();
651 boolean usingNames = false;
652 // Now see which parts of the group apply for this URL
653 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
654 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
655 String[] seqstr, ids; // input to makeUrl
658 int numinput = ((int[]) idset[0])[0];
659 String[] allids = ((String[]) idset[1]);
660 seqstr = new String[numinput];
661 ids = new String[numinput];
662 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
664 if (allids[sq] != null)
666 ids[idcount] = allids[sq];
667 seqstr[idcount++] = idandseqs[1][sq];
673 // just use the id/seq set
674 seqstr = idandseqs[1];
678 // and try and make the groupURL!
680 Object[] urlset = null;
683 urlset = urlLink.makeUrlStubs(ids, seqstr,
684 "FromJalview" + System.currentTimeMillis(), false);
685 } catch (UrlStringTooLongException e)
690 int type = urlLink.getGroupURLType() & 3;
691 // System.out.println(urlLink.getGroupURLType()
692 // +" "+((String[])urlset[3])[0]);
693 // first two bits ofurlLink type bitfield are sequenceids and sequences
694 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
695 addshowLink(linkMenus[type], label
696 + (((type & 1) == 1) ? ("("
697 + (usingNames ? "Names" : ltarget) + ")") : ""),
704 groupLinksMenu = new JMenu("Group Links");
705 for (int m = 0; m < linkMenus.length; m++)
707 if (linkMenus[m] != null
708 && linkMenus[m].getMenuComponentCount() > 0)
710 groupLinksMenu.add(linkMenus[m]);
714 groupMenu.add(groupLinksMenu);
719 * add a show URL menu item to the given linkMenu
723 * - menu label string
727 private void addshowLink(JMenu linkMenu, String label, final String url)
729 JMenuItem item = new JMenuItem(label);
730 item.setToolTipText("open URL: " + url);
731 item.addActionListener(new java.awt.event.ActionListener()
733 public void actionPerformed(ActionEvent e)
735 new Thread(new Runnable()
751 * add a late bound groupURL item to the given linkMenu
755 * - menu label string
756 * @param urlgenerator
757 * GroupURLLink used to generate URL
759 * Object array returned from the makeUrlStubs function.
761 private void addshowLink(JMenu linkMenu, String label,
762 final GroupUrlLink urlgenerator, final Object[] urlstub)
764 JMenuItem item = new JMenuItem(label);
765 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
766 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
775 item.addActionListener(new java.awt.event.ActionListener()
777 public void actionPerformed(ActionEvent e)
779 new Thread(new Runnable()
786 showLink(urlgenerator.constructFrom(urlstub));
787 } catch (UrlStringTooLongException e)
805 private void jbInit() throws Exception
807 groupMenu.setText("Group");
808 groupMenu.setText("Selection");
809 groupName.setText("Name");
810 groupName.addActionListener(new java.awt.event.ActionListener()
812 public void actionPerformed(ActionEvent e)
814 groupName_actionPerformed();
817 sequenceMenu.setText("Sequence");
818 sequenceName.setText("Edit Name/Description");
819 sequenceName.addActionListener(new java.awt.event.ActionListener()
821 public void actionPerformed(ActionEvent e)
823 sequenceName_actionPerformed();
826 PIDColour.setFocusPainted(false);
827 unGroupMenuItem.setText("Remove Group");
828 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
830 public void actionPerformed(ActionEvent e)
832 unGroupMenuItem_actionPerformed();
836 outline.setText("Border colour");
837 outline.addActionListener(new java.awt.event.ActionListener()
839 public void actionPerformed(ActionEvent e)
841 outline_actionPerformed();
844 nucleotideMenuItem.setText("Nucleotide");
845 nucleotideMenuItem.addActionListener(new ActionListener()
847 public void actionPerformed(ActionEvent e)
849 nucleotideMenuItem_actionPerformed();
852 colourMenu.setText("Group Colour");
853 showBoxes.setText("Boxes");
854 showBoxes.setState(true);
855 showBoxes.addActionListener(new ActionListener()
857 public void actionPerformed(ActionEvent e)
859 showBoxes_actionPerformed();
862 showText.setText("Text");
863 showText.setState(true);
864 showText.addActionListener(new ActionListener()
866 public void actionPerformed(ActionEvent e)
868 showText_actionPerformed();
871 showColourText.setText("Colour Text");
872 showColourText.addActionListener(new ActionListener()
874 public void actionPerformed(ActionEvent e)
876 showColourText_actionPerformed();
879 displayNonconserved.setText("Show Nonconserved");
880 displayNonconserved.setState(true);
881 displayNonconserved.addActionListener(new ActionListener()
883 public void actionPerformed(ActionEvent e)
885 showNonconserved_actionPerformed();
888 editMenu.setText("Edit");
890 cut.addActionListener(new ActionListener()
892 public void actionPerformed(ActionEvent e)
894 cut_actionPerformed();
897 upperCase.setText("To Upper Case");
898 upperCase.addActionListener(new ActionListener()
900 public void actionPerformed(ActionEvent e)
905 copy.setText("Copy");
906 copy.addActionListener(new ActionListener()
908 public void actionPerformed(ActionEvent e)
910 copy_actionPerformed();
913 lowerCase.setText("To Lower Case");
914 lowerCase.addActionListener(new ActionListener()
916 public void actionPerformed(ActionEvent e)
921 toggle.setText("Toggle Case");
922 toggle.addActionListener(new ActionListener()
924 public void actionPerformed(ActionEvent e)
929 pdbMenu.setText("Associate Structure with Sequence");
930 pdbFromFile.setText("From File");
931 pdbFromFile.addActionListener(new ActionListener()
933 public void actionPerformed(ActionEvent e)
935 pdbFromFile_actionPerformed();
938 enterPDB.setText("Enter PDB Id");
939 enterPDB.addActionListener(new ActionListener()
941 public void actionPerformed(ActionEvent e)
943 enterPDB_actionPerformed();
946 discoverPDB.setText("Discover PDB ids");
947 discoverPDB.addActionListener(new ActionListener()
949 public void actionPerformed(ActionEvent e)
951 discoverPDB_actionPerformed();
954 outputMenu.setText("Output to Textbox...");
955 sequenceFeature.setText("Create Sequence Feature");
956 sequenceFeature.addActionListener(new ActionListener()
958 public void actionPerformed(ActionEvent e)
960 sequenceFeature_actionPerformed();
963 textColour.setText("Text Colour");
964 textColour.addActionListener(new ActionListener()
966 public void actionPerformed(ActionEvent e)
968 textColour_actionPerformed();
971 jMenu1.setText("Group");
972 structureMenu.setText("Structure");
973 viewStructureMenu.setText("View Structure");
974 // colStructureMenu.setText("Colour By Structure");
975 editSequence.setText("Edit Sequence...");
976 editSequence.addActionListener(new ActionListener()
978 public void actionPerformed(ActionEvent actionEvent)
980 editSequence_actionPerformed(actionEvent);
984 * annotationMenuItem.setText("By Annotation");
985 * annotationMenuItem.addActionListener(new ActionListener() { public void
986 * actionPerformed(ActionEvent actionEvent) {
987 * annotationMenuItem_actionPerformed(actionEvent); } });
993 this.add(structureMenu);
994 groupMenu.add(editMenu);
995 groupMenu.add(outputMenu);
996 groupMenu.add(sequenceFeature);
997 groupMenu.add(jMenu1);
998 sequenceMenu.add(sequenceName);
999 colourMenu.add(textColour);
1000 colourMenu.add(noColourmenuItem);
1001 colourMenu.add(clustalColour);
1002 colourMenu.add(BLOSUM62Colour);
1003 colourMenu.add(PIDColour);
1004 colourMenu.add(zappoColour);
1005 colourMenu.add(taylorColour);
1006 colourMenu.add(hydrophobicityColour);
1007 colourMenu.add(helixColour);
1008 colourMenu.add(strandColour);
1009 colourMenu.add(turnColour);
1010 colourMenu.add(buriedColour);
1011 colourMenu.add(nucleotideMenuItem);
1012 colourMenu.add(purinePyrimidineColour);
1013 //colourMenu.add(covariationColour);
1014 colourMenu.add(userDefinedColour);
1016 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1018 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1019 .getUserColourSchemes().keys();
1021 while (userColours.hasMoreElements())
1023 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1024 item.addActionListener(new ActionListener()
1026 public void actionPerformed(ActionEvent evt)
1028 userDefinedColour_actionPerformed(evt);
1031 colourMenu.add(item);
1035 colourMenu.addSeparator();
1036 colourMenu.add(abovePIDColour);
1037 colourMenu.add(conservationMenuItem);
1038 // colourMenu.add(annotationMenuItem);
1041 editMenu.add(editSequence);
1042 editMenu.add(upperCase);
1043 editMenu.add(lowerCase);
1044 editMenu.add(toggle);
1045 pdbMenu.add(pdbFromFile);
1046 pdbMenu.add(enterPDB);
1047 pdbMenu.add(discoverPDB);
1048 jMenu1.add(groupName);
1049 jMenu1.add(unGroupMenuItem);
1050 jMenu1.add(colourMenu);
1051 jMenu1.add(showBoxes);
1052 jMenu1.add(showText);
1053 jMenu1.add(showColourText);
1054 jMenu1.add(outline);
1055 jMenu1.add(displayNonconserved);
1056 structureMenu.add(pdbMenu);
1057 structureMenu.add(viewStructureMenu);
1058 // structureMenu.add(colStructureMenu);
1059 noColourmenuItem.setText("None");
1060 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1062 public void actionPerformed(ActionEvent e)
1064 noColourmenuItem_actionPerformed();
1068 clustalColour.setText("Clustalx colours");
1069 clustalColour.addActionListener(new java.awt.event.ActionListener()
1071 public void actionPerformed(ActionEvent e)
1073 clustalColour_actionPerformed();
1076 zappoColour.setText("Zappo");
1077 zappoColour.addActionListener(new java.awt.event.ActionListener()
1079 public void actionPerformed(ActionEvent e)
1081 zappoColour_actionPerformed();
1084 taylorColour.setText("Taylor");
1085 taylorColour.addActionListener(new java.awt.event.ActionListener()
1087 public void actionPerformed(ActionEvent e)
1089 taylorColour_actionPerformed();
1092 hydrophobicityColour.setText("Hydrophobicity");
1093 hydrophobicityColour
1094 .addActionListener(new java.awt.event.ActionListener()
1096 public void actionPerformed(ActionEvent e)
1098 hydrophobicityColour_actionPerformed();
1101 helixColour.setText("Helix propensity");
1102 helixColour.addActionListener(new java.awt.event.ActionListener()
1104 public void actionPerformed(ActionEvent e)
1106 helixColour_actionPerformed();
1109 strandColour.setText("Strand propensity");
1110 strandColour.addActionListener(new java.awt.event.ActionListener()
1112 public void actionPerformed(ActionEvent e)
1114 strandColour_actionPerformed();
1117 turnColour.setText("Turn propensity");
1118 turnColour.addActionListener(new java.awt.event.ActionListener()
1120 public void actionPerformed(ActionEvent e)
1122 turnColour_actionPerformed();
1125 buriedColour.setText("Buried Index");
1126 buriedColour.addActionListener(new java.awt.event.ActionListener()
1128 public void actionPerformed(ActionEvent e)
1130 buriedColour_actionPerformed();
1133 abovePIDColour.setText("Above % Identity");
1134 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1136 public void actionPerformed(ActionEvent e)
1138 abovePIDColour_actionPerformed();
1141 userDefinedColour.setText("User Defined...");
1142 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1144 public void actionPerformed(ActionEvent e)
1146 userDefinedColour_actionPerformed(e);
1149 PIDColour.setText("Percentage Identity");
1150 PIDColour.addActionListener(new java.awt.event.ActionListener()
1152 public void actionPerformed(ActionEvent e)
1154 PIDColour_actionPerformed();
1157 BLOSUM62Colour.setText("BLOSUM62");
1158 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1160 public void actionPerformed(ActionEvent e)
1162 BLOSUM62Colour_actionPerformed();
1165 purinePyrimidineColour.setText("Purine/Pyrimidine");
1166 purinePyrimidineColour.addActionListener(new java.awt.event.ActionListener()
1168 public void actionPerformed(ActionEvent e)
1170 purinePyrimidineColour_actionPerformed();
1174 covariationColour.addActionListener(new java.awt.event.ActionListener()
1176 public void actionPerformed(ActionEvent e)
1178 covariationColour_actionPerformed();
1182 conservationMenuItem.setText("Conservation");
1183 conservationMenuItem
1184 .addActionListener(new java.awt.event.ActionListener()
1186 public void actionPerformed(ActionEvent e)
1188 conservationMenuItem_actionPerformed();
1193 protected void showNonconserved_actionPerformed()
1195 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1200 * call to refresh view after settings change
1204 ap.updateAnnotation();
1205 ap.paintAlignment(true);
1207 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1216 protected void clustalColour_actionPerformed()
1218 SequenceGroup sg = getGroup();
1219 sg.cs = new ClustalxColourScheme(
1220 sg.getSequences(ap.av.hiddenRepSequences),
1221 ap.av.alignment.getWidth());
1231 protected void zappoColour_actionPerformed()
1233 getGroup().cs = new ZappoColourScheme();
1243 protected void taylorColour_actionPerformed()
1245 getGroup().cs = new TaylorColourScheme();
1255 protected void hydrophobicityColour_actionPerformed()
1257 getGroup().cs = new HydrophobicColourScheme();
1267 protected void helixColour_actionPerformed()
1269 getGroup().cs = new HelixColourScheme();
1279 protected void strandColour_actionPerformed()
1281 getGroup().cs = new StrandColourScheme();
1291 protected void turnColour_actionPerformed()
1293 getGroup().cs = new TurnColourScheme();
1303 protected void buriedColour_actionPerformed()
1305 getGroup().cs = new BuriedColourScheme();
1315 public void nucleotideMenuItem_actionPerformed()
1317 getGroup().cs = new NucleotideColourScheme();
1321 protected void purinePyrimidineColour_actionPerformed()
1323 getGroup().cs = new PurinePyrimidineColourScheme();
1327 protected void covariationColour_actionPerformed()
1329 getGroup().cs = new CovariationColourScheme(sequence.getAnnotation()[0]);
1339 protected void abovePIDColour_actionPerformed()
1341 SequenceGroup sg = getGroup();
1347 if (abovePIDColour.isSelected())
1349 sg.cs.setConsensus(AAFrequency.calculate(
1350 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1351 sg.getEndRes() + 1));
1353 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1356 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1358 SliderPanel.showPIDSlider();
1361 // remove PIDColouring
1363 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1375 protected void userDefinedColour_actionPerformed(ActionEvent e)
1377 SequenceGroup sg = getGroup();
1379 if (e.getActionCommand().equals("User Defined..."))
1381 new UserDefinedColours(ap, sg);
1385 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1386 .getUserColourSchemes().get(e.getActionCommand());
1399 protected void PIDColour_actionPerformed()
1401 SequenceGroup sg = getGroup();
1402 sg.cs = new PIDColourScheme();
1403 sg.cs.setConsensus(AAFrequency.calculate(
1404 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1405 sg.getEndRes() + 1));
1415 protected void BLOSUM62Colour_actionPerformed()
1417 SequenceGroup sg = getGroup();
1419 sg.cs = new Blosum62ColourScheme();
1421 sg.cs.setConsensus(AAFrequency.calculate(
1422 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1423 sg.getEndRes() + 1));
1434 protected void noColourmenuItem_actionPerformed()
1436 getGroup().cs = null;
1446 protected void conservationMenuItem_actionPerformed()
1448 SequenceGroup sg = getGroup();
1454 if (conservationMenuItem.isSelected())
1456 Conservation c = new Conservation("Group",
1457 ResidueProperties.propHash, 3,
1458 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1459 sg.getEndRes() + 1);
1462 c.verdict(false, ap.av.ConsPercGaps);
1464 sg.cs.setConservation(c);
1466 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1467 SliderPanel.showConservationSlider();
1470 // remove ConservationColouring
1472 sg.cs.setConservation(null);
1478 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1480 SequenceGroup sg = getGroup();
1486 AnnotationColourGradient acg = new AnnotationColourGradient(
1487 sequence.getAnnotation()[0], null,
1488 AnnotationColourGradient.NO_THRESHOLD);
1490 acg.predefinedColours = true;
1502 protected void groupName_actionPerformed()
1505 SequenceGroup sg = getGroup();
1506 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1507 sg.getDescription(), " Group Name ",
1508 "Group Description ", "Edit Group Name/Description",
1516 sg.setName(dialog.getName());
1517 sg.setDescription(dialog.getDescription());
1522 * Get selection group - adding it to the alignment if necessary.
1524 * @return sequence group to operate on
1526 SequenceGroup getGroup()
1528 SequenceGroup sg = ap.av.getSelectionGroup();
1529 // this method won't add a new group if it already exists
1532 ap.av.alignment.addGroup(sg);
1544 void sequenceName_actionPerformed()
1546 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1547 sequence.getDescription(), " Sequence Name ",
1548 "Sequence Description ", "Edit Sequence Name/Description",
1556 if (dialog.getName() != null)
1558 if (dialog.getName().indexOf(" ") > -1)
1560 JOptionPane.showMessageDialog(ap,
1561 "Spaces have been converted to \"_\"",
1562 "No spaces allowed in Sequence Name",
1563 JOptionPane.WARNING_MESSAGE);
1566 sequence.setName(dialog.getName().replace(' ', '_'));
1567 ap.paintAlignment(false);
1570 sequence.setDescription(dialog.getDescription());
1572 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1583 void unGroupMenuItem_actionPerformed()
1585 SequenceGroup sg = ap.av.getSelectionGroup();
1586 ap.av.alignment.deleteGroup(sg);
1587 ap.av.setSelectionGroup(null);
1597 protected void outline_actionPerformed()
1599 SequenceGroup sg = getGroup();
1600 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1605 sg.setOutlineColour(col);
1617 public void showBoxes_actionPerformed()
1619 getGroup().setDisplayBoxes(showBoxes.isSelected());
1629 public void showText_actionPerformed()
1631 getGroup().setDisplayText(showText.isSelected());
1641 public void showColourText_actionPerformed()
1643 getGroup().setColourText(showColourText.isSelected());
1647 public void showLink(String url)
1651 jalview.util.BrowserLauncher.openURL(url);
1652 } catch (Exception ex)
1655 .showInternalMessageDialog(
1657 "Unixers: Couldn't find default web browser."
1658 + "\nAdd the full path to your browser in Preferences.",
1659 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1661 ex.printStackTrace();
1665 void hideSequences(boolean representGroup)
1667 SequenceGroup sg = ap.av.getSelectionGroup();
1668 if (sg == null || sg.getSize() < 1)
1670 ap.av.hideSequence(new SequenceI[]
1675 ap.av.setSelectionGroup(null);
1679 ap.av.hideRepSequences(sequence, sg);
1684 int gsize = sg.getSize();
1687 hseqs = new SequenceI[gsize];
1690 for (int i = 0; i < gsize; i++)
1692 hseqs[index++] = sg.getSequenceAt(i);
1695 ap.av.hideSequence(hseqs);
1696 // refresh(); TODO: ? needed ?
1697 ap.av.sendSelection();
1700 public void copy_actionPerformed()
1702 ap.alignFrame.copy_actionPerformed(null);
1705 public void cut_actionPerformed()
1707 ap.alignFrame.cut_actionPerformed(null);
1710 void changeCase(ActionEvent e)
1712 Object source = e.getSource();
1713 SequenceGroup sg = ap.av.getSelectionGroup();
1717 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1718 sg.getEndRes() + 1);
1723 if (source == toggle)
1725 description = "Toggle Case";
1726 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1728 else if (source == upperCase)
1730 description = "To Upper Case";
1731 caseChange = ChangeCaseCommand.TO_UPPER;
1735 description = "To Lower Case";
1736 caseChange = ChangeCaseCommand.TO_LOWER;
1739 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1740 sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1743 ap.alignFrame.addHistoryItem(caseCommand);
1745 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1751 public void outputText_actionPerformed(ActionEvent e)
1753 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1754 cap.setForInput(null);
1755 Desktop.addInternalFrame(cap,
1756 "Alignment output - " + e.getActionCommand(), 600, 500);
1758 String[] omitHidden = null;
1760 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1761 // or we simply trust the user wants
1762 // wysiwig behaviour
1763 SequenceGroup sg = ap.av.getSelectionGroup();
1764 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1765 omitHidden = ap.av.getViewAsString(true);
1766 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1767 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1770 for (int i = 0; i < nala.length; i++)
1772 AlignmentAnnotation na = nala[i];
1773 oal.addAnnotation(na);
1776 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1777 oal, omitHidden, csel, sg));
1781 public void pdbFromFile_actionPerformed()
1783 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1784 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1785 chooser.setFileView(new jalview.io.JalviewFileView());
1786 chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
1787 chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
1789 int value = chooser.showOpenDialog(null);
1791 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1793 String choice = chooser.getSelectedFile().getPath();
1794 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1795 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
1800 public void enterPDB_actionPerformed()
1802 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1803 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1805 if (id != null && id.length() > 0)
1807 PDBEntry entry = new PDBEntry();
1808 entry.setId(id.toUpperCase());
1809 sequence.getDatasetSequence().addPDBId(entry);
1813 public void discoverPDB_actionPerformed()
1816 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1818 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1819 Thread discpdb = new Thread(new Runnable()
1824 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1825 .fetchDBRefs(false);
1832 public void sequenceFeature_actionPerformed()
1834 SequenceGroup sg = ap.av.getSelectionGroup();
1840 int rsize = 0, gSize = sg.getSize();
1841 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1842 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1844 for (int i = 0; i < gSize; i++)
1846 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1847 int end = sg.findEndRes(sg.getSequenceAt(i));
1850 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1851 features[rsize] = new SequenceFeature(null, null, null, start, end,
1856 rseqs = new SequenceI[rsize];
1857 tfeatures = new SequenceFeature[rsize];
1858 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1859 System.arraycopy(features, 0, tfeatures, 0, rsize);
1860 features = tfeatures;
1862 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1863 features, true, ap))
1865 ap.alignFrame.setShowSeqFeatures(true);
1866 ap.highlightSearchResults(null);
1870 public void textColour_actionPerformed()
1872 SequenceGroup sg = getGroup();
1875 new TextColourChooser().chooseColour(ap, sg);
1879 public void colourByStructure(String pdbid)
1881 Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure(
1884 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1885 "Coloured by " + pdbid, anots);
1887 ap.av.alignment.addAnnotation(an);
1888 an.createSequenceMapping(sequence, 0, true);
1889 // an.adjustForAlignment();
1890 ap.av.alignment.setAnnotationIndex(an, 0);
1892 ap.adjustAnnotationHeight();
1894 sequence.addAlignmentAnnotation(an);
1898 public void editSequence_actionPerformed(ActionEvent actionEvent)
1900 SequenceGroup sg = ap.av.getSelectionGroup();
1904 if (sequence == null)
1905 sequence = (Sequence) sg.getSequenceAt(0);
1907 EditNameDialog dialog = new EditNameDialog(
1908 sequence.getSequenceAsString(sg.getStartRes(),
1909 sg.getEndRes() + 1), null, "Edit Sequence ", null,
1910 "Edit Sequence", ap.alignFrame);
1914 EditCommand editCommand = new EditCommand("Edit Sequences",
1915 EditCommand.REPLACE, dialog.getName().replace(' ',
1916 ap.av.getGapCharacter()),
1917 sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1918 sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1920 ap.alignFrame.addHistoryItem(editCommand);
1922 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()