Check for all gapped seqs
[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 \r
28 import jalview.schemes.*;\r
29 \r
30 import java.awt.*;\r
31 import java.awt.event.*;\r
32 \r
33 import javax.swing.*;\r
34 \r
35 import java.util.Vector;\r
36 \r
37 \r
38 /**\r
39  * DOCUMENT ME!\r
40  *\r
41  * @author $author$\r
42  * @version $Revision$\r
43  */\r
44 public class PopupMenu extends JPopupMenu\r
45 {\r
46     JMenu groupMenu = new JMenu();\r
47     JMenuItem groupName = new JMenuItem();\r
48     protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();\r
49     protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();\r
50     protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();\r
51     protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();\r
52     protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();\r
53     protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();\r
54     protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();\r
55     protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();\r
56     protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();\r
57     protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();\r
58     protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();\r
59     protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();\r
60     JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();\r
61     protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();\r
62     AlignmentPanel ap;\r
63     JMenu sequenceMenu = new JMenu();\r
64     JMenuItem sequenceName = new JMenuItem();\r
65     Sequence sequence;\r
66     JMenuItem unGroupMenuItem = 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   JMenu editMenu = new JMenu();\r
74   JMenuItem cut = new JMenuItem();\r
75   JMenuItem copy = new JMenuItem();\r
76   JMenuItem upperCase = new JMenuItem();\r
77   JMenuItem lowerCase = new JMenuItem();\r
78   JMenuItem toggle = new JMenuItem();\r
79 \r
80   /**\r
81      * Creates a new PopupMenu object.\r
82      *\r
83      * @param ap DOCUMENT ME!\r
84      * @param seq DOCUMENT ME!\r
85      */\r
86     public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)\r
87     {\r
88         ///////////////////////////////////////////////////////////\r
89         // If this is activated from the sequence panel, the user may want to\r
90         // edit or annotate a particular residue. Therefore display the residue menu\r
91         //\r
92         // If from the IDPanel, we must display the sequence menu\r
93         //////////////////////////////////////////////////////////\r
94         this.ap = ap;\r
95         sequence = seq;\r
96 \r
97         ButtonGroup colours = new ButtonGroup();\r
98         colours.add(noColourmenuItem);\r
99         colours.add(clustalColour);\r
100         colours.add(zappoColour);\r
101         colours.add(taylorColour);\r
102         colours.add(hydrophobicityColour);\r
103         colours.add(helixColour);\r
104         colours.add(strandColour);\r
105         colours.add(turnColour);\r
106         colours.add(buriedColour);\r
107         colours.add(abovePIDColour);\r
108         colours.add(userDefinedColour);\r
109         colours.add(PIDColour);\r
110         colours.add(BLOSUM62Colour);\r
111 \r
112         try\r
113         {\r
114             jbInit();\r
115         }\r
116         catch (Exception e)\r
117         {\r
118             e.printStackTrace();\r
119         }\r
120 \r
121 \r
122         if (seq != null)\r
123         {\r
124           JMenuItem menuItem;\r
125           if( seq.getDatasetSequence().getPDBId() != null)\r
126           {\r
127             java.util.Enumeration e = seq.getDatasetSequence().getPDBId().\r
128                 elements();\r
129             while (e.hasMoreElements())\r
130             {\r
131               final PDBEntry pdb = (PDBEntry) e.nextElement();\r
132 \r
133               menuItem = new JMenuItem();\r
134               menuItem.setText("View PDB entry: " + pdb.getId());\r
135               menuItem.addActionListener(new java.awt.event.ActionListener()\r
136               {\r
137                 public void actionPerformed(ActionEvent e)\r
138                 {\r
139                   new PDBViewer(pdb, sequence, ap.seqPanel.seqCanvas);\r
140                 }\r
141               });\r
142               sequenceMenu.add(menuItem);\r
143             }\r
144           }\r
145 \r
146           menuItem = new JMenuItem("Hide Sequences");\r
147           menuItem.addActionListener(new java.awt.event.ActionListener()\r
148               {\r
149                 public void actionPerformed(ActionEvent e)\r
150                 {\r
151                   hideSequences(false);\r
152                 }\r
153               });\r
154           sequenceMenu.add(menuItem);\r
155 \r
156           if(ap.av.getSelectionGroup() !=null\r
157              && ap.av.getSelectionGroup().getSize(false)>1)\r
158           {\r
159             menuItem = new JMenuItem("Represent Group with " + seq.getName());\r
160             menuItem.addActionListener(new java.awt.event.ActionListener()\r
161             {\r
162               public void actionPerformed(ActionEvent e)\r
163               {\r
164                 hideSequences(true);\r
165               }\r
166             });\r
167             sequenceMenu.add(menuItem);\r
168           }\r
169 \r
170           if (ap.av.hasHiddenRows)\r
171           {\r
172             final int index = ap.av.alignment.findIndex(seq);\r
173 \r
174             if (ap.av.adjustForHiddenSeqs(index) -\r
175                 ap.av.adjustForHiddenSeqs(index - 1) > 1)\r
176             {\r
177               menuItem = new JMenuItem("Reveal");\r
178               menuItem.addActionListener(new ActionListener()\r
179               {\r
180                 public void actionPerformed(ActionEvent e)\r
181                 {\r
182                   ap.av.showSequence(index);\r
183                   ap.repaint();\r
184                   if (ap.overviewPanel != null)\r
185                     ap.overviewPanel.updateOverviewImage();\r
186                 }\r
187               });\r
188               sequenceMenu.add(menuItem);\r
189             }\r
190 \r
191             menuItem = new JMenuItem("Reveal All");\r
192             menuItem.addActionListener(new ActionListener()\r
193                 {\r
194                   public void actionPerformed(ActionEvent e)\r
195                   {\r
196                     ap.av.showAllHiddenSeqs();\r
197                     ap.repaint();\r
198                     if (ap.overviewPanel != null)\r
199                       ap.overviewPanel.updateOverviewImage();\r
200                       }\r
201                 });\r
202 \r
203             sequenceMenu.add(menuItem);\r
204 \r
205 \r
206 \r
207           }\r
208 \r
209 \r
210         }\r
211 \r
212 \r
213 \r
214         SequenceGroup sg = ap.av.getSelectionGroup();\r
215 \r
216         if (sg != null)\r
217         {\r
218             groupName.setText(sg.getName());\r
219 \r
220             if (sg.cs instanceof ZappoColourScheme)\r
221             {\r
222                 zappoColour.setSelected(true);\r
223             }\r
224             else if (sg.cs instanceof TaylorColourScheme)\r
225             {\r
226                 taylorColour.setSelected(true);\r
227             }\r
228             else if (sg.cs instanceof PIDColourScheme)\r
229             {\r
230                 PIDColour.setSelected(true);\r
231             }\r
232             else if (sg.cs instanceof Blosum62ColourScheme)\r
233             {\r
234                 BLOSUM62Colour.setSelected(true);\r
235             }\r
236             else if (sg.cs instanceof UserColourScheme)\r
237             {\r
238                 userDefinedColour.setSelected(true);\r
239             }\r
240             else if (sg.cs instanceof HydrophobicColourScheme)\r
241             {\r
242                 hydrophobicityColour.setSelected(true);\r
243             }\r
244             else if (sg.cs instanceof HelixColourScheme)\r
245             {\r
246                 helixColour.setSelected(true);\r
247             }\r
248             else if (sg.cs instanceof StrandColourScheme)\r
249             {\r
250                 strandColour.setSelected(true);\r
251             }\r
252             else if (sg.cs instanceof TurnColourScheme)\r
253             {\r
254                 turnColour.setSelected(true);\r
255             }\r
256             else if (sg.cs instanceof BuriedColourScheme)\r
257             {\r
258                 buriedColour.setSelected(true);\r
259             }\r
260             else if (sg.cs instanceof ClustalxColourScheme)\r
261             {\r
262                 clustalColour.setSelected(true);\r
263             }\r
264             else\r
265             {\r
266                 noColourmenuItem.setSelected(true);\r
267             }\r
268 \r
269             if (sg.cs!=null && sg.cs.conservationApplied())\r
270             {\r
271                 conservationMenuItem.setSelected(true);\r
272             }\r
273 \r
274             showText.setSelected(sg.getDisplayText());\r
275             showColourText.setSelected(sg.getColourText());\r
276             showBoxes.setSelected(sg.getDisplayBoxes());\r
277         }\r
278         else\r
279         {\r
280           groupMenu.setVisible(false);\r
281           editMenu.setVisible(false);\r
282         }\r
283 \r
284         if (!ap.av.alignment.getGroups().contains(sg))\r
285         {\r
286             unGroupMenuItem.setVisible(false);\r
287         }\r
288         else\r
289         {\r
290             groupMenu.insertSeparator(3);\r
291         }\r
292 \r
293         if (seq == null)\r
294         {\r
295             sequenceMenu.setVisible(false);\r
296         }\r
297 \r
298         if(links != null && links.size()>0)\r
299         {\r
300           JMenu linkMenu = new JMenu("Link");\r
301           JMenuItem item;\r
302           for(int i=0; i<links.size(); i++)\r
303           {\r
304             String link = links.elementAt(i).toString();\r
305             final String label = link.substring(0, link.indexOf("|"));\r
306             item = new JMenuItem(label);\r
307             final String url;\r
308 \r
309             if (link.indexOf("$SEQUENCE_ID$") > -1)\r
310             {\r
311               String id = seq.getName();\r
312               if (id.indexOf("|") > -1)\r
313                 id = id.substring(id.lastIndexOf("|") + 1);\r
314 \r
315               url = link.substring(link.indexOf("|") + 1,\r
316                                    link.indexOf("$SEQUENCE_ID$"))\r
317                   + id +\r
318                   link.substring(link.indexOf("$SEQUENCE_ID$") + 13);\r
319             }\r
320             else\r
321               url = link.substring(link.lastIndexOf("|")+1);\r
322 \r
323 \r
324             item.addActionListener(new java.awt.event.ActionListener()\r
325             {\r
326                 public void actionPerformed(ActionEvent e)\r
327                 {\r
328                     showLink(url);\r
329                 }\r
330             });\r
331 \r
332             linkMenu.add(item);\r
333           }\r
334           add(linkMenu);\r
335         }\r
336     }\r
337 \r
338 \r
339     /**\r
340      * DOCUMENT ME!\r
341      *\r
342      * @throws Exception DOCUMENT ME!\r
343      */\r
344     private void jbInit() throws Exception\r
345     {\r
346         groupMenu.setText("Group");\r
347         groupMenu.setText("Group");\r
348         groupName.setText("Name");\r
349         groupName.addActionListener(new java.awt.event.ActionListener()\r
350             {\r
351                 public void actionPerformed(ActionEvent e)\r
352                 {\r
353                     groupName_actionPerformed(e);\r
354                 }\r
355             });\r
356         sequenceMenu.setText("Sequence");\r
357         sequenceName.setText("Edit Name/Description");\r
358         sequenceName.addActionListener(new java.awt.event.ActionListener()\r
359             {\r
360                 public void actionPerformed(ActionEvent e)\r
361                 {\r
362                     sequenceName_actionPerformed(e);\r
363                 }\r
364             });\r
365         PIDColour.setFocusPainted(false);\r
366         unGroupMenuItem.setText("Remove Group");\r
367         unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()\r
368             {\r
369                 public void actionPerformed(ActionEvent e)\r
370                 {\r
371                     unGroupMenuItem_actionPerformed(e);\r
372                 }\r
373             });\r
374 \r
375         outline.setText("Border colour");\r
376         outline.addActionListener(new java.awt.event.ActionListener()\r
377             {\r
378                 public void actionPerformed(ActionEvent e)\r
379                 {\r
380                     outline_actionPerformed(e);\r
381                 }\r
382             });\r
383         nucleotideMenuItem.setText("Nucleotide");\r
384         nucleotideMenuItem.addActionListener(new ActionListener()\r
385             {\r
386                 public void actionPerformed(ActionEvent e)\r
387                 {\r
388                     nucleotideMenuItem_actionPerformed(e);\r
389                 }\r
390             });\r
391         colourMenu.setText("Group Colour");\r
392         showBoxes.setText("Boxes");\r
393         showBoxes.setState(true);\r
394         showBoxes.addActionListener(new ActionListener()\r
395             {\r
396                 public void actionPerformed(ActionEvent e)\r
397                 {\r
398                     showBoxes_actionPerformed(e);\r
399                 }\r
400             });\r
401         showText.setText("Text");\r
402         showText.setState(true);\r
403         showText.addActionListener(new ActionListener()\r
404             {\r
405                 public void actionPerformed(ActionEvent e)\r
406                 {\r
407                     showText_actionPerformed(e);\r
408                 }\r
409             });\r
410         showColourText.setText("Colour Text");\r
411         showColourText.addActionListener(new ActionListener()\r
412             {\r
413                 public void actionPerformed(ActionEvent e)\r
414                 {\r
415                     showColourText_actionPerformed(e);\r
416                 }\r
417             });\r
418     editMenu.setText("Edit");\r
419     cut.setText("Cut");\r
420     cut.addActionListener(new ActionListener()\r
421     {\r
422       public void actionPerformed(ActionEvent e)\r
423       {\r
424         cut_actionPerformed(e);\r
425       }\r
426     });\r
427     upperCase.setText("To Upper Case");\r
428     upperCase.addActionListener(new ActionListener()\r
429     {\r
430       public void actionPerformed(ActionEvent e)\r
431       {\r
432         upperCase_actionPerformed(e);\r
433       }\r
434     });\r
435     copy.setText("Copy");\r
436     copy.addActionListener(new ActionListener()\r
437     {\r
438       public void actionPerformed(ActionEvent e)\r
439       {\r
440         copy_actionPerformed(e);\r
441       }\r
442     });\r
443     lowerCase.setText("To Lower Case");\r
444     lowerCase.addActionListener(new ActionListener()\r
445     {\r
446       public void actionPerformed(ActionEvent e)\r
447       {\r
448         lowerCase_actionPerformed(e);\r
449       }\r
450     });\r
451     toggle.setText("Toggle Case");\r
452     toggle.addActionListener(new ActionListener()\r
453     {\r
454       public void actionPerformed(ActionEvent e)\r
455       {\r
456         toggle_actionPerformed(e);\r
457       }\r
458     });\r
459     add(groupMenu);\r
460         add(sequenceMenu);\r
461     this.add(editMenu);\r
462     groupMenu.add(groupName);\r
463         groupMenu.addSeparator();\r
464         groupMenu.add(unGroupMenuItem);\r
465         groupMenu.add(colourMenu);\r
466         groupMenu.addSeparator();\r
467         groupMenu.add(showBoxes);\r
468         groupMenu.add(showText);\r
469         groupMenu.add(showColourText);\r
470         groupMenu.addSeparator();\r
471         groupMenu.add(outline);\r
472         sequenceMenu.add(sequenceName);\r
473         colourMenu.add(noColourmenuItem);\r
474         colourMenu.add(clustalColour);\r
475         colourMenu.add(BLOSUM62Colour);\r
476         colourMenu.add(PIDColour);\r
477         colourMenu.add(zappoColour);\r
478         colourMenu.add(taylorColour);\r
479         colourMenu.add(hydrophobicityColour);\r
480         colourMenu.add(helixColour);\r
481         colourMenu.add(strandColour);\r
482         colourMenu.add(turnColour);\r
483         colourMenu.add(buriedColour);\r
484         colourMenu.add(nucleotideMenuItem);\r
485         colourMenu.add(userDefinedColour);\r
486 \r
487         if(jalview.gui.UserDefinedColours.getUserColourSchemes()!=null)\r
488         {\r
489           java.util.Enumeration userColours = jalview.gui.UserDefinedColours.\r
490               getUserColourSchemes().keys();\r
491 \r
492           while (userColours.hasMoreElements())\r
493           {\r
494             JMenuItem item = new JMenuItem(userColours.\r
495                 nextElement().toString());\r
496             item.addActionListener(new ActionListener()\r
497             {\r
498               public void actionPerformed(ActionEvent evt)\r
499               {\r
500                 userDefinedColour_actionPerformed(evt);\r
501               }\r
502             });\r
503             colourMenu.add(item);\r
504           }\r
505         }\r
506 \r
507 \r
508         colourMenu.addSeparator();\r
509         colourMenu.add(abovePIDColour);\r
510         colourMenu.add(conservationMenuItem);\r
511     editMenu.add(copy);\r
512     editMenu.add(cut);\r
513     editMenu.add(upperCase);\r
514     editMenu.add(lowerCase);\r
515     editMenu.add(toggle);\r
516     noColourmenuItem.setText("None");\r
517         noColourmenuItem.addActionListener(new java.awt.event.ActionListener()\r
518             {\r
519                 public void actionPerformed(ActionEvent e)\r
520                 {\r
521                     noColourmenuItem_actionPerformed(e);\r
522                 }\r
523             });\r
524 \r
525         clustalColour.setText("Clustalx colours");\r
526         clustalColour.addActionListener(new java.awt.event.ActionListener()\r
527             {\r
528                 public void actionPerformed(ActionEvent e)\r
529                 {\r
530                     clustalColour_actionPerformed(e);\r
531                 }\r
532             });\r
533         zappoColour.setText("Zappo");\r
534         zappoColour.addActionListener(new java.awt.event.ActionListener()\r
535             {\r
536                 public void actionPerformed(ActionEvent e)\r
537                 {\r
538                     zappoColour_actionPerformed(e);\r
539                 }\r
540             });\r
541         taylorColour.setText("Taylor");\r
542         taylorColour.addActionListener(new java.awt.event.ActionListener()\r
543             {\r
544                 public void actionPerformed(ActionEvent e)\r
545                 {\r
546                     taylorColour_actionPerformed(e);\r
547                 }\r
548             });\r
549         hydrophobicityColour.setText("Hydrophobicity");\r
550         hydrophobicityColour.addActionListener(new java.awt.event.ActionListener()\r
551             {\r
552                 public void actionPerformed(ActionEvent e)\r
553                 {\r
554                     hydrophobicityColour_actionPerformed(e);\r
555                 }\r
556             });\r
557         helixColour.setText("Helix propensity");\r
558         helixColour.addActionListener(new java.awt.event.ActionListener()\r
559             {\r
560                 public void actionPerformed(ActionEvent e)\r
561                 {\r
562                     helixColour_actionPerformed(e);\r
563                 }\r
564             });\r
565         strandColour.setText("Strand propensity");\r
566         strandColour.addActionListener(new java.awt.event.ActionListener()\r
567             {\r
568                 public void actionPerformed(ActionEvent e)\r
569                 {\r
570                     strandColour_actionPerformed(e);\r
571                 }\r
572             });\r
573         turnColour.setText("Turn propensity");\r
574         turnColour.addActionListener(new java.awt.event.ActionListener()\r
575             {\r
576                 public void actionPerformed(ActionEvent e)\r
577                 {\r
578                     turnColour_actionPerformed(e);\r
579                 }\r
580             });\r
581         buriedColour.setText("Buried Index");\r
582         buriedColour.addActionListener(new java.awt.event.ActionListener()\r
583             {\r
584                 public void actionPerformed(ActionEvent e)\r
585                 {\r
586                     buriedColour_actionPerformed(e);\r
587                 }\r
588             });\r
589         abovePIDColour.setText("Above % Identity");\r
590         abovePIDColour.addActionListener(new java.awt.event.ActionListener()\r
591             {\r
592                 public void actionPerformed(ActionEvent e)\r
593                 {\r
594                     abovePIDColour_actionPerformed(e);\r
595                 }\r
596             });\r
597         userDefinedColour.setText("User Defined...");\r
598         userDefinedColour.addActionListener(new java.awt.event.ActionListener()\r
599             {\r
600                 public void actionPerformed(ActionEvent e)\r
601                 {\r
602                     userDefinedColour_actionPerformed(e);\r
603                 }\r
604             });\r
605         PIDColour.setText("Percentage Identity");\r
606         PIDColour.addActionListener(new java.awt.event.ActionListener()\r
607             {\r
608                 public void actionPerformed(ActionEvent e)\r
609                 {\r
610                     PIDColour_actionPerformed(e);\r
611                 }\r
612             });\r
613         BLOSUM62Colour.setText("BLOSUM62");\r
614         BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()\r
615             {\r
616                 public void actionPerformed(ActionEvent e)\r
617                 {\r
618                     BLOSUM62Colour_actionPerformed(e);\r
619                 }\r
620             });\r
621         conservationMenuItem.setText("Conservation");\r
622         conservationMenuItem.addActionListener(new java.awt.event.ActionListener()\r
623             {\r
624                 public void actionPerformed(ActionEvent e)\r
625                 {\r
626                     conservationMenuItem_actionPerformed(e);\r
627                 }\r
628             });\r
629     }\r
630 \r
631     /**\r
632      * DOCUMENT ME!\r
633      */\r
634     void refresh()\r
635     {\r
636         if (ap.overviewPanel != null)\r
637           ap.overviewPanel.updateOverviewImage();\r
638 \r
639         ap.seqPanel.repaint();\r
640     }\r
641 \r
642     /**\r
643      * DOCUMENT ME!\r
644      *\r
645      * @param e DOCUMENT ME!\r
646      */\r
647     protected void clustalColour_actionPerformed(ActionEvent e)\r
648     {\r
649         SequenceGroup sg = getGroup();\r
650         sg.cs = new ClustalxColourScheme(sg.getSequences(true),\r
651                 ap.av.alignment.getWidth());\r
652         refresh();\r
653     }\r
654 \r
655     /**\r
656      * DOCUMENT ME!\r
657      *\r
658      * @param e DOCUMENT ME!\r
659      */\r
660     protected void zappoColour_actionPerformed(ActionEvent e)\r
661     {\r
662         getGroup().cs = new ZappoColourScheme();\r
663         refresh();\r
664     }\r
665 \r
666     /**\r
667      * DOCUMENT ME!\r
668      *\r
669      * @param e DOCUMENT ME!\r
670      */\r
671     protected void taylorColour_actionPerformed(ActionEvent e)\r
672     {\r
673         getGroup().cs = new TaylorColourScheme();\r
674         refresh();\r
675     }\r
676 \r
677     /**\r
678      * DOCUMENT ME!\r
679      *\r
680      * @param e DOCUMENT ME!\r
681      */\r
682     protected void hydrophobicityColour_actionPerformed(ActionEvent e)\r
683     {\r
684         getGroup().cs = new HydrophobicColourScheme();\r
685         refresh();\r
686     }\r
687 \r
688     /**\r
689      * DOCUMENT ME!\r
690      *\r
691      * @param e DOCUMENT ME!\r
692      */\r
693     protected void helixColour_actionPerformed(ActionEvent e)\r
694     {\r
695         getGroup().cs = new HelixColourScheme();\r
696         refresh();\r
697     }\r
698 \r
699     /**\r
700      * DOCUMENT ME!\r
701      *\r
702      * @param e DOCUMENT ME!\r
703      */\r
704     protected void strandColour_actionPerformed(ActionEvent e)\r
705     {\r
706         getGroup().cs = new StrandColourScheme();\r
707         refresh();\r
708     }\r
709 \r
710     /**\r
711      * DOCUMENT ME!\r
712      *\r
713      * @param e DOCUMENT ME!\r
714      */\r
715     protected void turnColour_actionPerformed(ActionEvent e)\r
716     {\r
717         getGroup().cs = new TurnColourScheme();\r
718         refresh();\r
719     }\r
720 \r
721     /**\r
722      * DOCUMENT ME!\r
723      *\r
724      * @param e DOCUMENT ME!\r
725      */\r
726     protected void buriedColour_actionPerformed(ActionEvent e)\r
727     {\r
728         getGroup().cs = new BuriedColourScheme();\r
729         refresh();\r
730     }\r
731 \r
732     /**\r
733      * DOCUMENT ME!\r
734      *\r
735      * @param e DOCUMENT ME!\r
736      */\r
737     public void nucleotideMenuItem_actionPerformed(ActionEvent e)\r
738     {\r
739         getGroup().cs = new NucleotideColourScheme();\r
740         refresh();\r
741     }\r
742 \r
743     /**\r
744      * DOCUMENT ME!\r
745      *\r
746      * @param e DOCUMENT ME!\r
747      */\r
748     protected void abovePIDColour_actionPerformed(ActionEvent e)\r
749     {\r
750         SequenceGroup sg = getGroup();\r
751         if(sg.cs==null)\r
752           return;\r
753 \r
754         if (abovePIDColour.isSelected())\r
755         {\r
756             sg.cs.setConsensus(AAFrequency.calculate(\r
757                     sg.getSequences(true), 0,\r
758                     ap.av.alignment.getWidth()));\r
759 \r
760             int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,\r
761                     getGroup().getName());\r
762 \r
763            sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());\r
764 \r
765             SliderPanel.showPIDSlider();\r
766         }\r
767         else // remove PIDColouring\r
768         {\r
769             sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());\r
770         }\r
771 \r
772         refresh();\r
773     }\r
774 \r
775     /**\r
776      * DOCUMENT ME!\r
777      *\r
778      * @param e DOCUMENT ME!\r
779      */\r
780     protected void userDefinedColour_actionPerformed(ActionEvent e)\r
781     {\r
782        SequenceGroup sg = getGroup();\r
783 \r
784        if (e.getActionCommand().equals("User Defined..."))\r
785          new UserDefinedColours(ap, sg);\r
786        else\r
787        {\r
788          UserColourScheme udc = (UserColourScheme) UserDefinedColours.\r
789              getUserColourSchemes().get(e.getActionCommand());\r
790 \r
791          sg.cs = udc;\r
792        }\r
793      }\r
794     /**\r
795      * DOCUMENT ME!\r
796      *\r
797      * @param e DOCUMENT ME!\r
798      */\r
799     protected void PIDColour_actionPerformed(ActionEvent e)\r
800     {\r
801         SequenceGroup sg = getGroup();\r
802         sg.cs = new PIDColourScheme();\r
803         sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,\r
804                 ap.av.alignment.getWidth()));\r
805         refresh();\r
806     }\r
807 \r
808     /**\r
809      * DOCUMENT ME!\r
810      *\r
811      * @param e DOCUMENT ME!\r
812      */\r
813     protected void BLOSUM62Colour_actionPerformed(ActionEvent e)\r
814     {\r
815         SequenceGroup sg = getGroup();\r
816 \r
817         sg.cs = new Blosum62ColourScheme();\r
818 \r
819         sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,\r
820                 ap.av.alignment.getWidth()));\r
821 \r
822         refresh();\r
823     }\r
824 \r
825     /**\r
826      * DOCUMENT ME!\r
827      *\r
828      * @param e DOCUMENT ME!\r
829      */\r
830     protected void noColourmenuItem_actionPerformed(ActionEvent e)\r
831     {\r
832         getGroup().cs = null;\r
833         refresh();\r
834     }\r
835 \r
836     /**\r
837      * DOCUMENT ME!\r
838      *\r
839      * @param e DOCUMENT ME!\r
840      */\r
841     protected void conservationMenuItem_actionPerformed(ActionEvent e)\r
842     {\r
843         SequenceGroup sg = getGroup();\r
844         if(sg.cs==null)\r
845           return;\r
846 \r
847         if (conservationMenuItem.isSelected())\r
848         {\r
849             Conservation c = new Conservation("Group",\r
850                     ResidueProperties.propHash, 3,\r
851                     sg.getSequences(true), 0,\r
852                     ap.av.alignment.getWidth());\r
853 \r
854             c.calculate();\r
855             c.verdict(false, ap.av.ConsPercGaps);\r
856 \r
857             sg.cs.setConservation(c);\r
858 \r
859             SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());\r
860             SliderPanel.showConservationSlider();\r
861         }\r
862         else // remove ConservationColouring\r
863         {\r
864             sg.cs.setConservation(null);\r
865         }\r
866 \r
867         refresh();\r
868     }\r
869 \r
870     /**\r
871      * DOCUMENT ME!\r
872      *\r
873      * @param e DOCUMENT ME!\r
874      */\r
875     protected void groupName_actionPerformed(ActionEvent e)\r
876     {\r
877         SequenceGroup sg = getGroup();\r
878         String reply = JOptionPane.showInternalInputDialog(Desktop.desktop,\r
879                 "Enter new group name", "Edit group name",\r
880                 JOptionPane.QUESTION_MESSAGE);\r
881 \r
882         if (reply == null)\r
883         {\r
884             return;\r
885         }\r
886 \r
887         sg.setName(reply);\r
888         groupName.setText(reply);\r
889     }\r
890 \r
891     /**\r
892      * DOCUMENT ME!\r
893      *\r
894      * @param e DOCUMENT ME!\r
895      */\r
896     protected void analyze_actionPerformed(ActionEvent e)\r
897     {\r
898         CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
899         JInternalFrame frame = new JInternalFrame();\r
900         frame.setContentPane(cap);\r
901         Desktop.addInternalFrame(frame, "Analyze this - ", 400, 300);\r
902 \r
903         SequenceGroup sg = getGroup();\r
904         StringBuffer sb = new StringBuffer();\r
905 \r
906         for (int i = 0; i < sg.getSize(false); i++)\r
907         {\r
908             Sequence tmp = (Sequence) sg.getSequences(false).elementAt(i);\r
909             sb.append(tmp.getSequence(sg.getStartRes(), sg.getEndRes() + 1));\r
910             sb.append("\n");\r
911         }\r
912 \r
913         sb.append("Something amazing will happen soon");\r
914         cap.setText(sb.toString());\r
915     }\r
916 \r
917     /**\r
918      * DOCUMENT ME!\r
919      *\r
920      * @return DOCUMENT ME!\r
921      */\r
922     SequenceGroup getGroup()\r
923     {\r
924         SequenceGroup sg = ap.av.getSelectionGroup();\r
925       // this method won't add a new group if it already exists\r
926         if(sg!=null)\r
927           ap.av.alignment.addGroup(sg);\r
928 \r
929         return sg;\r
930     }\r
931 \r
932     /**\r
933      * DOCUMENT ME!\r
934      *\r
935      * @param e DOCUMENT ME!\r
936      */\r
937     void sequenceName_actionPerformed(ActionEvent e)\r
938     {\r
939       JLabel idlabel = new JLabel(  "       Sequence Name ");\r
940       JLabel desclabel = new JLabel("Sequence Description ");\r
941       idlabel.setFont(new Font("Courier", Font.PLAIN, 12));\r
942       desclabel.setFont(new Font("Courier", Font.PLAIN, 12));\r
943       JTextField id = new JTextField(sequence.getName(), 40);\r
944       JTextField description = new JTextField(sequence.getDescription(), 40);\r
945       JPanel panel = new JPanel(new BorderLayout());\r
946       JPanel panel2 = new JPanel(new BorderLayout());\r
947       panel2.add(idlabel, BorderLayout.WEST);\r
948       panel2.add(id, BorderLayout.CENTER);\r
949       panel.add(panel2, BorderLayout.NORTH);\r
950       panel2 = new JPanel(new BorderLayout());\r
951       panel2.add(desclabel, BorderLayout.WEST);\r
952       panel2.add(description, BorderLayout.CENTER);\r
953       panel.add(panel2, BorderLayout.SOUTH);\r
954 \r
955 \r
956        int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,\r
957           panel, "Edit Sequence Name/Description",\r
958           JOptionPane.OK_CANCEL_OPTION );\r
959 \r
960 \r
961         if (reply != JOptionPane.OK_OPTION )\r
962         {\r
963             return;\r
964         }\r
965 \r
966         String s = id.getText();\r
967 \r
968         if (s != null)\r
969         {\r
970             if (s.indexOf(" ") > -1)\r
971             {\r
972                 JOptionPane.showMessageDialog(ap,\r
973                     "Spaces have been converted to \"_\"",\r
974                     "No spaces allowed in Sequence Name",\r
975                     JOptionPane.WARNING_MESSAGE);\r
976             }\r
977 \r
978             s = s.replace(' ', '_');\r
979             sequence.getDatasetSequence().setName(s);\r
980             sequence.setName(s);\r
981             ap.repaint();\r
982         }\r
983 \r
984         sequence.getDatasetSequence().setDescription(description.getText());\r
985         sequence.setDescription(description.getText());\r
986     }\r
987 \r
988     /**\r
989      * DOCUMENT ME!\r
990      *\r
991      * @param e DOCUMENT ME!\r
992      */\r
993     void unGroupMenuItem_actionPerformed(ActionEvent e)\r
994     {\r
995         SequenceGroup sg = ap.av.getSelectionGroup();\r
996         ap.av.alignment.deleteGroup(sg);\r
997         ap.av.setSelectionGroup(null);\r
998         refresh();\r
999     }\r
1000 \r
1001 \r
1002     /**\r
1003      * DOCUMENT ME!\r
1004      *\r
1005      * @param e DOCUMENT ME!\r
1006      */\r
1007     protected void outline_actionPerformed(ActionEvent e)\r
1008     {\r
1009         SequenceGroup sg = getGroup();\r
1010         Color col = JColorChooser.showDialog(this, "Select Outline Colour",\r
1011                 Color.BLUE);\r
1012 \r
1013         if (col != null)\r
1014         {\r
1015             sg.setOutlineColour(col);\r
1016         }\r
1017 \r
1018         refresh();\r
1019     }\r
1020 \r
1021     /**\r
1022      * DOCUMENT ME!\r
1023      *\r
1024      * @param e DOCUMENT ME!\r
1025      */\r
1026     public void showBoxes_actionPerformed(ActionEvent e)\r
1027     {\r
1028         getGroup().setDisplayBoxes(showBoxes.isSelected());\r
1029         refresh();\r
1030     }\r
1031 \r
1032     /**\r
1033      * DOCUMENT ME!\r
1034      *\r
1035      * @param e DOCUMENT ME!\r
1036      */\r
1037     public void showText_actionPerformed(ActionEvent e)\r
1038     {\r
1039         getGroup().setDisplayText(showText.isSelected());\r
1040         refresh();\r
1041     }\r
1042 \r
1043     /**\r
1044      * DOCUMENT ME!\r
1045      *\r
1046      * @param e DOCUMENT ME!\r
1047      */\r
1048     public void showColourText_actionPerformed(ActionEvent e)\r
1049     {\r
1050         getGroup().setColourText(showColourText.isSelected());\r
1051         refresh();\r
1052     }\r
1053 \r
1054     public void showLink(String url)\r
1055     {\r
1056       try\r
1057       {\r
1058         jalview.util.BrowserLauncher.openURL(url);\r
1059       }\r
1060       catch (Exception ex)\r
1061       {\r
1062         JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
1063             "Unixers: Couldn't find default web browser."\r
1064            +"\nAdd the full path to your browser in Preferences.",\r
1065            "Web browser not found", JOptionPane.WARNING_MESSAGE );\r
1066 \r
1067 \r
1068         ex.printStackTrace();\r
1069       }\r
1070     }\r
1071 \r
1072     void hideSequences(boolean representGroup)\r
1073     {\r
1074       SequenceGroup sg = ap.av.getSelectionGroup();\r
1075       if(sg==null || sg.getSize(false)<1)\r
1076       {\r
1077         ap.av.hideSequence(sequence);\r
1078         return;\r
1079       }\r
1080 \r
1081         int index = 0;\r
1082         while(index < sg.getSize(false))\r
1083         {\r
1084           if(representGroup && sg.getSequenceAt(index)!=sequence)\r
1085           {\r
1086             sequence.addHiddenSequence(sg.getSequenceAt(index));\r
1087             ap.av.hideSequence(sg.getSequenceAt(index));\r
1088           }\r
1089           else if(!representGroup)\r
1090           {\r
1091             ap.av.hideSequence(sg.getSequenceAt(index));\r
1092           }\r
1093           index ++;\r
1094         }\r
1095 \r
1096         ap.av.setSelectionGroup(null);\r
1097         refresh();\r
1098     }\r
1099 \r
1100   public void copy_actionPerformed(ActionEvent e)\r
1101   {\r
1102     ap.alignFrame.copy_actionPerformed(null);\r
1103   }\r
1104 \r
1105   public void cut_actionPerformed(ActionEvent e)\r
1106   {\r
1107     ap.alignFrame.cut_actionPerformed(null);\r
1108   }\r
1109 \r
1110   public void upperCase_actionPerformed(ActionEvent e)\r
1111   {\r
1112     SequenceGroup sg = ap.av.getSelectionGroup();\r
1113     if(sg==null)\r
1114       return;\r
1115 \r
1116     for(int g=0; g<sg.getSize(true); g++)\r
1117     {\r
1118     ( (SequenceI)sg.getSequences(true).elementAt(g))\r
1119         .changeCase(true, sg.getStartRes(), sg.getEndRes()+1);\r
1120     }\r
1121     ap.repaint();\r
1122   }\r
1123 \r
1124   public void lowerCase_actionPerformed(ActionEvent e)\r
1125   {\r
1126     SequenceGroup sg = ap.av.getSelectionGroup();\r
1127     if(sg==null)\r
1128       return;\r
1129 \r
1130     for(int g=0; g<sg.getSize(true); g++)\r
1131     {\r
1132        ( (SequenceI)sg.getSequences(true).elementAt(g))\r
1133            .changeCase(false, sg.getStartRes(), sg.getEndRes()+1);\r
1134     }\r
1135     ap.repaint();\r
1136   }\r
1137 \r
1138   public void toggle_actionPerformed(ActionEvent e)\r
1139   {\r
1140     SequenceGroup sg = ap.av.getSelectionGroup();\r
1141     if (sg == null)\r
1142       return;\r
1143 \r
1144     for (int g = 0; g < sg.getSize(true); g++)\r
1145     {\r
1146       ( (SequenceI)sg.getSequences(true).elementAt(g))\r
1147           .toggleCase(sg.getStartRes(), sg.getEndRes() + 1);\r
1148     }\r
1149 \r
1150     ap.repaint();\r
1151   }\r
1152 \r
1153 }\r