2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 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.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);
158 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links, Vector groupLinks)
160 // /////////////////////////////////////////////////////////
161 // If this is activated from the sequence panel, the user may want to
162 // edit or annotate a particular residue. Therefore display the residue menu
164 // If from the IDPanel, we must display the sequence menu
165 // ////////////////////////////////////////////////////////
169 ButtonGroup colours = new ButtonGroup();
170 colours.add(noColourmenuItem);
171 colours.add(clustalColour);
172 colours.add(zappoColour);
173 colours.add(taylorColour);
174 colours.add(hydrophobicityColour);
175 colours.add(helixColour);
176 colours.add(strandColour);
177 colours.add(turnColour);
178 colours.add(buriedColour);
179 colours.add(abovePIDColour);
180 colours.add(userDefinedColour);
181 colours.add(PIDColour);
182 colours.add(BLOSUM62Colour);
184 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
186 JMenuItem item = new JMenuItem(
187 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
189 item.addActionListener(new java.awt.event.ActionListener()
191 public void actionPerformed(ActionEvent e)
193 outputText_actionPerformed(e);
197 outputMenu.add(item);
203 } catch (Exception e)
210 sequenceMenu.setText(sequence.getName());
213 if (seq.getDatasetSequence().getPDBId() != null
214 && seq.getDatasetSequence().getPDBId().size() > 0)
216 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
219 while (e.hasMoreElements())
221 final PDBEntry pdb = (PDBEntry) e.nextElement();
223 menuItem = new JMenuItem();
224 menuItem.setText(pdb.getId());
225 menuItem.addActionListener(new java.awt.event.ActionListener()
227 public void actionPerformed(ActionEvent e)
229 Vector seqs = new Vector();
230 for (int i = 0; i < ap.av.alignment.getHeight(); i++)
232 Vector pdbs = ap.av.alignment.getSequenceAt(i)
233 .getDatasetSequence().getPDBId();
237 for (int p = 0; p < pdbs.size(); p++)
239 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
240 if (p1.getId().equals(pdb.getId()))
242 if (!seqs.contains(ap.av.alignment.getSequenceAt(i)))
243 seqs.addElement(ap.av.alignment.getSequenceAt(i));
250 SequenceI[] seqs2 = new SequenceI[seqs.size()];
253 new AppJmol(pdb, seqs2, null, ap);
254 // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
257 viewStructureMenu.add(menuItem);
260 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
261 * menuItem.addActionListener(new java.awt.event.ActionListener() {
262 * public void actionPerformed(ActionEvent e) {
263 * colourByStructure(pdb.getId()); } });
264 * colStructureMenu.add(menuItem);
270 structureMenu.remove(viewStructureMenu);
271 // structureMenu.remove(colStructureMenu);
274 menuItem = new JMenuItem("Hide Sequences");
275 menuItem.addActionListener(new java.awt.event.ActionListener()
277 public void actionPerformed(ActionEvent e)
279 hideSequences(false);
284 if (ap.av.getSelectionGroup() != null
285 && ap.av.getSelectionGroup().getSize() > 1)
287 menuItem = new JMenuItem("Represent Group with " + seq.getName());
288 menuItem.addActionListener(new java.awt.event.ActionListener()
290 public void actionPerformed(ActionEvent e)
295 sequenceMenu.add(menuItem);
298 if (ap.av.hasHiddenRows)
300 final int index = ap.av.alignment.findIndex(seq);
302 if (ap.av.adjustForHiddenSeqs(index)
303 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
305 menuItem = new JMenuItem("Reveal Sequences");
306 menuItem.addActionListener(new ActionListener()
308 public void actionPerformed(ActionEvent e)
310 ap.av.showSequence(index);
311 if (ap.overviewPanel != null)
313 ap.overviewPanel.updateOverviewImage();
320 menuItem = new JMenuItem("Reveal All");
321 menuItem.addActionListener(new ActionListener()
323 public void actionPerformed(ActionEvent e)
325 ap.av.showAllHiddenSeqs();
326 if (ap.overviewPanel != null)
328 ap.overviewPanel.updateOverviewImage();
338 SequenceGroup sg = ap.av.getSelectionGroup();
342 groupName.setText(sg.getName());
344 if (sg.cs instanceof ZappoColourScheme)
346 zappoColour.setSelected(true);
348 else if (sg.cs instanceof TaylorColourScheme)
350 taylorColour.setSelected(true);
352 else if (sg.cs instanceof PIDColourScheme)
354 PIDColour.setSelected(true);
356 else if (sg.cs instanceof Blosum62ColourScheme)
358 BLOSUM62Colour.setSelected(true);
360 else if (sg.cs instanceof UserColourScheme)
362 userDefinedColour.setSelected(true);
364 else if (sg.cs instanceof HydrophobicColourScheme)
366 hydrophobicityColour.setSelected(true);
368 else if (sg.cs instanceof HelixColourScheme)
370 helixColour.setSelected(true);
372 else if (sg.cs instanceof StrandColourScheme)
374 strandColour.setSelected(true);
376 else if (sg.cs instanceof TurnColourScheme)
378 turnColour.setSelected(true);
380 else if (sg.cs instanceof BuriedColourScheme)
382 buriedColour.setSelected(true);
384 else if (sg.cs instanceof ClustalxColourScheme)
386 clustalColour.setSelected(true);
390 noColourmenuItem.setSelected(true);
393 if (sg.cs != null && sg.cs.conservationApplied())
395 conservationMenuItem.setSelected(true);
397 displayNonconserved.setSelected(sg.getShowunconserved());
398 showText.setSelected(sg.getDisplayText());
399 showColourText.setSelected(sg.getColourText());
400 showBoxes.setSelected(sg.getDisplayBoxes());
401 // add any groupURLs to the groupURL submenu and make it visible
402 if (groupLinks!=null && groupLinks.size()>0) {
403 buildGroupURLMenu(sg, groupLinks);
408 groupMenu.setVisible(false);
409 editMenu.setVisible(false);
412 if (!ap.av.alignment.getGroups().contains(sg))
414 unGroupMenuItem.setVisible(false);
419 sequenceMenu.setVisible(false);
420 structureMenu.setVisible(false);
423 if (links != null && links.size() > 0)
426 JMenu linkMenu = new JMenu("Link");
427 Vector linkset = new Vector();
428 for (int i = 0; i < links.size(); i++)
430 String link = links.elementAt(i).toString();
431 UrlLink urlLink = null;
434 urlLink = new UrlLink(link);
435 } catch (Exception foo)
437 jalview.bin.Cache.log.error("Exception for URLLink '" + link
442 if (!urlLink.isValid())
444 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
447 final String label = urlLink.getLabel();
448 if (urlLink.isDynamic())
451 // collect matching db-refs
452 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq
453 .getDBRef(), new String[]
454 { urlLink.getTarget() });
455 // collect id string too
456 String id = seq.getName();
457 String descr = seq.getDescription();
458 if (descr!=null && descr.length()<1)
465 for (int r = 0; r < dbr.length; r++)
467 if (id != null && dbr[r].getAccessionId().equals(id))
469 // suppress duplicate link creation for the bare sequence ID
470 // string with this link
473 // create Bare ID link for this RUL
474 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
478 for (int u = 0; u < urls.length; u += 2)
480 if (!linkset.contains(urls[u]+"|"+urls[u+1]))
482 linkset.addElement(urls[u]+"|"+urls[u+1]);
483 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
491 // create Bare ID link for this RUL
492 String[] urls = urlLink.makeUrls(id, true);
495 for (int u = 0; u < urls.length; u += 2)
497 if (!linkset.contains(urls[u]+"|"+urls[u+1]))
499 linkset.addElement(urls[u]+"|"+urls[u+1]);
500 addshowLink(linkMenu, label, urls[u + 1]);
505 // Create urls from description but only for URL links which are regex links
506 if (descr != null && urlLink.getRegexReplace()!=null)
508 // create link for this URL from description where regex matches
509 String[] urls = urlLink.makeUrls(descr, true);
512 for (int u = 0; u < urls.length; u += 2)
514 if (!linkset.contains(urls[u]+"|"+urls[u+1]))
516 linkset.addElement(urls[u]+"|"+urls[u+1]);
517 addshowLink(linkMenu, label, urls[u + 1]);
525 if (!linkset.contains(label+"|"+urlLink.getUrl_prefix()))
527 linkset.addElement(label+"|"+urlLink.getUrl_prefix());
528 // Add a non-dynamic link
529 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
533 if (sequence != null)
535 sequenceMenu.add(linkMenu);
544 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
547 // TODO: usability: thread off the generation of group url content so root menu appears asap
548 // sequence only URLs
549 // ID/regex match URLs
550 groupLinksMenu = new JMenu("Group Link");
551 JMenu[] linkMenus = new JMenu[] { null, new JMenu("IDS"), new JMenu("Sequences"), new JMenu("IDS and Sequences")}; // three types of url that might be created.
552 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
553 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
554 Hashtable commonDbrefs = new Hashtable();
555 for (int sq = 0; sq<seqs.length;sq++) {
557 int start = seqs[sq].findPosition(sg.getStartRes()),end=seqs[sq].findPosition(sg.getEndRes());
558 // just collect ids from dataset sequence
559 // TODO: check if IDs collected from selecton group intersects with the current selection, too
560 SequenceI sqi = seqs[sq];
561 while (sqi.getDatasetSequence()!=null) {
562 sqi = sqi.getDatasetSequence(); }
563 DBRefEntry[] dbr = sqi.getDBRef();
564 if (dbr!=null && dbr.length>0)
566 for (int d=0;d<dbr.length;d++)
568 String src =dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
569 Object[] sarray = (Object[]) commonDbrefs.get(src);
572 sarray = new Object[2];
573 sarray[0] = new int[] { 0 };
574 sarray[1] = new String[seqs.length];
576 commonDbrefs.put(src,sarray);
579 if (((String[])sarray[1])[sq]==null) {
580 if (!dbr[d].hasMap() || (dbr[d].getMap().locateMappedRange(start, end)!=null)) {
581 ((String[])sarray[1])[sq] = dbr[d].getAccessionId();
582 ((int[])sarray[0])[0]++;
588 // now create group links for all distinct ID/sequence sets.
589 boolean addMenu = false; // indicates if there are any group links to give to user
590 for (int i = 0; i < groupLinks.size(); i++) {
591 String link = groupLinks.elementAt(i).toString();
592 GroupUrlLink urlLink = null;
595 urlLink = new GroupUrlLink(link);
596 } catch (Exception foo)
598 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
603 if (!urlLink.isValid())
605 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
608 final String label = urlLink.getLabel();
609 boolean usingNames = false;
610 // Now see which parts of the group apply for this URL
611 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
612 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
613 String[] seqstr,ids; // input to makeUrl
616 int numinput = ((int[])idset[0])[0];
617 String[] allids = ((String[])idset[1]);
618 seqstr = new String[numinput];
619 ids = new String[numinput];
620 for (int sq=0,idcount=0;sq<seqs.length;sq++)
622 if (allids[sq]!=null) {
623 ids[idcount] = allids[sq];
624 seqstr[idcount++] = idandseqs[1][sq];
628 // just use the id/seq set
629 seqstr = idandseqs[1];
633 // and try and make the groupURL!
635 Object[] urlset = urlLink.makeUrlStubs(ids,seqstr, "FromJalview"+System.currentTimeMillis(),false);
638 int type = urlLink.getGroupURLType() & 3;
639 //System.out.println(urlLink.getGroupURLType() +" "+((String[])urlset[3])[0]);
640 // first two bits ofurlLink type bitfield are sequenceids and sequences
641 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
642 addshowLink(linkMenus[type], label + (((type & 1)==1) ? ("("+(usingNames ? "Names" : ltarget)+")") : ""), urlLink, urlset);
648 groupLinksMenu = new JMenu("Group Links");
649 for (int m=0;m<linkMenus.length; m++)
651 if (linkMenus[m]!=null && linkMenus[m].getMenuComponentCount()>0)
653 groupLinksMenu.add(linkMenus[m]);
657 groupMenu.add(groupLinksMenu);
662 * add a show URL menu item to the given linkMenu
670 private void addshowLink(JMenu linkMenu, String label, final String url)
672 JMenuItem item = new JMenuItem(label);
673 item.setToolTipText("open URL: " + url);
674 item.addActionListener(new java.awt.event.ActionListener()
676 public void actionPerformed(ActionEvent e)
678 new Thread(new Runnable()
693 * add a late bound groupURL item to the given linkMenu
698 * @param urlgenerator GroupURLLink used to generate URL
699 * @param urlstub Object array returned from the makeUrlStubs function.
701 private void addshowLink(JMenu linkMenu, String label, final GroupUrlLink urlgenerator, final Object[] urlstub)
703 JMenuItem item = new JMenuItem(label);
704 item.setToolTipText("open URL ("+urlgenerator.getUrl_prefix()+"..) ("+urlgenerator.getNumberInvolved(urlstub)+" seqs)"); // TODO: put in info about what is being sent.
705 item.addActionListener(new java.awt.event.ActionListener()
707 public void actionPerformed(ActionEvent e)
709 new Thread(new Runnable()
714 showLink(urlgenerator.constructFrom(urlstub));
729 private void jbInit() throws Exception
731 groupMenu.setText("Group");
732 groupMenu.setText("Selection");
733 groupName.setText("Name");
734 groupName.addActionListener(new java.awt.event.ActionListener()
736 public void actionPerformed(ActionEvent e)
738 groupName_actionPerformed();
741 sequenceMenu.setText("Sequence");
742 sequenceName.setText("Edit Name/Description");
743 sequenceName.addActionListener(new java.awt.event.ActionListener()
745 public void actionPerformed(ActionEvent e)
747 sequenceName_actionPerformed();
750 PIDColour.setFocusPainted(false);
751 unGroupMenuItem.setText("Remove Group");
752 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
754 public void actionPerformed(ActionEvent e)
756 unGroupMenuItem_actionPerformed();
760 outline.setText("Border colour");
761 outline.addActionListener(new java.awt.event.ActionListener()
763 public void actionPerformed(ActionEvent e)
765 outline_actionPerformed();
768 nucleotideMenuItem.setText("Nucleotide");
769 nucleotideMenuItem.addActionListener(new ActionListener()
771 public void actionPerformed(ActionEvent e)
773 nucleotideMenuItem_actionPerformed();
776 colourMenu.setText("Group Colour");
777 showBoxes.setText("Boxes");
778 showBoxes.setState(true);
779 showBoxes.addActionListener(new ActionListener()
781 public void actionPerformed(ActionEvent e)
783 showBoxes_actionPerformed();
786 showText.setText("Text");
787 showText.setState(true);
788 showText.addActionListener(new ActionListener()
790 public void actionPerformed(ActionEvent e)
792 showText_actionPerformed();
795 showColourText.setText("Colour Text");
796 showColourText.addActionListener(new ActionListener()
798 public void actionPerformed(ActionEvent e)
800 showColourText_actionPerformed();
803 displayNonconserved.setText("Show Nonconserved");
804 displayNonconserved.setState(true);
805 displayNonconserved.addActionListener(new ActionListener()
807 public void actionPerformed(ActionEvent e)
809 showNonconserved_actionPerformed();
812 editMenu.setText("Edit");
814 cut.addActionListener(new ActionListener()
816 public void actionPerformed(ActionEvent e)
818 cut_actionPerformed();
821 upperCase.setText("To Upper Case");
822 upperCase.addActionListener(new ActionListener()
824 public void actionPerformed(ActionEvent e)
829 copy.setText("Copy");
830 copy.addActionListener(new ActionListener()
832 public void actionPerformed(ActionEvent e)
834 copy_actionPerformed();
837 lowerCase.setText("To Lower Case");
838 lowerCase.addActionListener(new ActionListener()
840 public void actionPerformed(ActionEvent e)
845 toggle.setText("Toggle Case");
846 toggle.addActionListener(new ActionListener()
848 public void actionPerformed(ActionEvent e)
853 pdbMenu.setText("Associate Structure with Sequence");
854 pdbFromFile.setText("From File");
855 pdbFromFile.addActionListener(new ActionListener()
857 public void actionPerformed(ActionEvent e)
859 pdbFromFile_actionPerformed();
862 enterPDB.setText("Enter PDB Id");
863 enterPDB.addActionListener(new ActionListener()
865 public void actionPerformed(ActionEvent e)
867 enterPDB_actionPerformed();
870 discoverPDB.setText("Discover PDB ids");
871 discoverPDB.addActionListener(new ActionListener()
873 public void actionPerformed(ActionEvent e)
875 discoverPDB_actionPerformed();
878 outputMenu.setText("Output to Textbox...");
879 sequenceFeature.setText("Create Sequence Feature");
880 sequenceFeature.addActionListener(new ActionListener()
882 public void actionPerformed(ActionEvent e)
884 sequenceFeature_actionPerformed();
887 textColour.setText("Text Colour");
888 textColour.addActionListener(new ActionListener()
890 public void actionPerformed(ActionEvent e)
892 textColour_actionPerformed();
895 jMenu1.setText("Group");
896 structureMenu.setText("Structure");
897 viewStructureMenu.setText("View Structure");
898 // colStructureMenu.setText("Colour By Structure");
899 editSequence.setText("Edit Sequence...");
900 editSequence.addActionListener(new ActionListener()
902 public void actionPerformed(ActionEvent actionEvent)
904 editSequence_actionPerformed(actionEvent);
908 * annotationMenuItem.setText("By Annotation");
909 * annotationMenuItem.addActionListener(new ActionListener() { public void
910 * actionPerformed(ActionEvent actionEvent) {
911 * annotationMenuItem_actionPerformed(actionEvent); } });
917 this.add(structureMenu);
918 groupMenu.add(editMenu);
919 groupMenu.add(outputMenu);
920 groupMenu.add(sequenceFeature);
921 groupMenu.add(jMenu1);
922 sequenceMenu.add(sequenceName);
923 colourMenu.add(textColour);
924 colourMenu.add(noColourmenuItem);
925 colourMenu.add(clustalColour);
926 colourMenu.add(BLOSUM62Colour);
927 colourMenu.add(PIDColour);
928 colourMenu.add(zappoColour);
929 colourMenu.add(taylorColour);
930 colourMenu.add(hydrophobicityColour);
931 colourMenu.add(helixColour);
932 colourMenu.add(strandColour);
933 colourMenu.add(turnColour);
934 colourMenu.add(buriedColour);
935 colourMenu.add(nucleotideMenuItem);
936 colourMenu.add(userDefinedColour);
938 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
940 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
941 .getUserColourSchemes().keys();
943 while (userColours.hasMoreElements())
945 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
946 item.addActionListener(new ActionListener()
948 public void actionPerformed(ActionEvent evt)
950 userDefinedColour_actionPerformed(evt);
953 colourMenu.add(item);
957 colourMenu.addSeparator();
958 colourMenu.add(abovePIDColour);
959 colourMenu.add(conservationMenuItem);
960 // colourMenu.add(annotationMenuItem);
963 editMenu.add(editSequence);
964 editMenu.add(upperCase);
965 editMenu.add(lowerCase);
966 editMenu.add(toggle);
967 pdbMenu.add(pdbFromFile);
968 pdbMenu.add(enterPDB);
969 pdbMenu.add(discoverPDB);
970 jMenu1.add(groupName);
971 jMenu1.add(unGroupMenuItem);
972 jMenu1.add(colourMenu);
973 jMenu1.add(showBoxes);
974 jMenu1.add(showText);
975 jMenu1.add(showColourText);
977 jMenu1.add(displayNonconserved);
978 structureMenu.add(pdbMenu);
979 structureMenu.add(viewStructureMenu);
980 // structureMenu.add(colStructureMenu);
981 noColourmenuItem.setText("None");
982 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
984 public void actionPerformed(ActionEvent e)
986 noColourmenuItem_actionPerformed();
990 clustalColour.setText("Clustalx colours");
991 clustalColour.addActionListener(new java.awt.event.ActionListener()
993 public void actionPerformed(ActionEvent e)
995 clustalColour_actionPerformed();
998 zappoColour.setText("Zappo");
999 zappoColour.addActionListener(new java.awt.event.ActionListener()
1001 public void actionPerformed(ActionEvent e)
1003 zappoColour_actionPerformed();
1006 taylorColour.setText("Taylor");
1007 taylorColour.addActionListener(new java.awt.event.ActionListener()
1009 public void actionPerformed(ActionEvent e)
1011 taylorColour_actionPerformed();
1014 hydrophobicityColour.setText("Hydrophobicity");
1015 hydrophobicityColour
1016 .addActionListener(new java.awt.event.ActionListener()
1018 public void actionPerformed(ActionEvent e)
1020 hydrophobicityColour_actionPerformed();
1023 helixColour.setText("Helix propensity");
1024 helixColour.addActionListener(new java.awt.event.ActionListener()
1026 public void actionPerformed(ActionEvent e)
1028 helixColour_actionPerformed();
1031 strandColour.setText("Strand propensity");
1032 strandColour.addActionListener(new java.awt.event.ActionListener()
1034 public void actionPerformed(ActionEvent e)
1036 strandColour_actionPerformed();
1039 turnColour.setText("Turn propensity");
1040 turnColour.addActionListener(new java.awt.event.ActionListener()
1042 public void actionPerformed(ActionEvent e)
1044 turnColour_actionPerformed();
1047 buriedColour.setText("Buried Index");
1048 buriedColour.addActionListener(new java.awt.event.ActionListener()
1050 public void actionPerformed(ActionEvent e)
1052 buriedColour_actionPerformed();
1055 abovePIDColour.setText("Above % Identity");
1056 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1058 public void actionPerformed(ActionEvent e)
1060 abovePIDColour_actionPerformed();
1063 userDefinedColour.setText("User Defined...");
1064 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1066 public void actionPerformed(ActionEvent e)
1068 userDefinedColour_actionPerformed(e);
1071 PIDColour.setText("Percentage Identity");
1072 PIDColour.addActionListener(new java.awt.event.ActionListener()
1074 public void actionPerformed(ActionEvent e)
1076 PIDColour_actionPerformed();
1079 BLOSUM62Colour.setText("BLOSUM62");
1080 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1082 public void actionPerformed(ActionEvent e)
1084 BLOSUM62Colour_actionPerformed();
1087 conservationMenuItem.setText("Conservation");
1088 conservationMenuItem
1089 .addActionListener(new java.awt.event.ActionListener()
1091 public void actionPerformed(ActionEvent e)
1093 conservationMenuItem_actionPerformed();
1098 protected void showNonconserved_actionPerformed()
1100 getGroup().setShowunconserved(displayNonconserved.isSelected());
1105 * call to refresh view after settings change
1109 ap.updateAnnotation();
1110 ap.paintAlignment(true);
1112 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1121 protected void clustalColour_actionPerformed()
1123 SequenceGroup sg = getGroup();
1124 sg.cs = new ClustalxColourScheme(sg
1125 .getSequences(ap.av.hiddenRepSequences), ap.av.alignment
1136 protected void zappoColour_actionPerformed()
1138 getGroup().cs = new ZappoColourScheme();
1148 protected void taylorColour_actionPerformed()
1150 getGroup().cs = new TaylorColourScheme();
1160 protected void hydrophobicityColour_actionPerformed()
1162 getGroup().cs = new HydrophobicColourScheme();
1172 protected void helixColour_actionPerformed()
1174 getGroup().cs = new HelixColourScheme();
1184 protected void strandColour_actionPerformed()
1186 getGroup().cs = new StrandColourScheme();
1196 protected void turnColour_actionPerformed()
1198 getGroup().cs = new TurnColourScheme();
1208 protected void buriedColour_actionPerformed()
1210 getGroup().cs = new BuriedColourScheme();
1220 public void nucleotideMenuItem_actionPerformed()
1222 getGroup().cs = new NucleotideColourScheme();
1232 protected void abovePIDColour_actionPerformed()
1234 SequenceGroup sg = getGroup();
1240 if (abovePIDColour.isSelected())
1242 sg.cs.setConsensus(AAFrequency.calculate(sg
1243 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1246 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1249 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1251 SliderPanel.showPIDSlider();
1254 // remove PIDColouring
1256 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1268 protected void userDefinedColour_actionPerformed(ActionEvent e)
1270 SequenceGroup sg = getGroup();
1272 if (e.getActionCommand().equals("User Defined..."))
1274 new UserDefinedColours(ap, sg);
1278 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1279 .getUserColourSchemes().get(e.getActionCommand());
1292 protected void PIDColour_actionPerformed()
1294 SequenceGroup sg = getGroup();
1295 sg.cs = new PIDColourScheme();
1296 sg.cs.setConsensus(AAFrequency.calculate(sg
1297 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1308 protected void BLOSUM62Colour_actionPerformed()
1310 SequenceGroup sg = getGroup();
1312 sg.cs = new Blosum62ColourScheme();
1314 sg.cs.setConsensus(AAFrequency.calculate(sg
1315 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1327 protected void noColourmenuItem_actionPerformed()
1329 getGroup().cs = null;
1339 protected void conservationMenuItem_actionPerformed()
1341 SequenceGroup sg = getGroup();
1347 if (conservationMenuItem.isSelected())
1349 Conservation c = new Conservation("Group",
1350 ResidueProperties.propHash, 3, sg
1351 .getSequences(ap.av.hiddenRepSequences), sg
1352 .getStartRes(), sg.getEndRes() + 1);
1355 c.verdict(false, ap.av.ConsPercGaps);
1357 sg.cs.setConservation(c);
1359 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1360 SliderPanel.showConservationSlider();
1363 // remove ConservationColouring
1365 sg.cs.setConservation(null);
1371 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1373 SequenceGroup sg = getGroup();
1379 AnnotationColourGradient acg = new AnnotationColourGradient(sequence
1380 .getAnnotation()[0], null,
1381 AnnotationColourGradient.NO_THRESHOLD);
1383 acg.predefinedColours = true;
1395 protected void groupName_actionPerformed()
1398 SequenceGroup sg = getGroup();
1399 EditNameDialog dialog = new EditNameDialog(sg.getName(), sg
1400 .getDescription(), " Group Name ", "Group Description ",
1401 "Edit Group Name/Description");
1408 sg.setName(dialog.getName());
1409 sg.setDescription(dialog.getDescription());
1414 * Get selection group - adding it to the alignment if necessary.
1416 * @return sequence group to operate on
1418 SequenceGroup getGroup()
1420 SequenceGroup sg = ap.av.getSelectionGroup();
1421 // this method won't add a new group if it already exists
1424 ap.av.alignment.addGroup(sg);
1436 void sequenceName_actionPerformed()
1438 EditNameDialog dialog = new EditNameDialog(sequence.getName(), sequence
1439 .getDescription(), " Sequence Name ",
1440 "Sequence Description ", "Edit Sequence Name/Description");
1447 if (dialog.getName() != null)
1449 if (dialog.getName().indexOf(" ") > -1)
1451 JOptionPane.showMessageDialog(ap,
1452 "Spaces have been converted to \"_\"",
1453 "No spaces allowed in Sequence Name",
1454 JOptionPane.WARNING_MESSAGE);
1457 sequence.setName(dialog.getName().replace(' ', '_'));
1458 ap.paintAlignment(false);
1461 sequence.setDescription(dialog.getDescription());
1463 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1474 void unGroupMenuItem_actionPerformed()
1476 SequenceGroup sg = ap.av.getSelectionGroup();
1477 ap.av.alignment.deleteGroup(sg);
1478 ap.av.setSelectionGroup(null);
1488 protected void outline_actionPerformed()
1490 SequenceGroup sg = getGroup();
1491 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1496 sg.setOutlineColour(col);
1508 public void showBoxes_actionPerformed()
1510 getGroup().setDisplayBoxes(showBoxes.isSelected());
1520 public void showText_actionPerformed()
1522 getGroup().setDisplayText(showText.isSelected());
1532 public void showColourText_actionPerformed()
1534 getGroup().setColourText(showColourText.isSelected());
1538 public void showLink(String url)
1542 jalview.util.BrowserLauncher.openURL(url);
1543 } catch (Exception ex)
1546 .showInternalMessageDialog(
1548 "Unixers: Couldn't find default web browser."
1549 + "\nAdd the full path to your browser in Preferences.",
1550 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1552 ex.printStackTrace();
1556 void hideSequences(boolean representGroup)
1558 SequenceGroup sg = ap.av.getSelectionGroup();
1559 if (sg == null || sg.getSize() < 1)
1561 ap.av.hideSequence(new SequenceI[]
1566 ap.av.setSelectionGroup(null);
1570 ap.av.hideRepSequences(sequence, sg);
1575 int gsize = sg.getSize();
1578 hseqs = new SequenceI[gsize];
1581 for (int i = 0; i < gsize; i++)
1583 hseqs[index++] = sg.getSequenceAt(i);
1586 ap.av.hideSequence(hseqs);
1587 // refresh(); TODO: ? needed ?
1588 ap.av.sendSelection();
1591 public void copy_actionPerformed()
1593 ap.alignFrame.copy_actionPerformed(null);
1596 public void cut_actionPerformed()
1598 ap.alignFrame.cut_actionPerformed(null);
1601 void changeCase(ActionEvent e)
1603 Object source = e.getSource();
1604 SequenceGroup sg = ap.av.getSelectionGroup();
1608 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1609 sg.getEndRes() + 1);
1614 if (source == toggle)
1616 description = "Toggle Case";
1617 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1619 else if (source == upperCase)
1621 description = "To Upper Case";
1622 caseChange = ChangeCaseCommand.TO_UPPER;
1626 description = "To Lower Case";
1627 caseChange = ChangeCaseCommand.TO_LOWER;
1630 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description, sg
1631 .getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1634 ap.alignFrame.addHistoryItem(caseCommand);
1636 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1642 public void outputText_actionPerformed(ActionEvent e)
1644 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1645 cap.setForInput(null);
1646 Desktop.addInternalFrame(cap, "Alignment output - "
1647 + e.getActionCommand(), 600, 500);
1649 String[] omitHidden = null;
1651 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1652 // or we simply trust the user wants
1653 // wysiwig behaviour
1654 SequenceGroup sg = ap.av.getSelectionGroup();
1655 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1656 omitHidden = ap.av.getViewAsString(true);
1657 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1658 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1659 for (int i = 0; i < nala.length; i++)
1661 AlignmentAnnotation na = nala[i];
1662 oal.addAnnotation(na);
1664 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1665 oal, omitHidden, csel, sg));
1669 public void pdbFromFile_actionPerformed()
1671 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1672 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1673 chooser.setFileView(new jalview.io.JalviewFileView());
1674 chooser.setDialogTitle("Select a PDB file");
1675 chooser.setToolTipText("Load a PDB file");
1677 int value = chooser.showOpenDialog(null);
1679 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1681 PDBEntry entry = new PDBEntry();
1682 String choice = chooser.getSelectedFile().getPath();
1683 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1686 MCview.PDBfile pdbfile = new MCview.PDBfile(choice,
1687 jalview.io.AppletFormatAdapter.FILE);
1689 if (pdbfile.id == null)
1691 String reply = JOptionPane
1692 .showInternalInputDialog(
1694 "Couldn't find a PDB id in the file supplied."
1695 + "Please enter an Id to identify this structure.",
1696 "No PDB Id in File", JOptionPane.QUESTION_MESSAGE);
1706 entry.setId(pdbfile.id);
1708 } catch (java.io.IOException ex)
1710 ex.printStackTrace();
1713 entry.setFile(choice);
1714 sequence.getDatasetSequence().addPDBId(entry);
1719 public void enterPDB_actionPerformed()
1721 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1722 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1724 if (id != null && id.length() > 0)
1726 PDBEntry entry = new PDBEntry();
1727 entry.setId(id.toUpperCase());
1728 sequence.getDatasetSequence().addPDBId(entry);
1732 public void discoverPDB_actionPerformed()
1735 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1737 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1738 Thread discpdb = new Thread(new Runnable()
1743 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1744 .fetchDBRefs(false);
1751 public void sequenceFeature_actionPerformed()
1753 SequenceGroup sg = ap.av.getSelectionGroup();
1759 int rsize=0,gSize = sg.getSize();
1760 SequenceI[] rseqs,seqs = new SequenceI[gSize];
1761 SequenceFeature[] tfeatures,features = new SequenceFeature[gSize];
1763 for (int i = 0; i < gSize; i++)
1765 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1766 int end = sg.findEndRes(sg.getSequenceAt(i));
1769 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1770 features[rsize] = new SequenceFeature(null, null, null, start, end,
1775 rseqs = new SequenceI[rsize];
1776 tfeatures = new SequenceFeature[rsize];
1777 System.arraycopy(seqs,0,rseqs, 0, rsize);
1778 System.arraycopy(features, 0, tfeatures, 0, rsize);
1779 features = tfeatures;
1781 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1782 features, true, ap))
1784 ap.alignFrame.setShowSeqFeatures(true);
1785 ap.highlightSearchResults(null);
1789 public void textColour_actionPerformed()
1791 SequenceGroup sg = getGroup();
1794 new TextColourChooser().chooseColour(ap, sg);
1798 public void colourByStructure(String pdbid)
1800 Annotation[] anots = jalview.structure.StructureSelectionManager
1801 .getStructureSelectionManager().colourSequenceFromStructure(
1804 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1805 "Coloured by " + pdbid, anots);
1807 ap.av.alignment.addAnnotation(an);
1808 an.createSequenceMapping(sequence, 0, true);
1809 // an.adjustForAlignment();
1810 ap.av.alignment.setAnnotationIndex(an, 0);
1812 ap.adjustAnnotationHeight();
1814 sequence.addAlignmentAnnotation(an);
1818 public void editSequence_actionPerformed(ActionEvent actionEvent)
1820 SequenceGroup sg = ap.av.getSelectionGroup();
1824 if (sequence == null)
1825 sequence = (Sequence) sg.getSequenceAt(0);
1827 EditNameDialog dialog = new EditNameDialog(sequence
1828 .getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
1829 null, "Edit Sequence ", null, "Edit Sequence");
1833 EditCommand editCommand = new EditCommand("Edit Sequences",
1834 EditCommand.REPLACE, dialog.getName().replace(' ',
1835 ap.av.getGapCharacter()), sg
1836 .getSequencesAsArray(ap.av.hiddenRepSequences), sg
1837 .getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1839 ap.alignFrame.addHistoryItem(editCommand);
1841 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()