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