2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
23 import jalview.analysis.*;
\r
25 import jalview.datamodel.*;
\r
27 import jalview.io.*;
\r
29 import jalview.schemes.*;
\r
32 import java.awt.event.*;
\r
34 import javax.swing.*;
\r
41 * @version $Revision$
\r
43 public class PopupMenu extends JPopupMenu
\r
45 JMenu groupMenu = new JMenu();
\r
46 JMenuItem groupName = new JMenuItem();
\r
47 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
\r
48 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
\r
49 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
\r
50 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
\r
51 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
\r
52 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
\r
53 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
\r
54 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
\r
55 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
\r
56 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
\r
57 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
\r
58 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
\r
59 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
\r
60 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
\r
62 JMenu sequenceMenu = new JMenu();
\r
63 JMenuItem sequenceName = new JMenuItem();
\r
65 JMenuItem unGroupMenuItem = new JMenuItem();
\r
66 JMenuItem pdbMenuItem = new JMenuItem();
\r
67 JMenuItem outline = new JMenuItem();
\r
68 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
\r
69 JMenu colourMenu = new JMenu();
\r
70 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
\r
71 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
\r
72 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
\r
75 * Creates a new PopupMenu object.
\r
77 * @param ap DOCUMENT ME!
\r
78 * @param seq DOCUMENT ME!
\r
80 public PopupMenu(AlignmentPanel ap, Sequence seq)
\r
82 ///////////////////////////////////////////////////////////
\r
83 // If this is activated from the sequence panel, the user may want to
\r
84 // edit or annotate a particular residue. Therefore display the residue menu
\r
86 // If from the IDPanel, we must display the sequence menu
\r
87 //////////////////////////////////////////////////////////
\r
91 ButtonGroup colours = new ButtonGroup();
\r
92 colours.add(noColourmenuItem);
\r
93 colours.add(clustalColour);
\r
94 colours.add(zappoColour);
\r
95 colours.add(taylorColour);
\r
96 colours.add(hydrophobicityColour);
\r
97 colours.add(helixColour);
\r
98 colours.add(strandColour);
\r
99 colours.add(turnColour);
\r
100 colours.add(buriedColour);
\r
101 colours.add(abovePIDColour);
\r
102 colours.add(userDefinedColour);
\r
103 colours.add(PIDColour);
\r
104 colours.add(BLOSUM62Colour);
\r
110 catch (Exception e)
\r
112 e.printStackTrace();
\r
115 if ((seq == null) || (seq.getPDBId() == null))
\r
117 pdbMenuItem.setVisible(false);
\r
120 SequenceGroup sg = ap.av.getSelectionGroup();
\r
124 groupName.setText(sg.getName());
\r
126 if (sg.cs instanceof ZappoColourScheme)
\r
128 zappoColour.setSelected(true);
\r
130 else if (sg.cs instanceof TaylorColourScheme)
\r
132 taylorColour.setSelected(true);
\r
134 else if (sg.cs instanceof PIDColourScheme)
\r
136 PIDColour.setSelected(true);
\r
138 else if (sg.cs instanceof Blosum62ColourScheme)
\r
140 BLOSUM62Colour.setSelected(true);
\r
142 else if (sg.cs instanceof UserColourScheme)
\r
144 userDefinedColour.setSelected(true);
\r
146 else if (sg.cs instanceof HydrophobicColourScheme)
\r
148 hydrophobicityColour.setSelected(true);
\r
150 else if (sg.cs instanceof HelixColourScheme)
\r
152 helixColour.setSelected(true);
\r
154 else if (sg.cs instanceof StrandColourScheme)
\r
156 strandColour.setSelected(true);
\r
158 else if (sg.cs instanceof TurnColourScheme)
\r
160 turnColour.setSelected(true);
\r
162 else if (sg.cs instanceof BuriedColourScheme)
\r
164 buriedColour.setSelected(true);
\r
166 else if (sg.cs instanceof ClustalxColourScheme)
\r
168 clustalColour.setSelected(true);
\r
172 noColourmenuItem.setSelected(true);
\r
175 if (sg.cs instanceof ConservationColourScheme)
\r
177 conservationMenuItem.setSelected(true);
\r
180 showText.setSelected(sg.getDisplayText());
\r
181 showColourText.setSelected(sg.getColourText());
\r
182 showBoxes.setSelected(sg.getDisplayBoxes());
\r
185 if (!ap.av.alignment.getGroups().contains(sg))
\r
187 unGroupMenuItem.setVisible(false);
\r
191 groupMenu.insertSeparator(3);
\r
196 sequenceMenu.setVisible(false);
\r
203 * @throws Exception DOCUMENT ME!
\r
205 private void jbInit() throws Exception
\r
207 groupMenu.setText("Group");
\r
208 groupMenu.setText("Define");
\r
209 groupName.setText("Name");
\r
210 groupName.addActionListener(new java.awt.event.ActionListener()
\r
212 public void actionPerformed(ActionEvent e)
\r
214 groupName_actionPerformed(e);
\r
217 sequenceMenu.setText("Sequence");
\r
218 sequenceName.setText("Edit name");
\r
219 sequenceName.addActionListener(new java.awt.event.ActionListener()
\r
221 public void actionPerformed(ActionEvent e)
\r
223 sequenceName_actionPerformed(e);
\r
226 PIDColour.setFocusPainted(false);
\r
227 unGroupMenuItem.setText("Remove Group");
\r
228 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
\r
230 public void actionPerformed(ActionEvent e)
\r
232 unGroupMenuItem_actionPerformed(e);
\r
235 pdbMenuItem.setText("View PDB structure");
\r
236 pdbMenuItem.addActionListener(new java.awt.event.ActionListener()
\r
238 public void actionPerformed(ActionEvent e)
\r
240 pdbMenuItem_actionPerformed(e);
\r
243 outline.setText("Border colour");
\r
244 outline.addActionListener(new java.awt.event.ActionListener()
\r
246 public void actionPerformed(ActionEvent e)
\r
248 outline_actionPerformed(e);
\r
251 nucleotideMenuItem.setText("Nucleotide");
\r
252 nucleotideMenuItem.addActionListener(new ActionListener()
\r
254 public void actionPerformed(ActionEvent e)
\r
256 nucleotideMenuItem_actionPerformed(e);
\r
259 colourMenu.setText("Group Colour");
\r
260 showBoxes.setText("Boxes");
\r
261 showBoxes.setState(true);
\r
262 showBoxes.addActionListener(new ActionListener()
\r
264 public void actionPerformed(ActionEvent e)
\r
266 showBoxes_actionPerformed(e);
\r
269 showText.setText("Text");
\r
270 showText.setState(true);
\r
271 showText.addActionListener(new ActionListener()
\r
273 public void actionPerformed(ActionEvent e)
\r
275 showText_actionPerformed(e);
\r
278 showColourText.setText("Colour Text");
\r
279 showColourText.addActionListener(new ActionListener()
\r
281 public void actionPerformed(ActionEvent e)
\r
283 showColourText_actionPerformed(e);
\r
288 groupMenu.add(groupName);
\r
289 groupMenu.addSeparator();
\r
290 groupMenu.add(unGroupMenuItem);
\r
291 groupMenu.add(colourMenu);
\r
292 groupMenu.addSeparator();
\r
293 groupMenu.add(showBoxes);
\r
294 groupMenu.add(showText);
\r
295 groupMenu.add(showColourText);
\r
296 groupMenu.addSeparator();
\r
297 groupMenu.add(outline);
\r
298 sequenceMenu.add(sequenceName);
\r
299 sequenceMenu.add(pdbMenuItem);
\r
300 colourMenu.add(noColourmenuItem);
\r
301 colourMenu.add(clustalColour);
\r
302 colourMenu.add(BLOSUM62Colour);
\r
303 colourMenu.add(PIDColour);
\r
304 colourMenu.add(zappoColour);
\r
305 colourMenu.add(taylorColour);
\r
306 colourMenu.add(hydrophobicityColour);
\r
307 colourMenu.add(helixColour);
\r
308 colourMenu.add(strandColour);
\r
309 colourMenu.add(turnColour);
\r
310 colourMenu.add(buriedColour);
\r
311 colourMenu.add(nucleotideMenuItem);
\r
312 colourMenu.add(userDefinedColour);
\r
313 colourMenu.addSeparator();
\r
314 colourMenu.add(abovePIDColour);
\r
315 colourMenu.add(conservationMenuItem);
\r
316 noColourmenuItem.setText("None");
\r
317 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
\r
319 public void actionPerformed(ActionEvent e)
\r
321 noColourmenuItem_actionPerformed(e);
\r
325 clustalColour.setText("Clustalx colours");
\r
326 clustalColour.addActionListener(new java.awt.event.ActionListener()
\r
328 public void actionPerformed(ActionEvent e)
\r
330 clustalColour_actionPerformed(e);
\r
333 zappoColour.setText("Zappo");
\r
334 zappoColour.addActionListener(new java.awt.event.ActionListener()
\r
336 public void actionPerformed(ActionEvent e)
\r
338 zappoColour_actionPerformed(e);
\r
341 taylorColour.setText("Taylor");
\r
342 taylorColour.addActionListener(new java.awt.event.ActionListener()
\r
344 public void actionPerformed(ActionEvent e)
\r
346 taylorColour_actionPerformed(e);
\r
349 hydrophobicityColour.setText("Hydrophobicity");
\r
350 hydrophobicityColour.addActionListener(new java.awt.event.ActionListener()
\r
352 public void actionPerformed(ActionEvent e)
\r
354 hydrophobicityColour_actionPerformed(e);
\r
357 helixColour.setText("Helix propensity");
\r
358 helixColour.addActionListener(new java.awt.event.ActionListener()
\r
360 public void actionPerformed(ActionEvent e)
\r
362 helixColour_actionPerformed(e);
\r
365 strandColour.setText("Strand propensity");
\r
366 strandColour.addActionListener(new java.awt.event.ActionListener()
\r
368 public void actionPerformed(ActionEvent e)
\r
370 strandColour_actionPerformed(e);
\r
373 turnColour.setText("Turn propensity");
\r
374 turnColour.addActionListener(new java.awt.event.ActionListener()
\r
376 public void actionPerformed(ActionEvent e)
\r
378 turnColour_actionPerformed(e);
\r
381 buriedColour.setText("Buried Index");
\r
382 buriedColour.addActionListener(new java.awt.event.ActionListener()
\r
384 public void actionPerformed(ActionEvent e)
\r
386 buriedColour_actionPerformed(e);
\r
389 abovePIDColour.setText("Above % Identity");
\r
390 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
\r
392 public void actionPerformed(ActionEvent e)
\r
394 abovePIDColour_actionPerformed(e);
\r
397 userDefinedColour.setText("User Defined");
\r
398 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
\r
400 public void actionPerformed(ActionEvent e)
\r
402 userDefinedColour_actionPerformed(e);
\r
405 PIDColour.setText("Percentage Identity");
\r
406 PIDColour.addActionListener(new java.awt.event.ActionListener()
\r
408 public void actionPerformed(ActionEvent e)
\r
410 PIDColour_actionPerformed(e);
\r
413 BLOSUM62Colour.setText("BLOSUM62");
\r
414 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
\r
416 public void actionPerformed(ActionEvent e)
\r
418 BLOSUM62Colour_actionPerformed(e);
\r
421 conservationMenuItem.setText("Conservation");
\r
422 conservationMenuItem.addActionListener(new java.awt.event.ActionListener()
\r
424 public void actionPerformed(ActionEvent e)
\r
426 conservationMenuItem_actionPerformed(e);
\r
436 SequenceGroup sg = getGroup();
\r
439 SuperGroup superG = ap.av.alignment.getSuperGroup(sg);
\r
441 if (superG != null)
\r
443 superG.setSuperGroupProperties(sg);
\r
446 ap.seqPanel.repaint();
\r
452 * @param e DOCUMENT ME!
\r
454 protected void clustalColour_actionPerformed(ActionEvent e)
\r
456 SequenceGroup sg = getGroup();
\r
457 sg.cs = new ClustalxColourScheme(sg.sequences,
\r
458 ap.av.alignment.getWidth());
\r
465 * @param e DOCUMENT ME!
\r
467 protected void zappoColour_actionPerformed(ActionEvent e)
\r
469 getGroup().cs = new ZappoColourScheme();
\r
476 * @param e DOCUMENT ME!
\r
478 protected void taylorColour_actionPerformed(ActionEvent e)
\r
480 getGroup().cs = new TaylorColourScheme();
\r
487 * @param e DOCUMENT ME!
\r
489 protected void hydrophobicityColour_actionPerformed(ActionEvent e)
\r
491 getGroup().cs = new HydrophobicColourScheme();
\r
498 * @param e DOCUMENT ME!
\r
500 protected void helixColour_actionPerformed(ActionEvent e)
\r
502 getGroup().cs = new HelixColourScheme();
\r
509 * @param e DOCUMENT ME!
\r
511 protected void strandColour_actionPerformed(ActionEvent e)
\r
513 getGroup().cs = new StrandColourScheme();
\r
520 * @param e DOCUMENT ME!
\r
522 protected void turnColour_actionPerformed(ActionEvent e)
\r
524 getGroup().cs = new TurnColourScheme();
\r
531 * @param e DOCUMENT ME!
\r
533 protected void buriedColour_actionPerformed(ActionEvent e)
\r
535 getGroup().cs = new BuriedColourScheme();
\r
542 * @param e DOCUMENT ME!
\r
544 public void nucleotideMenuItem_actionPerformed(ActionEvent e)
\r
546 getGroup().cs = new NucleotideColourScheme();
\r
553 * @param e DOCUMENT ME!
\r
555 protected void abovePIDColour_actionPerformed(ActionEvent e)
\r
557 SequenceGroup sg = getGroup();
\r
559 if (abovePIDColour.isSelected())
\r
561 sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,
\r
562 ap.av.alignment.getWidth()));
\r
564 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,
\r
565 getGroup().getName());
\r
567 if (sg.cs instanceof ResidueColourScheme)
\r
569 ((ResidueColourScheme) sg.cs).setThreshold(threshold);
\r
571 else if (sg.cs instanceof ScoreColourScheme)
\r
573 ((ScoreColourScheme) sg.cs).setThreshold(threshold);
\r
576 SliderPanel.showPIDSlider();
\r
578 else // remove PIDColouring
\r
580 ResidueColourScheme rcs = (ResidueColourScheme) sg.cs;
\r
581 rcs.setThreshold(0);
\r
591 * @param e DOCUMENT ME!
\r
593 protected void userDefinedColour_actionPerformed(ActionEvent e)
\r
595 new UserDefinedColours(ap, getGroup());
\r
601 * @param e DOCUMENT ME!
\r
603 protected void PIDColour_actionPerformed(ActionEvent e)
\r
605 SequenceGroup sg = getGroup();
\r
606 sg.cs = new PIDColourScheme();
\r
607 sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,
\r
608 ap.av.alignment.getWidth()));
\r
615 * @param e DOCUMENT ME!
\r
617 protected void BLOSUM62Colour_actionPerformed(ActionEvent e)
\r
619 SequenceGroup sg = getGroup();
\r
621 sg.cs = new Blosum62ColourScheme();
\r
623 sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,
\r
624 ap.av.alignment.getWidth()));
\r
632 * @param e DOCUMENT ME!
\r
634 protected void noColourmenuItem_actionPerformed(ActionEvent e)
\r
636 getGroup().cs = null;
\r
643 * @param e DOCUMENT ME!
\r
645 protected void conservationMenuItem_actionPerformed(ActionEvent e)
\r
647 SequenceGroup sg = getGroup();
\r
649 if (conservationMenuItem.isSelected())
\r
651 Conservation c = new Conservation("Group",
\r
652 ResidueProperties.propHash, 3, sg.sequences, 0,
\r
653 ap.av.alignment.getWidth());
\r
656 c.verdict(false, ap.av.ConsPercGaps);
\r
658 ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs);
\r
662 SliderPanel.setConservationSlider(ap, ccs, sg.getName());
\r
663 SliderPanel.showConservationSlider();
\r
665 else // remove ConservationColouring
\r
667 ConservationColourScheme ccs = (ConservationColourScheme) sg.cs;
\r
677 * @param e DOCUMENT ME!
\r
679 protected void groupName_actionPerformed(ActionEvent e)
\r
681 SequenceGroup sg = getGroup();
\r
682 String reply = JOptionPane.showInternalInputDialog(Desktop.desktop,
\r
683 "Enter new group name", "Edit group name",
\r
684 JOptionPane.QUESTION_MESSAGE);
\r
692 groupName.setText(reply);
\r
698 * @param e DOCUMENT ME!
\r
700 protected void analyze_actionPerformed(ActionEvent e)
\r
702 CutAndPasteTransfer cap = new CutAndPasteTransfer();
\r
703 JInternalFrame frame = new JInternalFrame();
\r
704 frame.setContentPane(cap);
\r
705 Desktop.addInternalFrame(frame, "Analyze this - ", 400, 300);
\r
707 SequenceGroup sg = getGroup();
\r
708 StringBuffer sb = new StringBuffer();
\r
710 for (int i = 0; i < sg.sequences.size(); i++)
\r
712 Sequence tmp = (Sequence) sg.sequences.get(i);
\r
713 sb.append(tmp.getSequence(sg.getStartRes(), sg.getEndRes() + 1));
\r
717 sb.append("Something amazing will happen soon");
\r
718 cap.setText(sb.toString());
\r
724 * @return DOCUMENT ME!
\r
726 SequenceGroup getGroup()
\r
728 SequenceGroup sg = ap.av.getSelectionGroup();
\r
729 // this method won't add a new group if it already exists
\r
731 ap.av.alignment.addGroup(sg);
\r
739 * @param e DOCUMENT ME!
\r
741 void sequenceName_actionPerformed(ActionEvent e)
\r
743 String id = sequence.getName();
\r
744 String s = (String) JOptionPane.showInternalInputDialog(ap,
\r
745 "Edit sequence name",
\r
746 "Edit sequence name (" + sequence.getName() + ")",
\r
747 JOptionPane.PLAIN_MESSAGE, null, null, id);
\r
751 if (s.indexOf(" ") > -1)
\r
753 JOptionPane.showMessageDialog(ap,
\r
754 "Spaces have been converted to \"_\"",
\r
755 "No spaces allowed in Sequence Name",
\r
756 JOptionPane.WARNING_MESSAGE);
\r
759 s = s.replace(' ', '_');
\r
760 sequence.setName(s);
\r
768 * @param e DOCUMENT ME!
\r
770 void unGroupMenuItem_actionPerformed(ActionEvent e)
\r
772 SequenceGroup sg = ap.av.getSelectionGroup();
\r
773 ap.av.alignment.deleteGroup(sg);
\r
774 ap.av.setSelectionGroup(null);
\r
781 * @param e DOCUMENT ME!
\r
783 void pdbMenuItem_actionPerformed(ActionEvent e)
\r
785 if (sequence.getPDBId() == null)
\r
792 EBIFetchClient ebi = new EBIFetchClient();
\r
793 String[] result = ebi.fetchData("pdb:" + sequence.getPDBId(), null,
\r
796 PDBfile pdb = new PDBfile(result);
\r
798 rotCanvas rc = new rotCanvas(pdb, sequence, ap.av);
\r
799 JInternalFrame frame = new JInternalFrame();
\r
800 frame.setContentPane(rc);
\r
801 Desktop.addInternalFrame(frame,
\r
802 sequence.getName() + " " + sequence.getPDBId(), 400, 400);
\r
804 catch (Exception ex)
\r
806 ex.printStackTrace();
\r
813 * @param e DOCUMENT ME!
\r
815 protected void outline_actionPerformed(ActionEvent e)
\r
817 SequenceGroup sg = getGroup();
\r
818 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
\r
823 sg.setOutlineColour(col);
\r
832 * @param e DOCUMENT ME!
\r
834 public void showBoxes_actionPerformed(ActionEvent e)
\r
836 getGroup().setDisplayBoxes(showBoxes.isSelected());
\r
843 * @param e DOCUMENT ME!
\r
845 public void showText_actionPerformed(ActionEvent e)
\r
847 getGroup().setDisplayText(showText.isSelected());
\r
854 * @param e DOCUMENT ME!
\r
856 public void showColourText_actionPerformed(ActionEvent e)
\r
858 getGroup().setColourText(showColourText.isSelected());
\r