2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
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.UrlLink;
41 public class PopupMenu extends JPopupMenu
43 JMenu groupMenu = new JMenu();
45 JMenuItem groupName = new JMenuItem();
47 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
49 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
51 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
53 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
55 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
57 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
59 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
61 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
63 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
65 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
67 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
69 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
71 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
73 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
77 JMenu sequenceMenu = new JMenu();
79 JMenuItem sequenceName = new JMenuItem();
83 JMenuItem unGroupMenuItem = new JMenuItem();
85 JMenuItem outline = new JMenuItem();
87 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
89 JMenu colourMenu = new JMenu();
91 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
93 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
95 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
97 JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem();
99 JMenu editMenu = new JMenu();
101 JMenuItem cut = new JMenuItem();
103 JMenuItem copy = new JMenuItem();
105 JMenuItem upperCase = new JMenuItem();
107 JMenuItem lowerCase = new JMenuItem();
109 JMenuItem toggle = new JMenuItem();
111 JMenu pdbMenu = new JMenu();
113 JMenuItem pdbFromFile = new JMenuItem();
115 JMenuItem enterPDB = new JMenuItem();
117 JMenuItem discoverPDB = new JMenuItem();
119 JMenu outputMenu = new JMenu();
121 JMenuItem sequenceFeature = new JMenuItem();
123 JMenuItem textColour = new JMenuItem();
125 JMenu jMenu1 = new JMenu();
127 JMenu structureMenu = new JMenu();
129 JMenu viewStructureMenu = new JMenu();
131 // JMenu colStructureMenu = new JMenu();
132 JMenuItem editSequence = new JMenuItem();
134 // JMenuItem annotationMenuItem = new JMenuItem();
136 JMenu groupLinksMenu;
139 * Creates a new PopupMenu object.
146 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
148 this(ap, seq, links, null);
158 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links,
161 // /////////////////////////////////////////////////////////
162 // If this is activated from the sequence panel, the user may want to
163 // edit or annotate a particular residue. Therefore display the residue menu
165 // If from the IDPanel, we must display the sequence menu
166 // ////////////////////////////////////////////////////////
170 ButtonGroup colours = new ButtonGroup();
171 colours.add(noColourmenuItem);
172 colours.add(clustalColour);
173 colours.add(zappoColour);
174 colours.add(taylorColour);
175 colours.add(hydrophobicityColour);
176 colours.add(helixColour);
177 colours.add(strandColour);
178 colours.add(turnColour);
179 colours.add(buriedColour);
180 colours.add(abovePIDColour);
181 colours.add(userDefinedColour);
182 colours.add(PIDColour);
183 colours.add(BLOSUM62Colour);
185 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
187 JMenuItem item = new JMenuItem(
188 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
190 item.addActionListener(new java.awt.event.ActionListener()
192 public void actionPerformed(ActionEvent e)
194 outputText_actionPerformed(e);
198 outputMenu.add(item);
204 } catch (Exception e)
211 sequenceMenu.setText(sequence.getName());
214 if (seq.getDatasetSequence().getPDBId() != null
215 && seq.getDatasetSequence().getPDBId().size() > 0)
217 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
220 while (e.hasMoreElements())
222 final PDBEntry pdb = (PDBEntry) e.nextElement();
224 menuItem = new JMenuItem();
225 menuItem.setText(pdb.getId());
226 menuItem.addActionListener(new java.awt.event.ActionListener()
228 public void actionPerformed(ActionEvent e)
230 Vector seqs = new Vector();
231 for (int i = 0; i < ap.av.alignment.getHeight(); i++)
233 Vector pdbs = ap.av.alignment.getSequenceAt(i)
234 .getDatasetSequence().getPDBId();
238 for (int p = 0; p < pdbs.size(); p++)
240 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
241 if (p1.getId().equals(pdb.getId()))
243 if (!seqs.contains(ap.av.alignment.getSequenceAt(i)))
244 seqs.addElement(ap.av.alignment.getSequenceAt(i));
251 SequenceI[] seqs2 = new SequenceI[seqs.size()];
254 new AppJmol(pdb, seqs2, null, ap);
255 // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
258 viewStructureMenu.add(menuItem);
261 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
262 * menuItem.addActionListener(new java.awt.event.ActionListener() {
263 * public void actionPerformed(ActionEvent e) {
264 * colourByStructure(pdb.getId()); } });
265 * colStructureMenu.add(menuItem);
271 structureMenu.remove(viewStructureMenu);
272 // structureMenu.remove(colStructureMenu);
275 menuItem = new JMenuItem("Hide Sequences");
276 menuItem.addActionListener(new java.awt.event.ActionListener()
278 public void actionPerformed(ActionEvent e)
280 hideSequences(false);
285 if (ap.av.getSelectionGroup() != null
286 && ap.av.getSelectionGroup().getSize() > 1)
288 menuItem = new JMenuItem("Represent Group with " + seq.getName());
289 menuItem.addActionListener(new java.awt.event.ActionListener()
291 public void actionPerformed(ActionEvent e)
296 sequenceMenu.add(menuItem);
299 if (ap.av.hasHiddenRows)
301 final int index = ap.av.alignment.findIndex(seq);
303 if (ap.av.adjustForHiddenSeqs(index)
304 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
306 menuItem = new JMenuItem("Reveal Sequences");
307 menuItem.addActionListener(new ActionListener()
309 public void actionPerformed(ActionEvent e)
311 ap.av.showSequence(index);
312 if (ap.overviewPanel != null)
314 ap.overviewPanel.updateOverviewImage();
321 menuItem = new JMenuItem("Reveal All");
322 menuItem.addActionListener(new ActionListener()
324 public void actionPerformed(ActionEvent e)
326 ap.av.showAllHiddenSeqs();
327 if (ap.overviewPanel != null)
329 ap.overviewPanel.updateOverviewImage();
339 SequenceGroup sg = ap.av.getSelectionGroup();
343 groupName.setText(sg.getName());
345 if (sg.cs instanceof ZappoColourScheme)
347 zappoColour.setSelected(true);
349 else if (sg.cs instanceof TaylorColourScheme)
351 taylorColour.setSelected(true);
353 else if (sg.cs instanceof PIDColourScheme)
355 PIDColour.setSelected(true);
357 else if (sg.cs instanceof Blosum62ColourScheme)
359 BLOSUM62Colour.setSelected(true);
361 else if (sg.cs instanceof UserColourScheme)
363 userDefinedColour.setSelected(true);
365 else if (sg.cs instanceof HydrophobicColourScheme)
367 hydrophobicityColour.setSelected(true);
369 else if (sg.cs instanceof HelixColourScheme)
371 helixColour.setSelected(true);
373 else if (sg.cs instanceof StrandColourScheme)
375 strandColour.setSelected(true);
377 else if (sg.cs instanceof TurnColourScheme)
379 turnColour.setSelected(true);
381 else if (sg.cs instanceof BuriedColourScheme)
383 buriedColour.setSelected(true);
385 else if (sg.cs instanceof ClustalxColourScheme)
387 clustalColour.setSelected(true);
391 noColourmenuItem.setSelected(true);
394 if (sg.cs != null && sg.cs.conservationApplied())
396 conservationMenuItem.setSelected(true);
398 displayNonconserved.setSelected(sg.getShowunconserved());
399 showText.setSelected(sg.getDisplayText());
400 showColourText.setSelected(sg.getColourText());
401 showBoxes.setSelected(sg.getDisplayBoxes());
402 // add any groupURLs to the groupURL submenu and make it visible
403 if (groupLinks != null && groupLinks.size() > 0)
405 buildGroupURLMenu(sg, groupLinks);
410 groupMenu.setVisible(false);
411 editMenu.setVisible(false);
414 if (!ap.av.alignment.getGroups().contains(sg))
416 unGroupMenuItem.setVisible(false);
421 sequenceMenu.setVisible(false);
422 structureMenu.setVisible(false);
425 if (links != null && links.size() > 0)
428 JMenu linkMenu = new JMenu("Link");
429 Vector linkset = new Vector();
430 for (int i = 0; i < links.size(); i++)
432 String link = links.elementAt(i).toString();
433 UrlLink urlLink = null;
436 urlLink = new UrlLink(link);
437 } catch (Exception foo)
439 jalview.bin.Cache.log.error("Exception for URLLink '" + link
444 if (!urlLink.isValid())
446 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
449 final String label = urlLink.getLabel();
450 if (urlLink.isDynamic())
453 // collect matching db-refs
454 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq
455 .getDBRef(), new String[]
456 { urlLink.getTarget() });
457 // collect id string too
458 String id = seq.getName();
459 String descr = seq.getDescription();
460 if (descr != null && descr.length() < 1)
467 for (int r = 0; r < dbr.length; r++)
469 if (id != null && dbr[r].getAccessionId().equals(id))
471 // suppress duplicate link creation for the bare sequence ID
472 // string with this link
475 // create Bare ID link for this RUL
476 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
480 for (int u = 0; u < urls.length; u += 2)
482 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
484 linkset.addElement(urls[u] + "|" + urls[u + 1]);
485 addshowLink(linkMenu, label + "|" + urls[u],
494 // create Bare ID link for this RUL
495 String[] urls = urlLink.makeUrls(id, true);
498 for (int u = 0; u < urls.length; u += 2)
500 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
502 linkset.addElement(urls[u] + "|" + urls[u + 1]);
503 addshowLink(linkMenu, label, urls[u + 1]);
508 // Create urls from description but only for URL links which are regex
510 if (descr != null && urlLink.getRegexReplace() != null)
512 // create link for this URL from description where regex matches
513 String[] urls = urlLink.makeUrls(descr, true);
516 for (int u = 0; u < urls.length; u += 2)
518 if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
520 linkset.addElement(urls[u] + "|" + urls[u + 1]);
521 addshowLink(linkMenu, label, urls[u + 1]);
529 if (!linkset.contains(label + "|" + urlLink.getUrl_prefix()))
531 linkset.addElement(label + "|" + urlLink.getUrl_prefix());
532 // Add a non-dynamic link
533 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
537 if (sequence != null)
539 sequenceMenu.add(linkMenu);
548 private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
551 // TODO: usability: thread off the generation of group url content so root
553 // sequence only URLs
554 // ID/regex match URLs
555 groupLinksMenu = new JMenu("Group Link");
556 JMenu[] linkMenus = new JMenu[]
557 { null, new JMenu("IDS"), new JMenu("Sequences"),
558 new JMenu("IDS and Sequences") }; // three types of url that might be
560 SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
561 String[][] idandseqs = GroupUrlLink.formStrings(seqs);
562 Hashtable commonDbrefs = new Hashtable();
563 for (int sq = 0; sq < seqs.length; sq++)
566 int start = seqs[sq].findPosition(sg.getStartRes()), end = seqs[sq]
567 .findPosition(sg.getEndRes());
568 // just collect ids from dataset sequence
569 // TODO: check if IDs collected from selecton group intersects with the
570 // current selection, too
571 SequenceI sqi = seqs[sq];
572 while (sqi.getDatasetSequence() != null)
574 sqi = sqi.getDatasetSequence();
576 DBRefEntry[] dbr = sqi.getDBRef();
577 if (dbr != null && dbr.length > 0)
579 for (int d = 0; d < dbr.length; d++)
581 String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
582 Object[] sarray = (Object[]) commonDbrefs.get(src);
585 sarray = new Object[2];
586 sarray[0] = new int[]
588 sarray[1] = new String[seqs.length];
590 commonDbrefs.put(src, sarray);
593 if (((String[]) sarray[1])[sq] == null)
596 || (dbr[d].getMap().locateMappedRange(start, end) != null))
598 ((String[]) sarray[1])[sq] = dbr[d].getAccessionId();
599 ((int[]) sarray[0])[0]++;
605 // now create group links for all distinct ID/sequence sets.
606 boolean addMenu = false; // indicates if there are any group links to give
608 for (int i = 0; i < groupLinks.size(); i++)
610 String link = groupLinks.elementAt(i).toString();
611 GroupUrlLink urlLink = null;
614 urlLink = new GroupUrlLink(link);
615 } catch (Exception foo)
617 jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
622 if (!urlLink.isValid())
624 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
627 final String label = urlLink.getLabel();
628 boolean usingNames = false;
629 // Now see which parts of the group apply for this URL
630 String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
631 Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
632 String[] seqstr, ids; // input to makeUrl
635 int numinput = ((int[]) idset[0])[0];
636 String[] allids = ((String[]) idset[1]);
637 seqstr = new String[numinput];
638 ids = new String[numinput];
639 for (int sq = 0, idcount = 0; sq < seqs.length; sq++)
641 if (allids[sq] != null)
643 ids[idcount] = allids[sq];
644 seqstr[idcount++] = idandseqs[1][sq];
650 // just use the id/seq set
651 seqstr = idandseqs[1];
655 // and try and make the groupURL!
657 Object[] urlset = urlLink.makeUrlStubs(ids, seqstr, "FromJalview"
658 + System.currentTimeMillis(), false);
661 int type = urlLink.getGroupURLType() & 3;
662 // System.out.println(urlLink.getGroupURLType()
663 // +" "+((String[])urlset[3])[0]);
664 // first two bits ofurlLink type bitfield are sequenceids and sequences
665 // TODO: FUTURE: ensure the groupURL menu structure can be generalised
666 addshowLink(linkMenus[type], label
667 + (((type & 1) == 1) ? ("("
668 + (usingNames ? "Names" : ltarget) + ")") : ""),
675 groupLinksMenu = new JMenu("Group Links");
676 for (int m = 0; m < linkMenus.length; m++)
678 if (linkMenus[m] != null
679 && linkMenus[m].getMenuComponentCount() > 0)
681 groupLinksMenu.add(linkMenus[m]);
685 groupMenu.add(groupLinksMenu);
690 * add a show URL menu item to the given linkMenu
694 * - menu label string
698 private void addshowLink(JMenu linkMenu, String label, final String url)
700 JMenuItem item = new JMenuItem(label);
701 item.setToolTipText("open URL: " + url);
702 item.addActionListener(new java.awt.event.ActionListener()
704 public void actionPerformed(ActionEvent e)
706 new Thread(new Runnable()
722 * add a late bound groupURL item to the given linkMenu
726 * - menu label string
727 * @param urlgenerator
728 * GroupURLLink used to generate URL
730 * Object array returned from the makeUrlStubs function.
732 private void addshowLink(JMenu linkMenu, String label,
733 final GroupUrlLink urlgenerator, final Object[] urlstub)
735 JMenuItem item = new JMenuItem(label);
736 item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
737 + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
746 item.addActionListener(new java.awt.event.ActionListener()
748 public void actionPerformed(ActionEvent e)
750 new Thread(new Runnable()
755 showLink(urlgenerator.constructFrom(urlstub));
771 private void jbInit() throws Exception
773 groupMenu.setText("Group");
774 groupMenu.setText("Selection");
775 groupName.setText("Name");
776 groupName.addActionListener(new java.awt.event.ActionListener()
778 public void actionPerformed(ActionEvent e)
780 groupName_actionPerformed();
783 sequenceMenu.setText("Sequence");
784 sequenceName.setText("Edit Name/Description");
785 sequenceName.addActionListener(new java.awt.event.ActionListener()
787 public void actionPerformed(ActionEvent e)
789 sequenceName_actionPerformed();
792 PIDColour.setFocusPainted(false);
793 unGroupMenuItem.setText("Remove Group");
794 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
796 public void actionPerformed(ActionEvent e)
798 unGroupMenuItem_actionPerformed();
802 outline.setText("Border colour");
803 outline.addActionListener(new java.awt.event.ActionListener()
805 public void actionPerformed(ActionEvent e)
807 outline_actionPerformed();
810 nucleotideMenuItem.setText("Nucleotide");
811 nucleotideMenuItem.addActionListener(new ActionListener()
813 public void actionPerformed(ActionEvent e)
815 nucleotideMenuItem_actionPerformed();
818 colourMenu.setText("Group Colour");
819 showBoxes.setText("Boxes");
820 showBoxes.setState(true);
821 showBoxes.addActionListener(new ActionListener()
823 public void actionPerformed(ActionEvent e)
825 showBoxes_actionPerformed();
828 showText.setText("Text");
829 showText.setState(true);
830 showText.addActionListener(new ActionListener()
832 public void actionPerformed(ActionEvent e)
834 showText_actionPerformed();
837 showColourText.setText("Colour Text");
838 showColourText.addActionListener(new ActionListener()
840 public void actionPerformed(ActionEvent e)
842 showColourText_actionPerformed();
845 displayNonconserved.setText("Show Nonconserved");
846 displayNonconserved.setState(true);
847 displayNonconserved.addActionListener(new ActionListener()
849 public void actionPerformed(ActionEvent e)
851 showNonconserved_actionPerformed();
854 editMenu.setText("Edit");
856 cut.addActionListener(new ActionListener()
858 public void actionPerformed(ActionEvent e)
860 cut_actionPerformed();
863 upperCase.setText("To Upper Case");
864 upperCase.addActionListener(new ActionListener()
866 public void actionPerformed(ActionEvent e)
871 copy.setText("Copy");
872 copy.addActionListener(new ActionListener()
874 public void actionPerformed(ActionEvent e)
876 copy_actionPerformed();
879 lowerCase.setText("To Lower Case");
880 lowerCase.addActionListener(new ActionListener()
882 public void actionPerformed(ActionEvent e)
887 toggle.setText("Toggle Case");
888 toggle.addActionListener(new ActionListener()
890 public void actionPerformed(ActionEvent e)
895 pdbMenu.setText("Associate Structure with Sequence");
896 pdbFromFile.setText("From File");
897 pdbFromFile.addActionListener(new ActionListener()
899 public void actionPerformed(ActionEvent e)
901 pdbFromFile_actionPerformed();
904 enterPDB.setText("Enter PDB Id");
905 enterPDB.addActionListener(new ActionListener()
907 public void actionPerformed(ActionEvent e)
909 enterPDB_actionPerformed();
912 discoverPDB.setText("Discover PDB ids");
913 discoverPDB.addActionListener(new ActionListener()
915 public void actionPerformed(ActionEvent e)
917 discoverPDB_actionPerformed();
920 outputMenu.setText("Output to Textbox...");
921 sequenceFeature.setText("Create Sequence Feature");
922 sequenceFeature.addActionListener(new ActionListener()
924 public void actionPerformed(ActionEvent e)
926 sequenceFeature_actionPerformed();
929 textColour.setText("Text Colour");
930 textColour.addActionListener(new ActionListener()
932 public void actionPerformed(ActionEvent e)
934 textColour_actionPerformed();
937 jMenu1.setText("Group");
938 structureMenu.setText("Structure");
939 viewStructureMenu.setText("View Structure");
940 // colStructureMenu.setText("Colour By Structure");
941 editSequence.setText("Edit Sequence...");
942 editSequence.addActionListener(new ActionListener()
944 public void actionPerformed(ActionEvent actionEvent)
946 editSequence_actionPerformed(actionEvent);
950 * annotationMenuItem.setText("By Annotation");
951 * annotationMenuItem.addActionListener(new ActionListener() { public void
952 * actionPerformed(ActionEvent actionEvent) {
953 * annotationMenuItem_actionPerformed(actionEvent); } });
959 this.add(structureMenu);
960 groupMenu.add(editMenu);
961 groupMenu.add(outputMenu);
962 groupMenu.add(sequenceFeature);
963 groupMenu.add(jMenu1);
964 sequenceMenu.add(sequenceName);
965 colourMenu.add(textColour);
966 colourMenu.add(noColourmenuItem);
967 colourMenu.add(clustalColour);
968 colourMenu.add(BLOSUM62Colour);
969 colourMenu.add(PIDColour);
970 colourMenu.add(zappoColour);
971 colourMenu.add(taylorColour);
972 colourMenu.add(hydrophobicityColour);
973 colourMenu.add(helixColour);
974 colourMenu.add(strandColour);
975 colourMenu.add(turnColour);
976 colourMenu.add(buriedColour);
977 colourMenu.add(nucleotideMenuItem);
978 colourMenu.add(userDefinedColour);
980 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
982 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
983 .getUserColourSchemes().keys();
985 while (userColours.hasMoreElements())
987 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
988 item.addActionListener(new ActionListener()
990 public void actionPerformed(ActionEvent evt)
992 userDefinedColour_actionPerformed(evt);
995 colourMenu.add(item);
999 colourMenu.addSeparator();
1000 colourMenu.add(abovePIDColour);
1001 colourMenu.add(conservationMenuItem);
1002 // colourMenu.add(annotationMenuItem);
1005 editMenu.add(editSequence);
1006 editMenu.add(upperCase);
1007 editMenu.add(lowerCase);
1008 editMenu.add(toggle);
1009 pdbMenu.add(pdbFromFile);
1010 pdbMenu.add(enterPDB);
1011 pdbMenu.add(discoverPDB);
1012 jMenu1.add(groupName);
1013 jMenu1.add(unGroupMenuItem);
1014 jMenu1.add(colourMenu);
1015 jMenu1.add(showBoxes);
1016 jMenu1.add(showText);
1017 jMenu1.add(showColourText);
1018 jMenu1.add(outline);
1019 jMenu1.add(displayNonconserved);
1020 structureMenu.add(pdbMenu);
1021 structureMenu.add(viewStructureMenu);
1022 // structureMenu.add(colStructureMenu);
1023 noColourmenuItem.setText("None");
1024 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
1026 public void actionPerformed(ActionEvent e)
1028 noColourmenuItem_actionPerformed();
1032 clustalColour.setText("Clustalx colours");
1033 clustalColour.addActionListener(new java.awt.event.ActionListener()
1035 public void actionPerformed(ActionEvent e)
1037 clustalColour_actionPerformed();
1040 zappoColour.setText("Zappo");
1041 zappoColour.addActionListener(new java.awt.event.ActionListener()
1043 public void actionPerformed(ActionEvent e)
1045 zappoColour_actionPerformed();
1048 taylorColour.setText("Taylor");
1049 taylorColour.addActionListener(new java.awt.event.ActionListener()
1051 public void actionPerformed(ActionEvent e)
1053 taylorColour_actionPerformed();
1056 hydrophobicityColour.setText("Hydrophobicity");
1057 hydrophobicityColour
1058 .addActionListener(new java.awt.event.ActionListener()
1060 public void actionPerformed(ActionEvent e)
1062 hydrophobicityColour_actionPerformed();
1065 helixColour.setText("Helix propensity");
1066 helixColour.addActionListener(new java.awt.event.ActionListener()
1068 public void actionPerformed(ActionEvent e)
1070 helixColour_actionPerformed();
1073 strandColour.setText("Strand propensity");
1074 strandColour.addActionListener(new java.awt.event.ActionListener()
1076 public void actionPerformed(ActionEvent e)
1078 strandColour_actionPerformed();
1081 turnColour.setText("Turn propensity");
1082 turnColour.addActionListener(new java.awt.event.ActionListener()
1084 public void actionPerformed(ActionEvent e)
1086 turnColour_actionPerformed();
1089 buriedColour.setText("Buried Index");
1090 buriedColour.addActionListener(new java.awt.event.ActionListener()
1092 public void actionPerformed(ActionEvent e)
1094 buriedColour_actionPerformed();
1097 abovePIDColour.setText("Above % Identity");
1098 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
1100 public void actionPerformed(ActionEvent e)
1102 abovePIDColour_actionPerformed();
1105 userDefinedColour.setText("User Defined...");
1106 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
1108 public void actionPerformed(ActionEvent e)
1110 userDefinedColour_actionPerformed(e);
1113 PIDColour.setText("Percentage Identity");
1114 PIDColour.addActionListener(new java.awt.event.ActionListener()
1116 public void actionPerformed(ActionEvent e)
1118 PIDColour_actionPerformed();
1121 BLOSUM62Colour.setText("BLOSUM62");
1122 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
1124 public void actionPerformed(ActionEvent e)
1126 BLOSUM62Colour_actionPerformed();
1129 conservationMenuItem.setText("Conservation");
1130 conservationMenuItem
1131 .addActionListener(new java.awt.event.ActionListener()
1133 public void actionPerformed(ActionEvent e)
1135 conservationMenuItem_actionPerformed();
1140 protected void showNonconserved_actionPerformed()
1142 getGroup().setShowunconserved(displayNonconserved.isSelected());
1147 * call to refresh view after settings change
1151 ap.updateAnnotation();
1152 ap.paintAlignment(true);
1154 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
1163 protected void clustalColour_actionPerformed()
1165 SequenceGroup sg = getGroup();
1166 sg.cs = new ClustalxColourScheme(sg
1167 .getSequences(ap.av.hiddenRepSequences), ap.av.alignment
1178 protected void zappoColour_actionPerformed()
1180 getGroup().cs = new ZappoColourScheme();
1190 protected void taylorColour_actionPerformed()
1192 getGroup().cs = new TaylorColourScheme();
1202 protected void hydrophobicityColour_actionPerformed()
1204 getGroup().cs = new HydrophobicColourScheme();
1214 protected void helixColour_actionPerformed()
1216 getGroup().cs = new HelixColourScheme();
1226 protected void strandColour_actionPerformed()
1228 getGroup().cs = new StrandColourScheme();
1238 protected void turnColour_actionPerformed()
1240 getGroup().cs = new TurnColourScheme();
1250 protected void buriedColour_actionPerformed()
1252 getGroup().cs = new BuriedColourScheme();
1262 public void nucleotideMenuItem_actionPerformed()
1264 getGroup().cs = new NucleotideColourScheme();
1274 protected void abovePIDColour_actionPerformed()
1276 SequenceGroup sg = getGroup();
1282 if (abovePIDColour.isSelected())
1284 sg.cs.setConsensus(AAFrequency.calculate(sg
1285 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1288 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1291 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1293 SliderPanel.showPIDSlider();
1296 // remove PIDColouring
1298 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1310 protected void userDefinedColour_actionPerformed(ActionEvent e)
1312 SequenceGroup sg = getGroup();
1314 if (e.getActionCommand().equals("User Defined..."))
1316 new UserDefinedColours(ap, sg);
1320 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1321 .getUserColourSchemes().get(e.getActionCommand());
1334 protected void PIDColour_actionPerformed()
1336 SequenceGroup sg = getGroup();
1337 sg.cs = new PIDColourScheme();
1338 sg.cs.setConsensus(AAFrequency.calculate(sg
1339 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1350 protected void BLOSUM62Colour_actionPerformed()
1352 SequenceGroup sg = getGroup();
1354 sg.cs = new Blosum62ColourScheme();
1356 sg.cs.setConsensus(AAFrequency.calculate(sg
1357 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1369 protected void noColourmenuItem_actionPerformed()
1371 getGroup().cs = null;
1381 protected void conservationMenuItem_actionPerformed()
1383 SequenceGroup sg = getGroup();
1389 if (conservationMenuItem.isSelected())
1391 Conservation c = new Conservation("Group",
1392 ResidueProperties.propHash, 3, sg
1393 .getSequences(ap.av.hiddenRepSequences), sg
1394 .getStartRes(), sg.getEndRes() + 1);
1397 c.verdict(false, ap.av.ConsPercGaps);
1399 sg.cs.setConservation(c);
1401 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1402 SliderPanel.showConservationSlider();
1405 // remove ConservationColouring
1407 sg.cs.setConservation(null);
1413 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1415 SequenceGroup sg = getGroup();
1421 AnnotationColourGradient acg = new AnnotationColourGradient(sequence
1422 .getAnnotation()[0], null,
1423 AnnotationColourGradient.NO_THRESHOLD);
1425 acg.predefinedColours = true;
1437 protected void groupName_actionPerformed()
1440 SequenceGroup sg = getGroup();
1441 EditNameDialog dialog = new EditNameDialog(sg.getName(), sg
1442 .getDescription(), " Group Name ", "Group Description ",
1443 "Edit Group Name/Description");
1450 sg.setName(dialog.getName());
1451 sg.setDescription(dialog.getDescription());
1456 * Get selection group - adding it to the alignment if necessary.
1458 * @return sequence group to operate on
1460 SequenceGroup getGroup()
1462 SequenceGroup sg = ap.av.getSelectionGroup();
1463 // this method won't add a new group if it already exists
1466 ap.av.alignment.addGroup(sg);
1478 void sequenceName_actionPerformed()
1480 EditNameDialog dialog = new EditNameDialog(sequence.getName(), sequence
1481 .getDescription(), " Sequence Name ",
1482 "Sequence Description ", "Edit Sequence Name/Description");
1489 if (dialog.getName() != null)
1491 if (dialog.getName().indexOf(" ") > -1)
1493 JOptionPane.showMessageDialog(ap,
1494 "Spaces have been converted to \"_\"",
1495 "No spaces allowed in Sequence Name",
1496 JOptionPane.WARNING_MESSAGE);
1499 sequence.setName(dialog.getName().replace(' ', '_'));
1500 ap.paintAlignment(false);
1503 sequence.setDescription(dialog.getDescription());
1505 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1516 void unGroupMenuItem_actionPerformed()
1518 SequenceGroup sg = ap.av.getSelectionGroup();
1519 ap.av.alignment.deleteGroup(sg);
1520 ap.av.setSelectionGroup(null);
1530 protected void outline_actionPerformed()
1532 SequenceGroup sg = getGroup();
1533 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1538 sg.setOutlineColour(col);
1550 public void showBoxes_actionPerformed()
1552 getGroup().setDisplayBoxes(showBoxes.isSelected());
1562 public void showText_actionPerformed()
1564 getGroup().setDisplayText(showText.isSelected());
1574 public void showColourText_actionPerformed()
1576 getGroup().setColourText(showColourText.isSelected());
1580 public void showLink(String url)
1584 jalview.util.BrowserLauncher.openURL(url);
1585 } catch (Exception ex)
1588 .showInternalMessageDialog(
1590 "Unixers: Couldn't find default web browser."
1591 + "\nAdd the full path to your browser in Preferences.",
1592 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1594 ex.printStackTrace();
1598 void hideSequences(boolean representGroup)
1600 SequenceGroup sg = ap.av.getSelectionGroup();
1601 if (sg == null || sg.getSize() < 1)
1603 ap.av.hideSequence(new SequenceI[]
1608 ap.av.setSelectionGroup(null);
1612 ap.av.hideRepSequences(sequence, sg);
1617 int gsize = sg.getSize();
1620 hseqs = new SequenceI[gsize];
1623 for (int i = 0; i < gsize; i++)
1625 hseqs[index++] = sg.getSequenceAt(i);
1628 ap.av.hideSequence(hseqs);
1629 // refresh(); TODO: ? needed ?
1630 ap.av.sendSelection();
1633 public void copy_actionPerformed()
1635 ap.alignFrame.copy_actionPerformed(null);
1638 public void cut_actionPerformed()
1640 ap.alignFrame.cut_actionPerformed(null);
1643 void changeCase(ActionEvent e)
1645 Object source = e.getSource();
1646 SequenceGroup sg = ap.av.getSelectionGroup();
1650 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1651 sg.getEndRes() + 1);
1656 if (source == toggle)
1658 description = "Toggle Case";
1659 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1661 else if (source == upperCase)
1663 description = "To Upper Case";
1664 caseChange = ChangeCaseCommand.TO_UPPER;
1668 description = "To Lower Case";
1669 caseChange = ChangeCaseCommand.TO_LOWER;
1672 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description, sg
1673 .getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1676 ap.alignFrame.addHistoryItem(caseCommand);
1678 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1684 public void outputText_actionPerformed(ActionEvent e)
1686 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1687 cap.setForInput(null);
1688 Desktop.addInternalFrame(cap, "Alignment output - "
1689 + e.getActionCommand(), 600, 500);
1691 String[] omitHidden = null;
1693 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1694 // or we simply trust the user wants
1695 // wysiwig behaviour
1696 SequenceGroup sg = ap.av.getSelectionGroup();
1697 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1698 omitHidden = ap.av.getViewAsString(true);
1699 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1700 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1702 for (int i = 0; i < nala.length; i++)
1704 AlignmentAnnotation na = nala[i];
1705 oal.addAnnotation(na);
1708 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1709 oal, omitHidden, csel, sg));
1713 public void pdbFromFile_actionPerformed()
1715 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1716 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1717 chooser.setFileView(new jalview.io.JalviewFileView());
1718 chooser.setDialogTitle("Select a PDB file");
1719 chooser.setToolTipText("Load a PDB file");
1721 int value = chooser.showOpenDialog(null);
1723 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1725 PDBEntry entry = new PDBEntry();
1726 String choice = chooser.getSelectedFile().getPath();
1727 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1730 MCview.PDBfile pdbfile = new MCview.PDBfile(choice,
1731 jalview.io.AppletFormatAdapter.FILE);
1733 if (pdbfile.id == null)
1735 String reply = JOptionPane
1736 .showInternalInputDialog(
1738 "Couldn't find a PDB id in the file supplied."
1739 + "Please enter an Id to identify this structure.",
1740 "No PDB Id in File", JOptionPane.QUESTION_MESSAGE);
1750 entry.setId(pdbfile.id);
1752 } catch (java.io.IOException ex)
1754 ex.printStackTrace();
1757 entry.setFile(choice);
1758 sequence.getDatasetSequence().addPDBId(entry);
1763 public void enterPDB_actionPerformed()
1765 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1766 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1768 if (id != null && id.length() > 0)
1770 PDBEntry entry = new PDBEntry();
1771 entry.setId(id.toUpperCase());
1772 sequence.getDatasetSequence().addPDBId(entry);
1776 public void discoverPDB_actionPerformed()
1779 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1781 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1782 Thread discpdb = new Thread(new Runnable()
1787 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1788 .fetchDBRefs(false);
1795 public void sequenceFeature_actionPerformed()
1797 SequenceGroup sg = ap.av.getSelectionGroup();
1803 int rsize = 0, gSize = sg.getSize();
1804 SequenceI[] rseqs, seqs = new SequenceI[gSize];
1805 SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
1807 for (int i = 0; i < gSize; i++)
1809 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1810 int end = sg.findEndRes(sg.getSequenceAt(i));
1813 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1814 features[rsize] = new SequenceFeature(null, null, null, start, end,
1819 rseqs = new SequenceI[rsize];
1820 tfeatures = new SequenceFeature[rsize];
1821 System.arraycopy(seqs, 0, rseqs, 0, rsize);
1822 System.arraycopy(features, 0, tfeatures, 0, rsize);
1823 features = tfeatures;
1825 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1826 features, true, ap))
1828 ap.alignFrame.setShowSeqFeatures(true);
1829 ap.highlightSearchResults(null);
1833 public void textColour_actionPerformed()
1835 SequenceGroup sg = getGroup();
1838 new TextColourChooser().chooseColour(ap, sg);
1842 public void colourByStructure(String pdbid)
1844 Annotation[] anots = jalview.structure.StructureSelectionManager
1845 .getStructureSelectionManager().colourSequenceFromStructure(
1848 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1849 "Coloured by " + pdbid, anots);
1851 ap.av.alignment.addAnnotation(an);
1852 an.createSequenceMapping(sequence, 0, true);
1853 // an.adjustForAlignment();
1854 ap.av.alignment.setAnnotationIndex(an, 0);
1856 ap.adjustAnnotationHeight();
1858 sequence.addAlignmentAnnotation(an);
1862 public void editSequence_actionPerformed(ActionEvent actionEvent)
1864 SequenceGroup sg = ap.av.getSelectionGroup();
1868 if (sequence == null)
1869 sequence = (Sequence) sg.getSequenceAt(0);
1871 EditNameDialog dialog = new EditNameDialog(sequence
1872 .getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
1873 null, "Edit Sequence ", null, "Edit Sequence");
1877 EditCommand editCommand = new EditCommand("Edit Sequences",
1878 EditCommand.REPLACE, dialog.getName().replace(' ',
1879 ap.av.getGapCharacter()), sg
1880 .getSequencesAsArray(ap.av.hiddenRepSequences), sg
1881 .getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1883 ap.alignFrame.addHistoryItem(editCommand);
1885 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()