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.ForesterConstants;
34 import org.forester.util.ForesterUtil;
37 // <applet archive="forester.jar"
38 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
39 // codebase="http://www.myserver.org/path/to/forester"
42 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
43 // <param name="url_of_tree_to_load"
44 // value="http://www.myserver.org/examples/data/apaf.xml">
45 // <param name="config_file"
46 // value="http://www.myserver.org/examples/config/config_file.txt">
48 public class ArchaeopteryxE extends JApplet implements ActionListener {
50 private final static String NAME = "ArchaeopteryxE";
51 private static final long serialVersionUID = -1220055577935759443L;
52 private Configuration _configuration;
53 private MainPanelApplets _main_panel;
54 private JMenuBar _jmenubar;
55 private JMenu _options_jmenu;
56 private JMenu _font_size_menu;
57 private JMenuItem _super_tiny_fonts_mi;
58 private JMenuItem _tiny_fonts_mi;
59 private JMenuItem _small_fonts_mi;
60 private JMenuItem _medium_fonts_mi;
61 private JMenuItem _large_fonts_mi;
62 private TextFrame _textframe;
63 private JMenu _tools_menu;
64 private JMenuItem _taxcolor_item;
65 private JMenuItem _confcolor_item;
66 private JMenuItem _midpoint_root_item;
67 private JMenu _view_jmenu;
68 private JMenuItem _view_as_XML_item;
69 private JMenuItem _view_as_NH_item;
70 private JMenuItem _view_as_NHX_item;
71 private JMenuItem _view_as_nexus_item;
72 private JMenu _type_menu;
73 private JCheckBoxMenuItem _rectangular_type_cbmi;
74 private JCheckBoxMenuItem _triangular_type_cbmi;
75 private JCheckBoxMenuItem _curved_type_cbmi;
76 private JCheckBoxMenuItem _convex_type_cbmi;
77 private JCheckBoxMenuItem _euro_type_cbmi;
78 private JCheckBoxMenuItem _rounded_type_cbmi;
79 private JCheckBoxMenuItem _unrooted_type_cbmi;
80 private JCheckBoxMenuItem _circular_type_cbmi;
81 private JMenuItem _help_item;
82 private JMenuItem _about_item;
83 private JMenu _help_jmenu;
84 private JMenuItem _website_item;
85 private JMenuItem _phyloxml_website_item;
86 private JMenuItem _phyloxml_ref_item;
87 private JMenuItem _aptx_ref_item;
88 private JMenuItem _remove_branch_color_item;
89 private JMenuItem _infer_common_sn_names_item;
90 private JCheckBoxMenuItem _show_domain_labels;
91 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
92 private JCheckBoxMenuItem _abbreviate_scientific_names;
93 private JCheckBoxMenuItem _screen_antialias_cbmi;
94 private JCheckBoxMenuItem _background_gradient_cbmi;
95 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
96 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
97 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
98 private Options _options;
99 private JMenuItem _choose_font_mi;
100 private JMenuItem _switch_colors_mi;
101 JCheckBoxMenuItem _label_direction_cbmi;
102 private JCheckBoxMenuItem _show_scale_cbmi;
103 private JCheckBoxMenuItem _search_case_senstive_cbmi;
104 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
105 private JCheckBoxMenuItem _inverse_search_result_cbmi;
106 private JCheckBoxMenuItem _show_overview_cbmi;
107 private JMenuItem _choose_minimal_confidence_mi;
108 private JCheckBoxMenuItem _show_branch_length_values_cbmi;
109 private JMenuItem _collapse_species_specific_subtrees;
110 private JMenuItem _overview_placment_mi;
111 private ButtonGroup _radio_group_1;
112 private JCheckBoxMenuItem _show_default_node_shapes_cbmi;
113 private JMenuItem _cycle_node_shape_mi;
114 private JMenuItem _cycle_node_fill_mi;
115 private JMenuItem _choose_node_size_mi;
116 private JCheckBoxMenuItem _taxonomy_colorize_node_shapes_cbmi;
119 public void actionPerformed( final ActionEvent e ) {
120 final Object o = e.getSource();
121 if ( o == _midpoint_root_item ) {
122 getMainPanel().getCurrentTreePanel().midpointRoot();
124 else if ( o == _taxcolor_item ) {
125 getMainPanel().getCurrentTreePanel().taxColor();
127 else if ( o == _confcolor_item ) {
128 getMainPanel().getCurrentTreePanel().confColor();
130 else if ( o == _infer_common_sn_names_item ) {
131 if ( getCurrentTreePanel() != null ) {
132 getCurrentTreePanel().inferCommonPartOfScientificNames();
135 else if ( o == _collapse_species_specific_subtrees ) {
136 if ( getCurrentTreePanel() != null ) {
137 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
140 else if ( o == _remove_branch_color_item ) {
141 removeBranchColors();
143 else if ( o == _switch_colors_mi ) {
146 else if ( o == _view_as_NH_item ) {
149 else if ( o == _view_as_NHX_item ) {
152 else if ( o == _view_as_XML_item ) {
155 else if ( o == _view_as_nexus_item ) {
158 else if ( o == _super_tiny_fonts_mi ) {
159 if ( getCurrentTreePanel() != null ) {
160 getCurrentTreePanel().setSuperTinyFonts();
161 getCurrentTreePanel().repaint();
164 else if ( o == _tiny_fonts_mi ) {
165 if ( getCurrentTreePanel() != null ) {
166 getCurrentTreePanel().setTinyFonts();
167 getCurrentTreePanel().repaint();
170 else if ( o == _small_fonts_mi ) {
171 if ( getCurrentTreePanel() != null ) {
172 getCurrentTreePanel().setSmallFonts();
173 getCurrentTreePanel().repaint();
176 else if ( o == _medium_fonts_mi ) {
177 if ( getCurrentTreePanel() != null ) {
178 getCurrentTreePanel().setMediumFonts();
179 getCurrentTreePanel().repaint();
182 else if ( o == _large_fonts_mi ) {
183 if ( getCurrentTreePanel() != null ) {
184 getCurrentTreePanel().setLargeFonts();
185 getCurrentTreePanel().repaint();
188 else if ( o == _choose_font_mi ) {
191 else if ( o == _choose_minimal_confidence_mi ) {
192 chooseMinimalConfidence();
194 else if ( o == _choose_node_size_mi ) {
195 MainFrame.chooseNodeSize( getOptions(), this );
197 else if ( o == _overview_placment_mi ) {
198 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
200 else if ( o == _cycle_node_fill_mi ) {
201 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
203 else if ( o == _cycle_node_shape_mi ) {
204 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
206 else if ( o == _non_lined_up_cladograms_rbmi ) {
207 updateOptions( getOptions() );
208 _main_panel.getControlPanel().showWhole();
210 else if ( o == _uniform_cladograms_rbmi ) {
211 updateOptions( getOptions() );
212 _main_panel.getControlPanel().showWhole();
214 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
215 updateOptions( getOptions() );
216 _main_panel.getControlPanel().showWhole();
218 else if ( o == _search_case_senstive_cbmi ) {
219 updateOptions( getOptions() );
220 getMainPanel().getControlPanel().search();
222 else if ( o == _search_whole_words_only_cbmi ) {
223 updateOptions( getOptions() );
224 getMainPanel().getControlPanel().search();
226 else if ( o == _inverse_search_result_cbmi ) {
227 updateOptions( getOptions() );
228 getMainPanel().getControlPanel().search();
230 else if ( o == _show_scale_cbmi ) {
231 updateOptions( getOptions() );
233 else if ( o == _show_branch_length_values_cbmi ) {
234 updateOptions( getOptions() );
236 else if ( o == _label_direction_cbmi ) {
237 updateOptions( getOptions() );
239 else if ( o == _show_overview_cbmi ) {
240 updateOptions( getOptions() );
241 if ( getCurrentTreePanel() != null ) {
242 getCurrentTreePanel().updateOvSizes();
245 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
246 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
247 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
250 else if ( o == _screen_antialias_cbmi ) {
251 updateOptions( getOptions() );
252 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
254 else if ( o == _background_gradient_cbmi ) {
255 updateOptions( getOptions() );
257 else if ( o == _show_domain_labels ) {
258 updateOptions( getOptions() );
260 else if ( o == _color_labels_same_as_parent_branch ) {
261 updateOptions( getOptions() );
263 else if ( o == _show_default_node_shapes_cbmi ) {
264 updateOptions( getOptions() );
266 else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
267 updateOptions( getOptions() );
269 else if ( o == _about_item ) {
272 else if ( o == _help_item ) {
273 MainFrame.help( getConfiguration().getWebLinks() );
275 else if ( o == _website_item ) {
277 Util.openWebsite( Constants.APTX_WEB_SITE, true, this );
279 catch ( final IOException e1 ) {
280 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
283 else if ( o == _phyloxml_website_item ) {
285 Util.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
287 catch ( final IOException e1 ) {
288 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
291 else if ( o == _aptx_ref_item ) {
293 Util.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
295 catch ( final IOException e1 ) {
296 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
299 else if ( o == _phyloxml_ref_item ) {
301 Util.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
303 catch ( final IOException e1 ) {
304 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
311 * This method returns the current phylogeny as a string in the chosen format
313 * @param format must be NH, NHX, NEXUS or PHYLOXML
314 * @return the phylogeny string
315 * @author Herve Menager
317 public String getCurrentPhylogeny( final String format ) {
319 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
320 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
323 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
325 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
327 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
329 return getMainPanel().getCurrentPhylogeny().toNexus();
331 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
338 void buildFontSizeMenu() {
339 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
340 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
341 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
342 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
343 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
344 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
345 customizeJMenuItem( _super_tiny_fonts_mi );
346 customizeJMenuItem( _tiny_fonts_mi );
347 customizeJMenuItem( _small_fonts_mi );
348 customizeJMenuItem( _medium_fonts_mi );
349 customizeJMenuItem( _large_fonts_mi );
350 _jmenubar.add( _font_size_menu );
353 void buildHelpMenu() {
354 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
355 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
356 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
357 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
358 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
359 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
360 _help_jmenu.addSeparator();
361 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
362 customizeJMenuItem( _help_item );
363 customizeJMenuItem( _website_item );
364 customizeJMenuItem( _phyloxml_website_item );
365 customizeJMenuItem( _aptx_ref_item );
366 customizeJMenuItem( _phyloxml_ref_item );
367 customizeJMenuItem( _about_item );
368 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
369 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
370 _jmenubar.add( _help_jmenu );
373 void buildOptionsMenu() {
374 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
375 _options_jmenu.addChangeListener( new ChangeListener() {
378 public void stateChanged( final ChangeEvent e ) {
379 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
380 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
382 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
383 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
384 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
385 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
387 _show_branch_length_values_cbmi,
388 _non_lined_up_cladograms_rbmi,
389 _uniform_cladograms_rbmi,
390 _ext_node_dependent_cladogram_rbmi,
391 _label_direction_cbmi );
392 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
393 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
394 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
397 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
398 getConfiguration() ) );
400 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
401 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
403 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
404 _radio_group_1 = new ButtonGroup();
405 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
406 _radio_group_1.add( _uniform_cladograms_rbmi );
407 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
410 .add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL ) );
412 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
413 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
414 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
415 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
417 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
419 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
420 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
421 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
423 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
424 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
425 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
426 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
427 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
428 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
429 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
430 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
432 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
433 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
434 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
435 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
436 _options_jmenu.addSeparator();
437 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
438 getConfiguration() ) );
440 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
441 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
443 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
444 customizeJMenuItem( _choose_font_mi );
445 customizeJMenuItem( _choose_minimal_confidence_mi );
446 customizeJMenuItem( _switch_colors_mi );
447 customizeJMenuItem( _overview_placment_mi );
448 customizeCheckBoxMenuItem( _label_direction_cbmi,
449 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
450 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
451 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
452 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
453 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
454 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
455 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
456 customizeJMenuItem( _cycle_node_shape_mi );
457 customizeJMenuItem( _cycle_node_fill_mi );
458 customizeJMenuItem( _choose_node_size_mi );
459 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
460 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
461 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
462 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
463 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
464 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
465 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
466 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
467 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
468 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
469 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
470 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
471 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
472 _jmenubar.add( _options_jmenu );
475 void buildToolsMenu() {
476 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
477 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
478 customizeJMenuItem( _confcolor_item );
479 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
480 customizeJMenuItem( _taxcolor_item );
481 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
482 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
483 customizeJMenuItem( _remove_branch_color_item );
484 _tools_menu.addSeparator();
485 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
486 customizeJMenuItem( _midpoint_root_item );
487 _tools_menu.addSeparator();
489 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
490 customizeJMenuItem( _infer_common_sn_names_item );
491 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
492 customizeJMenuItem( _collapse_species_specific_subtrees );
493 _jmenubar.add( _tools_menu );
496 void buildTypeMenu() {
497 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
498 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
499 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
500 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
501 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
502 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
503 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
504 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
505 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
506 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
507 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
508 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
509 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
510 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
511 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
512 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
513 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
514 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
515 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
516 initializeTypeMenu( getOptions() );
517 _jmenubar.add( _type_menu );
520 void buildViewMenu() {
521 _view_jmenu = MainFrame.createMenu( "View as Text", getConfiguration() );
522 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
523 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
524 _view_jmenu.add( _view_as_NHX_item = new JMenuItem( "View as NHX" ) );
525 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
526 customizeJMenuItem( _view_as_NH_item );
527 customizeJMenuItem( _view_as_NHX_item );
528 customizeJMenuItem( _view_as_XML_item );
529 customizeJMenuItem( _view_as_nexus_item );
530 _jmenubar.add( _view_jmenu );
533 private void chooseFont() {
534 final FontChooser fc = new FontChooser();
535 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
536 fc.showDialog( this, "Select the Base Font" );
537 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
540 private void chooseMinimalConfidence() {
541 final String s = ( String ) JOptionPane
542 .showInputDialog( this,
543 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
544 + getOptions().getMinConfidenceValue() + "]\n",
545 "Minimal Confidence Value",
546 JOptionPane.QUESTION_MESSAGE,
549 getOptions().getMinConfidenceValue() );
550 if ( !ForesterUtil.isEmpty( s ) ) {
551 boolean success = true;
553 final String m_str = s.trim();
554 if ( !ForesterUtil.isEmpty( m_str ) ) {
556 m = Double.parseDouble( m_str );
558 catch ( final Exception ex ) {
565 if ( success && ( m >= 0.0 ) ) {
566 getOptions().setMinConfidenceValue( m );
571 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
572 if ( item != null ) {
573 item.setFont( MainFrame.menu_font );
574 if ( !getConfiguration().isUseNativeUI() ) {
575 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
576 item.setForeground( getConfiguration().getGuiMenuTextColor() );
578 item.setSelected( is_selected );
579 item.addActionListener( this );
583 void customizeJMenuItem( final JMenuItem jmi ) {
584 jmi.setFont( MainFrame.menu_font );
585 if ( !getConfiguration().isUseNativeUI() ) {
586 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
587 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
589 jmi.addActionListener( this );
592 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
593 if ( item != null ) {
594 item.setFont( MainFrame.menu_font );
595 if ( !getConfiguration().isUseNativeUI() ) {
596 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
597 item.setForeground( getConfiguration().getGuiMenuTextColor() );
599 item.setSelected( is_selected );
600 item.addActionListener( this );
605 public void destroy() {
606 Util.printAppletMessage( NAME, "going to be destroyed " );
608 if ( getMainPanel() != null ) {
609 getMainPanel().terminate();
613 Configuration getConfiguration() {
614 return _configuration;
617 TreePanel getCurrentTreePanel() {
618 return getMainPanel().getCurrentTreePanel();
621 JCheckBoxMenuItem getlabelDirectionCbmi() {
622 return _label_direction_cbmi;
625 private MainPanel getMainPanel() {
629 public Options getOptions() {
633 Options getOtions() {
639 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
640 Util.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
641 final Configuration configuration = new Configuration( config_filename, true, true );
642 setConfiguration( configuration );
643 setOptions( Options.createInstance( configuration ) );
646 Phylogeny[] phys = null;
647 final String phys_url_string = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
648 Util.printAppletMessage( NAME, "URL for phylogenies is " + phys_url_string );
649 // Get URL to tree file
650 if ( phys_url_string != null ) {
652 phys_url = new URL( phys_url_string );
654 catch ( final Exception e ) {
655 ForesterUtil.printErrorMessage( NAME, "error: " + e );
657 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + phys_url_string
658 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
661 // Load the tree from URL
662 if ( phys_url != null ) {
664 phys = Util.readPhylogeniesFromUrl( phys_url, getConfiguration().isValidatePhyloXmlAgainstSchema() );
666 catch ( final Exception e ) {
667 ForesterUtil.printErrorMessage( NAME, e.toString() );
669 JOptionPane.showMessageDialog( this,
670 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
671 "Failed to read phylogenies",
672 JOptionPane.ERROR_MESSAGE );
675 if ( ( phys == null ) || ( phys.length < 1 ) ) {
676 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
677 JOptionPane.showMessageDialog( this,
678 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
679 "Failed to read phylogenies",
680 JOptionPane.ERROR_MESSAGE );
684 Util.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
687 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
688 _jmenubar = new JMenuBar();
689 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
690 if ( !getConfiguration().isUseNativeUI() ) {
691 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
699 setJMenuBar( _jmenubar );
701 final Container contentpane = getContentPane();
702 contentpane.setLayout( new BorderLayout() );
703 contentpane.add( getMainPanel(), BorderLayout.CENTER );
704 addComponentListener( new ComponentAdapter() {
707 public void componentResized( final ComponentEvent e ) {
708 if ( getMainPanel().getCurrentTreePanel() != null ) {
709 getMainPanel().getCurrentTreePanel().setParametersForPainting( getMainPanel().getCurrentTreePanel()
711 getMainPanel().getCurrentTreePanel()
717 if ( getConfiguration().isUseTabbedDisplay() ) {
718 Util.printAppletMessage( NAME, "using tabbed display" );
719 Util.addPhylogeniesToTabs( phys,
720 new File( phys_url.getFile() ).getName(),
726 Util.printAppletMessage( NAME, "not using tabbed display" );
727 Util.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
731 getMainPanel().getControlPanel().showWholeAll();
732 getMainPanel().getControlPanel().showWhole();
734 Util.printAppletMessage( NAME, "successfully initialized" );
736 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
737 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
738 .getRelevantSequenceRelationTypes() ) {
739 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
741 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
742 if ( default_relation != null ) {
743 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
745 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
746 if ( default_sequence != null ) {
747 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
753 void initializeTypeMenu( final Options options ) {
754 setTypeMenuToAllUnselected();
756 switch ( options.getPhylogenyGraphicsType() ) {
758 _convex_type_cbmi.setSelected( true );
761 _curved_type_cbmi.setSelected( true );
764 _euro_type_cbmi.setSelected( true );
767 _rounded_type_cbmi.setSelected( true );
770 _triangular_type_cbmi.setSelected( true );
773 _unrooted_type_cbmi.setSelected( true );
776 _circular_type_cbmi.setSelected( true );
779 _rectangular_type_cbmi.setSelected( true );
783 catch ( final NullPointerException np ) {
784 // In all likelihood, this is caused by menu-less display.
788 private boolean isScreenAntialias() {
792 private void removeBranchColors() {
793 if ( getMainPanel().getCurrentPhylogeny() != null ) {
794 Util.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
798 void removeTextFrame() {
799 if ( _textframe != null ) {
805 void setConfiguration( final Configuration configuration ) {
806 _configuration = configuration;
809 private void setMainPanel( final MainPanelApplets main_panel ) {
810 _main_panel = main_panel;
813 void setOptions( final Options options ) {
817 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
818 setTypeMenuToAllUnselected();
822 _circular_type_cbmi.setSelected( true );
825 _convex_type_cbmi.setSelected( true );
828 _curved_type_cbmi.setSelected( true );
831 _euro_type_cbmi.setSelected( true );
834 _rounded_type_cbmi.setSelected( true );
837 _rectangular_type_cbmi.setSelected( true );
840 _triangular_type_cbmi.setSelected( true );
843 _unrooted_type_cbmi.setSelected( true );
846 throw new IllegalArgumentException( "unknown type: " + type );
849 catch ( final NullPointerException np ) {
850 // In all likelihood, this is caused by menu-less display.
854 void setTypeMenuToAllUnselected() {
855 if ( _convex_type_cbmi != null ) {
856 _convex_type_cbmi.setSelected( false );
858 if ( _curved_type_cbmi != null ) {
859 _curved_type_cbmi.setSelected( false );
861 if ( _euro_type_cbmi != null ) {
862 _euro_type_cbmi.setSelected( false );
864 if ( _rounded_type_cbmi != null ) {
865 _rounded_type_cbmi.setSelected( false );
867 if ( _triangular_type_cbmi != null ) {
868 _triangular_type_cbmi.setSelected( false );
870 if ( _rectangular_type_cbmi != null ) {
871 _rectangular_type_cbmi.setSelected( false );
873 if ( _unrooted_type_cbmi != null ) {
874 _unrooted_type_cbmi.setSelected( false );
876 if ( _circular_type_cbmi != null ) {
877 _circular_type_cbmi.setSelected( false );
881 private void setupUI() {
883 if ( getConfiguration().isUseNativeUI() ) {
884 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
887 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
890 catch ( final UnsupportedLookAndFeelException e ) {
891 Util.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
893 catch ( final ClassNotFoundException e ) {
894 Util.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
896 catch ( final InstantiationException e ) {
897 Util.dieWithSystemError( "InstantiationException: " + e.toString() );
899 catch ( final IllegalAccessException e ) {
900 Util.dieWithSystemError( "IllegalAccessException: " + e.toString() );
902 catch ( final Exception e ) {
903 Util.dieWithSystemError( e.toString() );
908 public void start() {
909 if ( getMainPanel() != null ) {
910 getMainPanel().validate();
913 requestFocusInWindow();
915 Util.printAppletMessage( NAME, "started" );
918 void switchColors() {
919 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
920 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
921 csc.setVisible( true );
922 getMainPanel().setTreeColorSet( colorset );
925 void typeChanged( final Object o ) {
926 updateTypeCheckboxes( getOptions(), o );
927 updateOptions( getOptions() );
928 if ( getCurrentTreePanel() != null ) {
929 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
930 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
931 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
932 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
933 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
934 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
935 getCurrentTreePanel().getControlPanel().showWhole();
937 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
938 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
941 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
943 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
944 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
948 void updateOptions( final Options options ) {
949 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
950 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
951 && _background_gradient_cbmi.isSelected() );
952 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
953 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
954 && _abbreviate_scientific_names.isSelected() );
955 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
956 && _color_labels_same_as_parent_branch.isSelected() );
957 options.setShowDefaultNodeShapes( ( _show_default_node_shapes_cbmi != null )
958 && _show_default_node_shapes_cbmi.isSelected() );
959 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
960 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
961 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
962 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
964 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
965 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
967 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
968 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
970 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
971 && _search_case_senstive_cbmi.isSelected() );
972 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
973 options.setShowScale( _show_scale_cbmi.isSelected() );
975 if ( _label_direction_cbmi != null ) {
976 if ( _label_direction_cbmi.isSelected() ) {
977 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
980 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
983 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
984 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
985 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
987 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
988 && _search_whole_words_only_cbmi.isSelected() );
989 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
990 && _inverse_search_result_cbmi.isSelected() );
991 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
992 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
994 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
995 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
997 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
998 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1000 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1001 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1003 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1004 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1006 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1007 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1009 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1010 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1012 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1013 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1017 void updateTypeCheckboxes( final Options options, final Object o ) {
1018 setTypeMenuToAllUnselected();
1019 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1022 void viewAsNexus() {
1024 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1025 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1028 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNexus() );
1033 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1034 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1037 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshire( false ) );
1042 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1043 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1046 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshireX() );
1051 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1052 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1055 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ) );
1058 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1059 for( final TreePanel tree_panel : treepanels ) {
1060 tree_panel.setTextAntialias();