c524d9b2b720737d3cc35e6a99a3abbda35a5f3a
[jalview.git] / forester / java / src / org / forester / archaeopteryx / MainFrameApplication.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon
8 // All rights reserved
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 //
24 // Contact: phylosoft @ gmail . com
25 // WWW: www.phylosoft.org/forester
26
27 package org.forester.archaeopteryx;
28
29 import java.awt.BorderLayout;
30 import java.awt.Font;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ComponentAdapter;
33 import java.awt.event.ComponentEvent;
34 import java.awt.event.WindowAdapter;
35 import java.awt.event.WindowEvent;
36 import java.io.File;
37 import java.io.FileInputStream;
38 import java.io.IOException;
39 import java.net.MalformedURLException;
40 import java.net.URL;
41 import java.util.ArrayList;
42 import java.util.HashSet;
43 import java.util.List;
44 import java.util.Set;
45
46 import javax.swing.ButtonGroup;
47 import javax.swing.JCheckBoxMenuItem;
48 import javax.swing.JFileChooser;
49 import javax.swing.JMenu;
50 import javax.swing.JMenuBar;
51 import javax.swing.JMenuItem;
52 import javax.swing.JOptionPane;
53 import javax.swing.JRadioButtonMenuItem;
54 import javax.swing.UIManager;
55 import javax.swing.UnsupportedLookAndFeelException;
56 import javax.swing.WindowConstants;
57 import javax.swing.event.ChangeEvent;
58 import javax.swing.event.ChangeListener;
59 import javax.swing.filechooser.FileFilter;
60 import javax.swing.plaf.synth.SynthLookAndFeel;
61
62 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
63 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
64 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
65 import org.forester.archaeopteryx.Util.GraphicsExportType;
66 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
67 import org.forester.archaeopteryx.tools.GoAnnotation;
68 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
69 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
70 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
71 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
72 import org.forester.archaeopteryx.tools.TaxonomyDataObtainer;
73 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
74 import org.forester.archaeopteryx.webservices.WebservicesManager;
75 import org.forester.io.parsers.FastaParser;
76 import org.forester.io.parsers.GeneralMsaParser;
77 import org.forester.io.parsers.PhylogenyParser;
78 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
79 import org.forester.io.parsers.nhx.NHXParser;
80 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
81 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
82 import org.forester.io.parsers.tol.TolParser;
83 import org.forester.io.writers.PhylogenyWriter;
84 import org.forester.io.writers.SequenceWriter;
85 import org.forester.msa.Msa;
86 import org.forester.msa.MsaFormatException;
87 import org.forester.phylogeny.Phylogeny;
88 import org.forester.phylogeny.PhylogenyMethods;
89 import org.forester.phylogeny.PhylogenyNode;
90 import org.forester.phylogeny.data.Confidence;
91 import org.forester.phylogeny.data.Taxonomy;
92 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
93 import org.forester.phylogeny.factories.PhylogenyFactory;
94 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
95 import org.forester.sdi.GSDI;
96 import org.forester.sdi.SDI;
97 import org.forester.sdi.SDIR;
98 import org.forester.sdi.SDIse;
99 import org.forester.sequence.Sequence;
100 import org.forester.util.BasicDescriptiveStatistics;
101 import org.forester.util.BasicTable;
102 import org.forester.util.BasicTableParser;
103 import org.forester.util.DescriptiveStatistics;
104 import org.forester.util.ForesterUtil;
105 import org.forester.util.ForesterUtil.PhylogenyNodeField;
106 import org.forester.util.ForesterUtil.TAXONOMY_EXTRACTION;
107 import org.forester.util.WindowsUtils;
108
109 class DefaultFilter extends FileFilter {
110
111     @Override
112     public boolean accept( final File f ) {
113         final String file_name = f.getName().trim().toLowerCase();
114         return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
115                 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
116                 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
117                 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
118                 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
119                 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
120                 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
121                 || file_name.endsWith( ".con" ) || f.isDirectory();
122     }
123
124     @Override
125     public String getDescription() {
126         return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
127     }
128 }
129
130 class GraphicsFileFilter extends FileFilter {
131
132     @Override
133     public boolean accept( final File f ) {
134         final String file_name = f.getName().trim().toLowerCase();
135         return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
136                 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
137     }
138
139     @Override
140     public String getDescription() {
141         return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
142     }
143 }
144
145 class MsaFileFilter extends FileFilter {
146
147     @Override
148     public boolean accept( final File f ) {
149         final String file_name = f.getName().trim().toLowerCase();
150         return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
151                 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
152     }
153
154     @Override
155     public String getDescription() {
156         return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
157     }
158 }
159
160 class SequencesFileFilter extends FileFilter {
161
162     @Override
163     public boolean accept( final File f ) {
164         final String file_name = f.getName().trim().toLowerCase();
165         return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
166                 || file_name.endsWith( ".seqs" ) || f.isDirectory();
167     }
168
169     @Override
170     public String getDescription() {
171         return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
172     }
173 }
174
175 public final class MainFrameApplication extends MainFrame {
176
177     static final String                      INFER_ANCESTOR_TAXONOMIES             = "Infer Ancestor Taxonomies";
178     static final String                      OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";
179     private final static int                 FRAME_X_SIZE                          = 800;
180     private final static int                 FRAME_Y_SIZE                          = 800;
181     // Filters for the file-open dialog (classes defined in this file)
182     private final static NHFilter            nhfilter                              = new NHFilter();
183     private final static NHXFilter           nhxfilter                             = new NHXFilter();
184     private final static XMLFilter           xmlfilter                             = new XMLFilter();
185     private final static TolFilter           tolfilter                             = new TolFilter();
186     private final static NexusFilter         nexusfilter                           = new NexusFilter();
187     private final static PdfFilter           pdffilter                             = new PdfFilter();
188     private final static GraphicsFileFilter  graphicsfilefilter                    = new GraphicsFileFilter();
189     private final static MsaFileFilter       msafilter                             = new MsaFileFilter();
190     private final static SequencesFileFilter seqsfilter                            = new SequencesFileFilter();
191     private final static DefaultFilter       defaultfilter                         = new DefaultFilter();
192     private static final long                serialVersionUID                      = -799735726778865234L;
193     private final JFileChooser               _values_filechooser;
194     private final JFileChooser               _open_filechooser;
195     private final JFileChooser               _msa_filechooser;
196     private final JFileChooser               _seqs_filechooser;
197     private final JFileChooser               _open_filechooser_for_species_tree;
198     private final JFileChooser               _save_filechooser;
199     private final JFileChooser               _writetopdf_filechooser;
200     private final JFileChooser               _writetographics_filechooser;
201     // Analysis menu
202     private JMenu                            _analysis_menu;
203     private JMenuItem                        _load_species_tree_item;
204     private JMenuItem                        _sdi_item;
205     private JMenuItem                        _gsdi_item;
206     private JMenuItem                        _root_min_dups_item;
207     private JMenuItem                        _root_min_cost_l_item;
208     private JMenuItem                        _lineage_inference;
209     private JMenuItem                        _function_analysis;
210     // Application-only print menu items
211     private JMenuItem                        _print_item;
212     private JMenuItem                        _write_to_pdf_item;
213     private JMenuItem                        _write_to_jpg_item;
214     private JMenuItem                        _write_to_gif_item;
215     private JMenuItem                        _write_to_tif_item;
216     private JMenuItem                        _write_to_png_item;
217     private JMenuItem                        _write_to_bmp_item;
218     private Phylogeny                        _species_tree;
219     private File                             _current_dir;
220     private ButtonGroup                      _radio_group_1;
221     // Others:
222     double                                   _min_not_collapse                     = Constants.MIN_NOT_COLLAPSE_DEFAULT;
223     // Phylogeny Inference menu
224     private JMenu                            _inference_menu;
225     private JMenuItem                        _inference_from_msa_item;
226     private JMenuItem                        _inference_from_seqs_item;
227     // Phylogeny Inference
228     private PhylogeneticInferenceOptions     _phylogenetic_inference_options       = null;
229     private Msa                              _msa                                  = null;
230     private File                             _msa_file                             = null;
231     private List<Sequence>                   _seqs                                 = null;
232     private File                             _seqs_file                            = null;
233     // expression values menu:
234     JMenuItem                                _read_values_jmi;
235
236     private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
237         _configuration = config;
238         if ( _configuration == null ) {
239             throw new IllegalArgumentException( "configuration is null" );
240         }
241         try {
242             boolean synth_exception = false;
243             if ( Constants.__SYNTH_LF ) {
244                 try {
245                     final SynthLookAndFeel synth = new SynthLookAndFeel();
246                     synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),
247                                 MainFrameApplication.class );
248                     UIManager.setLookAndFeel( synth );
249                 }
250                 catch ( final Exception ex ) {
251                     synth_exception = true;
252                     ForesterUtil.printWarningMessage( Constants.PRG_NAME,
253                                                       "could not create synth look and feel: "
254                                                               + ex.getLocalizedMessage() );
255                 }
256             }
257             if ( !Constants.__SYNTH_LF || synth_exception ) {
258                 if ( _configuration.isUseNativeUI() ) {
259                     UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
260                 }
261                 else {
262                     UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
263                 }
264             }
265             //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
266         }
267         catch ( final UnsupportedLookAndFeelException e ) {
268             Util.dieWithSystemError( "unsupported look and feel: " + e.toString() );
269         }
270         catch ( final ClassNotFoundException e ) {
271             Util.dieWithSystemError( "class not found exception: " + e.toString() );
272         }
273         catch ( final InstantiationException e ) {
274             Util.dieWithSystemError( "instantiation exception: " + e.toString() );
275         }
276         catch ( final IllegalAccessException e ) {
277             Util.dieWithSystemError( "illegal access exception: " + e.toString() );
278         }
279         catch ( final Exception e ) {
280             Util.dieWithSystemError( e.toString() );
281         }
282         // hide until everything is ready
283         setVisible( false );
284         setOptions( Options.createInstance( _configuration ) );
285         setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
286         _textframe = null;
287         _species_tree = null;
288         // set title
289         setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
290         _mainpanel = new MainPanel( _configuration, this );
291         // The file dialogs
292         _open_filechooser = new JFileChooser();
293         _open_filechooser.setCurrentDirectory( new File( "." ) );
294         _open_filechooser.setMultiSelectionEnabled( false );
295         _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );
296         _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
297         _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
298         _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
299         _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );
300         _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
301         _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );
302         _open_filechooser_for_species_tree = new JFileChooser();
303         _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );
304         _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
305         _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );
306         _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );
307         _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );
308         _save_filechooser = new JFileChooser();
309         _save_filechooser.setCurrentDirectory( new File( "." ) );
310         _save_filechooser.setMultiSelectionEnabled( false );
311         _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );
312         _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
313         _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
314         _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
315         _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
316         _writetopdf_filechooser = new JFileChooser();
317         _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );
318         _writetographics_filechooser = new JFileChooser();
319         _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );
320         // Msa:
321         _msa_filechooser = new JFileChooser();
322         _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
323         _msa_filechooser.setCurrentDirectory( new File( "." ) );
324         _msa_filechooser.setMultiSelectionEnabled( false );
325         _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
326         _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );
327         // Seqs:
328         _seqs_filechooser = new JFileChooser();
329         _seqs_filechooser.setName( "Read Sequences File" );
330         _seqs_filechooser.setCurrentDirectory( new File( "." ) );
331         _seqs_filechooser.setMultiSelectionEnabled( false );
332         _seqs_filechooser.addChoosableFileFilter( _seqs_filechooser.getAcceptAllFileFilter() );
333         _seqs_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
334         // Expression
335         _values_filechooser = new JFileChooser();
336         _values_filechooser.setCurrentDirectory( new File( "." ) );
337         _values_filechooser.setMultiSelectionEnabled( false );
338         // build the menu bar
339         _jmenubar = new JMenuBar();
340         if ( !_configuration.isUseNativeUI() ) {
341             _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
342         }
343         buildFileMenu();
344         if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
345             buildPhylogeneticInferenceMenu();
346         }
347         buildAnalysisMenu();
348         buildToolsMenu();
349         buildViewMenu();
350         buildFontSizeMenu();
351         buildOptionsMenu();
352         buildTypeMenu();
353         buildHelpMenu();
354         setJMenuBar( _jmenubar );
355         _jmenubar.add( _help_jmenu );
356         _contentpane = getContentPane();
357         _contentpane.setLayout( new BorderLayout() );
358         _contentpane.add( _mainpanel, BorderLayout.CENTER );
359         // App is this big
360         setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
361         //        addWindowFocusListener( new WindowAdapter() {
362         //
363         //            @Override
364         //            public void windowGainedFocus( WindowEvent e ) {
365         //                requestFocusInWindow();
366         //            }
367         //        } );
368         // The window listener
369         setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
370         addWindowListener( new WindowAdapter() {
371
372             @Override
373             public void windowClosing( final WindowEvent e ) {
374                 if ( isUnsavedDataPresent() ) {
375                     final int r = JOptionPane.showConfirmDialog( null,
376                                                                  "Exit despite potentially unsaved changes?",
377                                                                  "Exit?",
378                                                                  JOptionPane.YES_NO_OPTION );
379                     if ( r != JOptionPane.YES_OPTION ) {
380                         return;
381                     }
382                 }
383                 else {
384                     final int r = JOptionPane.showConfirmDialog( null,
385                                                                  "Exit Archaeopteryx?",
386                                                                  "Exit?",
387                                                                  JOptionPane.YES_NO_OPTION );
388                     if ( r != JOptionPane.YES_OPTION ) {
389                         return;
390                     }
391                 }
392                 exit();
393             }
394         } );
395         // The component listener
396         addComponentListener( new ComponentAdapter() {
397
398             @Override
399             public void componentResized( final ComponentEvent e ) {
400                 if ( _mainpanel.getCurrentTreePanel() != null ) {
401                     _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel()
402                                                                                        .getWidth(),
403                                                                                _mainpanel.getCurrentTreePanel()
404                                                                                        .getHeight(),
405                                                                                false );
406                 }
407             }
408         } );
409         requestFocusInWindow();
410         // addKeyListener( this );
411         setVisible( true );
412         if ( ( phys != null ) && ( phys.length > 0 ) ) {
413             Util.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
414             validate();
415             getMainPanel().getControlPanel().showWholeAll();
416             getMainPanel().getControlPanel().showWhole();
417         }
418         activateSaveAllIfNeeded();
419         // ...and its children
420         _contentpane.repaint();
421         System.gc();
422     }
423
424     private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
425         // Reads the config file (false, false => not url, not applet):
426         this( phys, new Configuration( config_file, false, false ), title );
427     }
428
429     @Override
430     public void actionPerformed( final ActionEvent e ) {
431         try {
432             super.actionPerformed( e );
433             final Object o = e.getSource();
434             // Handle app-specific actions here:
435             if ( o == _open_item ) {
436                 readPhylogeniesFromFile();
437             }
438             else if ( o == _save_item ) {
439                 writeToFile( _mainpanel.getCurrentPhylogeny() );
440                 // If subtree currently displayed, save it, instead of complete
441                 // tree.
442             }
443             else if ( o == _new_item ) {
444                 newTree();
445             }
446             else if ( o == _save_all_item ) {
447                 writeAllToFile();
448             }
449             else if ( o == _close_item ) {
450                 closeCurrentPane();
451             }
452             else if ( o == _write_to_pdf_item ) {
453                 writeToPdf( _mainpanel.getCurrentPhylogeny() );
454             }
455             else if ( o == _write_to_jpg_item ) {
456                 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
457             }
458             else if ( o == _write_to_png_item ) {
459                 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
460             }
461             else if ( o == _write_to_gif_item ) {
462                 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
463             }
464             else if ( o == _write_to_tif_item ) {
465                 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
466             }
467             else if ( o == _write_to_bmp_item ) {
468                 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
469             }
470             else if ( o == _print_item ) {
471                 print();
472             }
473             else if ( o == _load_species_tree_item ) {
474                 readSpeciesTreeFromFile();
475             }
476             else if ( o == _sdi_item ) {
477                 if ( isSubtreeDisplayed() ) {
478                     return;
479                 }
480                 executeSDI();
481             }
482             else if ( o == _lineage_inference ) {
483                 if ( isSubtreeDisplayed() ) {
484                     JOptionPane.showMessageDialog( this,
485                                                    "Subtree is shown.",
486                                                    "Cannot infer ancestral taxonomies",
487                                                    JOptionPane.ERROR_MESSAGE );
488                     return;
489                 }
490                 executeLineageInference();
491             }
492             else if ( o == _function_analysis ) {
493                 executeFunctionAnalysis();
494             }
495             else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
496                 if ( isSubtreeDisplayed() ) {
497                     return;
498                 }
499                 obtainDetailedTaxonomicInformation();
500             }
501             else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
502                 if ( isSubtreeDisplayed() ) {
503                     return;
504                 }
505                 obtainDetailedTaxonomicInformationDelete();
506             }
507             else if ( o == _obtain_uniprot_seq_information_jmi ) {
508                 obtainUniProtSequenceInformation();
509             }
510             else if ( o == _read_values_jmi ) {
511                 if ( isSubtreeDisplayed() ) {
512                     return;
513                 }
514                 addExpressionValuesFromFile();
515             }
516             else if ( o == _move_node_names_to_tax_sn_jmi ) {
517                 moveNodeNamesToTaxSn();
518             }
519             else if ( o == _move_node_names_to_seq_names_jmi ) {
520                 moveNodeNamesToSeqNames();
521             }
522             else if ( o == _extract_tax_code_from_node_names_jmi ) {
523                 extractTaxCodeFromNodeNames();
524             }
525             else if ( o == _gsdi_item ) {
526                 if ( isSubtreeDisplayed() ) {
527                     return;
528                 }
529                 executeGSDI();
530             }
531             else if ( o == _root_min_dups_item ) {
532                 if ( isSubtreeDisplayed() ) {
533                     return;
534                 }
535                 executeSDIR( false );
536             }
537             else if ( o == _root_min_cost_l_item ) {
538                 if ( isSubtreeDisplayed() ) {
539                     return;
540                 }
541                 executeSDIR( true );
542             }
543             else if ( o == _graphics_export_visible_only_cbmi ) {
544                 updateOptions( getOptions() );
545             }
546             else if ( o == _antialias_print_cbmi ) {
547                 updateOptions( getOptions() );
548             }
549             else if ( o == _print_black_and_white_cbmi ) {
550                 updateOptions( getOptions() );
551             }
552             else if ( o == _print_using_actual_size_cbmi ) {
553                 updateOptions( getOptions() );
554             }
555             else if ( o == _graphics_export_using_actual_size_cbmi ) {
556                 updateOptions( getOptions() );
557             }
558             else if ( o == _print_size_mi ) {
559                 choosePrintSize();
560             }
561             else if ( o == _choose_pdf_width_mi ) {
562                 choosePdfWidth();
563             }
564             else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
565                 updateOptions( getOptions() );
566             }
567             else if ( o == _replace_underscores_cbmi ) {
568                 if ( ( _extract_pfam_style_tax_codes_cbmi != null ) && _replace_underscores_cbmi.isSelected() ) {
569                     _extract_pfam_style_tax_codes_cbmi.setSelected( false );
570                 }
571                 updateOptions( getOptions() );
572             }
573             else if ( o == _collapse_below_threshold ) {
574                 if ( isSubtreeDisplayed() ) {
575                     return;
576                 }
577                 collapseBelowThreshold();
578             }
579             else if ( o == _extract_pfam_style_tax_codes_cbmi ) {
580                 if ( ( _replace_underscores_cbmi != null ) && _extract_pfam_style_tax_codes_cbmi.isSelected() ) {
581                     _replace_underscores_cbmi.setSelected( false );
582                 }
583                 updateOptions( getOptions() );
584             }
585             else if ( o == _inference_from_msa_item ) {
586                 executePhyleneticInference( false );
587             }
588             else if ( o == _inference_from_seqs_item ) {
589                 executePhyleneticInference( true );
590             }
591             _contentpane.repaint();
592         }
593         catch ( final Exception ex ) {
594             Util.unexpectedException( ex );
595         }
596         catch ( final Error err ) {
597             Util.unexpectedError( err );
598         }
599     }
600
601     void buildAnalysisMenu() {
602         _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
603         _analysis_menu.add( _sdi_item = new JMenuItem( "SDI (Speciation Duplication Inference)" ) );
604         if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
605             _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
606         }
607         _analysis_menu.addSeparator();
608         _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
609         _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
610         _analysis_menu.addSeparator();
611         _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
612         customizeJMenuItem( _sdi_item );
613         customizeJMenuItem( _gsdi_item );
614         customizeJMenuItem( _root_min_dups_item );
615         customizeJMenuItem( _root_min_cost_l_item );
616         customizeJMenuItem( _load_species_tree_item );
617         _analysis_menu.addSeparator();
618         _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
619         customizeJMenuItem( _lineage_inference );
620         _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
621         _jmenubar.add( _analysis_menu );
622     }
623
624     void buildPhylogeneticInferenceMenu() {
625         _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
626         _inference_menu
627                 .add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment...(EXPERIMENTAL - DO NOT USE!!) " ) );
628         customizeJMenuItem( _inference_from_msa_item );
629         _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
630         _inference_menu
631                 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences...(EXPERIMENTAL - DO NOT USE!!) " ) );
632         customizeJMenuItem( _inference_from_seqs_item );
633         _inference_from_seqs_item.setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
634         _jmenubar.add( _inference_menu );
635     }
636
637     @Override
638     void buildFileMenu() {
639         _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
640         _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
641         _file_jmenu.addSeparator();
642         _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
643         _file_jmenu.addSeparator();
644         final WebservicesManager webservices_manager = WebservicesManager.getInstance();
645         _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
646                 .getAvailablePhylogeniesWebserviceClients().size() ];
647         for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
648             final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
649             _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
650             _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
651         }
652         if ( getConfiguration().isEditable() ) {
653             _file_jmenu.addSeparator();
654             _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
655             _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
656         }
657         _file_jmenu.addSeparator();
658         _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
659         _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
660         _save_all_item.setToolTipText( "Write all phylogenies to one file." );
661         _save_all_item.setEnabled( false );
662         _file_jmenu.addSeparator();
663         _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
664         if ( Util.canWriteFormat( "tif" ) || Util.canWriteFormat( "tiff" ) || Util.canWriteFormat( "TIF" ) ) {
665             _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
666         }
667         _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
668         _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
669         if ( Util.canWriteFormat( "gif" ) ) {
670             _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
671         }
672         if ( Util.canWriteFormat( "bmp" ) ) {
673             _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
674         }
675         _file_jmenu.addSeparator();
676         _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
677         _file_jmenu.addSeparator();
678         _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
679         _close_item.setToolTipText( "To close the current pane." );
680         _close_item.setEnabled( true );
681         _file_jmenu.addSeparator();
682         _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
683         // For print in color option item
684         customizeJMenuItem( _open_item );
685         _open_item
686                 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
687         customizeJMenuItem( _open_url_item );
688         for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
689             customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
690         }
691         customizeJMenuItem( _save_item );
692         if ( getConfiguration().isEditable() ) {
693             customizeJMenuItem( _new_item );
694         }
695         customizeJMenuItem( _close_item );
696         customizeJMenuItem( _save_all_item );
697         customizeJMenuItem( _write_to_pdf_item );
698         customizeJMenuItem( _write_to_png_item );
699         customizeJMenuItem( _write_to_jpg_item );
700         customizeJMenuItem( _write_to_gif_item );
701         customizeJMenuItem( _write_to_tif_item );
702         customizeJMenuItem( _write_to_bmp_item );
703         customizeJMenuItem( _print_item );
704         customizeJMenuItem( _exit_item );
705         _jmenubar.add( _file_jmenu );
706     }
707
708     void buildOptionsMenu() {
709         _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
710         _options_jmenu.addChangeListener( new ChangeListener() {
711
712             @Override
713             public void stateChanged( final ChangeEvent e ) {
714                 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
715                 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
716                 MainFrame
717                         .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
718                 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
719                         .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
720                 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
721                 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
722                 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
723                                                                      _show_scale_cbmi,
724                                                                      _show_branch_length_values_cbmi,
725                                                                      _non_lined_up_cladograms_rbmi,
726                                                                      _uniform_cladograms_rbmi,
727                                                                      _ext_node_dependent_cladogram_rbmi,
728                                                                      _label_direction_cbmi );
729                 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
730                 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
731                 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
732             }
733         } );
734         _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
735         _options_jmenu
736                 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
737         _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
738         _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
739         _radio_group_1 = new ButtonGroup();
740         _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
741         _radio_group_1.add( _uniform_cladograms_rbmi );
742         _radio_group_1.add( _non_lined_up_cladograms_rbmi );
743         _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
744         _options_jmenu
745                 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
746         _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
747         _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
748         _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
749         _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
750         _options_jmenu
751                 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
752         _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
753         _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
754         _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
755         _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
756         _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
757         _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
758         _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
759         _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
760         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
761             _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
762         }
763         _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
764         _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
765         _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
766         _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
767         _options_jmenu.addSeparator();
768         _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
769         _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
770         _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
771         _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
772         _options_jmenu.addSeparator();
773         _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
774                                                       getConfiguration() ) );
775         _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
776         _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
777         _options_jmenu
778                 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
779         _options_jmenu
780                 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
781         _options_jmenu
782                 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
783         _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
784         _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
785         _options_jmenu.addSeparator();
786         _options_jmenu
787                 .add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Parsing:" ), getConfiguration() ) );
788         _options_jmenu
789                 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Numbers Are Confidence Values" ) );
790         _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
791         _options_jmenu
792                 .add( _extract_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) );
793         customizeJMenuItem( _choose_font_mi );
794         customizeJMenuItem( _choose_minimal_confidence_mi );
795         customizeJMenuItem( _switch_colors_mi );
796         customizeJMenuItem( _print_size_mi );
797         customizeJMenuItem( _choose_pdf_width_mi );
798         customizeJMenuItem( _overview_placment_mi );
799         customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
800         customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
801         customizeJMenuItem( _cycle_node_shape_mi );
802         customizeJMenuItem( _cycle_node_fill_mi );
803         customizeJMenuItem( _choose_node_size_mi );
804         customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
805         customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
806         customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
807         customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
808         customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
809         customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
810         customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
811         customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
812                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
813         customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
814                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
815         customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
816                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
817         customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
818         customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
819         customizeCheckBoxMenuItem( _label_direction_cbmi,
820                                    getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
821         customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
822         customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
823         customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
824                 .isInternalNumberAreConfidenceForNhParsing() );
825         customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
826                 .isExtractPfamTaxonomyCodesInNhParsing() );
827         customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
828         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
829         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
830         customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
831         customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
832         customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
833                 .isGraphicsExportUsingActualSize() );
834         _jmenubar.add( _options_jmenu );
835     }
836
837     void buildToolsMenu() {
838         _tools_menu = createMenu( "Tools", getConfiguration() );
839         _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
840         customizeJMenuItem( _confcolor_item );
841         _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );
842         customizeJMenuItem( _color_rank_jmi );
843         _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );
844         _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
845         customizeJMenuItem( _taxcolor_item );
846         _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
847         _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
848         customizeJMenuItem( _remove_branch_color_item );
849         _tools_menu.addSeparator();
850         _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
851         customizeJMenuItem( _midpoint_root_item );
852         _tools_menu.addSeparator();
853         _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
854         customizeJMenuItem( _collapse_species_specific_subtrees );
855         _tools_menu
856                 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
857         customizeJMenuItem( _collapse_below_threshold );
858         _collapse_below_threshold
859                 .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
860         _tools_menu.addSeparator();
861         _tools_menu
862                 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
863         customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
864         _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
865         _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
866         customizeJMenuItem( _move_node_names_to_seq_names_jmi );
867         _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
868         _tools_menu
869                 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
870         customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
871         _extract_tax_code_from_node_names_jmi
872                 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
873         _tools_menu.addSeparator();
874         _tools_menu
875                 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
876         customizeJMenuItem( _infer_common_sn_names_item );
877         _tools_menu.addSeparator();
878         _tools_menu
879                 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );
880         customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
881         _obtain_detailed_taxonomic_information_jmi
882                 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
883         _tools_menu
884                 .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
885         customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
886         _obtain_detailed_taxonomic_information_deleting_jmi
887                 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
888         _tools_menu
889                 .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
890         customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
891         _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
892         _tools_menu.addSeparator();
893         if ( !Constants.__RELEASE ) {
894             _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
895             customizeJMenuItem( _function_analysis );
896             _function_analysis
897                     .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
898             _tools_menu.addSeparator();
899         }
900         _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
901         customizeJMenuItem( _read_values_jmi );
902         _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
903         _jmenubar.add( _tools_menu );
904     }
905
906     private void choosePdfWidth() {
907         final String s = ( String ) JOptionPane.showInputDialog( this,
908                                                                  "Please enter the default line width for PDF export.\n"
909                                                                          + "[current value: "
910                                                                          + getOptions().getPrintLineWidth() + "]\n",
911                                                                  "Line Width for PDF Export",
912                                                                  JOptionPane.QUESTION_MESSAGE,
913                                                                  null,
914                                                                  null,
915                                                                  getOptions().getPrintLineWidth() );
916         if ( !ForesterUtil.isEmpty( s ) ) {
917             boolean success = true;
918             float f = 0.0f;
919             final String m_str = s.trim();
920             if ( !ForesterUtil.isEmpty( m_str ) ) {
921                 try {
922                     f = Float.parseFloat( m_str );
923                 }
924                 catch ( final Exception ex ) {
925                     success = false;
926                 }
927             }
928             else {
929                 success = false;
930             }
931             if ( success && ( f > 0.0 ) ) {
932                 getOptions().setPrintLineWidth( f );
933             }
934         }
935     }
936
937     private void choosePrintSize() {
938         final String s = ( String ) JOptionPane.showInputDialog( this,
939                                                                  "Please enter values for width and height,\nseparated by a comma.\n"
940                                                                          + "[current values: "
941                                                                          + getOptions().getPrintSizeX() + ", "
942                                                                          + getOptions().getPrintSizeY() + "]\n"
943                                                                          + "[A4: " + Constants.A4_SIZE_X + ", "
944                                                                          + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
945                                                                          + Constants.US_LETTER_SIZE_X + ", "
946                                                                          + Constants.US_LETTER_SIZE_Y + "]",
947                                                                  "Default Size for Graphics Export",
948                                                                  JOptionPane.QUESTION_MESSAGE,
949                                                                  null,
950                                                                  null,
951                                                                  getOptions().getPrintSizeX() + ", "
952                                                                          + getOptions().getPrintSizeY() );
953         if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
954             boolean success = true;
955             int x = 0;
956             int y = 0;
957             final String[] str_ary = s.split( "," );
958             if ( str_ary.length == 2 ) {
959                 final String x_str = str_ary[ 0 ].trim();
960                 final String y_str = str_ary[ 1 ].trim();
961                 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
962                     try {
963                         x = Integer.parseInt( x_str );
964                         y = Integer.parseInt( y_str );
965                     }
966                     catch ( final Exception ex ) {
967                         success = false;
968                     }
969                 }
970                 else {
971                     success = false;
972                 }
973             }
974             else {
975                 success = false;
976             }
977             if ( success && ( x > 1 ) && ( y > 1 ) ) {
978                 getOptions().setPrintSizeX( x );
979                 getOptions().setPrintSizeY( y );
980             }
981         }
982     }
983
984     @Override
985     void close() {
986         if ( isUnsavedDataPresent() ) {
987             final int r = JOptionPane.showConfirmDialog( this,
988                                                          "Exit despite potentially unsaved changes?",
989                                                          "Exit?",
990                                                          JOptionPane.YES_NO_OPTION );
991             if ( r != JOptionPane.YES_OPTION ) {
992                 return;
993             }
994         }
995         exit();
996     }
997
998     private void closeCurrentPane() {
999         if ( getMainPanel().getCurrentTreePanel() != null ) {
1000             if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
1001                 final int r = JOptionPane.showConfirmDialog( this,
1002                                                              "Close tab despite potentially unsaved changes?",
1003                                                              "Close Tab?",
1004                                                              JOptionPane.YES_NO_OPTION );
1005                 if ( r != JOptionPane.YES_OPTION ) {
1006                     return;
1007                 }
1008             }
1009             getMainPanel().closeCurrentPane();
1010             activateSaveAllIfNeeded();
1011         }
1012     }
1013
1014     private void collapse( final Phylogeny phy, final double m ) {
1015         final PhylogenyNodeIterator it = phy.iteratorPostorder();
1016         final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
1017         double min_support = Double.MAX_VALUE;
1018         boolean conf_present = false;
1019         while ( it.hasNext() ) {
1020             final PhylogenyNode n = it.next();
1021             if ( !n.isExternal() && !n.isRoot() ) {
1022                 final List<Confidence> c = n.getBranchData().getConfidences();
1023                 if ( ( c != null ) && ( c.size() > 0 ) ) {
1024                     conf_present = true;
1025                     double max = 0;
1026                     for( final Confidence confidence : c ) {
1027                         if ( confidence.getValue() > max ) {
1028                             max = confidence.getValue();
1029                         }
1030                     }
1031                     if ( max < getMinNotCollapseConfidenceValue() ) {
1032                         to_be_removed.add( n );
1033                     }
1034                     if ( max < min_support ) {
1035                         min_support = max;
1036                     }
1037                 }
1038             }
1039         }
1040         if ( conf_present ) {
1041             for( final PhylogenyNode node : to_be_removed ) {
1042                 PhylogenyMethods.removeNode( node, phy );
1043             }
1044             if ( to_be_removed.size() > 0 ) {
1045                 phy.externalNodesHaveChanged();
1046                 phy.hashIDs();
1047                 phy.recalculateNumberOfExternalDescendants( true );
1048                 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1049                 getCurrentTreePanel().setEdited( true );
1050                 getCurrentTreePanel().repaint();
1051             }
1052             if ( to_be_removed.size() > 0 ) {
1053                 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1054                         + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1055                         + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1056             }
1057             else {
1058                 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1059                         + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1060             }
1061         }
1062         else {
1063             JOptionPane.showMessageDialog( this,
1064                                            "No branch collapsed because no confidence values present",
1065                                            "No confidence values present",
1066                                            JOptionPane.INFORMATION_MESSAGE );
1067         }
1068     }
1069
1070     private void collapseBelowThreshold() {
1071         if ( getCurrentTreePanel() != null ) {
1072             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1073             if ( ( phy != null ) && !phy.isEmpty() ) {
1074                 final String s = ( String ) JOptionPane.showInputDialog( this,
1075                                                                          "Please enter the minimum confidence value\n",
1076                                                                          "Minimal Confidence Value",
1077                                                                          JOptionPane.QUESTION_MESSAGE,
1078                                                                          null,
1079                                                                          null,
1080                                                                          getMinNotCollapseConfidenceValue() );
1081                 if ( !ForesterUtil.isEmpty( s ) ) {
1082                     boolean success = true;
1083                     double m = 0.0;
1084                     final String m_str = s.trim();
1085                     if ( !ForesterUtil.isEmpty( m_str ) ) {
1086                         try {
1087                             m = Double.parseDouble( m_str );
1088                         }
1089                         catch ( final Exception ex ) {
1090                             success = false;
1091                         }
1092                     }
1093                     else {
1094                         success = false;
1095                     }
1096                     if ( success && ( m >= 0.0 ) ) {
1097                         setMinNotCollapseConfidenceValue( m );
1098                         collapse( phy, m );
1099                     }
1100                 }
1101             }
1102         }
1103     }
1104
1105     private PhyloXmlParser createPhyloXmlParser() {
1106         PhyloXmlParser xml_parser = null;
1107         if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1108             try {
1109                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1110             }
1111             catch ( final Exception e ) {
1112                 JOptionPane.showMessageDialog( this,
1113                                                e.getLocalizedMessage(),
1114                                                "failed to create validating XML parser",
1115                                                JOptionPane.WARNING_MESSAGE );
1116             }
1117         }
1118         if ( xml_parser == null ) {
1119             xml_parser = new PhyloXmlParser();
1120         }
1121         return xml_parser;
1122     }
1123
1124     void executeGSDI() {
1125         if ( !isOKforSDI( false, true ) ) {
1126             return;
1127         }
1128         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1129             JOptionPane.showMessageDialog( this,
1130                                            "Gene tree is not rooted.",
1131                                            "Cannot execute GSDI",
1132                                            JOptionPane.ERROR_MESSAGE );
1133             return;
1134         }
1135         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1136         gene_tree.setAllNodesToNotCollapse();
1137         gene_tree.recalculateNumberOfExternalDescendants( false );
1138         GSDI gsdi = null;
1139         int duplications = -1;
1140         try {
1141             gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
1142             duplications = gsdi.getDuplicationsSum();
1143         }
1144         catch ( final Exception e ) {
1145             JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1146         }
1147         gene_tree.setRerootable( false );
1148         _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1149         getControlPanel().setShowEvents( true );
1150         showWhole();
1151         _mainpanel.getCurrentTreePanel().setEdited( true );
1152         JOptionPane.showMessageDialog( this,
1153                                        "Number of duplications: " + duplications,
1154                                        "GSDI successfully completed",
1155                                        JOptionPane.INFORMATION_MESSAGE );
1156     }
1157
1158     void executeFunctionAnalysis() {
1159         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1160             return;
1161         }
1162         final GoAnnotation a = new GoAnnotation( this,
1163                                                  _mainpanel.getCurrentTreePanel(),
1164                                                  _mainpanel.getCurrentPhylogeny() );
1165         new Thread( a ).start();
1166     }
1167
1168     void executeLineageInference() {
1169         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1170             return;
1171         }
1172         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1173             JOptionPane.showMessageDialog( this,
1174                                            "Phylogeny is not rooted.",
1175                                            "Cannot infer ancestral taxonomies",
1176                                            JOptionPane.ERROR_MESSAGE );
1177             return;
1178         }
1179         final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1180                                                                                   _mainpanel.getCurrentTreePanel(),
1181                                                                                   _mainpanel.getCurrentPhylogeny()
1182                                                                                           .copy() );
1183         new Thread( inferrer ).start();
1184     }
1185
1186     private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1187         final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1188                                                                       getPhylogeneticInferenceOptions(),
1189                                                                       from_unaligned_seqs );
1190         dialog.activate();
1191         if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1192             if ( !from_unaligned_seqs ) {
1193                 if ( getMsa() != null ) {
1194                     final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1195                                                                                     getPhylogeneticInferenceOptions()
1196                                                                                             .copy(), this );
1197                     new Thread( inferrer ).start();
1198                 }
1199                 else {
1200                     JOptionPane.showMessageDialog( this,
1201                                                    "No multiple sequence alignment selected",
1202                                                    "Phylogenetic Inference Not Launched",
1203                                                    JOptionPane.WARNING_MESSAGE );
1204                 }
1205             }
1206             else {
1207                 if ( getSeqs() != null ) {
1208                     final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1209                                                                                     getPhylogeneticInferenceOptions()
1210                                                                                             .copy(), this );
1211                     new Thread( inferrer ).start();
1212                 }
1213                 else {
1214                     JOptionPane.showMessageDialog( this,
1215                                                    "No input sequences selected",
1216                                                    "Phylogenetic Inference Not Launched",
1217                                                    JOptionPane.WARNING_MESSAGE );
1218                 }
1219             }
1220         }
1221     }
1222
1223     void executeSDI() {
1224         if ( !isOKforSDI( true, true ) ) {
1225             return;
1226         }
1227         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1228             JOptionPane.showMessageDialog( this,
1229                                            "Gene tree is not rooted",
1230                                            "Cannot execute SDI",
1231                                            JOptionPane.ERROR_MESSAGE );
1232             return;
1233         }
1234         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1235         gene_tree.setAllNodesToNotCollapse();
1236         gene_tree.recalculateNumberOfExternalDescendants( false );
1237         SDI sdi = null;
1238         int duplications = -1;
1239         try {
1240             sdi = new SDIse( gene_tree, _species_tree.copy() );
1241             duplications = sdi.getDuplicationsSum();
1242         }
1243         catch ( final Exception e ) {
1244             JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
1245         }
1246         gene_tree.setRerootable( false );
1247         _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1248         getControlPanel().setShowEvents( true );
1249         showWhole();
1250         _mainpanel.getCurrentTreePanel().setEdited( true );
1251         JOptionPane.showMessageDialog( this,
1252                                        "Number of duplications: " + duplications,
1253                                        "SDI successfully completed",
1254                                        JOptionPane.INFORMATION_MESSAGE );
1255     }
1256
1257     void executeSDIR( final boolean minimize_cost ) {
1258         if ( !isOKforSDI( true, true ) ) {
1259             return;
1260         }
1261         Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1262         final SDIR sdiunrooted = new SDIR();
1263         gene_tree.setAllNodesToNotCollapse();
1264         gene_tree.recalculateNumberOfExternalDescendants( false );
1265         try {
1266             gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1267                                            !minimize_cost, // minimize sum of dups
1268                                            true, // minimize height
1269                                            true, // return tree(s)
1270                                            1 )[ 0 ]; // # of trees to return
1271         }
1272         catch ( final Exception e ) {
1273             JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1274             return;
1275         }
1276         final int duplications = sdiunrooted.getMinimalDuplications();
1277         gene_tree.setRerootable( false );
1278         _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1279         getControlPanel().setShowEvents( true );
1280         showWhole();
1281         _mainpanel.getCurrentTreePanel().setEdited( true );
1282         JOptionPane.showMessageDialog( this,
1283                                        "Number of duplications: " + duplications,
1284                                        "SDIR successfully completed",
1285                                        JOptionPane.INFORMATION_MESSAGE );
1286     }
1287
1288     void exit() {
1289         removeTextFrame();
1290         _mainpanel.terminate();
1291         _contentpane.removeAll();
1292         setVisible( false );
1293         dispose();
1294         System.exit( 0 );
1295     }
1296
1297     private void extractTaxCodeFromNodeNames() {
1298         if ( getCurrentTreePanel() != null ) {
1299             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1300             if ( ( phy != null ) && !phy.isEmpty() ) {
1301                 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1302                 while ( it.hasNext() ) {
1303                     final PhylogenyNode n = it.next();
1304                     final String name = n.getName().trim();
1305                     if ( !ForesterUtil.isEmpty( name ) ) {
1306                         final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
1307                                                                                           false,
1308                                                                                           TAXONOMY_EXTRACTION.YES );
1309                         if ( !ForesterUtil.isEmpty( code ) ) {
1310                             PhylogenyMethods.setTaxonomyCode( n, code );
1311                         }
1312                     }
1313                 }
1314             }
1315         }
1316     }
1317
1318     private ControlPanel getControlPanel() {
1319         return getMainPanel().getControlPanel();
1320     }
1321
1322     private File getCurrentDir() {
1323         if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1324             if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
1325                 try {
1326                     _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1327                 }
1328                 catch ( final Exception e ) {
1329                     _current_dir = null;
1330                 }
1331             }
1332         }
1333         if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1334             if ( System.getProperty( "user.home" ) != null ) {
1335                 _current_dir = new File( System.getProperty( "user.home" ) );
1336             }
1337             else if ( System.getProperty( "user.dir" ) != null ) {
1338                 _current_dir = new File( System.getProperty( "user.dir" ) );
1339             }
1340         }
1341         return _current_dir;
1342     }
1343
1344     @Override
1345     public MainPanel getMainPanel() {
1346         return _mainpanel;
1347     }
1348
1349     private double getMinNotCollapseConfidenceValue() {
1350         return _min_not_collapse;
1351     }
1352
1353     boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1354         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1355             return false;
1356         }
1357         else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1358             JOptionPane.showMessageDialog( this,
1359                                            "No species tree loaded",
1360                                            "Cannot execute SDI",
1361                                            JOptionPane.ERROR_MESSAGE );
1362             return false;
1363         }
1364         else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1365             JOptionPane.showMessageDialog( this,
1366                                            "Species tree is not completely binary",
1367                                            "Cannot execute SDI",
1368                                            JOptionPane.ERROR_MESSAGE );
1369             return false;
1370         }
1371         else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1372             JOptionPane.showMessageDialog( this,
1373                                            "Gene tree is not completely binary",
1374                                            "Cannot execute SDI",
1375                                            JOptionPane.ERROR_MESSAGE );
1376             return false;
1377         }
1378         else {
1379             return true;
1380         }
1381     }
1382
1383     private boolean isUnsavedDataPresent() {
1384         final List<TreePanel> tps = getMainPanel().getTreePanels();
1385         for( final TreePanel tp : tps ) {
1386             if ( tp.isEdited() ) {
1387                 return true;
1388             }
1389         }
1390         return false;
1391     }
1392
1393     private void moveNodeNamesToSeqNames() {
1394         if ( getCurrentTreePanel() != null ) {
1395             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1396             if ( ( phy != null ) && !phy.isEmpty() ) {
1397                 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
1398             }
1399         }
1400     }
1401
1402     private void moveNodeNamesToTaxSn() {
1403         if ( getCurrentTreePanel() != null ) {
1404             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1405             if ( ( phy != null ) && !phy.isEmpty() ) {
1406                 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
1407             }
1408         }
1409     }
1410
1411     private void newTree() {
1412         final Phylogeny[] phys = new Phylogeny[ 1 ];
1413         final Phylogeny phy = new Phylogeny();
1414         final PhylogenyNode node = new PhylogenyNode();
1415         phy.setRoot( node );
1416         phy.setRooted( true );
1417         phys[ 0 ] = phy;
1418         Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1419         _mainpanel.getControlPanel().showWhole();
1420         _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1421         _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1422         if ( getMainPanel().getMainFrame() == null ) {
1423             // Must be "E" applet version.
1424             ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1425                     .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1426         }
1427         else {
1428             getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1429         }
1430         activateSaveAllIfNeeded();
1431         System.gc();
1432     }
1433
1434     private void obtainDetailedTaxonomicInformation() {
1435         if ( getCurrentTreePanel() != null ) {
1436             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1437             if ( ( phy != null ) && !phy.isEmpty() ) {
1438                 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1439                                                                          _mainpanel.getCurrentTreePanel(),
1440                                                                          phy.copy() );
1441                 new Thread( t ).start();
1442             }
1443         }
1444     }
1445
1446     private void obtainDetailedTaxonomicInformationDelete() {
1447         if ( getCurrentTreePanel() != null ) {
1448             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1449             if ( ( phy != null ) && !phy.isEmpty() ) {
1450                 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1451                                                                          _mainpanel.getCurrentTreePanel(),
1452                                                                          phy.copy(),
1453                                                                          true );
1454                 new Thread( t ).start();
1455             }
1456         }
1457     }
1458
1459     private void obtainUniProtSequenceInformation() {
1460         if ( getCurrentTreePanel() != null ) {
1461             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1462             if ( ( phy != null ) && !phy.isEmpty() ) {
1463                 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1464                                                                          _mainpanel.getCurrentTreePanel(),
1465                                                                          phy.copy() );
1466                 new Thread( u ).start();
1467             }
1468         }
1469     }
1470
1471     private void print() {
1472         if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1473                 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1474             return;
1475         }
1476         if ( !getOptions().isPrintUsingActualSize() ) {
1477             getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1478                                                             getOptions().getPrintSizeY() - 140,
1479                                                             true );
1480             getCurrentTreePanel().resetPreferredSize();
1481             getCurrentTreePanel().repaint();
1482         }
1483         final String job_name = Constants.PRG_NAME;
1484         boolean error = false;
1485         String printer_name = null;
1486         try {
1487             printer_name = Printer.print( getCurrentTreePanel(), job_name );
1488         }
1489         catch ( final Exception e ) {
1490             error = true;
1491             JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1492         }
1493         if ( !error && ( printer_name != null ) ) {
1494             String msg = "Printing data sent to printer";
1495             if ( printer_name.length() > 1 ) {
1496                 msg += " [" + printer_name + "]";
1497             }
1498             JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1499         }
1500         if ( !getOptions().isPrintUsingActualSize() ) {
1501             getControlPanel().showWhole();
1502         }
1503     }
1504
1505     private void printPhylogenyToPdf( final String file_name ) {
1506         if ( !getOptions().isPrintUsingActualSize() ) {
1507             getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1508                                                             getOptions().getPrintSizeY(),
1509                                                             true );
1510             getCurrentTreePanel().resetPreferredSize();
1511             getCurrentTreePanel().repaint();
1512         }
1513         String pdf_written_to = "";
1514         boolean error = false;
1515         try {
1516             if ( getOptions().isPrintUsingActualSize() ) {
1517                 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1518                                                                   getCurrentTreePanel(),
1519                                                                   getCurrentTreePanel().getWidth(),
1520                                                                   getCurrentTreePanel().getHeight() );
1521             }
1522             else {
1523                 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1524                         .getPrintSizeX(), getOptions().getPrintSizeY() );
1525             }
1526         }
1527         catch ( final IOException e ) {
1528             error = true;
1529             JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1530         }
1531         if ( !error ) {
1532             if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1533                 JOptionPane.showMessageDialog( this,
1534                                                "Wrote PDF to: " + pdf_written_to,
1535                                                "Information",
1536                                                JOptionPane.INFORMATION_MESSAGE );
1537             }
1538             else {
1539                 JOptionPane.showMessageDialog( this,
1540                                                "There was an unknown problem when attempting to write to PDF file: \""
1541                                                        + file_name + "\"",
1542                                                "Error",
1543                                                JOptionPane.ERROR_MESSAGE );
1544             }
1545         }
1546         if ( !getOptions().isPrintUsingActualSize() ) {
1547             getControlPanel().showWhole();
1548         }
1549     }
1550
1551     private void addExpressionValuesFromFile() {
1552         if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1553             JOptionPane.showMessageDialog( this,
1554                                            "Need to load evolutionary tree first",
1555                                            "Can Not Read Expression Values",
1556                                            JOptionPane.WARNING_MESSAGE );
1557             return;
1558         }
1559         final File my_dir = getCurrentDir();
1560         if ( my_dir != null ) {
1561             _values_filechooser.setCurrentDirectory( my_dir );
1562         }
1563         final int result = _values_filechooser.showOpenDialog( _contentpane );
1564         final File file = _values_filechooser.getSelectedFile();
1565         if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1566             BasicTable<String> t = null;
1567             try {
1568                 t = BasicTableParser.parse( file, "\t" );
1569                 if ( t.getNumberOfColumns() < 2 ) {
1570                     t = BasicTableParser.parse( file, "," );
1571                 }
1572                 if ( t.getNumberOfColumns() < 2 ) {
1573                     t = BasicTableParser.parse( file, " " );
1574                 }
1575             }
1576             catch ( final IOException e ) {
1577                 JOptionPane.showMessageDialog( this,
1578                                                e.getMessage(),
1579                                                "Could Not Read Expression Value Table",
1580                                                JOptionPane.ERROR_MESSAGE );
1581                 return;
1582             }
1583             if ( t.getNumberOfColumns() < 2 ) {
1584                 JOptionPane.showMessageDialog( this,
1585                                                "Table contains " + t.getNumberOfColumns() + " column(s)",
1586                                                "Problem with Expression Value Table",
1587                                                JOptionPane.ERROR_MESSAGE );
1588                 return;
1589             }
1590             if ( t.getNumberOfRows() < 1 ) {
1591                 JOptionPane.showMessageDialog( this,
1592                                                "Table contains zero rows",
1593                                                "Problem with Expression Value Table",
1594                                                JOptionPane.ERROR_MESSAGE );
1595                 return;
1596             }
1597             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1598             if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1599                 JOptionPane.showMessageDialog( this,
1600                                                "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1601                                                        + phy.getNumberOfExternalNodes() + " external nodes",
1602                                                "Warning",
1603                                                JOptionPane.WARNING_MESSAGE );
1604             }
1605             final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1606             int not_found = 0;
1607             for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1608                 final PhylogenyNode node = iter.next();
1609                 final String node_name = node.getName();
1610                 if ( !ForesterUtil.isEmpty( node_name ) ) {
1611                     int row = -1;
1612                     try {
1613                         row = t.findRow( node_name );
1614                     }
1615                     catch ( final IllegalArgumentException e ) {
1616                         JOptionPane
1617                                 .showMessageDialog( this,
1618                                                     e.getMessage(),
1619                                                     "Error Mapping Node Identifiers to Expression Value Identifiers",
1620                                                     JOptionPane.ERROR_MESSAGE );
1621                         return;
1622                     }
1623                     if ( row < 0 ) {
1624                         if ( node.isExternal() ) {
1625                             not_found++;
1626                         }
1627                         continue;
1628                     }
1629                     final List<Double> l = new ArrayList<Double>();
1630                     for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1631                         double d = -100;
1632                         try {
1633                             d = Double.parseDouble( t.getValueAsString( col, row ) );
1634                         }
1635                         catch ( final NumberFormatException e ) {
1636                             JOptionPane.showMessageDialog( this,
1637                                                            "Could not parse \"" + t.getValueAsString( col, row )
1638                                                                    + "\" into a decimal value",
1639                                                            "Issue with Expression Value Table",
1640                                                            JOptionPane.ERROR_MESSAGE );
1641                             return;
1642                         }
1643                         stats.addValue( d );
1644                         l.add( d );
1645                     }
1646                     if ( !l.isEmpty() ) {
1647                         if ( node.getNodeData().getProperties() != null ) {
1648                             node.getNodeData().getProperties()
1649                                     .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1650                         }
1651                         node.getNodeData().setVector( l );
1652                     }
1653                 }
1654             }
1655             if ( not_found > 0 ) {
1656                 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1657                         + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1658             }
1659             getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1660         }
1661     }
1662
1663     private void readPhylogeniesFromFile() {
1664         boolean exception = false;
1665         Phylogeny[] phys = null;
1666         // Set an initial directory if none set yet
1667         final File my_dir = getCurrentDir();
1668         _open_filechooser.setMultiSelectionEnabled( true );
1669         // Open file-open dialog and set current directory
1670         if ( my_dir != null ) {
1671             _open_filechooser.setCurrentDirectory( my_dir );
1672         }
1673         final int result = _open_filechooser.showOpenDialog( _contentpane );
1674         // All done: get the file
1675         final File[] files = _open_filechooser.getSelectedFiles();
1676         setCurrentDir( _open_filechooser.getCurrentDirectory() );
1677         boolean nhx_or_nexus = false;
1678         if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1679             for( final File file : files ) {
1680                 if ( ( file != null ) && !file.isDirectory() ) {
1681                     if ( _mainpanel.getCurrentTreePanel() != null ) {
1682                         _mainpanel.getCurrentTreePanel().setWaitCursor();
1683                     }
1684                     else {
1685                         _mainpanel.setWaitCursor();
1686                     }
1687                     if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1688                             || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1689                         try {
1690                             final NHXParser nhx = new NHXParser();
1691                             setSpecialOptionsForNhxParser( nhx );
1692                             phys = ForesterUtil.readPhylogenies( nhx, file );
1693                             nhx_or_nexus = true;
1694                         }
1695                         catch ( final Exception e ) {
1696                             exception = true;
1697                             exceptionOccuredDuringOpenFile( e );
1698                         }
1699                     }
1700                     else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1701                         warnIfNotPhyloXmlValidation( getConfiguration() );
1702                         try {
1703                             final PhyloXmlParser xml_parser = createPhyloXmlParser();
1704                             phys = ForesterUtil.readPhylogenies( xml_parser, file );
1705                         }
1706                         catch ( final Exception e ) {
1707                             exception = true;
1708                             exceptionOccuredDuringOpenFile( e );
1709                         }
1710                     }
1711                     else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1712                         try {
1713                             phys = ForesterUtil.readPhylogenies( new TolParser(), file );
1714                         }
1715                         catch ( final Exception e ) {
1716                             exception = true;
1717                             exceptionOccuredDuringOpenFile( e );
1718                         }
1719                     }
1720                     else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1721                         try {
1722                             final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1723                             setSpecialOptionsForNexParser( nex );
1724                             phys = ForesterUtil.readPhylogenies( nex, file );
1725                             nhx_or_nexus = true;
1726                         }
1727                         catch ( final Exception e ) {
1728                             exception = true;
1729                             exceptionOccuredDuringOpenFile( e );
1730                         }
1731                     }
1732                     // "*.*":
1733                     else {
1734                         try {
1735                             final PhylogenyParser parser = ForesterUtil
1736                                     .createParserDependingOnFileType( file, getConfiguration()
1737                                             .isValidatePhyloXmlAgainstSchema() );
1738                             if ( parser instanceof NexusPhylogeniesParser ) {
1739                                 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1740                                 setSpecialOptionsForNexParser( nex );
1741                                 nhx_or_nexus = true;
1742                             }
1743                             else if ( parser instanceof NHXParser ) {
1744                                 final NHXParser nhx = ( NHXParser ) parser;
1745                                 setSpecialOptionsForNhxParser( nhx );
1746                                 nhx_or_nexus = true;
1747                             }
1748                             else if ( parser instanceof PhyloXmlParser ) {
1749                                 warnIfNotPhyloXmlValidation( getConfiguration() );
1750                             }
1751                             phys = ForesterUtil.readPhylogenies( parser, file );
1752                         }
1753                         catch ( final Exception e ) {
1754                             exception = true;
1755                             exceptionOccuredDuringOpenFile( e );
1756                         }
1757                     }
1758                     if ( _mainpanel.getCurrentTreePanel() != null ) {
1759                         _mainpanel.getCurrentTreePanel().setArrowCursor();
1760                     }
1761                     else {
1762                         _mainpanel.setArrowCursor();
1763                     }
1764                     if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1765                         boolean one_desc = false;
1766                         if ( nhx_or_nexus ) {
1767                             for( final Phylogeny phy : phys ) {
1768                                 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1769                                     ForesterUtil.transferInternalNodeNamesToConfidence( phy );
1770                                 }
1771                                 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1772                                     one_desc = true;
1773                                     break;
1774                                 }
1775                             }
1776                         }
1777                         Util.addPhylogeniesToTabs( phys,
1778                                                    file.getName(),
1779                                                    file.getAbsolutePath(),
1780                                                    getConfiguration(),
1781                                                    getMainPanel() );
1782                         _mainpanel.getControlPanel().showWhole();
1783                         if ( nhx_or_nexus && one_desc ) {
1784                             JOptionPane
1785                                     .showMessageDialog( this,
1786                                                         "One or more trees contain (a) node(s) with one descendant, "
1787                                                                 + ForesterUtil.LINE_SEPARATOR
1788                                                                 + "possibly indicating illegal parentheses within node names.",
1789                                                         "Warning: Possible Error in New Hampshire Formatted Data",
1790                                                         JOptionPane.WARNING_MESSAGE );
1791                         }
1792                     }
1793                 }
1794             }
1795         }
1796         activateSaveAllIfNeeded();
1797         System.gc();
1798     }
1799
1800     public void readSeqsFromFile() {
1801         // Set an initial directory if none set yet
1802         final File my_dir = getCurrentDir();
1803         _seqs_filechooser.setMultiSelectionEnabled( false );
1804         // Open file-open dialog and set current directory
1805         if ( my_dir != null ) {
1806             _seqs_filechooser.setCurrentDirectory( my_dir );
1807         }
1808         final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1809         // All done: get the seqs
1810         final File file = _seqs_filechooser.getSelectedFile();
1811         setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1812         if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1813             setSeqsFile( null );
1814             setSeqs( null );
1815             List<Sequence> seqs = null;
1816             try {
1817                 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1818                     seqs = FastaParser.parse( new FileInputStream( file ) );
1819                     for( final Sequence seq : seqs ) {
1820                         System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1821                     }
1822                 }
1823                 else {
1824                     //TODO error
1825                 }
1826             }
1827             catch ( final MsaFormatException e ) {
1828                 try {
1829                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1830                 }
1831                 catch ( final Exception ex ) {
1832                     // Do nothing.
1833                 }
1834                 JOptionPane.showMessageDialog( this,
1835                                                e.getLocalizedMessage(),
1836                                                "Multiple sequence file format error",
1837                                                JOptionPane.ERROR_MESSAGE );
1838                 return;
1839             }
1840             catch ( final IOException e ) {
1841                 try {
1842                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1843                 }
1844                 catch ( final Exception ex ) {
1845                     // Do nothing.
1846                 }
1847                 JOptionPane.showMessageDialog( this,
1848                                                e.getLocalizedMessage(),
1849                                                "Failed to read multiple sequence file",
1850                                                JOptionPane.ERROR_MESSAGE );
1851                 return;
1852             }
1853             catch ( final IllegalArgumentException e ) {
1854                 try {
1855                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1856                 }
1857                 catch ( final Exception ex ) {
1858                     // Do nothing.
1859                 }
1860                 JOptionPane.showMessageDialog( this,
1861                                                e.getLocalizedMessage(),
1862                                                "Unexpected error during reading of multiple sequence file",
1863                                                JOptionPane.ERROR_MESSAGE );
1864                 return;
1865             }
1866             catch ( final Exception e ) {
1867                 try {
1868                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1869                 }
1870                 catch ( final Exception ex ) {
1871                     // Do nothing.
1872                 }
1873                 e.printStackTrace();
1874                 JOptionPane.showMessageDialog( this,
1875                                                e.getLocalizedMessage(),
1876                                                "Unexpected error during reading of multiple sequence file",
1877                                                JOptionPane.ERROR_MESSAGE );
1878                 return;
1879             }
1880             if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1881                 JOptionPane.showMessageDialog( this,
1882                                                "Multiple sequence file is empty",
1883                                                "Illegal multiple sequence file",
1884                                                JOptionPane.ERROR_MESSAGE );
1885                 return;
1886             }
1887             if ( seqs.size() < 4 ) {
1888                 JOptionPane.showMessageDialog( this,
1889                                                "Multiple sequence file needs to contain at least 3 sequences",
1890                                                "Illegal multiple sequence file",
1891                                                JOptionPane.ERROR_MESSAGE );
1892                 return;
1893             }
1894             //  if ( msa.getLength() < 2 ) {
1895             //       JOptionPane.showMessageDialog( this,
1896             //                                      "Multiple sequence alignment needs to contain at least 2 residues",
1897             //                                      "Illegal multiple sequence file",
1898             //                                      JOptionPane.ERROR_MESSAGE );
1899             //       return;
1900             //   }
1901             System.gc();
1902             setSeqsFile( _seqs_filechooser.getSelectedFile() );
1903             setSeqs( seqs );
1904         }
1905     }
1906
1907     public void readMsaFromFile() {
1908         // Set an initial directory if none set yet
1909         final File my_dir = getCurrentDir();
1910         _msa_filechooser.setMultiSelectionEnabled( false );
1911         // Open file-open dialog and set current directory
1912         if ( my_dir != null ) {
1913             _msa_filechooser.setCurrentDirectory( my_dir );
1914         }
1915         final int result = _msa_filechooser.showOpenDialog( _contentpane );
1916         // All done: get the msa
1917         final File file = _msa_filechooser.getSelectedFile();
1918         setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1919         if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1920             setMsaFile( null );
1921             setMsa( null );
1922             Msa msa = null;
1923             try {
1924                 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1925                     msa = FastaParser.parseMsa( new FileInputStream( file ) );
1926                     System.out.println( msa.toString() );
1927                 }
1928                 else {
1929                     msa = GeneralMsaParser.parse( new FileInputStream( file ) );
1930                 }
1931             }
1932             catch ( final MsaFormatException e ) {
1933                 try {
1934                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1935                 }
1936                 catch ( final Exception ex ) {
1937                     // Do nothing.
1938                 }
1939                 JOptionPane.showMessageDialog( this,
1940                                                e.getLocalizedMessage(),
1941                                                "Multiple sequence alignment format error",
1942                                                JOptionPane.ERROR_MESSAGE );
1943                 return;
1944             }
1945             catch ( final IOException e ) {
1946                 try {
1947                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1948                 }
1949                 catch ( final Exception ex ) {
1950                     // Do nothing.
1951                 }
1952                 JOptionPane.showMessageDialog( this,
1953                                                e.getLocalizedMessage(),
1954                                                "Failed to read multiple sequence alignment",
1955                                                JOptionPane.ERROR_MESSAGE );
1956                 return;
1957             }
1958             catch ( final IllegalArgumentException e ) {
1959                 try {
1960                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1961                 }
1962                 catch ( final Exception ex ) {
1963                     // Do nothing.
1964                 }
1965                 JOptionPane.showMessageDialog( this,
1966                                                e.getLocalizedMessage(),
1967                                                "Unexpected error during reading of multiple sequence alignment",
1968                                                JOptionPane.ERROR_MESSAGE );
1969                 return;
1970             }
1971             catch ( final Exception e ) {
1972                 try {
1973                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1974                 }
1975                 catch ( final Exception ex ) {
1976                     // Do nothing.
1977                 }
1978                 e.printStackTrace();
1979                 JOptionPane.showMessageDialog( this,
1980                                                e.getLocalizedMessage(),
1981                                                "Unexpected error during reading of multiple sequence alignment",
1982                                                JOptionPane.ERROR_MESSAGE );
1983                 return;
1984             }
1985             if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
1986                 JOptionPane.showMessageDialog( this,
1987                                                "Multiple sequence alignment is empty",
1988                                                "Illegal Multiple Sequence Alignment",
1989                                                JOptionPane.ERROR_MESSAGE );
1990                 return;
1991             }
1992             if ( msa.getNumberOfSequences() < 4 ) {
1993                 JOptionPane.showMessageDialog( this,
1994                                                "Multiple sequence alignment needs to contain at least 3 sequences",
1995                                                "Illegal multiple sequence alignment",
1996                                                JOptionPane.ERROR_MESSAGE );
1997                 return;
1998             }
1999             if ( msa.getLength() < 2 ) {
2000                 JOptionPane.showMessageDialog( this,
2001                                                "Multiple sequence alignment needs to contain at least 2 residues",
2002                                                "Illegal multiple sequence alignment",
2003                                                JOptionPane.ERROR_MESSAGE );
2004                 return;
2005             }
2006             System.gc();
2007             setMsaFile( _msa_filechooser.getSelectedFile() );
2008             setMsa( msa );
2009         }
2010     }
2011
2012     @Override
2013     void readPhylogeniesFromURL() {
2014         URL url = null;
2015         Phylogeny[] phys = null;
2016         final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
2017         final String url_string = JOptionPane.showInputDialog( this,
2018                                                                message,
2019                                                                "Use URL/webservice to obtain a phylogeny",
2020                                                                JOptionPane.QUESTION_MESSAGE );
2021         boolean nhx_or_nexus = false;
2022         if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
2023             try {
2024                 url = new URL( url_string );
2025                 PhylogenyParser parser = null;
2026                 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
2027                     parser = new TolParser();
2028                 }
2029                 else {
2030                     parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
2031                             .isValidatePhyloXmlAgainstSchema() );
2032                 }
2033                 if ( parser instanceof NexusPhylogeniesParser ) {
2034                     nhx_or_nexus = true;
2035                 }
2036                 else if ( parser instanceof NHXParser ) {
2037                     nhx_or_nexus = true;
2038                 }
2039                 if ( _mainpanel.getCurrentTreePanel() != null ) {
2040                     _mainpanel.getCurrentTreePanel().setWaitCursor();
2041                 }
2042                 else {
2043                     _mainpanel.setWaitCursor();
2044                 }
2045                 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2046                 phys = factory.create( url.openStream(), parser );
2047             }
2048             catch ( final MalformedURLException e ) {
2049                 JOptionPane.showMessageDialog( this,
2050                                                "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
2051                                                "Malformed URL",
2052                                                JOptionPane.ERROR_MESSAGE );
2053             }
2054             catch ( final IOException e ) {
2055                 JOptionPane.showMessageDialog( this,
2056                                                "Could not read from " + url + "\n"
2057                                                        + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2058                                                "Failed to read URL",
2059                                                JOptionPane.ERROR_MESSAGE );
2060             }
2061             catch ( final Exception e ) {
2062                 JOptionPane.showMessageDialog( this,
2063                                                ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2064                                                "Unexpected Exception",
2065                                                JOptionPane.ERROR_MESSAGE );
2066             }
2067             finally {
2068                 if ( _mainpanel.getCurrentTreePanel() != null ) {
2069                     _mainpanel.getCurrentTreePanel().setArrowCursor();
2070                 }
2071                 else {
2072                     _mainpanel.setArrowCursor();
2073                 }
2074             }
2075             if ( ( phys != null ) && ( phys.length > 0 ) ) {
2076                 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2077                     for( final Phylogeny phy : phys ) {
2078                         ForesterUtil.transferInternalNodeNamesToConfidence( phy );
2079                     }
2080                 }
2081                 Util.addPhylogeniesToTabs( phys,
2082                                            new File( url.getFile() ).getName(),
2083                                            new File( url.getFile() ).toString(),
2084                                            getConfiguration(),
2085                                            getMainPanel() );
2086                 _mainpanel.getControlPanel().showWhole();
2087             }
2088         }
2089         activateSaveAllIfNeeded();
2090         System.gc();
2091     }
2092
2093     private void readSpeciesTreeFromFile() {
2094         Phylogeny t = null;
2095         boolean exception = false;
2096         final File my_dir = getCurrentDir();
2097         _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2098         if ( my_dir != null ) {
2099             _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2100         }
2101         final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2102         final File file = _open_filechooser_for_species_tree.getSelectedFile();
2103         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2104             if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2105                 try {
2106                     final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2107                     t = trees[ 0 ];
2108                 }
2109                 catch ( final Exception e ) {
2110                     exception = true;
2111                     exceptionOccuredDuringOpenFile( e );
2112                 }
2113             }
2114             else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2115                 try {
2116                     final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
2117                     t = trees[ 0 ];
2118                 }
2119                 catch ( final Exception e ) {
2120                     exception = true;
2121                     exceptionOccuredDuringOpenFile( e );
2122                 }
2123             }
2124             // "*.*":
2125             else {
2126                 try {
2127                     final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2128                     t = trees[ 0 ];
2129                 }
2130                 catch ( final Exception e ) {
2131                     exception = true;
2132                     exceptionOccuredDuringOpenFile( e );
2133                 }
2134             }
2135             if ( !exception && ( t != null ) && !t.isRooted() ) {
2136                 exception = true;
2137                 t = null;
2138                 JOptionPane.showMessageDialog( this,
2139                                                "Species tree is not rooted",
2140                                                "Species tree not loaded",
2141                                                JOptionPane.ERROR_MESSAGE );
2142             }
2143             if ( !exception && ( t != null ) ) {
2144                 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2145                 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2146                     final PhylogenyNode node = it.next();
2147                     if ( !node.getNodeData().isHasTaxonomy() ) {
2148                         exception = true;
2149                         t = null;
2150                         JOptionPane
2151                                 .showMessageDialog( this,
2152                                                     "Species tree contains external node(s) without taxonomy information",
2153                                                     "Species tree not loaded",
2154                                                     JOptionPane.ERROR_MESSAGE );
2155                         break;
2156                     }
2157                     else {
2158                         if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2159                             exception = true;
2160                             t = null;
2161                             JOptionPane.showMessageDialog( this,
2162                                                            "Taxonomy ["
2163                                                                    + node.getNodeData().getTaxonomy().asSimpleText()
2164                                                                    + "] is not unique in species tree",
2165                                                            "Species tree not loaded",
2166                                                            JOptionPane.ERROR_MESSAGE );
2167                             break;
2168                         }
2169                         else {
2170                             tax_set.add( node.getNodeData().getTaxonomy() );
2171                         }
2172                     }
2173                 }
2174             }
2175             if ( !exception && ( t != null ) ) {
2176                 _species_tree = t;
2177                 JOptionPane.showMessageDialog( this,
2178                                                "Species tree successfully loaded",
2179                                                "Species tree loaded",
2180                                                JOptionPane.INFORMATION_MESSAGE );
2181             }
2182             _contentpane.repaint();
2183             System.gc();
2184         }
2185     }
2186
2187     private void setCurrentDir( final File current_dir ) {
2188         _current_dir = current_dir;
2189     }
2190
2191     private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2192         _min_not_collapse = min_not_collapse;
2193     }
2194
2195     private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2196         nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2197     }
2198
2199     private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2200         nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2201         ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
2202         if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2203             te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
2204         }
2205         nhx.setTaxonomyExtraction( te );
2206     }
2207
2208     private void writeAllToFile() {
2209         if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2210             return;
2211         }
2212         final File my_dir = getCurrentDir();
2213         if ( my_dir != null ) {
2214             _save_filechooser.setCurrentDirectory( my_dir );
2215         }
2216         _save_filechooser.setSelectedFile( new File( "" ) );
2217         final int result = _save_filechooser.showSaveDialog( _contentpane );
2218         final File file = _save_filechooser.getSelectedFile();
2219         setCurrentDir( _save_filechooser.getCurrentDirectory() );
2220         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2221             if ( file.exists() ) {
2222                 final int i = JOptionPane.showConfirmDialog( this,
2223                                                              file + " already exists. Overwrite?",
2224                                                              "Warning",
2225                                                              JOptionPane.OK_CANCEL_OPTION,
2226                                                              JOptionPane.WARNING_MESSAGE );
2227                 if ( i != JOptionPane.OK_OPTION ) {
2228                     return;
2229                 }
2230                 else {
2231                     try {
2232                         file.delete();
2233                     }
2234                     catch ( final Exception e ) {
2235                         JOptionPane.showMessageDialog( this,
2236                                                        "Failed to delete: " + file,
2237                                                        "Error",
2238                                                        JOptionPane.WARNING_MESSAGE );
2239                     }
2240                 }
2241             }
2242             final int count = getMainPanel().getTabbedPane().getTabCount();
2243             final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2244             for( int i = 0; i < count; ++i ) {
2245                 trees.add( getMainPanel().getPhylogeny( i ) );
2246                 getMainPanel().getTreePanels().get( i ).setEdited( false );
2247             }
2248             final PhylogenyWriter writer = new PhylogenyWriter();
2249             try {
2250                 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2251             }
2252             catch ( final IOException e ) {
2253                 JOptionPane.showMessageDialog( this,
2254                                                "Failed to write to: " + file,
2255                                                "Error",
2256                                                JOptionPane.WARNING_MESSAGE );
2257             }
2258         }
2259     }
2260
2261     private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2262         try {
2263             final PhylogenyWriter writer = new PhylogenyWriter();
2264             writer.toNewHampshire( t, false, true, file );
2265         }
2266         catch ( final Exception e ) {
2267             exception = true;
2268             exceptionOccuredDuringSaveAs( e );
2269         }
2270         return exception;
2271     }
2272
2273     private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2274         try {
2275             final PhylogenyWriter writer = new PhylogenyWriter();
2276             writer.toNexus( file, t );
2277         }
2278         catch ( final Exception e ) {
2279             exception = true;
2280             exceptionOccuredDuringSaveAs( e );
2281         }
2282         return exception;
2283     }
2284
2285     private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2286         try {
2287             final PhylogenyWriter writer = new PhylogenyWriter();
2288             writer.toNewHampshireX( t, file );
2289         }
2290         catch ( final Exception e ) {
2291             exception = true;
2292             exceptionOccuredDuringSaveAs( e );
2293         }
2294         return exception;
2295     }
2296
2297     private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2298         try {
2299             final PhylogenyWriter writer = new PhylogenyWriter();
2300             writer.toPhyloXML( file, t, 0 );
2301         }
2302         catch ( final Exception e ) {
2303             exception = true;
2304             exceptionOccuredDuringSaveAs( e );
2305         }
2306         return exception;
2307     }
2308
2309     private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2310         _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2311                                                                    _mainpanel.getCurrentTreePanel().getHeight(),
2312                                                                    true );
2313         String file_written_to = "";
2314         boolean error = false;
2315         try {
2316             file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
2317                                                                  _mainpanel.getCurrentTreePanel().getWidth(),
2318                                                                  _mainpanel.getCurrentTreePanel().getHeight(),
2319                                                                  _mainpanel.getCurrentTreePanel(),
2320                                                                  _mainpanel.getControlPanel(),
2321                                                                  type,
2322                                                                  getOptions() );
2323         }
2324         catch ( final IOException e ) {
2325             error = true;
2326             JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2327         }
2328         if ( !error ) {
2329             if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2330                 JOptionPane.showMessageDialog( this,
2331                                                "Wrote image to: " + file_written_to,
2332                                                "Graphics Export",
2333                                                JOptionPane.INFORMATION_MESSAGE );
2334             }
2335             else {
2336                 JOptionPane.showMessageDialog( this,
2337                                                "There was an unknown problem when attempting to write to an image file: \""
2338                                                        + file_name + "\"",
2339                                                "Error",
2340                                                JOptionPane.ERROR_MESSAGE );
2341             }
2342         }
2343         _contentpane.repaint();
2344     }
2345
2346     private void writeToFile( final Phylogeny t ) {
2347         if ( t == null ) {
2348             return;
2349         }
2350         String initial_filename = null;
2351         if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2352             try {
2353                 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2354             }
2355             catch ( final IOException e ) {
2356                 initial_filename = null;
2357             }
2358         }
2359         if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2360             _save_filechooser.setSelectedFile( new File( initial_filename ) );
2361         }
2362         else {
2363             _save_filechooser.setSelectedFile( new File( "" ) );
2364         }
2365         final File my_dir = getCurrentDir();
2366         if ( my_dir != null ) {
2367             _save_filechooser.setCurrentDirectory( my_dir );
2368         }
2369         final int result = _save_filechooser.showSaveDialog( _contentpane );
2370         final File file = _save_filechooser.getSelectedFile();
2371         setCurrentDir( _save_filechooser.getCurrentDirectory() );
2372         boolean exception = false;
2373         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2374             if ( file.exists() ) {
2375                 final int i = JOptionPane.showConfirmDialog( this,
2376                                                              file + " already exists.\nOverwrite?",
2377                                                              "Overwrite?",
2378                                                              JOptionPane.OK_CANCEL_OPTION,
2379                                                              JOptionPane.QUESTION_MESSAGE );
2380                 if ( i != JOptionPane.OK_OPTION ) {
2381                     return;
2382                 }
2383                 else {
2384                     final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2385                     try {
2386                         ForesterUtil.copyFile( file, to );
2387                     }
2388                     catch ( final Exception e ) {
2389                         JOptionPane.showMessageDialog( this,
2390                                                        "Failed to create backup copy " + to,
2391                                                        "Failed to Create Backup Copy",
2392                                                        JOptionPane.WARNING_MESSAGE );
2393                     }
2394                     try {
2395                         file.delete();
2396                     }
2397                     catch ( final Exception e ) {
2398                         JOptionPane.showMessageDialog( this,
2399                                                        "Failed to delete: " + file,
2400                                                        "Failed to Delete",
2401                                                        JOptionPane.WARNING_MESSAGE );
2402                     }
2403                 }
2404             }
2405             if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2406                 exception = writeAsNewHampshire( t, exception, file );
2407             }
2408             else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2409                 exception = writeAsNHX( t, exception, file );
2410             }
2411             else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2412                 exception = writeAsPhyloXml( t, exception, file );
2413             }
2414             else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2415                 exception = writeAsNexus( t, exception, file );
2416             }
2417             // "*.*":
2418             else {
2419                 final String file_name = file.getName().trim().toLowerCase();
2420                 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2421                         || file_name.endsWith( ".tree" ) ) {
2422                     exception = writeAsNewHampshire( t, exception, file );
2423                 }
2424                 else if ( file_name.endsWith( ".nhx" ) ) {
2425                     exception = writeAsNHX( t, exception, file );
2426                 }
2427                 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2428                     exception = writeAsNexus( t, exception, file );
2429                 }
2430                 // XML is default:
2431                 else {
2432                     exception = writeAsPhyloXml( t, exception, file );
2433                 }
2434             }
2435             if ( !exception ) {
2436                 getMainPanel().setTitleOfSelectedTab( file.getName() );
2437                 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2438                 getMainPanel().getCurrentTreePanel().setEdited( false );
2439             }
2440         }
2441     }
2442
2443     private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2444         if ( ( t == null ) || t.isEmpty() ) {
2445             return;
2446         }
2447         String initial_filename = "";
2448         if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2449             initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2450         }
2451         if ( initial_filename.indexOf( '.' ) > 0 ) {
2452             initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2453         }
2454         initial_filename = initial_filename + "." + type;
2455         _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2456         final File my_dir = getCurrentDir();
2457         if ( my_dir != null ) {
2458             _writetographics_filechooser.setCurrentDirectory( my_dir );
2459         }
2460         final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2461         File file = _writetographics_filechooser.getSelectedFile();
2462         setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2463         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2464             if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2465                 file = new File( file.toString() + "." + type );
2466             }
2467             if ( file.exists() ) {
2468                 final int i = JOptionPane.showConfirmDialog( this,
2469                                                              file + " already exists. Overwrite?",
2470                                                              "Warning",
2471                                                              JOptionPane.OK_CANCEL_OPTION,
2472                                                              JOptionPane.WARNING_MESSAGE );
2473                 if ( i != JOptionPane.OK_OPTION ) {
2474                     return;
2475                 }
2476                 else {
2477                     try {
2478                         file.delete();
2479                     }
2480                     catch ( final Exception e ) {
2481                         JOptionPane.showMessageDialog( this,
2482                                                        "Failed to delete: " + file,
2483                                                        "Error",
2484                                                        JOptionPane.WARNING_MESSAGE );
2485                     }
2486                 }
2487             }
2488             writePhylogenyToGraphicsFile( file.toString(), type );
2489         }
2490     }
2491
2492     private void writeToPdf( final Phylogeny t ) {
2493         if ( ( t == null ) || t.isEmpty() ) {
2494             return;
2495         }
2496         String initial_filename = "";
2497         if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2498             initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2499         }
2500         if ( initial_filename.indexOf( '.' ) > 0 ) {
2501             initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2502         }
2503         initial_filename = initial_filename + ".pdf";
2504         _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2505         final File my_dir = getCurrentDir();
2506         if ( my_dir != null ) {
2507             _writetopdf_filechooser.setCurrentDirectory( my_dir );
2508         }
2509         final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2510         File file = _writetopdf_filechooser.getSelectedFile();
2511         setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2512         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2513             if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2514                 file = new File( file.toString() + ".pdf" );
2515             }
2516             if ( file.exists() ) {
2517                 final int i = JOptionPane.showConfirmDialog( this,
2518                                                              file + " already exists. Overwrite?",
2519                                                              "WARNING",
2520                                                              JOptionPane.OK_CANCEL_OPTION,
2521                                                              JOptionPane.WARNING_MESSAGE );
2522                 if ( i != JOptionPane.OK_OPTION ) {
2523                     return;
2524                 }
2525             }
2526             printPhylogenyToPdf( file.toString() );
2527         }
2528     }
2529
2530     static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2531         return new MainFrameApplication( phys, config, title );
2532     }
2533
2534     static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2535         return new MainFrameApplication( phys, config_file_name, title );
2536     }
2537
2538     static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2539         mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2540                 + o.getPrintSizeY() + ")" );
2541     }
2542
2543     static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2544         mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2545     }
2546
2547     static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2548         if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2549             JOptionPane
2550                     .showMessageDialog( null,
2551                                         ForesterUtil
2552                                                 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2553                                                            80 ),
2554                                         "Warning",
2555                                         JOptionPane.WARNING_MESSAGE );
2556         }
2557     }
2558
2559     private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2560         _phylogenetic_inference_options = phylogenetic_inference_options;
2561     }
2562
2563     private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2564         if ( _phylogenetic_inference_options == null ) {
2565             _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2566         }
2567         return _phylogenetic_inference_options;
2568     }
2569
2570     public Msa getMsa() {
2571         return _msa;
2572     }
2573
2574     void setMsa( final Msa msa ) {
2575         _msa = msa;
2576     }
2577
2578     void setMsaFile( final File msa_file ) {
2579         _msa_file = msa_file;
2580     }
2581
2582     public File getMsaFile() {
2583         return _msa_file;
2584     }
2585
2586     public List<Sequence> getSeqs() {
2587         return _seqs;
2588     }
2589
2590     void setSeqs( final List<Sequence> seqs ) {
2591         _seqs = seqs;
2592     }
2593
2594     void setSeqsFile( final File seqs_file ) {
2595         _seqs_file = seqs_file;
2596     }
2597
2598     public File getSeqsFile() {
2599         return _seqs_file;
2600     }
2601 } // MainFrameApplication.
2602
2603 class NexusFilter extends FileFilter {
2604
2605     @Override
2606     public boolean accept( final File f ) {
2607         final String file_name = f.getName().trim().toLowerCase();
2608         return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2609                 || file_name.endsWith( ".tre" ) || f.isDirectory();
2610     }
2611
2612     @Override
2613     public String getDescription() {
2614         return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2615     }
2616 } // NexusFilter
2617
2618 class NHFilter extends FileFilter {
2619
2620     @Override
2621     public boolean accept( final File f ) {
2622         final String file_name = f.getName().trim().toLowerCase();
2623         return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2624                 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2625                 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2626                 || f.isDirectory();
2627     }
2628
2629     @Override
2630     public String getDescription() {
2631         return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2632     }
2633 } // NHFilter
2634
2635 class NHXFilter extends FileFilter {
2636
2637     @Override
2638     public boolean accept( final File f ) {
2639         final String file_name = f.getName().trim().toLowerCase();
2640         return file_name.endsWith( ".nhx" ) || f.isDirectory();
2641     }
2642
2643     @Override
2644     public String getDescription() {
2645         return "NHX files (*.nhx)";
2646     }
2647 }
2648
2649 class PdfFilter extends FileFilter {
2650
2651     @Override
2652     public boolean accept( final File f ) {
2653         return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2654     }
2655
2656     @Override
2657     public String getDescription() {
2658         return "PDF files (*.pdf)";
2659     }
2660 } // PdfFilter
2661
2662 class TolFilter extends FileFilter {
2663
2664     @Override
2665     public boolean accept( final File f ) {
2666         final String file_name = f.getName().trim().toLowerCase();
2667         return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2668                 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2669     }
2670
2671     @Override
2672     public String getDescription() {
2673         return "Tree of Life files (*.tol, *.tolxml)";
2674     }
2675 } // TolFilter
2676
2677 class XMLFilter extends FileFilter {
2678
2679     @Override
2680     public boolean accept( final File f ) {
2681         final String file_name = f.getName().trim().toLowerCase();
2682         return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2683                 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2684     }
2685
2686     @Override
2687     public String getDescription() {
2688         return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";
2689     }
2690 } // XMLFilter