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.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();
137 * Creates a new PopupMenu object.
144 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
146 // /////////////////////////////////////////////////////////
147 // If this is activated from the sequence panel, the user may want to
148 // edit or annotate a particular residue. Therefore display the residue menu
150 // If from the IDPanel, we must display the sequence menu
151 // ////////////////////////////////////////////////////////
155 ButtonGroup colours = new ButtonGroup();
156 colours.add(noColourmenuItem);
157 colours.add(clustalColour);
158 colours.add(zappoColour);
159 colours.add(taylorColour);
160 colours.add(hydrophobicityColour);
161 colours.add(helixColour);
162 colours.add(strandColour);
163 colours.add(turnColour);
164 colours.add(buriedColour);
165 colours.add(abovePIDColour);
166 colours.add(userDefinedColour);
167 colours.add(PIDColour);
168 colours.add(BLOSUM62Colour);
170 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
172 JMenuItem item = new JMenuItem(
173 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
175 item.addActionListener(new java.awt.event.ActionListener()
177 public void actionPerformed(ActionEvent e)
179 outputText_actionPerformed(e);
183 outputMenu.add(item);
189 } catch (Exception e)
196 sequenceMenu.setText(sequence.getName());
199 if (seq.getDatasetSequence().getPDBId() != null
200 && seq.getDatasetSequence().getPDBId().size() > 0)
202 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
205 while (e.hasMoreElements())
207 final PDBEntry pdb = (PDBEntry) e.nextElement();
209 menuItem = new JMenuItem();
210 menuItem.setText(pdb.getId());
211 menuItem.addActionListener(new java.awt.event.ActionListener()
213 public void actionPerformed(ActionEvent e)
215 Vector seqs = new Vector();
216 for (int i = 0; i < ap.av.alignment.getHeight(); i++)
218 Vector pdbs = ap.av.alignment.getSequenceAt(i)
219 .getDatasetSequence().getPDBId();
223 for (int p = 0; p < pdbs.size(); p++)
225 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
226 if (p1.getId().equals(pdb.getId()))
228 if (!seqs.contains(ap.av.alignment.getSequenceAt(i)))
229 seqs.addElement(ap.av.alignment.getSequenceAt(i));
236 SequenceI[] seqs2 = new SequenceI[seqs.size()];
239 new AppJmol(pdb, seqs2, null, ap);
240 // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
243 viewStructureMenu.add(menuItem);
246 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
247 * menuItem.addActionListener(new java.awt.event.ActionListener() {
248 * public void actionPerformed(ActionEvent e) {
249 * colourByStructure(pdb.getId()); } });
250 * colStructureMenu.add(menuItem);
256 structureMenu.remove(viewStructureMenu);
257 // structureMenu.remove(colStructureMenu);
260 menuItem = new JMenuItem("Hide Sequences");
261 menuItem.addActionListener(new java.awt.event.ActionListener()
263 public void actionPerformed(ActionEvent e)
265 hideSequences(false);
270 if (ap.av.getSelectionGroup() != null
271 && ap.av.getSelectionGroup().getSize() > 1)
273 menuItem = new JMenuItem("Represent Group with " + seq.getName());
274 menuItem.addActionListener(new java.awt.event.ActionListener()
276 public void actionPerformed(ActionEvent e)
281 sequenceMenu.add(menuItem);
284 if (ap.av.hasHiddenRows)
286 final int index = ap.av.alignment.findIndex(seq);
288 if (ap.av.adjustForHiddenSeqs(index)
289 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
291 menuItem = new JMenuItem("Reveal Sequences");
292 menuItem.addActionListener(new ActionListener()
294 public void actionPerformed(ActionEvent e)
296 ap.av.showSequence(index);
297 if (ap.overviewPanel != null)
299 ap.overviewPanel.updateOverviewImage();
306 menuItem = new JMenuItem("Reveal All");
307 menuItem.addActionListener(new ActionListener()
309 public void actionPerformed(ActionEvent e)
311 ap.av.showAllHiddenSeqs();
312 if (ap.overviewPanel != null)
314 ap.overviewPanel.updateOverviewImage();
324 SequenceGroup sg = ap.av.getSelectionGroup();
328 groupName.setText(sg.getName());
330 if (sg.cs instanceof ZappoColourScheme)
332 zappoColour.setSelected(true);
334 else if (sg.cs instanceof TaylorColourScheme)
336 taylorColour.setSelected(true);
338 else if (sg.cs instanceof PIDColourScheme)
340 PIDColour.setSelected(true);
342 else if (sg.cs instanceof Blosum62ColourScheme)
344 BLOSUM62Colour.setSelected(true);
346 else if (sg.cs instanceof UserColourScheme)
348 userDefinedColour.setSelected(true);
350 else if (sg.cs instanceof HydrophobicColourScheme)
352 hydrophobicityColour.setSelected(true);
354 else if (sg.cs instanceof HelixColourScheme)
356 helixColour.setSelected(true);
358 else if (sg.cs instanceof StrandColourScheme)
360 strandColour.setSelected(true);
362 else if (sg.cs instanceof TurnColourScheme)
364 turnColour.setSelected(true);
366 else if (sg.cs instanceof BuriedColourScheme)
368 buriedColour.setSelected(true);
370 else if (sg.cs instanceof ClustalxColourScheme)
372 clustalColour.setSelected(true);
376 noColourmenuItem.setSelected(true);
379 if (sg.cs != null && sg.cs.conservationApplied())
381 conservationMenuItem.setSelected(true);
383 displayNonconserved.setSelected(sg.getShowunconserved());
384 showText.setSelected(sg.getDisplayText());
385 showColourText.setSelected(sg.getColourText());
386 showBoxes.setSelected(sg.getDisplayBoxes());
390 groupMenu.setVisible(false);
391 editMenu.setVisible(false);
394 if (!ap.av.alignment.getGroups().contains(sg))
396 unGroupMenuItem.setVisible(false);
401 sequenceMenu.setVisible(false);
402 structureMenu.setVisible(false);
405 if (links != null && links.size() > 0)
407 JMenu linkMenu = new JMenu("Link");
408 Vector linkset = new Vector();
409 for (int i = 0; i < links.size(); i++)
411 String link = links.elementAt(i).toString();
412 UrlLink urlLink = null;
415 urlLink = new UrlLink(link);
416 } catch (Exception foo)
418 jalview.bin.Cache.log.error("Exception for URLLink '" + link
423 if (!urlLink.isValid())
425 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
428 final String label = urlLink.getLabel();
429 if (urlLink.isDynamic())
432 // collect matching db-refs
433 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq
434 .getDBRef(), new String[]
435 { urlLink.getTarget() });
436 // collect id string too
437 String id = seq.getName();
438 String descr = seq.getDescription();
439 if (descr!=null && descr.length()<1)
446 for (int r = 0; r < dbr.length; r++)
448 if (id != null && dbr[r].getAccessionId().equals(id))
450 // suppress duplicate link creation for the bare sequence ID
451 // string with this link
454 // create Bare ID link for this RUL
455 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
459 for (int u = 0; u < urls.length; u += 2)
461 if (!linkset.contains(urls[u]+"|"+urls[u+1]))
463 linkset.addElement(urls[u]+"|"+urls[u+1]);
464 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
472 // create Bare ID link for this RUL
473 String[] urls = urlLink.makeUrls(id, true);
476 for (int u = 0; u < urls.length; u += 2)
478 if (!linkset.contains(urls[u]+"|"+urls[u+1]))
480 linkset.addElement(urls[u]+"|"+urls[u+1]);
481 addshowLink(linkMenu, label, urls[u + 1]);
486 // Create urls from description but only for URL links which are regex links
487 if (descr != null && urlLink.getRegexReplace()!=null)
489 // create link for this URL from description where regex matches
490 String[] urls = urlLink.makeUrls(descr, true);
493 for (int u = 0; u < urls.length; u += 2)
495 if (!linkset.contains(urls[u]+"|"+urls[u+1]))
497 linkset.addElement(urls[u]+"|"+urls[u+1]);
498 addshowLink(linkMenu, label, urls[u + 1]);
506 if (!linkset.contains(label+"|"+urlLink.getUrl_prefix()))
508 linkset.addElement(label+"|"+urlLink.getUrl_prefix());
509 // Add a non-dynamic link
510 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
514 if (sequence != null)
516 sequenceMenu.add(linkMenu);
526 * add a show URL menu item to the given linkMenu
534 private void addshowLink(JMenu linkMenu, String label, final String url)
536 JMenuItem item = new JMenuItem(label);
537 item.setToolTipText("open URL: " + url);
538 item.addActionListener(new java.awt.event.ActionListener()
540 public void actionPerformed(ActionEvent e)
542 new Thread(new Runnable()
563 private void jbInit() throws Exception
565 groupMenu.setText("Group");
566 groupMenu.setText("Selection");
567 groupName.setText("Name");
568 groupName.addActionListener(new java.awt.event.ActionListener()
570 public void actionPerformed(ActionEvent e)
572 groupName_actionPerformed();
575 sequenceMenu.setText("Sequence");
576 sequenceName.setText("Edit Name/Description");
577 sequenceName.addActionListener(new java.awt.event.ActionListener()
579 public void actionPerformed(ActionEvent e)
581 sequenceName_actionPerformed();
584 PIDColour.setFocusPainted(false);
585 unGroupMenuItem.setText("Remove Group");
586 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
588 public void actionPerformed(ActionEvent e)
590 unGroupMenuItem_actionPerformed();
594 outline.setText("Border colour");
595 outline.addActionListener(new java.awt.event.ActionListener()
597 public void actionPerformed(ActionEvent e)
599 outline_actionPerformed();
602 nucleotideMenuItem.setText("Nucleotide");
603 nucleotideMenuItem.addActionListener(new ActionListener()
605 public void actionPerformed(ActionEvent e)
607 nucleotideMenuItem_actionPerformed();
610 colourMenu.setText("Group Colour");
611 showBoxes.setText("Boxes");
612 showBoxes.setState(true);
613 showBoxes.addActionListener(new ActionListener()
615 public void actionPerformed(ActionEvent e)
617 showBoxes_actionPerformed();
620 showText.setText("Text");
621 showText.setState(true);
622 showText.addActionListener(new ActionListener()
624 public void actionPerformed(ActionEvent e)
626 showText_actionPerformed();
629 showColourText.setText("Colour Text");
630 showColourText.addActionListener(new ActionListener()
632 public void actionPerformed(ActionEvent e)
634 showColourText_actionPerformed();
637 displayNonconserved.setText("Show Nonconserved");
638 displayNonconserved.setState(true);
639 displayNonconserved.addActionListener(new ActionListener()
641 public void actionPerformed(ActionEvent e)
643 showNonconserved_actionPerformed();
646 editMenu.setText("Edit");
648 cut.addActionListener(new ActionListener()
650 public void actionPerformed(ActionEvent e)
652 cut_actionPerformed();
655 upperCase.setText("To Upper Case");
656 upperCase.addActionListener(new ActionListener()
658 public void actionPerformed(ActionEvent e)
663 copy.setText("Copy");
664 copy.addActionListener(new ActionListener()
666 public void actionPerformed(ActionEvent e)
668 copy_actionPerformed();
671 lowerCase.setText("To Lower Case");
672 lowerCase.addActionListener(new ActionListener()
674 public void actionPerformed(ActionEvent e)
679 toggle.setText("Toggle Case");
680 toggle.addActionListener(new ActionListener()
682 public void actionPerformed(ActionEvent e)
687 pdbMenu.setText("Associate Structure with Sequence");
688 pdbFromFile.setText("From File");
689 pdbFromFile.addActionListener(new ActionListener()
691 public void actionPerformed(ActionEvent e)
693 pdbFromFile_actionPerformed();
696 enterPDB.setText("Enter PDB Id");
697 enterPDB.addActionListener(new ActionListener()
699 public void actionPerformed(ActionEvent e)
701 enterPDB_actionPerformed();
704 discoverPDB.setText("Discover PDB ids");
705 discoverPDB.addActionListener(new ActionListener()
707 public void actionPerformed(ActionEvent e)
709 discoverPDB_actionPerformed();
712 outputMenu.setText("Output to Textbox...");
713 sequenceFeature.setText("Create Sequence Feature");
714 sequenceFeature.addActionListener(new ActionListener()
716 public void actionPerformed(ActionEvent e)
718 sequenceFeature_actionPerformed();
721 textColour.setText("Text Colour");
722 textColour.addActionListener(new ActionListener()
724 public void actionPerformed(ActionEvent e)
726 textColour_actionPerformed();
729 jMenu1.setText("Group");
730 structureMenu.setText("Structure");
731 viewStructureMenu.setText("View Structure");
732 // colStructureMenu.setText("Colour By Structure");
733 editSequence.setText("Edit Sequence...");
734 editSequence.addActionListener(new ActionListener()
736 public void actionPerformed(ActionEvent actionEvent)
738 editSequence_actionPerformed(actionEvent);
742 * annotationMenuItem.setText("By Annotation");
743 * annotationMenuItem.addActionListener(new ActionListener() { public void
744 * actionPerformed(ActionEvent actionEvent) {
745 * annotationMenuItem_actionPerformed(actionEvent); } });
751 this.add(structureMenu);
752 groupMenu.add(editMenu);
753 groupMenu.add(outputMenu);
754 groupMenu.add(sequenceFeature);
755 groupMenu.add(jMenu1);
756 sequenceMenu.add(sequenceName);
757 colourMenu.add(textColour);
758 colourMenu.add(noColourmenuItem);
759 colourMenu.add(clustalColour);
760 colourMenu.add(BLOSUM62Colour);
761 colourMenu.add(PIDColour);
762 colourMenu.add(zappoColour);
763 colourMenu.add(taylorColour);
764 colourMenu.add(hydrophobicityColour);
765 colourMenu.add(helixColour);
766 colourMenu.add(strandColour);
767 colourMenu.add(turnColour);
768 colourMenu.add(buriedColour);
769 colourMenu.add(nucleotideMenuItem);
770 colourMenu.add(userDefinedColour);
772 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
774 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
775 .getUserColourSchemes().keys();
777 while (userColours.hasMoreElements())
779 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
780 item.addActionListener(new ActionListener()
782 public void actionPerformed(ActionEvent evt)
784 userDefinedColour_actionPerformed(evt);
787 colourMenu.add(item);
791 colourMenu.addSeparator();
792 colourMenu.add(abovePIDColour);
793 colourMenu.add(conservationMenuItem);
794 // colourMenu.add(annotationMenuItem);
797 editMenu.add(editSequence);
798 editMenu.add(upperCase);
799 editMenu.add(lowerCase);
800 editMenu.add(toggle);
801 pdbMenu.add(pdbFromFile);
802 pdbMenu.add(enterPDB);
803 pdbMenu.add(discoverPDB);
804 jMenu1.add(groupName);
805 jMenu1.add(unGroupMenuItem);
806 jMenu1.add(colourMenu);
807 jMenu1.add(showBoxes);
808 jMenu1.add(showText);
809 jMenu1.add(showColourText);
811 jMenu1.add(displayNonconserved);
812 structureMenu.add(pdbMenu);
813 structureMenu.add(viewStructureMenu);
814 // structureMenu.add(colStructureMenu);
815 noColourmenuItem.setText("None");
816 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
818 public void actionPerformed(ActionEvent e)
820 noColourmenuItem_actionPerformed();
824 clustalColour.setText("Clustalx colours");
825 clustalColour.addActionListener(new java.awt.event.ActionListener()
827 public void actionPerformed(ActionEvent e)
829 clustalColour_actionPerformed();
832 zappoColour.setText("Zappo");
833 zappoColour.addActionListener(new java.awt.event.ActionListener()
835 public void actionPerformed(ActionEvent e)
837 zappoColour_actionPerformed();
840 taylorColour.setText("Taylor");
841 taylorColour.addActionListener(new java.awt.event.ActionListener()
843 public void actionPerformed(ActionEvent e)
845 taylorColour_actionPerformed();
848 hydrophobicityColour.setText("Hydrophobicity");
850 .addActionListener(new java.awt.event.ActionListener()
852 public void actionPerformed(ActionEvent e)
854 hydrophobicityColour_actionPerformed();
857 helixColour.setText("Helix propensity");
858 helixColour.addActionListener(new java.awt.event.ActionListener()
860 public void actionPerformed(ActionEvent e)
862 helixColour_actionPerformed();
865 strandColour.setText("Strand propensity");
866 strandColour.addActionListener(new java.awt.event.ActionListener()
868 public void actionPerformed(ActionEvent e)
870 strandColour_actionPerformed();
873 turnColour.setText("Turn propensity");
874 turnColour.addActionListener(new java.awt.event.ActionListener()
876 public void actionPerformed(ActionEvent e)
878 turnColour_actionPerformed();
881 buriedColour.setText("Buried Index");
882 buriedColour.addActionListener(new java.awt.event.ActionListener()
884 public void actionPerformed(ActionEvent e)
886 buriedColour_actionPerformed();
889 abovePIDColour.setText("Above % Identity");
890 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
892 public void actionPerformed(ActionEvent e)
894 abovePIDColour_actionPerformed();
897 userDefinedColour.setText("User Defined...");
898 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
900 public void actionPerformed(ActionEvent e)
902 userDefinedColour_actionPerformed(e);
905 PIDColour.setText("Percentage Identity");
906 PIDColour.addActionListener(new java.awt.event.ActionListener()
908 public void actionPerformed(ActionEvent e)
910 PIDColour_actionPerformed();
913 BLOSUM62Colour.setText("BLOSUM62");
914 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
916 public void actionPerformed(ActionEvent e)
918 BLOSUM62Colour_actionPerformed();
921 conservationMenuItem.setText("Conservation");
923 .addActionListener(new java.awt.event.ActionListener()
925 public void actionPerformed(ActionEvent e)
927 conservationMenuItem_actionPerformed();
932 protected void showNonconserved_actionPerformed()
934 getGroup().setShowunconserved(displayNonconserved.isSelected());
939 * call to refresh view after settings change
943 ap.updateAnnotation();
944 ap.paintAlignment(true);
946 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
955 protected void clustalColour_actionPerformed()
957 SequenceGroup sg = getGroup();
958 sg.cs = new ClustalxColourScheme(sg
959 .getSequences(ap.av.hiddenRepSequences), ap.av.alignment
970 protected void zappoColour_actionPerformed()
972 getGroup().cs = new ZappoColourScheme();
982 protected void taylorColour_actionPerformed()
984 getGroup().cs = new TaylorColourScheme();
994 protected void hydrophobicityColour_actionPerformed()
996 getGroup().cs = new HydrophobicColourScheme();
1006 protected void helixColour_actionPerformed()
1008 getGroup().cs = new HelixColourScheme();
1018 protected void strandColour_actionPerformed()
1020 getGroup().cs = new StrandColourScheme();
1030 protected void turnColour_actionPerformed()
1032 getGroup().cs = new TurnColourScheme();
1042 protected void buriedColour_actionPerformed()
1044 getGroup().cs = new BuriedColourScheme();
1054 public void nucleotideMenuItem_actionPerformed()
1056 getGroup().cs = new NucleotideColourScheme();
1066 protected void abovePIDColour_actionPerformed()
1068 SequenceGroup sg = getGroup();
1074 if (abovePIDColour.isSelected())
1076 sg.cs.setConsensus(AAFrequency.calculate(sg
1077 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1080 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1083 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1085 SliderPanel.showPIDSlider();
1088 // remove PIDColouring
1090 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1102 protected void userDefinedColour_actionPerformed(ActionEvent e)
1104 SequenceGroup sg = getGroup();
1106 if (e.getActionCommand().equals("User Defined..."))
1108 new UserDefinedColours(ap, sg);
1112 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1113 .getUserColourSchemes().get(e.getActionCommand());
1126 protected void PIDColour_actionPerformed()
1128 SequenceGroup sg = getGroup();
1129 sg.cs = new PIDColourScheme();
1130 sg.cs.setConsensus(AAFrequency.calculate(sg
1131 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1142 protected void BLOSUM62Colour_actionPerformed()
1144 SequenceGroup sg = getGroup();
1146 sg.cs = new Blosum62ColourScheme();
1148 sg.cs.setConsensus(AAFrequency.calculate(sg
1149 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1161 protected void noColourmenuItem_actionPerformed()
1163 getGroup().cs = null;
1173 protected void conservationMenuItem_actionPerformed()
1175 SequenceGroup sg = getGroup();
1181 if (conservationMenuItem.isSelected())
1183 Conservation c = new Conservation("Group",
1184 ResidueProperties.propHash, 3, sg
1185 .getSequences(ap.av.hiddenRepSequences), sg
1186 .getStartRes(), sg.getEndRes() + 1);
1189 c.verdict(false, ap.av.ConsPercGaps);
1191 sg.cs.setConservation(c);
1193 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1194 SliderPanel.showConservationSlider();
1197 // remove ConservationColouring
1199 sg.cs.setConservation(null);
1205 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1207 SequenceGroup sg = getGroup();
1213 AnnotationColourGradient acg = new AnnotationColourGradient(sequence
1214 .getAnnotation()[0], null,
1215 AnnotationColourGradient.NO_THRESHOLD);
1217 acg.predefinedColours = true;
1229 protected void groupName_actionPerformed()
1232 SequenceGroup sg = getGroup();
1233 EditNameDialog dialog = new EditNameDialog(sg.getName(), sg
1234 .getDescription(), " Group Name ", "Group Description ",
1235 "Edit Group Name/Description");
1242 sg.setName(dialog.getName());
1243 sg.setDescription(dialog.getDescription());
1249 * @return DOCUMENT ME!
1251 SequenceGroup getGroup()
1253 SequenceGroup sg = ap.av.getSelectionGroup();
1254 // this method won't add a new group if it already exists
1257 ap.av.alignment.addGroup(sg);
1269 void sequenceName_actionPerformed()
1271 EditNameDialog dialog = new EditNameDialog(sequence.getName(), sequence
1272 .getDescription(), " Sequence Name ",
1273 "Sequence Description ", "Edit Sequence Name/Description");
1280 if (dialog.getName() != null)
1282 if (dialog.getName().indexOf(" ") > -1)
1284 JOptionPane.showMessageDialog(ap,
1285 "Spaces have been converted to \"_\"",
1286 "No spaces allowed in Sequence Name",
1287 JOptionPane.WARNING_MESSAGE);
1290 sequence.setName(dialog.getName().replace(' ', '_'));
1291 ap.paintAlignment(false);
1294 sequence.setDescription(dialog.getDescription());
1296 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1307 void unGroupMenuItem_actionPerformed()
1309 SequenceGroup sg = ap.av.getSelectionGroup();
1310 ap.av.alignment.deleteGroup(sg);
1311 ap.av.setSelectionGroup(null);
1321 protected void outline_actionPerformed()
1323 SequenceGroup sg = getGroup();
1324 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1329 sg.setOutlineColour(col);
1341 public void showBoxes_actionPerformed()
1343 getGroup().setDisplayBoxes(showBoxes.isSelected());
1353 public void showText_actionPerformed()
1355 getGroup().setDisplayText(showText.isSelected());
1365 public void showColourText_actionPerformed()
1367 getGroup().setColourText(showColourText.isSelected());
1371 public void showLink(String url)
1375 jalview.util.BrowserLauncher.openURL(url);
1376 } catch (Exception ex)
1379 .showInternalMessageDialog(
1381 "Unixers: Couldn't find default web browser."
1382 + "\nAdd the full path to your browser in Preferences.",
1383 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1385 ex.printStackTrace();
1389 void hideSequences(boolean representGroup)
1391 SequenceGroup sg = ap.av.getSelectionGroup();
1392 if (sg == null || sg.getSize() < 1)
1394 ap.av.hideSequence(new SequenceI[]
1399 ap.av.setSelectionGroup(null);
1403 ap.av.hideRepSequences(sequence, sg);
1408 int gsize = sg.getSize();
1411 hseqs = new SequenceI[gsize];
1414 for (int i = 0; i < gsize; i++)
1416 hseqs[index++] = sg.getSequenceAt(i);
1419 ap.av.hideSequence(hseqs);
1420 ap.av.sendSelection();
1423 public void copy_actionPerformed()
1425 ap.alignFrame.copy_actionPerformed(null);
1428 public void cut_actionPerformed()
1430 ap.alignFrame.cut_actionPerformed(null);
1433 void changeCase(ActionEvent e)
1435 Object source = e.getSource();
1436 SequenceGroup sg = ap.av.getSelectionGroup();
1440 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1441 sg.getEndRes() + 1);
1446 if (source == toggle)
1448 description = "Toggle Case";
1449 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1451 else if (source == upperCase)
1453 description = "To Upper Case";
1454 caseChange = ChangeCaseCommand.TO_UPPER;
1458 description = "To Lower Case";
1459 caseChange = ChangeCaseCommand.TO_LOWER;
1462 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description, sg
1463 .getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1466 ap.alignFrame.addHistoryItem(caseCommand);
1468 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1474 public void outputText_actionPerformed(ActionEvent e)
1476 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1477 cap.setForInput(null);
1478 Desktop.addInternalFrame(cap, "Alignment output - "
1479 + e.getActionCommand(), 600, 500);
1481 String[] omitHidden = null;
1483 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1484 // or we simply trust the user wants
1485 // wysiwig behaviour
1486 SequenceGroup sg = ap.av.getSelectionGroup();
1487 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1488 omitHidden = ap.av.getViewAsString(true);
1489 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1490 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1491 for (int i = 0; i < nala.length; i++)
1493 AlignmentAnnotation na = nala[i];
1494 oal.addAnnotation(na);
1496 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1497 oal, omitHidden, csel, sg));
1501 public void pdbFromFile_actionPerformed()
1503 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1504 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1505 chooser.setFileView(new jalview.io.JalviewFileView());
1506 chooser.setDialogTitle("Select a PDB file");
1507 chooser.setToolTipText("Load a PDB file");
1509 int value = chooser.showOpenDialog(null);
1511 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1513 PDBEntry entry = new PDBEntry();
1514 String choice = chooser.getSelectedFile().getPath();
1515 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1518 MCview.PDBfile pdbfile = new MCview.PDBfile(choice,
1519 jalview.io.AppletFormatAdapter.FILE);
1521 if (pdbfile.id == null)
1523 String reply = JOptionPane
1524 .showInternalInputDialog(
1526 "Couldn't find a PDB id in the file supplied."
1527 + "Please enter an Id to identify this structure.",
1528 "No PDB Id in File", JOptionPane.QUESTION_MESSAGE);
1538 entry.setId(pdbfile.id);
1540 } catch (java.io.IOException ex)
1542 ex.printStackTrace();
1545 entry.setFile(choice);
1546 sequence.getDatasetSequence().addPDBId(entry);
1551 public void enterPDB_actionPerformed()
1553 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1554 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1556 if (id != null && id.length() > 0)
1558 PDBEntry entry = new PDBEntry();
1559 entry.setId(id.toUpperCase());
1560 sequence.getDatasetSequence().addPDBId(entry);
1564 public void discoverPDB_actionPerformed()
1567 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1569 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1570 Thread discpdb = new Thread(new Runnable()
1575 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1576 .fetchDBRefs(false);
1583 public void sequenceFeature_actionPerformed()
1585 SequenceGroup sg = ap.av.getSelectionGroup();
1591 int rsize=0,gSize = sg.getSize();
1592 SequenceI[] rseqs,seqs = new SequenceI[gSize];
1593 SequenceFeature[] tfeatures,features = new SequenceFeature[gSize];
1595 for (int i = 0; i < gSize; i++)
1597 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1598 int end = sg.findEndRes(sg.getSequenceAt(i));
1601 seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
1602 features[rsize] = new SequenceFeature(null, null, null, start, end,
1607 rseqs = new SequenceI[rsize];
1608 tfeatures = new SequenceFeature[rsize];
1609 System.arraycopy(seqs,0,rseqs, 0, rsize);
1610 System.arraycopy(features, 0, tfeatures, 0, rsize);
1611 features = tfeatures;
1613 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1614 features, true, ap))
1616 ap.alignFrame.setShowSeqFeatures(true);
1617 ap.highlightSearchResults(null);
1621 public void textColour_actionPerformed()
1623 SequenceGroup sg = getGroup();
1626 new TextColourChooser().chooseColour(ap, sg);
1630 public void colourByStructure(String pdbid)
1632 Annotation[] anots = jalview.structure.StructureSelectionManager
1633 .getStructureSelectionManager().colourSequenceFromStructure(
1636 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1637 "Coloured by " + pdbid, anots);
1639 ap.av.alignment.addAnnotation(an);
1640 an.createSequenceMapping(sequence, 0, true);
1641 // an.adjustForAlignment();
1642 ap.av.alignment.setAnnotationIndex(an, 0);
1644 ap.adjustAnnotationHeight();
1646 sequence.addAlignmentAnnotation(an);
1650 public void editSequence_actionPerformed(ActionEvent actionEvent)
1652 SequenceGroup sg = ap.av.getSelectionGroup();
1656 if (sequence == null)
1657 sequence = (Sequence) sg.getSequenceAt(0);
1659 EditNameDialog dialog = new EditNameDialog(sequence
1660 .getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
1661 null, "Edit Sequence ", null, "Edit Sequence");
1665 EditCommand editCommand = new EditCommand("Edit Sequences",
1666 EditCommand.REPLACE, dialog.getName().replace(' ',
1667 ap.av.getGapCharacter()), sg
1668 .getSequencesAsArray(ap.av.hiddenRepSequences), sg
1669 .getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1671 ap.alignFrame.addHistoryItem(editCommand);
1673 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()