JAL-2403 redundant 'implements' removed
[jalview.git] / src / jalview / appletgui / AlignFrame.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.AlignmentSorter;
24 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
25 import jalview.analysis.NJTree;
26 import jalview.api.AlignViewControllerGuiI;
27 import jalview.api.AlignViewControllerI;
28 import jalview.api.AlignViewportI;
29 import jalview.api.FeatureColourI;
30 import jalview.api.FeatureRenderer;
31 import jalview.api.FeatureSettingsControllerI;
32 import jalview.api.SequenceStructureBinding;
33 import jalview.bin.JalviewLite;
34 import jalview.commands.CommandI;
35 import jalview.commands.EditCommand;
36 import jalview.commands.EditCommand.Action;
37 import jalview.commands.OrderCommand;
38 import jalview.commands.RemoveGapColCommand;
39 import jalview.commands.RemoveGapsCommand;
40 import jalview.commands.SlideSequencesCommand;
41 import jalview.commands.TrimRegionCommand;
42 import jalview.datamodel.Alignment;
43 import jalview.datamodel.AlignmentAnnotation;
44 import jalview.datamodel.AlignmentI;
45 import jalview.datamodel.AlignmentOrder;
46 import jalview.datamodel.ColumnSelection;
47 import jalview.datamodel.PDBEntry;
48 import jalview.datamodel.Sequence;
49 import jalview.datamodel.SequenceGroup;
50 import jalview.datamodel.SequenceI;
51 import jalview.io.AnnotationFile;
52 import jalview.io.AppletFormatAdapter;
53 import jalview.io.DataSourceType;
54 import jalview.io.FeaturesFile;
55 import jalview.io.FileFormat;
56 import jalview.io.FileFormatI;
57 import jalview.io.FileFormats;
58 import jalview.io.TCoffeeScoreFile;
59 import jalview.schemes.Blosum62ColourScheme;
60 import jalview.schemes.BuriedColourScheme;
61 import jalview.schemes.ClustalxColourScheme;
62 import jalview.schemes.ColourSchemeI;
63 import jalview.schemes.HelixColourScheme;
64 import jalview.schemes.HydrophobicColourScheme;
65 import jalview.schemes.NucleotideColourScheme;
66 import jalview.schemes.PIDColourScheme;
67 import jalview.schemes.PurinePyrimidineColourScheme;
68 import jalview.schemes.RNAHelicesColour;
69 import jalview.schemes.StrandColourScheme;
70 import jalview.schemes.TCoffeeColourScheme;
71 import jalview.schemes.TaylorColourScheme;
72 import jalview.schemes.TurnColourScheme;
73 import jalview.schemes.ZappoColourScheme;
74 import jalview.structure.StructureSelectionManager;
75 import jalview.structures.models.AAStructureBindingModel;
76 import jalview.util.MappingUtils;
77 import jalview.util.MessageManager;
78 import jalview.viewmodel.AlignmentViewport;
79
80 import java.awt.BorderLayout;
81 import java.awt.Canvas;
82 import java.awt.CheckboxMenuItem;
83 import java.awt.Color;
84 import java.awt.FlowLayout;
85 import java.awt.Font;
86 import java.awt.FontMetrics;
87 import java.awt.Frame;
88 import java.awt.Graphics;
89 import java.awt.Label;
90 import java.awt.Menu;
91 import java.awt.MenuBar;
92 import java.awt.MenuItem;
93 import java.awt.Panel;
94 import java.awt.event.ActionEvent;
95 import java.awt.event.ActionListener;
96 import java.awt.event.FocusEvent;
97 import java.awt.event.FocusListener;
98 import java.awt.event.ItemEvent;
99 import java.awt.event.ItemListener;
100 import java.awt.event.KeyEvent;
101 import java.awt.event.KeyListener;
102 import java.awt.event.WindowAdapter;
103 import java.awt.event.WindowEvent;
104 import java.io.IOException;
105 import java.net.URL;
106 import java.net.URLEncoder;
107 import java.util.Arrays;
108 import java.util.Deque;
109 import java.util.HashMap;
110 import java.util.List;
111 import java.util.Map;
112 import java.util.StringTokenizer;
113 import java.util.Vector;
114
115 import org.jmol.viewer.Viewer;
116
117 public class AlignFrame extends EmbmenuFrame implements ActionListener,
118         ItemListener, KeyListener, AlignViewControllerGuiI
119 {
120   public AlignViewControllerI avc;
121
122   public AlignmentPanel alignPanel;
123
124   public AlignViewport viewport;
125
126   // width and height may be overridden by applet parameters
127   int frameWidth = 700;
128
129   int frameHeight = 500;
130
131   String jalviewServletURL;
132
133   /*
134    * Flag for showing autocalculated consensus above or below other consensus
135    * rows
136    */
137   private boolean showAutoCalculatedAbove;
138
139   private SequenceAnnotationOrder annotationSortOrder;
140
141   /**
142    * Constructor that creates the frame and adds it to the display.
143    * 
144    * @param al
145    * @param applet
146    * @param title
147    * @param embedded
148    */
149   public AlignFrame(AlignmentI al, JalviewLite applet, String title,
150           boolean embedded)
151   {
152     this(al, applet, title, embedded, true);
153   }
154
155   /**
156    * Constructor that optionally allows the frame to be displayed or only
157    * created.
158    * 
159    * @param al
160    * @param applet
161    * @param title
162    * @param embedded
163    * @param addToDisplay
164    */
165   public AlignFrame(AlignmentI al, JalviewLite applet, String title,
166           boolean embedded, boolean addToDisplay)
167   {
168     this(al, null, null, applet, title, embedded, addToDisplay);
169   }
170
171   public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
172           ColumnSelection columnSelection, JalviewLite applet,
173           String title, boolean embedded)
174   {
175     this(al, hiddenSeqs, columnSelection, applet, title, embedded, true);
176   }
177
178   public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
179           ColumnSelection columnSelection, JalviewLite applet,
180           String title, boolean embedded, boolean addToDisplay)
181   {
182     if (applet != null)
183     {
184       jalviewServletURL = applet.getParameter("APPLICATION_URL");
185     }
186
187     try
188     {
189       jbInit();
190     } catch (Exception ex)
191     {
192       ex.printStackTrace();
193     }
194     // need to get window geometry before we calculate alignment layout
195     if (applet != null)
196     {
197       String param;
198       try
199       {
200         param = applet.getParameter("windowWidth");
201         if (param != null)
202         {
203           int width = Integer.parseInt(param);
204           frameWidth = width;
205         }
206         param = applet.getParameter("windowHeight");
207         if (param != null)
208         {
209           int height = Integer.parseInt(param);
210           frameHeight = height;
211         }
212       } catch (Exception ex)
213       {
214       }
215     }
216     viewport = new AlignViewport(al, applet);
217
218     if (hiddenSeqs != null && hiddenSeqs.length > 0)
219     {
220       viewport.hideSequence(hiddenSeqs);
221     }
222     if (columnSelection != null)
223     {
224       viewport.setColumnSelection(columnSelection);
225     }
226     viewport.setScaleAboveWrapped(scaleAbove.getState());
227
228     alignPanel = new AlignmentPanel(this, viewport);
229     avc = new jalview.controller.AlignViewController(this, viewport,
230             alignPanel);
231     viewport.updateConservation(alignPanel);
232     viewport.updateConsensus(alignPanel);
233
234     displayNonconservedMenuItem.setState(viewport.getShowUnconserved());
235     followMouseOverFlag.setState(viewport.isFollowHighlight());
236     showGroupConsensus.setState(viewport.isShowGroupConsensus());
237     showGroupConservation.setState(viewport.isShowGroupConservation());
238     showConsensusHistogram.setState(viewport.isShowConsensusHistogram());
239     showSequenceLogo.setState(viewport.isShowSequenceLogo());
240     normSequenceLogo.setState(viewport.isNormaliseSequenceLogo());
241     applyToAllGroups.setState(viewport.getColourAppliesToAllGroups());
242     annotationPanelMenuItem.setState(viewport.isShowAnnotation());
243     showAlignmentAnnotations.setEnabled(annotationPanelMenuItem.getState());
244     showSequenceAnnotations.setEnabled(annotationPanelMenuItem.getState());
245     showAlignmentAnnotations.setState(true);
246     showSequenceAnnotations.setState(false);
247
248     seqLimits.setState(viewport.getShowJVSuffix());
249
250     if (applet != null)
251     {
252       String param = applet.getParameter("sortBy");
253       if (param != null)
254       {
255         if (param.equalsIgnoreCase("Id"))
256         {
257           sortIDMenuItem_actionPerformed();
258         }
259         else if (param.equalsIgnoreCase("Pairwise Identity"))
260         {
261           sortPairwiseMenuItem_actionPerformed();
262         }
263         else if (param.equalsIgnoreCase("Length"))
264         {
265           sortLengthMenuItem_actionPerformed();
266         }
267       }
268
269       param = applet.getParameter("wrap");
270       if (param != null)
271       {
272         if (param.equalsIgnoreCase("true"))
273         {
274           wrapMenuItem.setState(true);
275           wrapMenuItem_actionPerformed();
276         }
277       }
278       param = applet.getParameter("centrecolumnlabels");
279       if (param != null)
280       {
281         centreColumnLabelFlag.setState(true);
282         centreColumnLabelFlag_stateChanged();
283       }
284
285     }
286     if (viewport.getAlignment().isNucleotide())
287     {
288       conservationMenuItem.setEnabled(false);
289       clustalColour.setEnabled(false);
290       BLOSUM62Colour.setEnabled(false);
291       zappoColour.setEnabled(false);
292       taylorColour.setEnabled(false);
293       hydrophobicityColour.setEnabled(false);
294       helixColour.setEnabled(false);
295       strandColour.setEnabled(false);
296       turnColour.setEnabled(false);
297       buriedColour.setEnabled(false);
298       viewport.updateStrucConsensus(alignPanel);
299       if (viewport.getAlignment().hasRNAStructure())
300       {
301         RNAHelixColour.setEnabled(true);
302       }
303       else
304       {
305         RNAHelixColour.setEnabled(false);
306       }
307     }
308     else
309     {
310       RNAHelixColour.setEnabled(false);
311       purinePyrimidineColour.setEnabled(false);
312       nucleotideColour.setEnabled(false);
313     }
314     // Some JVMS send keyevents to Top frame or lowest panel,
315     // Havent worked out why yet. So add to both this frame and seqCanvas for
316     // now
317     this.addKeyListener(this);
318     alignPanel.seqPanel.seqCanvas.addKeyListener(this);
319     alignPanel.idPanel.idCanvas.addKeyListener(this);
320     alignPanel.scalePanel.addKeyListener(this);
321     alignPanel.annotationPanel.addKeyListener(this);
322     alignPanel.annotationPanelHolder.addKeyListener(this);
323     alignPanel.annotationSpaceFillerHolder.addKeyListener(this);
324     alignPanel.alabels.addKeyListener(this);
325
326     setAnnotationsVisibility();
327
328     if (addToDisplay)
329     {
330       addToDisplay(embedded);
331     }
332   }
333
334   /**
335    * @param embedded
336    */
337   public void addToDisplay(boolean embedded)
338   {
339     createAlignFrameWindow(embedded);
340     validate();
341     alignPanel.adjustAnnotationHeight();
342     alignPanel.paintAlignment(true);
343   }
344
345   public AlignViewport getAlignViewport()
346   {
347     return viewport;
348   }
349
350   public SeqCanvas getSeqcanvas()
351   {
352     return alignPanel.seqPanel.seqCanvas;
353   }
354
355   /**
356    * Load a features file onto the alignment
357    * 
358    * @param file
359    *          file URL, content, or other resolvable path
360    * @param type
361    *          is protocol for accessing data referred to by file
362    */
363
364   public boolean parseFeaturesFile(String file, DataSourceType type)
365   {
366     return parseFeaturesFile(file, type, true);
367   }
368
369   /**
370    * Load a features file onto the alignment
371    * 
372    * @param file
373    *          file URL, content, or other resolvable path
374    * @param sourceType
375    *          is protocol for accessing data referred to by file
376    * @param autoenabledisplay
377    *          when true, display features flag will be automatically enabled if
378    *          features are loaded
379    * @return true if data parsed as a features file
380    */
381   public boolean parseFeaturesFile(String file, DataSourceType sourceType,
382           boolean autoenabledisplay)
383   {
384     boolean featuresFile = false;
385     try
386     {
387       Map<String, FeatureColourI> colours = alignPanel.seqPanel.seqCanvas
388               .getFeatureRenderer().getFeatureColours();
389       boolean relaxedIdMatching = viewport.applet.getDefaultParameter(
390               "relaxedidmatch", false);
391       featuresFile = new FeaturesFile(file, sourceType).parse(
392               viewport.getAlignment(), colours, true, relaxedIdMatching);
393     } catch (Exception ex)
394     {
395       ex.printStackTrace();
396     }
397
398     if (featuresFile)
399     {
400       if (autoenabledisplay)
401       {
402         viewport.setShowSequenceFeatures(true);
403         sequenceFeatures.setState(true);
404       }
405       if (alignPanel.seqPanel.seqCanvas.fr != null)
406       {
407         // update the min/max ranges where necessary
408         alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
409       }
410       if (viewport.featureSettings != null)
411       {
412         viewport.featureSettings.refreshTable();
413       }
414       alignPanel.paintAlignment(true);
415       statusBar.setText(MessageManager
416               .getString("label.successfully_added_features_alignment"));
417     }
418     return featuresFile;
419   }
420
421   @Override
422   public void keyPressed(KeyEvent evt)
423   {
424     if (viewport.cursorMode
425             && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
426                     .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
427                     .getKeyCode() <= KeyEvent.VK_NUMPAD9))
428             && Character.isDigit(evt.getKeyChar()))
429     {
430       alignPanel.seqPanel.numberPressed(evt.getKeyChar());
431     }
432
433     switch (evt.getKeyCode())
434     {
435     case 27: // escape key
436       deselectAllSequenceMenuItem_actionPerformed();
437
438       alignPanel.alabels.cancelDrag();
439       break;
440     case KeyEvent.VK_X:
441       if (evt.isControlDown() || evt.isMetaDown())
442       {
443         cut_actionPerformed();
444       }
445       break;
446     case KeyEvent.VK_C:
447       if (viewport.cursorMode && !evt.isControlDown())
448       {
449         alignPanel.seqPanel.setCursorColumn();
450       }
451       if (evt.isControlDown() || evt.isMetaDown())
452       {
453         copy_actionPerformed();
454       }
455       break;
456     case KeyEvent.VK_V:
457       if (evt.isControlDown())
458       {
459         paste(evt.isShiftDown());
460       }
461       break;
462     case KeyEvent.VK_A:
463       if (evt.isControlDown() || evt.isMetaDown())
464       {
465         selectAllSequenceMenuItem_actionPerformed();
466       }
467       break;
468     case KeyEvent.VK_DOWN:
469       if (viewport.cursorMode)
470       {
471         alignPanel.seqPanel.moveCursor(0, 1);
472       }
473       else
474       {
475         moveSelectedSequences(false);
476       }
477       break;
478
479     case KeyEvent.VK_UP:
480       if (viewport.cursorMode)
481       {
482         alignPanel.seqPanel.moveCursor(0, -1);
483       }
484       else
485       {
486         moveSelectedSequences(true);
487       }
488       break;
489
490     case KeyEvent.VK_LEFT:
491       if (evt.isAltDown() || !viewport.cursorMode)
492       {
493         slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
494       }
495       else
496       {
497         alignPanel.seqPanel.moveCursor(-1, 0);
498       }
499       break;
500
501     case KeyEvent.VK_RIGHT:
502       if (evt.isAltDown() || !viewport.cursorMode)
503       {
504         slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
505       }
506       else
507       {
508         alignPanel.seqPanel.moveCursor(1, 0);
509       }
510       break;
511
512     case KeyEvent.VK_SPACE:
513       if (viewport.cursorMode)
514       {
515         alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
516                 || evt.isShiftDown() || evt.isAltDown());
517       }
518       break;
519
520     case KeyEvent.VK_DELETE:
521     case KeyEvent.VK_BACK_SPACE:
522       if (viewport.cursorMode)
523       {
524         alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
525                 || evt.isShiftDown() || evt.isAltDown());
526       }
527       else
528       {
529         cut_actionPerformed();
530         alignPanel.seqPanel.seqCanvas.repaint();
531       }
532       break;
533
534     case KeyEvent.VK_S:
535       if (viewport.cursorMode)
536       {
537         alignPanel.seqPanel.setCursorRow();
538       }
539       break;
540     case KeyEvent.VK_P:
541       if (viewport.cursorMode)
542       {
543         alignPanel.seqPanel.setCursorPosition();
544       }
545       break;
546
547     case KeyEvent.VK_ENTER:
548     case KeyEvent.VK_COMMA:
549       if (viewport.cursorMode)
550       {
551         alignPanel.seqPanel.setCursorRowAndColumn();
552       }
553       break;
554
555     case KeyEvent.VK_Q:
556       if (viewport.cursorMode)
557       {
558         alignPanel.seqPanel.setSelectionAreaAtCursor(true);
559       }
560       break;
561     case KeyEvent.VK_M:
562       if (viewport.cursorMode)
563       {
564         alignPanel.seqPanel.setSelectionAreaAtCursor(false);
565       }
566       break;
567
568     case KeyEvent.VK_F2:
569       viewport.cursorMode = !viewport.cursorMode;
570       statusBar.setText(MessageManager.formatMessage(
571               "label.keyboard_editing_mode",
572               new String[] { (viewport.cursorMode ? "on" : "off") }));
573       if (viewport.cursorMode)
574       {
575         alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
576         alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
577       }
578       break;
579
580     case KeyEvent.VK_F:
581       if (evt.isControlDown())
582       {
583         findMenuItem_actionPerformed();
584       }
585       break;
586
587     case KeyEvent.VK_H:
588     {
589       boolean toggleSeqs = !evt.isControlDown();
590       boolean toggleCols = !evt.isShiftDown();
591       toggleHiddenRegions(toggleSeqs, toggleCols);
592       break;
593     }
594
595     case KeyEvent.VK_PAGE_UP:
596       if (viewport.getWrapAlignment())
597       {
598         alignPanel.scrollUp(true);
599       }
600       else
601       {
602         alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
603                 - viewport.endSeq + viewport.startSeq);
604       }
605       break;
606
607     case KeyEvent.VK_PAGE_DOWN:
608       if (viewport.getWrapAlignment())
609       {
610         alignPanel.scrollUp(false);
611       }
612       else
613       {
614         alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
615                 + viewport.endSeq - viewport.startSeq);
616       }
617       break;
618
619     case KeyEvent.VK_Z:
620       if (evt.isControlDown())
621       {
622         undoMenuItem_actionPerformed();
623       }
624       break;
625
626     case KeyEvent.VK_Y:
627       if (evt.isControlDown())
628       {
629         redoMenuItem_actionPerformed();
630       }
631       break;
632
633     case KeyEvent.VK_L:
634       if (evt.isControlDown())
635       {
636         trimAlignment(true);
637       }
638       break;
639
640     case KeyEvent.VK_R:
641       if (evt.isControlDown())
642       {
643         trimAlignment(false);
644       }
645       break;
646
647     case KeyEvent.VK_E:
648       if (evt.isControlDown())
649       {
650         if (evt.isShiftDown())
651         {
652           this.removeAllGapsMenuItem_actionPerformed();
653         }
654         else
655         {
656           removeGappedColumnMenuItem_actionPerformed();
657         }
658       }
659       break;
660     case KeyEvent.VK_I:
661       if (evt.isControlDown())
662       {
663         if (evt.isAltDown())
664         {
665           invertColSel_actionPerformed();
666         }
667         else
668         {
669           invertSequenceMenuItem_actionPerformed();
670         }
671       }
672       break;
673
674     case KeyEvent.VK_G:
675       if (evt.isControlDown())
676       {
677         if (evt.isShiftDown())
678         {
679           this.unGroup_actionPerformed();
680         }
681         else
682         {
683           this.createGroup_actionPerformed();
684         }
685       }
686       break;
687
688     case KeyEvent.VK_U:
689       if (evt.isControlDown())
690       {
691         this.deleteGroups_actionPerformed();
692       }
693       break;
694
695     case KeyEvent.VK_T:
696       if (evt.isControlDown())
697       {
698         newView(null);
699       }
700       break;
701
702     }
703     alignPanel.paintAlignment(true);
704   }
705
706   /**
707    * called by key handler and the hide all/show all menu items
708    * 
709    * @param toggleSeqs
710    * @param toggleCols
711    */
712   private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
713   {
714     boolean hide = false;
715     SequenceGroup sg = viewport.getSelectionGroup();
716     if (!toggleSeqs && !toggleCols)
717     {
718       // Hide everything by the current selection - this is a hack - we do the
719       // invert and then hide
720       // first check that there will be visible columns after the invert.
721       if (viewport.hasSelectedColumns()
722               || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
723                       .getEndRes()))
724       {
725         // now invert the sequence set, if required - empty selection implies
726         // that no hiding is required.
727         if (sg != null)
728         {
729           invertSequenceMenuItem_actionPerformed();
730           sg = viewport.getSelectionGroup();
731           toggleSeqs = true;
732
733         }
734         viewport.expandColSelection(sg, true);
735         // finally invert the column selection and get the new sequence
736         // selection and indicate it should be hidden.
737         invertColSel_actionPerformed();
738         toggleCols = true;
739       }
740     }
741
742     if (toggleSeqs)
743     {
744       if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
745       {
746         hide = true;
747         viewport.hideAllSelectedSeqs();
748       }
749       else if (!(toggleCols && viewport.hasSelectedColumns()))
750       {
751         viewport.showAllHiddenSeqs();
752       }
753     }
754
755     if (toggleCols)
756     {
757       if (viewport.hasSelectedColumns())
758       {
759         viewport.hideSelectedColumns();
760         if (!toggleSeqs)
761         {
762           viewport.setSelectionGroup(sg);
763         }
764       }
765       else if (!hide)
766       {
767         viewport.showAllHiddenColumns();
768       }
769       viewport.sendSelection();
770     }
771   }
772
773   @Override
774   public void keyReleased(KeyEvent evt)
775   {
776   }
777
778   @Override
779   public void keyTyped(KeyEvent evt)
780   {
781   }
782
783   @Override
784   public void itemStateChanged(ItemEvent evt)
785   {
786     final Object source = evt.getSource();
787     if (source == displayNonconservedMenuItem)
788     {
789       displayNonconservedMenuItem_actionPerformed();
790     }
791     else if (source == colourTextMenuItem)
792     {
793       colourTextMenuItem_actionPerformed();
794     }
795     else if (source == wrapMenuItem)
796     {
797       wrapMenuItem_actionPerformed();
798     }
799     else if (source == scaleAbove)
800     {
801       viewport.setScaleAboveWrapped(scaleAbove.getState());
802     }
803     else if (source == scaleLeft)
804     {
805       viewport.setScaleLeftWrapped(scaleLeft.getState());
806     }
807     else if (source == scaleRight)
808     {
809       viewport.setScaleRightWrapped(scaleRight.getState());
810     }
811     else if (source == seqLimits)
812     {
813       seqLimits_itemStateChanged();
814     }
815     else if (source == viewBoxesMenuItem)
816     {
817       viewport.setShowBoxes(viewBoxesMenuItem.getState());
818     }
819     else if (source == viewTextMenuItem)
820     {
821       viewport.setShowText(viewTextMenuItem.getState());
822     }
823     else if (source == renderGapsMenuItem)
824     {
825       viewport.setRenderGaps(renderGapsMenuItem.getState());
826     }
827     else if (source == annotationPanelMenuItem)
828     {
829       boolean showAnnotations = annotationPanelMenuItem.getState();
830       showAlignmentAnnotations.setEnabled(showAnnotations);
831       showSequenceAnnotations.setEnabled(showAnnotations);
832       viewport.setShowAnnotation(showAnnotations);
833       alignPanel.setAnnotationVisible(showAnnotations);
834     }
835     else if (source == sequenceFeatures)
836     {
837       viewport.setShowSequenceFeatures(sequenceFeatures.getState());
838       alignPanel.seqPanel.seqCanvas.repaint();
839     }
840     else if (source == showAlignmentAnnotations)
841     {
842       setAnnotationsVisibility();
843     }
844     else if (source == showSequenceAnnotations)
845     {
846       setAnnotationsVisibility();
847     }
848     else if (source == sortAnnBySequence)
849     {
850       boolean newState = sortAnnBySequence.getState();
851       sortAnnByLabel.setState(false);
852       setAnnotationSortOrder(newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
853               : SequenceAnnotationOrder.NONE);
854       setViewportAnnotationOrder();
855     }
856     else if (source == sortAnnByLabel)
857     {
858       boolean newState = sortAnnByLabel.getState();
859       sortAnnBySequence.setState(false);
860       setAnnotationSortOrder(newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
861               : SequenceAnnotationOrder.NONE);
862       setViewportAnnotationOrder();
863     }
864     else if (source == showAutoFirst)
865     {
866       showAutoLast.setState(!showAutoFirst.getState());
867       setShowAutoCalculatedAbove(showAutoFirst.getState());
868       setViewportAnnotationOrder();
869     }
870     else if (source == showAutoLast)
871     {
872       showAutoFirst.setState(!showAutoLast.getState());
873       setShowAutoCalculatedAbove(showAutoFirst.getState());
874       setViewportAnnotationOrder();
875     }
876     else if (source == conservationMenuItem)
877     {
878       conservationMenuItem_actionPerformed();
879     }
880     else if (source == abovePIDThreshold)
881     {
882       abovePIDThreshold_actionPerformed();
883     }
884     else if (source == applyToAllGroups)
885     {
886       viewport.setColourAppliesToAllGroups(applyToAllGroups.getState());
887     }
888     else if (source == autoCalculate)
889     {
890       viewport.autoCalculateConsensus = autoCalculate.getState();
891     }
892     else if (source == sortByTree)
893     {
894       viewport.sortByTree = sortByTree.getState();
895     }
896     else if (source == this.centreColumnLabelFlag)
897     {
898       centreColumnLabelFlag_stateChanged();
899     }
900     else if (source == this.followMouseOverFlag)
901     {
902       mouseOverFlag_stateChanged();
903     }
904     else if (source == showGroupConsensus)
905     {
906       showGroupConsensus_actionPerformed();
907     }
908     else if (source == showGroupConservation)
909     {
910       showGroupConservation_actionPerformed();
911     }
912     else if (source == showSequenceLogo)
913     {
914       showSequenceLogo_actionPerformed();
915     }
916     else if (source == normSequenceLogo)
917     {
918       normSequenceLogo_actionPerformed();
919     }
920     else if (source == showConsensusHistogram)
921     {
922       showConsensusHistogram_actionPerformed();
923     }
924     else if (source == applyAutoAnnotationSettings)
925     {
926       applyAutoAnnotationSettings_actionPerformed();
927     }
928     alignPanel.paintAlignment(true);
929   }
930
931   /**
932    * Set the visibility state of sequence-related and/or alignment-related
933    * annotations depending on checkbox selections, and repaint.
934    * 
935    * @param visible
936    */
937   private void setAnnotationsVisibility()
938   {
939     boolean showForAlignment = showAlignmentAnnotations.getState();
940     boolean showForSequences = showSequenceAnnotations.getState();
941     if (alignPanel.getAlignment().getAlignmentAnnotation() != null)
942     {
943       for (AlignmentAnnotation aa : alignPanel.getAlignment()
944               .getAlignmentAnnotation())
945       {
946         boolean visible = (aa.sequenceRef == null ? showForAlignment
947                 : showForSequences);
948         aa.visible = visible;
949       }
950     }
951     alignPanel.validateAnnotationDimensions(true);
952     validate();
953     repaint();
954   }
955
956   private void setAnnotationSortOrder(SequenceAnnotationOrder order)
957   {
958     this.annotationSortOrder = order;
959   }
960
961   /**
962    * Set flags on the viewport that control annotation ordering
963    */
964   private void setViewportAnnotationOrder()
965   {
966     this.alignPanel.av.setSortAnnotationsBy(this.annotationSortOrder);
967     this.alignPanel.av
968             .setShowAutocalculatedAbove(this.showAutoCalculatedAbove);
969   }
970
971   private void setShowAutoCalculatedAbove(boolean showAbove)
972   {
973     this.showAutoCalculatedAbove = showAbove;
974   }
975
976   private void mouseOverFlag_stateChanged()
977   {
978     viewport.setFollowHighlight(followMouseOverFlag.getState());
979     // TODO: could kick the scrollTo mechanism to reset view for current
980     // searchresults.
981   }
982
983   private void centreColumnLabelFlag_stateChanged()
984   {
985     viewport.centreColumnLabels = centreColumnLabelFlag.getState();
986     this.alignPanel.annotationPanel.repaint();
987   }
988
989   @Override
990   public void actionPerformed(ActionEvent evt)
991   {
992     viewport.applet.currentAlignFrame = this;
993
994     Object source = evt.getSource();
995
996     if (source == inputText)
997     {
998       inputText_actionPerformed();
999     }
1000     else if (source == loadTree)
1001     {
1002       loadTree_actionPerformed();
1003     }
1004     else if (source == loadApplication)
1005     {
1006       launchFullApplication();
1007     }
1008     else if (source == loadAnnotations)
1009     {
1010       loadAnnotations();
1011     }
1012     else if (source == outputAnnotations)
1013     {
1014       outputAnnotations(true);
1015     }
1016     else if (source == outputFeatures)
1017     {
1018       outputFeatures(true, "Jalview");
1019     }
1020     else if (source == closeMenuItem)
1021     {
1022       closeMenuItem_actionPerformed();
1023     }
1024     else if (source == copy)
1025     {
1026       copy_actionPerformed();
1027     }
1028     else if (source == undoMenuItem)
1029     {
1030       undoMenuItem_actionPerformed();
1031     }
1032     else if (source == redoMenuItem)
1033     {
1034       redoMenuItem_actionPerformed();
1035     }
1036     else if (source == inputText)
1037     {
1038       inputText_actionPerformed();
1039     }
1040     else if (source == closeMenuItem)
1041     {
1042       closeMenuItem_actionPerformed();
1043     }
1044     else if (source == undoMenuItem)
1045     {
1046       undoMenuItem_actionPerformed();
1047     }
1048     else if (source == redoMenuItem)
1049     {
1050       redoMenuItem_actionPerformed();
1051     }
1052     else if (source == copy)
1053     {
1054       copy_actionPerformed();
1055     }
1056     else if (source == pasteNew)
1057     {
1058       pasteNew_actionPerformed();
1059     }
1060     else if (source == pasteThis)
1061     {
1062       pasteThis_actionPerformed();
1063     }
1064     else if (source == cut)
1065     {
1066       cut_actionPerformed();
1067     }
1068     else if (source == delete)
1069     {
1070       delete_actionPerformed();
1071     }
1072     else if (source == grpsFromSelection)
1073     {
1074       makeGrpsFromSelection_actionPerformed();
1075     }
1076     else if (source == deleteGroups)
1077     {
1078       deleteGroups_actionPerformed();
1079     }
1080     else if (source == selectAllSequenceMenuItem)
1081     {
1082       selectAllSequenceMenuItem_actionPerformed();
1083     }
1084     else if (source == deselectAllSequenceMenuItem)
1085     {
1086       deselectAllSequenceMenuItem_actionPerformed();
1087     }
1088     else if (source == invertSequenceMenuItem)
1089     {
1090       invertSequenceMenuItem_actionPerformed();
1091       // uncomment to slave sequence selections in split frame
1092       // viewport.sendSelection();
1093     }
1094     else if (source == invertColSel)
1095     {
1096       viewport.invertColumnSelection();
1097       alignPanel.paintAlignment(true);
1098       viewport.sendSelection();
1099     }
1100     else if (source == remove2LeftMenuItem)
1101     {
1102       trimAlignment(true);
1103     }
1104     else if (source == remove2RightMenuItem)
1105     {
1106       trimAlignment(false);
1107     }
1108     else if (source == removeGappedColumnMenuItem)
1109     {
1110       removeGappedColumnMenuItem_actionPerformed();
1111     }
1112     else if (source == removeAllGapsMenuItem)
1113     {
1114       removeAllGapsMenuItem_actionPerformed();
1115     }
1116     else if (source == findMenuItem)
1117     {
1118       findMenuItem_actionPerformed();
1119     }
1120     else if (source == font)
1121     {
1122       new FontChooser(alignPanel);
1123     }
1124     else if (source == newView)
1125     {
1126       newView(null);
1127     }
1128     else if (source == showColumns)
1129     {
1130       viewport.showAllHiddenColumns();
1131       alignPanel.paintAlignment(true);
1132       viewport.sendSelection();
1133     }
1134     else if (source == showSeqs)
1135     {
1136       viewport.showAllHiddenSeqs();
1137       alignPanel.paintAlignment(true);
1138       // uncomment if we want to slave sequence selections in split frame
1139       // viewport.sendSelection();
1140     }
1141     else if (source == hideColumns)
1142     {
1143       viewport.hideSelectedColumns();
1144       alignPanel.paintAlignment(true);
1145       viewport.sendSelection();
1146     }
1147     else if (source == hideSequences
1148             && viewport.getSelectionGroup() != null)
1149     {
1150       viewport.hideAllSelectedSeqs();
1151       alignPanel.paintAlignment(true);
1152       // uncomment if we want to slave sequence selections in split frame
1153       // viewport.sendSelection();
1154     }
1155     else if (source == hideAllButSelection)
1156     {
1157       toggleHiddenRegions(false, false);
1158       alignPanel.paintAlignment(true);
1159       viewport.sendSelection();
1160     }
1161     else if (source == hideAllSelection)
1162     {
1163       SequenceGroup sg = viewport.getSelectionGroup();
1164       viewport.expandColSelection(sg, false);
1165       viewport.hideAllSelectedSeqs();
1166       viewport.hideSelectedColumns();
1167       alignPanel.paintAlignment(true);
1168       viewport.sendSelection();
1169     }
1170     else if (source == showAllHidden)
1171     {
1172       viewport.showAllHiddenColumns();
1173       viewport.showAllHiddenSeqs();
1174       alignPanel.paintAlignment(true);
1175       viewport.sendSelection();
1176     }
1177     else if (source == showGroupConsensus)
1178     {
1179       showGroupConsensus_actionPerformed();
1180     }
1181     else if (source == showGroupConservation)
1182     {
1183       showGroupConservation_actionPerformed();
1184     }
1185     else if (source == showSequenceLogo)
1186     {
1187       showSequenceLogo_actionPerformed();
1188     }
1189     else if (source == normSequenceLogo)
1190     {
1191       normSequenceLogo_actionPerformed();
1192     }
1193     else if (source == showConsensusHistogram)
1194     {
1195       showConsensusHistogram_actionPerformed();
1196     }
1197     else if (source == applyAutoAnnotationSettings)
1198     {
1199       applyAutoAnnotationSettings_actionPerformed();
1200     }
1201     else if (source == featureSettings)
1202     {
1203       new FeatureSettings(alignPanel);
1204     }
1205     else if (source == alProperties)
1206     {
1207       StringBuffer contents = new jalview.io.AlignmentProperties(
1208               viewport.getAlignment()).formatAsString();
1209       CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1210       cap.setText(contents.toString());
1211       Frame frame = new Frame();
1212       frame.add(cap);
1213       jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
1214               "label.alignment_properties", new String[] { getTitle() }),
1215               400, 250);
1216     }
1217     else if (source == overviewMenuItem)
1218     {
1219       overviewMenuItem_actionPerformed();
1220     }
1221     else if (source == noColourmenuItem)
1222     {
1223       changeColour(null);
1224     }
1225     else if (source == clustalColour)
1226     {
1227       abovePIDThreshold.setState(false);
1228       changeColour(new ClustalxColourScheme(viewport.getAlignment(), null));
1229     }
1230     else if (source == zappoColour)
1231     {
1232       changeColour(new ZappoColourScheme());
1233     }
1234     else if (source == taylorColour)
1235     {
1236       changeColour(new TaylorColourScheme());
1237     }
1238     else if (source == hydrophobicityColour)
1239     {
1240       changeColour(new HydrophobicColourScheme());
1241     }
1242     else if (source == helixColour)
1243     {
1244       changeColour(new HelixColourScheme());
1245     }
1246     else if (source == strandColour)
1247     {
1248       changeColour(new StrandColourScheme());
1249     }
1250     else if (source == turnColour)
1251     {
1252       changeColour(new TurnColourScheme());
1253     }
1254     else if (source == buriedColour)
1255     {
1256       changeColour(new BuriedColourScheme());
1257     }
1258     else if (source == nucleotideColour)
1259     {
1260       changeColour(new NucleotideColourScheme());
1261     }
1262     else if (source == purinePyrimidineColour)
1263     {
1264       changeColour(new PurinePyrimidineColourScheme());
1265     }
1266     // else if (source == RNAInteractionColour)
1267     // {
1268     // changeColour(new RNAInteractionColourScheme());
1269     // }
1270     else if (source == RNAHelixColour)
1271     {
1272       changeColour(new RNAHelicesColour(viewport.getAlignment()));
1273       // new RNAHelicesColourChooser(viewport, alignPanel);
1274     }
1275     else if (source == modifyPID)
1276     {
1277       modifyPID_actionPerformed();
1278     }
1279     else if (source == modifyConservation)
1280     {
1281       modifyConservation_actionPerformed();
1282     }
1283     else if (source == userDefinedColour)
1284     {
1285       new UserDefinedColours(alignPanel, null);
1286     }
1287     else if (source == PIDColour)
1288     {
1289       changeColour(new PIDColourScheme());
1290     }
1291     else if (source == BLOSUM62Colour)
1292     {
1293       changeColour(new Blosum62ColourScheme());
1294     }
1295     else if (source == tcoffeeColour)
1296     {
1297       changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
1298     }
1299     else if (source == annotationColour)
1300     {
1301       new AnnotationColourChooser(viewport, alignPanel);
1302     }
1303     else if (source == annotationColumnSelection)
1304     {
1305       new AnnotationColumnChooser(viewport, alignPanel);
1306     }
1307     else if (source == sortPairwiseMenuItem)
1308     {
1309       sortPairwiseMenuItem_actionPerformed();
1310     }
1311     else if (source == sortIDMenuItem)
1312     {
1313       sortIDMenuItem_actionPerformed();
1314     }
1315     else if (source == sortLengthMenuItem)
1316     {
1317       sortLengthMenuItem_actionPerformed();
1318     }
1319     else if (source == sortGroupMenuItem)
1320     {
1321       sortGroupMenuItem_actionPerformed();
1322     }
1323     else if (source == removeRedundancyMenuItem)
1324     {
1325       removeRedundancyMenuItem_actionPerformed();
1326     }
1327     else if (source == pairwiseAlignmentMenuItem)
1328     {
1329       pairwiseAlignmentMenuItem_actionPerformed();
1330     }
1331     else if (source == PCAMenuItem)
1332     {
1333       PCAMenuItem_actionPerformed();
1334     }
1335     else if (source == averageDistanceTreeMenuItem)
1336     {
1337       averageDistanceTreeMenuItem_actionPerformed();
1338     }
1339     else if (source == neighbourTreeMenuItem)
1340     {
1341       neighbourTreeMenuItem_actionPerformed();
1342     }
1343     else if (source == njTreeBlosumMenuItem)
1344     {
1345       njTreeBlosumMenuItem_actionPerformed();
1346     }
1347     else if (source == avDistanceTreeBlosumMenuItem)
1348     {
1349       avTreeBlosumMenuItem_actionPerformed();
1350     }
1351     else if (source == documentation)
1352     {
1353       documentation_actionPerformed();
1354     }
1355     else if (source == about)
1356     {
1357       about_actionPerformed();
1358     }
1359
1360   }
1361
1362   public void inputText_actionPerformed()
1363   {
1364     CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1365     Frame frame = new Frame();
1366     frame.add(cap);
1367     jalview.bin.JalviewLite.addFrame(frame,
1368             MessageManager.getString("label.input_cut_paste"), 500, 500);
1369   }
1370
1371   protected void outputText_actionPerformed(ActionEvent e)
1372   {
1373     CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1374     Frame frame = new Frame();
1375     frame.add(cap);
1376     JalviewLite.addFrame(frame, MessageManager.formatMessage(
1377             "label.alignment_output_command",
1378             new Object[] { e.getActionCommand() }), 600, 500);
1379
1380     FileFormatI fileFormat = FileFormats.getInstance().forName(
1381             e.getActionCommand());
1382     cap.setText(new AppletFormatAdapter(alignPanel).formatSequences(
1383             fileFormat, viewport.getAlignment(),
1384             viewport.getShowJVSuffix()));
1385   }
1386
1387   public void loadAnnotations()
1388   {
1389     CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1390     cap.setText(MessageManager
1391             .getString("label.paste_features_annotations_Tcoffee_here"));
1392     cap.setAnnotationImport();
1393     Frame frame = new Frame();
1394     frame.add(cap);
1395     jalview.bin.JalviewLite.addFrame(frame,
1396             MessageManager.getString("action.paste_annotations"), 400, 300);
1397
1398   }
1399
1400   public String outputAnnotations(boolean displayTextbox)
1401   {
1402     String annotation = new AnnotationFile()
1403             .printAnnotationsForView(viewport);
1404
1405     if (displayTextbox)
1406     {
1407       CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1408       Frame frame = new Frame();
1409       frame.add(cap);
1410       jalview.bin.JalviewLite.addFrame(frame,
1411               MessageManager.getString("label.annotations"), 600, 500);
1412       cap.setText(annotation);
1413     }
1414
1415     return annotation;
1416   }
1417
1418   private Map<String, FeatureColourI> getDisplayedFeatureCols()
1419   {
1420     if (alignPanel.getFeatureRenderer() != null
1421             && viewport.getFeaturesDisplayed() != null)
1422     {
1423       return alignPanel.getFeatureRenderer().getDisplayedFeatureCols();
1424
1425     }
1426     return null;
1427   }
1428
1429   public String outputFeatures(boolean displayTextbox, String format)
1430   {
1431     String features;
1432     FeaturesFile formatter = new FeaturesFile();
1433     if (format.equalsIgnoreCase("Jalview"))
1434     {
1435       features = formatter.printJalviewFormat(viewport.getAlignment()
1436               .getSequencesArray(), getDisplayedFeatureCols());
1437     }
1438     else
1439     {
1440       features = formatter.printGffFormat(viewport.getAlignment()
1441               .getSequencesArray(), getDisplayedFeatureCols());
1442     }
1443
1444     if (displayTextbox)
1445     {
1446       boolean frimport = false;
1447       if (features == null || features.equals("No Features Visible"))
1448       {
1449         features = "# No features visible - paste some and import them here.";
1450         frimport = true;
1451       }
1452
1453       CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this);
1454       if (frimport)
1455       {
1456         cap.setAnnotationImport();
1457       }
1458       Frame frame = new Frame();
1459       frame.add(cap);
1460       jalview.bin.JalviewLite.addFrame(frame,
1461               MessageManager.getString("label.features"), 600, 500);
1462       cap.setText(features);
1463     }
1464     else
1465     {
1466       if (features == null)
1467       {
1468         features = "";
1469       }
1470     }
1471
1472     return features;
1473   }
1474
1475   void launchFullApplication()
1476   {
1477     StringBuffer url = new StringBuffer(jalviewServletURL);
1478
1479     // allow servlet parameters to be passed in applet parameter
1480     String firstSep = url.lastIndexOf("?") > url.lastIndexOf("/") ? "&"
1481             : "?";
1482     url.append(firstSep);
1483
1484     url.append("open="
1485             + appendProtocol(viewport.applet.getParameter("file")));
1486
1487     if (viewport.applet.getParameter("features") != null)
1488     {
1489       url.append("&features=");
1490       url.append(appendProtocol(viewport.applet.getParameter("features")));
1491     }
1492
1493     if (viewport.applet.getParameter("annotations") != null)
1494     {
1495       url.append("&annotations=");
1496       url.append(appendProtocol(viewport.applet.getParameter("annotations")));
1497     }
1498
1499     if (viewport.applet.getParameter("jnetfile") != null
1500             || viewport.applet.getParameter("jpredfile") != null)
1501     {
1502       url.append("&annotations=");
1503       url.append(appendProtocol(viewport.applet.getParameter("jnetfile") != null ? viewport.applet
1504               .getParameter("jnetfile") : viewport.applet
1505               .getParameter("jpredfile")));
1506     }
1507
1508     if (viewport.applet.getParameter("defaultColour") != null)
1509     {
1510       url.append("&colour="
1511               + removeWhiteSpace(viewport.applet
1512                       .getParameter("defaultColour")));
1513     }
1514
1515     if (viewport.applet.getParameter("userDefinedColour") != null)
1516     {
1517       url.append("&colour="
1518               + removeWhiteSpace(viewport.applet
1519                       .getParameter("userDefinedColour")));
1520     }
1521     if (viewport.applet.getParameter("tree") != null)
1522     {
1523       url.append("&tree="
1524               + appendProtocol(viewport.applet.getParameter("tree")));
1525     }
1526     if (viewport.applet.getParameter("treeFile") != null)
1527     {
1528       url.append("&tree="
1529               + appendProtocol(viewport.applet.getParameter("treeFile")));
1530     }
1531
1532     showURL(url.toString(), "FULL_APP");
1533   }
1534
1535   String removeWhiteSpace(String colour)
1536   {
1537     StringBuffer sb = new StringBuffer();
1538     for (int i = 0; i < colour.length(); i++)
1539     {
1540       if (Character.isWhitespace(colour.charAt(i)))
1541       {
1542         sb.append("%20");
1543       }
1544       else
1545       {
1546         sb.append(colour.charAt(i));
1547       }
1548     }
1549
1550     return sb.toString();
1551   }
1552
1553   String appendProtocol(String url)
1554   {
1555     try
1556     {
1557       new URL(url);
1558       url = URLEncoder.encode(url);
1559     }
1560     /*
1561      * When we finally deprecate 1.1 compatibility, we can start to use
1562      * URLEncoder.encode(url,"UTF-8") and then we'll need this catch: catch
1563      * (UnsupportedEncodingException ex) { System.err.println("WARNING -
1564      * IMPLEMENTATION ERROR - UNSUPPORTED ENCODING EXCEPTION FOR "+url);
1565      * ex.printStackTrace(); }
1566      */
1567     catch (java.net.MalformedURLException ex)
1568     {
1569       url = viewport.applet.getCodeBase() + url;
1570     }
1571     return url;
1572   }
1573
1574   public void closeMenuItem_actionPerformed()
1575   {
1576     PaintRefresher.RemoveComponent(alignPanel);
1577     if (alignPanel.seqPanel != null
1578             && alignPanel.seqPanel.seqCanvas != null)
1579     {
1580       PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1581     }
1582     if (alignPanel.idPanel != null && alignPanel.idPanel.idCanvas != null)
1583     {
1584       PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1585     }
1586
1587     if (PaintRefresher.components.size() == 0 && viewport.applet == null)
1588     {
1589       System.exit(0);
1590     }
1591     else
1592     {
1593     }
1594     viewport = null;
1595     alignPanel = null;
1596     this.dispose();
1597   }
1598
1599   /**
1600    * TODO: JAL-1104
1601    */
1602   void updateEditMenuBar()
1603   {
1604
1605     if (viewport.getHistoryList().size() > 0)
1606     {
1607       undoMenuItem.setEnabled(true);
1608       CommandI command = viewport.getHistoryList().peek();
1609       undoMenuItem.setLabel(MessageManager.formatMessage(
1610               "label.undo_command",
1611               new Object[] { command.getDescription() }));
1612     }
1613     else
1614     {
1615       undoMenuItem.setEnabled(false);
1616       undoMenuItem.setLabel(MessageManager.getString("action.undo"));
1617     }
1618
1619     if (viewport.getRedoList().size() > 0)
1620     {
1621       redoMenuItem.setEnabled(true);
1622
1623       CommandI command = viewport.getRedoList().peek();
1624       redoMenuItem.setLabel(MessageManager.formatMessage(
1625               "label.redo_command",
1626               new Object[] { command.getDescription() }));
1627     }
1628     else
1629     {
1630       redoMenuItem.setEnabled(false);
1631       redoMenuItem.setLabel(MessageManager.getString("action.redo"));
1632     }
1633   }
1634
1635   /**
1636    * TODO: JAL-1104
1637    */
1638   @Override
1639   public void addHistoryItem(CommandI command)
1640   {
1641     if (command.getSize() > 0)
1642     {
1643       viewport.addToHistoryList(command);
1644       viewport.clearRedoList();
1645       updateEditMenuBar();
1646       viewport.updateHiddenColumns();
1647     }
1648   }
1649
1650   /**
1651    * TODO: JAL-1104 DOCUMENT ME!
1652    * 
1653    * @param e
1654    *          DOCUMENT ME!
1655    */
1656   protected void undoMenuItem_actionPerformed()
1657   {
1658     if (viewport.getHistoryList().isEmpty())
1659     {
1660       return;
1661     }
1662
1663     CommandI command = viewport.getHistoryList().pop();
1664     viewport.addToRedoList(command);
1665     command.undoCommand(null);
1666
1667     AlignmentViewport originalSource = getOriginatingSource(command);
1668     // JBPNote Test
1669     if (originalSource != viewport)
1670     {
1671       System.err
1672               .println("Warning: Viewport object mismatch whilst undoing");
1673     }
1674     originalSource.updateHiddenColumns(); // originalSource.hasHiddenColumns =
1675                                           // viewport.getColumnSelection().getHiddenColumns()
1676                                           // != null;
1677     updateEditMenuBar();
1678     originalSource.firePropertyChange("alignment", null, originalSource
1679             .getAlignment().getSequences());
1680   }
1681
1682   /**
1683    * TODO: JAL-1104 DOCUMENT ME!
1684    * 
1685    * @param e
1686    *          DOCUMENT ME!
1687    */
1688   protected void redoMenuItem_actionPerformed()
1689   {
1690     if (viewport.getRedoList().isEmpty())
1691     {
1692       return;
1693     }
1694
1695     CommandI command = viewport.getRedoList().pop();
1696     viewport.addToHistoryList(command);
1697     command.doCommand(null);
1698
1699     AlignmentViewport originalSource = getOriginatingSource(command);
1700     // JBPNote Test
1701     if (originalSource != viewport)
1702     {
1703       System.err
1704               .println("Warning: Viewport object mismatch whilst re-doing");
1705     }
1706     originalSource.updateHiddenColumns(); // sethasHiddenColumns(); =
1707                                           // viewport.getColumnSelection().getHiddenColumns()
1708                                           // != null;
1709
1710     updateEditMenuBar();
1711     originalSource.firePropertyChange("alignment", null, originalSource
1712             .getAlignment().getSequences());
1713   }
1714
1715   AlignmentViewport getOriginatingSource(CommandI command)
1716   {
1717     AlignmentViewport originalSource = null;
1718     // For sequence removal and addition, we need to fire
1719     // the property change event FROM the viewport where the
1720     // original alignment was altered
1721     AlignmentI al = null;
1722     if (command instanceof EditCommand)
1723     {
1724       EditCommand editCommand = (EditCommand) command;
1725       al = editCommand.getAlignment();
1726       Vector comps = (Vector) PaintRefresher.components.get(viewport
1727               .getSequenceSetId());
1728       for (int i = 0; i < comps.size(); i++)
1729       {
1730         if (comps.elementAt(i) instanceof AlignmentPanel)
1731         {
1732           if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1733           {
1734             originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1735             break;
1736           }
1737         }
1738       }
1739     }
1740
1741     if (originalSource == null)
1742     {
1743       // The original view is closed, we must validate
1744       // the current view against the closed view first
1745       if (al != null)
1746       {
1747         PaintRefresher.validateSequences(al, viewport.getAlignment());
1748       }
1749
1750       originalSource = viewport;
1751     }
1752
1753     return originalSource;
1754   }
1755
1756   /**
1757    * Move the currently selected sequences up or down one position in the
1758    * alignment
1759    * 
1760    * @param up
1761    */
1762   public void moveSelectedSequences(boolean up)
1763   {
1764     SequenceGroup sg = viewport.getSelectionGroup();
1765     if (sg == null)
1766     {
1767       return;
1768     }
1769     viewport.getAlignment().moveSelectedSequencesByOne(sg,
1770             up ? null : viewport.getHiddenRepSequences(), up);
1771     alignPanel.paintAlignment(true);
1772
1773     /*
1774      * Also move cDNA/protein complement sequences
1775      */
1776     AlignViewportI complement = viewport.getCodingComplement();
1777     if (complement != null)
1778     {
1779       SequenceGroup mappedSelection = MappingUtils.mapSequenceGroup(sg,
1780               viewport, complement);
1781       complement.getAlignment().moveSelectedSequencesByOne(mappedSelection,
1782               up ? null : complement.getHiddenRepSequences(), up);
1783       getSplitFrame().getComplement(this).alignPanel.paintAlignment(true);
1784     }
1785   }
1786
1787   synchronized void slideSequences(boolean right, int size)
1788   {
1789     List<SequenceI> sg = new Vector<SequenceI>();
1790     if (viewport.cursorMode)
1791     {
1792       sg.add(viewport.getAlignment().getSequenceAt(
1793               alignPanel.seqPanel.seqCanvas.cursorY));
1794     }
1795     else if (viewport.getSelectionGroup() != null
1796             && viewport.getSelectionGroup().getSize() != viewport
1797                     .getAlignment().getHeight())
1798     {
1799       sg = viewport.getSelectionGroup().getSequences(
1800               viewport.getHiddenRepSequences());
1801     }
1802
1803     if (sg.size() < 1)
1804     {
1805       return;
1806     }
1807
1808     Vector<SequenceI> invertGroup = new Vector();
1809
1810     for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1811     {
1812       if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1813       {
1814         invertGroup.addElement(viewport.getAlignment().getSequenceAt(i));
1815       }
1816     }
1817
1818     SequenceI[] seqs1 = sg.toArray(new SequenceI[sg.size()]);
1819
1820     SequenceI[] seqs2 = invertGroup.toArray(new SequenceI[invertGroup
1821             .size()]);
1822     for (int i = 0; i < invertGroup.size(); i++)
1823     {
1824       seqs2[i] = invertGroup.elementAt(i);
1825     }
1826
1827     SlideSequencesCommand ssc;
1828     if (right)
1829     {
1830       ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1831               size, viewport.getGapCharacter());
1832     }
1833     else
1834     {
1835       ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1836               size, viewport.getGapCharacter());
1837     }
1838
1839     int groupAdjustment = 0;
1840     if (ssc.getGapsInsertedBegin() && right)
1841     {
1842       if (viewport.cursorMode)
1843       {
1844         alignPanel.seqPanel.moveCursor(size, 0);
1845       }
1846       else
1847       {
1848         groupAdjustment = size;
1849       }
1850     }
1851     else if (!ssc.getGapsInsertedBegin() && !right)
1852     {
1853       if (viewport.cursorMode)
1854       {
1855         alignPanel.seqPanel.moveCursor(-size, 0);
1856       }
1857       else
1858       {
1859         groupAdjustment = -size;
1860       }
1861     }
1862
1863     if (groupAdjustment != 0)
1864     {
1865       viewport.getSelectionGroup().setStartRes(
1866               viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1867       viewport.getSelectionGroup().setEndRes(
1868               viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1869     }
1870
1871     boolean appendHistoryItem = false;
1872     Deque<CommandI> historyList = viewport.getHistoryList();
1873     if (historyList != null && historyList.size() > 0
1874             && historyList.peek() instanceof SlideSequencesCommand)
1875     {
1876       appendHistoryItem = ssc
1877               .appendSlideCommand((SlideSequencesCommand) historyList
1878                       .peek());
1879     }
1880
1881     if (!appendHistoryItem)
1882     {
1883       addHistoryItem(ssc);
1884     }
1885
1886     repaint();
1887   }
1888
1889   static StringBuffer copiedSequences;
1890
1891   static Vector copiedHiddenColumns;
1892
1893   protected void copy_actionPerformed()
1894   {
1895     if (viewport.getSelectionGroup() == null)
1896     {
1897       return;
1898     }
1899
1900     SequenceGroup sg = viewport.getSelectionGroup();
1901     copiedSequences = new StringBuffer();
1902     Map<Integer, SequenceI> orderedSeqs = new HashMap<Integer, SequenceI>();
1903     for (int i = 0; i < sg.getSize(); i++)
1904     {
1905       SequenceI seq = sg.getSequenceAt(i);
1906       int index = viewport.getAlignment().findIndex(seq);
1907       orderedSeqs.put(index, seq);
1908     }
1909
1910     int index = 0, startRes, endRes;
1911     char ch;
1912
1913     if (viewport.hasHiddenColumns() && viewport.getSelectionGroup() != null)
1914     {
1915       copiedHiddenColumns = new Vector();
1916       int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1917       for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1918       {
1919         copiedHiddenColumns.addElement(new int[] {
1920             region[0] - hiddenOffset, region[1] - hiddenOffset });
1921       }
1922     }
1923     else
1924     {
1925       copiedHiddenColumns = null;
1926     }
1927
1928     for (int i = 0; i < sg.getSize(); i++)
1929     {
1930       SequenceI seq = null;
1931
1932       while (seq == null)
1933       {
1934         if (orderedSeqs.containsKey(index))
1935         {
1936           seq = orderedSeqs.get(index);
1937           index++;
1938           break;
1939         }
1940         else
1941         {
1942           index++;
1943         }
1944       }
1945
1946       // FIND START RES
1947       // Returns residue following index if gap
1948       startRes = seq.findPosition(sg.getStartRes());
1949
1950       // FIND END RES
1951       // Need to find the residue preceeding index if gap
1952       endRes = 0;
1953
1954       for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++)
1955       {
1956         ch = seq.getCharAt(j);
1957         if (!jalview.util.Comparison.isGap((ch)))
1958         {
1959           endRes++;
1960         }
1961       }
1962
1963       if (endRes > 0)
1964       {
1965         endRes += seq.getStart() - 1;
1966       }
1967
1968       copiedSequences.append(seq.getName()
1969               + "\t"
1970               + startRes
1971               + "\t"
1972               + endRes
1973               + "\t"
1974               + seq.getSequenceAsString(sg.getStartRes(),
1975                       sg.getEndRes() + 1) + "\n");
1976     }
1977
1978   }
1979
1980   protected void pasteNew_actionPerformed()
1981   {
1982     paste(true);
1983   }
1984
1985   protected void pasteThis_actionPerformed()
1986   {
1987     paste(false);
1988   }
1989
1990   void paste(boolean newAlignment)
1991   {
1992     try
1993     {
1994
1995       if (copiedSequences == null)
1996       {
1997         return;
1998       }
1999
2000       StringTokenizer st = new StringTokenizer(copiedSequences.toString());
2001       Vector seqs = new Vector();
2002       while (st.hasMoreElements())
2003       {
2004         String name = st.nextToken();
2005         int start = Integer.parseInt(st.nextToken());
2006         int end = Integer.parseInt(st.nextToken());
2007         seqs.addElement(new Sequence(name, st.nextToken(), start, end));
2008       }
2009       SequenceI[] newSeqs = new SequenceI[seqs.size()];
2010       for (int i = 0; i < seqs.size(); i++)
2011       {
2012         newSeqs[i] = (SequenceI) seqs.elementAt(i);
2013       }
2014
2015       if (newAlignment)
2016       {
2017         String newtitle = MessageManager
2018                 .getString("label.copied_sequences");
2019         if (getTitle().startsWith(
2020                 MessageManager.getString("label.copied_sequences")))
2021         {
2022           newtitle = getTitle();
2023         }
2024         else
2025         {
2026           newtitle = newtitle.concat(MessageManager.formatMessage(
2027                   "label.from_msname", new String[] { getTitle() }));
2028         }
2029         AlignFrame af = new AlignFrame(new Alignment(newSeqs),
2030                 viewport.applet, newtitle, false);
2031         if (copiedHiddenColumns != null)
2032         {
2033           for (int i = 0; i < copiedHiddenColumns.size(); i++)
2034           {
2035             int[] region = (int[]) copiedHiddenColumns.elementAt(i);
2036             af.viewport.hideColumns(region[0], region[1]);
2037           }
2038         }
2039
2040         jalview.bin.JalviewLite.addFrame(af, newtitle, frameWidth,
2041                 frameHeight);
2042       }
2043       else
2044       {
2045         addSequences(newSeqs);
2046       }
2047
2048     } catch (Exception ex)
2049     {
2050     } // could be anything being pasted in here
2051
2052   }
2053
2054   void addSequences(SequenceI[] seqs)
2055   {
2056     for (int i = 0; i < seqs.length; i++)
2057     {
2058       viewport.getAlignment().addSequence(seqs[i]);
2059     }
2060
2061     // !newAlignment
2062     addHistoryItem(new EditCommand(
2063             MessageManager.getString("label.add_sequences"), Action.PASTE,
2064             seqs, 0, viewport.getAlignment().getWidth(),
2065             viewport.getAlignment()));
2066
2067     viewport.setEndSeq(viewport.getAlignment().getHeight());
2068     viewport.getAlignment().getWidth();
2069     viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2070             .getSequences());
2071
2072   }
2073
2074   protected void cut_actionPerformed()
2075   {
2076     copy_actionPerformed();
2077     delete_actionPerformed();
2078   }
2079
2080   protected void delete_actionPerformed()
2081   {
2082
2083     SequenceGroup sg = viewport.getSelectionGroup();
2084     if (sg == null)
2085     {
2086       return;
2087     }
2088
2089     Vector seqs = new Vector();
2090     SequenceI seq;
2091     for (int i = 0; i < sg.getSize(); i++)
2092     {
2093       seq = sg.getSequenceAt(i);
2094       seqs.addElement(seq);
2095     }
2096
2097     /*
2098      * If the cut affects all sequences, warn, remove highlighted columns
2099      */
2100     if (sg.getSize() == viewport.getAlignment().getHeight())
2101     {
2102       boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
2103               .getAlignment().getWidth()) ? true : false;
2104       if (isEntireAlignWidth)
2105       {
2106         String title = MessageManager.getString("label.delete_all");
2107         Panel infoPanel = new Panel();
2108         infoPanel.setLayout(new FlowLayout());
2109         infoPanel
2110                 .add(new Label(MessageManager.getString("warn.delete_all")));
2111
2112         final JVDialog dialog = new JVDialog(this, title, true, 400, 200);
2113         dialog.setMainPanel(infoPanel);
2114         dialog.ok.setLabel(MessageManager.getString("action.ok"));
2115         dialog.cancel.setLabel(MessageManager.getString("action.cancel"));
2116         dialog.setVisible(true);
2117
2118         if (!dialog.accept)
2119         {
2120           return;
2121         }
2122       }
2123       viewport.getColumnSelection().removeElements(sg.getStartRes(),
2124               sg.getEndRes() + 1);
2125     }
2126
2127     SequenceI[] cut = new SequenceI[seqs.size()];
2128     for (int i = 0; i < seqs.size(); i++)
2129     {
2130       cut[i] = (SequenceI) seqs.elementAt(i);
2131     }
2132
2133     /*
2134      * //ADD HISTORY ITEM
2135      */
2136     addHistoryItem(new EditCommand(
2137             MessageManager.getString("label.cut_sequences"), Action.CUT,
2138             cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2139             viewport.getAlignment()));
2140
2141     viewport.setSelectionGroup(null);
2142     viewport.getAlignment().deleteGroup(sg);
2143
2144     viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2145             .getSequences());
2146
2147     if (viewport.getAlignment().getHeight() < 1)
2148     {
2149       this.setVisible(false);
2150     }
2151     viewport.sendSelection();
2152   }
2153
2154   /**
2155    * group consensus toggled
2156    * 
2157    */
2158   protected void showGroupConsensus_actionPerformed()
2159   {
2160     viewport.setShowGroupConsensus(showGroupConsensus.getState());
2161     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2162
2163   }
2164
2165   /**
2166    * group conservation toggled.
2167    */
2168   protected void showGroupConservation_actionPerformed()
2169   {
2170     viewport.setShowGroupConservation(showGroupConservation.getState());
2171     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2172   }
2173
2174   /*
2175    * (non-Javadoc)
2176    * 
2177    * @see
2178    * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
2179    * .event.ActionEvent)
2180    */
2181   protected void showConsensusHistogram_actionPerformed()
2182   {
2183     viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
2184     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2185   }
2186
2187   /*
2188    * (non-Javadoc)
2189    * 
2190    * @see
2191    * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
2192    * .event.ActionEvent)
2193    */
2194   protected void showSequenceLogo_actionPerformed()
2195   {
2196     viewport.setShowSequenceLogo(showSequenceLogo.getState());
2197     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2198   }
2199
2200   protected void normSequenceLogo_actionPerformed()
2201   {
2202     showSequenceLogo.setState(true);
2203     viewport.setShowSequenceLogo(true);
2204     viewport.setNormaliseSequenceLogo(normSequenceLogo.getState());
2205     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2206   }
2207
2208   protected void applyAutoAnnotationSettings_actionPerformed()
2209   {
2210     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
2211   }
2212
2213   protected void makeGrpsFromSelection_actionPerformed()
2214   {
2215     if (avc.makeGroupsFromSelection())
2216     {
2217       PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2218       alignPanel.updateAnnotation();
2219       alignPanel.paintAlignment(true);
2220     }
2221   }
2222
2223   protected void createGroup_actionPerformed()
2224   {
2225     avc.createGroup();
2226   }
2227
2228   protected void unGroup_actionPerformed()
2229   {
2230     if (avc.unGroup())
2231     {
2232       alignPanel.alignmentChanged();
2233     }
2234   }
2235
2236   protected void deleteGroups_actionPerformed()
2237   {
2238     if (avc.deleteGroups())
2239     {
2240       alignPanel.alignmentChanged();
2241     }
2242   }
2243
2244   public void selectAllSequenceMenuItem_actionPerformed()
2245   {
2246     SequenceGroup sg = new SequenceGroup();
2247     for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2248     {
2249       sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2250     }
2251     sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2252     viewport.setSelectionGroup(sg);
2253     // JAL-2034 - should delegate to
2254     // alignPanel to decide if overview needs
2255     // updating.
2256     alignPanel.paintAlignment(false);
2257     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2258     viewport.sendSelection();
2259   }
2260
2261   public void deselectAllSequenceMenuItem_actionPerformed()
2262   {
2263     if (viewport.cursorMode)
2264     {
2265       alignPanel.seqPanel.keyboardNo1 = null;
2266       alignPanel.seqPanel.keyboardNo2 = null;
2267     }
2268     viewport.setSelectionGroup(null);
2269     viewport.getColumnSelection().clear();
2270     viewport.setSelectionGroup(null);
2271     alignPanel.idPanel.idCanvas.searchResults = null;
2272     alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2273     // JAL-2034 - should delegate to
2274     // alignPanel to decide if overview needs
2275     // updating.
2276     alignPanel.paintAlignment(false);
2277     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2278     viewport.sendSelection();
2279   }
2280
2281   public void invertSequenceMenuItem_actionPerformed()
2282   {
2283     SequenceGroup sg = viewport.getSelectionGroup();
2284     for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2285     {
2286       sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2287     }
2288
2289     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2290     viewport.sendSelection();
2291   }
2292
2293   public void invertColSel_actionPerformed()
2294   {
2295     viewport.invertColumnSelection();
2296     alignPanel.paintAlignment(true);
2297     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2298     viewport.sendSelection();
2299   }
2300
2301   void trimAlignment(boolean trimLeft)
2302   {
2303     ColumnSelection colSel = viewport.getColumnSelection();
2304     int column;
2305
2306     if (!colSel.isEmpty())
2307     {
2308       if (trimLeft)
2309       {
2310         column = colSel.getMin();
2311       }
2312       else
2313       {
2314         column = colSel.getMax();
2315       }
2316
2317       SequenceI[] seqs;
2318       if (viewport.getSelectionGroup() != null)
2319       {
2320         seqs = viewport.getSelectionGroup().getSequencesAsArray(
2321                 viewport.getHiddenRepSequences());
2322       }
2323       else
2324       {
2325         seqs = viewport.getAlignment().getSequencesArray();
2326       }
2327
2328       TrimRegionCommand trimRegion;
2329       if (trimLeft)
2330       {
2331         trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2332                 column, viewport.getAlignment());
2333         viewport.setStartRes(0);
2334       }
2335       else
2336       {
2337         trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2338                 column, viewport.getAlignment());
2339       }
2340
2341       statusBar.setText(MessageManager.formatMessage(
2342               "label.removed_columns",
2343               new String[] { Integer.valueOf(trimRegion.getSize())
2344                       .toString() }));
2345       addHistoryItem(trimRegion);
2346
2347       for (SequenceGroup sg : viewport.getAlignment().getGroups())
2348       {
2349         if ((trimLeft && !sg.adjustForRemoveLeft(column))
2350                 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2351         {
2352           viewport.getAlignment().deleteGroup(sg);
2353         }
2354       }
2355
2356       viewport.firePropertyChange("alignment", null, viewport
2357               .getAlignment().getSequences());
2358     }
2359   }
2360
2361   public void removeGappedColumnMenuItem_actionPerformed()
2362   {
2363     int start = 0, end = viewport.getAlignment().getWidth() - 1;
2364
2365     SequenceI[] seqs;
2366     if (viewport.getSelectionGroup() != null)
2367     {
2368       seqs = viewport.getSelectionGroup().getSequencesAsArray(
2369               viewport.getHiddenRepSequences());
2370       start = viewport.getSelectionGroup().getStartRes();
2371       end = viewport.getSelectionGroup().getEndRes();
2372     }
2373     else
2374     {
2375       seqs = viewport.getAlignment().getSequencesArray();
2376     }
2377
2378     RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2379             "Remove Gapped Columns", seqs, start, end,
2380             viewport.getAlignment());
2381
2382     addHistoryItem(removeGapCols);
2383
2384     statusBar.setText(MessageManager.formatMessage(
2385             "label.removed_empty_columns",
2386             new String[] { Integer.valueOf(removeGapCols.getSize())
2387                     .toString() }));
2388
2389     // This is to maintain viewport position on first residue
2390     // of first sequence
2391     SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2392     int startRes = seq.findPosition(viewport.startRes);
2393     // ShiftList shifts;
2394     // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2395     // edit.alColumnChanges=shifts.getInverse();
2396     // if (viewport.hasHiddenColumns)
2397     // viewport.getColumnSelection().compensateForEdits(shifts);
2398     viewport.setStartRes(seq.findIndex(startRes) - 1);
2399     viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2400             .getSequences());
2401
2402   }
2403
2404   public void removeAllGapsMenuItem_actionPerformed()
2405   {
2406     int start = 0, end = viewport.getAlignment().getWidth() - 1;
2407
2408     SequenceI[] seqs;
2409     if (viewport.getSelectionGroup() != null)
2410     {
2411       seqs = viewport.getSelectionGroup().getSequencesAsArray(
2412               viewport.getHiddenRepSequences());
2413       start = viewport.getSelectionGroup().getStartRes();
2414       end = viewport.getSelectionGroup().getEndRes();
2415     }
2416     else
2417     {
2418       seqs = viewport.getAlignment().getSequencesArray();
2419     }
2420
2421     // This is to maintain viewport position on first residue
2422     // of first sequence
2423     SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2424     int startRes = seq.findPosition(viewport.startRes);
2425
2426     addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2427             viewport.getAlignment()));
2428
2429     viewport.setStartRes(seq.findIndex(startRes) - 1);
2430
2431     viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2432             .getSequences());
2433
2434   }
2435
2436   public void findMenuItem_actionPerformed()
2437   {
2438     new Finder(alignPanel);
2439   }
2440
2441   /**
2442    * create a new view derived from the current view
2443    * 
2444    * @param viewtitle
2445    * @return frame for the new view
2446    */
2447   public AlignFrame newView(String viewtitle)
2448   {
2449     AlignmentI newal;
2450     if (viewport.hasHiddenRows())
2451     {
2452       newal = new Alignment(viewport.getAlignment().getHiddenSequences()
2453               .getFullAlignment().getSequencesArray());
2454     }
2455     else
2456     {
2457       newal = new Alignment(viewport.getAlignment().getSequencesArray());
2458     }
2459
2460     if (viewport.getAlignment().getAlignmentAnnotation() != null)
2461     {
2462       for (int i = 0; i < viewport.getAlignment().getAlignmentAnnotation().length; i++)
2463       {
2464         if (!viewport.getAlignment().getAlignmentAnnotation()[i].autoCalculated)
2465         {
2466           newal.addAnnotation(viewport.getAlignment()
2467                   .getAlignmentAnnotation()[i]);
2468         }
2469       }
2470     }
2471
2472     AlignFrame newaf = new AlignFrame(newal, viewport.applet, "", false);
2473
2474     newaf.viewport.setSequenceSetId(alignPanel.av.getSequenceSetId());
2475     PaintRefresher.Register(alignPanel, alignPanel.av.getSequenceSetId());
2476     PaintRefresher.Register(newaf.alignPanel,
2477             newaf.alignPanel.av.getSequenceSetId());
2478
2479     PaintRefresher.Register(newaf.alignPanel.idPanel.idCanvas,
2480             newaf.alignPanel.av.getSequenceSetId());
2481     PaintRefresher.Register(newaf.alignPanel.seqPanel.seqCanvas,
2482             newaf.alignPanel.av.getSequenceSetId());
2483
2484     Vector comps = (Vector) PaintRefresher.components.get(viewport
2485             .getSequenceSetId());
2486     int viewSize = -1;
2487     for (int i = 0; i < comps.size(); i++)
2488     {
2489       if (comps.elementAt(i) instanceof AlignmentPanel)
2490       {
2491         viewSize++;
2492       }
2493     }
2494
2495     String title = new String(this.getTitle());
2496     if (viewtitle != null)
2497     {
2498       title = viewtitle + " ( " + title + ")";
2499     }
2500     else
2501     {
2502       if (title.indexOf("(View") > -1)
2503       {
2504         title = title.substring(0, title.indexOf("(View"));
2505       }
2506       title += "(View " + viewSize + ")";
2507     }
2508
2509     newaf.setTitle(title.toString());
2510
2511     newaf.viewport.setHistoryList(viewport.getHistoryList());
2512     newaf.viewport.setRedoList(viewport.getRedoList());
2513     return newaf;
2514   }
2515
2516   /**
2517    * 
2518    * @return list of feature groups on the view
2519    */
2520   public String[] getFeatureGroups()
2521   {
2522     FeatureRenderer fr = null;
2523     if (alignPanel != null
2524             && (fr = alignPanel.getFeatureRenderer()) != null)
2525     {
2526       List<String> gps = fr.getFeatureGroups();
2527       String[] _gps = gps.toArray(new String[gps.size()]);
2528       return _gps;
2529     }
2530     return null;
2531   }
2532
2533   /**
2534    * get sequence feature groups that are hidden or shown
2535    * 
2536    * @param visible
2537    *          true is visible
2538    * @return list
2539    */
2540   public String[] getFeatureGroupsOfState(boolean visible)
2541   {
2542     FeatureRenderer fr = null;
2543     if (alignPanel != null
2544             && (fr = alignPanel.getFeatureRenderer()) != null)
2545     {
2546       List<String> gps = fr.getGroups(visible);
2547       String[] _gps = gps.toArray(new String[gps.size()]);
2548       return _gps;
2549     }
2550     return null;
2551   }
2552
2553   /**
2554    * Change the display state for the given feature groups
2555    * 
2556    * @param groups
2557    *          list of group strings
2558    * @param state
2559    *          visible or invisible
2560    */
2561   public void setFeatureGroupState(String[] groups, boolean state)
2562   {
2563     FeatureRenderer fr = null;
2564     this.sequenceFeatures.setState(true);
2565     viewport.setShowSequenceFeatures(true);
2566     if (alignPanel != null
2567             && (fr = alignPanel.getFeatureRenderer()) != null)
2568     {
2569
2570       fr.setGroupVisibility(Arrays.asList(groups), state);
2571       alignPanel.seqPanel.seqCanvas.repaint();
2572       if (alignPanel.overviewPanel != null)
2573       {
2574         alignPanel.overviewPanel.updateOverviewImage();
2575       }
2576     }
2577   }
2578
2579   public void seqLimits_itemStateChanged()
2580   {
2581     viewport.setShowJVSuffix(seqLimits.getState());
2582     alignPanel.fontChanged();
2583     alignPanel.paintAlignment(true);
2584   }
2585
2586   protected void colourTextMenuItem_actionPerformed()
2587   {
2588     viewport.setColourText(colourTextMenuItem.getState());
2589     alignPanel.paintAlignment(true);
2590   }
2591
2592   protected void displayNonconservedMenuItem_actionPerformed()
2593   {
2594     viewport.setShowUnconserved(displayNonconservedMenuItem.getState());
2595     alignPanel.paintAlignment(true);
2596   }
2597
2598   protected void wrapMenuItem_actionPerformed()
2599   {
2600     viewport.setWrapAlignment(wrapMenuItem.getState());
2601     alignPanel.setWrapAlignment(wrapMenuItem.getState());
2602     scaleAbove.setEnabled(wrapMenuItem.getState());
2603     scaleLeft.setEnabled(wrapMenuItem.getState());
2604     scaleRight.setEnabled(wrapMenuItem.getState());
2605     alignPanel.paintAlignment(true);
2606   }
2607
2608   public void overviewMenuItem_actionPerformed()
2609   {
2610     if (alignPanel.overviewPanel != null)
2611     {
2612       return;
2613     }
2614
2615     Frame frame = new Frame();
2616     OverviewPanel overview = new OverviewPanel(alignPanel);
2617     frame.add(overview);
2618     // +50 must allow for applet frame window
2619     jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
2620             "label.overview_params", new String[] { this.getTitle() }),
2621             overview.getPreferredSize().width,
2622             overview.getPreferredSize().height + 50);
2623
2624     frame.pack();
2625     final AlignmentPanel ap = alignPanel;
2626     frame.addWindowListener(new WindowAdapter()
2627     {
2628       @Override
2629       public void windowClosing(WindowEvent e)
2630       {
2631         if (ap != null)
2632         {
2633           ap.setOverviewPanel(null);
2634         }
2635       };
2636     });
2637
2638     alignPanel.setOverviewPanel(overview);
2639
2640   }
2641
2642   @Override
2643   public void changeColour(ColourSchemeI cs)
2644   {
2645     viewport.setGlobalColourScheme(cs);
2646
2647     alignPanel.paintAlignment(true);
2648   }
2649
2650   protected void modifyPID_actionPerformed()
2651   {
2652     if (viewport.getAbovePIDThreshold()
2653             && viewport.getGlobalColourScheme() != null)
2654     {
2655       SliderPanel.setPIDSliderSource(alignPanel,
2656               viewport.getResidueShading(), alignPanel.getViewName());
2657       SliderPanel.showPIDSlider();
2658     }
2659   }
2660
2661   protected void modifyConservation_actionPerformed()
2662   {
2663     if (viewport.getConservationSelected()
2664             && viewport.getGlobalColourScheme() != null)
2665     {
2666       SliderPanel.setConservationSlider(alignPanel,
2667               viewport.getResidueShading(), alignPanel.getViewName());
2668       SliderPanel.showConservationSlider();
2669     }
2670   }
2671
2672   protected void conservationMenuItem_actionPerformed()
2673   {
2674     boolean selected = conservationMenuItem.getState();
2675     modifyConservation.setEnabled(selected);
2676     viewport.setConservationSelected(selected);
2677
2678     // viewport.setAbovePIDThreshold(false);
2679     // abovePIDThreshold.setState(false);
2680
2681     changeColour(viewport.getGlobalColourScheme());
2682
2683     if (selected)
2684     {
2685       modifyConservation_actionPerformed();
2686     }
2687     else
2688     {
2689       SliderPanel.hideConservationSlider();
2690     }
2691   }
2692
2693   public void abovePIDThreshold_actionPerformed()
2694   {
2695     boolean selected = abovePIDThreshold.getState();
2696     modifyPID.setEnabled(selected);
2697     viewport.setAbovePIDThreshold(selected);
2698     // conservationMenuItem.setState(false);
2699     // viewport.setConservationSelected(false);
2700
2701     changeColour(viewport.getGlobalColourScheme());
2702
2703     if (selected)
2704     {
2705       modifyPID_actionPerformed();
2706     }
2707     else
2708     {
2709       SliderPanel.hidePIDSlider();
2710     }
2711   }
2712
2713   public void sortPairwiseMenuItem_actionPerformed()
2714   {
2715     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2716     AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
2717             .getAlignment().getSequenceAt(0), null);
2718
2719     addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2720             viewport.getAlignment()));
2721     alignPanel.paintAlignment(true);
2722   }
2723
2724   public void sortIDMenuItem_actionPerformed()
2725   {
2726     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2727     AlignmentSorter.sortByID(viewport.getAlignment());
2728     addHistoryItem(new OrderCommand("ID Sort", oldOrder,
2729             viewport.getAlignment()));
2730     alignPanel.paintAlignment(true);
2731   }
2732
2733   public void sortLengthMenuItem_actionPerformed()
2734   {
2735     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2736     AlignmentSorter.sortByLength(viewport.getAlignment());
2737     addHistoryItem(new OrderCommand("Length Sort", oldOrder,
2738             viewport.getAlignment()));
2739     alignPanel.paintAlignment(true);
2740   }
2741
2742   public void sortGroupMenuItem_actionPerformed()
2743   {
2744     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2745     AlignmentSorter.sortByGroup(viewport.getAlignment());
2746     addHistoryItem(new OrderCommand("Group Sort", oldOrder,
2747             viewport.getAlignment()));
2748     alignPanel.paintAlignment(true);
2749
2750   }
2751
2752   public void removeRedundancyMenuItem_actionPerformed()
2753   {
2754     new RedundancyPanel(alignPanel);
2755   }
2756
2757   public void pairwiseAlignmentMenuItem_actionPerformed()
2758   {
2759     if (viewport.getSelectionGroup() != null
2760             && viewport.getSelectionGroup().getSize() > 1)
2761     {
2762       Frame frame = new Frame();
2763       frame.add(new PairwiseAlignPanel(alignPanel));
2764       jalview.bin.JalviewLite.addFrame(frame,
2765               MessageManager.getString("action.pairwise_alignment"), 600,
2766               500);
2767     }
2768   }
2769
2770   public void PCAMenuItem_actionPerformed()
2771   {
2772     // are the sequences aligned?
2773     if (!viewport.getAlignment().isAligned(false))
2774     {
2775       SequenceI current;
2776       int Width = viewport.getAlignment().getWidth();
2777
2778       for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2779       {
2780         current = viewport.getAlignment().getSequenceAt(i);
2781
2782         if (current.getLength() < Width)
2783         {
2784           current.insertCharAt(Width - 1, viewport.getGapCharacter());
2785         }
2786       }
2787       alignPanel.paintAlignment(true);
2788     }
2789
2790     if ((viewport.getSelectionGroup() != null
2791             && viewport.getSelectionGroup().getSize() < 4 && viewport
2792             .getSelectionGroup().getSize() > 0)
2793             || viewport.getAlignment().getHeight() < 4)
2794     {
2795       return;
2796     }
2797
2798     try
2799     {
2800       new PCAPanel(viewport);
2801     } catch (java.lang.OutOfMemoryError ex)
2802     {
2803     }
2804
2805   }
2806
2807   public void averageDistanceTreeMenuItem_actionPerformed()
2808   {
2809     NewTreePanel(NJTree.AVERAGE_DISTANCE, "PID",
2810             "Average distance tree using PID");
2811   }
2812
2813   public void neighbourTreeMenuItem_actionPerformed()
2814   {
2815     NewTreePanel(NJTree.NEIGHBOUR_JOINING, "PID",
2816             "Neighbour joining tree using PID");
2817   }
2818
2819   protected void njTreeBlosumMenuItem_actionPerformed()
2820   {
2821     NewTreePanel(NJTree.NEIGHBOUR_JOINING, "BL",
2822             "Neighbour joining tree using BLOSUM62");
2823   }
2824
2825   protected void avTreeBlosumMenuItem_actionPerformed()
2826   {
2827     NewTreePanel(NJTree.AVERAGE_DISTANCE, "BL",
2828             "Average distance tree using BLOSUM62");
2829   }
2830
2831   void NewTreePanel(String type, String pwType, String title)
2832   {
2833     // are the sequences aligned?
2834     if (!viewport.getAlignment().isAligned(false))
2835     {
2836       SequenceI current;
2837       int Width = viewport.getAlignment().getWidth();
2838
2839       for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2840       {
2841         current = viewport.getAlignment().getSequenceAt(i);
2842
2843         if (current.getLength() < Width)
2844         {
2845           current.insertCharAt(Width - 1, viewport.getGapCharacter());
2846         }
2847       }
2848       alignPanel.paintAlignment(true);
2849
2850     }
2851
2852     if ((viewport.getSelectionGroup() != null && viewport
2853             .getSelectionGroup().getSize() > 1)
2854             || (viewport.getAlignment().getHeight() > 1))
2855     {
2856       final TreePanel tp = new TreePanel(alignPanel, type, pwType);
2857
2858       addTreeMenuItem(tp, title);
2859
2860       jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);
2861     }
2862   }
2863
2864   void loadTree_actionPerformed()
2865   {
2866     CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
2867     cap.setText(MessageManager.getString("label.paste_newick_tree_file"));
2868     cap.setTreeImport();
2869     Frame frame = new Frame();
2870     frame.add(cap);
2871     jalview.bin.JalviewLite.addFrame(frame,
2872             MessageManager.getString("label.paste_newick_file"), 400, 300);
2873   }
2874
2875   public void loadTree(jalview.io.NewickFile tree, String treeFile)
2876   {
2877     TreePanel tp = new TreePanel(alignPanel, treeFile,
2878             MessageManager.getString("label.load_tree_from_file"), tree);
2879     jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
2880     addTreeMenuItem(tp, treeFile);
2881   }
2882
2883   /**
2884    * sort the alignment using the given treePanel
2885    * 
2886    * @param treePanel
2887    *          tree used to sort view
2888    * @param title
2889    *          string used for undo event name
2890    */
2891   public void sortByTree(TreePanel treePanel, String title)
2892   {
2893     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2894     AlignmentSorter
2895             .sortByTree(viewport.getAlignment(), treePanel.getTree());
2896     // addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2897     // HistoryItem.SORT));
2898     addHistoryItem(new OrderCommand(MessageManager.formatMessage(
2899             "label.order_by_params", new String[] { title }), oldOrder,
2900             viewport.getAlignment()));
2901     alignPanel.paintAlignment(true);
2902   }
2903
2904   /**
2905    * Do any automatic reordering of the alignment and add the necessary bits to
2906    * the menu structure for the new tree
2907    * 
2908    * @param treePanel
2909    * @param title
2910    */
2911   protected void addTreeMenuItem(final TreePanel treePanel,
2912           final String title)
2913   {
2914     final MenuItem item = new MenuItem(title);
2915     sortByTreeMenu.add(item);
2916     item.addActionListener(new java.awt.event.ActionListener()
2917     {
2918       @Override
2919       public void actionPerformed(ActionEvent evt)
2920       {
2921         sortByTree(treePanel, title); // treePanel.getTitle());
2922       }
2923     });
2924
2925     treePanel.addWindowListener(new WindowAdapter()
2926     {
2927       @Override
2928       public void windowOpened(WindowEvent e)
2929       {
2930         if (viewport.sortByTree)
2931         {
2932           sortByTree(treePanel, title);
2933         }
2934         super.windowOpened(e);
2935       }
2936
2937       @Override
2938       public void windowClosing(WindowEvent e)
2939       {
2940         sortByTreeMenu.remove(item);
2941       };
2942     });
2943   }
2944
2945   public boolean sortBy(AlignmentOrder alorder, String undoname)
2946   {
2947     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2948     if (viewport.applet.debug)
2949     {
2950       System.err.println("Sorting " + alorder.getOrder().size()
2951               + " in alignment '" + getTitle() + "'");
2952     }
2953     AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
2954     if (undoname != null)
2955     {
2956       addHistoryItem(new OrderCommand(undoname, oldOrder,
2957               viewport.getAlignment()));
2958     }
2959     alignPanel.paintAlignment(true);
2960     return true;
2961   }
2962
2963   protected void documentation_actionPerformed()
2964   {
2965     alignPanel.av.applet.openJalviewHelpUrl();
2966   }
2967
2968   protected void about_actionPerformed()
2969   {
2970
2971     class AboutPanel extends Canvas
2972     {
2973       String version;
2974
2975       String builddate;
2976
2977       public AboutPanel(String version, String builddate)
2978       {
2979         this.version = version;
2980         this.builddate = builddate;
2981       }
2982
2983       @Override
2984       public void paint(Graphics g)
2985       {
2986         g.setColor(Color.white);
2987         g.fillRect(0, 0, getSize().width, getSize().height);
2988         g.setFont(new Font("Helvetica", Font.PLAIN, 12));
2989         FontMetrics fm = g.getFontMetrics();
2990         int fh = fm.getHeight();
2991         int y = 5, x = 7;
2992         g.setColor(Color.black);
2993         // TODO: update this text for each release or centrally store it for
2994         // lite and application
2995         g.setFont(new Font("Helvetica", Font.BOLD, 14));
2996         g.drawString(MessageManager.formatMessage(
2997                 "label.jalviewLite_release", new String[] { version }), x,
2998                 y += fh);
2999         g.setFont(new Font("Helvetica", Font.BOLD, 12));
3000         g.drawString(MessageManager.formatMessage(
3001                 "label.jaview_build_date", new String[] { builddate }), x,
3002                 y += fh);
3003         g.setFont(new Font("Helvetica", Font.PLAIN, 12));
3004         g.drawString(MessageManager.getString("label.jalview_authors_1"),
3005                 x, y += fh * 1.5);
3006         g.drawString(MessageManager.getString("label.jalview_authors_2"),
3007                 x + 50, y += fh + 8);
3008         g.drawString(
3009                 MessageManager.getString("label.jalview_dev_managers"), x,
3010                 y += fh);
3011         g.drawString(MessageManager
3012                 .getString("label.jalview_distribution_lists"), x, y += fh);
3013         g.drawString(MessageManager.getString("label.jalview_please_cite"),
3014                 x, y += fh + 8);
3015         g.drawString(
3016                 MessageManager.getString("label.jalview_cite_1_authors"),
3017                 x, y += fh);
3018         g.drawString(
3019                 MessageManager.getString("label.jalview_cite_1_title"), x,
3020                 y += fh);
3021         g.drawString(MessageManager.getString("label.jalview_cite_1_ref"),
3022                 x, y += fh);
3023       }
3024     }
3025
3026     Frame frame = new Frame();
3027     frame.add(new AboutPanel(JalviewLite.getVersion(), JalviewLite
3028             .getBuildDate()));
3029     jalview.bin.JalviewLite.addFrame(frame,
3030             MessageManager.getString("label.jalview"), 580, 220);
3031
3032   }
3033
3034   public void showURL(String url, String target)
3035   {
3036     if (viewport.applet == null)
3037     {
3038       System.out.println("Not running as applet - no browser available.");
3039     }
3040     else
3041     {
3042       viewport.applet.showURL(url, target);
3043     }
3044   }
3045
3046   // ////////////////////////////////////////////////////////////////////////////////
3047   // JBuilder Graphics here
3048
3049   MenuBar alignFrameMenuBar = new MenuBar();
3050
3051   Menu fileMenu = new Menu(MessageManager.getString("action.file"));
3052
3053   MenuItem loadApplication = new MenuItem(
3054           MessageManager.getString("label.view_full_application"));
3055
3056   MenuItem loadTree = new MenuItem(
3057           MessageManager.getString("label.load_associated_tree"));
3058
3059   MenuItem loadAnnotations = new MenuItem(
3060           MessageManager.getString("label.load_features_annotations"));
3061
3062   MenuItem outputFeatures = new MenuItem(
3063           MessageManager.getString("label.export_features"));
3064
3065   MenuItem outputAnnotations = new MenuItem(
3066           MessageManager.getString("label.export_annotations"));
3067
3068   MenuItem closeMenuItem = new MenuItem(
3069           MessageManager.getString("action.close"));
3070
3071   MenuItem selectAllSequenceMenuItem = new MenuItem(
3072           MessageManager.getString("action.select_all"));
3073
3074   MenuItem deselectAllSequenceMenuItem = new MenuItem(
3075           MessageManager.getString("action.deselect_all"));
3076
3077   MenuItem invertSequenceMenuItem = new MenuItem(
3078           MessageManager.getString("action.invert_selection"));
3079
3080   MenuItem remove2LeftMenuItem = new MenuItem();
3081
3082   MenuItem remove2RightMenuItem = new MenuItem();
3083
3084   MenuItem removeGappedColumnMenuItem = new MenuItem();
3085
3086   MenuItem removeAllGapsMenuItem = new MenuItem();
3087
3088   CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();
3089
3090   CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();
3091
3092   MenuItem sortPairwiseMenuItem = new MenuItem();
3093
3094   MenuItem sortIDMenuItem = new MenuItem();
3095
3096   MenuItem sortLengthMenuItem = new MenuItem();
3097
3098   MenuItem sortGroupMenuItem = new MenuItem();
3099
3100   MenuItem removeRedundancyMenuItem = new MenuItem();
3101
3102   MenuItem pairwiseAlignmentMenuItem = new MenuItem();
3103
3104   MenuItem PCAMenuItem = new MenuItem();
3105
3106   MenuItem averageDistanceTreeMenuItem = new MenuItem();
3107
3108   MenuItem neighbourTreeMenuItem = new MenuItem();
3109
3110   BorderLayout borderLayout1 = new BorderLayout();
3111
3112   public Label statusBar = new Label();
3113
3114   MenuItem clustalColour = new MenuItem();
3115
3116   MenuItem zappoColour = new MenuItem();
3117
3118   MenuItem taylorColour = new MenuItem();
3119
3120   MenuItem hydrophobicityColour = new MenuItem();
3121
3122   MenuItem helixColour = new MenuItem();
3123
3124   MenuItem strandColour = new MenuItem();
3125
3126   MenuItem turnColour = new MenuItem();
3127
3128   MenuItem buriedColour = new MenuItem();
3129
3130   MenuItem purinePyrimidineColour = new MenuItem();
3131
3132   // MenuItem RNAInteractionColour = new MenuItem();
3133
3134   MenuItem RNAHelixColour = new MenuItem();
3135
3136   MenuItem userDefinedColour = new MenuItem();
3137
3138   MenuItem PIDColour = new MenuItem();
3139
3140   MenuItem BLOSUM62Colour = new MenuItem();
3141
3142   MenuItem tcoffeeColour = new MenuItem();
3143
3144   MenuItem njTreeBlosumMenuItem = new MenuItem();
3145
3146   MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();
3147
3148   CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();
3149
3150   CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();
3151
3152   CheckboxMenuItem displayNonconservedMenuItem = new CheckboxMenuItem();
3153
3154   MenuItem alProperties = new MenuItem(
3155           MessageManager.getString("label.alignment_props"));
3156
3157   MenuItem overviewMenuItem = new MenuItem();
3158
3159   MenuItem undoMenuItem = new MenuItem();
3160
3161   MenuItem redoMenuItem = new MenuItem();
3162
3163   CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
3164
3165   MenuItem noColourmenuItem = new MenuItem();
3166
3167   CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();
3168
3169   CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();
3170
3171   MenuItem findMenuItem = new MenuItem();
3172
3173   CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();
3174
3175   MenuItem nucleotideColour = new MenuItem();
3176
3177   MenuItem deleteGroups = new MenuItem();
3178
3179   MenuItem grpsFromSelection = new MenuItem();
3180
3181   MenuItem createGroup = new MenuItem();
3182
3183   MenuItem unGroup = new MenuItem();
3184
3185   MenuItem delete = new MenuItem();
3186
3187   MenuItem copy = new MenuItem();
3188
3189   MenuItem cut = new MenuItem();
3190
3191   Menu pasteMenu = new Menu();
3192
3193   MenuItem pasteNew = new MenuItem();
3194
3195   MenuItem pasteThis = new MenuItem();
3196
3197   CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();
3198
3199   MenuItem font = new MenuItem();
3200
3201   CheckboxMenuItem scaleAbove = new CheckboxMenuItem();
3202
3203   CheckboxMenuItem scaleLeft = new CheckboxMenuItem();
3204
3205   CheckboxMenuItem scaleRight = new CheckboxMenuItem();
3206
3207   MenuItem modifyPID = new MenuItem();
3208
3209   MenuItem modifyConservation = new MenuItem();
3210
3211   CheckboxMenuItem autoCalculate = null;
3212
3213   CheckboxMenuItem sortByTree = new CheckboxMenuItem(
3214           "Sort Alignment With New Tree", true);
3215
3216   Menu sortByTreeMenu = new Menu();
3217
3218   MenuItem inputText = new MenuItem();
3219
3220   MenuItem documentation = new MenuItem();
3221
3222   MenuItem about = new MenuItem();
3223
3224   CheckboxMenuItem seqLimits = new CheckboxMenuItem();
3225
3226   CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem();
3227
3228   CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem();
3229
3230   CheckboxMenuItem showSequenceLogo = new CheckboxMenuItem();
3231
3232   CheckboxMenuItem applyAutoAnnotationSettings = new CheckboxMenuItem();
3233
3234   CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem();
3235
3236   CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem();
3237
3238   CheckboxMenuItem showGroupConservation = new CheckboxMenuItem();
3239
3240   CheckboxMenuItem normSequenceLogo = new CheckboxMenuItem();
3241
3242   /**
3243    * Initialise menus and other items
3244    * 
3245    * @throws Exception
3246    */
3247   private void jbInit() throws Exception
3248   {
3249     setMenuBar(alignFrameMenuBar);
3250
3251     /*
3252      * Configure File menu items and actions
3253      */
3254     inputText
3255             .setLabel(MessageManager.getString("label.input_from_textbox"));
3256     inputText.addActionListener(this);
3257     Menu outputTextboxMenu = new Menu(
3258             MessageManager.getString("label.out_to_textbox"));
3259     for (String ff : FileFormats.getInstance().getWritableFormats(true))
3260     {
3261       MenuItem item = new MenuItem(ff);
3262
3263       item.addActionListener(new java.awt.event.ActionListener()
3264       {
3265         @Override
3266         public void actionPerformed(ActionEvent e)
3267         {
3268           outputText_actionPerformed(e);
3269         }
3270       });
3271
3272       outputTextboxMenu.add(item);
3273     }
3274     closeMenuItem.addActionListener(this);
3275     loadApplication.addActionListener(this);
3276     loadTree.addActionListener(this);
3277     loadAnnotations.addActionListener(this);
3278     outputFeatures.addActionListener(this);
3279     outputAnnotations.addActionListener(this);
3280
3281     /*
3282      * Configure Edit menu items and actions
3283      */
3284     undoMenuItem.setEnabled(false);
3285     undoMenuItem.setLabel(MessageManager.getString("action.undo"));
3286     undoMenuItem.addActionListener(this);
3287     redoMenuItem.setEnabled(false);
3288     redoMenuItem.setLabel(MessageManager.getString("action.redo"));
3289     redoMenuItem.addActionListener(this);
3290     copy.setLabel(MessageManager.getString("action.copy"));
3291     copy.addActionListener(this);
3292     cut.setLabel(MessageManager.getString("action.cut"));
3293     cut.addActionListener(this);
3294     delete.setLabel(MessageManager.getString("action.delete"));
3295     delete.addActionListener(this);
3296     pasteMenu.setLabel(MessageManager.getString("action.paste"));
3297     pasteNew.setLabel(MessageManager.getString("label.to_new_alignment"));
3298     pasteNew.addActionListener(this);
3299     pasteThis.setLabel(MessageManager.getString("label.to_this_alignment"));
3300     pasteThis.addActionListener(this);
3301     remove2LeftMenuItem.setLabel(MessageManager
3302             .getString("action.remove_left"));
3303     remove2LeftMenuItem.addActionListener(this);
3304     remove2RightMenuItem.setLabel(MessageManager
3305             .getString("action.remove_right"));
3306     remove2RightMenuItem.addActionListener(this);
3307     removeGappedColumnMenuItem.setLabel(MessageManager
3308             .getString("action.remove_empty_columns"));
3309     removeGappedColumnMenuItem.addActionListener(this);
3310     removeAllGapsMenuItem.setLabel(MessageManager
3311             .getString("action.remove_all_gaps"));
3312     removeAllGapsMenuItem.addActionListener(this);
3313     removeRedundancyMenuItem.setLabel(MessageManager
3314             .getString("action.remove_redundancy"));
3315     removeRedundancyMenuItem.addActionListener(this);
3316
3317     /*
3318      * Configure Select menu items and actions
3319      */
3320     findMenuItem.setLabel(MessageManager.getString("action.find"));
3321     findMenuItem.addActionListener(this);
3322     selectAllSequenceMenuItem.addActionListener(this);
3323     deselectAllSequenceMenuItem.addActionListener(this);
3324     invertSequenceMenuItem.setLabel(MessageManager
3325             .getString("action.invert_sequence_selection"));
3326     invertSequenceMenuItem.addActionListener(this);
3327     invertColSel.setLabel(MessageManager
3328             .getString("action.invert_column_selection"));
3329     invertColSel.addActionListener(this);
3330     deleteGroups.setLabel(MessageManager
3331             .getString("action.undefine_groups"));
3332     deleteGroups.addActionListener(this);
3333     grpsFromSelection.setLabel(MessageManager
3334             .getString("action.make_groups_selection"));
3335     grpsFromSelection.addActionListener(this);
3336     createGroup.setLabel(MessageManager.getString("action.create_group"));
3337     unGroup.setLabel(MessageManager.getString("action.remove_group"));
3338     annotationColumnSelection.setLabel(MessageManager
3339             .getString("action.select_by_annotation"));
3340     annotationColumnSelection.addActionListener(this);
3341
3342     /*
3343      * Configure View menu items and actions
3344      */
3345     newView.setLabel(MessageManager.getString("action.new_view"));
3346     newView.addActionListener(this);
3347     Menu showMenu = new Menu(MessageManager.getString("action.show"));
3348     showColumns.setLabel(MessageManager.getString("label.all_columns"));
3349     showSeqs.setLabel(MessageManager.getString("label.all_sequences"));
3350     Menu hideMenu = new Menu(MessageManager.getString("action.hide"));
3351     hideColumns
3352             .setLabel(MessageManager.getString("label.selected_columns"));
3353     hideSequences.setLabel(MessageManager
3354             .getString("label.selected_sequences"));
3355     hideAllButSelection.setLabel(MessageManager
3356             .getString("label.all_but_selected_region"));
3357     hideAllSelection.setLabel(MessageManager
3358             .getString("label.selected_region"));
3359     showAllHidden.setLabel(MessageManager
3360             .getString("label.all_sequences_columns"));
3361     showColumns.addActionListener(this);
3362     showSeqs.addActionListener(this);
3363     hideColumns.addActionListener(this);
3364     hideSequences.addActionListener(this);
3365     hideAllButSelection.addActionListener(this);
3366     hideAllSelection.addActionListener(this);
3367     showAllHidden.addActionListener(this);
3368     featureSettings.setLabel(MessageManager
3369             .getString("action.feature_settings"));
3370     featureSettings.addActionListener(this);
3371     sequenceFeatures.setLabel(MessageManager
3372             .getString("label.show_sequence_features"));
3373     sequenceFeatures.addItemListener(this);
3374     sequenceFeatures.setState(false);
3375     followMouseOverFlag.setLabel(MessageManager
3376             .getString("label.automatic_scrolling"));
3377     followMouseOverFlag.addItemListener(this);
3378     alProperties.addActionListener(this);
3379     overviewMenuItem.setLabel(MessageManager
3380             .getString("label.overview_window"));
3381     overviewMenuItem.addActionListener(this);
3382
3383     /*
3384      * Configure Annotations menu items and actions
3385      */
3386     annotationPanelMenuItem.setLabel(MessageManager
3387             .getString("label.show_annotations"));
3388     annotationPanelMenuItem.addItemListener(this);
3389     showGroupConsensus.setLabel(MessageManager
3390             .getString("label.group_consensus"));
3391     showGroupConservation.setLabel(MessageManager
3392             .getString("label.group_conservation"));
3393     showConsensusHistogram.setLabel(MessageManager
3394             .getString("label.show_consensus_histogram"));
3395     showSequenceLogo.setLabel(MessageManager
3396             .getString("label.show_consensus_logo"));
3397     normSequenceLogo.setLabel(MessageManager
3398             .getString("label.norm_consensus_logo"));
3399     applyAutoAnnotationSettings.setLabel(MessageManager
3400             .getString("label.apply_all_groups"));
3401     applyAutoAnnotationSettings.setState(true);
3402     Menu autoAnnMenu = new Menu(
3403             MessageManager.getString("label.autocalculated_annotation"));
3404     showGroupConsensus.addItemListener(this);
3405     showGroupConservation.addItemListener(this);
3406     showConsensusHistogram.addItemListener(this);
3407     showSequenceLogo.addItemListener(this);
3408     normSequenceLogo.addItemListener(this);
3409     applyAutoAnnotationSettings.addItemListener(this);
3410     showAlignmentAnnotations = new CheckboxMenuItem(
3411             MessageManager.getString("label.show_all_al_annotations"));
3412     showSequenceAnnotations = new CheckboxMenuItem(
3413             MessageManager.getString("label.show_all_seq_annotations"));
3414     sortAnnBySequence = new CheckboxMenuItem(
3415             MessageManager.getString("label.sort_annotations_by_sequence"));
3416     sortAnnByLabel = new CheckboxMenuItem(
3417             MessageManager.getString("label.sort_annotations_by_label"));
3418     showAutoFirst = new CheckboxMenuItem(
3419             MessageManager.getString("label.show_first"));
3420     showAutoFirst.setState(false); // pending applet parameter
3421     setShowAutoCalculatedAbove(showAutoFirst.getState());
3422     showAutoLast = new CheckboxMenuItem(
3423             MessageManager.getString("label.show_last"));
3424     showAutoLast.setState(!showAutoFirst.getState());
3425     showAlignmentAnnotations.addItemListener(this);
3426     showSequenceAnnotations.addItemListener(this);
3427     sortAnnBySequence.addItemListener(this);
3428     sortAnnByLabel.addItemListener(this);
3429     showAutoFirst.addItemListener(this);
3430     showAutoLast.addItemListener(this);
3431
3432     /*
3433      * Configure Format menu items and actions
3434      */
3435     font.setLabel(MessageManager.getString("action.font"));
3436     font.addActionListener(this);
3437     scaleAbove.setLabel(MessageManager.getString("action.scale_above"));
3438     scaleAbove.setState(true);
3439     scaleAbove.setEnabled(false);
3440     scaleAbove.addItemListener(this);
3441     scaleLeft.setEnabled(false);
3442     scaleLeft.setState(true);
3443     scaleLeft.setLabel(MessageManager.getString("action.scale_left"));
3444     scaleLeft.addItemListener(this);
3445     scaleRight.setEnabled(false);
3446     scaleRight.setState(true);
3447     scaleRight.setLabel(MessageManager.getString("action.scale_right"));
3448     scaleRight.addItemListener(this);
3449     viewBoxesMenuItem.setLabel(MessageManager.getString("action.boxes"));
3450     viewBoxesMenuItem.setState(true);
3451     viewBoxesMenuItem.addItemListener(this);
3452     viewTextMenuItem.setLabel(MessageManager.getString("action.text"));
3453     viewTextMenuItem.setState(true);
3454     viewTextMenuItem.addItemListener(this);
3455     colourTextMenuItem.setLabel(MessageManager
3456             .getString("label.colour_text"));
3457     colourTextMenuItem.addItemListener(this);
3458     displayNonconservedMenuItem.setLabel(MessageManager
3459             .getString("label.show_non_conserved"));
3460     displayNonconservedMenuItem.addItemListener(this);
3461     wrapMenuItem.setLabel(MessageManager.getString("action.wrap"));
3462     wrapMenuItem.addItemListener(this);
3463     renderGapsMenuItem.setLabel(MessageManager
3464             .getString("action.show_gaps"));
3465     renderGapsMenuItem.setState(true);
3466     renderGapsMenuItem.addItemListener(this);
3467     centreColumnLabelFlag.setLabel(MessageManager
3468             .getString("label.centre_column_labels"));
3469     centreColumnLabelFlag.addItemListener(this);
3470     seqLimits.setState(true);
3471     seqLimits.setLabel(MessageManager
3472             .getString("label.show_sequence_limits"));
3473     seqLimits.addItemListener(this);
3474
3475     /*
3476      * Configure Colour menu items and actions
3477      */
3478     applyToAllGroups.setLabel(MessageManager
3479             .getString("label.apply_colour_to_all_groups"));
3480     applyToAllGroups.setState(true);
3481     applyToAllGroups.addItemListener(this);
3482     clustalColour.setLabel(MessageManager
3483             .getString("label.colourScheme_clustal"));
3484     clustalColour.addActionListener(this);
3485     zappoColour.setLabel(MessageManager
3486             .getString("label.colourScheme_zappo"));
3487     zappoColour.addActionListener(this);
3488     taylorColour.setLabel(MessageManager
3489             .getString("label.colourScheme_taylor"));
3490     taylorColour.addActionListener(this);
3491     hydrophobicityColour.setLabel(MessageManager
3492             .getString("label.colourScheme_hydrophobic"));
3493     hydrophobicityColour.addActionListener(this);
3494     helixColour.setLabel(MessageManager
3495             .getString("label.colourScheme_helix_propensity"));
3496     helixColour.addActionListener(this);
3497     strandColour.setLabel(MessageManager
3498             .getString("label.colourScheme_strand_propensity"));
3499     strandColour.addActionListener(this);
3500     turnColour.setLabel(MessageManager
3501             .getString("label.colourScheme_turn_propensity"));
3502     turnColour.addActionListener(this);
3503     buriedColour.setLabel(MessageManager
3504             .getString("label.colourScheme_buried_index"));
3505     buriedColour.addActionListener(this);
3506     purinePyrimidineColour.setLabel(MessageManager
3507             .getString("label.colourScheme_purine/pyrimidine"));
3508     purinePyrimidineColour.addActionListener(this);
3509     // RNAInteractionColour.setLabel(MessageManager
3510     // .getString("label.rna_interaction"));
3511     // RNAInteractionColour.addActionListener(this);
3512     RNAHelixColour.setLabel(MessageManager
3513             .getString("label.colourScheme_rna_helices"));
3514     RNAHelixColour.addActionListener(this);
3515     userDefinedColour.setLabel(MessageManager
3516             .getString("action.user_defined"));
3517     userDefinedColour.addActionListener(this);
3518     PIDColour.setLabel(MessageManager
3519             .getString("label.colourScheme_%_identity"));
3520     PIDColour.addActionListener(this);
3521     BLOSUM62Colour.setLabel(MessageManager
3522             .getString("label.colourScheme_blosum62"));
3523     BLOSUM62Colour.addActionListener(this);
3524     tcoffeeColour.setLabel(MessageManager
3525             .getString("label.colourScheme_t-coffee_scores"));
3526     // it will be enabled only if a score file is provided
3527     tcoffeeColour.setEnabled(false);
3528     tcoffeeColour.addActionListener(this);
3529     conservationMenuItem.setLabel(MessageManager
3530             .getString("action.by_conservation"));
3531     conservationMenuItem.addItemListener(this);
3532     noColourmenuItem.setLabel(MessageManager.getString("label.none"));
3533     noColourmenuItem.addActionListener(this);
3534     abovePIDThreshold.setLabel(MessageManager
3535             .getString("label.above_identity_threshold"));
3536     abovePIDThreshold.addItemListener(this);
3537     nucleotideColour.setLabel(MessageManager
3538             .getString("label.colourScheme_nucleotide"));
3539     nucleotideColour.addActionListener(this);
3540     modifyPID.setLabel(MessageManager
3541             .getString("label.modify_identity_threshold"));
3542     modifyPID.setEnabled(abovePIDThreshold.getState());
3543     modifyPID.addActionListener(this);
3544     modifyConservation.setLabel(MessageManager
3545             .getString("label.modify_conservation_threshold"));
3546     modifyConservation.setEnabled(conservationMenuItem.getState());
3547     modifyConservation.addActionListener(this);
3548     annotationColour.setLabel(MessageManager
3549             .getString("action.by_annotation"));
3550     annotationColour.addActionListener(this);
3551
3552     /*
3553      * Configure Calculate menu items and actions
3554      */
3555     sortPairwiseMenuItem.setLabel(MessageManager
3556             .getString("action.by_pairwise_id"));
3557     sortPairwiseMenuItem.addActionListener(this);
3558     sortIDMenuItem.setLabel(MessageManager.getString("action.by_id"));
3559     sortIDMenuItem.addActionListener(this);
3560     sortLengthMenuItem.setLabel(MessageManager
3561             .getString("action.by_length"));
3562     sortLengthMenuItem.addActionListener(this);
3563     sortGroupMenuItem.setLabel(MessageManager.getString("action.by_group"));
3564     sortGroupMenuItem.addActionListener(this);
3565     pairwiseAlignmentMenuItem.setLabel(MessageManager
3566             .getString("action.pairwise_alignment"));
3567     pairwiseAlignmentMenuItem.addActionListener(this);
3568     PCAMenuItem.setLabel(MessageManager
3569             .getString("label.principal_component_analysis"));
3570     PCAMenuItem.addActionListener(this);
3571     autoCalculate = new CheckboxMenuItem(
3572             MessageManager.getString("label.autocalculate_consensus"), true);
3573     averageDistanceTreeMenuItem.setLabel(MessageManager
3574             .getString("label.average_distance_identity"));
3575     averageDistanceTreeMenuItem.addActionListener(this);
3576     neighbourTreeMenuItem.setLabel(MessageManager
3577             .getString("label.neighbour_joining_identity"));
3578     neighbourTreeMenuItem.addActionListener(this);
3579     avDistanceTreeBlosumMenuItem.setLabel(MessageManager
3580             .getString("label.average_distance_blosum62"));
3581     avDistanceTreeBlosumMenuItem.addActionListener(this);
3582     njTreeBlosumMenuItem.setLabel(MessageManager
3583             .getString("label.neighbour_blosum62"));
3584     njTreeBlosumMenuItem.addActionListener(this);
3585     sortByTreeMenu.setLabel(MessageManager
3586             .getString("action.by_tree_order"));
3587     Menu sortMenu = new Menu(MessageManager.getString("action.sort"));
3588     Menu calculateTreeMenu = new Menu(
3589             MessageManager.getString("action.calculate_tree"));
3590     autoCalculate.addItemListener(this);
3591     sortByTree.addItemListener(this);
3592
3593     /*
3594      * Configure Help menu items and actions
3595      */
3596     Menu helpMenu = new Menu(MessageManager.getString("action.help"));
3597     documentation.setLabel(MessageManager.getString("label.documentation"));
3598     documentation.addActionListener(this);
3599     about.setLabel(MessageManager.getString("label.about"));
3600     about.addActionListener(this);
3601
3602     /*
3603      * Add top level menus to frame
3604      */
3605     alignFrameMenuBar.add(fileMenu);
3606     Menu editMenu = new Menu(MessageManager.getString("action.edit"));
3607     alignFrameMenuBar.add(editMenu);
3608     Menu selectMenu = new Menu(MessageManager.getString("action.select"));
3609     alignFrameMenuBar.add(selectMenu);
3610     Menu viewMenu = new Menu(MessageManager.getString("action.view"));
3611     alignFrameMenuBar.add(viewMenu);
3612     Menu annotationsMenu = new Menu(
3613             MessageManager.getString("action.annotations"));
3614     alignFrameMenuBar.add(annotationsMenu);
3615     Menu formatMenu = new Menu(MessageManager.getString("action.format"));
3616     alignFrameMenuBar.add(formatMenu);
3617     Menu colourMenu = new Menu(MessageManager.getString("action.colour"));
3618     alignFrameMenuBar.add(colourMenu);
3619     Menu calculateMenu = new Menu(
3620             MessageManager.getString("action.calculate"));
3621     alignFrameMenuBar.add(calculateMenu);
3622     alignFrameMenuBar.add(helpMenu);
3623
3624     /*
3625      * File menu
3626      */
3627     fileMenu.add(inputText);
3628     fileMenu.add(loadTree);
3629     fileMenu.add(loadAnnotations);
3630     fileMenu.addSeparator();
3631     fileMenu.add(outputTextboxMenu);
3632     fileMenu.add(outputFeatures);
3633     fileMenu.add(outputAnnotations);
3634     if (jalviewServletURL != null)
3635     {
3636       fileMenu.add(loadApplication);
3637     }
3638     fileMenu.addSeparator();
3639     fileMenu.add(closeMenuItem);
3640
3641     /*
3642      * Edit menu
3643      */
3644     editMenu.add(undoMenuItem);
3645     editMenu.add(redoMenuItem);
3646     editMenu.add(cut);
3647     editMenu.add(copy);
3648     pasteMenu.add(pasteNew);
3649     pasteMenu.add(pasteThis);
3650     editMenu.add(pasteMenu);
3651     editMenu.add(delete);
3652     editMenu.addSeparator();
3653     editMenu.add(remove2LeftMenuItem);
3654     editMenu.add(remove2RightMenuItem);
3655     editMenu.add(removeGappedColumnMenuItem);
3656     editMenu.add(removeAllGapsMenuItem);
3657     editMenu.add(removeRedundancyMenuItem);
3658
3659     /*
3660      * Select menu
3661      */
3662     selectMenu.add(findMenuItem);
3663     selectMenu.addSeparator();
3664     selectMenu.add(selectAllSequenceMenuItem);
3665     selectMenu.add(deselectAllSequenceMenuItem);
3666     selectMenu.add(invertSequenceMenuItem);
3667     selectMenu.add(invertColSel);
3668     selectMenu.add(createGroup);
3669     selectMenu.add(unGroup);
3670     selectMenu.add(grpsFromSelection);
3671     selectMenu.add(deleteGroups);
3672     selectMenu.add(annotationColumnSelection);
3673
3674     /*
3675      * View menu
3676      */
3677     viewMenu.add(newView);
3678     viewMenu.addSeparator();
3679     showMenu.add(showColumns);
3680     showMenu.add(showSeqs);
3681     showMenu.add(showAllHidden);
3682     viewMenu.add(showMenu);
3683     hideMenu.add(hideColumns);
3684     hideMenu.add(hideSequences);
3685     hideMenu.add(hideAllSelection);
3686     hideMenu.add(hideAllButSelection);
3687     viewMenu.add(hideMenu);
3688     viewMenu.addSeparator();
3689     viewMenu.add(followMouseOverFlag);
3690     viewMenu.addSeparator();
3691     viewMenu.add(sequenceFeatures);
3692     viewMenu.add(featureSettings);
3693     viewMenu.addSeparator();
3694     viewMenu.add(alProperties);
3695     viewMenu.addSeparator();
3696     viewMenu.add(overviewMenuItem);
3697
3698     /*
3699      * Annotations menu
3700      */
3701     annotationsMenu.add(annotationPanelMenuItem);
3702     annotationsMenu.addSeparator();
3703     annotationsMenu.add(showAlignmentAnnotations);
3704     annotationsMenu.add(showSequenceAnnotations);
3705     annotationsMenu.add(sortAnnBySequence);
3706     annotationsMenu.add(sortAnnByLabel);
3707     annotationsMenu.addSeparator();
3708     autoAnnMenu.add(showAutoFirst);
3709     autoAnnMenu.add(showAutoLast);
3710     autoAnnMenu.addSeparator();
3711     autoAnnMenu.add(applyAutoAnnotationSettings);
3712     autoAnnMenu.add(showConsensusHistogram);
3713     autoAnnMenu.add(showSequenceLogo);
3714     autoAnnMenu.add(normSequenceLogo);
3715     autoAnnMenu.addSeparator();
3716     autoAnnMenu.add(showGroupConservation);
3717     autoAnnMenu.add(showGroupConsensus);
3718     annotationsMenu.add(autoAnnMenu);
3719
3720     /*
3721      * Format menu
3722      */
3723     formatMenu.add(font);
3724     formatMenu.add(seqLimits);
3725     formatMenu.add(wrapMenuItem);
3726     formatMenu.add(scaleAbove);
3727     formatMenu.add(scaleLeft);
3728     formatMenu.add(scaleRight);
3729     formatMenu.add(viewBoxesMenuItem);
3730     formatMenu.add(viewTextMenuItem);
3731     formatMenu.add(colourTextMenuItem);
3732     formatMenu.add(displayNonconservedMenuItem);
3733     formatMenu.add(renderGapsMenuItem);
3734     formatMenu.add(centreColumnLabelFlag);
3735
3736     /*
3737      * Colour menu
3738      */
3739     colourMenu.add(applyToAllGroups);
3740     colourMenu.addSeparator();
3741     colourMenu.add(noColourmenuItem);
3742     colourMenu.add(clustalColour);
3743     colourMenu.add(BLOSUM62Colour);
3744     colourMenu.add(PIDColour);
3745     colourMenu.add(zappoColour);
3746     colourMenu.add(taylorColour);
3747     colourMenu.add(hydrophobicityColour);
3748     colourMenu.add(helixColour);
3749     colourMenu.add(strandColour);
3750     colourMenu.add(turnColour);
3751     colourMenu.add(buriedColour);
3752     colourMenu.add(nucleotideColour);
3753     colourMenu.add(purinePyrimidineColour);
3754     // colourMenu.add(RNAInteractionColour);
3755     colourMenu.add(tcoffeeColour);
3756     colourMenu.add(userDefinedColour);
3757     colourMenu.addSeparator();
3758     colourMenu.add(conservationMenuItem);
3759     colourMenu.add(modifyConservation);
3760     colourMenu.add(abovePIDThreshold);
3761     colourMenu.add(modifyPID);
3762     colourMenu.add(annotationColour);
3763     colourMenu.add(RNAHelixColour);
3764
3765     /*
3766      * Calculate menu
3767      */
3768     sortMenu.add(sortIDMenuItem);
3769     sortMenu.add(sortLengthMenuItem);
3770     sortMenu.add(sortByTreeMenu);
3771     sortMenu.add(sortGroupMenuItem);
3772     sortMenu.add(sortPairwiseMenuItem);
3773     calculateMenu.add(sortMenu);
3774     calculateTreeMenu.add(averageDistanceTreeMenuItem);
3775     calculateTreeMenu.add(neighbourTreeMenuItem);
3776     calculateTreeMenu.add(avDistanceTreeBlosumMenuItem);
3777     calculateTreeMenu.add(njTreeBlosumMenuItem);
3778     calculateMenu.add(calculateTreeMenu);
3779     calculateMenu.addSeparator();
3780     calculateMenu.add(pairwiseAlignmentMenuItem);
3781     calculateMenu.add(PCAMenuItem);
3782     calculateMenu.add(autoCalculate);
3783     calculateMenu.add(sortByTree);
3784
3785     /*
3786      * Help menu
3787      */
3788     helpMenu.add(documentation);
3789     helpMenu.add(about);
3790
3791     /*
3792      * Status bar
3793      */
3794     statusBar.setBackground(Color.white);
3795     statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
3796     statusBar.setText(MessageManager.getString("label.status_bar"));
3797     this.add(statusBar, BorderLayout.SOUTH);
3798   }
3799
3800   @Override
3801   public void setStatus(String string)
3802   {
3803     statusBar.setText(string);
3804   };
3805
3806   MenuItem featureSettings = new MenuItem();
3807
3808   CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();
3809
3810   MenuItem annotationColour = new MenuItem();
3811
3812   MenuItem annotationColumnSelection = new MenuItem();
3813
3814   MenuItem invertColSel = new MenuItem();
3815
3816   MenuItem showColumns = new MenuItem();
3817
3818   MenuItem showSeqs = new MenuItem();
3819
3820   MenuItem hideColumns = new MenuItem();
3821
3822   MenuItem hideSequences = new MenuItem();
3823
3824   MenuItem hideAllButSelection = new MenuItem();
3825
3826   MenuItem hideAllSelection = new MenuItem();
3827
3828   MenuItem showAllHidden = new MenuItem();
3829
3830   MenuItem newView = new MenuItem();
3831
3832   private CheckboxMenuItem showAlignmentAnnotations;
3833
3834   private CheckboxMenuItem showSequenceAnnotations;
3835
3836   private CheckboxMenuItem sortAnnBySequence;
3837
3838   private CheckboxMenuItem sortAnnByLabel;
3839
3840   private CheckboxMenuItem showAutoFirst;
3841
3842   private CheckboxMenuItem showAutoLast;
3843
3844   private SplitFrame splitFrame;
3845
3846   /**
3847    * Attach the alignFrame panels after embedding menus, if necessary. This used
3848    * to be called setEmbedded, but is now creates the dropdown menus in a
3849    * platform independent manner to avoid OSX/Mac menu appendage daftness.
3850    * 
3851    * @param reallyEmbedded
3852    *          true to attach the view to the applet area on the page rather than
3853    *          in a new window
3854    */
3855   public void createAlignFrameWindow(boolean reallyEmbedded)
3856   {
3857     if (reallyEmbedded)
3858     {
3859       embedAlignFrameInApplet(viewport.applet);
3860     }
3861     else
3862     {
3863       // //////
3864       // test and embed menu bar if necessary.
3865       //
3866       if (embedMenuIfNeeded(alignPanel))
3867       {
3868         /*
3869          * adjust for status bar height too. ? pointless as overridden by layout
3870          * manager
3871          */
3872         alignPanel.setSize(getSize().width,
3873                 getSize().height - statusBar.getHeight());
3874       }
3875       add(statusBar, BorderLayout.SOUTH);
3876       add(alignPanel, BorderLayout.CENTER);
3877       // and register with the applet so it can pass external API calls to us
3878       jalview.bin.JalviewLite.addFrame(this, this.getTitle(), frameWidth,
3879               frameHeight);
3880     }
3881   }
3882
3883   /**
3884    * Add the components of this AlignFrame to the applet container.
3885    * 
3886    * @param theApplet
3887    */
3888   public void embedAlignFrameInApplet(final JalviewLite theApplet)
3889   {
3890     // ////
3891     // Explicitly build the embedded menu panel for the on-page applet
3892     //
3893     // view cannot be closed if its actually on the page
3894     fileMenu.remove(closeMenuItem);
3895     fileMenu.remove(3); // Remove Separator
3896     // construct embedded menu, using default font
3897     embeddedMenu = makeEmbeddedPopupMenu(alignFrameMenuBar, false, false);
3898     // and actually add the components to the applet area
3899     theApplet.setLayout(new BorderLayout());
3900     theApplet.add(embeddedMenu, BorderLayout.NORTH);
3901     theApplet.add(statusBar, BorderLayout.SOUTH);
3902     // TODO should size be left to the layout manager?
3903     alignPanel.setSize(theApplet.getSize().width,
3904             theApplet.getSize().height - embeddedMenu.getHeight()
3905                     - statusBar.getHeight());
3906     theApplet.add(alignPanel, BorderLayout.CENTER);
3907     final AlignFrame me = this;
3908     theApplet.addFocusListener(new FocusListener()
3909     {
3910
3911       @Override
3912       public void focusLost(FocusEvent e)
3913       {
3914         if (theApplet.currentAlignFrame == me)
3915         {
3916           theApplet.currentAlignFrame = null;
3917         }
3918       }
3919
3920       @Override
3921       public void focusGained(FocusEvent e)
3922       {
3923         theApplet.currentAlignFrame = me;
3924       }
3925     });
3926     theApplet.validate();
3927   }
3928
3929   /**
3930    * create a new binding between structures in an existing jmol viewer instance
3931    * and an alignpanel with sequences that have existing PDBFile entries. Note,
3932    * this does not open a new Jmol window, or modify the display of the
3933    * structures in the original jmol window. Note This method doesn't work
3934    * without an additional javascript library to exchange messages between the
3935    * distinct applets. See http://issues.jalview.org/browse/JAL-621
3936    * 
3937    * @param viewer
3938    *          JmolViewer instance
3939    * @param sequenceIds
3940    *          - sequence Ids to search for associations
3941    */
3942   public SequenceStructureBinding addStructureViewInstance(
3943           Object jmolviewer, String[] sequenceIds)
3944   {
3945     Viewer viewer = null;
3946     try
3947     {
3948       viewer = (Viewer) jmolviewer;
3949     } catch (ClassCastException ex)
3950     {
3951       System.err.println("Unsupported viewer object :"
3952               + jmolviewer.getClass());
3953     }
3954     if (viewer == null)
3955     {
3956       System.err.println("Can't use this object as a structure viewer:"
3957               + jmolviewer.getClass());
3958       return null;
3959     }
3960     SequenceI[] seqs = null;
3961     if (sequenceIds == null || sequenceIds.length == 0)
3962     {
3963       seqs = viewport.getAlignment().getSequencesArray();
3964     }
3965     else
3966     {
3967       Vector sqi = new Vector();
3968       AlignmentI al = viewport.getAlignment();
3969       for (int sid = 0; sid < sequenceIds.length; sid++)
3970       {
3971         SequenceI sq = al.findName(sequenceIds[sid]);
3972         if (sq != null)
3973         {
3974           sqi.addElement(sq);
3975         }
3976       }
3977       if (sqi.size() > 0)
3978       {
3979         seqs = new SequenceI[sqi.size()];
3980         for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
3981         {
3982           seqs[sid] = (SequenceI) sqi.elementAt(sid);
3983         }
3984       }
3985       else
3986       {
3987         return null;
3988       }
3989     }
3990     AAStructureBindingModel jmv = null;
3991     // TODO: search for a jmv that involves viewer
3992     if (jmv == null)
3993     { // create a new viewer/jalview binding.
3994       jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][] { seqs });
3995     }
3996     return jmv;
3997
3998   }
3999
4000   /**
4001    * bind a pdb file to a sequence in the current view
4002    * 
4003    * @param sequenceId
4004    *          - sequenceId within the dataset.
4005    * @param pdbEntryString
4006    *          - the short name for the PDB file
4007    * @param pdbFile
4008    *          - pdb file - either a URL or a valid PDB file.
4009    * @return true if binding was as success TODO: consider making an exception
4010    *         structure for indicating when PDB parsing or sequenceId location
4011    *         fails.
4012    */
4013   public boolean addPdbFile(String sequenceId, String pdbEntryString,
4014           String pdbFile)
4015   {
4016     SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId);
4017     boolean needtoadd = false;
4018     if (toaddpdb != null)
4019     {
4020       Vector pdbe = toaddpdb.getAllPDBEntries();
4021       PDBEntry pdbentry = null;
4022       if (pdbe != null && pdbe.size() > 0)
4023       {
4024         for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
4025         {
4026           pdbentry = (PDBEntry) pdbe.elementAt(pe);
4027           if (!pdbentry.getId().equals(pdbEntryString)
4028                   && !pdbentry.getFile().equals(pdbFile))
4029           {
4030             pdbentry = null;
4031           }
4032           else
4033           {
4034             continue;
4035           }
4036         }
4037       }
4038       if (pdbentry == null)
4039       {
4040         pdbentry = new PDBEntry();
4041         pdbentry.setId(pdbEntryString);
4042         pdbentry.setFile(pdbFile);
4043         needtoadd = true; // add this new entry to sequence.
4044       }
4045       // resolve data source
4046       // TODO: this code should be a refactored to an io package
4047       DataSourceType protocol = AppletFormatAdapter.resolveProtocol(
4048               pdbFile, FileFormat.PDB);
4049       if (protocol == null)
4050       {
4051         return false;
4052       }
4053       if (needtoadd)
4054       {
4055         pdbentry.setProperty("protocol", protocol);
4056         toaddpdb.addPDBId(pdbentry);
4057         alignPanel.getStructureSelectionManager()
4058                 .registerPDBEntry(pdbentry);
4059       }
4060     }
4061     return true;
4062   }
4063
4064   private Object[] cleanSeqChainArrays(SequenceI[] seqs, String[] chains)
4065   {
4066     if (seqs != null)
4067     {
4068       Vector sequences = new Vector();
4069       for (int i = 0; i < seqs.length; i++)
4070       {
4071         if (seqs[i] != null)
4072         {
4073           sequences.addElement(new Object[] { seqs[i],
4074               (chains != null) ? chains[i] : null });
4075         }
4076       }
4077       seqs = new SequenceI[sequences.size()];
4078       chains = new String[sequences.size()];
4079       for (int i = 0, isize = sequences.size(); i < isize; i++)
4080       {
4081         Object[] oj = (Object[]) sequences.elementAt(i);
4082
4083         seqs[i] = (SequenceI) oj[0];
4084         chains[i] = (String) oj[1];
4085       }
4086     }
4087     return new Object[] { seqs, chains };
4088
4089   }
4090
4091   public void newStructureView(JalviewLite applet, PDBEntry pdb,
4092           SequenceI[] seqs, String[] chains, DataSourceType protocol)
4093   {
4094     // Scrub any null sequences from the array
4095     Object[] sqch = cleanSeqChainArrays(seqs, chains);
4096     seqs = (SequenceI[]) sqch[0];
4097     chains = (String[]) sqch[1];
4098     if (seqs == null || seqs.length == 0)
4099     {
4100       System.err
4101               .println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
4102     }
4103     if (protocol == null)
4104     {
4105       String sourceType = (String) pdb.getProperty("protocol");
4106       try
4107       {
4108         protocol = DataSourceType.valueOf(sourceType);
4109       } catch (IllegalArgumentException e)
4110       {
4111         // ignore
4112       }
4113       if (protocol == null)
4114       {
4115         System.err.println("Couldn't work out protocol to open structure: "
4116                 + pdb.getId());
4117         return;
4118       }
4119     }
4120     if (applet.useXtrnalSviewer)
4121     {
4122       // register the association(s) and quit, don't create any windows.
4123       if (StructureSelectionManager.getStructureSelectionManager(applet)
4124               .setMapping(seqs, chains, pdb.getFile(), protocol) == null)
4125       {
4126         System.err.println("Failed to map " + pdb.getFile() + " ("
4127                 + protocol + ") to any sequences");
4128       }
4129       return;
4130     }
4131     if (applet.isAlignPdbStructures() && applet.jmolAvailable)
4132     {
4133       // can only do alignments with Jmol
4134       // find the last jmol window assigned to this alignment
4135       AppletJmol ajm = null, tajm;
4136       Vector jmols = applet.getAppletWindow(AppletJmol.class);
4137       for (int i = 0, iSize = jmols.size(); i < iSize; i++)
4138       {
4139         tajm = (AppletJmol) jmols.elementAt(i);
4140         if (tajm.ap.alignFrame == this)
4141         {
4142           ajm = tajm;
4143           break;
4144         }
4145       }
4146       if (ajm != null)
4147       {
4148         System.err
4149                 .println("Incremental adding and aligning structure to existing Jmol view not yet implemented.");
4150         // try and add the pdb structure
4151         // ajm.addS
4152         ajm = null;
4153       }
4154     }
4155     // otherwise, create a new window
4156     if (applet.jmolAvailable)
4157     {
4158       new AppletJmol(pdb, seqs, chains, alignPanel,
4159               protocol);
4160       applet.lastFrameX += 40;
4161       applet.lastFrameY += 40;
4162     }
4163     else
4164     {
4165       new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
4166     }
4167
4168   }
4169
4170   public void alignedStructureView(JalviewLite applet, PDBEntry[] pdb,
4171           SequenceI[][] seqs, String[][] chains, String[] protocols)
4172   {
4173     // TODO Auto-generated method stub
4174     System.err.println("Aligned Structure View: Not yet implemented.");
4175   }
4176
4177   /**
4178    * modify the current selection, providing the user has not made a selection
4179    * already.
4180    * 
4181    * @param sel
4182    *          - sequences from this alignment
4183    * @param csel
4184    *          - columns to be selected on the alignment
4185    */
4186   public void select(SequenceGroup sel, ColumnSelection csel)
4187   {
4188     alignPanel.seqPanel.selection(sel, csel, null);
4189   }
4190
4191   public void scrollTo(int row, int column)
4192   {
4193     alignPanel.seqPanel.scrollTo(row, column);
4194   }
4195
4196   public void scrollToRow(int row)
4197   {
4198     alignPanel.seqPanel.scrollToRow(row);
4199   }
4200
4201   public void scrollToColumn(int column)
4202   {
4203     alignPanel.seqPanel.scrollToColumn(column);
4204   }
4205
4206   /**
4207    * @return the alignments unique ID.
4208    */
4209   public String getSequenceSetId()
4210   {
4211     return viewport.getSequenceSetId();
4212   }
4213
4214   /**
4215    * Load the (T-Coffee) score file from the specified url
4216    * 
4217    * @param source
4218    *          File/URL/T-COFFEE score file contents
4219    * @throws IOException
4220    * @return true if alignment was annotated with data from source
4221    */
4222   public boolean loadScoreFile(String source) throws IOException
4223   {
4224
4225     TCoffeeScoreFile file = new TCoffeeScoreFile(source,
4226             AppletFormatAdapter.checkProtocol(source));
4227     if (!file.isValid())
4228     {
4229       // TODO: raise dialog for gui
4230       System.err.println("Problems parsing T-Coffee scores: "
4231               + file.getWarningMessage());
4232       System.err.println("Origin was:\n" + source);
4233       return false;
4234     }
4235
4236     /*
4237      * check that the score matrix matches the alignment dimensions
4238      */
4239     AlignmentI aln;
4240     if ((aln = viewport.getAlignment()) != null
4241             && (aln.getHeight() != file.getHeight() || aln.getWidth() != file
4242                     .getWidth()))
4243     {
4244       // TODO: raise a dialog box here rather than bomb out.
4245       System.err
4246               .println("The scores matrix does not match the alignment dimensions");
4247
4248     }
4249
4250     // TODO add parameter to indicate if matching should be done
4251     if (file.annotateAlignment(alignPanel.getAlignment(), false))
4252     {
4253       alignPanel.fontChanged();
4254       tcoffeeColour.setEnabled(true);
4255       // switch to this color
4256       changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4257       return true;
4258     }
4259     else
4260     {
4261       System.err.println("Problems resolving T-Coffee scores:");
4262       if (file.getWarningMessage() != null)
4263       {
4264         System.err.println(file.getWarningMessage());
4265       }
4266     }
4267     return false;
4268   }
4269
4270   public SplitFrame getSplitFrame()
4271   {
4272     return this.splitFrame;
4273   }
4274
4275   public void setSplitFrame(SplitFrame sf)
4276   {
4277     this.splitFrame = sf;
4278   }
4279
4280   // may not need this
4281   @Override
4282   public void setShowSeqFeatures(boolean b)
4283   {
4284     // showSeqFeatures.setSelected(b);
4285     viewport.setShowSequenceFeatures(b);
4286
4287   }
4288
4289   @Override
4290   public void setMenusForViewport()
4291   {
4292     // setMenusFromViewport(viewport);
4293
4294   }
4295
4296   @Override
4297   public void refreshFeatureUI(boolean enableIfNecessary)
4298   {
4299     if (enableIfNecessary)
4300     {
4301       sequenceFeatures.setState(true);
4302       alignPanel.av.setShowSequenceFeatures(true);
4303     }
4304   }
4305
4306   @Override
4307   public FeatureSettingsControllerI getFeatureSettingsUI()
4308   {
4309     return alignPanel.av.featureSettings;
4310   }
4311
4312 }