in progress
[jalview.git] / forester / java / src / org / forester / archaeopteryx / ArchaeopteryxE.java
1
2 package org.forester.archaeopteryx;
3
4 import java.awt.BorderLayout;
5 import java.awt.Container;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.awt.event.ComponentAdapter;
9 import java.awt.event.ComponentEvent;
10 import java.io.ByteArrayOutputStream;
11 import java.io.File;
12 import java.io.IOException;
13 import java.net.URL;
14 import java.util.List;
15
16 import javax.swing.ButtonGroup;
17 import javax.swing.JApplet;
18 import javax.swing.JCheckBoxMenuItem;
19 import javax.swing.JMenu;
20 import javax.swing.JMenuBar;
21 import javax.swing.JMenuItem;
22 import javax.swing.JOptionPane;
23 import javax.swing.JRadioButtonMenuItem;
24 import javax.swing.UIManager;
25 import javax.swing.UnsupportedLookAndFeelException;
26 import javax.swing.event.ChangeEvent;
27 import javax.swing.event.ChangeListener;
28
29 import org.apache.commons.codec.binary.Base64;
30 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
31 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
32 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
33 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
34 import org.forester.phylogeny.Phylogeny;
35 import org.forester.phylogeny.data.SequenceRelation;
36 import org.forester.util.ForesterConstants;
37 import org.forester.util.ForesterUtil;
38
39 // Use like this:
40 // <applet archive="forester.jar"
41 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
42 // codebase="http://www.myserver.org/path/to/forester"
43 // width="600"
44 // height="500"
45 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
46 // <param name="url_of_tree_to_load"
47 // value="http://www.myserver.org/examples/data/apaf.xml">
48 // <param name="config_file"
49 // value="http://www.myserver.org/examples/config/config_file.txt">
50 // </applet>
51 public class ArchaeopteryxE extends JApplet implements ActionListener {
52
53     private final static String  NAME             = "ArchaeopteryxE";
54     private static final long    serialVersionUID = -1220055577935759443L;
55     private Configuration        _configuration;
56     private MainPanelApplets     _main_panel;
57     private JMenuBar             _jmenubar;
58     private JMenu                _options_jmenu;
59     private JMenu                _font_size_menu;
60     private JMenuItem            _super_tiny_fonts_mi;
61     private JMenuItem            _tiny_fonts_mi;
62     private JMenuItem            _small_fonts_mi;
63     private JMenuItem            _medium_fonts_mi;
64     private JMenuItem            _large_fonts_mi;
65     private TextFrame            _textframe;
66     private JMenu                _tools_menu;
67     private JMenuItem            _taxcolor_item;
68     private JMenuItem            _confcolor_item;
69     private JMenuItem            _midpoint_root_item;
70     private JMenu                _view_jmenu;
71     private JMenuItem            _view_as_XML_item;
72     private JMenuItem            _view_as_NH_item;
73     private JMenuItem            _view_as_NHX_item;
74     private JMenuItem            _view_as_nexus_item;
75     private JMenu                _type_menu;
76     private JCheckBoxMenuItem    _rectangular_type_cbmi;
77     private JCheckBoxMenuItem    _triangular_type_cbmi;
78     private JCheckBoxMenuItem    _curved_type_cbmi;
79     private JCheckBoxMenuItem    _convex_type_cbmi;
80     private JCheckBoxMenuItem    _euro_type_cbmi;
81     private JCheckBoxMenuItem    _rounded_type_cbmi;
82     private JCheckBoxMenuItem    _unrooted_type_cbmi;
83     private JCheckBoxMenuItem    _circular_type_cbmi;
84     private JMenuItem            _help_item;
85     private JMenuItem            _about_item;
86     private JMenu                _help_jmenu;
87     private JMenuItem            _website_item;
88     private JMenuItem            _phyloxml_website_item;
89     private JMenuItem            _phyloxml_ref_item;
90     private JMenuItem            _aptx_ref_item;
91     private JMenuItem            _remove_branch_color_item;
92     private JMenuItem            _infer_common_sn_names_item;
93     private JCheckBoxMenuItem    _show_domain_labels;
94     private JCheckBoxMenuItem    _color_labels_same_as_parent_branch;
95     private JCheckBoxMenuItem    _abbreviate_scientific_names;
96     private JCheckBoxMenuItem    _screen_antialias_cbmi;
97     private JCheckBoxMenuItem    _background_gradient_cbmi;
98     private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
99     private JRadioButtonMenuItem _uniform_cladograms_rbmi;
100     private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
101     private Options              _options;
102     private JMenuItem            _choose_font_mi;
103     private JMenuItem            _switch_colors_mi;
104     JCheckBoxMenuItem            _label_direction_cbmi;
105     private JCheckBoxMenuItem    _show_scale_cbmi;
106     private JCheckBoxMenuItem    _search_case_senstive_cbmi;
107     private JCheckBoxMenuItem    _search_whole_words_only_cbmi;
108     private JCheckBoxMenuItem    _inverse_search_result_cbmi;
109     private JCheckBoxMenuItem    _show_overview_cbmi;
110     private JMenuItem            _choose_minimal_confidence_mi;
111     private JCheckBoxMenuItem    _show_branch_length_values_cbmi;
112     private JMenuItem            _collapse_species_specific_subtrees;
113     private JMenuItem            _overview_placment_mi;
114     private ButtonGroup          _radio_group_1;
115     private JCheckBoxMenuItem    _show_default_node_shapes_cbmi;
116     private JMenuItem            _cycle_node_shape_mi;
117     private JMenuItem            _cycle_node_fill_mi;
118     private JMenuItem            _choose_node_size_mi;
119     private JCheckBoxMenuItem    _taxonomy_colorize_node_shapes_cbmi;
120     private JCheckBoxMenuItem    _show_confidence_stddev_cbmi;
121
122     @Override
123     public void actionPerformed( final ActionEvent e ) {
124         final Object o = e.getSource();
125         if ( o == _midpoint_root_item ) {
126             getMainPanel().getCurrentTreePanel().midpointRoot();
127         }
128         else if ( o == _taxcolor_item ) {
129             getMainPanel().getCurrentTreePanel().taxColor();
130         }
131         else if ( o == _confcolor_item ) {
132             getMainPanel().getCurrentTreePanel().confColor();
133         }
134         else if ( o == _infer_common_sn_names_item ) {
135             if ( getCurrentTreePanel() != null ) {
136                 getCurrentTreePanel().inferCommonPartOfScientificNames();
137             }
138         }
139         else if ( o == _collapse_species_specific_subtrees ) {
140             if ( getCurrentTreePanel() != null ) {
141                 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
142             }
143         }
144         else if ( o == _remove_branch_color_item ) {
145             removeBranchColors();
146         }
147         else if ( o == _switch_colors_mi ) {
148             switchColors();
149         }
150         else if ( o == _view_as_NH_item ) {
151             viewAsNH();
152         }
153         else if ( o == _view_as_NHX_item ) {
154             viewAsNHX();
155         }
156         else if ( o == _view_as_XML_item ) {
157             viewAsXML();
158         }
159         else if ( o == _view_as_nexus_item ) {
160             viewAsNexus();
161         }
162         else if ( o == _super_tiny_fonts_mi ) {
163             if ( getCurrentTreePanel() != null ) {
164                 getCurrentTreePanel().setSuperTinyFonts();
165                 getCurrentTreePanel().repaint();
166             }
167         }
168         else if ( o == _tiny_fonts_mi ) {
169             if ( getCurrentTreePanel() != null ) {
170                 getCurrentTreePanel().setTinyFonts();
171                 getCurrentTreePanel().repaint();
172             }
173         }
174         else if ( o == _small_fonts_mi ) {
175             if ( getCurrentTreePanel() != null ) {
176                 getCurrentTreePanel().setSmallFonts();
177                 getCurrentTreePanel().repaint();
178             }
179         }
180         else if ( o == _medium_fonts_mi ) {
181             if ( getCurrentTreePanel() != null ) {
182                 getCurrentTreePanel().setMediumFonts();
183                 getCurrentTreePanel().repaint();
184             }
185         }
186         else if ( o == _large_fonts_mi ) {
187             if ( getCurrentTreePanel() != null ) {
188                 getCurrentTreePanel().setLargeFonts();
189                 getCurrentTreePanel().repaint();
190             }
191         }
192         else if ( o == _choose_font_mi ) {
193             chooseFont();
194         }
195         else if ( o == _choose_minimal_confidence_mi ) {
196             chooseMinimalConfidence();
197         }
198         else if ( o == _choose_node_size_mi ) {
199             MainFrame.chooseNodeSize( getOptions(), this );
200         }
201         else if ( o == _overview_placment_mi ) {
202             MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
203         }
204         else if ( o == _cycle_node_fill_mi ) {
205             MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
206         }
207         else if ( o == _cycle_node_shape_mi ) {
208             MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
209         }
210         else if ( o == _non_lined_up_cladograms_rbmi ) {
211             updateOptions( getOptions() );
212             _main_panel.getControlPanel().showWhole();
213         }
214         else if ( o == _uniform_cladograms_rbmi ) {
215             updateOptions( getOptions() );
216             _main_panel.getControlPanel().showWhole();
217         }
218         else if ( o == _ext_node_dependent_cladogram_rbmi ) {
219             updateOptions( getOptions() );
220             _main_panel.getControlPanel().showWhole();
221         }
222         else if ( o == _search_case_senstive_cbmi ) {
223             updateOptions( getOptions() );
224             getMainPanel().getControlPanel().search();
225         }
226         else if ( o == _search_whole_words_only_cbmi ) {
227             updateOptions( getOptions() );
228             getMainPanel().getControlPanel().search();
229         }
230         else if ( o == _inverse_search_result_cbmi ) {
231             updateOptions( getOptions() );
232             getMainPanel().getControlPanel().search();
233         }
234         else if ( o == _show_scale_cbmi ) {
235             updateOptions( getOptions() );
236         }
237         else if ( o == _show_branch_length_values_cbmi ) {
238             updateOptions( getOptions() );
239         }
240         else if ( o == _show_confidence_stddev_cbmi ) {
241             updateOptions( getOptions() );
242         }
243         else if ( o == _label_direction_cbmi ) {
244             updateOptions( getOptions() );
245         }
246         else if ( o == _show_overview_cbmi ) {
247             updateOptions( getOptions() );
248             if ( getCurrentTreePanel() != null ) {
249                 getCurrentTreePanel().updateOvSizes();
250             }
251         }
252         else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
253                 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
254                 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
255             typeChanged( o );
256         }
257         else if ( o == _screen_antialias_cbmi ) {
258             updateOptions( getOptions() );
259             setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
260         }
261         else if ( o == _background_gradient_cbmi ) {
262             updateOptions( getOptions() );
263         }
264         else if ( o == _show_domain_labels ) {
265             updateOptions( getOptions() );
266         }
267         else if ( o == _color_labels_same_as_parent_branch ) {
268             updateOptions( getOptions() );
269         }
270         else if ( o == _show_default_node_shapes_cbmi ) {
271             updateOptions( getOptions() );
272         }
273         else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
274             updateOptions( getOptions() );
275         }
276         else if ( o == _about_item ) {
277             MainFrame.about();
278         }
279         else if ( o == _help_item ) {
280             MainFrame.help( getConfiguration().getWebLinks() );
281         }
282         else if ( o == _website_item ) {
283             try {
284                 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
285             }
286             catch ( final IOException e1 ) {
287                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
288             }
289         }
290         else if ( o == _phyloxml_website_item ) {
291             try {
292                 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
293             }
294             catch ( final IOException e1 ) {
295                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
296             }
297         }
298         else if ( o == _aptx_ref_item ) {
299             try {
300                 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
301             }
302             catch ( final IOException e1 ) {
303                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
304             }
305         }
306         else if ( o == _phyloxml_ref_item ) {
307             try {
308                 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
309             }
310             catch ( final IOException e1 ) {
311                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
312             }
313         }
314         repaint();
315     }
316
317     /**
318      * This method returns the current phylogeny as a string in the chosen format
319      * 
320      * @param format must be NH, NHX, NEXUS or PHYLOXML
321      * @return the phylogeny string
322      * @author Herve Menager
323      */
324     public String getCurrentPhylogeny( final String format ) {
325         removeTextFrame();
326         if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
327                 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
328             return new String();
329         }
330         switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
331             case NH:
332                 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
333             case NHX:
334                 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
335             case NEXUS:
336                 return getMainPanel().getCurrentPhylogeny().toNexus();
337             case PHYLOXML:
338                 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
339             default:
340                 break;
341         }
342         return new String();
343     }
344
345     /**
346      * This method returns a view of the current phylogeny in a chosen 
347      * graphics format, base64-encoded in a string so that in can be used
348      * from javascript.
349      * 
350      * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
351      * @return the phylogeny string
352      * @author Herve Menager
353      */
354     public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
355         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
356         try {
357             AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
358                                                                     _main_panel.getWidth(),
359                                                                     _main_panel.getHeight(),
360                                                                     getCurrentTreePanel(),
361                                                                     getCurrentTreePanel().getControlPanel(),
362                                                                     GraphicsExportType.valueOf( format ),
363                                                                     getOptions() );
364         }
365         catch ( final IOException ioe ) {
366             ForesterUtil.printErrorMessage( NAME, ioe.toString() );
367             ioe.printStackTrace();
368             JOptionPane.showMessageDialog( this,
369                                            NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
370                                            "Failed to generate graphics",
371                                            JOptionPane.ERROR_MESSAGE );
372             return null;
373         }
374         final byte[] bytes = baos.toByteArray();
375         final String dataImg = Base64.encodeBase64String( bytes );
376         return dataImg;
377     }
378
379     void buildFontSizeMenu() {
380         _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
381         _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
382         _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
383         _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
384         _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
385         _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
386         customizeJMenuItem( _super_tiny_fonts_mi );
387         customizeJMenuItem( _tiny_fonts_mi );
388         customizeJMenuItem( _small_fonts_mi );
389         customizeJMenuItem( _medium_fonts_mi );
390         customizeJMenuItem( _large_fonts_mi );
391         _jmenubar.add( _font_size_menu );
392     }
393
394     void buildHelpMenu() {
395         _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
396         _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
397         _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
398         _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
399         _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
400         _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
401         _help_jmenu.addSeparator();
402         _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
403         customizeJMenuItem( _help_item );
404         customizeJMenuItem( _website_item );
405         customizeJMenuItem( _phyloxml_website_item );
406         customizeJMenuItem( _aptx_ref_item );
407         customizeJMenuItem( _phyloxml_ref_item );
408         customizeJMenuItem( _about_item );
409         _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
410         _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
411         _jmenubar.add( _help_jmenu );
412     }
413
414     void buildOptionsMenu() {
415         _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
416         _options_jmenu.addChangeListener( new ChangeListener() {
417
418             @Override
419             public void stateChanged( final ChangeEvent e ) {
420                 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
421                 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
422                 MainFrame
423                         .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
424                 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
425                         .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
426                 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
427                                                                      _show_scale_cbmi,
428                                                                      _show_branch_length_values_cbmi,
429                                                                      _non_lined_up_cladograms_rbmi,
430                                                                      _uniform_cladograms_rbmi,
431                                                                      _ext_node_dependent_cladogram_rbmi,
432                                                                      _label_direction_cbmi );
433                 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
434                 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
435                 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
436             }
437         } );
438         _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
439                                                                 getConfiguration() ) );
440         _options_jmenu
441                 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
442         _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
443         _options_jmenu
444                 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
445         _radio_group_1 = new ButtonGroup();
446         _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
447         _radio_group_1.add( _uniform_cladograms_rbmi );
448         _radio_group_1.add( _non_lined_up_cladograms_rbmi );
449         _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
450         _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
451         _options_jmenu
452                 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
453         _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
454         _options_jmenu
455                 .add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL ) );
456         _options_jmenu
457                 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
458         _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
459         _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
460         _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
461         _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
462         _options_jmenu
463                 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
464         _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
465         _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
466         _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
467         _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
468         _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
469         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
470             _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
471         }
472         _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
473         _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
474         _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
475         _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
476         _options_jmenu.addSeparator();
477         _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
478                                                                 getConfiguration() ) );
479         _options_jmenu
480                 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
481         _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
482         _options_jmenu
483                 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
484         customizeJMenuItem( _choose_font_mi );
485         customizeJMenuItem( _choose_minimal_confidence_mi );
486         customizeJMenuItem( _switch_colors_mi );
487         customizeJMenuItem( _overview_placment_mi );
488         customizeCheckBoxMenuItem( _label_direction_cbmi,
489                                    getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
490         customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
491         customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
492         customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
493         customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
494         customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
495         customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
496         customizeJMenuItem( _cycle_node_shape_mi );
497         customizeJMenuItem( _cycle_node_fill_mi );
498         customizeJMenuItem( _choose_node_size_mi );
499         customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
500         customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
501         customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
502         customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
503                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
504         customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
505                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
506         customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
507                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
508         customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
509         customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
510         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
511         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
512         customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
513         _jmenubar.add( _options_jmenu );
514     }
515
516     void buildToolsMenu() {
517         _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
518         _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
519         customizeJMenuItem( _confcolor_item );
520         _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
521         customizeJMenuItem( _taxcolor_item );
522         _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
523         _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
524         customizeJMenuItem( _remove_branch_color_item );
525         _tools_menu.addSeparator();
526         _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
527         customizeJMenuItem( _midpoint_root_item );
528         _tools_menu.addSeparator();
529         _tools_menu
530                 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
531         customizeJMenuItem( _infer_common_sn_names_item );
532         _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
533         customizeJMenuItem( _collapse_species_specific_subtrees );
534         _jmenubar.add( _tools_menu );
535     }
536
537     void buildTypeMenu() {
538         _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
539         _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
540         _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
541         _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
542         _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
543         _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
544         _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
545         _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
546         _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
547         customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
548         customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
549         customizeCheckBoxMenuItem( _euro_type_cbmi, false );
550         customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
551         customizeCheckBoxMenuItem( _curved_type_cbmi, false );
552         customizeCheckBoxMenuItem( _convex_type_cbmi, false );
553         customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
554         customizeCheckBoxMenuItem( _circular_type_cbmi, false );
555         _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
556         _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
557         initializeTypeMenu( getOptions() );
558         _jmenubar.add( _type_menu );
559     }
560
561     void buildViewMenu() {
562         _view_jmenu = MainFrame.createMenu( "View as Text", getConfiguration() );
563         _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
564         _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
565         _view_jmenu.add( _view_as_NHX_item = new JMenuItem( "View as NHX" ) );
566         _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
567         customizeJMenuItem( _view_as_NH_item );
568         customizeJMenuItem( _view_as_NHX_item );
569         customizeJMenuItem( _view_as_XML_item );
570         customizeJMenuItem( _view_as_nexus_item );
571         _jmenubar.add( _view_jmenu );
572     }
573
574     private void chooseFont() {
575         final FontChooser fc = new FontChooser();
576         fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
577         fc.showDialog( this, "Select the Base Font" );
578         getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
579     }
580
581     private void chooseMinimalConfidence() {
582         final String s = ( String ) JOptionPane
583                 .showInputDialog( this,
584                                   "Please the minimum for confidence values to be displayed.\n" + "[current value: "
585                                           + getOptions().getMinConfidenceValue() + "]\n",
586                                   "Minimal Confidence Value",
587                                   JOptionPane.QUESTION_MESSAGE,
588                                   null,
589                                   null,
590                                   getOptions().getMinConfidenceValue() );
591         if ( !ForesterUtil.isEmpty( s ) ) {
592             boolean success = true;
593             double m = 0.0;
594             final String m_str = s.trim();
595             if ( !ForesterUtil.isEmpty( m_str ) ) {
596                 try {
597                     m = Double.parseDouble( m_str );
598                 }
599                 catch ( final Exception ex ) {
600                     success = false;
601                 }
602             }
603             else {
604                 success = false;
605             }
606             if ( success && ( m >= 0.0 ) ) {
607                 getOptions().setMinConfidenceValue( m );
608             }
609         }
610     }
611
612     void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
613         if ( item != null ) {
614             item.setFont( MainFrame.menu_font );
615             if ( !getConfiguration().isUseNativeUI() ) {
616                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
617                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
618             }
619             item.setSelected( is_selected );
620             item.addActionListener( this );
621         }
622     }
623
624     void customizeJMenuItem( final JMenuItem jmi ) {
625         jmi.setFont( MainFrame.menu_font );
626         if ( !getConfiguration().isUseNativeUI() ) {
627             jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
628             jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
629         }
630         jmi.addActionListener( this );
631     }
632
633     private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
634         if ( item != null ) {
635             item.setFont( MainFrame.menu_font );
636             if ( !getConfiguration().isUseNativeUI() ) {
637                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
638                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
639             }
640             item.setSelected( is_selected );
641             item.addActionListener( this );
642         }
643     }
644
645     @Override
646     public void destroy() {
647         AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
648         removeTextFrame();
649         if ( getMainPanel() != null ) {
650             getMainPanel().terminate();
651         }
652     }
653
654     Configuration getConfiguration() {
655         return _configuration;
656     }
657
658     TreePanel getCurrentTreePanel() {
659         return getMainPanel().getCurrentTreePanel();
660     }
661
662     JCheckBoxMenuItem getlabelDirectionCbmi() {
663         return _label_direction_cbmi;
664     }
665
666     private MainPanel getMainPanel() {
667         return _main_panel;
668     }
669
670     public Options getOptions() {
671         return _options;
672     }
673
674     Options getOtions() {
675         return _options;
676     }
677
678     @Override
679     public void init() {
680         final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
681         AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
682         final Configuration configuration = new Configuration( config_filename, true, true, true );
683         setConfiguration( configuration );
684         setOptions( Options.createInstance( configuration ) );
685         setupUI();
686         URL phys_url = null;
687         Phylogeny[] phys = null;
688         final String phys_url_string = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
689         AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + phys_url_string );
690         // Get URL to tree file
691         if ( phys_url_string != null ) {
692             try {
693                 phys_url = new URL( phys_url_string );
694             }
695             catch ( final Exception e ) {
696                 ForesterUtil.printErrorMessage( NAME, "error: " + e );
697                 e.printStackTrace();
698                 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + phys_url_string
699                         + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
700             }
701         }
702         // Load the tree from URL
703         if ( phys_url != null ) {
704             try {
705                 phys = AptxUtil.readPhylogeniesFromUrl( phys_url, getConfiguration().isValidatePhyloXmlAgainstSchema() );
706             }
707             catch ( final Exception e ) {
708                 ForesterUtil.printErrorMessage( NAME, e.toString() );
709                 e.printStackTrace();
710                 JOptionPane.showMessageDialog( this,
711                                                NAME + ": Failed to read phylogenies: " + "\nException: " + e,
712                                                "Failed to read phylogenies",
713                                                JOptionPane.ERROR_MESSAGE );
714             }
715         }
716         if ( ( phys == null ) || ( phys.length < 1 ) ) {
717             ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
718             JOptionPane.showMessageDialog( this,
719                                            NAME + ": phylogenies from [" + phys_url + "] are null or empty",
720                                            "Failed to read phylogenies",
721                                            JOptionPane.ERROR_MESSAGE );
722             return;
723         }
724         else {
725             AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
726         }
727         setVisible( false );
728         setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
729         _jmenubar = new JMenuBar();
730         if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
731             if ( !getConfiguration().isUseNativeUI() ) {
732                 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
733             }
734             buildToolsMenu();
735             buildViewMenu();
736             buildFontSizeMenu();
737             buildOptionsMenu();
738             buildTypeMenu();
739             buildHelpMenu();
740             setJMenuBar( _jmenubar );
741         }
742         final Container contentpane = getContentPane();
743         contentpane.setLayout( new BorderLayout() );
744         contentpane.add( getMainPanel(), BorderLayout.CENTER );
745         addComponentListener( new ComponentAdapter() {
746
747             @Override
748             public void componentResized( final ComponentEvent e ) {
749                 if ( getMainPanel().getCurrentTreePanel() != null ) {
750                     getMainPanel().getCurrentTreePanel().setParametersForPainting( getMainPanel().getCurrentTreePanel()
751                                                                                            .getWidth(),
752                                                                                    getMainPanel().getCurrentTreePanel()
753                                                                                            .getHeight(),
754                                                                                    false );
755                 }
756             }
757         } );
758         if ( getConfiguration().isUseTabbedDisplay() ) {
759             AptxUtil.printAppletMessage( NAME, "using tabbed display" );
760             AptxUtil.addPhylogeniesToTabs( phys,
761                                            new File( phys_url.getFile() ).getName(),
762                                            phys_url.toString(),
763                                            getConfiguration(),
764                                            getMainPanel() );
765         }
766         else {
767             AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
768             AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
769         }
770         validate();
771         setName( NAME );
772         getMainPanel().getControlPanel().showWholeAll();
773         getMainPanel().getControlPanel().showWhole();
774         System.gc();
775         AptxUtil.printAppletMessage( NAME, "successfully initialized" );
776         /* GUILHEM_BEG */
777         getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
778         for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
779                 .getRelevantSequenceRelationTypes() ) {
780             getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
781         }
782         final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
783         if ( default_relation != null ) {
784             getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
785         }
786         final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
787         if ( default_sequence != null ) {
788             getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
789             /* GUILHEM_END */
790         }
791         setVisible( true );
792     }
793
794     void initializeTypeMenu( final Options options ) {
795         setTypeMenuToAllUnselected();
796         try {
797             switch ( options.getPhylogenyGraphicsType() ) {
798                 case CONVEX:
799                     _convex_type_cbmi.setSelected( true );
800                     break;
801                 case CURVED:
802                     _curved_type_cbmi.setSelected( true );
803                     break;
804                 case EURO_STYLE:
805                     _euro_type_cbmi.setSelected( true );
806                     break;
807                 case ROUNDED:
808                     _rounded_type_cbmi.setSelected( true );
809                     break;
810                 case TRIANGULAR:
811                     _triangular_type_cbmi.setSelected( true );
812                     break;
813                 case UNROOTED:
814                     _unrooted_type_cbmi.setSelected( true );
815                     break;
816                 case CIRCULAR:
817                     _circular_type_cbmi.setSelected( true );
818                     break;
819                 default:
820                     _rectangular_type_cbmi.setSelected( true );
821                     break;
822             }
823         }
824         catch ( final NullPointerException np ) {
825             // In all likelihood, this is caused by menu-less display.
826         }
827     }
828
829     private boolean isScreenAntialias() {
830         return true;
831     }
832
833     private void removeBranchColors() {
834         if ( getMainPanel().getCurrentPhylogeny() != null ) {
835             AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
836         }
837     }
838
839     void removeTextFrame() {
840         if ( _textframe != null ) {
841             _textframe.close();
842             _textframe = null;
843         }
844     }
845
846     void setConfiguration( final Configuration configuration ) {
847         _configuration = configuration;
848     }
849
850     private void setMainPanel( final MainPanelApplets main_panel ) {
851         _main_panel = main_panel;
852     }
853
854     void setOptions( final Options options ) {
855         _options = options;
856     }
857
858     void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
859         setTypeMenuToAllUnselected();
860         try {
861             switch ( type ) {
862                 case CIRCULAR:
863                     _circular_type_cbmi.setSelected( true );
864                     break;
865                 case CONVEX:
866                     _convex_type_cbmi.setSelected( true );
867                     break;
868                 case CURVED:
869                     _curved_type_cbmi.setSelected( true );
870                     break;
871                 case EURO_STYLE:
872                     _euro_type_cbmi.setSelected( true );
873                     break;
874                 case ROUNDED:
875                     _rounded_type_cbmi.setSelected( true );
876                     break;
877                 case RECTANGULAR:
878                     _rectangular_type_cbmi.setSelected( true );
879                     break;
880                 case TRIANGULAR:
881                     _triangular_type_cbmi.setSelected( true );
882                     break;
883                 case UNROOTED:
884                     _unrooted_type_cbmi.setSelected( true );
885                     break;
886                 default:
887                     throw new IllegalArgumentException( "unknown type: " + type );
888             }
889         }
890         catch ( final NullPointerException np ) {
891             // In all likelihood, this is caused by menu-less display.
892         }
893     }
894
895     void setTypeMenuToAllUnselected() {
896         if ( _convex_type_cbmi != null ) {
897             _convex_type_cbmi.setSelected( false );
898         }
899         if ( _curved_type_cbmi != null ) {
900             _curved_type_cbmi.setSelected( false );
901         }
902         if ( _euro_type_cbmi != null ) {
903             _euro_type_cbmi.setSelected( false );
904         }
905         if ( _rounded_type_cbmi != null ) {
906             _rounded_type_cbmi.setSelected( false );
907         }
908         if ( _triangular_type_cbmi != null ) {
909             _triangular_type_cbmi.setSelected( false );
910         }
911         if ( _rectangular_type_cbmi != null ) {
912             _rectangular_type_cbmi.setSelected( false );
913         }
914         if ( _unrooted_type_cbmi != null ) {
915             _unrooted_type_cbmi.setSelected( false );
916         }
917         if ( _circular_type_cbmi != null ) {
918             _circular_type_cbmi.setSelected( false );
919         }
920     }
921
922     private void setupUI() {
923         try {
924             if ( getConfiguration().isUseNativeUI() ) {
925                 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
926             }
927             else {
928                 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
929             }
930         }
931         catch ( final UnsupportedLookAndFeelException e ) {
932             AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
933         }
934         catch ( final ClassNotFoundException e ) {
935             AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
936         }
937         catch ( final InstantiationException e ) {
938             AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
939         }
940         catch ( final IllegalAccessException e ) {
941             AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
942         }
943         catch ( final Exception e ) {
944             AptxUtil.dieWithSystemError( e.toString() );
945         }
946     }
947
948     @Override
949     public void start() {
950         if ( getMainPanel() != null ) {
951             getMainPanel().validate();
952         }
953         requestFocus();
954         requestFocusInWindow();
955         requestFocus();
956         AptxUtil.printAppletMessage( NAME, "started" );
957     }
958
959     void switchColors() {
960         final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
961         final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
962         csc.setVisible( true );
963         getMainPanel().setTreeColorSet( colorset );
964     }
965
966     void typeChanged( final Object o ) {
967         updateTypeCheckboxes( getOptions(), o );
968         updateOptions( getOptions() );
969         if ( getCurrentTreePanel() != null ) {
970             final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
971             final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
972             if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
973                     || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
974                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
975                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
976                 getCurrentTreePanel().getControlPanel().showWhole();
977             }
978             if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
979                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
980             }
981             else {
982                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
983             }
984             getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
985             MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
986         }
987     }
988
989     void updateOptions( final Options options ) {
990         options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
991         options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
992                 && _background_gradient_cbmi.isSelected() );
993         options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
994         options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
995                 && _abbreviate_scientific_names.isSelected() );
996         options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
997                 && _color_labels_same_as_parent_branch.isSelected() );
998         options.setShowDefaultNodeShapes( ( _show_default_node_shapes_cbmi != null )
999                 && _show_default_node_shapes_cbmi.isSelected() );
1000         options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1001                 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1002         if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1003             options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1004         }
1005         else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1006             options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1007         }
1008         else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1009             options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1010         }
1011         options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1012                 && _search_case_senstive_cbmi.isSelected() );
1013         if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1014             options.setShowScale( _show_scale_cbmi.isSelected() );
1015         }
1016         if ( _label_direction_cbmi != null ) {
1017             if ( _label_direction_cbmi.isSelected() ) {
1018                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1019             }
1020             else {
1021                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1022             }
1023         }
1024         options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1025         options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1026                 && _show_confidence_stddev_cbmi.isSelected() );
1027         if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1028             options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1029         }
1030         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1031                 && _search_whole_words_only_cbmi.isSelected() );
1032         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1033                 && _inverse_search_result_cbmi.isSelected() );
1034         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1035             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1036         }
1037         else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1038             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1039         }
1040         else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1041             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1042         }
1043         else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1044             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1045         }
1046         else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1047             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1048         }
1049         else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1050             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1051         }
1052         else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1053             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1054         }
1055         else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1056             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1057         }
1058     }
1059
1060     void updateTypeCheckboxes( final Options options, final Object o ) {
1061         setTypeMenuToAllUnselected();
1062         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1063     }
1064
1065     void viewAsNexus() {
1066         removeTextFrame();
1067         if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1068                 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1069             return;
1070         }
1071         _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNexus() );
1072     }
1073
1074     void viewAsNH() {
1075         removeTextFrame();
1076         if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1077                 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1078             return;
1079         }
1080         _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshire() );
1081     }
1082
1083     void viewAsNHX() {
1084         removeTextFrame();
1085         if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1086                 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1087             return;
1088         }
1089         _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshireX() );
1090     }
1091
1092     void viewAsXML() {
1093         removeTextFrame();
1094         if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1095                 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1096             return;
1097         }
1098         _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ) );
1099     }
1100
1101     static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1102         for( final TreePanel tree_panel : treepanels ) {
1103             tree_panel.setTextAntialias();
1104         }
1105     }
1106 }