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             AptxUtil.printAppletMessage( NAME, "using tabbed display" );
612             AptxUtil.addPhylogeniesToTabs( phys,
613                                            new File( phys_url.getFile() ).getName(),
614                                            phys_url.toString(),
615                                            getConfiguration(),
616                                            getMainPanel() );
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
650     public void showTextFrame( final String s, final String title ) {
651         checkTextFrames();
652         _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
653     }
654
655     @Override
656     public void start() {
657         if ( getMainPanel() != null ) {
658             getMainPanel().validate();
659         }
660         requestFocus();
661         requestFocusInWindow();
662         requestFocus();
663         AptxUtil.printAppletMessage( NAME, "started" );
664     }
665
666     void buildAnalysisMenu() {
667         _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
668         _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
669         _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
670         customizeJMenuItem( _gsdi_item );
671         customizeJMenuItem( _gsdir_item );
672         //  _analysis_menu.addSeparator();
673         //  _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
674         //  customizeJMenuItem( _lineage_inference );
675         //  _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
676         _jmenubar.add( _analysis_menu );
677     }
678
679     void buildFontSizeMenu() {
680         _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
681         _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
682         _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
683         _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
684         _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
685         _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
686         customizeJMenuItem( _super_tiny_fonts_mi );
687         customizeJMenuItem( _tiny_fonts_mi );
688         customizeJMenuItem( _small_fonts_mi );
689         customizeJMenuItem( _medium_fonts_mi );
690         customizeJMenuItem( _large_fonts_mi );
691         _jmenubar.add( _font_size_menu );
692     }
693
694     void buildHelpMenu() {
695         _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
696         _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
697         _help_jmenu.addSeparator();
698         _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
699         _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
700         _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
701         _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
702         _help_jmenu.addSeparator();
703         _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
704         customizeJMenuItem( _help_item );
705         customizeJMenuItem( _website_item );
706         customizeJMenuItem( _phyloxml_website_item );
707         customizeJMenuItem( _aptx_ref_item );
708         customizeJMenuItem( _phyloxml_ref_item );
709         customizeJMenuItem( _about_item );
710         _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
711         _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
712         _jmenubar.add( _help_jmenu );
713     }
714
715     void buildOptionsMenu() {
716         _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
717         _options_jmenu.addChangeListener( new ChangeListener() {
718
719             @Override
720             public void stateChanged( final ChangeEvent e ) {
721                 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
722                 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
723                 MainFrame
724                         .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
725                 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
726                         .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
727                 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
728                                                                      _show_scale_cbmi,
729                                                                      _show_branch_length_values_cbmi,
730                                                                      _non_lined_up_cladograms_rbmi,
731                                                                      _uniform_cladograms_rbmi,
732                                                                      _ext_node_dependent_cladogram_rbmi,
733                                                                      _label_direction_cbmi );
734                 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
735                 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
736                 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
737             }
738         } );
739         _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
740                                                                 getConfiguration() ) );
741         _options_jmenu
742                 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
743         _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
744         _options_jmenu
745                 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
746         _radio_group_1 = new ButtonGroup();
747         _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
748         _radio_group_1.add( _uniform_cladograms_rbmi );
749         _radio_group_1.add( _non_lined_up_cladograms_rbmi );
750         /////
751         _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
752         _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
753         _options_jmenu
754                 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
755         _options_jmenu
756                 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
757         _options_jmenu
758                 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
759         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
760             _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
761             _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
762         }
763         _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
764         _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
765         _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
766         _options_jmenu
767                 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
768         _options_jmenu
769                 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
770         _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
771         _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
772         _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
773         _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
774         _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
775         _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
776         _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
777         _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
778         _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
779         _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
780         _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
781         _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
782         _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
783         /////
784         _options_jmenu.addSeparator();
785         _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
786                                                                 getConfiguration() ) );
787         _options_jmenu
788                 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
789         _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
790         _options_jmenu
791                 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
792         customizeJMenuItem( _choose_font_mi );
793         customizeJMenuItem( _choose_minimal_confidence_mi );
794         customizeJMenuItem( _switch_colors_mi );
795         customizeJMenuItem( _overview_placment_mi );
796         customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
797         customizeCheckBoxMenuItem( _label_direction_cbmi,
798                                    getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
799         customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
800         customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
801         customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
802         customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
803         customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
804         customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
805                 .isShowDefaultNodeShapesExternal() );
806         customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
807                 .isShowDefaultNodeShapesInternal() );
808         customizeJMenuItem( _cycle_node_shape_mi );
809         customizeJMenuItem( _cycle_node_fill_mi );
810         customizeJMenuItem( _choose_node_size_mi );
811         customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
812         customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
813         customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
814         customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
815                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
816         customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
817                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
818         customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
819                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
820         customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
821         customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
822         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
823         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
824         customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
825         customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
826         customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
827         _jmenubar.add( _options_jmenu );
828     }
829
830     void buildToolsMenu() {
831         _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
832         _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
833         customizeJMenuItem( _confcolor_item );
834         _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
835         customizeJMenuItem( _taxcolor_item );
836         _tools_menu.addSeparator();
837         _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
838         _remove_visual_styles_item
839                 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
840         customizeJMenuItem( _remove_visual_styles_item );
841         _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
842         _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
843         customizeJMenuItem( _remove_branch_color_item );
844         _tools_menu.addSeparator();
845         _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
846         customizeJMenuItem( _midpoint_root_item );
847         _tools_menu.addSeparator();
848         _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
849         customizeJMenuItem( _collapse_species_specific_subtrees );
850         _jmenubar.add( _tools_menu );
851     }
852
853     void buildTypeMenu() {
854         _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
855         _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
856         _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
857         _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
858         _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
859         _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
860         _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
861         _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
862         _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
863         customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
864         customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
865         customizeCheckBoxMenuItem( _euro_type_cbmi, false );
866         customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
867         customizeCheckBoxMenuItem( _curved_type_cbmi, false );
868         customizeCheckBoxMenuItem( _convex_type_cbmi, false );
869         customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
870         customizeCheckBoxMenuItem( _circular_type_cbmi, false );
871         _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
872         _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
873         initializeTypeMenu( getOptions() );
874         _jmenubar.add( _type_menu );
875     }
876
877     void buildViewMenu() {
878         _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
879         _view_jmenu
880                 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
881         _view_jmenu.addSeparator();
882         _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
883         _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
884         _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
885         customizeJMenuItem( _display_basic_information_item );
886         customizeJMenuItem( _view_as_NH_item );
887         customizeJMenuItem( _view_as_XML_item );
888         customizeJMenuItem( _view_as_nexus_item );
889         _jmenubar.add( _view_jmenu );
890     }
891
892     void checkTextFrames() {
893         if ( _textframes.size() > 5 ) {
894             try {
895                 if ( _textframes.getFirst() != null ) {
896                     _textframes.getFirst().removeMe();
897                 }
898                 else {
899                     _textframes.removeFirst();
900                 }
901             }
902             catch ( final NoSuchElementException e ) {
903                 // Ignore.
904             }
905         }
906     }
907
908     void clearCurrentExternalNodesDataBuffer() {
909         getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
910     }
911
912     void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
913         if ( item != null ) {
914             item.setFont( MainFrame.menu_font );
915             if ( !getConfiguration().isUseNativeUI() ) {
916                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
917                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
918             }
919             item.setSelected( is_selected );
920             item.addActionListener( this );
921         }
922     }
923
924     void customizeJMenuItem( final JMenuItem jmi ) {
925         jmi.setFont( MainFrame.menu_font );
926         if ( !getConfiguration().isUseNativeUI() ) {
927             jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
928             jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
929         }
930         jmi.addActionListener( this );
931     }
932
933     void displayBasicInformation() {
934         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
935             String title = "Basic Information";
936             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
937                 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
938             }
939             showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
940         }
941     }
942
943     void executeGSDI() {
944         if ( !isOKforSDI( false, true ) ) {
945             return;
946         }
947         if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
948             JOptionPane.showMessageDialog( this,
949                                            "Gene tree is not rooted.",
950                                            "Cannot execute GSDI",
951                                            JOptionPane.ERROR_MESSAGE );
952             return;
953         }
954         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
955         gene_tree.setAllNodesToNotCollapse();
956         gene_tree.recalculateNumberOfExternalDescendants( false );
957         GSDI gsdi = null;
958         final Phylogeny species_tree = _species_tree.copy();
959         try {
960             gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
961         }
962         catch ( final SDIException e ) {
963             JOptionPane.showMessageDialog( this,
964                                            e.getLocalizedMessage(),
965                                            "Error during GSDI",
966                                            JOptionPane.ERROR_MESSAGE );
967             return;
968         }
969         catch ( final Exception e ) {
970             AptxUtil.unexpectedException( e );
971             return;
972         }
973         gene_tree.setRerootable( false );
974         gene_tree.clearHashIdToNodeMap();
975         gene_tree.recalculateNumberOfExternalDescendants( true );
976         _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
977         getMainPanel().getControlPanel().setShowEvents( true );
978         showWhole();
979         final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
980         _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
981         showWhole();
982         _mainpanel.getTabbedPane().setSelectedIndex( selected );
983         showWhole();
984         _mainpanel.getCurrentTreePanel().setEdited( true );
985         final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
986         if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
987             JOptionPane.showMessageDialog( this,
988                                            "Duplications: " + gsdi.getDuplicationsSum() + "\n"
989                                                    + "Potential duplications: "
990                                                    + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
991                                                    + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
992                                                    + "Stripped gene tree nodes: "
993                                                    + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
994                                                    + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
995                                                    + "Number of polytomies in species tree used: " + poly + "\n",
996                                            "GSDI successfully completed",
997                                            JOptionPane.WARNING_MESSAGE );
998         }
999         else {
1000             JOptionPane.showMessageDialog( this,
1001                                            "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1002                                                    + "Potential duplications: "
1003                                                    + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1004                                                    + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1005                                                    + "Stripped gene tree nodes: "
1006                                                    + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1007                                                    + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1008                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1009                                            "GSDI successfully completed",
1010                                            JOptionPane.INFORMATION_MESSAGE );
1011         }
1012     }
1013
1014     void executeGSDIR() {
1015         if ( !isOKforSDI( false, false ) ) {
1016             return;
1017         }
1018         final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1019         if ( ( p > 0 )
1020                 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1021             JOptionPane.showMessageDialog( this,
1022                                            "Gene tree is not completely binary",
1023                                            "Cannot execute GSDI",
1024                                            JOptionPane.ERROR_MESSAGE );
1025             return;
1026         }
1027         final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1028         gene_tree.setAllNodesToNotCollapse();
1029         gene_tree.recalculateNumberOfExternalDescendants( false );
1030         GSDIR gsdir = null;
1031         final Phylogeny species_tree = _species_tree.copy();
1032         try {
1033             gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1034         }
1035         catch ( final SDIException e ) {
1036             JOptionPane.showMessageDialog( this,
1037                                            e.getLocalizedMessage(),
1038                                            "Error during GSDIR",
1039                                            JOptionPane.ERROR_MESSAGE );
1040             return;
1041         }
1042         catch ( final Exception e ) {
1043             AptxUtil.unexpectedException( e );
1044             return;
1045         }
1046         final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1047         result_gene_tree.setRerootable( false );
1048         result_gene_tree.clearHashIdToNodeMap();
1049         result_gene_tree.recalculateNumberOfExternalDescendants( true );
1050         PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1051         _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1052         getMainPanel().getControlPanel().setShowEvents( true );
1053         showWhole();
1054         final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1055         _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1056         showWhole();
1057         _mainpanel.getTabbedPane().setSelectedIndex( selected );
1058         showWhole();
1059         _mainpanel.getCurrentTreePanel().setEdited( true );
1060         final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1061         if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1062             JOptionPane.showMessageDialog( this,
1063                                            "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1064                                                    + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1065                                                    + "Stripped gene tree nodes: "
1066                                                    + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1067                                                    + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1068                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1069                                            "GSDIR successfully completed",
1070                                            JOptionPane.WARNING_MESSAGE );
1071         }
1072         else {
1073             JOptionPane.showMessageDialog( this,
1074                                            "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1075                                                    + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1076                                                    + "Stripped gene tree nodes: "
1077                                                    + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1078                                                    + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1079                                                    + "Number of polytomies in species tree used: " + poly + "\n",
1080                                            "GSDIR successfully completed",
1081                                            JOptionPane.INFORMATION_MESSAGE );
1082         }
1083     }
1084
1085     Configuration getConfiguration() {
1086         return _configuration;
1087     }
1088
1089     TreePanel getCurrentTreePanel() {
1090         return getMainPanel().getCurrentTreePanel();
1091     }
1092
1093     JCheckBoxMenuItem getlabelDirectionCbmi() {
1094         return _label_direction_cbmi;
1095     }
1096
1097     Options getOtions() {
1098         return _options;
1099     }
1100
1101     void initializeTypeMenu( final Options options ) {
1102         setTypeMenuToAllUnselected();
1103         try {
1104             switch ( options.getPhylogenyGraphicsType() ) {
1105                 case CONVEX:
1106                     _convex_type_cbmi.setSelected( true );
1107                     break;
1108                 case CURVED:
1109                     _curved_type_cbmi.setSelected( true );
1110                     break;
1111                 case EURO_STYLE:
1112                     _euro_type_cbmi.setSelected( true );
1113                     break;
1114                 case ROUNDED:
1115                     _rounded_type_cbmi.setSelected( true );
1116                     break;
1117                 case TRIANGULAR:
1118                     _triangular_type_cbmi.setSelected( true );
1119                     break;
1120                 case UNROOTED:
1121                     _unrooted_type_cbmi.setSelected( true );
1122                     break;
1123                 case CIRCULAR:
1124                     _circular_type_cbmi.setSelected( true );
1125                     break;
1126                 default:
1127                     _rectangular_type_cbmi.setSelected( true );
1128                     break;
1129             }
1130         }
1131         catch ( final NullPointerException np ) {
1132             // In all likelihood, this is caused by menu-less display.
1133         }
1134     }
1135
1136     boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1137         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1138             return false;
1139         }
1140         else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1141             JOptionPane.showMessageDialog( this,
1142                                            "No species tree loaded",
1143                                            "Cannot execute GSDI",
1144                                            JOptionPane.ERROR_MESSAGE );
1145             return false;
1146         }
1147         else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1148             JOptionPane.showMessageDialog( this,
1149                                            "Species tree is not completely binary",
1150                                            "Cannot execute GSDI",
1151                                            JOptionPane.ERROR_MESSAGE );
1152             return false;
1153         }
1154         else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1155             JOptionPane.showMessageDialog( this,
1156                                            "Gene tree is not completely binary",
1157                                            "Cannot execute GSDI",
1158                                            JOptionPane.ERROR_MESSAGE );
1159             return false;
1160         }
1161         else {
1162             return true;
1163         }
1164     }
1165
1166     boolean isSubtreeDisplayed() {
1167         if ( getCurrentTreePanel() != null ) {
1168             if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1169                 JOptionPane
1170                         .showMessageDialog( this,
1171                                             "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1172                                             "Operation can not be exectuted on a sub-tree",
1173                                             JOptionPane.WARNING_MESSAGE );
1174                 return true;
1175             }
1176         }
1177         return false;
1178     }
1179
1180     void removeAllTextFrames() {
1181         for( final TextFrame tf : _textframes ) {
1182             if ( tf != null ) {
1183                 tf.close();
1184             }
1185         }
1186         _textframes.clear();
1187     }
1188
1189     void setConfiguration( final Configuration configuration ) {
1190         _configuration = configuration;
1191     }
1192
1193     void setOptions( final Options options ) {
1194         _options = options;
1195     }
1196
1197     void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1198         setTypeMenuToAllUnselected();
1199         try {
1200             switch ( type ) {
1201                 case CIRCULAR:
1202                     _circular_type_cbmi.setSelected( true );
1203                     break;
1204                 case CONVEX:
1205                     _convex_type_cbmi.setSelected( true );
1206                     break;
1207                 case CURVED:
1208                     _curved_type_cbmi.setSelected( true );
1209                     break;
1210                 case EURO_STYLE:
1211                     _euro_type_cbmi.setSelected( true );
1212                     break;
1213                 case ROUNDED:
1214                     _rounded_type_cbmi.setSelected( true );
1215                     break;
1216                 case RECTANGULAR:
1217                     _rectangular_type_cbmi.setSelected( true );
1218                     break;
1219                 case TRIANGULAR:
1220                     _triangular_type_cbmi.setSelected( true );
1221                     break;
1222                 case UNROOTED:
1223                     _unrooted_type_cbmi.setSelected( true );
1224                     break;
1225                 default:
1226                     throw new IllegalArgumentException( "unknown type: " + type );
1227             }
1228         }
1229         catch ( final NullPointerException np ) {
1230             // In all likelihood, this is caused by menu-less display.
1231         }
1232     }
1233
1234     void setTypeMenuToAllUnselected() {
1235         if ( _convex_type_cbmi != null ) {
1236             _convex_type_cbmi.setSelected( false );
1237         }
1238         if ( _curved_type_cbmi != null ) {
1239             _curved_type_cbmi.setSelected( false );
1240         }
1241         if ( _euro_type_cbmi != null ) {
1242             _euro_type_cbmi.setSelected( false );
1243         }
1244         if ( _rounded_type_cbmi != null ) {
1245             _rounded_type_cbmi.setSelected( false );
1246         }
1247         if ( _triangular_type_cbmi != null ) {
1248             _triangular_type_cbmi.setSelected( false );
1249         }
1250         if ( _rectangular_type_cbmi != null ) {
1251             _rectangular_type_cbmi.setSelected( false );
1252         }
1253         if ( _unrooted_type_cbmi != null ) {
1254             _unrooted_type_cbmi.setSelected( false );
1255         }
1256         if ( _circular_type_cbmi != null ) {
1257             _circular_type_cbmi.setSelected( false );
1258         }
1259     }
1260
1261     void showWhole() {
1262         _mainpanel.getControlPanel().showWhole();
1263     }
1264
1265     void switchColors() {
1266         final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1267         final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1268         csc.setVisible( true );
1269         getMainPanel().setTreeColorSet( colorset );
1270     }
1271
1272     void typeChanged( final Object o ) {
1273         updateTypeCheckboxes( getOptions(), o );
1274         updateOptions( getOptions() );
1275         if ( getCurrentTreePanel() != null ) {
1276             final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1277             final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1278             if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1279                     || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1280                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1281                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1282                 getCurrentTreePanel().getControlPanel().showWhole();
1283             }
1284             if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1285                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1286             }
1287             else {
1288                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1289             }
1290             getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1291             MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1292         }
1293     }
1294
1295     void updateOptions( final Options options ) {
1296         options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1297         options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1298                 && _background_gradient_cbmi.isSelected() );
1299         options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1300         options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1301                 && _show_annotation_ref_source.isSelected() );
1302         options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1303                 && _abbreviate_scientific_names.isSelected() );
1304         options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1305                 && _color_labels_same_as_parent_branch.isSelected() );
1306         options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1307                 && _show_default_node_shapes_internal_cbmi.isSelected() );
1308         options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1309                 && _show_default_node_shapes_external_cbmi.isSelected() );
1310         if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1311             options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1312         }
1313         else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1314             options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1315         }
1316         else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1317             options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1318         }
1319         options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1320                 && _search_case_senstive_cbmi.isSelected() );
1321         if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1322             options.setShowScale( _show_scale_cbmi.isSelected() );
1323         }
1324         if ( _label_direction_cbmi != null ) {
1325             if ( _label_direction_cbmi.isSelected() ) {
1326                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1327             }
1328             else {
1329                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1330             }
1331         }
1332         options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1333         options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1334                 && _show_confidence_stddev_cbmi.isSelected() );
1335         if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1336             options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1337         }
1338         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1339                 && _search_whole_words_only_cbmi.isSelected() );
1340         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1341                 && _inverse_search_result_cbmi.isSelected() );
1342         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1343             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1344         }
1345         else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1346             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1347         }
1348         else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1349             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1350         }
1351         else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1352             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1353         }
1354         else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1355             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1356         }
1357         else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1358             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1359         }
1360         else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1361             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1362         }
1363         else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1364             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1365         }
1366         if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1367             options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1368         }
1369         if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1370             options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1371         }
1372         if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1373             options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1374         }
1375     }
1376
1377     void updateTypeCheckboxes( final Options options, final Object o ) {
1378         setTypeMenuToAllUnselected();
1379         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1380     }
1381
1382     void viewAsNexus() {
1383         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1384             String title = "Nexus";
1385             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1386                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1387             }
1388             showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1389                                    .getNhConversionSupportValueStyle() ),
1390                            title );
1391         }
1392     }
1393
1394     void viewAsNH() {
1395         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1396             String title = "New Hampshire";
1397             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1398                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1399             }
1400             showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1401                                    .getNhConversionSupportValueStyle() ),
1402                            title );
1403         }
1404     }
1405
1406     void viewAsXML() {
1407         if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1408             String title = "phyloXML";
1409             if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1410                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1411             }
1412             showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1413         }
1414     }
1415
1416     private void chooseFont() {
1417         final FontChooser fc = new FontChooser();
1418         fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1419         fc.showDialog( this, "Select the Base Font" );
1420         getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1421     }
1422
1423     private void chooseMinimalConfidence() {
1424         final String s = ( String ) JOptionPane
1425                 .showInputDialog( this,
1426                                   "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1427                                           + getOptions().getMinConfidenceValue() + "]\n",
1428                                   "Minimal Confidence Value",
1429                                   JOptionPane.QUESTION_MESSAGE,
1430                                   null,
1431                                   null,
1432                                   getOptions().getMinConfidenceValue() );
1433         if ( !ForesterUtil.isEmpty( s ) ) {
1434             boolean success = true;
1435             double m = 0.0;
1436             final String m_str = s.trim();
1437             if ( !ForesterUtil.isEmpty( m_str ) ) {
1438                 try {
1439                     m = Double.parseDouble( m_str );
1440                 }
1441                 catch ( final Exception ex ) {
1442                     success = false;
1443                 }
1444             }
1445             else {
1446                 success = false;
1447             }
1448             if ( success && ( m >= 0.0 ) ) {
1449                 getOptions().setMinConfidenceValue( m );
1450             }
1451         }
1452     }
1453
1454     private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1455         if ( item != null ) {
1456             item.setFont( MainFrame.menu_font );
1457             if ( !getConfiguration().isUseNativeUI() ) {
1458                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1459                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1460             }
1461             item.setSelected( is_selected );
1462             item.addActionListener( this );
1463         }
1464     }
1465
1466     private MainPanel getMainPanel() {
1467         return _mainpanel;
1468     }
1469
1470     private Phylogeny getSpeciesTree() {
1471         return _species_tree;
1472     }
1473
1474     private boolean isScreenAntialias() {
1475         return true;
1476     }
1477
1478     private void removeBranchColors() {
1479         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1480             AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1481         }
1482     }
1483
1484     private void removeVisualStyles() {
1485         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1486             AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1487         }
1488     }
1489
1490     private void setMainPanel( final MainPanelApplets main_panel ) {
1491         _mainpanel = main_panel;
1492     }
1493
1494     private void setSpeciesTree( final Phylogeny species_tree ) {
1495         _species_tree = species_tree;
1496     }
1497
1498     private void setupUI() {
1499         try {
1500             if ( getConfiguration().isUseNativeUI() ) {
1501                 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1502             }
1503             else {
1504                 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1505             }
1506         }
1507         catch ( final UnsupportedLookAndFeelException e ) {
1508             AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1509         }
1510         catch ( final ClassNotFoundException e ) {
1511             AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1512         }
1513         catch ( final InstantiationException e ) {
1514             AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1515         }
1516         catch ( final IllegalAccessException e ) {
1517             AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1518         }
1519         catch ( final Exception e ) {
1520             AptxUtil.dieWithSystemError( e.toString() );
1521         }
1522     }
1523
1524     static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1525         for( final TreePanel tree_panel : treepanels ) {
1526             tree_panel.setTextAntialias();
1527         }
1528     }
1529 }