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