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