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