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