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