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