6055230fd471e7801941596ff85066704eed86f9
[jalview.git] / src / jalview / gui / PopupMenu.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\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
9  *\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
14  *\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
18  */\r
19 package jalview.gui;\r
20 \r
21 import MCview.*;\r
22 \r
23 import jalview.analysis.*;\r
24 \r
25 import jalview.datamodel.*;\r
26 \r
27 import jalview.io.*;\r
28 \r
29 import jalview.schemes.*;\r
30 \r
31 import java.awt.*;\r
32 import java.awt.event.*;\r
33 \r
34 import javax.swing.*;\r
35 \r
36 \r
37 /**\r
38  * DOCUMENT ME!\r
39  *\r
40  * @author $author$\r
41  * @version $Revision$\r
42  */\r
43 public class PopupMenu extends JPopupMenu\r
44 {\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
61     AlignmentPanel ap;\r
62     JMenu sequenceMenu = new JMenu();\r
63     JMenuItem sequenceName = new JMenuItem();\r
64     Sequence sequence;\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
73 \r
74     /**\r
75      * Creates a new PopupMenu object.\r
76      *\r
77      * @param ap DOCUMENT ME!\r
78      * @param seq DOCUMENT ME!\r
79      */\r
80     public PopupMenu(AlignmentPanel ap, Sequence seq)\r
81     {\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
85         //\r
86         // If from the IDPanel, we must display the sequence menu\r
87         //////////////////////////////////////////////////////////\r
88         this.ap = ap;\r
89         sequence = seq;\r
90 \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
105 \r
106         try\r
107         {\r
108             jbInit();\r
109         }\r
110         catch (Exception e)\r
111         {\r
112             e.printStackTrace();\r
113         }\r
114 \r
115         if ((seq == null) || (seq.getPDBId() == null))\r
116         {\r
117             pdbMenuItem.setVisible(false);\r
118         }\r
119 \r
120         SequenceGroup sg = ap.av.getSelectionGroup();\r
121 \r
122         if (sg != null)\r
123         {\r
124             groupName.setText(sg.getName());\r
125 \r
126             if (sg.cs instanceof ZappoColourScheme)\r
127             {\r
128                 zappoColour.setSelected(true);\r
129             }\r
130             else if (sg.cs instanceof TaylorColourScheme)\r
131             {\r
132                 taylorColour.setSelected(true);\r
133             }\r
134             else if (sg.cs instanceof PIDColourScheme)\r
135             {\r
136                 PIDColour.setSelected(true);\r
137             }\r
138             else if (sg.cs instanceof Blosum62ColourScheme)\r
139             {\r
140                 BLOSUM62Colour.setSelected(true);\r
141             }\r
142             else if (sg.cs instanceof UserColourScheme)\r
143             {\r
144                 userDefinedColour.setSelected(true);\r
145             }\r
146             else if (sg.cs instanceof HydrophobicColourScheme)\r
147             {\r
148                 hydrophobicityColour.setSelected(true);\r
149             }\r
150             else if (sg.cs instanceof HelixColourScheme)\r
151             {\r
152                 helixColour.setSelected(true);\r
153             }\r
154             else if (sg.cs instanceof StrandColourScheme)\r
155             {\r
156                 strandColour.setSelected(true);\r
157             }\r
158             else if (sg.cs instanceof TurnColourScheme)\r
159             {\r
160                 turnColour.setSelected(true);\r
161             }\r
162             else if (sg.cs instanceof BuriedColourScheme)\r
163             {\r
164                 buriedColour.setSelected(true);\r
165             }\r
166             else if (sg.cs instanceof ClustalxColourScheme)\r
167             {\r
168                 clustalColour.setSelected(true);\r
169             }\r
170             else\r
171             {\r
172                 noColourmenuItem.setSelected(true);\r
173             }\r
174 \r
175             if (sg.cs!=null && sg.cs.conservationApplied())\r
176             {\r
177                 conservationMenuItem.setSelected(true);\r
178             }\r
179 \r
180             showText.setSelected(sg.getDisplayText());\r
181             showColourText.setSelected(sg.getColourText());\r
182             showBoxes.setSelected(sg.getDisplayBoxes());\r
183         }\r
184 \r
185         if (!ap.av.alignment.getGroups().contains(sg))\r
186         {\r
187             unGroupMenuItem.setVisible(false);\r
188         }\r
189         else\r
190         {\r
191             groupMenu.insertSeparator(3);\r
192         }\r
193 \r
194         if (seq == null)\r
195         {\r
196             sequenceMenu.setVisible(false);\r
197         }\r
198         else\r
199         {\r
200           java.util.Vector links = Preferences.sequenceURLLinks;\r
201 \r
202           JMenu linkMenu = new JMenu("Link");\r
203           JMenuItem item;\r
204           for(int i=0; i<links.size(); i++)\r
205           {\r
206             String link = links.elementAt(i).toString();\r
207 \r
208             item = new JMenuItem(link.substring(0, link.indexOf("|")));\r
209 \r
210             final String url = link.substring(link.indexOf("|")+1, link.indexOf("$SEQUENCE_ID$"))\r
211                 + sequence.getName() +\r
212                 link.substring(link.indexOf("$SEQUENCE_ID$") + 13);\r
213 \r
214 \r
215             item.addActionListener(new java.awt.event.ActionListener()\r
216             {\r
217                 public void actionPerformed(ActionEvent e)\r
218                 {\r
219                     showLink(url);\r
220                 }\r
221             });\r
222 \r
223             linkMenu.add(item);\r
224           }\r
225           add(linkMenu);\r
226         }\r
227     }\r
228 \r
229     /**\r
230      * DOCUMENT ME!\r
231      *\r
232      * @throws Exception DOCUMENT ME!\r
233      */\r
234     private void jbInit() throws Exception\r
235     {\r
236         groupMenu.setText("Group");\r
237         groupMenu.setText("Define");\r
238         groupName.setText("Name");\r
239         groupName.addActionListener(new java.awt.event.ActionListener()\r
240             {\r
241                 public void actionPerformed(ActionEvent e)\r
242                 {\r
243                     groupName_actionPerformed(e);\r
244                 }\r
245             });\r
246         sequenceMenu.setText("Sequence");\r
247         sequenceName.setText("Edit name");\r
248         sequenceName.addActionListener(new java.awt.event.ActionListener()\r
249             {\r
250                 public void actionPerformed(ActionEvent e)\r
251                 {\r
252                     sequenceName_actionPerformed(e);\r
253                 }\r
254             });\r
255         PIDColour.setFocusPainted(false);\r
256         unGroupMenuItem.setText("Remove Group");\r
257         unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()\r
258             {\r
259                 public void actionPerformed(ActionEvent e)\r
260                 {\r
261                     unGroupMenuItem_actionPerformed(e);\r
262                 }\r
263             });\r
264         pdbMenuItem.setText("View PDB structure");\r
265         pdbMenuItem.addActionListener(new java.awt.event.ActionListener()\r
266             {\r
267                 public void actionPerformed(ActionEvent e)\r
268                 {\r
269                     pdbMenuItem_actionPerformed(e);\r
270                 }\r
271             });\r
272         outline.setText("Border colour");\r
273         outline.addActionListener(new java.awt.event.ActionListener()\r
274             {\r
275                 public void actionPerformed(ActionEvent e)\r
276                 {\r
277                     outline_actionPerformed(e);\r
278                 }\r
279             });\r
280         nucleotideMenuItem.setText("Nucleotide");\r
281         nucleotideMenuItem.addActionListener(new ActionListener()\r
282             {\r
283                 public void actionPerformed(ActionEvent e)\r
284                 {\r
285                     nucleotideMenuItem_actionPerformed(e);\r
286                 }\r
287             });\r
288         colourMenu.setText("Group Colour");\r
289         showBoxes.setText("Boxes");\r
290         showBoxes.setState(true);\r
291         showBoxes.addActionListener(new ActionListener()\r
292             {\r
293                 public void actionPerformed(ActionEvent e)\r
294                 {\r
295                     showBoxes_actionPerformed(e);\r
296                 }\r
297             });\r
298         showText.setText("Text");\r
299         showText.setState(true);\r
300         showText.addActionListener(new ActionListener()\r
301             {\r
302                 public void actionPerformed(ActionEvent e)\r
303                 {\r
304                     showText_actionPerformed(e);\r
305                 }\r
306             });\r
307         showColourText.setText("Colour Text");\r
308         showColourText.addActionListener(new ActionListener()\r
309             {\r
310                 public void actionPerformed(ActionEvent e)\r
311                 {\r
312                     showColourText_actionPerformed(e);\r
313                 }\r
314             });\r
315         add(groupMenu);\r
316         add(sequenceMenu);\r
317         groupMenu.add(groupName);\r
318         groupMenu.addSeparator();\r
319         groupMenu.add(unGroupMenuItem);\r
320         groupMenu.add(colourMenu);\r
321         groupMenu.addSeparator();\r
322         groupMenu.add(showBoxes);\r
323         groupMenu.add(showText);\r
324         groupMenu.add(showColourText);\r
325         groupMenu.addSeparator();\r
326         groupMenu.add(outline);\r
327         sequenceMenu.add(sequenceName);\r
328         sequenceMenu.add(pdbMenuItem);\r
329         colourMenu.add(noColourmenuItem);\r
330         colourMenu.add(clustalColour);\r
331         colourMenu.add(BLOSUM62Colour);\r
332         colourMenu.add(PIDColour);\r
333         colourMenu.add(zappoColour);\r
334         colourMenu.add(taylorColour);\r
335         colourMenu.add(hydrophobicityColour);\r
336         colourMenu.add(helixColour);\r
337         colourMenu.add(strandColour);\r
338         colourMenu.add(turnColour);\r
339         colourMenu.add(buriedColour);\r
340         colourMenu.add(nucleotideMenuItem);\r
341         colourMenu.add(userDefinedColour);\r
342 \r
343         if(jalview.gui.UserDefinedColours.getUserColourSchemes()!=null)\r
344         {\r
345           java.util.Enumeration userColours = jalview.gui.UserDefinedColours.\r
346               getUserColourSchemes().keys();\r
347 \r
348           while (userColours.hasMoreElements())\r
349           {\r
350             JMenuItem item = new JMenuItem(userColours.\r
351                 nextElement().toString());\r
352             item.addActionListener(new ActionListener()\r
353             {\r
354               public void actionPerformed(ActionEvent evt)\r
355               {\r
356                 userDefinedColour_actionPerformed(evt);\r
357               }\r
358             });\r
359             colourMenu.add(item);\r
360           }\r
361         }\r
362 \r
363 \r
364         colourMenu.addSeparator();\r
365         colourMenu.add(abovePIDColour);\r
366         colourMenu.add(conservationMenuItem);\r
367         noColourmenuItem.setText("None");\r
368         noColourmenuItem.addActionListener(new java.awt.event.ActionListener()\r
369             {\r
370                 public void actionPerformed(ActionEvent e)\r
371                 {\r
372                     noColourmenuItem_actionPerformed(e);\r
373                 }\r
374             });\r
375 \r
376         clustalColour.setText("Clustalx colours");\r
377         clustalColour.addActionListener(new java.awt.event.ActionListener()\r
378             {\r
379                 public void actionPerformed(ActionEvent e)\r
380                 {\r
381                     clustalColour_actionPerformed(e);\r
382                 }\r
383             });\r
384         zappoColour.setText("Zappo");\r
385         zappoColour.addActionListener(new java.awt.event.ActionListener()\r
386             {\r
387                 public void actionPerformed(ActionEvent e)\r
388                 {\r
389                     zappoColour_actionPerformed(e);\r
390                 }\r
391             });\r
392         taylorColour.setText("Taylor");\r
393         taylorColour.addActionListener(new java.awt.event.ActionListener()\r
394             {\r
395                 public void actionPerformed(ActionEvent e)\r
396                 {\r
397                     taylorColour_actionPerformed(e);\r
398                 }\r
399             });\r
400         hydrophobicityColour.setText("Hydrophobicity");\r
401         hydrophobicityColour.addActionListener(new java.awt.event.ActionListener()\r
402             {\r
403                 public void actionPerformed(ActionEvent e)\r
404                 {\r
405                     hydrophobicityColour_actionPerformed(e);\r
406                 }\r
407             });\r
408         helixColour.setText("Helix propensity");\r
409         helixColour.addActionListener(new java.awt.event.ActionListener()\r
410             {\r
411                 public void actionPerformed(ActionEvent e)\r
412                 {\r
413                     helixColour_actionPerformed(e);\r
414                 }\r
415             });\r
416         strandColour.setText("Strand propensity");\r
417         strandColour.addActionListener(new java.awt.event.ActionListener()\r
418             {\r
419                 public void actionPerformed(ActionEvent e)\r
420                 {\r
421                     strandColour_actionPerformed(e);\r
422                 }\r
423             });\r
424         turnColour.setText("Turn propensity");\r
425         turnColour.addActionListener(new java.awt.event.ActionListener()\r
426             {\r
427                 public void actionPerformed(ActionEvent e)\r
428                 {\r
429                     turnColour_actionPerformed(e);\r
430                 }\r
431             });\r
432         buriedColour.setText("Buried Index");\r
433         buriedColour.addActionListener(new java.awt.event.ActionListener()\r
434             {\r
435                 public void actionPerformed(ActionEvent e)\r
436                 {\r
437                     buriedColour_actionPerformed(e);\r
438                 }\r
439             });\r
440         abovePIDColour.setText("Above % Identity");\r
441         abovePIDColour.addActionListener(new java.awt.event.ActionListener()\r
442             {\r
443                 public void actionPerformed(ActionEvent e)\r
444                 {\r
445                     abovePIDColour_actionPerformed(e);\r
446                 }\r
447             });\r
448         userDefinedColour.setText("User Defined...");\r
449         userDefinedColour.addActionListener(new java.awt.event.ActionListener()\r
450             {\r
451                 public void actionPerformed(ActionEvent e)\r
452                 {\r
453                     userDefinedColour_actionPerformed(e);\r
454                 }\r
455             });\r
456         PIDColour.setText("Percentage Identity");\r
457         PIDColour.addActionListener(new java.awt.event.ActionListener()\r
458             {\r
459                 public void actionPerformed(ActionEvent e)\r
460                 {\r
461                     PIDColour_actionPerformed(e);\r
462                 }\r
463             });\r
464         BLOSUM62Colour.setText("BLOSUM62");\r
465         BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()\r
466             {\r
467                 public void actionPerformed(ActionEvent e)\r
468                 {\r
469                     BLOSUM62Colour_actionPerformed(e);\r
470                 }\r
471             });\r
472         conservationMenuItem.setText("Conservation");\r
473         conservationMenuItem.addActionListener(new java.awt.event.ActionListener()\r
474             {\r
475                 public void actionPerformed(ActionEvent e)\r
476                 {\r
477                     conservationMenuItem_actionPerformed(e);\r
478                 }\r
479             });\r
480     }\r
481 \r
482     /**\r
483      * DOCUMENT ME!\r
484      */\r
485     void refresh()\r
486     {\r
487         SequenceGroup sg = getGroup();\r
488         if(sg!=null)\r
489         {\r
490           SuperGroup superG = ap.av.alignment.getSuperGroup(sg);\r
491 \r
492           if (superG != null)\r
493           {\r
494             superG.setSuperGroupProperties(sg);\r
495           }\r
496         }\r
497         if (ap.overviewPanel != null)\r
498           ap.overviewPanel.updateOverviewImage();\r
499 \r
500         ap.seqPanel.repaint();\r
501     }\r
502 \r
503     /**\r
504      * DOCUMENT ME!\r
505      *\r
506      * @param e DOCUMENT ME!\r
507      */\r
508     protected void clustalColour_actionPerformed(ActionEvent e)\r
509     {\r
510         SequenceGroup sg = getGroup();\r
511         sg.cs = new ClustalxColourScheme(sg.sequences,\r
512                 ap.av.alignment.getWidth());\r
513         refresh();\r
514     }\r
515 \r
516     /**\r
517      * DOCUMENT ME!\r
518      *\r
519      * @param e DOCUMENT ME!\r
520      */\r
521     protected void zappoColour_actionPerformed(ActionEvent e)\r
522     {\r
523         getGroup().cs = new ZappoColourScheme();\r
524         refresh();\r
525     }\r
526 \r
527     /**\r
528      * DOCUMENT ME!\r
529      *\r
530      * @param e DOCUMENT ME!\r
531      */\r
532     protected void taylorColour_actionPerformed(ActionEvent e)\r
533     {\r
534         getGroup().cs = new TaylorColourScheme();\r
535         refresh();\r
536     }\r
537 \r
538     /**\r
539      * DOCUMENT ME!\r
540      *\r
541      * @param e DOCUMENT ME!\r
542      */\r
543     protected void hydrophobicityColour_actionPerformed(ActionEvent e)\r
544     {\r
545         getGroup().cs = new HydrophobicColourScheme();\r
546         refresh();\r
547     }\r
548 \r
549     /**\r
550      * DOCUMENT ME!\r
551      *\r
552      * @param e DOCUMENT ME!\r
553      */\r
554     protected void helixColour_actionPerformed(ActionEvent e)\r
555     {\r
556         getGroup().cs = new HelixColourScheme();\r
557         refresh();\r
558     }\r
559 \r
560     /**\r
561      * DOCUMENT ME!\r
562      *\r
563      * @param e DOCUMENT ME!\r
564      */\r
565     protected void strandColour_actionPerformed(ActionEvent e)\r
566     {\r
567         getGroup().cs = new StrandColourScheme();\r
568         refresh();\r
569     }\r
570 \r
571     /**\r
572      * DOCUMENT ME!\r
573      *\r
574      * @param e DOCUMENT ME!\r
575      */\r
576     protected void turnColour_actionPerformed(ActionEvent e)\r
577     {\r
578         getGroup().cs = new TurnColourScheme();\r
579         refresh();\r
580     }\r
581 \r
582     /**\r
583      * DOCUMENT ME!\r
584      *\r
585      * @param e DOCUMENT ME!\r
586      */\r
587     protected void buriedColour_actionPerformed(ActionEvent e)\r
588     {\r
589         getGroup().cs = new BuriedColourScheme();\r
590         refresh();\r
591     }\r
592 \r
593     /**\r
594      * DOCUMENT ME!\r
595      *\r
596      * @param e DOCUMENT ME!\r
597      */\r
598     public void nucleotideMenuItem_actionPerformed(ActionEvent e)\r
599     {\r
600         getGroup().cs = new NucleotideColourScheme();\r
601         refresh();\r
602     }\r
603 \r
604     /**\r
605      * DOCUMENT ME!\r
606      *\r
607      * @param e DOCUMENT ME!\r
608      */\r
609     protected void abovePIDColour_actionPerformed(ActionEvent e)\r
610     {\r
611         SequenceGroup sg = getGroup();\r
612         if(sg.cs==null)\r
613           return;\r
614 \r
615         if (abovePIDColour.isSelected())\r
616         {\r
617             sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,\r
618                     ap.av.alignment.getWidth()));\r
619 \r
620             int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,\r
621                     getGroup().getName());\r
622 \r
623            sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());\r
624 \r
625             SliderPanel.showPIDSlider();\r
626         }\r
627         else // remove PIDColouring\r
628         {\r
629             sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());\r
630         }\r
631 \r
632         refresh();\r
633     }\r
634 \r
635     /**\r
636      * DOCUMENT ME!\r
637      *\r
638      * @param e DOCUMENT ME!\r
639      */\r
640     protected void userDefinedColour_actionPerformed(ActionEvent e)\r
641     {\r
642        SequenceGroup sg = getGroup();\r
643 \r
644        if (e.getActionCommand().equals("User Defined..."))\r
645          new UserDefinedColours(ap, sg);\r
646        else\r
647        {\r
648          UserColourScheme udc = (UserColourScheme) UserDefinedColours.\r
649              getUserColourSchemes().get(e.getActionCommand());\r
650 \r
651          sg.cs = udc;\r
652        }\r
653      }\r
654     /**\r
655      * DOCUMENT ME!\r
656      *\r
657      * @param e DOCUMENT ME!\r
658      */\r
659     protected void PIDColour_actionPerformed(ActionEvent e)\r
660     {\r
661         SequenceGroup sg = getGroup();\r
662         sg.cs = new PIDColourScheme();\r
663         sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,\r
664                 ap.av.alignment.getWidth()));\r
665         refresh();\r
666     }\r
667 \r
668     /**\r
669      * DOCUMENT ME!\r
670      *\r
671      * @param e DOCUMENT ME!\r
672      */\r
673     protected void BLOSUM62Colour_actionPerformed(ActionEvent e)\r
674     {\r
675         SequenceGroup sg = getGroup();\r
676 \r
677         sg.cs = new Blosum62ColourScheme();\r
678 \r
679         sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,\r
680                 ap.av.alignment.getWidth()));\r
681 \r
682         refresh();\r
683     }\r
684 \r
685     /**\r
686      * DOCUMENT ME!\r
687      *\r
688      * @param e DOCUMENT ME!\r
689      */\r
690     protected void noColourmenuItem_actionPerformed(ActionEvent e)\r
691     {\r
692         getGroup().cs = null;\r
693         refresh();\r
694     }\r
695 \r
696     /**\r
697      * DOCUMENT ME!\r
698      *\r
699      * @param e DOCUMENT ME!\r
700      */\r
701     protected void conservationMenuItem_actionPerformed(ActionEvent e)\r
702     {\r
703         SequenceGroup sg = getGroup();\r
704         if(sg.cs==null)\r
705           return;\r
706 \r
707         if (conservationMenuItem.isSelected())\r
708         {\r
709             Conservation c = new Conservation("Group",\r
710                     ResidueProperties.propHash, 3, sg.sequences, 0,\r
711                     ap.av.alignment.getWidth());\r
712 \r
713             c.calculate();\r
714             c.verdict(false, ap.av.ConsPercGaps);\r
715 \r
716             sg.cs.setConservation(c);\r
717 \r
718             SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());\r
719             SliderPanel.showConservationSlider();\r
720         }\r
721         else // remove ConservationColouring\r
722         {\r
723             sg.cs.setConservation(null);\r
724         }\r
725 \r
726         refresh();\r
727     }\r
728 \r
729     /**\r
730      * DOCUMENT ME!\r
731      *\r
732      * @param e DOCUMENT ME!\r
733      */\r
734     protected void groupName_actionPerformed(ActionEvent e)\r
735     {\r
736         SequenceGroup sg = getGroup();\r
737         String reply = JOptionPane.showInternalInputDialog(Desktop.desktop,\r
738                 "Enter new group name", "Edit group name",\r
739                 JOptionPane.QUESTION_MESSAGE);\r
740 \r
741         if (reply == null)\r
742         {\r
743             return;\r
744         }\r
745 \r
746         sg.setName(reply);\r
747         groupName.setText(reply);\r
748     }\r
749 \r
750     /**\r
751      * DOCUMENT ME!\r
752      *\r
753      * @param e DOCUMENT ME!\r
754      */\r
755     protected void analyze_actionPerformed(ActionEvent e)\r
756     {\r
757         CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
758         JInternalFrame frame = new JInternalFrame();\r
759         frame.setContentPane(cap);\r
760         Desktop.addInternalFrame(frame, "Analyze this - ", 400, 300);\r
761 \r
762         SequenceGroup sg = getGroup();\r
763         StringBuffer sb = new StringBuffer();\r
764 \r
765         for (int i = 0; i < sg.sequences.size(); i++)\r
766         {\r
767             Sequence tmp = (Sequence) sg.sequences.get(i);\r
768             sb.append(tmp.getSequence(sg.getStartRes(), sg.getEndRes() + 1));\r
769             sb.append("\n");\r
770         }\r
771 \r
772         sb.append("Something amazing will happen soon");\r
773         cap.setText(sb.toString());\r
774     }\r
775 \r
776     /**\r
777      * DOCUMENT ME!\r
778      *\r
779      * @return DOCUMENT ME!\r
780      */\r
781     SequenceGroup getGroup()\r
782     {\r
783         SequenceGroup sg = ap.av.getSelectionGroup();\r
784       // this method won't add a new group if it already exists\r
785         if(sg!=null)\r
786           ap.av.alignment.addGroup(sg);\r
787 \r
788         return sg;\r
789     }\r
790 \r
791     /**\r
792      * DOCUMENT ME!\r
793      *\r
794      * @param e DOCUMENT ME!\r
795      */\r
796     void sequenceName_actionPerformed(ActionEvent e)\r
797     {\r
798         String id = sequence.getDisplayId(false, false);\r
799         String s = (String) JOptionPane.showInternalInputDialog(ap,\r
800                 "Edit sequence name",\r
801                 "Edit sequence name (" + sequence.getName() + ")",\r
802                 JOptionPane.PLAIN_MESSAGE, null, null, id);\r
803 \r
804         if (s != null)\r
805         {\r
806             if (s.indexOf(" ") > -1)\r
807             {\r
808                 JOptionPane.showMessageDialog(ap,\r
809                     "Spaces have been converted to \"_\"",\r
810                     "No spaces allowed in Sequence Name",\r
811                     JOptionPane.WARNING_MESSAGE);\r
812             }\r
813 \r
814             s = s.replace(' ', '_');\r
815             sequence.setName(s);\r
816             ap.repaint();\r
817         }\r
818     }\r
819 \r
820     /**\r
821      * DOCUMENT ME!\r
822      *\r
823      * @param e DOCUMENT ME!\r
824      */\r
825     void unGroupMenuItem_actionPerformed(ActionEvent e)\r
826     {\r
827         SequenceGroup sg = ap.av.getSelectionGroup();\r
828         ap.av.alignment.deleteGroup(sg);\r
829         ap.av.setSelectionGroup(null);\r
830         refresh();\r
831     }\r
832 \r
833     /**\r
834      * DOCUMENT ME!\r
835      *\r
836      * @param e DOCUMENT ME!\r
837      */\r
838     void pdbMenuItem_actionPerformed(ActionEvent e)\r
839     {\r
840         if (sequence.getPDBId() == null)\r
841         {\r
842             return;\r
843         }\r
844 \r
845         try\r
846         {\r
847             EBIFetchClient ebi = new EBIFetchClient();\r
848             String[] result = ebi.fetchData("pdb:" + sequence.getPDBId(), null,\r
849                     null);\r
850 \r
851             PDBfile pdb = new PDBfile(result);\r
852 \r
853             rotCanvas rc = new rotCanvas(pdb, sequence, ap.av);\r
854             JInternalFrame frame = new JInternalFrame();\r
855             frame.setContentPane(rc);\r
856             Desktop.addInternalFrame(frame,\r
857                 sequence.getName() + " " + sequence.getPDBId(), 400, 400);\r
858         }\r
859         catch (Exception ex)\r
860         {\r
861             ex.printStackTrace();\r
862         }\r
863     }\r
864 \r
865     /**\r
866      * DOCUMENT ME!\r
867      *\r
868      * @param e DOCUMENT ME!\r
869      */\r
870     protected void outline_actionPerformed(ActionEvent e)\r
871     {\r
872         SequenceGroup sg = getGroup();\r
873         Color col = JColorChooser.showDialog(this, "Select Outline Colour",\r
874                 Color.BLUE);\r
875 \r
876         if (col != null)\r
877         {\r
878             sg.setOutlineColour(col);\r
879         }\r
880 \r
881         refresh();\r
882     }\r
883 \r
884     /**\r
885      * DOCUMENT ME!\r
886      *\r
887      * @param e DOCUMENT ME!\r
888      */\r
889     public void showBoxes_actionPerformed(ActionEvent e)\r
890     {\r
891         getGroup().setDisplayBoxes(showBoxes.isSelected());\r
892         refresh();\r
893     }\r
894 \r
895     /**\r
896      * DOCUMENT ME!\r
897      *\r
898      * @param e DOCUMENT ME!\r
899      */\r
900     public void showText_actionPerformed(ActionEvent e)\r
901     {\r
902         getGroup().setDisplayText(showText.isSelected());\r
903         refresh();\r
904     }\r
905 \r
906     /**\r
907      * DOCUMENT ME!\r
908      *\r
909      * @param e DOCUMENT ME!\r
910      */\r
911     public void showColourText_actionPerformed(ActionEvent e)\r
912     {\r
913         getGroup().setColourText(showColourText.isSelected());\r
914         refresh();\r
915     }\r
916 \r
917     public void showLink(String url)\r
918     {\r
919       try\r
920       {\r
921         jalview.util.BrowserLauncher.openURL(url);\r
922       }\r
923       catch (Exception ex)\r
924       {\r
925         JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
926             "Unixers: Couldn't find default web browser."\r
927            +"\nAdd the full path to your browser in Preferences.",\r
928            "Web browser not found", JOptionPane.WARNING_MESSAGE );\r
929 \r
930 \r
931         ex.printStackTrace();\r
932       }\r
933     }\r
934 }\r