Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 20:42:03 GMT
  2. Package jalview.appletgui

File AlignFrame.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

682
1,710
131
2
4,370
3,489
568
0.33
13.05
65.5
4.34

Classes

Class Line # Actions
AlignFrame 123 1,688 566
0.00%
AlignFrame.AboutPanel 2999 22 2
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

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