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