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