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