in progress
[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.SequenceDataRetriver;
71 import org.forester.archaeopteryx.tools.TaxonomyDataObtainer;
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         //TODO FIXME ~~
766         //customizeCheckBoxMenuItem( _show_node_boxes_cbmi, getOptions().getDefaultNodeShape() );
767       //TODO FIXME ~~
768         customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
769         customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
770         customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
771         customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
772         customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
773         customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
774         customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
775         customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
776                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
777         customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
778                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
779         customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
780                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
781         customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
782         customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
783         customizeCheckBoxMenuItem( _label_direction_cbmi,
784                                    getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
785         customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
786         customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
787         customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
788                 .isInternalNumberAreConfidenceForNhParsing() );
789         customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
790                 .isExtractPfamTaxonomyCodesInNhParsing() );
791         customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
792         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
793         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
794         customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
795         customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
796         customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
797                 .isGraphicsExportUsingActualSize() );
798         _jmenubar.add( _options_jmenu );
799     }
800
801     void buildToolsMenu() {
802         _tools_menu = createMenu( "Tools", getConfiguration() );
803         _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
804         customizeJMenuItem( _confcolor_item );
805         _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
806         customizeJMenuItem( _taxcolor_item );
807         _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
808         _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
809         customizeJMenuItem( _remove_branch_color_item );
810         _tools_menu.addSeparator();
811         _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
812         customizeJMenuItem( _midpoint_root_item );
813         _tools_menu.addSeparator();
814         _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
815         customizeJMenuItem( _collapse_species_specific_subtrees );
816         _tools_menu
817                 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
818         customizeJMenuItem( _collapse_below_threshold );
819         _collapse_below_threshold
820                 .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
821         _tools_menu.addSeparator();
822         _tools_menu
823                 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
824         customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
825         _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
826         _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
827         customizeJMenuItem( _move_node_names_to_seq_names_jmi );
828         _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
829         _tools_menu
830                 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
831         customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
832         _extract_tax_code_from_node_names_jmi
833                 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
834         _tools_menu.addSeparator();
835         _tools_menu
836                 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
837         customizeJMenuItem( _infer_common_sn_names_item );
838         _tools_menu.addSeparator();
839         _tools_menu
840                 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information" ) );
841         customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
842         _obtain_detailed_taxonomic_information_jmi
843                 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
844         _tools_menu
845                 .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
846         customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
847         _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
848         _tools_menu.addSeparator();
849         if ( !Constants.__RELEASE ) {
850             _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
851             customizeJMenuItem( _function_analysis );
852             _function_analysis
853                     .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
854             _tools_menu.addSeparator();
855         }
856         _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
857         customizeJMenuItem( _read_values_jmi );
858         _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
859         _jmenubar.add( _tools_menu );
860     }
861
862     private void choosePdfWidth() {
863         final String s = ( String ) JOptionPane.showInputDialog( this,
864                                                                  "Please enter the default line width for PDF export.\n"
865                                                                          + "[current value: "
866                                                                          + getOptions().getPrintLineWidth() + "]\n",
867                                                                  "Line Width for PDF Export",
868                                                                  JOptionPane.QUESTION_MESSAGE,
869                                                                  null,
870                                                                  null,
871                                                                  getOptions().getPrintLineWidth() );
872         if ( !ForesterUtil.isEmpty( s ) ) {
873             boolean success = true;
874             float f = 0.0f;
875             final String m_str = s.trim();
876             if ( !ForesterUtil.isEmpty( m_str ) ) {
877                 try {
878                     f = Float.parseFloat( m_str );
879                 }
880                 catch ( final Exception ex ) {
881                     success = false;
882                 }
883             }
884             else {
885                 success = false;
886             }
887             if ( success && ( f > 0.0 ) ) {
888                 getOptions().setPrintLineWidth( f );
889             }
890         }
891     }
892
893     private void choosePrintSize() {
894         final String s = ( String ) JOptionPane.showInputDialog( this,
895                                                                  "Please enter values for width and height,\nseparated by a comma.\n"
896                                                                          + "[current values: "
897                                                                          + getOptions().getPrintSizeX() + ", "
898                                                                          + getOptions().getPrintSizeY() + "]\n"
899                                                                          + "[A4: " + Constants.A4_SIZE_X + ", "
900                                                                          + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
901                                                                          + Constants.US_LETTER_SIZE_X + ", "
902                                                                          + Constants.US_LETTER_SIZE_Y + "]",
903                                                                  "Default Size for Graphics Export",
904                                                                  JOptionPane.QUESTION_MESSAGE,
905                                                                  null,
906                                                                  null,
907                                                                  getOptions().getPrintSizeX() + ", "
908                                                                          + getOptions().getPrintSizeY() );
909         if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
910             boolean success = true;
911             int x = 0;
912             int y = 0;
913             final String[] str_ary = s.split( "," );
914             if ( str_ary.length == 2 ) {
915                 final String x_str = str_ary[ 0 ].trim();
916                 final String y_str = str_ary[ 1 ].trim();
917                 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
918                     try {
919                         x = Integer.parseInt( x_str );
920                         y = Integer.parseInt( y_str );
921                     }
922                     catch ( final Exception ex ) {
923                         success = false;
924                     }
925                 }
926                 else {
927                     success = false;
928                 }
929             }
930             else {
931                 success = false;
932             }
933             if ( success && ( x > 1 ) && ( y > 1 ) ) {
934                 getOptions().setPrintSizeX( x );
935                 getOptions().setPrintSizeY( y );
936             }
937         }
938     }
939
940     @Override
941     void close() {
942         if ( isUnsavedDataPresent() ) {
943             final int r = JOptionPane.showConfirmDialog( this,
944                                                          "Exit despite potentially unsaved changes?",
945                                                          "Exit?",
946                                                          JOptionPane.YES_NO_OPTION );
947             if ( r != JOptionPane.YES_OPTION ) {
948                 return;
949             }
950         }
951         exit();
952     }
953
954     private void closeCurrentPane() {
955         if ( getMainPanel().getCurrentTreePanel() != null ) {
956             if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
957                 final int r = JOptionPane.showConfirmDialog( this,
958                                                              "Close tab despite potentially unsaved changes?",
959                                                              "Close Tab?",
960                                                              JOptionPane.YES_NO_OPTION );
961                 if ( r != JOptionPane.YES_OPTION ) {
962                     return;
963                 }
964             }
965             getMainPanel().closeCurrentPane();
966             activateSaveAllIfNeeded();
967         }
968     }
969
970     private void collapse( final Phylogeny phy, final double m ) {
971         final PhylogenyNodeIterator it = phy.iteratorPostorder();
972         final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
973         double min_support = Double.MAX_VALUE;
974         boolean conf_present = false;
975         while ( it.hasNext() ) {
976             final PhylogenyNode n = it.next();
977             if ( !n.isExternal() && !n.isRoot() ) {
978                 final List<Confidence> c = n.getBranchData().getConfidences();
979                 if ( ( c != null ) && ( c.size() > 0 ) ) {
980                     conf_present = true;
981                     double max = 0;
982                     for( final Confidence confidence : c ) {
983                         if ( confidence.getValue() > max ) {
984                             max = confidence.getValue();
985                         }
986                     }
987                     if ( max < getMinNotCollapseConfidenceValue() ) {
988                         to_be_removed.add( n );
989                     }
990                     if ( max < min_support ) {
991                         min_support = max;
992                     }
993                 }
994             }
995         }
996         if ( conf_present ) {
997             for( final PhylogenyNode node : to_be_removed ) {
998                 PhylogenyMethods.removeNode( node, phy );
999             }
1000             if ( to_be_removed.size() > 0 ) {
1001                 phy.externalNodesHaveChanged();
1002                 phy.hashIDs();
1003                 phy.recalculateNumberOfExternalDescendants( true );
1004                 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1005                 getCurrentTreePanel().setEdited( true );
1006                 getCurrentTreePanel().repaint();
1007             }
1008             if ( to_be_removed.size() > 0 ) {
1009                 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1010                         + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1011                         + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1012             }
1013             else {
1014                 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1015                         + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1016             }
1017         }
1018         else {
1019             JOptionPane.showMessageDialog( this,
1020                                            "No branch collapsed because no confidence values present",
1021                                            "No confidence values present",
1022                                            JOptionPane.INFORMATION_MESSAGE );
1023         }
1024     }
1025
1026     private void collapseBelowThreshold() {
1027         if ( getCurrentTreePanel() != null ) {
1028             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1029             if ( ( phy != null ) && !phy.isEmpty() ) {
1030                 final String s = ( String ) JOptionPane.showInputDialog( this,
1031                                                                          "Please enter the minimum confidence value\n",
1032                                                                          "Minimal Confidence Value",
1033                                                                          JOptionPane.QUESTION_MESSAGE,
1034                                                                          null,
1035                                                                          null,
1036                                                                          getMinNotCollapseConfidenceValue() );
1037                 if ( !ForesterUtil.isEmpty( s ) ) {
1038                     boolean success = true;
1039                     double m = 0.0;
1040                     final String m_str = s.trim();
1041                     if ( !ForesterUtil.isEmpty( m_str ) ) {
1042                         try {
1043                             m = Double.parseDouble( m_str );
1044                         }
1045                         catch ( final Exception ex ) {
1046                             success = false;
1047                         }
1048                     }
1049                     else {
1050                         success = false;
1051                     }
1052                     if ( success && ( m >= 0.0 ) ) {
1053                         setMinNotCollapseConfidenceValue( m );
1054                         collapse( phy, m );
1055                     }
1056                 }
1057             }
1058         }
1059     }
1060
1061     private PhyloXmlParser createPhyloXmlParser() {
1062         PhyloXmlParser xml_parser = null;
1063         if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1064             try {
1065                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1066             }
1067             catch ( final Exception e ) {
1068                 JOptionPane.showMessageDialog( this,
1069                                                e.getLocalizedMessage(),
1070                                                "failed to create validating XML parser",
1071                                                JOptionPane.WARNING_MESSAGE );
1072             }
1073         }
1074         if ( xml_parser == null ) {
1075             xml_parser = new PhyloXmlParser();
1076         }
1077         return xml_parser;
1078     }
1079
1080     void executeGSDI() {
1081         if ( !isOKforSDI( false, true ) ) {
1082             return;
1083         }
1084         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1085             JOptionPane.showMessageDialog( this,
1086                                            "Gene tree is not rooted.",
1087                                            "Cannot execute GSDI",
1088                                            JOptionPane.ERROR_MESSAGE );
1089             return;
1090         }
1091         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1092         gene_tree.setAllNodesToNotCollapse();
1093         gene_tree.recalculateNumberOfExternalDescendants( false );
1094         GSDI gsdi = null;
1095         int duplications = -1;
1096         try {
1097             gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
1098             duplications = gsdi.getDuplicationsSum();
1099         }
1100         catch ( final Exception e ) {
1101             JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1102         }
1103         gene_tree.setRerootable( false );
1104         _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1105         getControlPanel().setShowEvents( true );
1106         showWhole();
1107         _mainpanel.getCurrentTreePanel().setEdited( true );
1108         JOptionPane.showMessageDialog( this,
1109                                        "Number of duplications: " + duplications,
1110                                        "GSDI successfully completed",
1111                                        JOptionPane.INFORMATION_MESSAGE );
1112     }
1113
1114     void executeFunctionAnalysis() {
1115         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1116             return;
1117         }
1118         final GoAnnotation a = new GoAnnotation( this,
1119                                                  _mainpanel.getCurrentTreePanel(),
1120                                                  _mainpanel.getCurrentPhylogeny() );
1121         new Thread( a ).start();
1122     }
1123
1124     void executeLineageInference() {
1125         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1126             return;
1127         }
1128         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1129             JOptionPane.showMessageDialog( this,
1130                                            "Phylogeny is not rooted.",
1131                                            "Cannot infer ancestral taxonomies",
1132                                            JOptionPane.ERROR_MESSAGE );
1133             return;
1134         }
1135         final Phylogeny phy = _mainpanel.getCurrentPhylogeny().copy();
1136         final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1137                                                                                   _mainpanel.getCurrentTreePanel(),
1138                                                                                   phy );
1139         new Thread( inferrer ).start();
1140     }
1141
1142     private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1143         final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1144                                                                       getPhylogeneticInferenceOptions(),
1145                                                                       from_unaligned_seqs );
1146         dialog.activate();
1147         if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1148             if ( !from_unaligned_seqs ) {
1149                 if ( getMsa() != null ) {
1150                     final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1151                                                                                     getPhylogeneticInferenceOptions()
1152                                                                                             .copy(), this );
1153                     new Thread( inferrer ).start();
1154                 }
1155                 else {
1156                     JOptionPane.showMessageDialog( this,
1157                                                    "No multiple sequence alignment selected",
1158                                                    "Phylogenetic Inference Not Launched",
1159                                                    JOptionPane.WARNING_MESSAGE );
1160                 }
1161             }
1162             else {
1163                 if ( getSeqs() != null ) {
1164                     final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1165                                                                                     getPhylogeneticInferenceOptions()
1166                                                                                             .copy(), this );
1167                     new Thread( inferrer ).start();
1168                 }
1169                 else {
1170                     JOptionPane.showMessageDialog( this,
1171                                                    "No input sequences selected",
1172                                                    "Phylogenetic Inference Not Launched",
1173                                                    JOptionPane.WARNING_MESSAGE );
1174                 }
1175             }
1176         }
1177     }
1178
1179     void executeSDI() {
1180         if ( !isOKforSDI( true, true ) ) {
1181             return;
1182         }
1183         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1184             JOptionPane.showMessageDialog( this,
1185                                            "Gene tree is not rooted",
1186                                            "Cannot execute SDI",
1187                                            JOptionPane.ERROR_MESSAGE );
1188             return;
1189         }
1190         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1191         gene_tree.setAllNodesToNotCollapse();
1192         gene_tree.recalculateNumberOfExternalDescendants( false );
1193         SDI sdi = null;
1194         int duplications = -1;
1195         try {
1196             sdi = new SDIse( gene_tree, _species_tree.copy() );
1197             duplications = sdi.getDuplicationsSum();
1198         }
1199         catch ( final Exception e ) {
1200             JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
1201         }
1202         gene_tree.setRerootable( false );
1203         _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1204         getControlPanel().setShowEvents( true );
1205         showWhole();
1206         _mainpanel.getCurrentTreePanel().setEdited( true );
1207         JOptionPane.showMessageDialog( this,
1208                                        "Number of duplications: " + duplications,
1209                                        "SDI successfully completed",
1210                                        JOptionPane.INFORMATION_MESSAGE );
1211     }
1212
1213     void executeSDIR( final boolean minimize_cost ) {
1214         if ( !isOKforSDI( true, true ) ) {
1215             return;
1216         }
1217         Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1218         final SDIR sdiunrooted = new SDIR();
1219         gene_tree.setAllNodesToNotCollapse();
1220         gene_tree.recalculateNumberOfExternalDescendants( false );
1221         try {
1222             gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1223                                            !minimize_cost, // minimize sum of dups
1224                                            true, // minimize height
1225                                            true, // return tree(s)
1226                                            1 )[ 0 ]; // # of trees to return
1227         }
1228         catch ( final Exception e ) {
1229             JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1230             return;
1231         }
1232         final int duplications = sdiunrooted.getMinimalDuplications();
1233         gene_tree.setRerootable( false );
1234         _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1235         getControlPanel().setShowEvents( true );
1236         showWhole();
1237         _mainpanel.getCurrentTreePanel().setEdited( true );
1238         JOptionPane.showMessageDialog( this,
1239                                        "Number of duplications: " + duplications,
1240                                        "SDIR successfully completed",
1241                                        JOptionPane.INFORMATION_MESSAGE );
1242     }
1243
1244     void exit() {
1245         removeTextFrame();
1246         _mainpanel.terminate();
1247         _contentpane.removeAll();
1248         setVisible( false );
1249         dispose();
1250         System.exit( 0 );
1251     }
1252
1253     private void extractTaxCodeFromNodeNames() {
1254         if ( getCurrentTreePanel() != null ) {
1255             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1256             if ( ( phy != null ) && !phy.isEmpty() ) {
1257                 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1258                 while ( it.hasNext() ) {
1259                     final PhylogenyNode n = it.next();
1260                     final String name = n.getName().trim();
1261                     if ( !ForesterUtil.isEmpty( name ) ) {
1262                         final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
1263                                                                                           false,
1264                                                                                           TAXONOMY_EXTRACTION.YES );
1265                         if ( !ForesterUtil.isEmpty( code ) ) {
1266                             PhylogenyMethods.setTaxonomyCode( n, code );
1267                         }
1268                     }
1269                 }
1270             }
1271         }
1272     }
1273
1274     private ControlPanel getControlPanel() {
1275         return getMainPanel().getControlPanel();
1276     }
1277
1278     private File getCurrentDir() {
1279         if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1280             if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
1281                 try {
1282                     _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1283                 }
1284                 catch ( final Exception e ) {
1285                     _current_dir = null;
1286                 }
1287             }
1288         }
1289         if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1290             if ( System.getProperty( "user.home" ) != null ) {
1291                 _current_dir = new File( System.getProperty( "user.home" ) );
1292             }
1293             else if ( System.getProperty( "user.dir" ) != null ) {
1294                 _current_dir = new File( System.getProperty( "user.dir" ) );
1295             }
1296         }
1297         return _current_dir;
1298     }
1299
1300     @Override
1301     public MainPanel getMainPanel() {
1302         return _mainpanel;
1303     }
1304
1305     private double getMinNotCollapseConfidenceValue() {
1306         return _min_not_collapse;
1307     }
1308
1309     boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1310         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1311             return false;
1312         }
1313         else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1314             JOptionPane.showMessageDialog( this,
1315                                            "No species tree loaded",
1316                                            "Cannot execute SDI",
1317                                            JOptionPane.ERROR_MESSAGE );
1318             return false;
1319         }
1320         else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1321             JOptionPane.showMessageDialog( this,
1322                                            "Species tree is not completely binary",
1323                                            "Cannot execute SDI",
1324                                            JOptionPane.ERROR_MESSAGE );
1325             return false;
1326         }
1327         else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1328             JOptionPane.showMessageDialog( this,
1329                                            "Gene tree is not completely binary",
1330                                            "Cannot execute SDI",
1331                                            JOptionPane.ERROR_MESSAGE );
1332             return false;
1333         }
1334         else {
1335             return true;
1336         }
1337     }
1338
1339     private boolean isUnsavedDataPresent() {
1340         final List<TreePanel> tps = getMainPanel().getTreePanels();
1341         for( final TreePanel tp : tps ) {
1342             if ( tp.isEdited() ) {
1343                 return true;
1344             }
1345         }
1346         return false;
1347     }
1348
1349     private void moveNodeNamesToSeqNames() {
1350         if ( getCurrentTreePanel() != null ) {
1351             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1352             if ( ( phy != null ) && !phy.isEmpty() ) {
1353                 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
1354             }
1355         }
1356     }
1357
1358     private void moveNodeNamesToTaxSn() {
1359         if ( getCurrentTreePanel() != null ) {
1360             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1361             if ( ( phy != null ) && !phy.isEmpty() ) {
1362                 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
1363             }
1364         }
1365     }
1366
1367     private void newTree() {
1368         final Phylogeny[] phys = new Phylogeny[ 1 ];
1369         final Phylogeny phy = new Phylogeny();
1370         final PhylogenyNode node = new PhylogenyNode();
1371         phy.setRoot( node );
1372         phy.setRooted( true );
1373         phys[ 0 ] = phy;
1374         Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1375         _mainpanel.getControlPanel().showWhole();
1376         _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1377         _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1378         if ( getMainPanel().getMainFrame() == null ) {
1379             // Must be "E" applet version.
1380             ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1381                     .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1382         }
1383         else {
1384             getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1385         }
1386         activateSaveAllIfNeeded();
1387         System.gc();
1388     }
1389
1390     private void obtainDetailedTaxonomicInformation() {
1391         if ( getCurrentTreePanel() != null ) {
1392             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1393             if ( ( phy != null ) && !phy.isEmpty() ) {
1394                 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1395                                                                          _mainpanel.getCurrentTreePanel(),
1396                                                                          phy.copy() );
1397                 new Thread( t ).start();
1398             }
1399         }
1400     }
1401
1402     private void obtainUniProtSequenceInformation() {
1403         if ( getCurrentTreePanel() != null ) {
1404             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1405             if ( ( phy != null ) && !phy.isEmpty() ) {
1406                 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1407                                                                          _mainpanel.getCurrentTreePanel(),
1408                                                                          phy.copy() );
1409                 new Thread( u ).start();
1410             }
1411         }
1412     }
1413
1414     private void print() {
1415         if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1416                 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1417             return;
1418         }
1419         if ( !getOptions().isPrintUsingActualSize() ) {
1420             getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1421                                                             getOptions().getPrintSizeY() - 140,
1422                                                             true );
1423             getCurrentTreePanel().resetPreferredSize();
1424             getCurrentTreePanel().repaint();
1425         }
1426         final String job_name = Constants.PRG_NAME;
1427         boolean error = false;
1428         String printer_name = null;
1429         try {
1430             printer_name = Printer.print( getCurrentTreePanel(), job_name );
1431         }
1432         catch ( final Exception e ) {
1433             error = true;
1434             JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1435         }
1436         if ( !error && ( printer_name != null ) ) {
1437             String msg = "Printing data sent to printer";
1438             if ( printer_name.length() > 1 ) {
1439                 msg += " [" + printer_name + "]";
1440             }
1441             JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1442         }
1443         if ( !getOptions().isPrintUsingActualSize() ) {
1444             getControlPanel().showWhole();
1445         }
1446     }
1447
1448     private void printPhylogenyToPdf( final String file_name ) {
1449         if ( !getOptions().isPrintUsingActualSize() ) {
1450             getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1451                                                             getOptions().getPrintSizeY(),
1452                                                             true );
1453             getCurrentTreePanel().resetPreferredSize();
1454             getCurrentTreePanel().repaint();
1455         }
1456         String pdf_written_to = "";
1457         boolean error = false;
1458         try {
1459             if ( getOptions().isPrintUsingActualSize() ) {
1460                 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1461                                                                   getCurrentTreePanel(),
1462                                                                   getCurrentTreePanel().getWidth(),
1463                                                                   getCurrentTreePanel().getHeight() );
1464             }
1465             else {
1466                 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1467                         .getPrintSizeX(), getOptions().getPrintSizeY() );
1468             }
1469         }
1470         catch ( final IOException e ) {
1471             error = true;
1472             JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1473         }
1474         if ( !error ) {
1475             if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1476                 JOptionPane.showMessageDialog( this,
1477                                                "Wrote PDF to: " + pdf_written_to,
1478                                                "Information",
1479                                                JOptionPane.INFORMATION_MESSAGE );
1480             }
1481             else {
1482                 JOptionPane.showMessageDialog( this,
1483                                                "There was an unknown problem when attempting to write to PDF file: \""
1484                                                        + file_name + "\"",
1485                                                "Error",
1486                                                JOptionPane.ERROR_MESSAGE );
1487             }
1488         }
1489         if ( !getOptions().isPrintUsingActualSize() ) {
1490             getControlPanel().showWhole();
1491         }
1492     }
1493
1494     private void addExpressionValuesFromFile() {
1495         if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1496             JOptionPane.showMessageDialog( this,
1497                                            "Need to load evolutionary tree first",
1498                                            "Can Not Read Expression Values",
1499                                            JOptionPane.WARNING_MESSAGE );
1500             return;
1501         }
1502         final File my_dir = getCurrentDir();
1503         if ( my_dir != null ) {
1504             _values_filechooser.setCurrentDirectory( my_dir );
1505         }
1506         final int result = _values_filechooser.showOpenDialog( _contentpane );
1507         final File file = _values_filechooser.getSelectedFile();
1508         if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1509             BasicTable<String> t = null;
1510             try {
1511                 t = BasicTableParser.parse( file, "\t" );
1512                 if ( t.getNumberOfColumns() < 2 ) {
1513                     t = BasicTableParser.parse( file, "," );
1514                 }
1515                 if ( t.getNumberOfColumns() < 2 ) {
1516                     t = BasicTableParser.parse( file, " " );
1517                 }
1518             }
1519             catch ( final IOException e ) {
1520                 JOptionPane.showMessageDialog( this,
1521                                                e.getMessage(),
1522                                                "Could Not Read Expression Value Table",
1523                                                JOptionPane.ERROR_MESSAGE );
1524                 return;
1525             }
1526             if ( t.getNumberOfColumns() < 2 ) {
1527                 JOptionPane.showMessageDialog( this,
1528                                                "Table contains " + t.getNumberOfColumns() + " column(s)",
1529                                                "Problem with Expression Value Table",
1530                                                JOptionPane.ERROR_MESSAGE );
1531                 return;
1532             }
1533             if ( t.getNumberOfRows() < 1 ) {
1534                 JOptionPane.showMessageDialog( this,
1535                                                "Table contains zero rows",
1536                                                "Problem with Expression Value Table",
1537                                                JOptionPane.ERROR_MESSAGE );
1538                 return;
1539             }
1540             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1541             if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1542                 JOptionPane.showMessageDialog( this,
1543                                                "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1544                                                        + phy.getNumberOfExternalNodes() + " external nodes",
1545                                                "Warning",
1546                                                JOptionPane.WARNING_MESSAGE );
1547             }
1548             final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1549             int not_found = 0;
1550             for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1551                 final PhylogenyNode node = iter.next();
1552                 final String node_name = node.getName();
1553                 if ( !ForesterUtil.isEmpty( node_name ) ) {
1554                     int row = -1;
1555                     try {
1556                         row = t.findRow( node_name );
1557                     }
1558                     catch ( final IllegalArgumentException e ) {
1559                         JOptionPane
1560                                 .showMessageDialog( this,
1561                                                     e.getMessage(),
1562                                                     "Error Mapping Node Identifiers to Expression Value Identifiers",
1563                                                     JOptionPane.ERROR_MESSAGE );
1564                         return;
1565                     }
1566                     if ( row < 0 ) {
1567                         if ( node.isExternal() ) {
1568                             not_found++;
1569                         }
1570                         continue;
1571                     }
1572                     final List<Double> l = new ArrayList<Double>();
1573                     for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1574                         double d = -100;
1575                         try {
1576                             d = Double.parseDouble( t.getValueAsString( col, row ) );
1577                         }
1578                         catch ( final NumberFormatException e ) {
1579                             JOptionPane.showMessageDialog( this,
1580                                                            "Could not parse \"" + t.getValueAsString( col, row )
1581                                                                    + "\" into a decimal value",
1582                                                            "Issue with Expression Value Table",
1583                                                            JOptionPane.ERROR_MESSAGE );
1584                             return;
1585                         }
1586                         stats.addValue( d );
1587                         l.add( d );
1588                     }
1589                     if ( !l.isEmpty() ) {
1590                         if ( node.getNodeData().getProperties() != null ) {
1591                             node.getNodeData().getProperties()
1592                                     .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1593                         }
1594                         node.getNodeData().setVector( l );
1595                     }
1596                 }
1597             }
1598             if ( not_found > 0 ) {
1599                 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1600                         + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1601             }
1602             getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1603         }
1604     }
1605
1606     private void readPhylogeniesFromFile() {
1607         boolean exception = false;
1608         Phylogeny[] phys = null;
1609         // Set an initial directory if none set yet
1610         final File my_dir = getCurrentDir();
1611         _open_filechooser.setMultiSelectionEnabled( true );
1612         // Open file-open dialog and set current directory
1613         if ( my_dir != null ) {
1614             _open_filechooser.setCurrentDirectory( my_dir );
1615         }
1616         final int result = _open_filechooser.showOpenDialog( _contentpane );
1617         // All done: get the file
1618         final File[] files = _open_filechooser.getSelectedFiles();
1619         setCurrentDir( _open_filechooser.getCurrentDirectory() );
1620         boolean nhx_or_nexus = false;
1621         if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1622             for( final File file : files ) {
1623                 if ( ( file != null ) && !file.isDirectory() ) {
1624                     if ( _mainpanel.getCurrentTreePanel() != null ) {
1625                         _mainpanel.getCurrentTreePanel().setWaitCursor();
1626                     }
1627                     else {
1628                         _mainpanel.setWaitCursor();
1629                     }
1630                     if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1631                             || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1632                         try {
1633                             final NHXParser nhx = new NHXParser();
1634                             setSpecialOptionsForNhxParser( nhx );
1635                             phys = ForesterUtil.readPhylogenies( nhx, file );
1636                             nhx_or_nexus = true;
1637                         }
1638                         catch ( final Exception e ) {
1639                             exception = true;
1640                             exceptionOccuredDuringOpenFile( e );
1641                         }
1642                     }
1643                     else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1644                         warnIfNotPhyloXmlValidation( getConfiguration() );
1645                         try {
1646                             final PhyloXmlParser xml_parser = createPhyloXmlParser();
1647                             phys = ForesterUtil.readPhylogenies( xml_parser, file );
1648                         }
1649                         catch ( final Exception e ) {
1650                             exception = true;
1651                             exceptionOccuredDuringOpenFile( e );
1652                         }
1653                     }
1654                     else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1655                         try {
1656                             phys = ForesterUtil.readPhylogenies( new TolParser(), file );
1657                         }
1658                         catch ( final Exception e ) {
1659                             exception = true;
1660                             exceptionOccuredDuringOpenFile( e );
1661                         }
1662                     }
1663                     else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1664                         try {
1665                             final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1666                             setSpecialOptionsForNexParser( nex );
1667                             phys = ForesterUtil.readPhylogenies( nex, file );
1668                             nhx_or_nexus = true;
1669                         }
1670                         catch ( final Exception e ) {
1671                             exception = true;
1672                             exceptionOccuredDuringOpenFile( e );
1673                         }
1674                     }
1675                     // "*.*":
1676                     else {
1677                         try {
1678                             final PhylogenyParser parser = ForesterUtil
1679                                     .createParserDependingOnFileType( file, getConfiguration()
1680                                             .isValidatePhyloXmlAgainstSchema() );
1681                             if ( parser instanceof NexusPhylogeniesParser ) {
1682                                 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1683                                 setSpecialOptionsForNexParser( nex );
1684                                 nhx_or_nexus = true;
1685                             }
1686                             else if ( parser instanceof NHXParser ) {
1687                                 final NHXParser nhx = ( NHXParser ) parser;
1688                                 setSpecialOptionsForNhxParser( nhx );
1689                                 nhx_or_nexus = true;
1690                             }
1691                             else if ( parser instanceof PhyloXmlParser ) {
1692                                 warnIfNotPhyloXmlValidation( getConfiguration() );
1693                             }
1694                             phys = ForesterUtil.readPhylogenies( parser, file );
1695                         }
1696                         catch ( final Exception e ) {
1697                             exception = true;
1698                             exceptionOccuredDuringOpenFile( e );
1699                         }
1700                     }
1701                     if ( _mainpanel.getCurrentTreePanel() != null ) {
1702                         _mainpanel.getCurrentTreePanel().setArrowCursor();
1703                     }
1704                     else {
1705                         _mainpanel.setArrowCursor();
1706                     }
1707                     if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1708                         boolean one_desc = false;
1709                         if ( nhx_or_nexus ) {
1710                             for( final Phylogeny phy : phys ) {
1711                                 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1712                                     ForesterUtil.transferInternalNodeNamesToConfidence( phy );
1713                                 }
1714                                 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1715                                     one_desc = true;
1716                                     break;
1717                                 }
1718                             }
1719                         }
1720                         Util.addPhylogeniesToTabs( phys,
1721                                                    file.getName(),
1722                                                    file.getAbsolutePath(),
1723                                                    getConfiguration(),
1724                                                    getMainPanel() );
1725                         _mainpanel.getControlPanel().showWhole();
1726                         if ( nhx_or_nexus && one_desc ) {
1727                             JOptionPane
1728                                     .showMessageDialog( this,
1729                                                         "One or more trees contain (a) node(s) with one descendant, "
1730                                                                 + ForesterUtil.LINE_SEPARATOR
1731                                                                 + "possibly indicating illegal parentheses within node names.",
1732                                                         "Warning: Possible Error in New Hampshire Formatted Data",
1733                                                         JOptionPane.WARNING_MESSAGE );
1734                         }
1735                     }
1736                 }
1737             }
1738         }
1739         activateSaveAllIfNeeded();
1740         System.gc();
1741     }
1742
1743     public void readSeqsFromFile() {
1744         // Set an initial directory if none set yet
1745         final File my_dir = getCurrentDir();
1746         _seqs_filechooser.setMultiSelectionEnabled( false );
1747         // Open file-open dialog and set current directory
1748         if ( my_dir != null ) {
1749             _seqs_filechooser.setCurrentDirectory( my_dir );
1750         }
1751         final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1752         // All done: get the seqs
1753         final File file = _seqs_filechooser.getSelectedFile();
1754         setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1755         if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1756             setSeqsFile( null );
1757             setSeqs( null );
1758             List<Sequence> seqs = null;
1759             try {
1760                 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1761                     seqs = FastaParser.parse( new FileInputStream( file ) );
1762                     for( final Sequence seq : seqs ) {
1763                         System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1764                     }
1765                 }
1766                 else {
1767                     //TODO error
1768                 }
1769             }
1770             catch ( final MsaFormatException e ) {
1771                 try {
1772                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1773                 }
1774                 catch ( final Exception ex ) {
1775                     // Do nothing.
1776                 }
1777                 JOptionPane.showMessageDialog( this,
1778                                                e.getLocalizedMessage(),
1779                                                "Multiple sequence file format error",
1780                                                JOptionPane.ERROR_MESSAGE );
1781                 return;
1782             }
1783             catch ( final IOException e ) {
1784                 try {
1785                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1786                 }
1787                 catch ( final Exception ex ) {
1788                     // Do nothing.
1789                 }
1790                 JOptionPane.showMessageDialog( this,
1791                                                e.getLocalizedMessage(),
1792                                                "Failed to read multiple sequence file",
1793                                                JOptionPane.ERROR_MESSAGE );
1794                 return;
1795             }
1796             catch ( final IllegalArgumentException e ) {
1797                 try {
1798                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1799                 }
1800                 catch ( final Exception ex ) {
1801                     // Do nothing.
1802                 }
1803                 JOptionPane.showMessageDialog( this,
1804                                                e.getLocalizedMessage(),
1805                                                "Unexpected error during reading of multiple sequence file",
1806                                                JOptionPane.ERROR_MESSAGE );
1807                 return;
1808             }
1809             catch ( final Exception e ) {
1810                 try {
1811                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1812                 }
1813                 catch ( final Exception ex ) {
1814                     // Do nothing.
1815                 }
1816                 e.printStackTrace();
1817                 JOptionPane.showMessageDialog( this,
1818                                                e.getLocalizedMessage(),
1819                                                "Unexpected error during reading of multiple sequence file",
1820                                                JOptionPane.ERROR_MESSAGE );
1821                 return;
1822             }
1823             if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1824                 JOptionPane.showMessageDialog( this,
1825                                                "Multiple sequence file is empty",
1826                                                "Illegal multiple sequence file",
1827                                                JOptionPane.ERROR_MESSAGE );
1828                 return;
1829             }
1830             if ( seqs.size() < 4 ) {
1831                 JOptionPane.showMessageDialog( this,
1832                                                "Multiple sequence file needs to contain at least 3 sequences",
1833                                                "Illegal multiple sequence file",
1834                                                JOptionPane.ERROR_MESSAGE );
1835                 return;
1836             }
1837             //  if ( msa.getLength() < 2 ) {
1838             //       JOptionPane.showMessageDialog( this,
1839             //                                      "Multiple sequence alignment needs to contain at least 2 residues",
1840             //                                      "Illegal multiple sequence file",
1841             //                                      JOptionPane.ERROR_MESSAGE );
1842             //       return;
1843             //   }
1844             System.gc();
1845             setSeqsFile( _seqs_filechooser.getSelectedFile() );
1846             setSeqs( seqs );
1847         }
1848     }
1849
1850     public void readMsaFromFile() {
1851         // Set an initial directory if none set yet
1852         final File my_dir = getCurrentDir();
1853         _msa_filechooser.setMultiSelectionEnabled( false );
1854         // Open file-open dialog and set current directory
1855         if ( my_dir != null ) {
1856             _msa_filechooser.setCurrentDirectory( my_dir );
1857         }
1858         final int result = _msa_filechooser.showOpenDialog( _contentpane );
1859         // All done: get the msa
1860         final File file = _msa_filechooser.getSelectedFile();
1861         setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1862         if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1863             setMsaFile( null );
1864             setMsa( null );
1865             Msa msa = null;
1866             try {
1867                 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1868                     msa = FastaParser.parseMsa( new FileInputStream( file ) );
1869                     System.out.println( msa.toString() );
1870                 }
1871                 else {
1872                     msa = GeneralMsaParser.parse( new FileInputStream( file ) );
1873                 }
1874             }
1875             catch ( final MsaFormatException e ) {
1876                 try {
1877                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1878                 }
1879                 catch ( final Exception ex ) {
1880                     // Do nothing.
1881                 }
1882                 JOptionPane.showMessageDialog( this,
1883                                                e.getLocalizedMessage(),
1884                                                "Multiple sequence alignment format error",
1885                                                JOptionPane.ERROR_MESSAGE );
1886                 return;
1887             }
1888             catch ( final IOException e ) {
1889                 try {
1890                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1891                 }
1892                 catch ( final Exception ex ) {
1893                     // Do nothing.
1894                 }
1895                 JOptionPane.showMessageDialog( this,
1896                                                e.getLocalizedMessage(),
1897                                                "Failed to read multiple sequence alignment",
1898                                                JOptionPane.ERROR_MESSAGE );
1899                 return;
1900             }
1901             catch ( final IllegalArgumentException e ) {
1902                 try {
1903                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1904                 }
1905                 catch ( final Exception ex ) {
1906                     // Do nothing.
1907                 }
1908                 JOptionPane.showMessageDialog( this,
1909                                                e.getLocalizedMessage(),
1910                                                "Unexpected error during reading of multiple sequence alignment",
1911                                                JOptionPane.ERROR_MESSAGE );
1912                 return;
1913             }
1914             catch ( final Exception e ) {
1915                 try {
1916                     _mainpanel.getCurrentTreePanel().setArrowCursor();
1917                 }
1918                 catch ( final Exception ex ) {
1919                     // Do nothing.
1920                 }
1921                 e.printStackTrace();
1922                 JOptionPane.showMessageDialog( this,
1923                                                e.getLocalizedMessage(),
1924                                                "Unexpected error during reading of multiple sequence alignment",
1925                                                JOptionPane.ERROR_MESSAGE );
1926                 return;
1927             }
1928             if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
1929                 JOptionPane.showMessageDialog( this,
1930                                                "Multiple sequence alignment is empty",
1931                                                "Illegal Multiple Sequence Alignment",
1932                                                JOptionPane.ERROR_MESSAGE );
1933                 return;
1934             }
1935             if ( msa.getNumberOfSequences() < 4 ) {
1936                 JOptionPane.showMessageDialog( this,
1937                                                "Multiple sequence alignment needs to contain at least 3 sequences",
1938                                                "Illegal multiple sequence alignment",
1939                                                JOptionPane.ERROR_MESSAGE );
1940                 return;
1941             }
1942             if ( msa.getLength() < 2 ) {
1943                 JOptionPane.showMessageDialog( this,
1944                                                "Multiple sequence alignment needs to contain at least 2 residues",
1945                                                "Illegal multiple sequence alignment",
1946                                                JOptionPane.ERROR_MESSAGE );
1947                 return;
1948             }
1949             System.gc();
1950             setMsaFile( _msa_filechooser.getSelectedFile() );
1951             setMsa( msa );
1952         }
1953     }
1954
1955     @Override
1956     void readPhylogeniesFromURL() {
1957         URL url = null;
1958         Phylogeny[] phys = null;
1959         final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1960         final String url_string = JOptionPane.showInputDialog( this,
1961                                                                message,
1962                                                                "Use URL/webservice to obtain a phylogeny",
1963                                                                JOptionPane.QUESTION_MESSAGE );
1964         boolean nhx_or_nexus = false;
1965         if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1966             try {
1967                 url = new URL( url_string );
1968                 PhylogenyParser parser = null;
1969                 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1970                     parser = new TolParser();
1971                 }
1972                 else {
1973                     parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
1974                             .isValidatePhyloXmlAgainstSchema() );
1975                 }
1976                 if ( parser instanceof NexusPhylogeniesParser ) {
1977                     nhx_or_nexus = true;
1978                 }
1979                 else if ( parser instanceof NHXParser ) {
1980                     nhx_or_nexus = true;
1981                 }
1982                 if ( _mainpanel.getCurrentTreePanel() != null ) {
1983                     _mainpanel.getCurrentTreePanel().setWaitCursor();
1984                 }
1985                 else {
1986                     _mainpanel.setWaitCursor();
1987                 }
1988                 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1989                 phys = factory.create( url.openStream(), parser );
1990             }
1991             catch ( final MalformedURLException e ) {
1992                 JOptionPane.showMessageDialog( this,
1993                                                "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
1994                                                "Malformed URL",
1995                                                JOptionPane.ERROR_MESSAGE );
1996             }
1997             catch ( final IOException e ) {
1998                 JOptionPane.showMessageDialog( this,
1999                                                "Could not read from " + url + "\n"
2000                                                        + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2001                                                "Failed to read URL",
2002                                                JOptionPane.ERROR_MESSAGE );
2003             }
2004             catch ( final Exception e ) {
2005                 JOptionPane.showMessageDialog( this,
2006                                                ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2007                                                "Unexpected Exception",
2008                                                JOptionPane.ERROR_MESSAGE );
2009             }
2010             finally {
2011                 if ( _mainpanel.getCurrentTreePanel() != null ) {
2012                     _mainpanel.getCurrentTreePanel().setArrowCursor();
2013                 }
2014                 else {
2015                     _mainpanel.setArrowCursor();
2016                 }
2017             }
2018             if ( ( phys != null ) && ( phys.length > 0 ) ) {
2019                 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2020                     for( final Phylogeny phy : phys ) {
2021                         ForesterUtil.transferInternalNodeNamesToConfidence( phy );
2022                     }
2023                 }
2024                 Util.addPhylogeniesToTabs( phys,
2025                                            new File( url.getFile() ).getName(),
2026                                            new File( url.getFile() ).toString(),
2027                                            getConfiguration(),
2028                                            getMainPanel() );
2029                 _mainpanel.getControlPanel().showWhole();
2030             }
2031         }
2032         activateSaveAllIfNeeded();
2033         System.gc();
2034     }
2035
2036     private void readSpeciesTreeFromFile() {
2037         Phylogeny t = null;
2038         boolean exception = false;
2039         final File my_dir = getCurrentDir();
2040         _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2041         if ( my_dir != null ) {
2042             _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2043         }
2044         final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2045         final File file = _open_filechooser_for_species_tree.getSelectedFile();
2046         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2047             if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2048                 try {
2049                     final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2050                     t = trees[ 0 ];
2051                 }
2052                 catch ( final Exception e ) {
2053                     exception = true;
2054                     exceptionOccuredDuringOpenFile( e );
2055                 }
2056             }
2057             else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2058                 try {
2059                     final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
2060                     t = trees[ 0 ];
2061                 }
2062                 catch ( final Exception e ) {
2063                     exception = true;
2064                     exceptionOccuredDuringOpenFile( e );
2065                 }
2066             }
2067             // "*.*":
2068             else {
2069                 try {
2070                     final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2071                     t = trees[ 0 ];
2072                 }
2073                 catch ( final Exception e ) {
2074                     exception = true;
2075                     exceptionOccuredDuringOpenFile( e );
2076                 }
2077             }
2078             if ( !exception && ( t != null ) && !t.isRooted() ) {
2079                 exception = true;
2080                 t = null;
2081                 JOptionPane.showMessageDialog( this,
2082                                                "Species tree is not rooted",
2083                                                "Species tree not loaded",
2084                                                JOptionPane.ERROR_MESSAGE );
2085             }
2086             if ( !exception && ( t != null ) ) {
2087                 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2088                 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2089                     final PhylogenyNode node = it.next();
2090                     if ( !node.getNodeData().isHasTaxonomy() ) {
2091                         exception = true;
2092                         t = null;
2093                         JOptionPane
2094                                 .showMessageDialog( this,
2095                                                     "Species tree contains external node(s) without taxonomy information",
2096                                                     "Species tree not loaded",
2097                                                     JOptionPane.ERROR_MESSAGE );
2098                         break;
2099                     }
2100                     else {
2101                         if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2102                             exception = true;
2103                             t = null;
2104                             JOptionPane.showMessageDialog( this,
2105                                                            "Taxonomy ["
2106                                                                    + node.getNodeData().getTaxonomy().asSimpleText()
2107                                                                    + "] is not unique in species tree",
2108                                                            "Species tree not loaded",
2109                                                            JOptionPane.ERROR_MESSAGE );
2110                             break;
2111                         }
2112                         else {
2113                             tax_set.add( node.getNodeData().getTaxonomy() );
2114                         }
2115                     }
2116                 }
2117             }
2118             if ( !exception && ( t != null ) ) {
2119                 _species_tree = t;
2120                 JOptionPane.showMessageDialog( this,
2121                                                "Species tree successfully loaded",
2122                                                "Species tree loaded",
2123                                                JOptionPane.INFORMATION_MESSAGE );
2124             }
2125             _contentpane.repaint();
2126             System.gc();
2127         }
2128     }
2129
2130     private void setCurrentDir( final File current_dir ) {
2131         _current_dir = current_dir;
2132     }
2133
2134     private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2135         _min_not_collapse = min_not_collapse;
2136     }
2137
2138     private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2139         nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2140     }
2141
2142     private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2143         nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2144         ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
2145         if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2146             te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
2147         }
2148         nhx.setTaxonomyExtraction( te );
2149     }
2150
2151     private void writeAllToFile() {
2152         if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2153             return;
2154         }
2155         final File my_dir = getCurrentDir();
2156         if ( my_dir != null ) {
2157             _save_filechooser.setCurrentDirectory( my_dir );
2158         }
2159         _save_filechooser.setSelectedFile( new File( "" ) );
2160         final int result = _save_filechooser.showSaveDialog( _contentpane );
2161         final File file = _save_filechooser.getSelectedFile();
2162         setCurrentDir( _save_filechooser.getCurrentDirectory() );
2163         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2164             if ( file.exists() ) {
2165                 final int i = JOptionPane.showConfirmDialog( this,
2166                                                              file + " already exists. Overwrite?",
2167                                                              "Warning",
2168                                                              JOptionPane.OK_CANCEL_OPTION,
2169                                                              JOptionPane.WARNING_MESSAGE );
2170                 if ( i != JOptionPane.OK_OPTION ) {
2171                     return;
2172                 }
2173                 else {
2174                     try {
2175                         file.delete();
2176                     }
2177                     catch ( final Exception e ) {
2178                         JOptionPane.showMessageDialog( this,
2179                                                        "Failed to delete: " + file,
2180                                                        "Error",
2181                                                        JOptionPane.WARNING_MESSAGE );
2182                     }
2183                 }
2184             }
2185             final int count = getMainPanel().getTabbedPane().getTabCount();
2186             final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2187             for( int i = 0; i < count; ++i ) {
2188                 trees.add( getMainPanel().getPhylogeny( i ) );
2189                 getMainPanel().getTreePanels().get( i ).setEdited( false );
2190             }
2191             final PhylogenyWriter writer = new PhylogenyWriter();
2192             try {
2193                 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2194             }
2195             catch ( final IOException e ) {
2196                 JOptionPane.showMessageDialog( this,
2197                                                "Failed to write to: " + file,
2198                                                "Error",
2199                                                JOptionPane.WARNING_MESSAGE );
2200             }
2201         }
2202     }
2203
2204     private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2205         try {
2206             final PhylogenyWriter writer = new PhylogenyWriter();
2207             writer.toNewHampshire( t, false, true, file );
2208         }
2209         catch ( final Exception e ) {
2210             exception = true;
2211             exceptionOccuredDuringSaveAs( e );
2212         }
2213         return exception;
2214     }
2215
2216     private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2217         try {
2218             final PhylogenyWriter writer = new PhylogenyWriter();
2219             writer.toNexus( file, t );
2220         }
2221         catch ( final Exception e ) {
2222             exception = true;
2223             exceptionOccuredDuringSaveAs( e );
2224         }
2225         return exception;
2226     }
2227
2228     private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2229         try {
2230             final PhylogenyWriter writer = new PhylogenyWriter();
2231             writer.toNewHampshireX( t, file );
2232         }
2233         catch ( final Exception e ) {
2234             exception = true;
2235             exceptionOccuredDuringSaveAs( e );
2236         }
2237         return exception;
2238     }
2239
2240     private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2241         try {
2242             final PhylogenyWriter writer = new PhylogenyWriter();
2243             writer.toPhyloXML( file, t, 0 );
2244         }
2245         catch ( final Exception e ) {
2246             exception = true;
2247             exceptionOccuredDuringSaveAs( e );
2248         }
2249         return exception;
2250     }
2251
2252     private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2253         _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2254                                                                    _mainpanel.getCurrentTreePanel().getHeight(),
2255                                                                    true );
2256         String file_written_to = "";
2257         boolean error = false;
2258         try {
2259             file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
2260                                                                  _mainpanel.getCurrentTreePanel().getWidth(),
2261                                                                  _mainpanel.getCurrentTreePanel().getHeight(),
2262                                                                  _mainpanel.getCurrentTreePanel(),
2263                                                                  _mainpanel.getControlPanel(),
2264                                                                  type,
2265                                                                  getOptions() );
2266         }
2267         catch ( final IOException e ) {
2268             error = true;
2269             JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2270         }
2271         if ( !error ) {
2272             if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2273                 JOptionPane.showMessageDialog( this,
2274                                                "Wrote image to: " + file_written_to,
2275                                                "Graphics Export",
2276                                                JOptionPane.INFORMATION_MESSAGE );
2277             }
2278             else {
2279                 JOptionPane.showMessageDialog( this,
2280                                                "There was an unknown problem when attempting to write to an image file: \""
2281                                                        + file_name + "\"",
2282                                                "Error",
2283                                                JOptionPane.ERROR_MESSAGE );
2284             }
2285         }
2286         _contentpane.repaint();
2287     }
2288
2289     private void writeToFile( final Phylogeny t ) {
2290         if ( t == null ) {
2291             return;
2292         }
2293         String initial_filename = null;
2294         if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2295             try {
2296                 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2297             }
2298             catch ( final IOException e ) {
2299                 initial_filename = null;
2300             }
2301         }
2302         if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2303             _save_filechooser.setSelectedFile( new File( initial_filename ) );
2304         }
2305         else {
2306             _save_filechooser.setSelectedFile( new File( "" ) );
2307         }
2308         final File my_dir = getCurrentDir();
2309         if ( my_dir != null ) {
2310             _save_filechooser.setCurrentDirectory( my_dir );
2311         }
2312         final int result = _save_filechooser.showSaveDialog( _contentpane );
2313         final File file = _save_filechooser.getSelectedFile();
2314         setCurrentDir( _save_filechooser.getCurrentDirectory() );
2315         boolean exception = false;
2316         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2317             if ( file.exists() ) {
2318                 final int i = JOptionPane.showConfirmDialog( this,
2319                                                              file + " already exists.\nOverwrite?",
2320                                                              "Overwrite?",
2321                                                              JOptionPane.OK_CANCEL_OPTION,
2322                                                              JOptionPane.QUESTION_MESSAGE );
2323                 if ( i != JOptionPane.OK_OPTION ) {
2324                     return;
2325                 }
2326                 else {
2327                     final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2328                     try {
2329                         ForesterUtil.copyFile( file, to );
2330                     }
2331                     catch ( final Exception e ) {
2332                         JOptionPane.showMessageDialog( this,
2333                                                        "Failed to create backup copy " + to,
2334                                                        "Failed to Create Backup Copy",
2335                                                        JOptionPane.WARNING_MESSAGE );
2336                     }
2337                     try {
2338                         file.delete();
2339                     }
2340                     catch ( final Exception e ) {
2341                         JOptionPane.showMessageDialog( this,
2342                                                        "Failed to delete: " + file,
2343                                                        "Failed to Delete",
2344                                                        JOptionPane.WARNING_MESSAGE );
2345                     }
2346                 }
2347             }
2348             if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2349                 exception = writeAsNewHampshire( t, exception, file );
2350             }
2351             else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2352                 exception = writeAsNHX( t, exception, file );
2353             }
2354             else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2355                 exception = writeAsPhyloXml( t, exception, file );
2356             }
2357             else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2358                 exception = writeAsNexus( t, exception, file );
2359             }
2360             // "*.*":
2361             else {
2362                 final String file_name = file.getName().trim().toLowerCase();
2363                 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2364                         || file_name.endsWith( ".tree" ) ) {
2365                     exception = writeAsNewHampshire( t, exception, file );
2366                 }
2367                 else if ( file_name.endsWith( ".nhx" ) ) {
2368                     exception = writeAsNHX( t, exception, file );
2369                 }
2370                 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2371                     exception = writeAsNexus( t, exception, file );
2372                 }
2373                 // XML is default:
2374                 else {
2375                     exception = writeAsPhyloXml( t, exception, file );
2376                 }
2377             }
2378             if ( !exception ) {
2379                 getMainPanel().setTitleOfSelectedTab( file.getName() );
2380                 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2381                 getMainPanel().getCurrentTreePanel().setEdited( false );
2382             }
2383         }
2384     }
2385
2386     private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2387         if ( ( t == null ) || t.isEmpty() ) {
2388             return;
2389         }
2390         String initial_filename = "";
2391         if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2392             initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2393         }
2394         if ( initial_filename.indexOf( '.' ) > 0 ) {
2395             initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2396         }
2397         initial_filename = initial_filename + "." + type;
2398         _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2399         final File my_dir = getCurrentDir();
2400         if ( my_dir != null ) {
2401             _writetographics_filechooser.setCurrentDirectory( my_dir );
2402         }
2403         final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2404         File file = _writetographics_filechooser.getSelectedFile();
2405         setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2406         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2407             if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2408                 file = new File( file.toString() + "." + type );
2409             }
2410             if ( file.exists() ) {
2411                 final int i = JOptionPane.showConfirmDialog( this,
2412                                                              file + " already exists. Overwrite?",
2413                                                              "Warning",
2414                                                              JOptionPane.OK_CANCEL_OPTION,
2415                                                              JOptionPane.WARNING_MESSAGE );
2416                 if ( i != JOptionPane.OK_OPTION ) {
2417                     return;
2418                 }
2419                 else {
2420                     try {
2421                         file.delete();
2422                     }
2423                     catch ( final Exception e ) {
2424                         JOptionPane.showMessageDialog( this,
2425                                                        "Failed to delete: " + file,
2426                                                        "Error",
2427                                                        JOptionPane.WARNING_MESSAGE );
2428                     }
2429                 }
2430             }
2431             writePhylogenyToGraphicsFile( file.toString(), type );
2432         }
2433     }
2434
2435     private void writeToPdf( final Phylogeny t ) {
2436         if ( ( t == null ) || t.isEmpty() ) {
2437             return;
2438         }
2439         String initial_filename = "";
2440         if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2441             initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2442         }
2443         if ( initial_filename.indexOf( '.' ) > 0 ) {
2444             initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2445         }
2446         initial_filename = initial_filename + ".pdf";
2447         _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2448         final File my_dir = getCurrentDir();
2449         if ( my_dir != null ) {
2450             _writetopdf_filechooser.setCurrentDirectory( my_dir );
2451         }
2452         final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2453         File file = _writetopdf_filechooser.getSelectedFile();
2454         setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2455         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2456             if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2457                 file = new File( file.toString() + ".pdf" );
2458             }
2459             if ( file.exists() ) {
2460                 final int i = JOptionPane.showConfirmDialog( this,
2461                                                              file + " already exists. Overwrite?",
2462                                                              "WARNING",
2463                                                              JOptionPane.OK_CANCEL_OPTION,
2464                                                              JOptionPane.WARNING_MESSAGE );
2465                 if ( i != JOptionPane.OK_OPTION ) {
2466                     return;
2467                 }
2468             }
2469             printPhylogenyToPdf( file.toString() );
2470         }
2471     }
2472
2473     static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2474         return new MainFrameApplication( phys, config, title );
2475     }
2476
2477     static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2478         return new MainFrameApplication( phys, config_file_name, title );
2479     }
2480
2481     static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2482         mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2483                 + o.getPrintSizeY() + ")" );
2484     }
2485
2486     static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2487         mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2488     }
2489
2490     static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2491         if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2492             JOptionPane
2493                     .showMessageDialog( null,
2494                                         ForesterUtil
2495                                                 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2496                                                            80 ),
2497                                         "Warning",
2498                                         JOptionPane.WARNING_MESSAGE );
2499         }
2500     }
2501
2502     private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2503         _phylogenetic_inference_options = phylogenetic_inference_options;
2504     }
2505
2506     private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2507         if ( _phylogenetic_inference_options == null ) {
2508             _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2509         }
2510         return _phylogenetic_inference_options;
2511     }
2512
2513     public Msa getMsa() {
2514         return _msa;
2515     }
2516
2517     void setMsa( final Msa msa ) {
2518         _msa = msa;
2519     }
2520
2521     void setMsaFile( final File msa_file ) {
2522         _msa_file = msa_file;
2523     }
2524
2525     public File getMsaFile() {
2526         return _msa_file;
2527     }
2528
2529     public List<Sequence> getSeqs() {
2530         return _seqs;
2531     }
2532
2533     void setSeqs( final List<Sequence> seqs ) {
2534         _seqs = seqs;
2535     }
2536
2537     void setSeqsFile( final File seqs_file ) {
2538         _seqs_file = seqs_file;
2539     }
2540
2541     public File getSeqsFile() {
2542         return _seqs_file;
2543     }
2544 } // MainFrameApplication.
2545
2546 class NexusFilter extends FileFilter {
2547
2548     @Override
2549     public boolean accept( final File f ) {
2550         final String file_name = f.getName().trim().toLowerCase();
2551         return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2552                 || file_name.endsWith( ".tre" ) || f.isDirectory();
2553     }
2554
2555     @Override
2556     public String getDescription() {
2557         return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2558     }
2559 } // NexusFilter
2560
2561 class NHFilter extends FileFilter {
2562
2563     @Override
2564     public boolean accept( final File f ) {
2565         final String file_name = f.getName().trim().toLowerCase();
2566         return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2567                 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2568                 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2569                 || f.isDirectory();
2570     }
2571
2572     @Override
2573     public String getDescription() {
2574         return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2575     }
2576 } // NHFilter
2577
2578 class NHXFilter extends FileFilter {
2579
2580     @Override
2581     public boolean accept( final File f ) {
2582         final String file_name = f.getName().trim().toLowerCase();
2583         return file_name.endsWith( ".nhx" ) || f.isDirectory();
2584     }
2585
2586     @Override
2587     public String getDescription() {
2588         return "NHX files (*.nhx)";
2589     }
2590 }
2591
2592 class PdfFilter extends FileFilter {
2593
2594     @Override
2595     public boolean accept( final File f ) {
2596         return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2597     }
2598
2599     @Override
2600     public String getDescription() {
2601         return "PDF files (*.pdf)";
2602     }
2603 } // PdfFilter
2604
2605 class TolFilter extends FileFilter {
2606
2607     @Override
2608     public boolean accept( final File f ) {
2609         final String file_name = f.getName().trim().toLowerCase();
2610         return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2611                 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2612     }
2613
2614     @Override
2615     public String getDescription() {
2616         return "Tree of Life files (*.tol, *.tolxml)";
2617     }
2618 } // TolFilter
2619
2620 class XMLFilter extends FileFilter {
2621
2622     @Override
2623     public boolean accept( final File f ) {
2624         final String file_name = f.getName().trim().toLowerCase();
2625         return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2626                 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2627     }
2628
2629     @Override
2630     public String getDescription() {
2631         return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";
2632     }
2633 } // XMLFilter