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