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