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