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.*;
27 import jalview.analysis.*;
28 import jalview.commands.*;
29 import jalview.datamodel.*;
31 import jalview.schemes.*;
32 import jalview.util.GroupUrlLink;
33 import jalview.util.GroupUrlLink.UrlStringTooLongException;
34 import jalview.util.UrlLink;
42 public class PopupMenu extends JPopupMenu
44 JMenu groupMenu = new JMenu();
46 JMenuItem groupName = new JMenuItem();
48 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
50 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
52 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
54 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
56 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
58 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
60 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
62 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
64 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
66 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
68 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
70 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
72 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
74 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
78 JMenu sequenceMenu = new JMenu();
80 JMenuItem sequenceName = new JMenuItem();
84 JMenuItem unGroupMenuItem = new JMenuItem();
86 JMenuItem outline = new JMenuItem();
88 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
90 JMenu colourMenu = new JMenu();
92 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
94 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
96 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
98 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
100 JMenu editMenu = new JMenu();
102 JMenuItem cut = new JMenuItem();
104 JMenuItem copy = new JMenuItem();
106 JMenuItem upperCase = new JMenuItem();
108 JMenuItem lowerCase = new JMenuItem();
110 JMenuItem toggle = new JMenuItem();
112 JMenu pdbMenu = new JMenu();
114 JMenuItem pdbFromFile = new JMenuItem();
116 JMenuItem enterPDB = new JMenuItem();
118 JMenuItem discoverPDB = new JMenuItem();
120 JMenu outputMenu = new JMenu();
122 JMenuItem sequenceFeature = new JMenuItem();
124 JMenuItem textColour = new JMenuItem();
126 JMenu jMenu1 = new JMenu();
128 JMenu structureMenu = new JMenu();
130 JMenu viewStructureMenu = new JMenu();
132 // JMenu colStructureMenu = new JMenu();
133 JMenuItem editSequence = new JMenuItem();
135 // JMenuItem annotationMenuItem = new JMenuItem();
137 JMenu groupLinksMenu;
140 * Creates a new PopupMenu object.
147 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
149 this(ap, seq, links, null);
159 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links,
162 // /////////////////////////////////////////////////////////
163 // If this is activated from the sequence panel, the user may want to
164 // edit or annotate a particular residue. Therefore display the residue menu
166 // If from the IDPanel, we must display the sequence menu
167 // ////////////////////////////////////////////////////////
171 ButtonGroup colours = new ButtonGroup();
172 colours.add(noColourmenuItem);
173 colours.add(clustalColour);
174 colours.add(zappoColour);
175 colours.add(taylorColour);
176 colours.add(hydrophobicityColour);
177 colours.add(helixColour);
178 colours.add(strandColour);
179 colours.add(turnColour);
180 colours.add(buriedColour);
181 colours.add(abovePIDColour);
182 colours.add(userDefinedColour);
183 colours.add(PIDColour);
184 colours.add(BLOSUM62Colour);
186 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
188 JMenuItem item = new JMenuItem(
189 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
191 item.addActionListener(new java.awt.event.ActionListener()
193 public void actionPerformed(ActionEvent e)
195 outputText_actionPerformed(e);
199 outputMenu.add(item);
205 } catch (Exception e)
212 sequenceMenu.setText(sequence.getName());
215 if (seq.getDatasetSequence().getPDBId() != null
216 && seq.getDatasetSequence().getPDBId().size() > 0)
218 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
221 while (e.hasMoreElements())
223 final PDBEntry pdb = (PDBEntry) e.nextElement();
225 menuItem = new JMenuItem();
226 menuItem.setText(pdb.getId());
227 menuItem.addActionListener(new java.awt.event.ActionListener()
229 public void actionPerformed(ActionEvent e)
231 Vector seqs = new Vector();
232 for (int i = 0; i < ap.av.alignment.getHeight(); i++)
234 Vector pdbs = ap.av.alignment.getSequenceAt(i)
235 .getDatasetSequence().getPDBId();
239 for (int p = 0; p < pdbs.size(); p++)
241 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
242 if (p1.getId().equals(pdb.getId()))
244 if (!seqs.contains(ap.av.alignment.getSequenceAt(i)))
245 seqs.addElement(ap.av.alignment.getSequenceAt(i));
252 SequenceI[] seqs2 = new SequenceI[seqs.size()];
255 new AppJmol(pdb, seqs2, null, ap);
256 // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
259 viewStructureMenu.add(menuItem);
262 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
263 * menuItem.addActionListener(new java.awt.event.ActionListener() {
264 * public void actionPerformed(ActionEvent e) {
265 * colourByStructure(pdb.getId()); } });
266 * colStructureMenu.add(menuItem);
272 structureMenu.remove(viewStructureMenu);
273 // structureMenu.remove(colStructureMenu);
276 menuItem = new JMenuItem("Hide Sequences");
277 menuItem.addActionListener(new java.awt.event.ActionListener()
279 public void actionPerformed(ActionEvent e)
281 hideSequences(false);
286 if (ap.av.getSelectionGroup() != null
287 && ap.av.getSelectionGroup().getSize() > 1)
289 menuItem = new JMenuItem("Represent Group with " + seq.getName());
290 menuItem.addActionListener(new java.awt.event.ActionListener()
292 public void actionPerformed(ActionEvent e)
297 sequenceMenu.add(menuItem);
300 if (ap.av.hasHiddenRows)
302 final int index = ap.av.alignment.findIndex(seq);
304 if (ap.av.adjustForHiddenSeqs(index)
305 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
307 menuItem = new JMenuItem("Reveal Sequences");
308 menuItem.addActionListener(new ActionListener()
310 public void actionPerformed(ActionEvent e)
312 ap.av.showSequence(index);
313 if (ap.overviewPanel != null)
315 ap.overviewPanel.updateOverviewImage();
322 menuItem = new JMenuItem("Reveal All");
323 menuItem.addActionListener(new ActionListener()
325 public void actionPerformed(ActionEvent e)
327 ap.av.showAllHiddenSeqs();
328 if (ap.overviewPanel != null)
330 ap.overviewPanel.updateOverviewImage();
340 SequenceGroup sg = ap.av.getSelectionGroup();
344 groupName.setText(sg.getName());
346 if (sg.cs instanceof ZappoColourScheme)
348 zappoColour.setSelected(true);
350 else if (sg.cs instanceof TaylorColourScheme)
352 taylorColour.setSelected(true);
354 else if (sg.cs instanceof PIDColourScheme)
356 PIDColour.setSelected(true);
358 else if (sg.cs instanceof Blosum62ColourScheme)
360 BLOSUM62Colour.setSelected(true);
362 else if (sg.cs instanceof UserColourScheme)
364 userDefinedColour.setSelected(true);
366 else if (sg.cs instanceof HydrophobicColourScheme)
368 hydrophobicityColour.setSelected(true);
370 else if (sg.cs instanceof HelixColourScheme)
372 helixColour.setSelected(true);
374 else if (sg.cs instanceof StrandColourScheme)
376 strandColour.setSelected(true);
378 else if (sg.cs instanceof TurnColourScheme)
380 turnColour.setSelected(true);
382 else if (sg.cs instanceof BuriedColourScheme)
384 buriedColour.setSelected(true);
386 else if (sg.cs instanceof ClustalxColourScheme)
388 clustalColour.setSelected(true);
392 noColourmenuItem.setSelected(true);
395 if (sg.cs != null && sg.cs.conservationApplied())
397 conservationMenuItem.setSelected(true);
399 displayNonconserved.setSelected(sg.getShowNonconserved());
400 showText.setSelected(sg.getDisplayText());
401 showColourText.setSelected(sg.getColourText());
402 showBoxes.setSelected(sg.getDisplayBoxes());
403 // add any groupURLs to the groupURL submenu and make it visible
404 if (groupLinks != null && groupLinks.size() > 0)
406 buildGroupURLMenu(sg, groupLinks);
411 groupMenu.setVisible(false);
412 editMenu.setVisible(false);
415 if (!ap.av.alignment.getGroups().contains(sg))
417 unGroupMenuItem.setVisible(false);
422 sequenceMenu.setVisible(false);
423 structureMenu.setVisible(false);
426 if (links != null && links.size() > 0)
429 JMenu linkMenu = new JMenu("Link");
430 Vector linkset = new Vector();
431 for (int i = 0; i < links.size(); i++)
433 String link = links.elementAt(i).toString();
434 UrlLink urlLink = null;
437 urlLink = new UrlLink(link);
438 } catch (Exception foo)
440 jalview.bin.Cache.log.error("Exception for URLLink '" + link
445 if (!urlLink.isValid())
447 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
450 final String label = urlLink.getLabel();
451 if (urlLink.isDynamic())
454 // collect matching db-refs
455 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
456 seq.getDBRef(), new String[]
457 { urlLink.getTarget() });
458 // collect id string too
459 String id = seq.getName();
460 String descr = seq.getDescription();
461 if (descr != null && descr.length() < 1)
468 for (int r = 0; r < dbr.length; r++)
470 if (id != null && dbr[r].getAccessionId().equals(id))
472 // suppress duplicate link creation for the bare sequence ID
473 // string with this link
476 // create Bare ID link for this RUL
477 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
481 for (int u = 0; u < urls.length; u += 2)
483 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
485 linkset.addElement(urls[u] + "|" + urls[u + 1]);
486 addshowLink(linkMenu, label + "|" + urls[u],
495 // create Bare ID link for this RUL
496 String[] urls = urlLink.makeUrls(id, true);
499 for (int u = 0; u < urls.length; u += 2)
501 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
503 linkset.addElement(urls[u] + "|" + urls[u + 1]);
504 addshowLink(linkMenu, label, urls[u + 1]);
509 // Create urls from description but only for URL links which are regex
511 if (descr != null && urlLink.getRegexReplace() != null)
513 // create link for this URL from description where regex matches
514 String[] urls = urlLink.makeUrls(descr, true);
517 for (int u = 0; u < urls.length; u += 2)
519 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
521 linkset.addElement(urls[u] + "|" + urls[u + 1]);
522 addshowLink(linkMenu, label, urls[u + 1]);
530 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
532 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
533 // Add a non-dynamic link
534 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
538 if (sequence != null)
540 sequenceMenu.add(linkMenu);
549 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
552 // TODO: usability: thread off the generation of group url content so root
554 // sequence only URLs
555 // ID/regex match URLs
556 groupLinksMenu = new JMenu("Group Link");
557 JMenu[] linkMenus = new JMenu[]
558 { null, new JMenu("IDS"), new JMenu("Sequences"),
559 new JMenu("IDS and Sequences") }; // three types of url that might be
561 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
562 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
563 Hashtable commonDbrefs = new Hashtable();
564 for (int sq = 0; sq < seqs.length; sq++)
567 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
568 .findPosition(sg.getEndRes());
569 // just collect ids from dataset sequence
570 // TODO: check if IDs collected from selecton group intersects with the
571 // current selection, too
572 SequenceI sqi = seqs[sq];
573 while (sqi.getDatasetSequence() != null)
575 sqi = sqi.getDatasetSequence();
577 DBRefEntry[] dbr = sqi.getDBRef();
578 if (dbr != null && dbr.length > 0)
580 for (int d = 0; d < dbr.length; d++)
582 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
583 Object[] sarray = (Object[]) commonDbrefs.get(src);
586 sarray = new Object[2];
587 sarray[0] = new int[]
589 sarray[1] = new String[seqs.length];
591 commonDbrefs.put(src, sarray);
594 if (((String[]) sarray[1])[sq] == null)
597 || (dbr[d].getMap().locateMappedRange(start, end) != null))
599 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
600 ((int[]) sarray[0])[0]++;
606 // now create group links for all distinct ID/sequence sets.
607 boolean addMenu = false; // indicates if there are any group links to give
609 for (int i = 0; i < groupLinks.size(); i++)
611 String link = groupLinks.elementAt(i).toString();
612 GroupUrlLink urlLink = null;
615 urlLink = new GroupUrlLink(link);
616 } catch (Exception foo)
618 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
623 if (!urlLink.isValid())
625 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
628 final String label = urlLink.getLabel();
629 boolean usingNames = false;
630 // Now see which parts of the group apply for this URL
631 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
632 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
633 String[] seqstr, ids; // input to makeUrl
636 int numinput = ((int[]) idset[0])[0];
637 String[] allids = ((String[]) idset[1]);
638 seqstr = new String[numinput];
639 ids = new String[numinput];
640 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
642 if (allids[sq] != null)
644 ids[idcount] = allids[sq];
645 seqstr[idcount++] = idandseqs[1][sq];
651 // just use the id/seq set
652 seqstr = idandseqs[1];
656 // and try and make the groupURL!
658 Object[] urlset = null;
661 urlset = urlLink.makeUrlStubs(ids, seqstr,
662 "FromJalview" + System.currentTimeMillis(), false);
663 } catch (UrlStringTooLongException e)
668 int type = urlLink.getGroupURLType() & 3;
669 // System.out.println(urlLink.getGroupURLType()
670 // +" "+((String[])urlset[3])[0]);
671 // first two bits ofurlLink type bitfield are sequenceids and sequences
672 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
673 addshowLink(linkMenus[type], label
674 + (((type & 1) == 1) ? ("("
675 + (usingNames ? "Names" : ltarget) + ")") : ""),
682 groupLinksMenu = new JMenu("Group Links");
683 for (int m = 0; m < linkMenus.length; m++)
685 if (linkMenus[m] != null
686 && linkMenus[m].getMenuComponentCount() > 0)
688 groupLinksMenu.add(linkMenus[m]);
692 groupMenu.add(groupLinksMenu);
697 * add a show URL menu item to the given linkMenu
701 * - menu label string
705 private void addshowLink(JMenu linkMenu, String label, final String url)
707 JMenuItem item = new JMenuItem(label);
708 item.setToolTipText("open URL: " + url);
709 item.addActionListener(new java.awt.event.ActionListener()
711 public void actionPerformed(ActionEvent e)
713 new Thread(new Runnable()
729 * add a late bound groupURL item to the given linkMenu
733 * - menu label string
734 * @param urlgenerator
735 * GroupURLLink used to generate URL
737 * Object array returned from the makeUrlStubs function.
739 private void addshowLink(JMenu linkMenu, String label,
740 final GroupUrlLink urlgenerator, final Object[] urlstub)
742 JMenuItem item = new JMenuItem(label);
743 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
744 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
753 item.addActionListener(new java.awt.event.ActionListener()
755 public void actionPerformed(ActionEvent e)
757 new Thread(new Runnable()
764 showLink(urlgenerator.constructFrom(urlstub));
765 } catch (UrlStringTooLongException e)
783 private void jbInit() throws Exception
785 groupMenu.setText("Group");
786 groupMenu.setText("Selection");
787 groupName.setText("Name");
788 groupName.addActionListener(new java.awt.event.ActionListener()
790 public void actionPerformed(ActionEvent e)
792 groupName_actionPerformed();
795 sequenceMenu.setText("Sequence");
796 sequenceName.setText("Edit Name/Description");
797 sequenceName.addActionListener(new java.awt.event.ActionListener()
799 public void actionPerformed(ActionEvent e)
801 sequenceName_actionPerformed();
804 PIDColour.setFocusPainted(false);
805 unGroupMenuItem.setText("Remove Group");
806 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
808 public void actionPerformed(ActionEvent e)
810 unGroupMenuItem_actionPerformed();
814 outline.setText("Border colour");
815 outline.addActionListener(new java.awt.event.ActionListener()
817 public void actionPerformed(ActionEvent e)
819 outline_actionPerformed();
822 nucleotideMenuItem.setText("Nucleotide");
823 nucleotideMenuItem.addActionListener(new ActionListener()
825 public void actionPerformed(ActionEvent e)
827 nucleotideMenuItem_actionPerformed();
830 colourMenu.setText("Group Colour");
831 showBoxes.setText("Boxes");
832 showBoxes.setState(true);
833 showBoxes.addActionListener(new ActionListener()
835 public void actionPerformed(ActionEvent e)
837 showBoxes_actionPerformed();
840 showText.setText("Text");
841 showText.setState(true);
842 showText.addActionListener(new ActionListener()
844 public void actionPerformed(ActionEvent e)
846 showText_actionPerformed();
849 showColourText.setText("Colour Text");
850 showColourText.addActionListener(new ActionListener()
852 public void actionPerformed(ActionEvent e)
854 showColourText_actionPerformed();
857 displayNonconserved.setText("Show Nonconserved");
858 displayNonconserved.setState(true);
859 displayNonconserved.addActionListener(new ActionListener()
861 public void actionPerformed(ActionEvent e)
863 showNonconserved_actionPerformed();
866 editMenu.setText("Edit");
868 cut.addActionListener(new ActionListener()
870 public void actionPerformed(ActionEvent e)
872 cut_actionPerformed();
875 upperCase.setText("To Upper Case");
876 upperCase.addActionListener(new ActionListener()
878 public void actionPerformed(ActionEvent e)
883 copy.setText("Copy");
884 copy.addActionListener(new ActionListener()
886 public void actionPerformed(ActionEvent e)
888 copy_actionPerformed();
891 lowerCase.setText("To Lower Case");
892 lowerCase.addActionListener(new ActionListener()
894 public void actionPerformed(ActionEvent e)
899 toggle.setText("Toggle Case");
900 toggle.addActionListener(new ActionListener()
902 public void actionPerformed(ActionEvent e)
907 pdbMenu.setText("Associate Structure with Sequence");
908 pdbFromFile.setText("From File");
909 pdbFromFile.addActionListener(new ActionListener()
911 public void actionPerformed(ActionEvent e)
913 pdbFromFile_actionPerformed();
916 enterPDB.setText("Enter PDB Id");
917 enterPDB.addActionListener(new ActionListener()
919 public void actionPerformed(ActionEvent e)
921 enterPDB_actionPerformed();
924 discoverPDB.setText("Discover PDB ids");
925 discoverPDB.addActionListener(new ActionListener()
927 public void actionPerformed(ActionEvent e)
929 discoverPDB_actionPerformed();
932 outputMenu.setText("Output to Textbox...");
933 sequenceFeature.setText("Create Sequence Feature");
934 sequenceFeature.addActionListener(new ActionListener()
936 public void actionPerformed(ActionEvent e)
938 sequenceFeature_actionPerformed();
941 textColour.setText("Text Colour");
942 textColour.addActionListener(new ActionListener()
944 public void actionPerformed(ActionEvent e)
946 textColour_actionPerformed();
949 jMenu1.setText("Group");
950 structureMenu.setText("Structure");
951 viewStructureMenu.setText("View Structure");
952 // colStructureMenu.setText("Colour By Structure");
953 editSequence.setText("Edit Sequence...");
954 editSequence.addActionListener(new ActionListener()
956 public void actionPerformed(ActionEvent actionEvent)
958 editSequence_actionPerformed(actionEvent);
962 * annotationMenuItem.setText("By Annotation");
963 * annotationMenuItem.addActionListener(new ActionListener() { public void
964 * actionPerformed(ActionEvent actionEvent) {
965 * annotationMenuItem_actionPerformed(actionEvent); } });
971 this.add(structureMenu);
972 groupMenu.add(editMenu);
973 groupMenu.add(outputMenu);
974 groupMenu.add(sequenceFeature);
975 groupMenu.add(jMenu1);
976 sequenceMenu.add(sequenceName);
977 colourMenu.add(textColour);
978 colourMenu.add(noColourmenuItem);
979 colourMenu.add(clustalColour);
980 colourMenu.add(BLOSUM62Colour);
981 colourMenu.add(PIDColour);
982 colourMenu.add(zappoColour);
983 colourMenu.add(taylorColour);
984 colourMenu.add(hydrophobicityColour);
985 colourMenu.add(helixColour);
986 colourMenu.add(strandColour);
987 colourMenu.add(turnColour);
988 colourMenu.add(buriedColour);
989 colourMenu.add(nucleotideMenuItem);
990 colourMenu.add(userDefinedColour);
992 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
994 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
995 .getUserColourSchemes().keys();
997 while (userColours.hasMoreElements())
999 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1000 item.addActionListener(new ActionListener()
1002 public void actionPerformed(ActionEvent evt)
1004 userDefinedColour_actionPerformed(evt);
1007 colourMenu.add(item);
1011 colourMenu.addSeparator();
1012 colourMenu.add(abovePIDColour);
1013 colourMenu.add(conservationMenuItem);
1014 // colourMenu.add(annotationMenuItem);
1017 editMenu.add(editSequence);
1018 editMenu.add(upperCase);
1019 editMenu.add(lowerCase);
1020 editMenu.add(toggle);
1021 pdbMenu.add(pdbFromFile);
1022 pdbMenu.add(enterPDB);
1023 pdbMenu.add(discoverPDB);
1024 jMenu1.add(groupName);
1025 jMenu1.add(unGroupMenuItem);
1026 jMenu1.add(colourMenu);
1027 jMenu1.add(showBoxes);
1028 jMenu1.add(showText);
1029 jMenu1.add(showColourText);
1030 jMenu1.add(outline);
1031 jMenu1.add(displayNonconserved);
1032 structureMenu.add(pdbMenu);
1033 structureMenu.add(viewStructureMenu);
1034 // structureMenu.add(colStructureMenu);
1035 noColourmenuItem.setText("None");
1036 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1038 public void actionPerformed(ActionEvent e)
1040 noColourmenuItem_actionPerformed();
1044 clustalColour.setText("Clustalx colours");
1045 clustalColour.addActionListener(new java.awt.event.ActionListener()
1047 public void actionPerformed(ActionEvent e)
1049 clustalColour_actionPerformed();
1052 zappoColour.setText("Zappo");
1053 zappoColour.addActionListener(new java.awt.event.ActionListener()
1055 public void actionPerformed(ActionEvent e)
1057 zappoColour_actionPerformed();
1060 taylorColour.setText("Taylor");
1061 taylorColour.addActionListener(new java.awt.event.ActionListener()
1063 public void actionPerformed(ActionEvent e)
1065 taylorColour_actionPerformed();
1068 hydrophobicityColour.setText("Hydrophobicity");
1069 hydrophobicityColour
1070 .addActionListener(new java.awt.event.ActionListener()
1072 public void actionPerformed(ActionEvent e)
1074 hydrophobicityColour_actionPerformed();
1077 helixColour.setText("Helix propensity");
1078 helixColour.addActionListener(new java.awt.event.ActionListener()
1080 public void actionPerformed(ActionEvent e)
1082 helixColour_actionPerformed();
1085 strandColour.setText("Strand propensity");
1086 strandColour.addActionListener(new java.awt.event.ActionListener()
1088 public void actionPerformed(ActionEvent e)
1090 strandColour_actionPerformed();
1093 turnColour.setText("Turn propensity");
1094 turnColour.addActionListener(new java.awt.event.ActionListener()
1096 public void actionPerformed(ActionEvent e)
1098 turnColour_actionPerformed();
1101 buriedColour.setText("Buried Index");
1102 buriedColour.addActionListener(new java.awt.event.ActionListener()
1104 public void actionPerformed(ActionEvent e)
1106 buriedColour_actionPerformed();
1109 abovePIDColour.setText("Above % Identity");
1110 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1112 public void actionPerformed(ActionEvent e)
1114 abovePIDColour_actionPerformed();
1117 userDefinedColour.setText("User Defined...");
1118 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1120 public void actionPerformed(ActionEvent e)
1122 userDefinedColour_actionPerformed(e);
1125 PIDColour.setText("Percentage Identity");
1126 PIDColour.addActionListener(new java.awt.event.ActionListener()
1128 public void actionPerformed(ActionEvent e)
1130 PIDColour_actionPerformed();
1133 BLOSUM62Colour.setText("BLOSUM62");
1134 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1136 public void actionPerformed(ActionEvent e)
1138 BLOSUM62Colour_actionPerformed();
1141 conservationMenuItem.setText("Conservation");
1142 conservationMenuItem
1143 .addActionListener(new java.awt.event.ActionListener()
1145 public void actionPerformed(ActionEvent e)
1147 conservationMenuItem_actionPerformed();
1152 protected void showNonconserved_actionPerformed()
1154 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1159 * call to refresh view after settings change
1163 ap.updateAnnotation();
1164 ap.paintAlignment(true);
1166 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1175 protected void clustalColour_actionPerformed()
1177 SequenceGroup sg = getGroup();
1178 sg.cs = new ClustalxColourScheme(
1179 sg.getSequences(ap.av.hiddenRepSequences),
1180 ap.av.alignment.getWidth());
1190 protected void zappoColour_actionPerformed()
1192 getGroup().cs = new ZappoColourScheme();
1202 protected void taylorColour_actionPerformed()
1204 getGroup().cs = new TaylorColourScheme();
1214 protected void hydrophobicityColour_actionPerformed()
1216 getGroup().cs = new HydrophobicColourScheme();
1226 protected void helixColour_actionPerformed()
1228 getGroup().cs = new HelixColourScheme();
1238 protected void strandColour_actionPerformed()
1240 getGroup().cs = new StrandColourScheme();
1250 protected void turnColour_actionPerformed()
1252 getGroup().cs = new TurnColourScheme();
1262 protected void buriedColour_actionPerformed()
1264 getGroup().cs = new BuriedColourScheme();
1274 public void nucleotideMenuItem_actionPerformed()
1276 getGroup().cs = new NucleotideColourScheme();
1286 protected void abovePIDColour_actionPerformed()
1288 SequenceGroup sg = getGroup();
1294 if (abovePIDColour.isSelected())
1296 sg.cs.setConsensus(AAFrequency.calculate(
1297 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1298 sg.getEndRes() + 1));
1300 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1303 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1305 SliderPanel.showPIDSlider();
1308 // remove PIDColouring
1310 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1322 protected void userDefinedColour_actionPerformed(ActionEvent e)
1324 SequenceGroup sg = getGroup();
1326 if (e.getActionCommand().equals("User Defined..."))
1328 new UserDefinedColours(ap, sg);
1332 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1333 .getUserColourSchemes().get(e.getActionCommand());
1346 protected void PIDColour_actionPerformed()
1348 SequenceGroup sg = getGroup();
1349 sg.cs = new PIDColourScheme();
1350 sg.cs.setConsensus(AAFrequency.calculate(
1351 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1352 sg.getEndRes() + 1));
1362 protected void BLOSUM62Colour_actionPerformed()
1364 SequenceGroup sg = getGroup();
1366 sg.cs = new Blosum62ColourScheme();
1368 sg.cs.setConsensus(AAFrequency.calculate(
1369 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1370 sg.getEndRes() + 1));
1381 protected void noColourmenuItem_actionPerformed()
1383 getGroup().cs = null;
1393 protected void conservationMenuItem_actionPerformed()
1395 SequenceGroup sg = getGroup();
1401 if (conservationMenuItem.isSelected())
1403 Conservation c = new Conservation("Group",
1404 ResidueProperties.propHash, 3,
1405 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1406 sg.getEndRes() + 1);
1409 c.verdict(false, ap.av.ConsPercGaps);
1411 sg.cs.setConservation(c);
1413 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1414 SliderPanel.showConservationSlider();
1417 // remove ConservationColouring
1419 sg.cs.setConservation(null);
1425 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1427 SequenceGroup sg = getGroup();
1433 AnnotationColourGradient acg = new AnnotationColourGradient(
1434 sequence.getAnnotation()[0], null,
1435 AnnotationColourGradient.NO_THRESHOLD);
1437 acg.predefinedColours = true;
1449 protected void groupName_actionPerformed()
1452 SequenceGroup sg = getGroup();
1453 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1454 sg.getDescription(), " Group Name ",
1455 "Group Description ", "Edit Group Name/Description",
1463 sg.setName(dialog.getName());
1464 sg.setDescription(dialog.getDescription());
1469 * Get selection group - adding it to the alignment if necessary.
1471 * @return sequence group to operate on
1473 SequenceGroup getGroup()
1475 SequenceGroup sg = ap.av.getSelectionGroup();
1476 // this method won't add a new group if it already exists
1479 ap.av.alignment.addGroup(sg);
1491 void sequenceName_actionPerformed()
1493 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1494 sequence.getDescription(), " Sequence Name ",
1495 "Sequence Description ", "Edit Sequence Name/Description",
1503 if (dialog.getName() != null)
1505 if (dialog.getName().indexOf(" ") > -1)
1507 JOptionPane.showMessageDialog(ap,
1508 "Spaces have been converted to \"_\"",
1509 "No spaces allowed in Sequence Name",
1510 JOptionPane.WARNING_MESSAGE);
1513 sequence.setName(dialog.getName().replace(' ', '_'));
1514 ap.paintAlignment(false);
1517 sequence.setDescription(dialog.getDescription());
1519 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1530 void unGroupMenuItem_actionPerformed()
1532 SequenceGroup sg = ap.av.getSelectionGroup();
1533 ap.av.alignment.deleteGroup(sg);
1534 ap.av.setSelectionGroup(null);
1544 protected void outline_actionPerformed()
1546 SequenceGroup sg = getGroup();
1547 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1552 sg.setOutlineColour(col);
1564 public void showBoxes_actionPerformed()
1566 getGroup().setDisplayBoxes(showBoxes.isSelected());
1576 public void showText_actionPerformed()
1578 getGroup().setDisplayText(showText.isSelected());
1588 public void showColourText_actionPerformed()
1590 getGroup().setColourText(showColourText.isSelected());
1594 public void showLink(String url)
1598 jalview.util.BrowserLauncher.openURL(url);
1599 } catch (Exception ex)
1602 .showInternalMessageDialog(
1604 "Unixers: Couldn't find default web browser."
1605 + "\nAdd the full path to your browser in Preferences.",
1606 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1608 ex.printStackTrace();
1612 void hideSequences(boolean representGroup)
1614 SequenceGroup sg = ap.av.getSelectionGroup();
1615 if (sg == null || sg.getSize() < 1)
1617 ap.av.hideSequence(new SequenceI[]
1622 ap.av.setSelectionGroup(null);
1626 ap.av.hideRepSequences(sequence, sg);
1631 int gsize = sg.getSize();
1634 hseqs = new SequenceI[gsize];
1637 for (int i = 0; i < gsize; i++)
1639 hseqs[index++] = sg.getSequenceAt(i);
1642 ap.av.hideSequence(hseqs);
1643 // refresh(); TODO: ? needed ?
1644 ap.av.sendSelection();
1647 public void copy_actionPerformed()
1649 ap.alignFrame.copy_actionPerformed(null);
1652 public void cut_actionPerformed()
1654 ap.alignFrame.cut_actionPerformed(null);
1657 void changeCase(ActionEvent e)
1659 Object source = e.getSource();
1660 SequenceGroup sg = ap.av.getSelectionGroup();
1664 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1665 sg.getEndRes() + 1);
1670 if (source == toggle)
1672 description = "Toggle Case";
1673 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1675 else if (source == upperCase)
1677 description = "To Upper Case";
1678 caseChange = ChangeCaseCommand.TO_UPPER;
1682 description = "To Lower Case";
1683 caseChange = ChangeCaseCommand.TO_LOWER;
1686 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1687 sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1690 ap.alignFrame.addHistoryItem(caseCommand);
1692 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1698 public void outputText_actionPerformed(ActionEvent e)
1700 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1701 cap.setForInput(null);
1702 Desktop.addInternalFrame(cap,
1703 "Alignment output - " + e.getActionCommand(), 600, 500);
1705 String[] omitHidden = null;
1707 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1708 // or we simply trust the user wants
1709 // wysiwig behaviour
1710 SequenceGroup sg = ap.av.getSelectionGroup();
1711 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1712 omitHidden = ap.av.getViewAsString(true);
1713 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1714 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1717 for (int i = 0; i < nala.length; i++)
1719 AlignmentAnnotation na = nala[i];
1720 oal.addAnnotation(na);
1723 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1724 oal, omitHidden, csel, sg));
1728 public void pdbFromFile_actionPerformed()
1730 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1731 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1732 chooser.setFileView(new jalview.io.JalviewFileView());
1733 chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
1734 chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
1736 int value = chooser.showOpenDialog(null);
1738 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1740 String choice = chooser.getSelectedFile().getPath();
1741 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1742 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
1747 public void enterPDB_actionPerformed()
1749 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1750 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1752 if (id != null && id.length() > 0)
1754 PDBEntry entry = new PDBEntry();
1755 entry.setId(id.toUpperCase());
1756 sequence.getDatasetSequence().addPDBId(entry);
1760 public void discoverPDB_actionPerformed()
1763 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1765 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1766 Thread discpdb = new Thread(new Runnable()
1771 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1772 .fetchDBRefs(false);
1779 public void sequenceFeature_actionPerformed()
1781 SequenceGroup sg = ap.av.getSelectionGroup();
1787 int rsize = 0, gSize = sg.getSize();
1788 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1789 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1791 for (int i = 0; i < gSize; i++)
1793 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1794 int end = sg.findEndRes(sg.getSequenceAt(i));
1797 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1798 features[rsize] = new SequenceFeature(null, null, null, start, end,
1803 rseqs = new SequenceI[rsize];
1804 tfeatures = new SequenceFeature[rsize];
1805 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1806 System.arraycopy(features, 0, tfeatures, 0, rsize);
1807 features = tfeatures;
1809 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1810 features, true, ap))
1812 ap.alignFrame.setShowSeqFeatures(true);
1813 ap.highlightSearchResults(null);
1817 public void textColour_actionPerformed()
1819 SequenceGroup sg = getGroup();
1822 new TextColourChooser().chooseColour(ap, sg);
1826 public void colourByStructure(String pdbid)
1828 Annotation[] anots = jalview.structure.StructureSelectionManager
1829 .getStructureSelectionManager().colourSequenceFromStructure(
1832 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1833 "Coloured by " + pdbid, anots);
1835 ap.av.alignment.addAnnotation(an);
1836 an.createSequenceMapping(sequence, 0, true);
1837 // an.adjustForAlignment();
1838 ap.av.alignment.setAnnotationIndex(an, 0);
1840 ap.adjustAnnotationHeight();
1842 sequence.addAlignmentAnnotation(an);
1846 public void editSequence_actionPerformed(ActionEvent actionEvent)
1848 SequenceGroup sg = ap.av.getSelectionGroup();
1852 if (sequence == null)
1853 sequence = (Sequence) sg.getSequenceAt(0);
1855 EditNameDialog dialog = new EditNameDialog(
1856 sequence.getSequenceAsString(sg.getStartRes(),
1857 sg.getEndRes() + 1), null, "Edit Sequence ", null,
1858 "Edit Sequence", ap.alignFrame);
1862 EditCommand editCommand = new EditCommand("Edit Sequences",
1863 EditCommand.REPLACE, dialog.getName().replace(' ',
1864 ap.av.getGapCharacter()),
1865 sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1866 sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1868 ap.alignFrame.addHistoryItem(editCommand);
1870 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()