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