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