251a43c8670a3142df13fd3f25269ad70c111486
[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         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
762             _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
763             _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
764         }
765         _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
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().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
936             String title = "Basic Information";
937             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
938                 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
939             }
940             showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
941         }
942     }
943
944     void executeGSDI() {
945         if ( !isOKforSDI( false, true ) ) {
946             return;
947         }
948         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
949             JOptionPane.showMessageDialog( this,
950                                            "Gene tree is not rooted.",
951                                            "Cannot execute GSDI",
952                                            JOptionPane.ERROR_MESSAGE );
953             return;
954         }
955         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
956         gene_tree.setAllNodesToNotCollapse();
957         gene_tree.recalculateNumberOfExternalDescendants( false );
958         GSDI gsdi = null;
959         final Phylogeny species_tree = _species_tree.copy();
960         try {
961             gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
962         }
963         catch ( final SDIException e ) {
964             JOptionPane.showMessageDialog( this,
965                                            e.getLocalizedMessage(),
966                                            "Error during GSDI",
967                                            JOptionPane.ERROR_MESSAGE );
968             return;
969         }
970         catch ( final Exception e ) {
971             AptxUtil.unexpectedException( e );
972             return;
973         }
974         gene_tree.setRerootable( false );
975         gene_tree.clearHashIdToNodeMap();
976         gene_tree.recalculateNumberOfExternalDescendants( true );
977         _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
978         getMainPanel().getControlPanel().setShowEvents( true );
979         showWhole();
980         final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
981         _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
982         showWhole();
983         _mainpanel.getTabbedPane().setSelectedIndex( selected );
984         showWhole();
985         _mainpanel.getCurrentTreePanel().setEdited( true );
986         final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
987         if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
988             JOptionPane.showMessageDialog( this,
989                                            "Duplications: " + gsdi.getDuplicationsSum() + "\n"
990                                                    + "Potential duplications: "
991                                                    + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
992                                                    + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
993                                                    + "Stripped gene tree nodes: "
994                                                    + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
995                                                    + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
996                                                    + "Number of polytomies in species tree used: " + poly + "\n",
997                                            "GSDI successfully completed",
998                                            JOptionPane.WARNING_MESSAGE );
999         }
1000         else {
1001             JOptionPane.showMessageDialog( this,
1002                                            "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1003                                                    + "Potential duplications: "
1004                                                    + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1005                                                    + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1006                                                    + "Stripped gene tree nodes: "
1007                                                    + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1008                                                    + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1009                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1010                                            "GSDI successfully completed",
1011                                            JOptionPane.INFORMATION_MESSAGE );
1012         }
1013     }
1014
1015     void executeGSDIR() {
1016         if ( !isOKforSDI( false, false ) ) {
1017             return;
1018         }
1019         final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1020         if ( ( p > 0 )
1021                 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1022             JOptionPane.showMessageDialog( this,
1023                                            "Gene tree is not completely binary",
1024                                            "Cannot execute GSDI",
1025                                            JOptionPane.ERROR_MESSAGE );
1026             return;
1027         }
1028         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1029         gene_tree.setAllNodesToNotCollapse();
1030         gene_tree.recalculateNumberOfExternalDescendants( false );
1031         GSDIR gsdir = null;
1032         final Phylogeny species_tree = _species_tree.copy();
1033         try {
1034             gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1035         }
1036         catch ( final SDIException e ) {
1037             JOptionPane.showMessageDialog( this,
1038                                            e.getLocalizedMessage(),
1039                                            "Error during GSDIR",
1040                                            JOptionPane.ERROR_MESSAGE );
1041             return;
1042         }
1043         catch ( final Exception e ) {
1044             AptxUtil.unexpectedException( e );
1045             return;
1046         }
1047         final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1048         result_gene_tree.setRerootable( false );
1049         result_gene_tree.clearHashIdToNodeMap();
1050         result_gene_tree.recalculateNumberOfExternalDescendants( true );
1051         PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1052         _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1053         getMainPanel().getControlPanel().setShowEvents( true );
1054         showWhole();
1055         final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1056         _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1057         showWhole();
1058         _mainpanel.getTabbedPane().setSelectedIndex( selected );
1059         showWhole();
1060         _mainpanel.getCurrentTreePanel().setEdited( true );
1061         final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1062         if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1063             JOptionPane.showMessageDialog( this,
1064                                            "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1065                                                    + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1066                                                    + "Stripped gene tree nodes: "
1067                                                    + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1068                                                    + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1069                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1070                                            "GSDIR successfully completed",
1071                                            JOptionPane.WARNING_MESSAGE );
1072         }
1073         else {
1074             JOptionPane.showMessageDialog( this,
1075                                            "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1076                                                    + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1077                                                    + "Stripped gene tree nodes: "
1078                                                    + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1079                                                    + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1080                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1081                                            "GSDIR successfully completed",
1082                                            JOptionPane.INFORMATION_MESSAGE );
1083         }
1084     }
1085
1086     Configuration getConfiguration() {
1087         return _configuration;
1088     }
1089
1090     TreePanel getCurrentTreePanel() {
1091         return getMainPanel().getCurrentTreePanel();
1092     }
1093
1094     JCheckBoxMenuItem getlabelDirectionCbmi() {
1095         return _label_direction_cbmi;
1096     }
1097
1098     Options getOtions() {
1099         return _options;
1100     }
1101
1102     void initializeTypeMenu( final Options options ) {
1103         setTypeMenuToAllUnselected();
1104         try {
1105             switch ( options.getPhylogenyGraphicsType() ) {
1106                 case CONVEX:
1107                     _convex_type_cbmi.setSelected( true );
1108                     break;
1109                 case CURVED:
1110                     _curved_type_cbmi.setSelected( true );
1111                     break;
1112                 case EURO_STYLE:
1113                     _euro_type_cbmi.setSelected( true );
1114                     break;
1115                 case ROUNDED:
1116                     _rounded_type_cbmi.setSelected( true );
1117                     break;
1118                 case TRIANGULAR:
1119                     _triangular_type_cbmi.setSelected( true );
1120                     break;
1121                 case UNROOTED:
1122                     _unrooted_type_cbmi.setSelected( true );
1123                     break;
1124                 case CIRCULAR:
1125                     _circular_type_cbmi.setSelected( true );
1126                     break;
1127                 default:
1128                     _rectangular_type_cbmi.setSelected( true );
1129                     break;
1130             }
1131         }
1132         catch ( final NullPointerException np ) {
1133             // In all likelihood, this is caused by menu-less display.
1134         }
1135     }
1136
1137     boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1138         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1139             return false;
1140         }
1141         else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1142             JOptionPane.showMessageDialog( this,
1143                                            "No species tree loaded",
1144                                            "Cannot execute GSDI",
1145                                            JOptionPane.ERROR_MESSAGE );
1146             return false;
1147         }
1148         else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1149             JOptionPane.showMessageDialog( this,
1150                                            "Species tree is not completely binary",
1151                                            "Cannot execute GSDI",
1152                                            JOptionPane.ERROR_MESSAGE );
1153             return false;
1154         }
1155         else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1156             JOptionPane.showMessageDialog( this,
1157                                            "Gene tree is not completely binary",
1158                                            "Cannot execute GSDI",
1159                                            JOptionPane.ERROR_MESSAGE );
1160             return false;
1161         }
1162         else {
1163             return true;
1164         }
1165     }
1166
1167     boolean isSubtreeDisplayed() {
1168         if ( getCurrentTreePanel() != null ) {
1169             if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1170                 JOptionPane
1171                         .showMessageDialog( this,
1172                                             "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1173                                             "Operation can not be exectuted on a sub-tree",
1174                                             JOptionPane.WARNING_MESSAGE );
1175                 return true;
1176             }
1177         }
1178         return false;
1179     }
1180
1181     void removeAllTextFrames() {
1182         for( final TextFrame tf : _textframes ) {
1183             if ( tf != null ) {
1184                 tf.close();
1185             }
1186         }
1187         _textframes.clear();
1188     }
1189
1190     void setConfiguration( final Configuration configuration ) {
1191         _configuration = configuration;
1192     }
1193
1194     void setOptions( final Options options ) {
1195         _options = options;
1196     }
1197
1198     void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1199         setTypeMenuToAllUnselected();
1200         try {
1201             switch ( type ) {
1202                 case CIRCULAR:
1203                     _circular_type_cbmi.setSelected( true );
1204                     break;
1205                 case CONVEX:
1206                     _convex_type_cbmi.setSelected( true );
1207                     break;
1208                 case CURVED:
1209                     _curved_type_cbmi.setSelected( true );
1210                     break;
1211                 case EURO_STYLE:
1212                     _euro_type_cbmi.setSelected( true );
1213                     break;
1214                 case ROUNDED:
1215                     _rounded_type_cbmi.setSelected( true );
1216                     break;
1217                 case RECTANGULAR:
1218                     _rectangular_type_cbmi.setSelected( true );
1219                     break;
1220                 case TRIANGULAR:
1221                     _triangular_type_cbmi.setSelected( true );
1222                     break;
1223                 case UNROOTED:
1224                     _unrooted_type_cbmi.setSelected( true );
1225                     break;
1226                 default:
1227                     throw new IllegalArgumentException( "unknown type: " + type );
1228             }
1229         }
1230         catch ( final NullPointerException np ) {
1231             // In all likelihood, this is caused by menu-less display.
1232         }
1233     }
1234
1235     void setTypeMenuToAllUnselected() {
1236         if ( _convex_type_cbmi != null ) {
1237             _convex_type_cbmi.setSelected( false );
1238         }
1239         if ( _curved_type_cbmi != null ) {
1240             _curved_type_cbmi.setSelected( false );
1241         }
1242         if ( _euro_type_cbmi != null ) {
1243             _euro_type_cbmi.setSelected( false );
1244         }
1245         if ( _rounded_type_cbmi != null ) {
1246             _rounded_type_cbmi.setSelected( false );
1247         }
1248         if ( _triangular_type_cbmi != null ) {
1249             _triangular_type_cbmi.setSelected( false );
1250         }
1251         if ( _rectangular_type_cbmi != null ) {
1252             _rectangular_type_cbmi.setSelected( false );
1253         }
1254         if ( _unrooted_type_cbmi != null ) {
1255             _unrooted_type_cbmi.setSelected( false );
1256         }
1257         if ( _circular_type_cbmi != null ) {
1258             _circular_type_cbmi.setSelected( false );
1259         }
1260     }
1261
1262     void showWhole() {
1263         _mainpanel.getControlPanel().showWhole();
1264     }
1265
1266     void switchColors() {
1267         final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1268         final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1269         csc.setVisible( true );
1270         getMainPanel().setTreeColorSet( colorset );
1271     }
1272
1273     void typeChanged( final Object o ) {
1274         updateTypeCheckboxes( getOptions(), o );
1275         updateOptions( getOptions() );
1276         if ( getCurrentTreePanel() != null ) {
1277             final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1278             final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1279             if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1280                     || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1281                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1282                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1283                 getCurrentTreePanel().getControlPanel().showWhole();
1284             }
1285             if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1286                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1287             }
1288             else {
1289                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1290             }
1291             getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1292             MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1293         }
1294     }
1295
1296     void updateOptions( final Options options ) {
1297         options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1298         options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1299                 && _background_gradient_cbmi.isSelected() );
1300         options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1301         options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1302                 && _show_annotation_ref_source.isSelected() );
1303         options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1304                 && _abbreviate_scientific_names.isSelected() );
1305         options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1306                 && _color_labels_same_as_parent_branch.isSelected() );
1307         options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1308                 && _show_default_node_shapes_internal_cbmi.isSelected() );
1309         options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1310                 && _show_default_node_shapes_external_cbmi.isSelected() );
1311         if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1312             options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1313         }
1314         else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1315             options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1316         }
1317         else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1318             options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1319         }
1320         options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1321                 && _search_case_senstive_cbmi.isSelected() );
1322         if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1323             options.setShowScale( _show_scale_cbmi.isSelected() );
1324         }
1325         if ( _label_direction_cbmi != null ) {
1326             if ( _label_direction_cbmi.isSelected() ) {
1327                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1328             }
1329             else {
1330                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1331             }
1332         }
1333         options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1334         options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1335                 && _show_confidence_stddev_cbmi.isSelected() );
1336         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1337                 && _search_whole_words_only_cbmi.isSelected() );
1338         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1339                 && _inverse_search_result_cbmi.isSelected() );
1340         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1341             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1342         }
1343         else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1344             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1345         }
1346         else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1347             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1348         }
1349         else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1350             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1351         }
1352         else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1353             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1354         }
1355         else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1356             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1357         }
1358         else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1359             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1360         }
1361         else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1362             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1363         }
1364         if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1365             options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1366         }
1367         if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1368             options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1369         }
1370         if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1371             options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1372         }
1373     }
1374
1375     void updateTypeCheckboxes( final Options options, final Object o ) {
1376         setTypeMenuToAllUnselected();
1377         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1378     }
1379
1380     void viewAsNexus() {
1381         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1382             String title = "Nexus";
1383             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1384                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1385             }
1386             showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1387                                    .getNhConversionSupportValueStyle() ),
1388                            title );
1389         }
1390     }
1391
1392     void viewAsNH() {
1393         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1394             String title = "New Hampshire";
1395             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1396                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1397             }
1398             showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1399                                    .getNhConversionSupportValueStyle() ),
1400                            title );
1401         }
1402     }
1403
1404     void viewAsXML() {
1405         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1406             String title = "phyloXML";
1407             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1408                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1409             }
1410             showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1411         }
1412     }
1413
1414     private void chooseFont() {
1415         final FontChooser fc = new FontChooser();
1416         fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1417         fc.showDialog( this, "Select the Base Font" );
1418         getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1419     }
1420
1421     private void chooseMinimalConfidence() {
1422         final String s = ( String ) JOptionPane
1423                 .showInputDialog( this,
1424                                   "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1425                                           + getOptions().getMinConfidenceValue() + "]\n",
1426                                   "Minimal Confidence Value",
1427                                   JOptionPane.QUESTION_MESSAGE,
1428                                   null,
1429                                   null,
1430                                   getOptions().getMinConfidenceValue() );
1431         if ( !ForesterUtil.isEmpty( s ) ) {
1432             boolean success = true;
1433             double m = 0.0;
1434             final String m_str = s.trim();
1435             if ( !ForesterUtil.isEmpty( m_str ) ) {
1436                 try {
1437                     m = Double.parseDouble( m_str );
1438                 }
1439                 catch ( final Exception ex ) {
1440                     success = false;
1441                 }
1442             }
1443             else {
1444                 success = false;
1445             }
1446             if ( success && ( m >= 0.0 ) ) {
1447                 getOptions().setMinConfidenceValue( m );
1448             }
1449         }
1450     }
1451
1452     private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1453         if ( item != null ) {
1454             item.setFont( MainFrame.menu_font );
1455             if ( !getConfiguration().isUseNativeUI() ) {
1456                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1457                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1458             }
1459             item.setSelected( is_selected );
1460             item.addActionListener( this );
1461         }
1462     }
1463
1464     MainPanel getMainPanel() {
1465         return _mainpanel;
1466     }
1467
1468     private Phylogeny getSpeciesTree() {
1469         return _species_tree;
1470     }
1471
1472     private boolean isScreenAntialias() {
1473         return true;
1474     }
1475
1476     private void removeBranchColors() {
1477         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1478             AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1479         }
1480     }
1481
1482     private void removeVisualStyles() {
1483         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1484             AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1485         }
1486     }
1487
1488     private void setMainPanel( final MainPanelApplets main_panel ) {
1489         _mainpanel = main_panel;
1490     }
1491
1492     private void setSpeciesTree( final Phylogeny species_tree ) {
1493         _species_tree = species_tree;
1494     }
1495
1496     private void setupUI() {
1497         try {
1498             if ( getConfiguration().isUseNativeUI() ) {
1499                 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1500             }
1501             else {
1502                 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1503             }
1504         }
1505         catch ( final UnsupportedLookAndFeelException e ) {
1506             AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1507         }
1508         catch ( final ClassNotFoundException e ) {
1509             AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1510         }
1511         catch ( final InstantiationException e ) {
1512             AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1513         }
1514         catch ( final IllegalAccessException e ) {
1515             AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1516         }
1517         catch ( final Exception e ) {
1518             AptxUtil.dieWithSystemError( e.toString() );
1519         }
1520     }
1521
1522     static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1523         for( final TreePanel tree_panel : treepanels ) {
1524             tree_panel.setTextAntialias();
1525         }
1526     }
1527 }