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