95f546c03018d5a57de89d7f3d9d5078130828a9
[jalview.git] / forester / java / src / org / forester / archaeopteryx / ArchaeopteryxE.java
1
2 package org.forester.archaeopteryx;
3
4 import java.awt.BorderLayout;
5 import java.awt.Container;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.awt.event.ComponentAdapter;
9 import java.awt.event.ComponentEvent;
10 import java.io.ByteArrayOutputStream;
11 import java.io.File;
12 import java.io.IOException;
13 import java.net.URL;
14 import java.util.LinkedList;
15 import java.util.List;
16 import java.util.NoSuchElementException;
17
18 import javax.swing.ButtonGroup;
19 import javax.swing.JApplet;
20 import javax.swing.JCheckBoxMenuItem;
21 import javax.swing.JMenu;
22 import javax.swing.JMenuBar;
23 import javax.swing.JMenuItem;
24 import javax.swing.JOptionPane;
25 import javax.swing.JRadioButtonMenuItem;
26 import javax.swing.UIManager;
27 import javax.swing.UnsupportedLookAndFeelException;
28 import javax.swing.event.ChangeEvent;
29 import javax.swing.event.ChangeListener;
30
31 import org.apache.commons.codec.binary.Base64;
32 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
33 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
34 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
35 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
36 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
37 import org.forester.phylogeny.Phylogeny;
38 import org.forester.phylogeny.PhylogenyMethods;
39 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
40 import org.forester.phylogeny.data.SequenceRelation;
41 import org.forester.sdi.GSDI;
42 import org.forester.sdi.GSDIR;
43 import org.forester.sdi.SDIException;
44 import org.forester.util.ForesterConstants;
45 import org.forester.util.ForesterUtil;
46
47 // Use like this:
48 // <applet archive="forester.jar"
49 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
50 // codebase="http://www.myserver.org/path/to/forester"
51 // width="600"
52 // height="500"
53 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
54 // <param name="url_of_tree_to_load"
55 // value="http://www.myserver.org/examples/data/apaf.xml">
56 // <param name="config_file"
57 // value="http://www.myserver.org/examples/config/config_file.txt">
58 // </applet>
59 public class ArchaeopteryxE extends JApplet implements ActionListener {
60
61     private final static String         NAME             = "ArchaeopteryxE";
62     private static final long           serialVersionUID = -1220055577935759443L;
63     private Configuration               _configuration;
64     private MainPanelApplets            _mainpanel;
65     private JMenuBar                    _jmenubar;
66     private JMenu                       _options_jmenu;
67     private JMenu                       _font_size_menu;
68     private JMenuItem                   _super_tiny_fonts_mi;
69     private JMenuItem                   _tiny_fonts_mi;
70     private JMenuItem                   _small_fonts_mi;
71     private JMenuItem                   _medium_fonts_mi;
72     private JMenuItem                   _large_fonts_mi;
73     private JMenu                       _tools_menu;
74     private JMenuItem                   _taxcolor_item;
75     private JMenuItem                   _confcolor_item;
76     private JMenuItem                   _midpoint_root_item;
77     private JMenu                       _view_jmenu;
78     private JMenuItem                   _view_as_XML_item;
79     private JMenuItem                   _view_as_NH_item;
80     private JMenuItem                   _view_as_nexus_item;
81     private JMenuItem                   _display_basic_information_item;
82     private JMenu                       _type_menu;
83     private JCheckBoxMenuItem           _rectangular_type_cbmi;
84     private JCheckBoxMenuItem           _triangular_type_cbmi;
85     private JCheckBoxMenuItem           _curved_type_cbmi;
86     private JCheckBoxMenuItem           _convex_type_cbmi;
87     private JCheckBoxMenuItem           _euro_type_cbmi;
88     private JCheckBoxMenuItem           _rounded_type_cbmi;
89     private JCheckBoxMenuItem           _unrooted_type_cbmi;
90     private JCheckBoxMenuItem           _circular_type_cbmi;
91     private JMenuItem                   _help_item;
92     private JMenuItem                   _about_item;
93     private JMenu                       _help_jmenu;
94     private JMenuItem                   _website_item;
95     private JMenuItem                   _phyloxml_website_item;
96     private JMenuItem                   _phyloxml_ref_item;
97     private JMenuItem                   _aptx_ref_item;
98     private JMenuItem                   _remove_branch_color_item;
99     private JMenuItem                   _remove_visual_styles_item;
100     private JCheckBoxMenuItem           _show_domain_labels;
101     private JCheckBoxMenuItem           _show_annotation_ref_source;
102     private JCheckBoxMenuItem           _color_labels_same_as_parent_branch;
103     private JCheckBoxMenuItem           _abbreviate_scientific_names;
104     private JCheckBoxMenuItem           _screen_antialias_cbmi;
105     private JCheckBoxMenuItem           _background_gradient_cbmi;
106     private JCheckBoxMenuItem           _color_by_taxonomic_group_cbmi;
107     private JRadioButtonMenuItem        _non_lined_up_cladograms_rbmi;
108     private JRadioButtonMenuItem        _uniform_cladograms_rbmi;
109     private JRadioButtonMenuItem        _ext_node_dependent_cladogram_rbmi;
110     private Options                     _options;
111     private JMenuItem                   _choose_font_mi;
112     private JMenuItem                   _switch_colors_mi;
113     JCheckBoxMenuItem                   _label_direction_cbmi;
114     private JCheckBoxMenuItem           _show_scale_cbmi;
115     private JCheckBoxMenuItem           _search_case_senstive_cbmi;
116     private JCheckBoxMenuItem           _search_whole_words_only_cbmi;
117     private JCheckBoxMenuItem           _inverse_search_result_cbmi;
118     private JCheckBoxMenuItem           _show_overview_cbmi;
119     private JMenuItem                   _choose_minimal_confidence_mi;
120     private JCheckBoxMenuItem           _show_branch_length_values_cbmi;
121     private JMenuItem                   _collapse_species_specific_subtrees;
122     private JMenuItem                   _overview_placment_mi;
123     private ButtonGroup                 _radio_group_1;
124     private JCheckBoxMenuItem           _show_default_node_shapes_internal_cbmi;
125     private JCheckBoxMenuItem           _show_default_node_shapes_external_cbmi;
126     private JMenuItem                   _cycle_node_shape_mi;
127     private JMenuItem                   _cycle_node_fill_mi;
128     private JMenuItem                   _choose_node_size_mi;
129     private JCheckBoxMenuItem           _show_confidence_stddev_cbmi;
130     private final LinkedList<TextFrame> _textframes      = new LinkedList<TextFrame>();
131     private JMenu                       _analysis_menu;
132     private JMenuItem                   _gsdi_item;
133     private JMenuItem                   _gsdir_item;
134     private Phylogeny                   _species_tree;
135     
136     private JCheckBoxMenuItem _right_line_up_domains_cbmi;
137     private JCheckBoxMenuItem _line_up_renderable_data_cbmi;
138     
139
140     @Override
141     public void actionPerformed( final ActionEvent e ) {
142         final Object o = e.getSource();
143         if ( o == _midpoint_root_item ) {
144             getMainPanel().getCurrentTreePanel().midpointRoot();
145         }
146         else if ( o == _gsdi_item ) {
147             if ( isSubtreeDisplayed() ) {
148                 return;
149             }
150             executeGSDI();
151         }
152         else if ( o == _gsdir_item ) {
153             if ( isSubtreeDisplayed() ) {
154                 return;
155             }
156             executeGSDIR();
157         }
158         else if ( o == _taxcolor_item ) {
159             getMainPanel().getCurrentTreePanel().taxColor();
160         }
161         else if ( o == _confcolor_item ) {
162             getMainPanel().getCurrentTreePanel().confColor();
163         }
164         else if ( o == _collapse_species_specific_subtrees ) {
165             if ( getCurrentTreePanel() != null ) {
166                 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
167             }
168         }
169         else if ( o == _remove_branch_color_item ) {
170             removeBranchColors();
171         }
172         else if ( o == _remove_visual_styles_item ) {
173             removeVisualStyles();
174         }
175         else if ( o == _switch_colors_mi ) {
176             switchColors();
177         }
178         else if ( o == _display_basic_information_item ) {
179             displayBasicInformation();
180         }
181         else if ( o == _view_as_NH_item ) {
182             viewAsNH();
183         }
184         else if ( o == _view_as_XML_item ) {
185             viewAsXML();
186         }
187         else if ( o == _view_as_nexus_item ) {
188             viewAsNexus();
189         }
190         else if ( o == _super_tiny_fonts_mi ) {
191             if ( getCurrentTreePanel() != null ) {
192                 getCurrentTreePanel().setSuperTinyFonts();
193                 getCurrentTreePanel().repaint();
194             }
195         }
196         else if ( o == _tiny_fonts_mi ) {
197             if ( getCurrentTreePanel() != null ) {
198                 getCurrentTreePanel().setTinyFonts();
199                 getCurrentTreePanel().repaint();
200             }
201         }
202         else if ( o == _small_fonts_mi ) {
203             if ( getCurrentTreePanel() != null ) {
204                 getCurrentTreePanel().setSmallFonts();
205                 getCurrentTreePanel().repaint();
206             }
207         }
208         else if ( o == _medium_fonts_mi ) {
209             if ( getCurrentTreePanel() != null ) {
210                 getCurrentTreePanel().setMediumFonts();
211                 getCurrentTreePanel().repaint();
212             }
213         }
214         else if ( o == _large_fonts_mi ) {
215             if ( getCurrentTreePanel() != null ) {
216                 getCurrentTreePanel().setLargeFonts();
217                 getCurrentTreePanel().repaint();
218             }
219         }
220         else if ( o == _choose_font_mi ) {
221             chooseFont();
222         }
223         else if ( o == _choose_minimal_confidence_mi ) {
224             chooseMinimalConfidence();
225         }
226         else if ( o == _choose_node_size_mi ) {
227             MainFrame.chooseNodeSize( getOptions(), this );
228         }
229         else if ( o == _overview_placment_mi ) {
230             MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
231         }
232         else if ( o == _cycle_node_fill_mi ) {
233             MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
234         }
235         else if ( o == _cycle_node_shape_mi ) {
236             MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
237         }
238         else if ( o == _non_lined_up_cladograms_rbmi ) {
239             updateOptions( getOptions() );
240             _mainpanel.getControlPanel().showWhole();
241         }
242         else if ( o == _uniform_cladograms_rbmi ) {
243             updateOptions( getOptions() );
244             _mainpanel.getControlPanel().showWhole();
245         }
246         else if ( o == _ext_node_dependent_cladogram_rbmi ) {
247             updateOptions( getOptions() );
248             _mainpanel.getControlPanel().showWhole();
249         }
250         else if ( o == _search_case_senstive_cbmi ) {
251             updateOptions( getOptions() );
252             getMainPanel().getControlPanel().search0();
253             getMainPanel().getControlPanel().search1();
254         }
255         else if ( o == _search_whole_words_only_cbmi ) {
256             updateOptions( getOptions() );
257             getMainPanel().getControlPanel().search0();
258             getMainPanel().getControlPanel().search1();
259         }
260         else if ( o == _inverse_search_result_cbmi ) {
261             updateOptions( getOptions() );
262             getMainPanel().getControlPanel().search0();
263             getMainPanel().getControlPanel().search1();
264         }
265         else if ( o == _show_scale_cbmi ) {
266             updateOptions( getOptions() );
267         }
268         else if ( o == _show_branch_length_values_cbmi ) {
269             updateOptions( getOptions() );
270         }
271         else if ( o == _show_confidence_stddev_cbmi ) {
272             updateOptions( getOptions() );
273         }
274         else if ( o == _label_direction_cbmi ) {
275             updateOptions( getOptions() );
276         }
277         else if ( o == _abbreviate_scientific_names ) {
278             updateOptions( getOptions() );
279         }
280         else if ( o == _show_overview_cbmi ) {
281             updateOptions( getOptions() );
282             if ( getCurrentTreePanel() != null ) {
283                 getCurrentTreePanel().updateOvSizes();
284             }
285         }
286         else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
287                 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
288                 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
289             typeChanged( o );
290         }
291         else if ( o == _screen_antialias_cbmi ) {
292             updateOptions( getOptions() );
293             setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
294         }
295         else if ( o == _background_gradient_cbmi ) {
296             updateOptions( getOptions() );
297         }
298         else if ( o == _show_domain_labels ) {
299             updateOptions( getOptions() );
300         }
301         else if ( o == _color_labels_same_as_parent_branch ) {
302             updateOptions( getOptions() );
303         }
304         else if ( o == _show_default_node_shapes_internal_cbmi ) {
305             updateOptions( getOptions() );
306         }
307         else if ( o == _show_default_node_shapes_external_cbmi ) {
308             updateOptions( getOptions() );
309         }
310         else if ( o == _about_item ) {
311             MainFrame.about();
312         }
313         else if ( o == _help_item ) {
314             try {
315                 AptxUtil.openWebsite( Constants.APTX_DOC_SITE, true, this );
316             }
317             catch ( final IOException e1 ) {
318                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
319             }
320         }
321         else if ( o == _website_item ) {
322             try {
323                 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
324             }
325             catch ( final IOException e1 ) {
326                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
327             }
328         }
329         else if ( o == _phyloxml_website_item ) {
330             try {
331                 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
332             }
333             catch ( final IOException e1 ) {
334                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
335             }
336         }
337         else if ( o == _aptx_ref_item ) {
338             try {
339                 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
340             }
341             catch ( final IOException e1 ) {
342                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
343             }
344         }
345         else if ( o == _phyloxml_ref_item ) {
346             try {
347                 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
348             }
349             catch ( final IOException e1 ) {
350                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
351             }
352         }
353         else if ( o == _color_by_taxonomic_group_cbmi ) {
354             updateOptions( getOptions() );
355         }
356        
357         
358         
359         else if ( o == _line_up_renderable_data_cbmi ) {
360             if ( !_line_up_renderable_data_cbmi.isSelected() ) {
361                 _right_line_up_domains_cbmi.setSelected( false );
362             }
363             updateOptions( getOptions() );
364         }
365         else if ( o == _right_line_up_domains_cbmi ) {
366             if ( _right_line_up_domains_cbmi.isSelected() ) {
367                 _line_up_renderable_data_cbmi.setSelected( true );
368             }
369             updateOptions( getOptions() );
370         }
371         
372         repaint();
373     }
374
375     @Override
376     public void destroy() {
377         AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
378         removeAllTextFrames();
379         if ( getMainPanel() != null ) {
380             getMainPanel().terminate();
381         }
382     }
383
384     /**
385      * This method returns the current external node data which
386      * has been selected by the user by clicking the "Return ..."
387      * menu item. This method is expected to be called from Javascript or
388      * something like it.
389      * 
390      * @return current external node data as String
391      */
392     public String getCurrentExternalNodesDataBuffer() {
393         return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
394     }
395
396     public int getCurrentExternalNodesDataBufferChangeCounter() {
397         return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
398     }
399
400     public int getCurrentExternalNodesDataBufferLength() {
401         return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
402     }
403
404     /**
405      * This method returns the current phylogeny as a string in the chosen format
406      * 
407      * @param format must be NH, NHX, NEXUS or PHYLOXML
408      * @return the phylogeny string
409      * @author Herve Menager
410      */
411     public String getCurrentPhylogeny( final String format ) {
412         removeAllTextFrames();
413         if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
414                 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
415             return new String();
416         }
417         switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
418             case NH:
419                 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
420             case NHX:
421                 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
422             case NEXUS:
423                 return getMainPanel().getCurrentPhylogeny().toNexus();
424             case PHYLOXML:
425                 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
426             default:
427                 break;
428         }
429         return new String();
430     }
431
432     /**
433      * This method returns a view of the current phylogeny in a chosen 
434      * graphics format, base64-encoded in a string so that in can be used
435      * from javascript.
436      * 
437      * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
438      * @return the phylogeny string
439      * @author Herve Menager
440      */
441     public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
442         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
443         try {
444             AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
445                                                                     _mainpanel.getWidth(),
446                                                                     _mainpanel.getHeight(),
447                                                                     getCurrentTreePanel(),
448                                                                     getCurrentTreePanel().getControlPanel(),
449                                                                     GraphicsExportType.valueOf( format ),
450                                                                     getOptions() );
451         }
452         catch ( final IOException ioe ) {
453             ForesterUtil.printErrorMessage( NAME, ioe.toString() );
454             ioe.printStackTrace();
455             JOptionPane.showMessageDialog( this,
456                                            NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
457                                            "Failed to generate graphics",
458                                            JOptionPane.ERROR_MESSAGE );
459             return null;
460         }
461         final byte[] bytes = baos.toByteArray();
462         final String dataImg = Base64.encodeBase64String( bytes );
463         return dataImg;
464     }
465
466     public Options getOptions() {
467         return _options;
468     }
469
470     @Override
471     public void init() {
472         final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
473         AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
474         final Configuration configuration = new Configuration( config_filename, true, true, true );
475         setConfiguration( configuration );
476         setOptions( Options.createInstance( configuration ) );
477         setupUI();
478         final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
479         if ( ForesterUtil.isEmpty( tree_url_str ) ) {
480             ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
481                     + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
482             JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
483                     + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
484             return;
485         }
486         AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
487         // Get URL to tree file
488         URL phys_url = null;
489         try {
490             phys_url = new URL( tree_url_str );
491         }
492         catch ( final Exception e ) {
493             ForesterUtil.printErrorMessage( NAME, "error: " + e );
494             e.printStackTrace();
495             JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
496                     + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
497         }
498         if ( phys_url == null ) {
499             ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
500                     + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
501             JOptionPane.showMessageDialog( this,
502                                            NAME + ": Could not create URL from: \"" + tree_url_str,
503                                            "Failed to create URL",
504                                            JOptionPane.ERROR_MESSAGE );
505             return;
506         }
507         // Load the tree from URL
508         Phylogeny[] phys = null;
509         try {
510             phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
511                                                     getConfiguration().isValidatePhyloXmlAgainstSchema(),
512                                                     getConfiguration().isReplaceUnderscoresInNhParsing(),
513                                                     getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
514                                                     getConfiguration().getTaxonomyExtraction(),
515                                                     getConfiguration().isMidpointReroot() );
516         }
517         catch ( final Exception e ) {
518             ForesterUtil.printErrorMessage( NAME, e.toString() );
519             e.printStackTrace();
520             JOptionPane.showMessageDialog( this,
521                                            NAME + ": Failed to read phylogenies: " + "\nException: " + e,
522                                            "Failed to read phylogenies",
523                                            JOptionPane.ERROR_MESSAGE );
524         }
525         if ( phys == null ) {
526             ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
527             JOptionPane.showMessageDialog( this,
528                                            NAME + ": phylogenies from [" + phys_url + "] are null",
529                                            "Failed to read phylogenies",
530                                            JOptionPane.ERROR_MESSAGE );
531             return;
532         }
533         else if ( phys.length < 1 ) {
534             ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
535             JOptionPane.showMessageDialog( this,
536                                            NAME + ": phylogenies from [" + phys_url + "] are empty",
537                                            "Failed to read phylogenies",
538                                            JOptionPane.ERROR_MESSAGE );
539             return;
540         }
541         else {
542             AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
543         }
544         //
545         final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
546         if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
547             AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
548             Phylogeny[] species_trees = null;
549             try {
550                 final URL species_tree_url = new URL( species_tree_url_str );
551                 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
552                                                                  configuration.isValidatePhyloXmlAgainstSchema(),
553                                                                  configuration.isReplaceUnderscoresInNhParsing(),
554                                                                  false,
555                                                                  TAXONOMY_EXTRACTION.NO,
556                                                                  false );
557             }
558             catch ( final IOException e ) {
559                 ForesterUtil.printErrorMessage( NAME, "could not read species tree from  [" + species_tree_url_str
560                         + "]" );
561                 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from  ["
562                         + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
563             }
564             if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
565                 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
566                 if ( species_trees[ 0 ].isEmpty() ) {
567                     ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
568                 }
569                 else if ( !species_trees[ 0 ].isRooted() ) {
570                     ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
571                 }
572                 else {
573                     setSpeciesTree( species_trees[ 0 ] );
574                     AptxUtil.printAppletMessage( NAME, "species tree OK" );
575                 }
576             }
577         }
578         //
579         setVisible( false );
580         setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
581         _jmenubar = new JMenuBar();
582         if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
583             if ( !getConfiguration().isUseNativeUI() ) {
584                 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
585             }
586             if ( getSpeciesTree() != null ) {
587                 buildAnalysisMenu();
588             }
589             buildToolsMenu();
590             buildViewMenu();
591             buildFontSizeMenu();
592             buildOptionsMenu();
593             buildTypeMenu();
594             buildHelpMenu();
595             setJMenuBar( _jmenubar );
596         }
597         final Container contentpane = getContentPane();
598         contentpane.setLayout( new BorderLayout() );
599         contentpane.add( getMainPanel(), BorderLayout.CENTER );
600         addComponentListener( new ComponentAdapter() {
601
602             @Override
603             public void componentResized( final ComponentEvent e ) {
604                 if ( getMainPanel().getCurrentTreePanel() != null ) {
605                     getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
606                                                                                             .getCurrentTreePanel()
607                                                                                             .getWidth(),
608                                                                                     getMainPanel()
609                                                                                             .getCurrentTreePanel()
610                                                                                             .getHeight(),
611                                                                                     getOptions()
612                                                                                             .isAllowFontSizeChange() );
613                 }
614             }
615         } );
616         if ( getConfiguration().isUseTabbedDisplay() ) {
617             AptxUtil.printAppletMessage( NAME, "using tabbed display" );
618             AptxUtil.addPhylogeniesToTabs( phys,
619                                            new File( phys_url.getFile() ).getName(),
620                                            phys_url.toString(),
621                                            getConfiguration(),
622                                            getMainPanel() );
623         }
624         else {
625             AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
626             if ( getSpeciesTree() != null ) {
627                 AptxUtil.printAppletMessage( NAME,
628                                              "Warning: gsdi (gene duplication inference) only available tabbed display" );
629             }
630             AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
631         }
632         validate();
633         setName( NAME );
634         getMainPanel().getControlPanel().showWholeAll();
635         getMainPanel().getControlPanel().showWhole();
636         /* GUILHEM_BEG */
637         getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
638         for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
639                 .getRelevantSequenceRelationTypes() ) {
640             getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
641         }
642         final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
643         if ( default_relation != null ) {
644             getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
645         }
646         final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
647         if ( default_sequence != null ) {
648             getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
649         }
650         /* GUILHEM_END */
651         System.gc();
652         AptxUtil.printAppletMessage( NAME, "successfully initialized" );
653         setVisible( true );
654     }
655
656     public void showTextFrame( final String s, final String title ) {
657         checkTextFrames();
658         _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
659     }
660
661     @Override
662     public void start() {
663         if ( getMainPanel() != null ) {
664             getMainPanel().validate();
665         }
666         requestFocus();
667         requestFocusInWindow();
668         requestFocus();
669         AptxUtil.printAppletMessage( NAME, "started" );
670     }
671
672     void buildAnalysisMenu() {
673         _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
674         _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
675         _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
676         customizeJMenuItem( _gsdi_item );
677         customizeJMenuItem( _gsdir_item );
678         //  _analysis_menu.addSeparator();
679         //  _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
680         //  customizeJMenuItem( _lineage_inference );
681         //  _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
682         _jmenubar.add( _analysis_menu );
683     }
684
685     void buildFontSizeMenu() {
686         _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
687         _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
688         _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
689         _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
690         _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
691         _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
692         customizeJMenuItem( _super_tiny_fonts_mi );
693         customizeJMenuItem( _tiny_fonts_mi );
694         customizeJMenuItem( _small_fonts_mi );
695         customizeJMenuItem( _medium_fonts_mi );
696         customizeJMenuItem( _large_fonts_mi );
697         _jmenubar.add( _font_size_menu );
698     }
699
700     void buildHelpMenu() {
701         _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
702         _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
703         _help_jmenu.addSeparator();
704         _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
705         _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
706         _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
707         _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
708         _help_jmenu.addSeparator();
709         _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
710         customizeJMenuItem( _help_item );
711         customizeJMenuItem( _website_item );
712         customizeJMenuItem( _phyloxml_website_item );
713         customizeJMenuItem( _aptx_ref_item );
714         customizeJMenuItem( _phyloxml_ref_item );
715         customizeJMenuItem( _about_item );
716         _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
717         _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
718         _jmenubar.add( _help_jmenu );
719     }
720
721     void buildOptionsMenu() {
722         _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
723         _options_jmenu.addChangeListener( new ChangeListener() {
724
725             @Override
726             public void stateChanged( final ChangeEvent e ) {
727                 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
728                 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
729                 MainFrame
730                         .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
731                 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
732                         .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
733                 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
734                                                                      _show_scale_cbmi,
735                                                                      _show_branch_length_values_cbmi,
736                                                                      _non_lined_up_cladograms_rbmi,
737                                                                      _uniform_cladograms_rbmi,
738                                                                      _ext_node_dependent_cladogram_rbmi,
739                                                                      _label_direction_cbmi );
740                 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
741                 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
742                 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
743             }
744         } );
745         _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
746                                                                 getConfiguration() ) );
747         _options_jmenu
748                 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
749         _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
750         _options_jmenu
751                 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
752         _radio_group_1 = new ButtonGroup();
753         _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
754         _radio_group_1.add( _uniform_cladograms_rbmi );
755         _radio_group_1.add( _non_lined_up_cladograms_rbmi );
756         /////
757         _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
758         _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
759         _options_jmenu
760                 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
761         _options_jmenu
762                 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
763         _options_jmenu
764                 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
765         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
766             _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
767             _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
768         }
769         _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
770         _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
771         _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
772         _options_jmenu
773                 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
774         _options_jmenu
775                 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
776         _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
777         _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
778         _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
779         _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
780         _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
781         _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
782         _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
783         _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
784         _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
785         _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
786         _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
787         _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
788         _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
789         /////
790         _options_jmenu.addSeparator();
791         _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
792                                                                 getConfiguration() ) );
793         _options_jmenu
794                 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
795         _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
796         _options_jmenu
797                 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
798         customizeJMenuItem( _choose_font_mi );
799         customizeJMenuItem( _choose_minimal_confidence_mi );
800         customizeJMenuItem( _switch_colors_mi );
801         customizeJMenuItem( _overview_placment_mi );
802         customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
803         customizeCheckBoxMenuItem( _label_direction_cbmi,
804                                    getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
805         customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
806         customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
807         customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
808         customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
809         customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
810         customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
811                 .isShowDefaultNodeShapesExternal() );
812         customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
813                 .isShowDefaultNodeShapesInternal() );
814         customizeJMenuItem( _cycle_node_shape_mi );
815         customizeJMenuItem( _cycle_node_fill_mi );
816         customizeJMenuItem( _choose_node_size_mi );
817         customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
818         customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
819         customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
820         customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
821                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
822         customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
823                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
824         customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
825                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
826         customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
827         customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
828         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
829         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
830         customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
831         _jmenubar.add( _options_jmenu );
832     }
833
834     void buildToolsMenu() {
835         _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
836         _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
837         customizeJMenuItem( _confcolor_item );
838         _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
839         customizeJMenuItem( _taxcolor_item );
840         _tools_menu.addSeparator();
841         _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
842         _remove_visual_styles_item
843                 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
844         customizeJMenuItem( _remove_visual_styles_item );
845         _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
846         _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
847         customizeJMenuItem( _remove_branch_color_item );
848         _tools_menu.addSeparator();
849         _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
850         customizeJMenuItem( _midpoint_root_item );
851         _tools_menu.addSeparator();
852         _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
853         customizeJMenuItem( _collapse_species_specific_subtrees );
854         _jmenubar.add( _tools_menu );
855     }
856
857     void buildTypeMenu() {
858         _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
859         _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
860         _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
861         _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
862         _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
863         _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
864         _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
865         _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
866         _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
867         customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
868         customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
869         customizeCheckBoxMenuItem( _euro_type_cbmi, false );
870         customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
871         customizeCheckBoxMenuItem( _curved_type_cbmi, false );
872         customizeCheckBoxMenuItem( _convex_type_cbmi, false );
873         customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
874         customizeCheckBoxMenuItem( _circular_type_cbmi, false );
875         _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
876         _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
877         initializeTypeMenu( getOptions() );
878         _jmenubar.add( _type_menu );
879     }
880
881     void buildViewMenu() {
882         _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
883         _view_jmenu
884                 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
885         _view_jmenu.addSeparator();
886         _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
887         _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
888         _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
889         customizeJMenuItem( _display_basic_information_item );
890         customizeJMenuItem( _view_as_NH_item );
891         customizeJMenuItem( _view_as_XML_item );
892         customizeJMenuItem( _view_as_nexus_item );
893         _jmenubar.add( _view_jmenu );
894     }
895
896     void checkTextFrames() {
897         if ( _textframes.size() > 5 ) {
898             try {
899                 if ( _textframes.getFirst() != null ) {
900                     _textframes.getFirst().removeMe();
901                 }
902                 else {
903                     _textframes.removeFirst();
904                 }
905             }
906             catch ( final NoSuchElementException e ) {
907                 // Ignore.
908             }
909         }
910     }
911
912     void clearCurrentExternalNodesDataBuffer() {
913         getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
914     }
915
916     void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
917         if ( item != null ) {
918             item.setFont( MainFrame.menu_font );
919             if ( !getConfiguration().isUseNativeUI() ) {
920                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
921                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
922             }
923             item.setSelected( is_selected );
924             item.addActionListener( this );
925         }
926     }
927
928     void customizeJMenuItem( final JMenuItem jmi ) {
929         jmi.setFont( MainFrame.menu_font );
930         if ( !getConfiguration().isUseNativeUI() ) {
931             jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
932             jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
933         }
934         jmi.addActionListener( this );
935     }
936
937     void displayBasicInformation() {
938         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
939             String title = "Basic Information";
940             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
941                 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
942             }
943             showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
944         }
945     }
946
947     void executeGSDI() {
948         if ( !isOKforSDI( false, true ) ) {
949             return;
950         }
951         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
952             JOptionPane.showMessageDialog( this,
953                                            "Gene tree is not rooted.",
954                                            "Cannot execute GSDI",
955                                            JOptionPane.ERROR_MESSAGE );
956             return;
957         }
958         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
959         gene_tree.setAllNodesToNotCollapse();
960         gene_tree.recalculateNumberOfExternalDescendants( false );
961         GSDI gsdi = null;
962         final Phylogeny species_tree = _species_tree.copy();
963         try {
964             gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
965         }
966         catch ( final SDIException e ) {
967             JOptionPane.showMessageDialog( this,
968                                            e.getLocalizedMessage(),
969                                            "Error during GSDI",
970                                            JOptionPane.ERROR_MESSAGE );
971             return;
972         }
973         catch ( final Exception e ) {
974             AptxUtil.unexpectedException( e );
975             return;
976         }
977         gene_tree.setRerootable( false );
978         gene_tree.clearHashIdToNodeMap();
979         gene_tree.recalculateNumberOfExternalDescendants( true );
980         _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
981         getMainPanel().getControlPanel().setShowEvents( true );
982         showWhole();
983         final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
984         _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
985         showWhole();
986         _mainpanel.getTabbedPane().setSelectedIndex( selected );
987         showWhole();
988         _mainpanel.getCurrentTreePanel().setEdited( true );
989         final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
990         if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
991             JOptionPane.showMessageDialog( this,
992                                            "Duplications: " + gsdi.getDuplicationsSum() + "\n"
993                                                    + "Potential duplications: "
994                                                    + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
995                                                    + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
996                                                    + "Stripped gene tree nodes: "
997                                                    + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
998                                                    + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
999                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1000                                            "GSDI successfully completed",
1001                                            JOptionPane.WARNING_MESSAGE );
1002         }
1003         else {
1004             JOptionPane.showMessageDialog( this,
1005                                            "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1006                                                    + "Potential duplications: "
1007                                                    + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1008                                                    + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1009                                                    + "Stripped gene tree nodes: "
1010                                                    + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1011                                                    + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1012                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1013                                            "GSDI successfully completed",
1014                                            JOptionPane.INFORMATION_MESSAGE );
1015         }
1016     }
1017
1018     void executeGSDIR() {
1019         if ( !isOKforSDI( false, false ) ) {
1020             return;
1021         }
1022         final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1023         if ( ( p > 0 )
1024                 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1025             JOptionPane.showMessageDialog( this,
1026                                            "Gene tree is not completely binary",
1027                                            "Cannot execute GSDI",
1028                                            JOptionPane.ERROR_MESSAGE );
1029             return;
1030         }
1031         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1032         gene_tree.setAllNodesToNotCollapse();
1033         gene_tree.recalculateNumberOfExternalDescendants( false );
1034         GSDIR gsdir = null;
1035         final Phylogeny species_tree = _species_tree.copy();
1036         try {
1037             gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1038         }
1039         catch ( final SDIException e ) {
1040             JOptionPane.showMessageDialog( this,
1041                                            e.getLocalizedMessage(),
1042                                            "Error during GSDIR",
1043                                            JOptionPane.ERROR_MESSAGE );
1044             return;
1045         }
1046         catch ( final Exception e ) {
1047             AptxUtil.unexpectedException( e );
1048             return;
1049         }
1050         final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1051         result_gene_tree.setRerootable( false );
1052         result_gene_tree.clearHashIdToNodeMap();
1053         result_gene_tree.recalculateNumberOfExternalDescendants( true );
1054         PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1055         _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1056         getMainPanel().getControlPanel().setShowEvents( true );
1057         showWhole();
1058         final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1059         _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1060         showWhole();
1061         _mainpanel.getTabbedPane().setSelectedIndex( selected );
1062         showWhole();
1063         _mainpanel.getCurrentTreePanel().setEdited( true );
1064         final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1065         if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1066             JOptionPane.showMessageDialog( this,
1067                                            "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1068                                                    + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1069                                                    + "Stripped gene tree nodes: "
1070                                                    + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1071                                                    + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1072                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1073                                            "GSDIR successfully completed",
1074                                            JOptionPane.WARNING_MESSAGE );
1075         }
1076         else {
1077             JOptionPane.showMessageDialog( this,
1078                                            "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1079                                                    + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1080                                                    + "Stripped gene tree nodes: "
1081                                                    + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1082                                                    + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1083                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1084                                            "GSDIR successfully completed",
1085                                            JOptionPane.INFORMATION_MESSAGE );
1086         }
1087     }
1088
1089     Configuration getConfiguration() {
1090         return _configuration;
1091     }
1092
1093     TreePanel getCurrentTreePanel() {
1094         return getMainPanel().getCurrentTreePanel();
1095     }
1096
1097     JCheckBoxMenuItem getlabelDirectionCbmi() {
1098         return _label_direction_cbmi;
1099     }
1100
1101     Options getOtions() {
1102         return _options;
1103     }
1104
1105    
1106
1107     void initializeTypeMenu( final Options options ) {
1108         setTypeMenuToAllUnselected();
1109         try {
1110             switch ( options.getPhylogenyGraphicsType() ) {
1111                 case CONVEX:
1112                     _convex_type_cbmi.setSelected( true );
1113                     break;
1114                 case CURVED:
1115                     _curved_type_cbmi.setSelected( true );
1116                     break;
1117                 case EURO_STYLE:
1118                     _euro_type_cbmi.setSelected( true );
1119                     break;
1120                 case ROUNDED:
1121                     _rounded_type_cbmi.setSelected( true );
1122                     break;
1123                 case TRIANGULAR:
1124                     _triangular_type_cbmi.setSelected( true );
1125                     break;
1126                 case UNROOTED:
1127                     _unrooted_type_cbmi.setSelected( true );
1128                     break;
1129                 case CIRCULAR:
1130                     _circular_type_cbmi.setSelected( true );
1131                     break;
1132                 default:
1133                     _rectangular_type_cbmi.setSelected( true );
1134                     break;
1135             }
1136         }
1137         catch ( final NullPointerException np ) {
1138             // In all likelihood, this is caused by menu-less display.
1139         }
1140     }
1141
1142     boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1143         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1144             return false;
1145         }
1146         else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1147             JOptionPane.showMessageDialog( this,
1148                                            "No species tree loaded",
1149                                            "Cannot execute GSDI",
1150                                            JOptionPane.ERROR_MESSAGE );
1151             return false;
1152         }
1153         else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1154             JOptionPane.showMessageDialog( this,
1155                                            "Species tree is not completely binary",
1156                                            "Cannot execute GSDI",
1157                                            JOptionPane.ERROR_MESSAGE );
1158             return false;
1159         }
1160         else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1161             JOptionPane.showMessageDialog( this,
1162                                            "Gene tree is not completely binary",
1163                                            "Cannot execute GSDI",
1164                                            JOptionPane.ERROR_MESSAGE );
1165             return false;
1166         }
1167         else {
1168             return true;
1169         }
1170     }
1171
1172     boolean isSubtreeDisplayed() {
1173         if ( getCurrentTreePanel() != null ) {
1174             if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1175                 JOptionPane
1176                         .showMessageDialog( this,
1177                                             "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1178                                             "Operation can not be exectuted on a sub-tree",
1179                                             JOptionPane.WARNING_MESSAGE );
1180                 return true;
1181             }
1182         }
1183         return false;
1184     }
1185
1186     void removeAllTextFrames() {
1187         for( final TextFrame tf : _textframes ) {
1188             if ( tf != null ) {
1189                 tf.close();
1190             }
1191         }
1192         _textframes.clear();
1193     }
1194
1195     void setConfiguration( final Configuration configuration ) {
1196         _configuration = configuration;
1197     }
1198
1199     void setOptions( final Options options ) {
1200         _options = options;
1201     }
1202
1203     void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1204         setTypeMenuToAllUnselected();
1205         try {
1206             switch ( type ) {
1207                 case CIRCULAR:
1208                     _circular_type_cbmi.setSelected( true );
1209                     break;
1210                 case CONVEX:
1211                     _convex_type_cbmi.setSelected( true );
1212                     break;
1213                 case CURVED:
1214                     _curved_type_cbmi.setSelected( true );
1215                     break;
1216                 case EURO_STYLE:
1217                     _euro_type_cbmi.setSelected( true );
1218                     break;
1219                 case ROUNDED:
1220                     _rounded_type_cbmi.setSelected( true );
1221                     break;
1222                 case RECTANGULAR:
1223                     _rectangular_type_cbmi.setSelected( true );
1224                     break;
1225                 case TRIANGULAR:
1226                     _triangular_type_cbmi.setSelected( true );
1227                     break;
1228                 case UNROOTED:
1229                     _unrooted_type_cbmi.setSelected( true );
1230                     break;
1231                 default:
1232                     throw new IllegalArgumentException( "unknown type: " + type );
1233             }
1234         }
1235         catch ( final NullPointerException np ) {
1236             // In all likelihood, this is caused by menu-less display.
1237         }
1238     }
1239
1240     void setTypeMenuToAllUnselected() {
1241         if ( _convex_type_cbmi != null ) {
1242             _convex_type_cbmi.setSelected( false );
1243         }
1244         if ( _curved_type_cbmi != null ) {
1245             _curved_type_cbmi.setSelected( false );
1246         }
1247         if ( _euro_type_cbmi != null ) {
1248             _euro_type_cbmi.setSelected( false );
1249         }
1250         if ( _rounded_type_cbmi != null ) {
1251             _rounded_type_cbmi.setSelected( false );
1252         }
1253         if ( _triangular_type_cbmi != null ) {
1254             _triangular_type_cbmi.setSelected( false );
1255         }
1256         if ( _rectangular_type_cbmi != null ) {
1257             _rectangular_type_cbmi.setSelected( false );
1258         }
1259         if ( _unrooted_type_cbmi != null ) {
1260             _unrooted_type_cbmi.setSelected( false );
1261         }
1262         if ( _circular_type_cbmi != null ) {
1263             _circular_type_cbmi.setSelected( false );
1264         }
1265     }
1266
1267     void showWhole() {
1268         _mainpanel.getControlPanel().showWhole();
1269     }
1270
1271     void switchColors() {
1272         final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1273         final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1274         csc.setVisible( true );
1275         getMainPanel().setTreeColorSet( colorset );
1276     }
1277
1278     void typeChanged( final Object o ) {
1279         updateTypeCheckboxes( getOptions(), o );
1280         updateOptions( getOptions() );
1281         if ( getCurrentTreePanel() != null ) {
1282             final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1283             final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1284             if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1285                     || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1286                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1287                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1288                 getCurrentTreePanel().getControlPanel().showWhole();
1289             }
1290             if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1291                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1292             }
1293             else {
1294                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1295             }
1296             getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1297             MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1298         }
1299     }
1300
1301     void updateOptions( final Options options ) {
1302         options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1303         options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1304                 && _background_gradient_cbmi.isSelected() );
1305         options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1306         options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1307                 && _show_annotation_ref_source.isSelected() );
1308         options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1309                 && _abbreviate_scientific_names.isSelected() );
1310         options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1311                 && _color_labels_same_as_parent_branch.isSelected() );
1312         options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1313                 && _show_default_node_shapes_internal_cbmi.isSelected() );
1314         options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1315                 && _show_default_node_shapes_external_cbmi.isSelected() );
1316         if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1317             options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1318         }
1319         else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1320             options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1321         }
1322         else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1323             options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1324         }
1325         options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1326                 && _search_case_senstive_cbmi.isSelected() );
1327         if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1328             options.setShowScale( _show_scale_cbmi.isSelected() );
1329         }
1330         if ( _label_direction_cbmi != null ) {
1331             if ( _label_direction_cbmi.isSelected() ) {
1332                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1333             }
1334             else {
1335                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1336             }
1337         }
1338         options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1339         options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1340                 && _show_confidence_stddev_cbmi.isSelected() );
1341         if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1342             options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1343         }
1344         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1345                 && _search_whole_words_only_cbmi.isSelected() );
1346         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1347                 && _inverse_search_result_cbmi.isSelected() );
1348         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1349             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1350         }
1351         else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1352             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1353         }
1354         else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1355             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1356         }
1357         else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1358             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1359         }
1360         else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1361             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1362         }
1363         else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1364             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1365         }
1366         else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1367             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1368         }
1369         else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1370             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1371         }
1372         if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1373             options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1374         }
1375         
1376        
1377         if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1378             options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1379         }
1380         
1381         
1382         if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1383             options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1384         }
1385         
1386     }
1387
1388     void updateTypeCheckboxes( final Options options, final Object o ) {
1389         setTypeMenuToAllUnselected();
1390         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1391     }
1392
1393     void viewAsNexus() {
1394         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1395             String title = "Nexus";
1396             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1397                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1398             }
1399             showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1400                                    .getNhConversionSupportValueStyle() ),
1401                            title );
1402         }
1403     }
1404
1405     void viewAsNH() {
1406         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1407             String title = "New Hampshire";
1408             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1409                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1410             }
1411             showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1412                                    .getNhConversionSupportValueStyle() ),
1413                            title );
1414         }
1415     }
1416
1417     void viewAsXML() {
1418         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1419             String title = "phyloXML";
1420             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1421                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1422             }
1423             showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1424         }
1425     }
1426
1427     private void chooseFont() {
1428         final FontChooser fc = new FontChooser();
1429         fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1430         fc.showDialog( this, "Select the Base Font" );
1431         getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1432     }
1433
1434     private void chooseMinimalConfidence() {
1435         final String s = ( String ) JOptionPane
1436                 .showInputDialog( this,
1437                                   "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1438                                           + getOptions().getMinConfidenceValue() + "]\n",
1439                                   "Minimal Confidence Value",
1440                                   JOptionPane.QUESTION_MESSAGE,
1441                                   null,
1442                                   null,
1443                                   getOptions().getMinConfidenceValue() );
1444         if ( !ForesterUtil.isEmpty( s ) ) {
1445             boolean success = true;
1446             double m = 0.0;
1447             final String m_str = s.trim();
1448             if ( !ForesterUtil.isEmpty( m_str ) ) {
1449                 try {
1450                     m = Double.parseDouble( m_str );
1451                 }
1452                 catch ( final Exception ex ) {
1453                     success = false;
1454                 }
1455             }
1456             else {
1457                 success = false;
1458             }
1459             if ( success && ( m >= 0.0 ) ) {
1460                 getOptions().setMinConfidenceValue( m );
1461             }
1462         }
1463     }
1464
1465     private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1466         if ( item != null ) {
1467             item.setFont( MainFrame.menu_font );
1468             if ( !getConfiguration().isUseNativeUI() ) {
1469                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1470                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1471             }
1472             item.setSelected( is_selected );
1473             item.addActionListener( this );
1474         }
1475     }
1476
1477     private MainPanel getMainPanel() {
1478         return _mainpanel;
1479     }
1480
1481     private Phylogeny getSpeciesTree() {
1482         return _species_tree;
1483     }
1484
1485     private boolean isScreenAntialias() {
1486         return true;
1487     }
1488
1489     private void removeBranchColors() {
1490         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1491             AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1492         }
1493     }
1494
1495     private void removeVisualStyles() {
1496         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1497             AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1498         }
1499     }
1500
1501     private void setMainPanel( final MainPanelApplets main_panel ) {
1502         _mainpanel = main_panel;
1503     }
1504
1505     private void setSpeciesTree( final Phylogeny species_tree ) {
1506         _species_tree = species_tree;
1507     }
1508
1509     private void setupUI() {
1510         try {
1511             if ( getConfiguration().isUseNativeUI() ) {
1512                 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1513             }
1514             else {
1515                 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1516             }
1517         }
1518         catch ( final UnsupportedLookAndFeelException e ) {
1519             AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1520         }
1521         catch ( final ClassNotFoundException e ) {
1522             AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1523         }
1524         catch ( final InstantiationException e ) {
1525             AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1526         }
1527         catch ( final IllegalAccessException e ) {
1528             AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1529         }
1530         catch ( final Exception e ) {
1531             AptxUtil.dieWithSystemError( e.toString() );
1532         }
1533     }
1534
1535     static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1536         for( final TreePanel tree_panel : treepanels ) {
1537             tree_panel.setTextAntialias();
1538         }
1539     }
1540 }