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