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