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