2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
44 JMenu groupMenu = new JMenu();
45 JMenuItem groupName = new JMenuItem();
46 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
47 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
48 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
49 protected JRadioButtonMenuItem hydrophobicityColour = new
50 JRadioButtonMenuItem();
51 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
52 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
53 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
54 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
55 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
56 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
57 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
58 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
59 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
60 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
62 JMenu sequenceMenu = new JMenu();
63 JMenuItem sequenceName = new JMenuItem();
65 JMenuItem unGroupMenuItem = new JMenuItem();
66 JMenuItem outline = new JMenuItem();
67 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
68 JMenu colourMenu = new JMenu();
69 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
70 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
71 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
72 JMenu editMenu = new JMenu();
73 JMenuItem cut = new JMenuItem();
74 JMenuItem copy = new JMenuItem();
75 JMenuItem upperCase = new JMenuItem();
76 JMenuItem lowerCase = new JMenuItem();
77 JMenuItem toggle = new JMenuItem();
78 JMenu pdbMenu = new JMenu();
79 JMenuItem pdbFromFile = new JMenuItem();
80 JMenuItem enterPDB = new JMenuItem();
81 JMenuItem discoverPDB = new JMenuItem();
82 JMenu outputMenu = new JMenu();
83 JMenuItem sequenceFeature = new JMenuItem();
84 JMenuItem textColour = new JMenuItem();
85 JMenu jMenu1 = new JMenu();
86 JMenu structureMenu = new JMenu();
87 JMenu viewStructureMenu = new JMenu();
88 // JMenu colStructureMenu = new JMenu();
89 JMenuItem editSequence = new JMenuItem();
90 // JMenuItem annotationMenuItem = new JMenuItem();
93 * Creates a new PopupMenu object.
95 * @param ap DOCUMENT ME!
96 * @param seq DOCUMENT ME!
98 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
100 ///////////////////////////////////////////////////////////
101 // If this is activated from the sequence panel, the user may want to
102 // edit or annotate a particular residue. Therefore display the residue menu
104 // If from the IDPanel, we must display the sequence menu
105 //////////////////////////////////////////////////////////
109 ButtonGroup colours = new ButtonGroup();
110 colours.add(noColourmenuItem);
111 colours.add(clustalColour);
112 colours.add(zappoColour);
113 colours.add(taylorColour);
114 colours.add(hydrophobicityColour);
115 colours.add(helixColour);
116 colours.add(strandColour);
117 colours.add(turnColour);
118 colours.add(buriedColour);
119 colours.add(abovePIDColour);
120 colours.add(userDefinedColour);
121 colours.add(PIDColour);
122 colours.add(BLOSUM62Colour);
124 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
126 JMenuItem item = new JMenuItem(jalview.io.FormatAdapter.WRITEABLE_FORMATS[
129 item.addActionListener(new java.awt.event.ActionListener()
131 public void actionPerformed(ActionEvent e)
133 outputText_actionPerformed(e);
137 outputMenu.add(item);
151 sequenceMenu.setText(sequence.getName());
154 if (seq.getDatasetSequence().getPDBId() != null
155 && seq.getDatasetSequence().getPDBId().size()>0)
157 java.util.Enumeration e = seq.getDatasetSequence().getPDBId().
160 while (e.hasMoreElements())
162 final PDBEntry pdb = (PDBEntry) e.nextElement();
164 menuItem = new JMenuItem();
165 menuItem.setText(pdb.getId());
166 menuItem.addActionListener(new java.awt.event.ActionListener()
168 public void actionPerformed(ActionEvent e)
170 Vector seqs = new Vector();
171 for (int i = 0; i < ap.av.alignment.getHeight(); i++)
173 Vector pdbs = ap.av.alignment.getSequenceAt(i).getDatasetSequence().getPDBId();
177 for(int p=0; p<pdbs.size(); p++)
179 PDBEntry p1 = (PDBEntry)pdbs.elementAt(p);
180 if(p1.getId().equals(pdb.getId()))
182 if (!seqs.contains(ap.av.alignment.getSequenceAt(i)))
183 seqs.addElement(ap.av.alignment.getSequenceAt(i));
190 SequenceI [] seqs2 = new SequenceI[seqs.size()];
193 new AppJmol(pdb, seqs2, null, ap);
194 // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
197 viewStructureMenu.add(menuItem);
199 /* menuItem = new JMenuItem();
200 menuItem.setText(pdb.getId());
201 menuItem.addActionListener(new java.awt.event.ActionListener()
203 public void actionPerformed(ActionEvent e)
205 colourByStructure(pdb.getId());
208 colStructureMenu.add(menuItem);*/
213 structureMenu.remove(viewStructureMenu);
214 // structureMenu.remove(colStructureMenu);
217 menuItem = new JMenuItem("Hide Sequences");
218 menuItem.addActionListener(new java.awt.event.ActionListener()
220 public void actionPerformed(ActionEvent e)
222 hideSequences(false);
227 if (ap.av.getSelectionGroup() != null
228 && ap.av.getSelectionGroup().getSize() > 1)
230 menuItem = new JMenuItem("Represent Group with " + seq.getName());
231 menuItem.addActionListener(new java.awt.event.ActionListener()
233 public void actionPerformed(ActionEvent e)
238 sequenceMenu.add(menuItem);
241 if (ap.av.hasHiddenRows)
243 final int index = ap.av.alignment.findIndex(seq);
245 if (ap.av.adjustForHiddenSeqs(index) -
246 ap.av.adjustForHiddenSeqs(index - 1) > 1)
248 menuItem = new JMenuItem("Reveal Sequences");
249 menuItem.addActionListener(new ActionListener()
251 public void actionPerformed(ActionEvent e)
253 ap.av.showSequence(index);
254 if (ap.overviewPanel != null)
256 ap.overviewPanel.updateOverviewImage();
263 menuItem = new JMenuItem("Reveal All");
264 menuItem.addActionListener(new ActionListener()
266 public void actionPerformed(ActionEvent e)
268 ap.av.showAllHiddenSeqs();
269 if (ap.overviewPanel != null)
271 ap.overviewPanel.updateOverviewImage();
281 SequenceGroup sg = ap.av.getSelectionGroup();
285 groupName.setText(sg.getName());
287 if (sg.cs instanceof ZappoColourScheme)
289 zappoColour.setSelected(true);
291 else if (sg.cs instanceof TaylorColourScheme)
293 taylorColour.setSelected(true);
295 else if (sg.cs instanceof PIDColourScheme)
297 PIDColour.setSelected(true);
299 else if (sg.cs instanceof Blosum62ColourScheme)
301 BLOSUM62Colour.setSelected(true);
303 else if (sg.cs instanceof UserColourScheme)
305 userDefinedColour.setSelected(true);
307 else if (sg.cs instanceof HydrophobicColourScheme)
309 hydrophobicityColour.setSelected(true);
311 else if (sg.cs instanceof HelixColourScheme)
313 helixColour.setSelected(true);
315 else if (sg.cs instanceof StrandColourScheme)
317 strandColour.setSelected(true);
319 else if (sg.cs instanceof TurnColourScheme)
321 turnColour.setSelected(true);
323 else if (sg.cs instanceof BuriedColourScheme)
325 buriedColour.setSelected(true);
327 else if (sg.cs instanceof ClustalxColourScheme)
329 clustalColour.setSelected(true);
333 noColourmenuItem.setSelected(true);
336 if (sg.cs != null && sg.cs.conservationApplied())
338 conservationMenuItem.setSelected(true);
341 showText.setSelected(sg.getDisplayText());
342 showColourText.setSelected(sg.getColourText());
343 showBoxes.setSelected(sg.getDisplayBoxes());
347 groupMenu.setVisible(false);
348 editMenu.setVisible(false);
351 if (!ap.av.alignment.getGroups().contains(sg))
353 unGroupMenuItem.setVisible(false);
358 sequenceMenu.setVisible(false);
359 structureMenu.setVisible(false);
362 if (links != null && links.size() > 0)
364 JMenu linkMenu = new JMenu("Link");
366 for (int i = 0; i < links.size(); i++)
368 String link = links.elementAt(i).toString();
369 UrlLink urlLink = new UrlLink(link);
370 if (!urlLink.isValid())
372 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
375 final String label = urlLink.getLabel();
376 if (urlLink.isDynamic())
379 // collect matching db-refs
380 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq.getDBRef(), new String[]{urlLink.getTarget()});
381 // collect id string too
382 String id = seq.getName();
385 for (int r=0;r<dbr.length; r++)
387 if (id!=null && dbr[r].getAccessionId().equals(id))
389 // suppress duplicate link creation for the bare sequence ID string with this link
392 // create Bare ID link for this RUL
393 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true);
396 for (int u=0; u<urls.length; u+=2)
398 addshowLink(linkMenu, label+"|"+urls[u],urls[u+1]);
405 // create Bare ID link for this RUL
406 String[] urls = urlLink.makeUrls(id, true);
409 for (int u=0; u<urls.length; u+=2)
411 addshowLink(linkMenu, label, urls[u+1]);
417 // Add a non-dynamic link
418 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
421 if (sequence != null)
423 sequenceMenu.add(linkMenu);
433 * add a show URL menu item to the given linkMenu
435 * @param label - menu label string
436 * @param url - url to open
438 private void addshowLink(JMenu linkMenu, String label, final String url)
440 JMenuItem item = new JMenuItem(label);
441 item.setToolTipText("open URL: "+url);
442 item.addActionListener(new java.awt.event.ActionListener()
444 public void actionPerformed(ActionEvent e)
446 new Thread(new Runnable() {
463 * @throws Exception DOCUMENT ME!
465 private void jbInit()
468 groupMenu.setText("Group");
469 groupMenu.setText("Selection");
470 groupName.setText("Name");
471 groupName.addActionListener(new java.awt.event.ActionListener()
473 public void actionPerformed(ActionEvent e)
475 groupName_actionPerformed();
478 sequenceMenu.setText("Sequence");
479 sequenceName.setText("Edit Name/Description");
480 sequenceName.addActionListener(new java.awt.event.ActionListener()
482 public void actionPerformed(ActionEvent e)
484 sequenceName_actionPerformed();
487 PIDColour.setFocusPainted(false);
488 unGroupMenuItem.setText("Remove Group");
489 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
491 public void actionPerformed(ActionEvent e)
493 unGroupMenuItem_actionPerformed();
497 outline.setText("Border colour");
498 outline.addActionListener(new java.awt.event.ActionListener()
500 public void actionPerformed(ActionEvent e)
502 outline_actionPerformed();
505 nucleotideMenuItem.setText("Nucleotide");
506 nucleotideMenuItem.addActionListener(new ActionListener()
508 public void actionPerformed(ActionEvent e)
510 nucleotideMenuItem_actionPerformed();
513 colourMenu.setText("Group Colour");
514 showBoxes.setText("Boxes");
515 showBoxes.setState(true);
516 showBoxes.addActionListener(new ActionListener()
518 public void actionPerformed(ActionEvent e)
520 showBoxes_actionPerformed();
523 showText.setText("Text");
524 showText.setState(true);
525 showText.addActionListener(new ActionListener()
527 public void actionPerformed(ActionEvent e)
529 showText_actionPerformed();
532 showColourText.setText("Colour Text");
533 showColourText.addActionListener(new ActionListener()
535 public void actionPerformed(ActionEvent e)
537 showColourText_actionPerformed();
540 editMenu.setText("Edit");
542 cut.addActionListener(new ActionListener()
544 public void actionPerformed(ActionEvent e)
546 cut_actionPerformed();
549 upperCase.setText("To Upper Case");
550 upperCase.addActionListener(new ActionListener()
552 public void actionPerformed(ActionEvent e)
557 copy.setText("Copy");
558 copy.addActionListener(new ActionListener()
560 public void actionPerformed(ActionEvent e)
562 copy_actionPerformed();
565 lowerCase.setText("To Lower Case");
566 lowerCase.addActionListener(new ActionListener()
568 public void actionPerformed(ActionEvent e)
573 toggle.setText("Toggle Case");
574 toggle.addActionListener(new ActionListener()
576 public void actionPerformed(ActionEvent e)
581 pdbMenu.setText("Associate Structure with Sequence");
582 pdbFromFile.setText("From File");
583 pdbFromFile.addActionListener(new ActionListener()
585 public void actionPerformed(ActionEvent e)
587 pdbFromFile_actionPerformed();
590 enterPDB.setText("Enter PDB Id");
591 enterPDB.addActionListener(new ActionListener()
593 public void actionPerformed(ActionEvent e)
595 enterPDB_actionPerformed();
598 discoverPDB.setText("Discover PDB ids");
599 discoverPDB.addActionListener(new ActionListener()
601 public void actionPerformed(ActionEvent e)
603 discoverPDB_actionPerformed();
606 outputMenu.setText("Output to Textbox...");
607 sequenceFeature.setText("Create Sequence Feature");
608 sequenceFeature.addActionListener(new ActionListener()
610 public void actionPerformed(ActionEvent e)
612 sequenceFeature_actionPerformed();
615 textColour.setText("Text Colour");
616 textColour.addActionListener(new ActionListener()
618 public void actionPerformed(ActionEvent e)
620 textColour_actionPerformed();
623 jMenu1.setText("Group");
624 structureMenu.setText("Structure");
625 viewStructureMenu.setText("View Structure");
626 // colStructureMenu.setText("Colour By Structure");
627 editSequence.setText("Edit Sequence...");
628 editSequence.addActionListener(new ActionListener()
630 public void actionPerformed(ActionEvent actionEvent)
632 editSequence_actionPerformed(actionEvent);
635 /* annotationMenuItem.setText("By Annotation");
636 annotationMenuItem.addActionListener(new ActionListener()
638 public void actionPerformed(ActionEvent actionEvent)
640 annotationMenuItem_actionPerformed(actionEvent);
647 this.add(structureMenu);
648 groupMenu.add(editMenu);
649 groupMenu.add(outputMenu);
650 groupMenu.add(sequenceFeature);
651 groupMenu.add(jMenu1);
652 sequenceMenu.add(sequenceName);
653 colourMenu.add(textColour);
654 colourMenu.add(noColourmenuItem);
655 colourMenu.add(clustalColour);
656 colourMenu.add(BLOSUM62Colour);
657 colourMenu.add(PIDColour);
658 colourMenu.add(zappoColour);
659 colourMenu.add(taylorColour);
660 colourMenu.add(hydrophobicityColour);
661 colourMenu.add(helixColour);
662 colourMenu.add(strandColour);
663 colourMenu.add(turnColour);
664 colourMenu.add(buriedColour);
665 colourMenu.add(nucleotideMenuItem);
666 colourMenu.add(userDefinedColour);
668 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
670 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
671 getUserColourSchemes().keys();
673 while (userColours.hasMoreElements())
675 JMenuItem item = new JMenuItem(userColours.
676 nextElement().toString());
677 item.addActionListener(new ActionListener()
679 public void actionPerformed(ActionEvent evt)
681 userDefinedColour_actionPerformed(evt);
684 colourMenu.add(item);
688 colourMenu.addSeparator();
689 colourMenu.add(abovePIDColour);
690 colourMenu.add(conservationMenuItem);
691 //colourMenu.add(annotationMenuItem);
694 editMenu.add(editSequence);
695 editMenu.add(upperCase);
696 editMenu.add(lowerCase);
697 editMenu.add(toggle);
698 pdbMenu.add(pdbFromFile);
699 pdbMenu.add(enterPDB);
700 pdbMenu.add(discoverPDB);
701 jMenu1.add(groupName);
702 jMenu1.add(unGroupMenuItem);
703 jMenu1.add(colourMenu);
704 jMenu1.add(showBoxes);
705 jMenu1.add(showText);
706 jMenu1.add(showColourText);
708 structureMenu.add(pdbMenu);
709 structureMenu.add(viewStructureMenu);
710 // structureMenu.add(colStructureMenu);
711 noColourmenuItem.setText("None");
712 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
714 public void actionPerformed(ActionEvent e)
716 noColourmenuItem_actionPerformed();
720 clustalColour.setText("Clustalx colours");
721 clustalColour.addActionListener(new java.awt.event.ActionListener()
723 public void actionPerformed(ActionEvent e)
725 clustalColour_actionPerformed();
728 zappoColour.setText("Zappo");
729 zappoColour.addActionListener(new java.awt.event.ActionListener()
731 public void actionPerformed(ActionEvent e)
733 zappoColour_actionPerformed();
736 taylorColour.setText("Taylor");
737 taylorColour.addActionListener(new java.awt.event.ActionListener()
739 public void actionPerformed(ActionEvent e)
741 taylorColour_actionPerformed();
744 hydrophobicityColour.setText("Hydrophobicity");
745 hydrophobicityColour.addActionListener(new java.awt.event.ActionListener()
747 public void actionPerformed(ActionEvent e)
749 hydrophobicityColour_actionPerformed();
752 helixColour.setText("Helix propensity");
753 helixColour.addActionListener(new java.awt.event.ActionListener()
755 public void actionPerformed(ActionEvent e)
757 helixColour_actionPerformed();
760 strandColour.setText("Strand propensity");
761 strandColour.addActionListener(new java.awt.event.ActionListener()
763 public void actionPerformed(ActionEvent e)
765 strandColour_actionPerformed();
768 turnColour.setText("Turn propensity");
769 turnColour.addActionListener(new java.awt.event.ActionListener()
771 public void actionPerformed(ActionEvent e)
773 turnColour_actionPerformed();
776 buriedColour.setText("Buried Index");
777 buriedColour.addActionListener(new java.awt.event.ActionListener()
779 public void actionPerformed(ActionEvent e)
781 buriedColour_actionPerformed();
784 abovePIDColour.setText("Above % Identity");
785 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
787 public void actionPerformed(ActionEvent e)
789 abovePIDColour_actionPerformed();
792 userDefinedColour.setText("User Defined...");
793 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
795 public void actionPerformed(ActionEvent e)
797 userDefinedColour_actionPerformed(e);
800 PIDColour.setText("Percentage Identity");
801 PIDColour.addActionListener(new java.awt.event.ActionListener()
803 public void actionPerformed(ActionEvent e)
805 PIDColour_actionPerformed();
808 BLOSUM62Colour.setText("BLOSUM62");
809 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
811 public void actionPerformed(ActionEvent e)
813 BLOSUM62Colour_actionPerformed();
816 conservationMenuItem.setText("Conservation");
817 conservationMenuItem.addActionListener(new java.awt.event.ActionListener()
819 public void actionPerformed(ActionEvent e)
821 conservationMenuItem_actionPerformed();
831 ap.paintAlignment(true);
833 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
839 * @param e DOCUMENT ME!
841 protected void clustalColour_actionPerformed()
843 SequenceGroup sg = getGroup();
844 sg.cs = new ClustalxColourScheme(sg.getSequences(ap.av.hiddenRepSequences),
845 ap.av.alignment.getWidth());
852 * @param e DOCUMENT ME!
854 protected void zappoColour_actionPerformed()
856 getGroup().cs = new ZappoColourScheme();
863 * @param e DOCUMENT ME!
865 protected void taylorColour_actionPerformed()
867 getGroup().cs = new TaylorColourScheme();
874 * @param e DOCUMENT ME!
876 protected void hydrophobicityColour_actionPerformed()
878 getGroup().cs = new HydrophobicColourScheme();
885 * @param e DOCUMENT ME!
887 protected void helixColour_actionPerformed()
889 getGroup().cs = new HelixColourScheme();
896 * @param e DOCUMENT ME!
898 protected void strandColour_actionPerformed()
900 getGroup().cs = new StrandColourScheme();
907 * @param e DOCUMENT ME!
909 protected void turnColour_actionPerformed()
911 getGroup().cs = new TurnColourScheme();
918 * @param e DOCUMENT ME!
920 protected void buriedColour_actionPerformed()
922 getGroup().cs = new BuriedColourScheme();
929 * @param e DOCUMENT ME!
931 public void nucleotideMenuItem_actionPerformed()
933 getGroup().cs = new NucleotideColourScheme();
940 * @param e DOCUMENT ME!
942 protected void abovePIDColour_actionPerformed()
944 SequenceGroup sg = getGroup();
950 if (abovePIDColour.isSelected())
952 sg.cs.setConsensus(AAFrequency.calculate(
953 sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
954 sg.getEndRes() + 1));
956 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,
957 getGroup().getName());
959 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
961 SliderPanel.showPIDSlider();
963 else // remove PIDColouring
965 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
974 * @param e DOCUMENT ME!
976 protected void userDefinedColour_actionPerformed(ActionEvent e)
978 SequenceGroup sg = getGroup();
980 if (e.getActionCommand().equals("User Defined..."))
982 new UserDefinedColours(ap, sg);
986 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
987 getUserColourSchemes().get(e.getActionCommand());
997 * @param e DOCUMENT ME!
999 protected void PIDColour_actionPerformed()
1001 SequenceGroup sg = getGroup();
1002 sg.cs = new PIDColourScheme();
1003 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av.
1004 hiddenRepSequences),
1006 sg.getEndRes() + 1));
1013 * @param e DOCUMENT ME!
1015 protected void BLOSUM62Colour_actionPerformed()
1017 SequenceGroup sg = getGroup();
1019 sg.cs = new Blosum62ColourScheme();
1021 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av.
1022 hiddenRepSequences),
1024 sg.getEndRes() + 1));
1032 * @param e DOCUMENT ME!
1034 protected void noColourmenuItem_actionPerformed()
1036 getGroup().cs = null;
1043 * @param e DOCUMENT ME!
1045 protected void conservationMenuItem_actionPerformed()
1047 SequenceGroup sg = getGroup();
1053 if (conservationMenuItem.isSelected())
1055 Conservation c = new Conservation("Group",
1056 ResidueProperties.propHash, 3,
1057 sg.getSequences(ap.av.
1058 hiddenRepSequences),
1060 sg.getEndRes() + 1);
1063 c.verdict(false, ap.av.ConsPercGaps);
1065 sg.cs.setConservation(c);
1067 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1068 SliderPanel.showConservationSlider();
1070 else // remove ConservationColouring
1072 sg.cs.setConservation(null);
1078 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1080 SequenceGroup sg = getGroup();
1086 AnnotationColourGradient acg = new AnnotationColourGradient(
1087 sequence.getAnnotation()[0], null, AnnotationColourGradient.NO_THRESHOLD);
1089 acg.predefinedColours = true;
1098 * @param e DOCUMENT ME!
1100 protected void groupName_actionPerformed()
1103 SequenceGroup sg = getGroup();
1104 EditNameDialog dialog = new EditNameDialog(sg.getName(),
1105 sg.getDescription(),
1107 "Group Description ",
1108 "Edit Group Name/Description");
1115 sg.setName(dialog.getName());
1116 sg.setDescription(dialog.getDescription());
1122 * @return DOCUMENT ME!
1124 SequenceGroup getGroup()
1126 SequenceGroup sg = ap.av.getSelectionGroup();
1127 // this method won't add a new group if it already exists
1130 ap.av.alignment.addGroup(sg);
1139 * @param e DOCUMENT ME!
1141 void sequenceName_actionPerformed()
1143 EditNameDialog dialog = new EditNameDialog(sequence.getName(),
1144 sequence.getDescription(),
1146 "Sequence Description ",
1147 "Edit Sequence Name/Description");
1154 if (dialog.getName() != null)
1156 if (dialog.getName().indexOf(" ") > -1)
1158 JOptionPane.showMessageDialog(ap,
1159 "Spaces have been converted to \"_\"",
1160 "No spaces allowed in Sequence Name",
1161 JOptionPane.WARNING_MESSAGE);
1164 sequence.setName(dialog.getName().replace(' ', '_'));
1165 ap.paintAlignment(false);
1168 sequence.setDescription(dialog.getDescription());
1170 ap.av.firePropertyChange("alignment", null,
1171 ap.av.getAlignment().getSequences());
1178 * @param e DOCUMENT ME!
1180 void unGroupMenuItem_actionPerformed()
1182 SequenceGroup sg = ap.av.getSelectionGroup();
1183 ap.av.alignment.deleteGroup(sg);
1184 ap.av.setSelectionGroup(null);
1191 * @param e DOCUMENT ME!
1193 protected void outline_actionPerformed()
1195 SequenceGroup sg = getGroup();
1196 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1201 sg.setOutlineColour(col);
1210 * @param e DOCUMENT ME!
1212 public void showBoxes_actionPerformed()
1214 getGroup().setDisplayBoxes(showBoxes.isSelected());
1221 * @param e DOCUMENT ME!
1223 public void showText_actionPerformed()
1225 getGroup().setDisplayText(showText.isSelected());
1232 * @param e DOCUMENT ME!
1234 public void showColourText_actionPerformed()
1236 getGroup().setColourText(showColourText.isSelected());
1240 public void showLink(String url)
1244 jalview.util.BrowserLauncher.openURL(url);
1246 catch (Exception ex)
1248 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1249 "Unixers: Couldn't find default web browser."
1251 "\nAdd the full path to your browser in Preferences.",
1252 "Web browser not found",
1253 JOptionPane.WARNING_MESSAGE);
1255 ex.printStackTrace();
1259 void hideSequences(boolean representGroup)
1261 SequenceGroup sg = ap.av.getSelectionGroup();
1262 if (sg == null || sg.getSize() < 1)
1264 ap.av.hideSequence(new SequenceI[]
1269 ap.av.setSelectionGroup(null);
1273 ap.av.hideRepSequences(sequence, sg);
1278 int gsize = sg.getSize();
1281 hseqs = new SequenceI[gsize];
1284 for (int i = 0; i < gsize; i++)
1286 hseqs[index++] = sg.getSequenceAt(i);
1289 ap.av.hideSequence(hseqs);
1292 public void copy_actionPerformed()
1294 ap.alignFrame.copy_actionPerformed(null);
1297 public void cut_actionPerformed()
1299 ap.alignFrame.cut_actionPerformed(null);
1302 void changeCase(ActionEvent e)
1304 Object source = e.getSource();
1305 SequenceGroup sg = ap.av.getSelectionGroup();
1309 int[][] startEnd = ap.av.getVisibleRegionBoundaries(
1310 sg.getStartRes(), sg.getEndRes() + 1);
1315 if (source == toggle)
1317 description = "Toggle Case";
1318 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1320 else if (source == upperCase)
1322 description = "To Upper Case";
1323 caseChange = ChangeCaseCommand.TO_UPPER;
1327 description = "To Lower Case";
1328 caseChange = ChangeCaseCommand.TO_LOWER;
1331 ChangeCaseCommand caseCommand = new ChangeCaseCommand(
1332 description, sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1333 startEnd, caseChange
1336 ap.alignFrame.addHistoryItem(caseCommand);
1338 ap.av.firePropertyChange("alignment", null,
1339 ap.av.getAlignment().getSequences());
1344 public void outputText_actionPerformed(ActionEvent e)
1346 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1347 cap.setForInput(null);
1348 Desktop.addInternalFrame(cap,
1349 "Alignment output - " + e.getActionCommand(), 600,
1352 String[] omitHidden = null;
1354 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens or we simply trust the user wants wysiwig behaviour
1355 SequenceGroup sg = ap.av.getSelectionGroup();
1356 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1357 omitHidden = ap.av.getViewAsString(true);
1358 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1359 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1360 for (int i=0; i<nala.length; i++)
1362 AlignmentAnnotation na =nala[i];
1363 oal.addAnnotation(na);
1365 cap.setText(new FormatAdapter().formatSequences(
1366 e.getActionCommand(),
1368 omitHidden, csel, sg));
1372 public void pdbFromFile_actionPerformed()
1374 jalview.io.JalviewFileChooser chooser
1375 = new jalview.io.JalviewFileChooser(jalview.bin.Cache.
1378 chooser.setFileView(new jalview.io.JalviewFileView());
1379 chooser.setDialogTitle("Select a PDB file");
1380 chooser.setToolTipText("Load a PDB file");
1382 int value = chooser.showOpenDialog(null);
1384 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1386 PDBEntry entry = new PDBEntry();
1387 String choice = chooser.getSelectedFile().getPath();
1388 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1391 MCview.PDBfile pdbfile = new MCview.PDBfile(choice,
1392 jalview.io.AppletFormatAdapter.FILE);
1394 if (pdbfile.id == null)
1396 String reply = JOptionPane.showInternalInputDialog(
1398 "Couldn't find a PDB id in the file supplied."
1399 + "Please enter an Id to identify this structure.",
1400 "No PDB Id in File", JOptionPane.QUESTION_MESSAGE);
1410 entry.setId(pdbfile.id);
1413 catch (java.io.IOException ex)
1415 ex.printStackTrace();
1418 entry.setFile(choice);
1419 sequence.getDatasetSequence().addPDBId(entry);
1424 public void enterPDB_actionPerformed()
1426 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1427 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1429 if (id != null && id.length() > 0)
1431 PDBEntry entry = new PDBEntry();
1432 entry.setId(id.toUpperCase());
1433 sequence.getDatasetSequence()
1438 public void discoverPDB_actionPerformed()
1440 SequenceI[] sequences =
1441 ap.av.selectionGroup == null ?
1442 new Sequence[]{sequence}
1443 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment);
1445 new jalview.ws.DBRefFetcher(sequences,
1446 ap.alignFrame).fetchDBRefs(false);
1449 public void sequenceFeature_actionPerformed()
1451 SequenceGroup sg = ap.av.getSelectionGroup();
1457 int gSize = sg.getSize();
1458 SequenceI[] seqs = new SequenceI[gSize];
1459 SequenceFeature[] features = new SequenceFeature[gSize];
1461 for (int i = 0; i < gSize; i++)
1463 seqs[i] = sg.getSequenceAt(i).getDatasetSequence();
1464 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1465 int end = sg.findEndRes(sg.getSequenceAt(i));
1466 features[i] = new SequenceFeature(null, null, null, start, end, "Jalview");
1469 if (ap.seqPanel.seqCanvas.getFeatureRenderer()
1470 .amendFeatures(seqs, features, true, ap))
1472 ap.alignFrame.showSeqFeatures.setSelected(true);
1473 ap.av.setShowSequenceFeatures(true);
1474 ap.highlightSearchResults(null);
1478 public void textColour_actionPerformed()
1480 SequenceGroup sg = getGroup();
1483 new TextColourChooser().chooseColour(ap, sg);
1487 public void colourByStructure(String pdbid)
1489 Annotation [] anots = jalview.structure.StructureSelectionManager.getStructureSelectionManager()
1490 .colourSequenceFromStructure(sequence, pdbid);
1492 AlignmentAnnotation an = new AlignmentAnnotation(
1493 "Structure", "Coloured by "+pdbid, anots);
1495 ap.av.alignment.addAnnotation(an);
1496 an.createSequenceMapping(sequence, 0, true);
1497 //an.adjustForAlignment();
1498 ap.av.alignment.setAnnotationIndex(an,0);
1500 ap.adjustAnnotationHeight();
1502 sequence.addAlignmentAnnotation(an);
1506 public void editSequence_actionPerformed(ActionEvent actionEvent)
1508 SequenceGroup sg = ap.av.getSelectionGroup();
1512 if (sequence == null)
1513 sequence = (Sequence) sg.getSequenceAt(0);
1515 EditNameDialog dialog = new EditNameDialog(
1516 sequence.getSequenceAsString(
1518 sg.getEndRes() + 1),
1526 EditCommand editCommand = new EditCommand(
1527 "Edit Sequences", EditCommand.REPLACE,
1528 dialog.getName().replace(' ', ap.av.getGapCharacter()),
1529 sg.getSequencesAsArray(ap.av.hiddenRepSequences),
1530 sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment
1533 ap.alignFrame.addHistoryItem(editCommand);
1535 ap.av.firePropertyChange("alignment", null,
1536 ap.av.getAlignment().getSequences());