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