2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 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 SequenceI sqass=null;
395 for (SequenceI sq: ap.av.getSequenceSelection())
397 Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence().getPDBId();
399 for (PDBEntry pe: pes)
401 pdbe.put(pe.getId(), pe);
411 final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]);
412 final JMenuItem gpdbview;
415 structureMenu.add(gpdbview=new JMenuItem("View structure for "+sqass.getDisplayId(false)));
417 structureMenu.add(gpdbview=new JMenuItem("View all "+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 (seq!=null && 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(userDefinedColour);
1014 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1016 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
1017 .getUserColourSchemes().keys();
1019 while (userColours.hasMoreElements())
1021 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1022 item.addActionListener(new ActionListener()
1024 public void actionPerformed(ActionEvent evt)
1026 userDefinedColour_actionPerformed(evt);
1029 colourMenu.add(item);
1033 colourMenu.addSeparator();
1034 colourMenu.add(abovePIDColour);
1035 colourMenu.add(conservationMenuItem);
1036 // colourMenu.add(annotationMenuItem);
1039 editMenu.add(editSequence);
1040 editMenu.add(upperCase);
1041 editMenu.add(lowerCase);
1042 editMenu.add(toggle);
1043 pdbMenu.add(pdbFromFile);
1044 pdbMenu.add(enterPDB);
1045 pdbMenu.add(discoverPDB);
1046 jMenu1.add(groupName);
1047 jMenu1.add(unGroupMenuItem);
1048 jMenu1.add(colourMenu);
1049 jMenu1.add(showBoxes);
1050 jMenu1.add(showText);
1051 jMenu1.add(showColourText);
1052 jMenu1.add(outline);
1053 jMenu1.add(displayNonconserved);
1054 structureMenu.add(pdbMenu);
1055 structureMenu.add(viewStructureMenu);
1056 // structureMenu.add(colStructureMenu);
1057 noColourmenuItem.setText("None");
1058 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1060 public void actionPerformed(ActionEvent e)
1062 noColourmenuItem_actionPerformed();
1066 clustalColour.setText("Clustalx colours");
1067 clustalColour.addActionListener(new java.awt.event.ActionListener()
1069 public void actionPerformed(ActionEvent e)
1071 clustalColour_actionPerformed();
1074 zappoColour.setText("Zappo");
1075 zappoColour.addActionListener(new java.awt.event.ActionListener()
1077 public void actionPerformed(ActionEvent e)
1079 zappoColour_actionPerformed();
1082 taylorColour.setText("Taylor");
1083 taylorColour.addActionListener(new java.awt.event.ActionListener()
1085 public void actionPerformed(ActionEvent e)
1087 taylorColour_actionPerformed();
1090 hydrophobicityColour.setText("Hydrophobicity");
1091 hydrophobicityColour
1092 .addActionListener(new java.awt.event.ActionListener()
1094 public void actionPerformed(ActionEvent e)
1096 hydrophobicityColour_actionPerformed();
1099 helixColour.setText("Helix propensity");
1100 helixColour.addActionListener(new java.awt.event.ActionListener()
1102 public void actionPerformed(ActionEvent e)
1104 helixColour_actionPerformed();
1107 strandColour.setText("Strand propensity");
1108 strandColour.addActionListener(new java.awt.event.ActionListener()
1110 public void actionPerformed(ActionEvent e)
1112 strandColour_actionPerformed();
1115 turnColour.setText("Turn propensity");
1116 turnColour.addActionListener(new java.awt.event.ActionListener()
1118 public void actionPerformed(ActionEvent e)
1120 turnColour_actionPerformed();
1123 buriedColour.setText("Buried Index");
1124 buriedColour.addActionListener(new java.awt.event.ActionListener()
1126 public void actionPerformed(ActionEvent e)
1128 buriedColour_actionPerformed();
1131 abovePIDColour.setText("Above % Identity");
1132 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1134 public void actionPerformed(ActionEvent e)
1136 abovePIDColour_actionPerformed();
1139 userDefinedColour.setText("User Defined...");
1140 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1142 public void actionPerformed(ActionEvent e)
1144 userDefinedColour_actionPerformed(e);
1147 PIDColour.setText("Percentage Identity");
1148 PIDColour.addActionListener(new java.awt.event.ActionListener()
1150 public void actionPerformed(ActionEvent e)
1152 PIDColour_actionPerformed();
1155 BLOSUM62Colour.setText("BLOSUM62");
1156 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1158 public void actionPerformed(ActionEvent e)
1160 BLOSUM62Colour_actionPerformed();
1163 conservationMenuItem.setText("Conservation");
1164 conservationMenuItem
1165 .addActionListener(new java.awt.event.ActionListener()
1167 public void actionPerformed(ActionEvent e)
1169 conservationMenuItem_actionPerformed();
1174 protected void showNonconserved_actionPerformed()
1176 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1181 * call to refresh view after settings change
1185 ap.updateAnnotation();
1186 ap.paintAlignment(true);
1188 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1197 protected void clustalColour_actionPerformed()
1199 SequenceGroup sg = getGroup();
1200 sg.cs = new ClustalxColourScheme(
1201 sg.getSequences(ap.av.hiddenRepSequences),
1202 ap.av.alignment.getWidth());
1212 protected void zappoColour_actionPerformed()
1214 getGroup().cs = new ZappoColourScheme();
1224 protected void taylorColour_actionPerformed()
1226 getGroup().cs = new TaylorColourScheme();
1236 protected void hydrophobicityColour_actionPerformed()
1238 getGroup().cs = new HydrophobicColourScheme();
1248 protected void helixColour_actionPerformed()
1250 getGroup().cs = new HelixColourScheme();
1260 protected void strandColour_actionPerformed()
1262 getGroup().cs = new StrandColourScheme();
1272 protected void turnColour_actionPerformed()
1274 getGroup().cs = new TurnColourScheme();
1284 protected void buriedColour_actionPerformed()
1286 getGroup().cs = new BuriedColourScheme();
1296 public void nucleotideMenuItem_actionPerformed()
1298 getGroup().cs = new NucleotideColourScheme();
1308 protected void abovePIDColour_actionPerformed()
1310 SequenceGroup sg = getGroup();
1316 if (abovePIDColour.isSelected())
1318 sg.cs.setConsensus(AAFrequency.calculate(
1319 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1320 sg.getEndRes() + 1));
1322 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1325 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1327 SliderPanel.showPIDSlider();
1330 // remove PIDColouring
1332 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1344 protected void userDefinedColour_actionPerformed(ActionEvent e)
1346 SequenceGroup sg = getGroup();
1348 if (e.getActionCommand().equals("User Defined..."))
1350 new UserDefinedColours(ap, sg);
1354 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1355 .getUserColourSchemes().get(e.getActionCommand());
1368 protected void PIDColour_actionPerformed()
1370 SequenceGroup sg = getGroup();
1371 sg.cs = new PIDColourScheme();
1372 sg.cs.setConsensus(AAFrequency.calculate(
1373 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1374 sg.getEndRes() + 1));
1384 protected void BLOSUM62Colour_actionPerformed()
1386 SequenceGroup sg = getGroup();
1388 sg.cs = new Blosum62ColourScheme();
1390 sg.cs.setConsensus(AAFrequency.calculate(
1391 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1392 sg.getEndRes() + 1));
1403 protected void noColourmenuItem_actionPerformed()
1405 getGroup().cs = null;
1415 protected void conservationMenuItem_actionPerformed()
1417 SequenceGroup sg = getGroup();
1423 if (conservationMenuItem.isSelected())
1425 Conservation c = new Conservation("Group",
1426 ResidueProperties.propHash, 3,
1427 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1428 sg.getEndRes() + 1);
1431 c.verdict(false, ap.av.ConsPercGaps);
1433 sg.cs.setConservation(c);
1435 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1436 SliderPanel.showConservationSlider();
1439 // remove ConservationColouring
1441 sg.cs.setConservation(null);
1447 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1449 SequenceGroup sg = getGroup();
1455 AnnotationColourGradient acg = new AnnotationColourGradient(
1456 sequence.getAnnotation()[0], null,
1457 AnnotationColourGradient.NO_THRESHOLD);
1459 acg.predefinedColours = true;
1471 protected void groupName_actionPerformed()
1474 SequenceGroup sg = getGroup();
1475 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1476 sg.getDescription(), " Group Name ",
1477 "Group Description ", "Edit Group Name/Description",
1485 sg.setName(dialog.getName());
1486 sg.setDescription(dialog.getDescription());
1491 * Get selection group - adding it to the alignment if necessary.
1493 * @return sequence group to operate on
1495 SequenceGroup getGroup()
1497 SequenceGroup sg = ap.av.getSelectionGroup();
1498 // this method won't add a new group if it already exists
1501 ap.av.alignment.addGroup(sg);
1513 void sequenceName_actionPerformed()
1515 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1516 sequence.getDescription(), " Sequence Name ",
1517 "Sequence Description ", "Edit Sequence Name/Description",
1525 if (dialog.getName() != null)
1527 if (dialog.getName().indexOf(" ") > -1)
1529 JOptionPane.showMessageDialog(ap,
1530 "Spaces have been converted to \"_\"",
1531 "No spaces allowed in Sequence Name",
1532 JOptionPane.WARNING_MESSAGE);
1535 sequence.setName(dialog.getName().replace(' ', '_'));
1536 ap.paintAlignment(false);
1539 sequence.setDescription(dialog.getDescription());
1541 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1552 void unGroupMenuItem_actionPerformed()
1554 SequenceGroup sg = ap.av.getSelectionGroup();
1555 ap.av.alignment.deleteGroup(sg);
1556 ap.av.setSelectionGroup(null);
1566 protected void outline_actionPerformed()
1568 SequenceGroup sg = getGroup();
1569 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1574 sg.setOutlineColour(col);
1586 public void showBoxes_actionPerformed()
1588 getGroup().setDisplayBoxes(showBoxes.isSelected());
1598 public void showText_actionPerformed()
1600 getGroup().setDisplayText(showText.isSelected());
1610 public void showColourText_actionPerformed()
1612 getGroup().setColourText(showColourText.isSelected());
1616 public void showLink(String url)
1620 jalview.util.BrowserLauncher.openURL(url);
1621 } catch (Exception ex)
1624 .showInternalMessageDialog(
1626 "Unixers: Couldn't find default web browser."
1627 + "\nAdd the full path to your browser in Preferences.",
1628 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1630 ex.printStackTrace();
1634 void hideSequences(boolean representGroup)
1636 SequenceGroup sg = ap.av.getSelectionGroup();
1637 if (sg == null || sg.getSize() < 1)
1639 ap.av.hideSequence(new SequenceI[]
1644 ap.av.setSelectionGroup(null);
1648 ap.av.hideRepSequences(sequence, sg);
1653 int gsize = sg.getSize();
1656 hseqs = new SequenceI[gsize];
1659 for (int i = 0; i < gsize; i++)
1661 hseqs[index++] = sg.getSequenceAt(i);
1664 ap.av.hideSequence(hseqs);
1665 // refresh(); TODO: ? needed ?
1666 ap.av.sendSelection();
1669 public void copy_actionPerformed()
1671 ap.alignFrame.copy_actionPerformed(null);
1674 public void cut_actionPerformed()
1676 ap.alignFrame.cut_actionPerformed(null);
1679 void changeCase(ActionEvent e)
1681 Object source = e.getSource();
1682 SequenceGroup sg = ap.av.getSelectionGroup();
1686 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1687 sg.getEndRes() + 1);
1692 if (source == toggle)
1694 description = "Toggle Case";
1695 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1697 else if (source == upperCase)
1699 description = "To Upper Case";
1700 caseChange = ChangeCaseCommand.TO_UPPER;
1704 description = "To Lower Case";
1705 caseChange = ChangeCaseCommand.TO_LOWER;
1708 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1709 sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1712 ap.alignFrame.addHistoryItem(caseCommand);
1714 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1720 public void outputText_actionPerformed(ActionEvent e)
1722 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1723 cap.setForInput(null);
1724 Desktop.addInternalFrame(cap,
1725 "Alignment output - " + e.getActionCommand(), 600, 500);
1727 String[] omitHidden = null;
1729 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1730 // or we simply trust the user wants
1731 // wysiwig behaviour
1732 SequenceGroup sg = ap.av.getSelectionGroup();
1733 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1734 omitHidden = ap.av.getViewAsString(true);
1735 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1736 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1739 for (int i = 0; i < nala.length; i++)
1741 AlignmentAnnotation na = nala[i];
1742 oal.addAnnotation(na);
1745 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1746 oal, omitHidden, csel, sg));
1750 public void pdbFromFile_actionPerformed()
1752 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1753 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1754 chooser.setFileView(new jalview.io.JalviewFileView());
1755 chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
1756 chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
1758 int value = chooser.showOpenDialog(null);
1760 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1762 String choice = chooser.getSelectedFile().getPath();
1763 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1764 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
1769 public void enterPDB_actionPerformed()
1771 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1772 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1774 if (id != null && id.length() > 0)
1776 PDBEntry entry = new PDBEntry();
1777 entry.setId(id.toUpperCase());
1778 sequence.getDatasetSequence().addPDBId(entry);
1782 public void discoverPDB_actionPerformed()
1785 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1787 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1788 Thread discpdb = new Thread(new Runnable()
1793 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1794 .fetchDBRefs(false);
1801 public void sequenceFeature_actionPerformed()
1803 SequenceGroup sg = ap.av.getSelectionGroup();
1809 int rsize = 0, gSize = sg.getSize();
1810 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1811 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1813 for (int i = 0; i < gSize; i++)
1815 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1816 int end = sg.findEndRes(sg.getSequenceAt(i));
1819 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1820 features[rsize] = new SequenceFeature(null, null, null, start, end,
1825 rseqs = new SequenceI[rsize];
1826 tfeatures = new SequenceFeature[rsize];
1827 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1828 System.arraycopy(features, 0, tfeatures, 0, rsize);
1829 features = tfeatures;
1831 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1832 features, true, ap))
1834 ap.alignFrame.setShowSeqFeatures(true);
1835 ap.highlightSearchResults(null);
1839 public void textColour_actionPerformed()
1841 SequenceGroup sg = getGroup();
1844 new TextColourChooser().chooseColour(ap, sg);
1848 public void colourByStructure(String pdbid)
1850 Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure(
1853 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1854 "Coloured by " + pdbid, anots);
1856 ap.av.alignment.addAnnotation(an);
1857 an.createSequenceMapping(sequence, 0, true);
1858 // an.adjustForAlignment();
1859 ap.av.alignment.setAnnotationIndex(an, 0);
1861 ap.adjustAnnotationHeight();
1863 sequence.addAlignmentAnnotation(an);
1867 public void editSequence_actionPerformed(ActionEvent actionEvent)
1869 SequenceGroup sg = ap.av.getSelectionGroup();
1873 if (sequence == null)
1874 sequence = (Sequence) sg.getSequenceAt(0);
1876 EditNameDialog dialog = new EditNameDialog(
1877 sequence.getSequenceAsString(sg.getStartRes(),
1878 sg.getEndRes() + 1), null, "Edit Sequence ", null,
1879 "Edit Sequence", ap.alignFrame);
1883 EditCommand editCommand = new EditCommand("Edit Sequences",
1884 EditCommand.REPLACE, dialog.getName().replace(' ',
1885 ap.av.getGapCharacter()),
1886 sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1887 sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1889 ap.alignFrame.addHistoryItem(editCommand);
1891 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()