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;
36 // <applet archive="forester.jar"
37 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
38 // codebase="http://www.myserver.org/path/to/forester"
41 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
42 // <param name="url_of_tree_to_load"
43 // value="http://www.myserver.org/examples/data/apaf.xml">
44 // <param name="config_file"
45 // value="http://www.myserver.org/examples/config/config_file.txt">
47 public class ArchaeopteryxE extends JApplet implements ActionListener {
49 private final static String NAME = "ArchaeopteryxE";
50 private static final long serialVersionUID = -1220055577935759443L;
51 private Configuration _configuration;
52 private MainPanelApplets _main_panel;
53 private JMenuBar _jmenubar;
54 private JMenu _options_jmenu;
55 private JMenu _font_size_menu;
56 private JMenuItem _super_tiny_fonts_mi;
57 private JMenuItem _tiny_fonts_mi;
58 private JMenuItem _small_fonts_mi;
59 private JMenuItem _medium_fonts_mi;
60 private JMenuItem _large_fonts_mi;
61 private TextFrame _textframe;
62 private JMenu _tools_menu;
63 private JMenuItem _taxcolor_item;
64 private JMenuItem _confcolor_item;
65 private JMenuItem _midpoint_root_item;
66 private JMenu _view_jmenu;
67 private JMenuItem _view_as_XML_item;
68 private JMenuItem _view_as_NH_item;
69 private JMenuItem _view_as_NHX_item;
70 private JMenuItem _view_as_nexus_item;
71 private JMenu _type_menu;
72 private JCheckBoxMenuItem _rectangular_type_cbmi;
73 private JCheckBoxMenuItem _triangular_type_cbmi;
74 private JCheckBoxMenuItem _curved_type_cbmi;
75 private JCheckBoxMenuItem _convex_type_cbmi;
76 private JCheckBoxMenuItem _euro_type_cbmi;
77 private JCheckBoxMenuItem _rounded_type_cbmi;
78 private JCheckBoxMenuItem _unrooted_type_cbmi;
79 private JCheckBoxMenuItem _circular_type_cbmi;
80 private JMenuItem _help_item;
81 private JMenuItem _about_item;
82 private JMenu _help_jmenu;
83 private JMenuItem _website_item;
84 private JMenuItem _phyloxml_website_item;
85 private JMenuItem _phyloxml_ref_item;
86 private JMenuItem _aptx_ref_item;
87 private JMenuItem _remove_branch_color_item;
88 private JMenuItem _infer_common_sn_names_item;
89 private JCheckBoxMenuItem _show_domain_labels;
90 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
91 private JCheckBoxMenuItem _abbreviate_scientific_names;
92 private JCheckBoxMenuItem _screen_antialias_cbmi;
93 private JCheckBoxMenuItem _background_gradient_cbmi;
94 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
95 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
96 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
97 private Options _options;
98 private JMenuItem _choose_font_mi;
99 private JMenuItem _switch_colors_mi;
100 JCheckBoxMenuItem _label_direction_cbmi;
101 private JCheckBoxMenuItem _show_scale_cbmi;
102 private JCheckBoxMenuItem _search_case_senstive_cbmi;
103 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
104 private JCheckBoxMenuItem _inverse_search_result_cbmi;
105 private JCheckBoxMenuItem _show_overview_cbmi;
106 private JMenuItem _choose_minimal_confidence_mi;
107 private JCheckBoxMenuItem _show_branch_length_values_cbmi;
108 private JMenuItem _collapse_species_specific_subtrees;
109 private JMenuItem _overview_placment_mi;
110 private ButtonGroup _radio_group_1;
111 private JCheckBoxMenuItem _show_default_node_shapes_cbmi;
112 private JMenuItem _cycle_node_shape_mi;
113 private JMenuItem _cycle_node_fill_mi;
114 private JMenuItem _choose_node_size_mi;
115 private JCheckBoxMenuItem _taxonomy_colorize_node_shapes_cbmi;
118 public void actionPerformed( final ActionEvent e ) {
119 final Object o = e.getSource();
120 if ( o == _midpoint_root_item ) {
121 getMainPanel().getCurrentTreePanel().midpointRoot();
123 else if ( o == _taxcolor_item ) {
124 getMainPanel().getCurrentTreePanel().taxColor();
126 else if ( o == _confcolor_item ) {
127 getMainPanel().getCurrentTreePanel().confColor();
129 else if ( o == _infer_common_sn_names_item ) {
130 if ( getCurrentTreePanel() != null ) {
131 getCurrentTreePanel().inferCommonPartOfScientificNames();
134 else if ( o == _collapse_species_specific_subtrees ) {
135 if ( getCurrentTreePanel() != null ) {
136 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
139 else if ( o == _remove_branch_color_item ) {
140 removeBranchColors();
142 else if ( o == _switch_colors_mi ) {
145 else if ( o == _view_as_NH_item ) {
148 else if ( o == _view_as_NHX_item ) {
151 else if ( o == _view_as_XML_item ) {
154 else if ( o == _view_as_nexus_item ) {
157 else if ( o == _super_tiny_fonts_mi ) {
158 if ( getCurrentTreePanel() != null ) {
159 getCurrentTreePanel().setSuperTinyFonts();
160 getCurrentTreePanel().repaint();
163 else if ( o == _tiny_fonts_mi ) {
164 if ( getCurrentTreePanel() != null ) {
165 getCurrentTreePanel().setTinyFonts();
166 getCurrentTreePanel().repaint();
169 else if ( o == _small_fonts_mi ) {
170 if ( getCurrentTreePanel() != null ) {
171 getCurrentTreePanel().setSmallFonts();
172 getCurrentTreePanel().repaint();
175 else if ( o == _medium_fonts_mi ) {
176 if ( getCurrentTreePanel() != null ) {
177 getCurrentTreePanel().setMediumFonts();
178 getCurrentTreePanel().repaint();
181 else if ( o == _large_fonts_mi ) {
182 if ( getCurrentTreePanel() != null ) {
183 getCurrentTreePanel().setLargeFonts();
184 getCurrentTreePanel().repaint();
187 else if ( o == _choose_font_mi ) {
190 else if ( o == _choose_minimal_confidence_mi ) {
191 chooseMinimalConfidence();
193 else if ( o == _choose_node_size_mi ) {
194 MainFrame.chooseNodeSize( getOptions(), this );
196 else if ( o == _overview_placment_mi ) {
197 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
199 else if ( o == _cycle_node_fill_mi ) {
200 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
202 else if ( o == _cycle_node_shape_mi ) {
203 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
205 else if ( o == _non_lined_up_cladograms_rbmi ) {
206 updateOptions( getOptions() );
207 _main_panel.getControlPanel().showWhole();
209 else if ( o == _uniform_cladograms_rbmi ) {
210 updateOptions( getOptions() );
211 _main_panel.getControlPanel().showWhole();
213 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
214 updateOptions( getOptions() );
215 _main_panel.getControlPanel().showWhole();
217 else if ( o == _search_case_senstive_cbmi ) {
218 updateOptions( getOptions() );
219 getMainPanel().getControlPanel().search();
221 else if ( o == _search_whole_words_only_cbmi ) {
222 updateOptions( getOptions() );
223 getMainPanel().getControlPanel().search();
225 else if ( o == _inverse_search_result_cbmi ) {
226 updateOptions( getOptions() );
227 getMainPanel().getControlPanel().search();
229 else if ( o == _show_scale_cbmi ) {
230 updateOptions( getOptions() );
232 else if ( o == _show_branch_length_values_cbmi ) {
233 updateOptions( getOptions() );
235 else if ( o == _label_direction_cbmi ) {
236 updateOptions( getOptions() );
238 else if ( o == _show_overview_cbmi ) {
239 updateOptions( getOptions() );
240 if ( getCurrentTreePanel() != null ) {
241 getCurrentTreePanel().updateOvSizes();
244 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
245 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
246 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
249 else if ( o == _screen_antialias_cbmi ) {
250 updateOptions( getOptions() );
251 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
253 else if ( o == _background_gradient_cbmi ) {
254 updateOptions( getOptions() );
256 else if ( o == _show_domain_labels ) {
257 updateOptions( getOptions() );
259 else if ( o == _color_labels_same_as_parent_branch ) {
260 updateOptions( getOptions() );
262 else if ( o == _show_default_node_shapes_cbmi ) {
263 updateOptions( getOptions() );
265 else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
266 updateOptions( getOptions() );
268 else if ( o == _about_item ) {
271 else if ( o == _help_item ) {
272 MainFrame.help( getConfiguration().getWebLinks() );
274 else if ( o == _website_item ) {
276 Util.openWebsite( Constants.APTX_WEB_SITE, true, this );
278 catch ( final IOException e1 ) {
279 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
282 else if ( o == _phyloxml_website_item ) {
284 Util.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
286 catch ( final IOException e1 ) {
287 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
290 else if ( o == _aptx_ref_item ) {
292 Util.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
294 catch ( final IOException e1 ) {
295 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
298 else if ( o == _phyloxml_ref_item ) {
300 Util.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
302 catch ( final IOException e1 ) {
303 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
309 void buildFontSizeMenu() {
310 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
311 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
312 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
313 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
314 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
315 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
316 customizeJMenuItem( _super_tiny_fonts_mi );
317 customizeJMenuItem( _tiny_fonts_mi );
318 customizeJMenuItem( _small_fonts_mi );
319 customizeJMenuItem( _medium_fonts_mi );
320 customizeJMenuItem( _large_fonts_mi );
321 _jmenubar.add( _font_size_menu );
324 void buildHelpMenu() {
325 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
326 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
327 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
328 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
329 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
330 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
331 _help_jmenu.addSeparator();
332 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
333 customizeJMenuItem( _help_item );
334 customizeJMenuItem( _website_item );
335 customizeJMenuItem( _phyloxml_website_item );
336 customizeJMenuItem( _aptx_ref_item );
337 customizeJMenuItem( _phyloxml_ref_item );
338 customizeJMenuItem( _about_item );
339 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
340 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
341 _jmenubar.add( _help_jmenu );
344 void buildOptionsMenu() {
345 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
346 _options_jmenu.addChangeListener( new ChangeListener() {
349 public void stateChanged( final ChangeEvent e ) {
350 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
351 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
353 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
354 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
355 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
356 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
358 _show_branch_length_values_cbmi,
359 _non_lined_up_cladograms_rbmi,
360 _uniform_cladograms_rbmi,
361 _ext_node_dependent_cladogram_rbmi,
362 _label_direction_cbmi );
363 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
364 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
365 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
368 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
369 getConfiguration() ) );
371 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
372 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
374 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
375 _radio_group_1 = new ButtonGroup();
376 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
377 _radio_group_1.add( _uniform_cladograms_rbmi );
378 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
381 .add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL ) );
383 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
384 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
385 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
386 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
388 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
390 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
391 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
392 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
394 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
395 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
396 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
397 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
398 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
399 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
400 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
401 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
403 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
404 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
405 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
406 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
407 _options_jmenu.addSeparator();
408 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
409 getConfiguration() ) );
411 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
412 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
414 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
415 customizeJMenuItem( _choose_font_mi );
416 customizeJMenuItem( _choose_minimal_confidence_mi );
417 customizeJMenuItem( _switch_colors_mi );
418 customizeJMenuItem( _overview_placment_mi );
419 customizeCheckBoxMenuItem( _label_direction_cbmi,
420 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
421 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
422 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
423 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
424 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
425 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
426 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
427 customizeJMenuItem( _cycle_node_shape_mi );
428 customizeJMenuItem( _cycle_node_fill_mi );
429 customizeJMenuItem( _choose_node_size_mi );
430 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
431 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
432 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
433 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
434 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
435 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
436 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
437 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
438 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
439 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
440 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
441 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
442 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
443 _jmenubar.add( _options_jmenu );
446 void buildToolsMenu() {
447 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
448 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
449 customizeJMenuItem( _confcolor_item );
450 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
451 customizeJMenuItem( _taxcolor_item );
452 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
453 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
454 customizeJMenuItem( _remove_branch_color_item );
455 _tools_menu.addSeparator();
456 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
457 customizeJMenuItem( _midpoint_root_item );
458 _tools_menu.addSeparator();
460 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
461 customizeJMenuItem( _infer_common_sn_names_item );
462 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
463 customizeJMenuItem( _collapse_species_specific_subtrees );
464 _jmenubar.add( _tools_menu );
467 void buildTypeMenu() {
468 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
469 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
470 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
471 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
472 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
473 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
474 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
475 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
476 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
477 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
478 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
479 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
480 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
481 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
482 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
483 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
484 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
485 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
486 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
487 initializeTypeMenu( getOptions() );
488 _jmenubar.add( _type_menu );
491 void buildViewMenu() {
492 _view_jmenu = MainFrame.createMenu( "View as Text", getConfiguration() );
493 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
494 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
495 _view_jmenu.add( _view_as_NHX_item = new JMenuItem( "View as NHX" ) );
496 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
497 customizeJMenuItem( _view_as_NH_item );
498 customizeJMenuItem( _view_as_NHX_item );
499 customizeJMenuItem( _view_as_XML_item );
500 customizeJMenuItem( _view_as_nexus_item );
501 _jmenubar.add( _view_jmenu );
504 private void chooseFont() {
505 final FontChooser fc = new FontChooser();
506 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
507 fc.showDialog( this, "Select the Base Font" );
508 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
511 private void chooseMinimalConfidence() {
512 final String s = ( String ) JOptionPane
513 .showInputDialog( this,
514 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
515 + getOptions().getMinConfidenceValue() + "]\n",
516 "Minimal Confidence Value",
517 JOptionPane.QUESTION_MESSAGE,
520 getOptions().getMinConfidenceValue() );
521 if ( !ForesterUtil.isEmpty( s ) ) {
522 boolean success = true;
524 final String m_str = s.trim();
525 if ( !ForesterUtil.isEmpty( m_str ) ) {
527 m = Double.parseDouble( m_str );
529 catch ( final Exception ex ) {
536 if ( success && ( m >= 0.0 ) ) {
537 getOptions().setMinConfidenceValue( m );
542 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
543 if ( item != null ) {
544 item.setFont( MainFrame.menu_font );
545 if ( !getConfiguration().isUseNativeUI() ) {
546 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
547 item.setForeground( getConfiguration().getGuiMenuTextColor() );
549 item.setSelected( is_selected );
550 item.addActionListener( this );
554 void customizeJMenuItem( final JMenuItem jmi ) {
555 jmi.setFont( MainFrame.menu_font );
556 if ( !getConfiguration().isUseNativeUI() ) {
557 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
558 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
560 jmi.addActionListener( this );
563 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
564 if ( item != null ) {
565 item.setFont( MainFrame.menu_font );
566 if ( !getConfiguration().isUseNativeUI() ) {
567 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
568 item.setForeground( getConfiguration().getGuiMenuTextColor() );
570 item.setSelected( is_selected );
571 item.addActionListener( this );
576 public void destroy() {
577 Util.printAppletMessage( NAME, "going to be destroyed " );
579 if ( getMainPanel() != null ) {
580 getMainPanel().terminate();
584 Configuration getConfiguration() {
585 return _configuration;
588 TreePanel getCurrentTreePanel() {
589 return getMainPanel().getCurrentTreePanel();
592 JCheckBoxMenuItem getlabelDirectionCbmi() {
593 return _label_direction_cbmi;
596 private MainPanel getMainPanel() {
600 public Options getOptions() {
604 Options getOtions() {
610 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
611 Util.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
612 final Configuration configuration = new Configuration( config_filename, true, true );
613 setConfiguration( configuration );
614 setOptions( Options.createInstance( configuration ) );
617 Phylogeny[] phys = null;
618 final String phys_url_string = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
619 Util.printAppletMessage( NAME, "URL for phylogenies is " + phys_url_string );
620 // Get URL to tree file
621 if ( phys_url_string != null ) {
623 phys_url = new URL( phys_url_string );
625 catch ( final Exception e ) {
626 ForesterUtil.printErrorMessage( NAME, "error: " + e );
628 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + phys_url_string
629 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
632 // Load the tree from URL
633 if ( phys_url != null ) {
635 phys = Util.readPhylogeniesFromUrl( phys_url, getConfiguration().isValidatePhyloXmlAgainstSchema() );
637 catch ( final Exception e ) {
638 ForesterUtil.printErrorMessage( NAME, e.toString() );
640 JOptionPane.showMessageDialog( this,
641 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
642 "Failed to read phylogenies",
643 JOptionPane.ERROR_MESSAGE );
646 if ( ( phys == null ) || ( phys.length < 1 ) ) {
647 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
648 JOptionPane.showMessageDialog( this,
649 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
650 "Failed to read phylogenies",
651 JOptionPane.ERROR_MESSAGE );
655 Util.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
658 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
659 _jmenubar = new JMenuBar();
660 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
661 if ( !getConfiguration().isUseNativeUI() ) {
662 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
670 setJMenuBar( _jmenubar );
672 final Container contentpane = getContentPane();
673 contentpane.setLayout( new BorderLayout() );
674 contentpane.add( getMainPanel(), BorderLayout.CENTER );
675 addComponentListener( new ComponentAdapter() {
678 public void componentResized( final ComponentEvent e ) {
679 if ( getMainPanel().getCurrentTreePanel() != null ) {
680 getMainPanel().getCurrentTreePanel().setParametersForPainting( getMainPanel().getCurrentTreePanel()
682 getMainPanel().getCurrentTreePanel()
688 if ( getConfiguration().isUseTabbedDisplay() ) {
689 Util.printAppletMessage( NAME, "using tabbed display" );
690 Util.addPhylogeniesToTabs( phys,
691 new File( phys_url.getFile() ).getName(),
697 Util.printAppletMessage( NAME, "not using tabbed display" );
698 Util.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
702 getMainPanel().getControlPanel().showWholeAll();
703 getMainPanel().getControlPanel().showWhole();
705 Util.printAppletMessage( NAME, "successfully initialized" );
707 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
708 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
709 .getRelevantSequenceRelationTypes() ) {
710 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
712 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
713 if ( default_relation != null ) {
714 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
716 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
717 if ( default_sequence != null ) {
718 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
724 void initializeTypeMenu( final Options options ) {
725 setTypeMenuToAllUnselected();
727 switch ( options.getPhylogenyGraphicsType() ) {
729 _convex_type_cbmi.setSelected( true );
732 _curved_type_cbmi.setSelected( true );
735 _euro_type_cbmi.setSelected( true );
738 _rounded_type_cbmi.setSelected( true );
741 _triangular_type_cbmi.setSelected( true );
744 _unrooted_type_cbmi.setSelected( true );
747 _circular_type_cbmi.setSelected( true );
750 _rectangular_type_cbmi.setSelected( true );
754 catch ( final NullPointerException np ) {
755 // In all likelihood, this is caused by menu-less display.
759 private boolean isScreenAntialias() {
763 private void removeBranchColors() {
764 if ( getMainPanel().getCurrentPhylogeny() != null ) {
765 Util.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
769 void removeTextFrame() {
770 if ( _textframe != null ) {
776 void setConfiguration( final Configuration configuration ) {
777 _configuration = configuration;
780 private void setMainPanel( final MainPanelApplets main_panel ) {
781 _main_panel = main_panel;
784 void setOptions( final Options options ) {
788 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
789 setTypeMenuToAllUnselected();
793 _circular_type_cbmi.setSelected( true );
796 _convex_type_cbmi.setSelected( true );
799 _curved_type_cbmi.setSelected( true );
802 _euro_type_cbmi.setSelected( true );
805 _rounded_type_cbmi.setSelected( true );
808 _rectangular_type_cbmi.setSelected( true );
811 _triangular_type_cbmi.setSelected( true );
814 _unrooted_type_cbmi.setSelected( true );
817 throw new IllegalArgumentException( "unknown type: " + type );
820 catch ( final NullPointerException np ) {
821 // In all likelihood, this is caused by menu-less display.
825 void setTypeMenuToAllUnselected() {
826 if ( _convex_type_cbmi != null ) {
827 _convex_type_cbmi.setSelected( false );
829 if ( _curved_type_cbmi != null ) {
830 _curved_type_cbmi.setSelected( false );
832 if ( _euro_type_cbmi != null ) {
833 _euro_type_cbmi.setSelected( false );
835 if ( _rounded_type_cbmi != null ) {
836 _rounded_type_cbmi.setSelected( false );
838 if ( _triangular_type_cbmi != null ) {
839 _triangular_type_cbmi.setSelected( false );
841 if ( _rectangular_type_cbmi != null ) {
842 _rectangular_type_cbmi.setSelected( false );
844 if ( _unrooted_type_cbmi != null ) {
845 _unrooted_type_cbmi.setSelected( false );
847 if ( _circular_type_cbmi != null ) {
848 _circular_type_cbmi.setSelected( false );
852 private void setupUI() {
854 if ( getConfiguration().isUseNativeUI() ) {
855 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
858 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
861 catch ( final UnsupportedLookAndFeelException e ) {
862 Util.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
864 catch ( final ClassNotFoundException e ) {
865 Util.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
867 catch ( final InstantiationException e ) {
868 Util.dieWithSystemError( "InstantiationException: " + e.toString() );
870 catch ( final IllegalAccessException e ) {
871 Util.dieWithSystemError( "IllegalAccessException: " + e.toString() );
873 catch ( final Exception e ) {
874 Util.dieWithSystemError( e.toString() );
879 public void start() {
880 if ( getMainPanel() != null ) {
881 getMainPanel().validate();
884 requestFocusInWindow();
886 Util.printAppletMessage( NAME, "started" );
889 void switchColors() {
890 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
891 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
892 csc.setVisible( true );
893 getMainPanel().setTreeColorSet( colorset );
896 void typeChanged( final Object o ) {
897 updateTypeCheckboxes( getOptions(), o );
898 updateOptions( getOptions() );
899 if ( getCurrentTreePanel() != null ) {
900 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
901 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
902 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
903 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
904 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
905 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
906 getCurrentTreePanel().getControlPanel().showWhole();
908 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
909 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
912 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
914 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
915 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
919 void updateOptions( final Options options ) {
920 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
921 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
922 && _background_gradient_cbmi.isSelected() );
923 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
924 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
925 && _abbreviate_scientific_names.isSelected() );
926 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
927 && _color_labels_same_as_parent_branch.isSelected() );
928 options.setShowDefaultNodeShapes( ( _show_default_node_shapes_cbmi != null )
929 && _show_default_node_shapes_cbmi.isSelected() );
930 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
931 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
932 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
933 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
935 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
936 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
938 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
939 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
941 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
942 && _search_case_senstive_cbmi.isSelected() );
943 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
944 options.setShowScale( _show_scale_cbmi.isSelected() );
946 if ( _label_direction_cbmi != null ) {
947 if ( _label_direction_cbmi.isSelected() ) {
948 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
951 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
954 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
955 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
956 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
958 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
959 && _search_whole_words_only_cbmi.isSelected() );
960 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
961 && _inverse_search_result_cbmi.isSelected() );
962 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
963 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
965 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
966 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
968 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
969 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
971 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
972 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
974 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
975 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
977 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
978 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
980 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
981 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
983 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
984 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
988 void updateTypeCheckboxes( final Options options, final Object o ) {
989 setTypeMenuToAllUnselected();
990 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
995 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
996 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
999 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNexus() );
1004 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1005 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1008 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshire( false ) );
1013 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1014 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1017 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshireX() );
1022 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
1023 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1026 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ) );
1029 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1030 for( final TreePanel tree_panel : treepanels ) {
1031 tree_panel.setTextAntialias();