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