JAL-2050 make SequenceFeature.score final, adjust constructor calls
[jalview.git] / src / jalview / appletgui / APopupMenu.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.appletgui;
22
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentAnnotationUtils;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.bin.JalviewLite;
28 import jalview.commands.ChangeCaseCommand;
29 import jalview.commands.EditCommand;
30 import jalview.commands.EditCommand.Action;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.PDBEntry;
34 import jalview.datamodel.SequenceFeature;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.io.AppletFormatAdapter;
38 import jalview.io.DataSourceType;
39 import jalview.io.FileFormatI;
40 import jalview.io.FileFormats;
41 import jalview.io.SequenceAnnotationReport;
42 import jalview.renderer.ResidueShader;
43 import jalview.renderer.ResidueShaderI;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.BuriedColourScheme;
46 import jalview.schemes.ClustalxColourScheme;
47 import jalview.schemes.HelixColourScheme;
48 import jalview.schemes.HydrophobicColourScheme;
49 import jalview.schemes.JalviewColourScheme;
50 import jalview.schemes.NucleotideColourScheme;
51 import jalview.schemes.PIDColourScheme;
52 import jalview.schemes.PurinePyrimidineColourScheme;
53 import jalview.schemes.StrandColourScheme;
54 import jalview.schemes.TaylorColourScheme;
55 import jalview.schemes.TurnColourScheme;
56 import jalview.schemes.ZappoColourScheme;
57 import jalview.util.MessageManager;
58 import jalview.util.UrlLink;
59
60 import java.awt.CheckboxMenuItem;
61 import java.awt.Frame;
62 import java.awt.Menu;
63 import java.awt.MenuItem;
64 import java.awt.event.ActionEvent;
65 import java.awt.event.ActionListener;
66 import java.awt.event.ItemEvent;
67 import java.awt.event.ItemListener;
68 import java.util.Arrays;
69 import java.util.Collection;
70 import java.util.Collections;
71 import java.util.LinkedHashMap;
72 import java.util.List;
73 import java.util.Map;
74 import java.util.SortedMap;
75 import java.util.TreeMap;
76 import java.util.Vector;
77
78 public class APopupMenu extends java.awt.PopupMenu implements
79         ActionListener, ItemListener
80 {
81   Menu groupMenu = new Menu();
82
83   MenuItem editGroupName = new MenuItem();
84
85   CheckboxMenuItem noColour = new CheckboxMenuItem();
86
87   protected CheckboxMenuItem clustalColour = new CheckboxMenuItem();
88
89   protected CheckboxMenuItem zappoColour = new CheckboxMenuItem();
90
91   protected CheckboxMenuItem taylorColour = new CheckboxMenuItem();
92
93   protected CheckboxMenuItem hydrophobicityColour = new CheckboxMenuItem();
94
95   protected CheckboxMenuItem helixColour = new CheckboxMenuItem();
96
97   protected CheckboxMenuItem strandColour = new CheckboxMenuItem();
98
99   protected CheckboxMenuItem turnColour = new CheckboxMenuItem();
100
101   protected CheckboxMenuItem buriedColour = new CheckboxMenuItem();
102
103   protected CheckboxMenuItem PIDColour = new CheckboxMenuItem();
104
105   protected CheckboxMenuItem BLOSUM62Colour = new CheckboxMenuItem();
106
107   CheckboxMenuItem nucleotideColour = new CheckboxMenuItem();
108
109   CheckboxMenuItem purinePyrimidineColour = new CheckboxMenuItem();
110
111   protected MenuItem userDefinedColour = new MenuItem();
112
113   protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
114
115   MenuItem modifyPID = new MenuItem();
116
117   protected CheckboxMenuItem conservationColour = new CheckboxMenuItem();
118
119   MenuItem modifyConservation = new MenuItem();
120
121   MenuItem noColourmenuItem = new MenuItem();
122
123   final AlignmentPanel ap;
124
125   MenuItem unGroupMenuItem = new MenuItem();
126
127   MenuItem createGroupMenuItem = new MenuItem();
128
129   Menu colourMenu = new Menu();
130
131   CheckboxMenuItem showBoxes = new CheckboxMenuItem();
132
133   CheckboxMenuItem showText = new CheckboxMenuItem();
134
135   CheckboxMenuItem showColourText = new CheckboxMenuItem();
136
137   CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
138
139   Menu seqShowAnnotationsMenu = new Menu(
140           MessageManager.getString("label.show_annotations"));
141
142   Menu seqHideAnnotationsMenu = new Menu(
143           MessageManager.getString("label.hide_annotations"));
144
145   MenuItem seqAddReferenceAnnotations = new MenuItem(
146           MessageManager.getString("label.add_reference_annotations"));
147
148   Menu groupShowAnnotationsMenu = new Menu(
149           MessageManager.getString("label.show_annotations"));
150
151   Menu groupHideAnnotationsMenu = new Menu(
152           MessageManager.getString("label.hide_annotations"));
153
154   MenuItem groupAddReferenceAnnotations = new MenuItem(
155           MessageManager.getString("label.add_reference_annotations"));
156
157   Menu editMenu = new Menu(MessageManager.getString("action.edit"));
158
159   MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
160
161   MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
162
163   MenuItem toUpper = new MenuItem(
164           MessageManager.getString("label.to_upper_case"));
165
166   MenuItem toLower = new MenuItem(
167           MessageManager.getString("label.to_lower_case"));
168
169   MenuItem toggleCase = new MenuItem(
170           MessageManager.getString("label.toggle_case"));
171
172   Menu outputmenu = new Menu();
173
174   Menu seqMenu = new Menu();
175
176   MenuItem pdb = new MenuItem();
177
178   MenuItem hideSeqs = new MenuItem();
179
180   MenuItem repGroup = new MenuItem();
181
182   MenuItem sequenceName = new MenuItem(
183           MessageManager.getString("label.edit_name_description"));
184
185   MenuItem sequenceFeature = new MenuItem(
186           MessageManager.getString("label.create_sequence_feature"));
187
188   MenuItem editSequence = new MenuItem(
189           MessageManager.getString("label.edit_sequence"));
190
191   MenuItem sequenceDetails = new MenuItem(
192           MessageManager.getString("label.sequence_details"));
193
194   MenuItem selSeqDetails = new MenuItem(
195           MessageManager.getString("label.sequence_details"));
196
197   MenuItem makeReferenceSeq = new MenuItem();
198
199   SequenceI seq;
200
201   MenuItem revealAll = new MenuItem();
202
203   MenuItem revealSeq = new MenuItem();
204
205   /**
206    * index of sequence to be revealed
207    */
208   int revealSeq_index = -1;
209
210   Menu menu1 = new Menu();
211
212   public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
213           List<String> links)
214   {
215     // /////////////////////////////////////////////////////////
216     // If this is activated from the sequence panel, the user may want to
217     // edit or annotate a particular residue. Therefore display the residue menu
218     //
219     // If from the IDPanel, we must display the sequence menu
220     // ////////////////////////////////////////////////////////
221
222     this.ap = apanel;
223     this.seq = seq;
224
225     try
226     {
227       jbInit();
228     } catch (Exception e)
229     {
230       e.printStackTrace();
231     }
232
233     for (String ff : FileFormats.getInstance().getWritableFormats(true))
234     {
235       MenuItem item = new MenuItem(ff);
236
237       item.addActionListener(this);
238       outputmenu.add(item);
239     }
240
241     buildAnnotationSubmenus();
242
243     SequenceGroup sg = ap.av.getSelectionGroup();
244     if (sg != null && sg.getSize() > 0)
245     {
246       if (sg.isNucleotide())
247       {
248         conservationColour.setEnabled(false);
249         clustalColour.setEnabled(false);
250         BLOSUM62Colour.setEnabled(false);
251         zappoColour.setEnabled(false);
252         taylorColour.setEnabled(false);
253         hydrophobicityColour.setEnabled(false);
254         helixColour.setEnabled(false);
255         strandColour.setEnabled(false);
256         turnColour.setEnabled(false);
257         buriedColour.setEnabled(false);
258       }
259       else
260       {
261         purinePyrimidineColour.setEnabled(false);
262         nucleotideColour.setEnabled(false);
263       }
264       editGroupName.setLabel(MessageManager.formatMessage(
265               "label.name_param", new Object[] { sg.getName() }));
266       showText.setState(sg.getDisplayText());
267       showColourText.setState(sg.getColourText());
268       showBoxes.setState(sg.getDisplayBoxes());
269       displayNonconserved.setState(sg.getShowNonconserved());
270       if (!ap.av.getAlignment().getGroups().contains(sg))
271       {
272         menu1.setLabel(MessageManager.getString("action.edit_new_group"));
273         groupMenu.remove(unGroupMenuItem);
274       }
275       else
276       {
277         menu1.setLabel(MessageManager.getString("action.edit_group"));
278         groupMenu.remove(createGroupMenuItem);
279         if (sg.cs != null)
280         {
281           abovePIDColour.setState(sg.cs.getThreshold() > 0);
282           conservationColour.setState(sg.cs.conservationApplied());
283           modifyPID.setEnabled(abovePIDColour.getState());
284           modifyConservation.setEnabled(conservationColour.getState());
285         }
286       }
287       setSelectedColour(sg.cs);
288     }
289     else
290     {
291       remove(hideSeqs);
292       remove(groupMenu);
293     }
294
295     if (links != null && links.size() > 0)
296     {
297       addFeatureLinks(seq, links);
298     }
299
300     // TODO: add group link menu entry here
301     if (seq != null)
302     {
303       seqMenu.setLabel(seq.getName());
304       if (seq == ap.av.getAlignment().getSeqrep())
305       {
306         makeReferenceSeq.setLabel(MessageManager
307                 .getString("action.unmark_as_reference"));// Unmark
308                                                           // representative");
309       }
310       else
311       {
312         makeReferenceSeq.setLabel(MessageManager
313                 .getString("action.set_as_reference")); // );
314       }
315       repGroup.setLabel(MessageManager.formatMessage(
316               "label.represent_group_with", new Object[] { seq.getName() }));
317     }
318     else
319     {
320       remove(seqMenu);
321     }
322
323     if (!ap.av.hasHiddenRows())
324     {
325       remove(revealAll);
326       remove(revealSeq);
327     }
328     else
329     {
330       final int index = ap.av.getAlignment().findIndex(seq);
331
332       if (ap.av.adjustForHiddenSeqs(index)
333               - ap.av.adjustForHiddenSeqs(index - 1) > 1)
334       {
335         revealSeq_index = index;
336       }
337       else
338       {
339         remove(revealSeq);
340       }
341     }
342   }
343
344   /**
345    * Select the menu item (if any) matching the current colour scheme. This
346    * works by matching the menu item name (not display text) to the canonical
347    * name of the colour scheme.
348    * 
349    * @param cs
350    */
351   protected void setSelectedColour(ResidueShaderI cs)
352   {
353     if (cs == null || cs.getColourScheme() == null)
354     {
355       noColour.setState(true);
356     }
357     else
358     {
359       String name = cs.getColourScheme().getSchemeName();
360       for (int i = 0; i < colourMenu.getItemCount(); i++)
361       {
362         MenuItem item = colourMenu.getItem(i);
363         if (item instanceof CheckboxMenuItem)
364         {
365           if (name.equals(item.getName()))
366           {
367             ((CheckboxMenuItem) item).setState(true);
368           }
369         }
370       }
371     }
372   }
373
374   /**
375    * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
376    * 
377    * @param seq
378    * @param links
379    */
380   void addFeatureLinks(final SequenceI seq, List<String> links)
381   {
382     Menu linkMenu = new Menu(MessageManager.getString("action.link"));
383     Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
384
385     for (String link : links)
386     {
387       UrlLink urlLink = null;
388       try
389       {
390         urlLink = new UrlLink(link);
391       } catch (Exception foo)
392       {
393         System.err.println("Exception for URLLink '" + link + "': "
394                 + foo.getMessage());
395         continue;
396       }
397
398       if (!urlLink.isValid())
399       {
400         System.err.println(urlLink.getInvalidMessage());
401         continue;
402       }
403
404       urlLink.createLinksFromSeq(seq, linkset);
405     }
406
407     addshowLinks(linkMenu, linkset.values());
408
409     // disable link menu if there are no valid entries
410     if (linkMenu.getItemCount() > 0)
411     {
412       linkMenu.setEnabled(true);
413     }
414     else
415     {
416       linkMenu.setEnabled(false);
417     }
418
419     if (seq != null)
420     {
421       seqMenu.add(linkMenu);
422     }
423     else
424     {
425       add(linkMenu);
426     }
427
428   }
429
430   private void addshowLinks(Menu linkMenu, Collection<List<String>> linkset)
431   {
432     for (List<String> linkstrset : linkset)
433     {
434       // split linkstr into label and url
435       addshowLink(linkMenu, linkstrset.get(1), linkstrset.get(3));
436     }
437   }
438
439   /**
440    * Build menus for annotation types that may be shown or hidden, and for
441    * 'reference annotations' that may be added to the alignment.
442    */
443   private void buildAnnotationSubmenus()
444   {
445     /*
446      * First for the currently selected sequence (if there is one):
447      */
448     final List<SequenceI> selectedSequence = (seq == null ? Collections
449             .<SequenceI> emptyList() : Arrays.asList(seq));
450     buildAnnotationTypesMenus(seqShowAnnotationsMenu,
451             seqHideAnnotationsMenu, selectedSequence);
452     configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
453             selectedSequence);
454
455     /*
456      * and repeat for the current selection group (if there is one):
457      */
458     final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null ? Collections
459             .<SequenceI> emptyList() : ap.av.getSelectionGroup()
460             .getSequences());
461     buildAnnotationTypesMenus(groupShowAnnotationsMenu,
462             groupHideAnnotationsMenu, selectedGroup);
463     configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
464             selectedGroup);
465   }
466
467   /**
468    * Determine whether or not to enable 'add reference annotations' menu item.
469    * It is enable if there are any annotations, on any of the selected
470    * sequences, which are not yet on the alignment (visible or not).
471    * 
472    * @param menu
473    * @param forSequences
474    */
475   private void configureReferenceAnnotationsMenu(MenuItem menuItem,
476           List<SequenceI> forSequences)
477   {
478     menuItem.setEnabled(false);
479
480     /*
481      * Temporary store to hold distinct calcId / type pairs for the tooltip.
482      * Using TreeMap means calcIds are shown in alphabetical order.
483      */
484     SortedMap<String, String> tipEntries = new TreeMap<String, String>();
485     final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
486     AlignmentI al = this.ap.av.getAlignment();
487     AlignmentUtils.findAddableReferenceAnnotations(forSequences,
488             tipEntries, candidates, al);
489     if (!candidates.isEmpty())
490     {
491       StringBuilder tooltip = new StringBuilder(64);
492       tooltip.append(MessageManager.getString("label.add_annotations_for"));
493
494       /*
495        * Found annotations that could be added. Enable the menu item, and
496        * configure its action.
497        */
498       menuItem.setEnabled(true);
499
500       menuItem.addActionListener(new ActionListener()
501       {
502         @Override
503         public void actionPerformed(ActionEvent e)
504         {
505           addReferenceAnnotations_actionPerformed(candidates);
506         }
507       });
508     }
509   }
510
511   /**
512    * Add annotations to the sequences and to the alignment.
513    * 
514    * @param candidates
515    *          a map whose keys are sequences on the alignment, and values a list
516    *          of annotations to add to each sequence
517    */
518   protected void addReferenceAnnotations_actionPerformed(
519           Map<SequenceI, List<AlignmentAnnotation>> candidates)
520   {
521     final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
522     final AlignmentI alignment = this.ap.getAlignment();
523     AlignmentUtils.addReferenceAnnotations(candidates, alignment,
524             selectionGroup);
525     refresh();
526   }
527
528   /**
529    * add a show URL menu item to the given linkMenu
530    * 
531    * @param linkMenu
532    * @param target
533    *          - menu label string
534    * @param url
535    *          - url to open
536    */
537   private void addshowLink(Menu linkMenu, final String target,
538           final String url)
539   {
540     addshowLink(linkMenu, target, target, url);
541   }
542
543   /**
544    * add a show URL menu item to the given linkMenu
545    * 
546    * @param linkMenu
547    * @param target
548    *          - URL target window
549    * @param label
550    *          - menu label string
551    * @param url
552    *          - url to open
553    */
554   private void addshowLink(Menu linkMenu, final String target,
555           final String label, final String url)
556   {
557     MenuItem item = new MenuItem(label);
558     item.addActionListener(new java.awt.event.ActionListener()
559     {
560       @Override
561       public void actionPerformed(ActionEvent e)
562       {
563         ap.alignFrame.showURL(url, target);
564       }
565     });
566     linkMenu.add(item);
567   }
568
569   /**
570    * Actions on selecting / unselecting a checkbox menu item
571    */
572   @Override
573   public void itemStateChanged(ItemEvent evt)
574   {
575     Object source = evt.getSource();
576     if (source == noColour)
577     {
578       noColourmenuItem_actionPerformed();
579     }
580     else if (source == clustalColour)
581     {
582       clustalColour_actionPerformed();
583     }
584     else if (source == BLOSUM62Colour)
585     {
586       BLOSUM62Colour_actionPerformed();
587     }
588     else if (evt.getSource() == PIDColour)
589     {
590       PIDColour_actionPerformed();
591     }
592     else if (source == zappoColour)
593     {
594       zappoColour_actionPerformed();
595     }
596     else if (source == taylorColour)
597     {
598       taylorColour_actionPerformed();
599     }
600     else if (source == hydrophobicityColour)
601     {
602       hydrophobicityColour_actionPerformed();
603     }
604     else if (source == helixColour)
605     {
606       helixColour_actionPerformed();
607     }
608     else if (source == strandColour)
609     {
610       strandColour_actionPerformed();
611     }
612     else if (source == turnColour)
613     {
614       turnColour_actionPerformed();
615     }
616     else if (source == buriedColour)
617     {
618       buriedColour_actionPerformed();
619     }
620     else if (source == nucleotideColour)
621     {
622       nucleotideMenuItem_actionPerformed();
623     }
624     else if (source == purinePyrimidineColour)
625     {
626       purinePyrimidineColour_actionPerformed();
627     }
628     else if (source == abovePIDColour)
629     {
630       abovePIDColour_itemStateChanged();
631     }
632     else if (source == conservationColour)
633     {
634       conservationMenuItem_itemStateChanged();
635     }
636     else if (source == showColourText)
637     {
638       showColourText_itemStateChanged();
639     }
640     else if (source == showText)
641     {
642       showText_itemStateChanged();
643     }
644     else if (source == showBoxes)
645     {
646       showBoxes_itemStateChanged();
647     }
648     else if (source == displayNonconserved)
649     {
650       this.showNonconserved_itemStateChanged();
651     }
652   }
653
654   /**
655    * Actions on clicking a menu item
656    */
657   @Override
658   public void actionPerformed(ActionEvent evt)
659   {
660     Object source = evt.getSource();
661     if (source == userDefinedColour)
662     {
663       userDefinedColour_actionPerformed();
664     }
665     else if (source == modifyConservation)
666     {
667       conservationMenuItem_itemStateChanged();
668     }
669     else if (source == modifyPID)
670     {
671       abovePIDColour_itemStateChanged();
672     }
673     else if (source == unGroupMenuItem)
674     {
675       unGroupMenuItem_actionPerformed();
676     }
677
678     else if (source == createGroupMenuItem)
679     {
680       createGroupMenuItem_actionPerformed();
681     }
682
683     else if (source == sequenceName)
684     {
685       editName();
686     }
687     else if (source == makeReferenceSeq)
688     {
689       makeReferenceSeq_actionPerformed();
690     }
691     else if (source == sequenceDetails)
692     {
693       showSequenceDetails();
694     }
695     else if (source == selSeqDetails)
696     {
697       showSequenceSelectionDetails();
698     }
699     else if (source == pdb)
700     {
701       addPDB();
702     }
703     else if (source == hideSeqs)
704     {
705       hideSequences(false);
706     }
707     else if (source == repGroup)
708     {
709       hideSequences(true);
710     }
711     else if (source == revealSeq)
712     {
713       ap.av.showSequence(revealSeq_index);
714     }
715     else if (source == revealAll)
716     {
717       ap.av.showAllHiddenSeqs();
718     }
719
720     else if (source == editGroupName)
721     {
722       EditNameDialog dialog = new EditNameDialog(getGroup().getName(),
723               getGroup().getDescription(), "       Group Name",
724               "Group Description", ap.alignFrame,
725               "Edit Group Name / Description", 500, 100, true);
726
727       if (dialog.accept)
728       {
729         getGroup().setName(dialog.getName().replace(' ', '_'));
730         getGroup().setDescription(dialog.getDescription());
731       }
732
733     }
734     else if (source == copy)
735     {
736       ap.alignFrame.copy_actionPerformed();
737     }
738     else if (source == cut)
739     {
740       ap.alignFrame.cut_actionPerformed();
741     }
742     else if (source == editSequence)
743     {
744       SequenceGroup sg = ap.av.getSelectionGroup();
745
746       if (sg != null)
747       {
748         if (seq == null)
749         {
750           seq = sg.getSequenceAt(0);
751         }
752
753         EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
754                 sg.getStartRes(), sg.getEndRes() + 1), null,
755                 "Edit Sequence ", null,
756
757                 ap.alignFrame, "Edit Sequence", 500, 100, true);
758
759         if (dialog.accept)
760         {
761           EditCommand editCommand = new EditCommand(
762                   MessageManager.getString("label.edit_sequences"),
763                   Action.REPLACE, dialog.getName().replace(' ',
764                           ap.av.getGapCharacter()),
765                   sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
766                   sg.getStartRes(), sg.getEndRes() + 1,
767                   ap.av.getAlignment());
768
769           ap.alignFrame.addHistoryItem(editCommand);
770
771           ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
772                   .getSequences());
773         }
774       }
775     }
776     else if (source == toUpper || source == toLower || source == toggleCase)
777     {
778       SequenceGroup sg = ap.av.getSelectionGroup();
779       if (sg != null)
780       {
781         List<int[]> startEnd = ap.av.getVisibleRegionBoundaries(
782                 sg.getStartRes(), sg.getEndRes() + 1);
783
784         String description;
785         int caseChange;
786
787         if (source == toggleCase)
788         {
789           description = "Toggle Case";
790           caseChange = ChangeCaseCommand.TOGGLE_CASE;
791         }
792         else if (source == toUpper)
793         {
794           description = "To Upper Case";
795           caseChange = ChangeCaseCommand.TO_UPPER;
796         }
797         else
798         {
799           description = "To Lower Case";
800           caseChange = ChangeCaseCommand.TO_LOWER;
801         }
802
803         ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
804                 sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
805                 startEnd, caseChange);
806
807         ap.alignFrame.addHistoryItem(caseCommand);
808
809         ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
810                 .getSequences());
811
812       }
813     }
814     else if (source == sequenceFeature)
815     {
816       SequenceGroup sg = ap.av.getSelectionGroup();
817       if (sg == null)
818       {
819         return;
820       }
821
822       int rsize = 0, gSize = sg.getSize();
823       SequenceI[] rseqs, seqs = new SequenceI[gSize];
824       SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
825
826       for (int i = 0; i < gSize; i++)
827       {
828         int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
829         int end = sg.findEndRes(sg.getSequenceAt(i));
830         if (start <= end)
831         {
832           seqs[rsize] = sg.getSequenceAt(i);
833           features[rsize] = new SequenceFeature(null, null, start,
834                   end, "Jalview");
835           rsize++;
836         }
837       }
838       rseqs = new SequenceI[rsize];
839       tfeatures = new SequenceFeature[rsize];
840       System.arraycopy(seqs, 0, rseqs, 0, rsize);
841       System.arraycopy(features, 0, tfeatures, 0, rsize);
842       features = tfeatures;
843       seqs = rseqs;
844
845       if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
846               features, true, ap))
847       {
848         ap.alignFrame.sequenceFeatures.setState(true);
849         ap.av.setShowSequenceFeatures(true);
850         ;
851         ap.highlightSearchResults(null);
852       }
853     }
854     else
855     {
856       outputText(evt);
857     }
858
859   }
860
861   void outputText(ActionEvent e)
862   {
863     CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
864
865     Frame frame = new Frame();
866     frame.add(cap);
867     JalviewLite.addFrame(frame, MessageManager.formatMessage(
868             "label.selection_output_command",
869             new Object[] { e.getActionCommand() }), 600, 500);
870     // JBPNote: getSelectionAsNewSequence behaviour has changed - this method
871     // now returns a full copy of sequence data
872     // TODO consider using getSequenceSelection instead here
873
874     FileFormatI fileFormat = FileFormats.getInstance().forName(
875             e.getActionCommand());
876     cap.setText(new AppletFormatAdapter().formatSequences(fileFormat,
877             ap.av.getShowJVSuffix(), ap, true));
878
879   }
880
881   protected void showSequenceSelectionDetails()
882   {
883     createSequenceDetailsReport(ap.av.getSequenceSelection());
884   }
885
886   protected void showSequenceDetails()
887   {
888     createSequenceDetailsReport(new SequenceI[] { seq });
889   }
890
891   public void createSequenceDetailsReport(SequenceI[] sequences)
892   {
893
894     CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
895
896     StringBuilder contents = new StringBuilder(128);
897     for (SequenceI seq : sequences)
898     {
899       contents.append(MessageManager.formatMessage(
900               "label.annotation_for_displayid",
901               new Object[] { seq.getDisplayId(true) }));
902       new SequenceAnnotationReport(null).createSequenceAnnotationReport(
903               contents,
904               seq,
905               true,
906               true,
907               (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
908                       .getMinMax() : null);
909       contents.append("</p>");
910     }
911     Frame frame = new Frame();
912     frame.add(cap);
913     jalview.bin.JalviewLite.addFrame(frame, "Sequence Details for "
914             + (sequences.length == 1 ? sequences[0].getDisplayId(true)
915                     : "Selection"), 600, 500);
916     cap.setText(MessageManager.formatMessage("label.html_content",
917             new Object[] { contents.toString() }));
918   }
919
920   void editName()
921   {
922     EditNameDialog dialog = new EditNameDialog(seq.getName(),
923             seq.getDescription(), "       Sequence Name",
924             "Sequence Description", ap.alignFrame,
925             "Edit Sequence Name / Description", 500, 100, true);
926
927     if (dialog.accept)
928     {
929       seq.setName(dialog.getName());
930       seq.setDescription(dialog.getDescription());
931       ap.paintAlignment(false);
932     }
933   }
934
935   void addPDB()
936   {
937     Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
938     if (pdbs != null && !pdbs.isEmpty())
939     {
940       PDBEntry entry = pdbs.firstElement();
941
942       if (ap.av.applet.jmolAvailable)
943       {
944         new AppletJmol(entry, new SequenceI[] { seq }, null, ap,
945                 DataSourceType.URL);
946       }
947       else
948       {
949         new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
950                 ap, DataSourceType.URL);
951       }
952
953     }
954     else
955     {
956       CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
957       cap.setText(MessageManager.getString("label.paste_pdb_file"));
958       cap.setPDBImport(seq);
959       Frame frame = new Frame();
960       frame.add(cap);
961       JalviewLite.addFrame(frame, MessageManager.formatMessage(
962               "label.paste_pdb_file_for_sequence",
963               new Object[] { seq.getName() }), 400, 300);
964     }
965   }
966
967   private void jbInit() throws Exception
968   {
969     groupMenu.setLabel(MessageManager.getString("label.selection"));
970     sequenceFeature.addActionListener(this);
971
972     editGroupName.addActionListener(this);
973     unGroupMenuItem.setLabel(MessageManager
974             .getString("action.remove_group"));
975     unGroupMenuItem.addActionListener(this);
976
977     createGroupMenuItem.setLabel(MessageManager
978             .getString("action.create_group"));
979     createGroupMenuItem.addActionListener(this);
980
981     modifyPID.setEnabled(abovePIDColour.getState());
982     modifyConservation.setEnabled(conservationColour.getState());
983     colourMenu.setLabel(MessageManager.getString("label.group_colour"));
984     showBoxes.setLabel(MessageManager.getString("action.boxes"));
985     showBoxes.setState(true);
986     showBoxes.addItemListener(this);
987     sequenceName.addActionListener(this);
988     sequenceDetails.addActionListener(this);
989     selSeqDetails.addActionListener(this);
990     displayNonconserved.setLabel(MessageManager
991             .getString("label.show_non_conserved"));
992     displayNonconserved.setState(false);
993     displayNonconserved.addItemListener(this);
994     showText.setLabel(MessageManager.getString("action.text"));
995     showText.addItemListener(this);
996     showColourText.setLabel(MessageManager.getString("label.colour_text"));
997     showColourText.addItemListener(this);
998     outputmenu.setLabel(MessageManager.getString("label.out_to_textbox"));
999     seqMenu.setLabel(MessageManager.getString("label.sequence"));
1000     pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
1001     hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
1002     repGroup.setLabel(MessageManager.formatMessage(
1003             "label.represent_group_with", new Object[] { "" }));
1004     revealAll.setLabel(MessageManager.getString("action.reveal_all"));
1005     revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
1006     menu1.setLabel(MessageManager.getString("label.group:"));
1007     add(groupMenu);
1008     this.add(seqMenu);
1009     this.add(hideSeqs);
1010     this.add(revealSeq);
1011     this.add(revealAll);
1012     // groupMenu.add(selSeqDetails);
1013     groupMenu.add(groupShowAnnotationsMenu);
1014     groupMenu.add(groupHideAnnotationsMenu);
1015     groupMenu.add(groupAddReferenceAnnotations);
1016     groupMenu.add(editMenu);
1017     groupMenu.add(outputmenu);
1018     groupMenu.add(sequenceFeature);
1019     groupMenu.add(createGroupMenuItem);
1020     groupMenu.add(unGroupMenuItem);
1021     groupMenu.add(menu1);
1022
1023     colourMenu.add(noColour);
1024     colourMenu.add(clustalColour);
1025     colourMenu.add(BLOSUM62Colour);
1026     colourMenu.add(PIDColour);
1027     colourMenu.add(zappoColour);
1028     colourMenu.add(taylorColour);
1029     colourMenu.add(hydrophobicityColour);
1030     colourMenu.add(helixColour);
1031     colourMenu.add(strandColour);
1032     colourMenu.add(turnColour);
1033     colourMenu.add(buriedColour);
1034     colourMenu.add(nucleotideColour);
1035     colourMenu.add(purinePyrimidineColour);
1036     colourMenu.add(userDefinedColour);
1037     colourMenu.addSeparator();
1038     colourMenu.add(conservationColour);
1039     colourMenu.add(modifyConservation);
1040     colourMenu.add(abovePIDColour);
1041     colourMenu.add(modifyPID);
1042
1043     noColour.setLabel(MessageManager.getString("label.none"));
1044     noColour.addItemListener(this);
1045
1046     /*
1047      * setName allows setSelectedColour to do its thing
1048      */
1049     clustalColour.setLabel(MessageManager
1050             .getString("label.colourScheme_clustal"));
1051     clustalColour.setName(JalviewColourScheme.Clustal.toString());
1052     clustalColour.addItemListener(this);
1053     BLOSUM62Colour.setLabel(MessageManager
1054             .getString("label.colourScheme_blosum62"));
1055     BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
1056     BLOSUM62Colour.addItemListener(this);
1057     PIDColour.setLabel(MessageManager
1058             .getString("label.colourScheme_%_identity"));
1059     PIDColour.setName(JalviewColourScheme.PID.toString());
1060     PIDColour.addItemListener(this);
1061     zappoColour.setLabel(MessageManager
1062             .getString("label.colourScheme_zappo"));
1063     zappoColour.setName(JalviewColourScheme.Zappo.toString());
1064     zappoColour.addItemListener(this);
1065     taylorColour.setLabel(MessageManager
1066             .getString("label.colourScheme_taylor"));
1067     taylorColour.setName(JalviewColourScheme.Taylor.toString());
1068     taylorColour.addItemListener(this);
1069     hydrophobicityColour.setLabel(MessageManager
1070             .getString("label.colourScheme_hydrophobic"));
1071     hydrophobicityColour
1072             .setName(JalviewColourScheme.Hydrophobic.toString());
1073     hydrophobicityColour.addItemListener(this);
1074     helixColour.setLabel(MessageManager
1075             .getString("label.colourScheme_helix_propensity"));
1076     helixColour.setName(JalviewColourScheme.Helix.toString());
1077     helixColour.addItemListener(this);
1078     strandColour.setLabel(MessageManager
1079             .getString("label.colourScheme_strand_propensity"));
1080     strandColour.setName(JalviewColourScheme.Strand.toString());
1081     strandColour.addItemListener(this);
1082     turnColour.setLabel(MessageManager
1083             .getString("label.colourScheme_turn_propensity"));
1084     turnColour.setName(JalviewColourScheme.Turn.toString());
1085     turnColour.addItemListener(this);
1086     buriedColour.setLabel(MessageManager
1087             .getString("label.colourScheme_buried_index"));
1088     buriedColour.setName(JalviewColourScheme.Buried.toString());
1089     buriedColour.addItemListener(this);
1090     nucleotideColour.setLabel(MessageManager
1091             .getString("label.colourScheme_nucleotide"));
1092     nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
1093     nucleotideColour.addItemListener(this);
1094     purinePyrimidineColour.setLabel(MessageManager
1095             .getString("label.colourScheme_purine/pyrimidine"));
1096     purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
1097             .toString());
1098     purinePyrimidineColour.addItemListener(this);
1099
1100     userDefinedColour.setLabel(MessageManager
1101             .getString("action.user_defined"));
1102     userDefinedColour.addActionListener(this);
1103
1104     abovePIDColour.setLabel(MessageManager
1105             .getString("label.above_identity_threshold"));
1106     abovePIDColour.addItemListener(this);
1107     modifyPID.setLabel(MessageManager
1108             .getString("label.modify_identity_threshold"));
1109     modifyPID.addActionListener(this);
1110     conservationColour.setLabel(MessageManager
1111             .getString("action.by_conservation"));
1112     conservationColour.addItemListener(this);
1113     modifyConservation.setLabel(MessageManager
1114             .getString("label.modify_conservation_threshold"));
1115     modifyConservation.addActionListener(this);
1116
1117     PIDColour.addActionListener(this);
1118     BLOSUM62Colour.addActionListener(this);
1119
1120     editMenu.add(copy);
1121     copy.addActionListener(this);
1122     editMenu.add(cut);
1123     cut.addActionListener(this);
1124
1125     editMenu.add(editSequence);
1126     editSequence.addActionListener(this);
1127
1128     editMenu.add(toUpper);
1129     toUpper.addActionListener(this);
1130     editMenu.add(toLower);
1131     toLower.addActionListener(this);
1132     editMenu.add(toggleCase);
1133     seqMenu.add(seqShowAnnotationsMenu);
1134     seqMenu.add(seqHideAnnotationsMenu);
1135     seqMenu.add(seqAddReferenceAnnotations);
1136     seqMenu.add(sequenceName);
1137     seqMenu.add(makeReferenceSeq);
1138     // seqMenu.add(sequenceDetails);
1139
1140     if (!ap.av.applet.useXtrnalSviewer)
1141     {
1142       seqMenu.add(pdb);
1143     }
1144     seqMenu.add(repGroup);
1145     menu1.add(editGroupName);
1146     menu1.add(colourMenu);
1147     menu1.add(showBoxes);
1148     menu1.add(showText);
1149     menu1.add(showColourText);
1150     menu1.add(displayNonconserved);
1151     toggleCase.addActionListener(this);
1152     pdb.addActionListener(this);
1153     hideSeqs.addActionListener(this);
1154     repGroup.addActionListener(this);
1155     revealAll.addActionListener(this);
1156     revealSeq.addActionListener(this);
1157     makeReferenceSeq.addActionListener(this);
1158   }
1159
1160   void refresh()
1161   {
1162     ap.paintAlignment(true);
1163   }
1164
1165   protected void clustalColour_actionPerformed()
1166   {
1167     SequenceGroup sg = getGroup();
1168     sg.cs = new ResidueShader(new ClustalxColourScheme(sg,
1169             ap.av.getHiddenRepSequences()));
1170     refresh();
1171   }
1172
1173   protected void zappoColour_actionPerformed()
1174   {
1175     getGroup().cs = new ResidueShader(new ZappoColourScheme());
1176     refresh();
1177   }
1178
1179   protected void taylorColour_actionPerformed()
1180   {
1181     getGroup().cs = new ResidueShader(new TaylorColourScheme());
1182     refresh();
1183   }
1184
1185   protected void hydrophobicityColour_actionPerformed()
1186   {
1187     getGroup().cs = new ResidueShader(new HydrophobicColourScheme());
1188     refresh();
1189   }
1190
1191   protected void helixColour_actionPerformed()
1192   {
1193     getGroup().cs = new ResidueShader(new HelixColourScheme());
1194     refresh();
1195   }
1196
1197   protected void strandColour_actionPerformed()
1198   {
1199     getGroup().cs = new ResidueShader(new StrandColourScheme());
1200     refresh();
1201   }
1202
1203   protected void turnColour_actionPerformed()
1204   {
1205     getGroup().cs = new ResidueShader(new TurnColourScheme());
1206     refresh();
1207   }
1208
1209   protected void buriedColour_actionPerformed()
1210   {
1211     getGroup().cs = new ResidueShader(new BuriedColourScheme());
1212     refresh();
1213   }
1214
1215   public void nucleotideMenuItem_actionPerformed()
1216   {
1217     getGroup().cs = new ResidueShader(new NucleotideColourScheme());
1218     refresh();
1219   }
1220
1221   public void purinePyrimidineColour_actionPerformed()
1222   {
1223     getGroup().cs = new ResidueShader(
1224             new PurinePyrimidineColourScheme());
1225     refresh();
1226   }
1227
1228   protected void abovePIDColour_itemStateChanged()
1229   {
1230     SequenceGroup sg = getGroup();
1231     if (sg.cs == null)
1232     {
1233       return;
1234     }
1235
1236     if (abovePIDColour.getState())
1237     {
1238       sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1239               .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1240       int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1241               .getName());
1242
1243       sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
1244
1245       SliderPanel.showPIDSlider();
1246
1247     }
1248     else
1249     // remove PIDColouring
1250     {
1251       SliderPanel.hidePIDSlider();
1252       sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
1253     }
1254     modifyPID.setEnabled(abovePIDColour.getState());
1255     refresh();
1256   }
1257
1258   protected void userDefinedColour_actionPerformed()
1259   {
1260     new UserDefinedColours(ap, getGroup());
1261   }
1262
1263   protected void PIDColour_actionPerformed()
1264   {
1265     SequenceGroup sg = getGroup();
1266     sg.cs = new ResidueShader(new PIDColourScheme());
1267     sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1268             .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1269     refresh();
1270   }
1271
1272   protected void BLOSUM62Colour_actionPerformed()
1273   {
1274     SequenceGroup sg = getGroup();
1275
1276     sg.cs = new ResidueShader(new Blosum62ColourScheme());
1277
1278     sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
1279             .getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
1280
1281     refresh();
1282   }
1283
1284   protected void noColourmenuItem_actionPerformed()
1285   {
1286     getGroup().cs = null;
1287     refresh();
1288   }
1289
1290   protected void conservationMenuItem_itemStateChanged()
1291   {
1292     SequenceGroup sg = getGroup();
1293     if (sg.cs == null)
1294     {
1295       return;
1296     }
1297
1298     if (conservationColour.getState())
1299     {
1300       Conservation conservation = Conservation.calculateConservation(
1301               "Group", sg
1302               .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
1303               .getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
1304               false);
1305       sg.getGroupColourScheme().setConservation(conservation);
1306       SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1307       SliderPanel.showConservationSlider();
1308     }
1309     else
1310     // remove ConservationColouring
1311     {
1312       SliderPanel.hideConservationSlider();
1313       sg.cs.setConservation(null);
1314     }
1315     modifyConservation.setEnabled(conservationColour.getState());
1316     refresh();
1317   }
1318
1319   SequenceGroup getGroup()
1320   {
1321     SequenceGroup sg = ap.av.getSelectionGroup();
1322
1323     // this method won't add a new group if it already exists
1324     if (sg != null)
1325     {
1326       ap.av.getAlignment().addGroup(sg);
1327     }
1328
1329     return sg;
1330   }
1331
1332   void unGroupMenuItem_actionPerformed()
1333   {
1334     SequenceGroup sg = ap.av.getSelectionGroup();
1335     ap.av.getAlignment().deleteGroup(sg);
1336     ap.av.setSelectionGroup(null);
1337     ap.paintAlignment(true);
1338   }
1339
1340   void createGroupMenuItem_actionPerformed()
1341   {
1342     getGroup(); // implicitly create group
1343     refresh();
1344   }
1345
1346   public void showColourText_itemStateChanged()
1347   {
1348     getGroup().setColourText(showColourText.getState());
1349     refresh();
1350   }
1351
1352   public void showText_itemStateChanged()
1353   {
1354     getGroup().setDisplayText(showText.getState());
1355     refresh();
1356   }
1357
1358   public void makeReferenceSeq_actionPerformed()
1359   {
1360     if (!ap.av.getAlignment().hasSeqrep())
1361     {
1362       // initialise the display flags so the user sees something happen
1363       ap.av.setDisplayReferenceSeq(true);
1364       ap.av.setColourByReferenceSeq(true);
1365       ap.av.getAlignment().setSeqrep(seq);
1366     }
1367     else
1368     {
1369       if (ap.av.getAlignment().getSeqrep() == seq)
1370       {
1371         ap.av.getAlignment().setSeqrep(null);
1372       }
1373       else
1374       {
1375         ap.av.getAlignment().setSeqrep(seq);
1376       }
1377     }
1378     refresh();
1379   }
1380
1381   public void showNonconserved_itemStateChanged()
1382   {
1383     getGroup().setShowNonconserved(this.displayNonconserved.getState());
1384     refresh();
1385   }
1386
1387   public void showBoxes_itemStateChanged()
1388   {
1389     getGroup().setDisplayBoxes(showBoxes.getState());
1390     refresh();
1391   }
1392
1393   void hideSequences(boolean representGroup)
1394   {
1395     ap.av.hideSequences(seq, representGroup);
1396   }
1397
1398   /**
1399    * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
1400    * "All" is added first, followed by a separator. Then add any annotation
1401    * types associated with the current selection. Separate menus are built for
1402    * the selected sequence group (if any), and the selected sequence.
1403    * <p>
1404    * Some annotation rows are always rendered together - these can be identified
1405    * by a common graphGroup property > -1. Only one of each group will be marked
1406    * as visible (to avoid duplication of the display). For such groups we add a
1407    * composite type name, e.g.
1408    * <p>
1409    * IUPredWS (Long), IUPredWS (Short)
1410    * 
1411    * @param seq
1412    */
1413   protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
1414           List<SequenceI> forSequences)
1415   {
1416     showMenu.removeAll();
1417     hideMenu.removeAll();
1418
1419     final List<String> all = Arrays.asList(new String[] { MessageManager
1420             .getString("label.all") });
1421     addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true);
1422     addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true,
1423             false);
1424     showMenu.addSeparator();
1425     hideMenu.addSeparator();
1426
1427     final AlignmentAnnotation[] annotations = ap.getAlignment()
1428             .getAlignmentAnnotation();
1429
1430     /*
1431      * Find shown/hidden annotations types, distinguished by source (calcId),
1432      * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in
1433      * the insertion order, which is the order of the annotations on the
1434      * alignment.
1435      */
1436     Map<String, List<List<String>>> shownTypes = new LinkedHashMap<String, List<List<String>>>();
1437     Map<String, List<List<String>>> hiddenTypes = new LinkedHashMap<String, List<List<String>>>();
1438     AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
1439             AlignmentAnnotationUtils.asList(annotations), forSequences);
1440
1441     for (String calcId : hiddenTypes.keySet())
1442     {
1443       for (List<String> type : hiddenTypes.get(calcId))
1444       {
1445         addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
1446                 false, true);
1447       }
1448     }
1449     // grey out 'show annotations' if none are hidden
1450     showMenu.setEnabled(!hiddenTypes.isEmpty());
1451
1452     for (String calcId : shownTypes.keySet())
1453     {
1454       for (List<String> type : shownTypes.get(calcId))
1455       {
1456         addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
1457                 false, false);
1458       }
1459     }
1460     // grey out 'hide annotations' if none are shown
1461     hideMenu.setEnabled(!shownTypes.isEmpty());
1462   }
1463
1464   /**
1465    * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
1466    * menus.
1467    * 
1468    * @param showOrHideMenu
1469    *          the menu to add to
1470    * @param forSequences
1471    *          the sequences whose annotations may be shown or hidden
1472    * @param calcId
1473    * @param types
1474    *          the label to add
1475    * @param allTypes
1476    *          if true this is a special label meaning 'All'
1477    * @param actionIsShow
1478    *          if true, the select menu item action is to show the annotation
1479    *          type, else hide
1480    */
1481   protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
1482           final List<SequenceI> forSequences, String calcId,
1483           final List<String> types, final boolean allTypes,
1484           final boolean actionIsShow)
1485   {
1486     String label = types.toString(); // [a, b, c]
1487     label = label.substring(1, label.length() - 1);
1488     final MenuItem item = new MenuItem(label);
1489     item.addActionListener(new java.awt.event.ActionListener()
1490     {
1491       @Override
1492       public void actionPerformed(ActionEvent e)
1493       {
1494         AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
1495                 types, forSequences, allTypes, actionIsShow);
1496         refresh();
1497       }
1498     });
1499     showOrHideMenu.add(item);
1500   }
1501
1502 }