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("Name: "+sg.getName());
345 groupName.setText("Edit name and description of current group.");
347 if (sg.cs instanceof ZappoColourScheme)
349 zappoColour.setSelected(true);
351 else if (sg.cs instanceof TaylorColourScheme)
353 taylorColour.setSelected(true);
355 else if (sg.cs instanceof PIDColourScheme)
357 PIDColour.setSelected(true);
359 else if (sg.cs instanceof Blosum62ColourScheme)
361 BLOSUM62Colour.setSelected(true);
363 else if (sg.cs instanceof UserColourScheme)
365 userDefinedColour.setSelected(true);
367 else if (sg.cs instanceof HydrophobicColourScheme)
369 hydrophobicityColour.setSelected(true);
371 else if (sg.cs instanceof HelixColourScheme)
373 helixColour.setSelected(true);
375 else if (sg.cs instanceof StrandColourScheme)
377 strandColour.setSelected(true);
379 else if (sg.cs instanceof TurnColourScheme)
381 turnColour.setSelected(true);
383 else if (sg.cs instanceof BuriedColourScheme)
385 buriedColour.setSelected(true);
387 else if (sg.cs instanceof ClustalxColourScheme)
389 clustalColour.setSelected(true);
393 noColourmenuItem.setSelected(true);
396 if (sg.cs != null && sg.cs.conservationApplied())
398 conservationMenuItem.setSelected(true);
400 displayNonconserved.setSelected(sg.getShowNonconserved());
401 showText.setSelected(sg.getDisplayText());
402 showColourText.setSelected(sg.getColourText());
403 showBoxes.setSelected(sg.getDisplayBoxes());
404 // add any groupURLs to the groupURL submenu and make it visible
405 if (groupLinks != null && groupLinks.size() > 0)
407 buildGroupURLMenu(sg, groupLinks);
412 groupMenu.setVisible(false);
413 editMenu.setVisible(false);
416 if (!ap.av.alignment.getGroups().contains(sg))
418 unGroupMenuItem.setVisible(false);
423 sequenceMenu.setVisible(false);
424 structureMenu.setVisible(false);
427 if (links != null && links.size() > 0)
430 JMenu linkMenu = new JMenu("Link");
431 Vector linkset = new Vector();
432 for (int i = 0; i < links.size(); i++)
434 String link = links.elementAt(i).toString();
435 UrlLink urlLink = null;
438 urlLink = new UrlLink(link);
439 } catch (Exception foo)
441 jalview.bin.Cache.log.error("Exception for URLLink '" + link
446 if (!urlLink.isValid())
448 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
451 final String label = urlLink.getLabel();
452 if (urlLink.isDynamic())
455 // collect matching db-refs
456 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
457 seq.getDBRef(), new String[]
458 { urlLink.getTarget() });
459 // collect id string too
460 String id = seq.getName();
461 String descr = seq.getDescription();
462 if (descr != null && descr.length() < 1)
469 for (int r = 0; r < dbr.length; r++)
471 if (id != null && dbr[r].getAccessionId().equals(id))
473 // suppress duplicate link creation for the bare sequence ID
474 // string with this link
477 // create Bare ID link for this RUL
478 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
482 for (int u = 0; u < urls.length; u += 2)
484 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
486 linkset.addElement(urls[u] + "|" + urls[u + 1]);
487 addshowLink(linkMenu, label + "|" + urls[u],
496 // create Bare ID link for this RUL
497 String[] urls = urlLink.makeUrls(id, true);
500 for (int u = 0; u < urls.length; u += 2)
502 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
504 linkset.addElement(urls[u] + "|" + urls[u + 1]);
505 addshowLink(linkMenu, label, urls[u + 1]);
510 // Create urls from description but only for URL links which are regex
512 if (descr != null && urlLink.getRegexReplace() != null)
514 // create link for this URL from description where regex matches
515 String[] urls = urlLink.makeUrls(descr, true);
518 for (int u = 0; u < urls.length; u += 2)
520 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
522 linkset.addElement(urls[u] + "|" + urls[u + 1]);
523 addshowLink(linkMenu, label, urls[u + 1]);
531 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
533 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
534 // Add a non-dynamic link
535 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
539 if (sequence != null)
541 sequenceMenu.add(linkMenu);
550 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
553 // TODO: usability: thread off the generation of group url content so root
555 // sequence only URLs
556 // ID/regex match URLs
557 groupLinksMenu = new JMenu("Group Link");
558 JMenu[] linkMenus = new JMenu[]
559 { null, new JMenu("IDS"), new JMenu("Sequences"),
560 new JMenu("IDS and Sequences") }; // three types of url that might be
562 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
563 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
564 Hashtable commonDbrefs = new Hashtable();
565 for (int sq = 0; sq < seqs.length; sq++)
568 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
569 .findPosition(sg.getEndRes());
570 // just collect ids from dataset sequence
571 // TODO: check if IDs collected from selecton group intersects with the
572 // current selection, too
573 SequenceI sqi = seqs[sq];
574 while (sqi.getDatasetSequence() != null)
576 sqi = sqi.getDatasetSequence();
578 DBRefEntry[] dbr = sqi.getDBRef();
579 if (dbr != null && dbr.length > 0)
581 for (int d = 0; d < dbr.length; d++)
583 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
584 Object[] sarray = (Object[]) commonDbrefs.get(src);
587 sarray = new Object[2];
588 sarray[0] = new int[]
590 sarray[1] = new String[seqs.length];
592 commonDbrefs.put(src, sarray);
595 if (((String[]) sarray[1])[sq] == null)
598 || (dbr[d].getMap().locateMappedRange(start, end) != null))
600 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
601 ((int[]) sarray[0])[0]++;
607 // now create group links for all distinct ID/sequence sets.
608 boolean addMenu = false; // indicates if there are any group links to give
610 for (int i = 0; i < groupLinks.size(); i++)
612 String link = groupLinks.elementAt(i).toString();
613 GroupUrlLink urlLink = null;
616 urlLink = new GroupUrlLink(link);
617 } catch (Exception foo)
619 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
624 if (!urlLink.isValid())
626 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
629 final String label = urlLink.getLabel();
630 boolean usingNames = false;
631 // Now see which parts of the group apply for this URL
632 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
633 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
634 String[] seqstr, ids; // input to makeUrl
637 int numinput = ((int[]) idset[0])[0];
638 String[] allids = ((String[]) idset[1]);
639 seqstr = new String[numinput];
640 ids = new String[numinput];
641 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
643 if (allids[sq] != null)
645 ids[idcount] = allids[sq];
646 seqstr[idcount++] = idandseqs[1][sq];
652 // just use the id/seq set
653 seqstr = idandseqs[1];
657 // and try and make the groupURL!
659 Object[] urlset = null;
662 urlset = urlLink.makeUrlStubs(ids, seqstr,
663 "FromJalview" + System.currentTimeMillis(), false);
664 } catch (UrlStringTooLongException e)
669 int type = urlLink.getGroupURLType() & 3;
670 // System.out.println(urlLink.getGroupURLType()
671 // +" "+((String[])urlset[3])[0]);
672 // first two bits ofurlLink type bitfield are sequenceids and sequences
673 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
674 addshowLink(linkMenus[type], label
675 + (((type & 1) == 1) ? ("("
676 + (usingNames ? "Names" : ltarget) + ")") : ""),
683 groupLinksMenu = new JMenu("Group Links");
684 for (int m = 0; m < linkMenus.length; m++)
686 if (linkMenus[m] != null
687 && linkMenus[m].getMenuComponentCount() > 0)
689 groupLinksMenu.add(linkMenus[m]);
693 groupMenu.add(groupLinksMenu);
698 * add a show URL menu item to the given linkMenu
702 * - menu label string
706 private void addshowLink(JMenu linkMenu, String label, final String url)
708 JMenuItem item = new JMenuItem(label);
709 item.setToolTipText("open URL: " + url);
710 item.addActionListener(new java.awt.event.ActionListener()
712 public void actionPerformed(ActionEvent e)
714 new Thread(new Runnable()
730 * add a late bound groupURL item to the given linkMenu
734 * - menu label string
735 * @param urlgenerator
736 * GroupURLLink used to generate URL
738 * Object array returned from the makeUrlStubs function.
740 private void addshowLink(JMenu linkMenu, String label,
741 final GroupUrlLink urlgenerator, final Object[] urlstub)
743 JMenuItem item = new JMenuItem(label);
744 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
745 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
754 item.addActionListener(new java.awt.event.ActionListener()
756 public void actionPerformed(ActionEvent e)
758 new Thread(new Runnable()
765 showLink(urlgenerator.constructFrom(urlstub));
766 } catch (UrlStringTooLongException e)
784 private void jbInit() throws Exception
786 groupMenu.setText("Group");
787 groupMenu.setText("Selection");
788 groupName.setText("Name");
789 groupName.addActionListener(new java.awt.event.ActionListener()
791 public void actionPerformed(ActionEvent e)
793 groupName_actionPerformed();
796 sequenceMenu.setText("Sequence");
797 sequenceName.setText("Edit Name/Description");
798 sequenceName.addActionListener(new java.awt.event.ActionListener()
800 public void actionPerformed(ActionEvent e)
802 sequenceName_actionPerformed();
805 PIDColour.setFocusPainted(false);
806 unGroupMenuItem.setText("Remove Group");
807 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
809 public void actionPerformed(ActionEvent e)
811 unGroupMenuItem_actionPerformed();
815 outline.setText("Border colour");
816 outline.addActionListener(new java.awt.event.ActionListener()
818 public void actionPerformed(ActionEvent e)
820 outline_actionPerformed();
823 nucleotideMenuItem.setText("Nucleotide");
824 nucleotideMenuItem.addActionListener(new ActionListener()
826 public void actionPerformed(ActionEvent e)
828 nucleotideMenuItem_actionPerformed();
831 colourMenu.setText("Group Colour");
832 showBoxes.setText("Boxes");
833 showBoxes.setState(true);
834 showBoxes.addActionListener(new ActionListener()
836 public void actionPerformed(ActionEvent e)
838 showBoxes_actionPerformed();
841 showText.setText("Text");
842 showText.setState(true);
843 showText.addActionListener(new ActionListener()
845 public void actionPerformed(ActionEvent e)
847 showText_actionPerformed();
850 showColourText.setText("Colour Text");
851 showColourText.addActionListener(new ActionListener()
853 public void actionPerformed(ActionEvent e)
855 showColourText_actionPerformed();
858 displayNonconserved.setText("Show Nonconserved");
859 displayNonconserved.setState(true);
860 displayNonconserved.addActionListener(new ActionListener()
862 public void actionPerformed(ActionEvent e)
864 showNonconserved_actionPerformed();
867 editMenu.setText("Edit");
869 cut.addActionListener(new ActionListener()
871 public void actionPerformed(ActionEvent e)
873 cut_actionPerformed();
876 upperCase.setText("To Upper Case");
877 upperCase.addActionListener(new ActionListener()
879 public void actionPerformed(ActionEvent e)
884 copy.setText("Copy");
885 copy.addActionListener(new ActionListener()
887 public void actionPerformed(ActionEvent e)
889 copy_actionPerformed();
892 lowerCase.setText("To Lower Case");
893 lowerCase.addActionListener(new ActionListener()
895 public void actionPerformed(ActionEvent e)
900 toggle.setText("Toggle Case");
901 toggle.addActionListener(new ActionListener()
903 public void actionPerformed(ActionEvent e)
908 pdbMenu.setText("Associate Structure with Sequence");
909 pdbFromFile.setText("From File");
910 pdbFromFile.addActionListener(new ActionListener()
912 public void actionPerformed(ActionEvent e)
914 pdbFromFile_actionPerformed();
917 enterPDB.setText("Enter PDB Id");
918 enterPDB.addActionListener(new ActionListener()
920 public void actionPerformed(ActionEvent e)
922 enterPDB_actionPerformed();
925 discoverPDB.setText("Discover PDB ids");
926 discoverPDB.addActionListener(new ActionListener()
928 public void actionPerformed(ActionEvent e)
930 discoverPDB_actionPerformed();
933 outputMenu.setText("Output to Textbox...");
934 sequenceFeature.setText("Create Sequence Feature");
935 sequenceFeature.addActionListener(new ActionListener()
937 public void actionPerformed(ActionEvent e)
939 sequenceFeature_actionPerformed();
942 textColour.setText("Text Colour");
943 textColour.addActionListener(new ActionListener()
945 public void actionPerformed(ActionEvent e)
947 textColour_actionPerformed();
950 jMenu1.setText("Group");
951 structureMenu.setText("Structure");
952 viewStructureMenu.setText("View Structure");
953 // colStructureMenu.setText("Colour By Structure");
954 editSequence.setText("Edit Sequence...");
955 editSequence.addActionListener(new ActionListener()
957 public void actionPerformed(ActionEvent actionEvent)
959 editSequence_actionPerformed(actionEvent);
963 * annotationMenuItem.setText("By Annotation");
964 * annotationMenuItem.addActionListener(new ActionListener() { public void
965 * actionPerformed(ActionEvent actionEvent) {
966 * annotationMenuItem_actionPerformed(actionEvent); } });
972 this.add(structureMenu);
973 groupMenu.add(editMenu);
974 groupMenu.add(outputMenu);
975 groupMenu.add(sequenceFeature);
976 groupMenu.add(jMenu1);
977 sequenceMenu.add(sequenceName);
978 colourMenu.add(textColour);
979 colourMenu.add(noColourmenuItem);
980 colourMenu.add(clustalColour);
981 colourMenu.add(BLOSUM62Colour);
982 colourMenu.add(PIDColour);
983 colourMenu.add(zappoColour);
984 colourMenu.add(taylorColour);
985 colourMenu.add(hydrophobicityColour);
986 colourMenu.add(helixColour);
987 colourMenu.add(strandColour);
988 colourMenu.add(turnColour);
989 colourMenu.add(buriedColour);
990 colourMenu.add(nucleotideMenuItem);
991 colourMenu.add(userDefinedColour);
993 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
995 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
996 .getUserColourSchemes().keys();
998 while (userColours.hasMoreElements())
1000 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
1001 item.addActionListener(new ActionListener()
1003 public void actionPerformed(ActionEvent evt)
1005 userDefinedColour_actionPerformed(evt);
1008 colourMenu.add(item);
1012 colourMenu.addSeparator();
1013 colourMenu.add(abovePIDColour);
1014 colourMenu.add(conservationMenuItem);
1015 // colourMenu.add(annotationMenuItem);
1018 editMenu.add(editSequence);
1019 editMenu.add(upperCase);
1020 editMenu.add(lowerCase);
1021 editMenu.add(toggle);
1022 pdbMenu.add(pdbFromFile);
1023 pdbMenu.add(enterPDB);
1024 pdbMenu.add(discoverPDB);
1025 jMenu1.add(groupName);
1026 jMenu1.add(unGroupMenuItem);
1027 jMenu1.add(colourMenu);
1028 jMenu1.add(showBoxes);
1029 jMenu1.add(showText);
1030 jMenu1.add(showColourText);
1031 jMenu1.add(outline);
1032 jMenu1.add(displayNonconserved);
1033 structureMenu.add(pdbMenu);
1034 structureMenu.add(viewStructureMenu);
1035 // structureMenu.add(colStructureMenu);
1036 noColourmenuItem.setText("None");
1037 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1039 public void actionPerformed(ActionEvent e)
1041 noColourmenuItem_actionPerformed();
1045 clustalColour.setText("Clustalx colours");
1046 clustalColour.addActionListener(new java.awt.event.ActionListener()
1048 public void actionPerformed(ActionEvent e)
1050 clustalColour_actionPerformed();
1053 zappoColour.setText("Zappo");
1054 zappoColour.addActionListener(new java.awt.event.ActionListener()
1056 public void actionPerformed(ActionEvent e)
1058 zappoColour_actionPerformed();
1061 taylorColour.setText("Taylor");
1062 taylorColour.addActionListener(new java.awt.event.ActionListener()
1064 public void actionPerformed(ActionEvent e)
1066 taylorColour_actionPerformed();
1069 hydrophobicityColour.setText("Hydrophobicity");
1070 hydrophobicityColour
1071 .addActionListener(new java.awt.event.ActionListener()
1073 public void actionPerformed(ActionEvent e)
1075 hydrophobicityColour_actionPerformed();
1078 helixColour.setText("Helix propensity");
1079 helixColour.addActionListener(new java.awt.event.ActionListener()
1081 public void actionPerformed(ActionEvent e)
1083 helixColour_actionPerformed();
1086 strandColour.setText("Strand propensity");
1087 strandColour.addActionListener(new java.awt.event.ActionListener()
1089 public void actionPerformed(ActionEvent e)
1091 strandColour_actionPerformed();
1094 turnColour.setText("Turn propensity");
1095 turnColour.addActionListener(new java.awt.event.ActionListener()
1097 public void actionPerformed(ActionEvent e)
1099 turnColour_actionPerformed();
1102 buriedColour.setText("Buried Index");
1103 buriedColour.addActionListener(new java.awt.event.ActionListener()
1105 public void actionPerformed(ActionEvent e)
1107 buriedColour_actionPerformed();
1110 abovePIDColour.setText("Above % Identity");
1111 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1113 public void actionPerformed(ActionEvent e)
1115 abovePIDColour_actionPerformed();
1118 userDefinedColour.setText("User Defined...");
1119 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1121 public void actionPerformed(ActionEvent e)
1123 userDefinedColour_actionPerformed(e);
1126 PIDColour.setText("Percentage Identity");
1127 PIDColour.addActionListener(new java.awt.event.ActionListener()
1129 public void actionPerformed(ActionEvent e)
1131 PIDColour_actionPerformed();
1134 BLOSUM62Colour.setText("BLOSUM62");
1135 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1137 public void actionPerformed(ActionEvent e)
1139 BLOSUM62Colour_actionPerformed();
1142 conservationMenuItem.setText("Conservation");
1143 conservationMenuItem
1144 .addActionListener(new java.awt.event.ActionListener()
1146 public void actionPerformed(ActionEvent e)
1148 conservationMenuItem_actionPerformed();
1153 protected void showNonconserved_actionPerformed()
1155 getGroup().setShowNonconserved(displayNonconserved.isSelected());
1160 * call to refresh view after settings change
1164 ap.updateAnnotation();
1165 ap.paintAlignment(true);
1167 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1176 protected void clustalColour_actionPerformed()
1178 SequenceGroup sg = getGroup();
1179 sg.cs = new ClustalxColourScheme(
1180 sg.getSequences(ap.av.hiddenRepSequences),
1181 ap.av.alignment.getWidth());
1191 protected void zappoColour_actionPerformed()
1193 getGroup().cs = new ZappoColourScheme();
1203 protected void taylorColour_actionPerformed()
1205 getGroup().cs = new TaylorColourScheme();
1215 protected void hydrophobicityColour_actionPerformed()
1217 getGroup().cs = new HydrophobicColourScheme();
1227 protected void helixColour_actionPerformed()
1229 getGroup().cs = new HelixColourScheme();
1239 protected void strandColour_actionPerformed()
1241 getGroup().cs = new StrandColourScheme();
1251 protected void turnColour_actionPerformed()
1253 getGroup().cs = new TurnColourScheme();
1263 protected void buriedColour_actionPerformed()
1265 getGroup().cs = new BuriedColourScheme();
1275 public void nucleotideMenuItem_actionPerformed()
1277 getGroup().cs = new NucleotideColourScheme();
1287 protected void abovePIDColour_actionPerformed()
1289 SequenceGroup sg = getGroup();
1295 if (abovePIDColour.isSelected())
1297 sg.cs.setConsensus(AAFrequency.calculate(
1298 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1299 sg.getEndRes() + 1));
1301 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1304 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1306 SliderPanel.showPIDSlider();
1309 // remove PIDColouring
1311 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1323 protected void userDefinedColour_actionPerformed(ActionEvent e)
1325 SequenceGroup sg = getGroup();
1327 if (e.getActionCommand().equals("User Defined..."))
1329 new UserDefinedColours(ap, sg);
1333 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1334 .getUserColourSchemes().get(e.getActionCommand());
1347 protected void PIDColour_actionPerformed()
1349 SequenceGroup sg = getGroup();
1350 sg.cs = new PIDColourScheme();
1351 sg.cs.setConsensus(AAFrequency.calculate(
1352 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1353 sg.getEndRes() + 1));
1363 protected void BLOSUM62Colour_actionPerformed()
1365 SequenceGroup sg = getGroup();
1367 sg.cs = new Blosum62ColourScheme();
1369 sg.cs.setConsensus(AAFrequency.calculate(
1370 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1371 sg.getEndRes() + 1));
1382 protected void noColourmenuItem_actionPerformed()
1384 getGroup().cs = null;
1394 protected void conservationMenuItem_actionPerformed()
1396 SequenceGroup sg = getGroup();
1402 if (conservationMenuItem.isSelected())
1404 Conservation c = new Conservation("Group",
1405 ResidueProperties.propHash, 3,
1406 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
1407 sg.getEndRes() + 1);
1410 c.verdict(false, ap.av.ConsPercGaps);
1412 sg.cs.setConservation(c);
1414 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1415 SliderPanel.showConservationSlider();
1418 // remove ConservationColouring
1420 sg.cs.setConservation(null);
1426 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1428 SequenceGroup sg = getGroup();
1434 AnnotationColourGradient acg = new AnnotationColourGradient(
1435 sequence.getAnnotation()[0], null,
1436 AnnotationColourGradient.NO_THRESHOLD);
1438 acg.predefinedColours = true;
1450 protected void groupName_actionPerformed()
1453 SequenceGroup sg = getGroup();
1454 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1455 sg.getDescription(), " Group Name ",
1456 "Group Description ", "Edit Group Name/Description",
1464 sg.setName(dialog.getName());
1465 sg.setDescription(dialog.getDescription());
1470 * Get selection group - adding it to the alignment if necessary.
1472 * @return sequence group to operate on
1474 SequenceGroup getGroup()
1476 SequenceGroup sg = ap.av.getSelectionGroup();
1477 // this method won't add a new group if it already exists
1480 ap.av.alignment.addGroup(sg);
1492 void sequenceName_actionPerformed()
1494 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1495 sequence.getDescription(), " Sequence Name ",
1496 "Sequence Description ", "Edit Sequence Name/Description",
1504 if (dialog.getName() != null)
1506 if (dialog.getName().indexOf(" ") > -1)
1508 JOptionPane.showMessageDialog(ap,
1509 "Spaces have been converted to \"_\"",
1510 "No spaces allowed in Sequence Name",
1511 JOptionPane.WARNING_MESSAGE);
1514 sequence.setName(dialog.getName().replace(' ', '_'));
1515 ap.paintAlignment(false);
1518 sequence.setDescription(dialog.getDescription());
1520 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1531 void unGroupMenuItem_actionPerformed()
1533 SequenceGroup sg = ap.av.getSelectionGroup();
1534 ap.av.alignment.deleteGroup(sg);
1535 ap.av.setSelectionGroup(null);
1545 protected void outline_actionPerformed()
1547 SequenceGroup sg = getGroup();
1548 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1553 sg.setOutlineColour(col);
1565 public void showBoxes_actionPerformed()
1567 getGroup().setDisplayBoxes(showBoxes.isSelected());
1577 public void showText_actionPerformed()
1579 getGroup().setDisplayText(showText.isSelected());
1589 public void showColourText_actionPerformed()
1591 getGroup().setColourText(showColourText.isSelected());
1595 public void showLink(String url)
1599 jalview.util.BrowserLauncher.openURL(url);
1600 } catch (Exception ex)
1603 .showInternalMessageDialog(
1605 "Unixers: Couldn't find default web browser."
1606 + "\nAdd the full path to your browser in Preferences.",
1607 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1609 ex.printStackTrace();
1613 void hideSequences(boolean representGroup)
1615 SequenceGroup sg = ap.av.getSelectionGroup();
1616 if (sg == null || sg.getSize() < 1)
1618 ap.av.hideSequence(new SequenceI[]
1623 ap.av.setSelectionGroup(null);
1627 ap.av.hideRepSequences(sequence, sg);
1632 int gsize = sg.getSize();
1635 hseqs = new SequenceI[gsize];
1638 for (int i = 0; i < gsize; i++)
1640 hseqs[index++] = sg.getSequenceAt(i);
1643 ap.av.hideSequence(hseqs);
1644 // refresh(); TODO: ? needed ?
1645 ap.av.sendSelection();
1648 public void copy_actionPerformed()
1650 ap.alignFrame.copy_actionPerformed(null);
1653 public void cut_actionPerformed()
1655 ap.alignFrame.cut_actionPerformed(null);
1658 void changeCase(ActionEvent e)
1660 Object source = e.getSource();
1661 SequenceGroup sg = ap.av.getSelectionGroup();
1665 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1666 sg.getEndRes() + 1);
1671 if (source == toggle)
1673 description = "Toggle Case";
1674 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1676 else if (source == upperCase)
1678 description = "To Upper Case";
1679 caseChange = ChangeCaseCommand.TO_UPPER;
1683 description = "To Lower Case";
1684 caseChange = ChangeCaseCommand.TO_LOWER;
1687 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
1688 sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1691 ap.alignFrame.addHistoryItem(caseCommand);
1693 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1699 public void outputText_actionPerformed(ActionEvent e)
1701 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1702 cap.setForInput(null);
1703 Desktop.addInternalFrame(cap,
1704 "Alignment output - " + e.getActionCommand(), 600, 500);
1706 String[] omitHidden = null;
1708 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1709 // or we simply trust the user wants
1710 // wysiwig behaviour
1711 SequenceGroup sg = ap.av.getSelectionGroup();
1712 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1713 omitHidden = ap.av.getViewAsString(true);
1714 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1715 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1718 for (int i = 0; i < nala.length; i++)
1720 AlignmentAnnotation na = nala[i];
1721 oal.addAnnotation(na);
1724 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1725 oal, omitHidden, csel, sg));
1729 public void pdbFromFile_actionPerformed()
1731 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1732 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1733 chooser.setFileView(new jalview.io.JalviewFileView());
1734 chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
1735 chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
1737 int value = chooser.showOpenDialog(null);
1739 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1741 String choice = chooser.getSelectedFile().getPath();
1742 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1743 new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
1748 public void enterPDB_actionPerformed()
1750 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1751 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1753 if (id != null && id.length() > 0)
1755 PDBEntry entry = new PDBEntry();
1756 entry.setId(id.toUpperCase());
1757 sequence.getDatasetSequence().addPDBId(entry);
1761 public void discoverPDB_actionPerformed()
1764 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1766 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1767 Thread discpdb = new Thread(new Runnable()
1772 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1773 .fetchDBRefs(false);
1780 public void sequenceFeature_actionPerformed()
1782 SequenceGroup sg = ap.av.getSelectionGroup();
1788 int rsize = 0, gSize = sg.getSize();
1789 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1790 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1792 for (int i = 0; i < gSize; i++)
1794 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1795 int end = sg.findEndRes(sg.getSequenceAt(i));
1798 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1799 features[rsize] = new SequenceFeature(null, null, null, start, end,
1804 rseqs = new SequenceI[rsize];
1805 tfeatures = new SequenceFeature[rsize];
1806 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1807 System.arraycopy(features, 0, tfeatures, 0, rsize);
1808 features = tfeatures;
1810 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1811 features, true, ap))
1813 ap.alignFrame.setShowSeqFeatures(true);
1814 ap.highlightSearchResults(null);
1818 public void textColour_actionPerformed()
1820 SequenceGroup sg = getGroup();
1823 new TextColourChooser().chooseColour(ap, sg);
1827 public void colourByStructure(String pdbid)
1829 Annotation[] anots = jalview.structure.StructureSelectionManager
1830 .getStructureSelectionManager().colourSequenceFromStructure(
1833 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1834 "Coloured by " + pdbid, anots);
1836 ap.av.alignment.addAnnotation(an);
1837 an.createSequenceMapping(sequence, 0, true);
1838 // an.adjustForAlignment();
1839 ap.av.alignment.setAnnotationIndex(an, 0);
1841 ap.adjustAnnotationHeight();
1843 sequence.addAlignmentAnnotation(an);
1847 public void editSequence_actionPerformed(ActionEvent actionEvent)
1849 SequenceGroup sg = ap.av.getSelectionGroup();
1853 if (sequence == null)
1854 sequence = (Sequence) sg.getSequenceAt(0);
1856 EditNameDialog dialog = new EditNameDialog(
1857 sequence.getSequenceAsString(sg.getStartRes(),
1858 sg.getEndRes() + 1), null, "Edit Sequence ", null,
1859 "Edit Sequence", ap.alignFrame);
1863 EditCommand editCommand = new EditCommand("Edit Sequences",
1864 EditCommand.REPLACE, dialog.getName().replace(' ',
1865 ap.av.getGapCharacter()),
1866 sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1867 sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1869 ap.alignFrame.addHistoryItem(editCommand);
1871 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()