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