2 package org.forester.archaeopteryx;
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;
11 import java.io.IOException;
13 import java.util.List;
15 import javax.swing.ButtonGroup;
16 import javax.swing.JApplet;
17 import javax.swing.JCheckBoxMenuItem;
18 import javax.swing.JMenu;
19 import javax.swing.JMenuBar;
20 import javax.swing.JMenuItem;
21 import javax.swing.JOptionPane;
22 import javax.swing.JRadioButtonMenuItem;
23 import javax.swing.UIManager;
24 import javax.swing.UnsupportedLookAndFeelException;
25 import javax.swing.event.ChangeEvent;
26 import javax.swing.event.ChangeListener;
28 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
29 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
30 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
31 import org.forester.phylogeny.Phylogeny;
32 import org.forester.phylogeny.data.SequenceRelation;
33 import org.forester.util.ForesterUtil;
34 import org.forester.util.ForesterConstants;
38 // <applet archive="forester.jar"
39 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
40 // codebase="http://www.myserver.org/path/to/forester"
43 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
44 // <param name="url_of_tree_to_load"
45 // value="http://www.myserver.org/examples/data/apaf.xml">
46 // <param name="config_file"
47 // value="http://www.myserver.org/examples/config/config_file.txt">
49 public class ArchaeopteryxE extends JApplet implements ActionListener {
51 private final static String NAME = "ArchaeopteryxE";
52 private static final long serialVersionUID = -1220055577935759443L;
53 private Configuration _configuration;
54 private MainPanelApplets _main_panel;
55 private JMenuBar _jmenubar;
56 private JMenu _options_jmenu;
57 private JMenu _font_size_menu;
58 private JMenuItem _super_tiny_fonts_mi;
59 private JMenuItem _tiny_fonts_mi;
60 private JMenuItem _small_fonts_mi;
61 private JMenuItem _medium_fonts_mi;
62 private JMenuItem _large_fonts_mi;
63 private TextFrame _textframe;
64 private JMenu _tools_menu;
65 private JMenuItem _taxcolor_item;
66 private JMenuItem _confcolor_item;
67 private JMenuItem _midpoint_root_item;
68 private JMenu _view_jmenu;
69 private JMenuItem _view_as_XML_item;
70 private JMenuItem _view_as_NH_item;
71 private JMenuItem _view_as_NHX_item;
72 private JMenuItem _view_as_nexus_item;
73 private JMenu _type_menu;
74 private JCheckBoxMenuItem _rectangular_type_cbmi;
75 private JCheckBoxMenuItem _triangular_type_cbmi;
76 private JCheckBoxMenuItem _curved_type_cbmi;
77 private JCheckBoxMenuItem _convex_type_cbmi;
78 private JCheckBoxMenuItem _euro_type_cbmi;
79 private JCheckBoxMenuItem _rounded_type_cbmi;
80 private JCheckBoxMenuItem _unrooted_type_cbmi;
81 private JCheckBoxMenuItem _circular_type_cbmi;
82 private JMenuItem _help_item;
83 private JMenuItem _about_item;
84 private JMenu _help_jmenu;
85 private JMenuItem _website_item;
86 private JMenuItem _phyloxml_website_item;
87 private JMenuItem _phyloxml_ref_item;
88 private JMenuItem _aptx_ref_item;
89 private JMenuItem _remove_branch_color_item;
90 private JMenuItem _infer_common_sn_names_item;
91 private JCheckBoxMenuItem _show_domain_labels;
92 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
93 private JCheckBoxMenuItem _abbreviate_scientific_names;
94 private JCheckBoxMenuItem _screen_antialias_cbmi;
95 private JCheckBoxMenuItem _background_gradient_cbmi;
96 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
97 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
98 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
99 private Options _options;
100 private JMenuItem _choose_font_mi;
101 private JMenuItem _switch_colors_mi;
102 JCheckBoxMenuItem _label_direction_cbmi;
103 private JCheckBoxMenuItem _show_scale_cbmi;
104 private JCheckBoxMenuItem _search_case_senstive_cbmi;
105 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
106 private JCheckBoxMenuItem _inverse_search_result_cbmi;
107 private JCheckBoxMenuItem _show_overview_cbmi;
108 private JMenuItem _choose_minimal_confidence_mi;
109 private JCheckBoxMenuItem _show_branch_length_values_cbmi;
110 private JMenuItem _collapse_species_specific_subtrees;
111 private JMenuItem _overview_placment_mi;
112 private ButtonGroup _radio_group_1;
113 private JCheckBoxMenuItem _show_default_node_shapes_cbmi;
114 private JMenuItem _cycle_node_shape_mi;
115 private JMenuItem _cycle_node_fill_mi;
116 private JMenuItem _choose_node_size_mi;
117 private JCheckBoxMenuItem _taxonomy_colorize_node_shapes_cbmi;
120 public void actionPerformed( final ActionEvent e ) {
121 final Object o = e.getSource();
122 if ( o == _midpoint_root_item ) {
123 getMainPanel().getCurrentTreePanel().midpointRoot();
125 else if ( o == _taxcolor_item ) {
126 getMainPanel().getCurrentTreePanel().taxColor();
128 else if ( o == _confcolor_item ) {
129 getMainPanel().getCurrentTreePanel().confColor();
131 else if ( o == _infer_common_sn_names_item ) {
132 if ( getCurrentTreePanel() != null ) {
133 getCurrentTreePanel().inferCommonPartOfScientificNames();
136 else if ( o == _collapse_species_specific_subtrees ) {
137 if ( getCurrentTreePanel() != null ) {
138 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
141 else if ( o == _remove_branch_color_item ) {
142 removeBranchColors();
144 else if ( o == _switch_colors_mi ) {
147 else if ( o == _view_as_NH_item ) {
150 else if ( o == _view_as_NHX_item ) {
153 else if ( o == _view_as_XML_item ) {
156 else if ( o == _view_as_nexus_item ) {
159 else if ( o == _super_tiny_fonts_mi ) {
160 if ( getCurrentTreePanel() != null ) {
161 getCurrentTreePanel().setSuperTinyFonts();
162 getCurrentTreePanel().repaint();
165 else if ( o == _tiny_fonts_mi ) {
166 if ( getCurrentTreePanel() != null ) {
167 getCurrentTreePanel().setTinyFonts();
168 getCurrentTreePanel().repaint();
171 else if ( o == _small_fonts_mi ) {
172 if ( getCurrentTreePanel() != null ) {
173 getCurrentTreePanel().setSmallFonts();
174 getCurrentTreePanel().repaint();
177 else if ( o == _medium_fonts_mi ) {
178 if ( getCurrentTreePanel() != null ) {
179 getCurrentTreePanel().setMediumFonts();
180 getCurrentTreePanel().repaint();
183 else if ( o == _large_fonts_mi ) {
184 if ( getCurrentTreePanel() != null ) {
185 getCurrentTreePanel().setLargeFonts();
186 getCurrentTreePanel().repaint();
189 else if ( o == _choose_font_mi ) {
192 else if ( o == _choose_minimal_confidence_mi ) {
193 chooseMinimalConfidence();
195 else if ( o == _choose_node_size_mi ) {
196 MainFrame.chooseNodeSize( getOptions(), this );
198 else if ( o == _overview_placment_mi ) {
199 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
201 else if ( o == _cycle_node_fill_mi ) {
202 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
204 else if ( o == _cycle_node_shape_mi ) {
205 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
207 else if ( o == _non_lined_up_cladograms_rbmi ) {
208 updateOptions( getOptions() );
209 _main_panel.getControlPanel().showWhole();
211 else if ( o == _uniform_cladograms_rbmi ) {
212 updateOptions( getOptions() );
213 _main_panel.getControlPanel().showWhole();
215 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
216 updateOptions( getOptions() );
217 _main_panel.getControlPanel().showWhole();
219 else if ( o == _search_case_senstive_cbmi ) {
220 updateOptions( getOptions() );
221 getMainPanel().getControlPanel().search();
223 else if ( o == _search_whole_words_only_cbmi ) {
224 updateOptions( getOptions() );
225 getMainPanel().getControlPanel().search();
227 else if ( o == _inverse_search_result_cbmi ) {
228 updateOptions( getOptions() );
229 getMainPanel().getControlPanel().search();
231 else if ( o == _show_scale_cbmi ) {
232 updateOptions( getOptions() );
234 else if ( o == _show_branch_length_values_cbmi ) {
235 updateOptions( getOptions() );
237 else if ( o == _label_direction_cbmi ) {
238 updateOptions( getOptions() );
240 else if ( o == _show_overview_cbmi ) {
241 updateOptions( getOptions() );
242 if ( getCurrentTreePanel() != null ) {
243 getCurrentTreePanel().updateOvSizes();
246 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
247 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
248 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
251 else if ( o == _screen_antialias_cbmi ) {
252 updateOptions( getOptions() );
253 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
255 else if ( o == _background_gradient_cbmi ) {
256 updateOptions( getOptions() );
258 else if ( o == _show_domain_labels ) {
259 updateOptions( getOptions() );
261 else if ( o == _color_labels_same_as_parent_branch ) {
262 updateOptions( getOptions() );
264 else if ( o == _show_default_node_shapes_cbmi ) {
265 updateOptions( getOptions() );
267 else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
268 updateOptions( getOptions() );
270 else if ( o == _about_item ) {
273 else if ( o == _help_item ) {
274 MainFrame.help( getConfiguration().getWebLinks() );
276 else if ( o == _website_item ) {
278 Util.openWebsite( Constants.APTX_WEB_SITE, true, this );
280 catch ( final IOException e1 ) {
281 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
284 else if ( o == _phyloxml_website_item ) {
286 Util.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
288 catch ( final IOException e1 ) {
289 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
292 else if ( o == _aptx_ref_item ) {
294 Util.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
296 catch ( final IOException e1 ) {
297 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
300 else if ( o == _phyloxml_ref_item ) {
302 Util.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
304 catch ( final IOException e1 ) {
305 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
312 * This method returns the current phylogeny as a string in the chosen format
314 * @param format must be NH, NHX, NEXUS or PHYLOXML
315 * @return the phylogeny string
316 * @author Hervé Ménager
318 public String getCurrentPhylogeny( final String format ) {
320 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
321 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
324 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
326 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
328 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
330 return getMainPanel().getCurrentPhylogeny().toNexus();
332 return getMainPanel().getCurrentPhylogeny().toPhyloXML(-1);
340 void buildFontSizeMenu() {
341 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
342 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
343 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
344 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
345 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
346 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
347 customizeJMenuItem( _super_tiny_fonts_mi );
348 customizeJMenuItem( _tiny_fonts_mi );
349 customizeJMenuItem( _small_fonts_mi );
350 customizeJMenuItem( _medium_fonts_mi );
351 customizeJMenuItem( _large_fonts_mi );
352 _jmenubar.add( _font_size_menu );
355 void buildHelpMenu() {
356 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
357 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
358 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
359 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
360 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
361 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
362 _help_jmenu.addSeparator();
363 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
364 customizeJMenuItem( _help_item );
365 customizeJMenuItem( _website_item );
366 customizeJMenuItem( _phyloxml_website_item );
367 customizeJMenuItem( _aptx_ref_item );
368 customizeJMenuItem( _phyloxml_ref_item );
369 customizeJMenuItem( _about_item );
370 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
371 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
372 _jmenubar.add( _help_jmenu );
375 void buildOptionsMenu() {
376 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
377 _options_jmenu.addChangeListener( new ChangeListener() {
380 public void stateChanged( final ChangeEvent e ) {
381 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
382 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
384 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
385 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
386 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
387 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
389 _show_branch_length_values_cbmi,
390 _non_lined_up_cladograms_rbmi,
391 _uniform_cladograms_rbmi,
392 _ext_node_dependent_cladogram_rbmi,
393 _label_direction_cbmi );
394 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
395 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
396 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
399 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
400 getConfiguration() ) );
402 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
403 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
405 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
406 _radio_group_1 = new ButtonGroup();
407 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
408 _radio_group_1.add( _uniform_cladograms_rbmi );
409 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
412 .add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL ) );
414 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
415 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
416 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
417 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
419 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
421 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
422 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
423 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
425 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
426 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
427 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
428 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
429 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
430 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
431 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
432 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
434 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
435 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
436 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
437 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
438 _options_jmenu.addSeparator();
439 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
440 getConfiguration() ) );
442 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
443 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
445 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
446 customizeJMenuItem( _choose_font_mi );
447 customizeJMenuItem( _choose_minimal_confidence_mi );
448 customizeJMenuItem( _switch_colors_mi );
449 customizeJMenuItem( _overview_placment_mi );
450 customizeCheckBoxMenuItem( _label_direction_cbmi,
451 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
452 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
453 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
454 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
455 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
456 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
457 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
458 customizeJMenuItem( _cycle_node_shape_mi );
459 customizeJMenuItem( _cycle_node_fill_mi );
460 customizeJMenuItem( _choose_node_size_mi );
461 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
462 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
463 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
464 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
465 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
466 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
467 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
468 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
469 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
470 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
471 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
472 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
473 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
474 _jmenubar.add( _options_jmenu );
477 void buildToolsMenu() {
478 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
479 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
480 customizeJMenuItem( _confcolor_item );
481 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
482 customizeJMenuItem( _taxcolor_item );
483 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
484 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
485 customizeJMenuItem( _remove_branch_color_item );
486 _tools_menu.addSeparator();
487 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
488 customizeJMenuItem( _midpoint_root_item );
489 _tools_menu.addSeparator();
491 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
492 customizeJMenuItem( _infer_common_sn_names_item );
493 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
494 customizeJMenuItem( _collapse_species_specific_subtrees );
495 _jmenubar.add( _tools_menu );
498 void buildTypeMenu() {
499 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
500 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
501 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
502 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
503 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
504 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
505 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
506 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
507 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
508 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
509 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
510 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
511 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
512 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
513 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
514 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
515 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
516 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
517 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
518 initializeTypeMenu( getOptions() );
519 _jmenubar.add( _type_menu );
522 void buildViewMenu() {
523 _view_jmenu = MainFrame.createMenu( "View as Text", getConfiguration() );
524 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
525 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
526 _view_jmenu.add( _view_as_NHX_item = new JMenuItem( "View as NHX" ) );
527 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
528 customizeJMenuItem( _view_as_NH_item );
529 customizeJMenuItem( _view_as_NHX_item );
530 customizeJMenuItem( _view_as_XML_item );
531 customizeJMenuItem( _view_as_nexus_item );
532 _jmenubar.add( _view_jmenu );
535 private void chooseFont() {
536 final FontChooser fc = new FontChooser();
537 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
538 fc.showDialog( this, "Select the Base Font" );
539 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
542 private void chooseMinimalConfidence() {
543 final String s = ( String ) JOptionPane
544 .showInputDialog( this,
545 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
546 + getOptions().getMinConfidenceValue() + "]\n",
547 "Minimal Confidence Value",
548 JOptionPane.QUESTION_MESSAGE,
551 getOptions().getMinConfidenceValue() );
552 if ( !ForesterUtil.isEmpty( s ) ) {
553 boolean success = true;
555 final String m_str = s.trim();
556 if ( !ForesterUtil.isEmpty( m_str ) ) {
558 m = Double.parseDouble( m_str );
560 catch ( final Exception ex ) {
567 if ( success && ( m >= 0.0 ) ) {
568 getOptions().setMinConfidenceValue( m );
573 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
574 if ( item != null ) {
575 item.setFont( MainFrame.menu_font );
576 if ( !getConfiguration().isUseNativeUI() ) {
577 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
578 item.setForeground( getConfiguration().getGuiMenuTextColor() );
580 item.setSelected( is_selected );
581 item.addActionListener( this );
585 void customizeJMenuItem( final JMenuItem jmi ) {
586 jmi.setFont( MainFrame.menu_font );
587 if ( !getConfiguration().isUseNativeUI() ) {
588 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
589 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
591 jmi.addActionListener( this );
594 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
595 if ( item != null ) {
596 item.setFont( MainFrame.menu_font );
597 if ( !getConfiguration().isUseNativeUI() ) {
598 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
599 item.setForeground( getConfiguration().getGuiMenuTextColor() );
601 item.setSelected( is_selected );
602 item.addActionListener( this );
607 public void destroy() {
608 Util.printAppletMessage( NAME, "going to be destroyed " );
610 if ( getMainPanel() != null ) {
611 getMainPanel().terminate();
615 Configuration getConfiguration() {
616 return _configuration;
619 TreePanel getCurrentTreePanel() {
620 return getMainPanel().getCurrentTreePanel();
623 JCheckBoxMenuItem getlabelDirectionCbmi() {
624 return _label_direction_cbmi;
627 private MainPanel getMainPanel() {
631 public Options getOptions() {
635 Options getOtions() {
641 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
642 Util.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
643 final Configuration configuration = new Configuration( config_filename, true, true );
644 setConfiguration( configuration );
645 setOptions( Options.createInstance( configuration ) );
648 Phylogeny[] phys = null;
649 final String phys_url_string = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
650 Util.printAppletMessage( NAME, "URL for phylogenies is " + phys_url_string );
651 // Get URL to tree file
652 if ( phys_url_string != null ) {
654 phys_url = new URL( phys_url_string );
656 catch ( final Exception e ) {
657 ForesterUtil.printErrorMessage( NAME, "error: " + e );
659 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + phys_url_string
660 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
663 // Load the tree from URL
664 if ( phys_url != null ) {
666 phys = Util.readPhylogeniesFromUrl( phys_url, getConfiguration().isValidatePhyloXmlAgainstSchema() );
668 catch ( final Exception e ) {
669 ForesterUtil.printErrorMessage( NAME, e.toString() );
671 JOptionPane.showMessageDialog( this,
672 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
673 "Failed to read phylogenies",
674 JOptionPane.ERROR_MESSAGE );
677 if ( ( phys == null ) || ( phys.length < 1 ) ) {
678 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
679 JOptionPane.showMessageDialog( this,
680 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
681 "Failed to read phylogenies",
682 JOptionPane.ERROR_MESSAGE );
686 Util.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
689 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
690 _jmenubar = new JMenuBar();
691 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
692 if ( !getConfiguration().isUseNativeUI() ) {
693 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
701 setJMenuBar( _jmenubar );
703 final Container contentpane = getContentPane();
704 contentpane.setLayout( new BorderLayout() );
705 contentpane.add( getMainPanel(), BorderLayout.CENTER );
706 addComponentListener( new ComponentAdapter() {
709 public void componentResized( final ComponentEvent e ) {
710 if ( getMainPanel().getCurrentTreePanel() != null ) {
711 getMainPanel().getCurrentTreePanel().setParametersForPainting( getMainPanel().getCurrentTreePanel()
713 getMainPanel().getCurrentTreePanel()
719 if ( getConfiguration().isUseTabbedDisplay() ) {
720 Util.printAppletMessage( NAME, "using tabbed display" );
721 Util.addPhylogeniesToTabs( phys,
722 new File( phys_url.getFile() ).getName(),
728 Util.printAppletMessage( NAME, "not using tabbed display" );
729 Util.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
733 getMainPanel().getControlPanel().showWholeAll();
734 getMainPanel().getControlPanel().showWhole();
736 Util.printAppletMessage( NAME, "successfully initialized" );
738 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
739 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
740 .getRelevantSequenceRelationTypes() ) {
741 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
743 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
744 if ( default_relation != null ) {
745 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
747 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
748 if ( default_sequence != null ) {
749 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
755 void initializeTypeMenu( final Options options ) {
756 setTypeMenuToAllUnselected();
758 switch ( options.getPhylogenyGraphicsType() ) {
760 _convex_type_cbmi.setSelected( true );
763 _curved_type_cbmi.setSelected( true );
766 _euro_type_cbmi.setSelected( true );
769 _rounded_type_cbmi.setSelected( true );
772 _triangular_type_cbmi.setSelected( true );
775 _unrooted_type_cbmi.setSelected( true );
778 _circular_type_cbmi.setSelected( true );
781 _rectangular_type_cbmi.setSelected( true );
785 catch ( final NullPointerException np ) {
786 // In all likelihood, this is caused by menu-less display.
790 private boolean isScreenAntialias() {
794 private void removeBranchColors() {
795 if ( getMainPanel().getCurrentPhylogeny() != null ) {
796 Util.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
800 void removeTextFrame() {
801 if ( _textframe != null ) {
807 void setConfiguration( final Configuration configuration ) {
808 _configuration = configuration;
811 private void setMainPanel( final MainPanelApplets main_panel ) {
812 _main_panel = main_panel;
815 void setOptions( final Options options ) {
819 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
820 setTypeMenuToAllUnselected();
824 _circular_type_cbmi.setSelected( true );
827 _convex_type_cbmi.setSelected( true );
830 _curved_type_cbmi.setSelected( true );
833 _euro_type_cbmi.setSelected( true );
836 _rounded_type_cbmi.setSelected( true );
839 _rectangular_type_cbmi.setSelected( true );
842 _triangular_type_cbmi.setSelected( true );
845 _unrooted_type_cbmi.setSelected( true );
848 throw new IllegalArgumentException( "unknown type: " + type );
851 catch ( final NullPointerException np ) {
852 // In all likelihood, this is caused by menu-less display.
856 void setTypeMenuToAllUnselected() {
857 if ( _convex_type_cbmi != null ) {
858 _convex_type_cbmi.setSelected( false );
860 if ( _curved_type_cbmi != null ) {
861 _curved_type_cbmi.setSelected( false );
863 if ( _euro_type_cbmi != null ) {
864 _euro_type_cbmi.setSelected( false );
866 if ( _rounded_type_cbmi != null ) {
867 _rounded_type_cbmi.setSelected( false );
869 if ( _triangular_type_cbmi != null ) {
870 _triangular_type_cbmi.setSelected( false );
872 if ( _rectangular_type_cbmi != null ) {
873 _rectangular_type_cbmi.setSelected( false );
875 if ( _unrooted_type_cbmi != null ) {
876 _unrooted_type_cbmi.setSelected( false );
878 if ( _circular_type_cbmi != null ) {
879 _circular_type_cbmi.setSelected( false );
883 private void setupUI() {
885 if ( getConfiguration().isUseNativeUI() ) {
886 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
889 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
892 catch ( final UnsupportedLookAndFeelException e ) {
893 Util.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
895 catch ( final ClassNotFoundException e ) {
896 Util.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
898 catch ( final InstantiationException e ) {
899 Util.dieWithSystemError( "InstantiationException: " + e.toString() );
901 catch ( final IllegalAccessException e ) {
902 Util.dieWithSystemError( "IllegalAccessException: " + e.toString() );
904 catch ( final Exception e ) {
905 Util.dieWithSystemError( e.toString() );
910 public void start() {
911 if ( getMainPanel() != null ) {
912 getMainPanel().validate();
915 requestFocusInWindow();
917 Util.printAppletMessage( NAME, "started" );
920 void switchColors() {
921 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
922 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
923 csc.setVisible( true );
924 getMainPanel().setTreeColorSet( colorset );
927 void typeChanged( final Object o ) {
928 updateTypeCheckboxes( getOptions(), o );
929 updateOptions( getOptions() );
930 if ( getCurrentTreePanel() != null ) {
931 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
932 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
933 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
934 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
935 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
936 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
937 getCurrentTreePanel().getControlPanel().showWhole();
939 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
940 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
943 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
945 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
946 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
950 void updateOptions( final Options options ) {
951 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
952 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
953 && _background_gradient_cbmi.isSelected() );
954 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
955 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
956 && _abbreviate_scientific_names.isSelected() );
957 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
958 && _color_labels_same_as_parent_branch.isSelected() );
959 options.setShowDefaultNodeShapes( ( _show_default_node_shapes_cbmi != null )
960 && _show_default_node_shapes_cbmi.isSelected() );
961 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
962 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
963 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
964 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
966 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
967 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
969 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
970 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
972 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
973 && _search_case_senstive_cbmi.isSelected() );
974 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
975 options.setShowScale( _show_scale_cbmi.isSelected() );
977 if ( _label_direction_cbmi != null ) {
978 if ( _label_direction_cbmi.isSelected() ) {
979 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
982 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
985 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
986 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
987 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
989 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
990 && _search_whole_words_only_cbmi.isSelected() );
991 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
992 && _inverse_search_result_cbmi.isSelected() );
993 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
994 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
996 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
997 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
999 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1000 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1002 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1003 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1005 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1006 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1008 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1009 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1011 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1012 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1014 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1015 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1019 void updateTypeCheckboxes( final Options options, final Object o ) {
1020 setTypeMenuToAllUnselected();
1021 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1024 void viewAsNexus() {
1026 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1027 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1030 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNexus() );
1035 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1036 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1039 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshire( false ) );
1044 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1045 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1048 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshireX() );
1053 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1054 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1057 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ) );
1060 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1061 for( final TreePanel tree_panel : treepanels ) {
1062 tree_panel.setTextAntialias();