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