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