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_node_boxes_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;
114 public void actionPerformed( final ActionEvent e ) {
115 final Object o = e.getSource();
116 if ( o == _midpoint_root_item ) {
117 getMainPanel().getCurrentTreePanel().midpointRoot();
119 else if ( o == _taxcolor_item ) {
120 getMainPanel().getCurrentTreePanel().taxColor();
122 else if ( o == _confcolor_item ) {
123 getMainPanel().getCurrentTreePanel().confColor();
125 else if ( o == _infer_common_sn_names_item ) {
126 if ( getCurrentTreePanel() != null ) {
127 getCurrentTreePanel().inferCommonPartOfScientificNames();
130 else if ( o == _collapse_species_specific_subtrees ) {
131 if ( getCurrentTreePanel() != null ) {
132 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
135 else if ( o == _remove_branch_color_item ) {
136 removeBranchColors();
138 else if ( o == _switch_colors_mi ) {
141 else if ( o == _view_as_NH_item ) {
144 else if ( o == _view_as_NHX_item ) {
147 else if ( o == _view_as_XML_item ) {
150 else if ( o == _view_as_nexus_item ) {
153 else if ( o == _super_tiny_fonts_mi ) {
154 if ( getCurrentTreePanel() != null ) {
155 getCurrentTreePanel().setSuperTinyFonts();
156 getCurrentTreePanel().repaint();
159 else if ( o == _tiny_fonts_mi ) {
160 if ( getCurrentTreePanel() != null ) {
161 getCurrentTreePanel().setTinyFonts();
162 getCurrentTreePanel().repaint();
165 else if ( o == _small_fonts_mi ) {
166 if ( getCurrentTreePanel() != null ) {
167 getCurrentTreePanel().setSmallFonts();
168 getCurrentTreePanel().repaint();
171 else if ( o == _medium_fonts_mi ) {
172 if ( getCurrentTreePanel() != null ) {
173 getCurrentTreePanel().setMediumFonts();
174 getCurrentTreePanel().repaint();
177 else if ( o == _large_fonts_mi ) {
178 if ( getCurrentTreePanel() != null ) {
179 getCurrentTreePanel().setLargeFonts();
180 getCurrentTreePanel().repaint();
183 else if ( o == _choose_font_mi ) {
186 else if ( o == _choose_minimal_confidence_mi ) {
187 chooseMinimalConfidence();
189 else if ( o == _overview_placment_mi ) {
190 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
192 else if ( o == _show_node_boxes_cbmi ) {
193 updateOptions( getOptions() );
195 else if ( o == _non_lined_up_cladograms_rbmi ) {
196 updateOptions( getOptions() );
197 _main_panel.getControlPanel().showWhole();
199 else if ( o == _uniform_cladograms_rbmi ) {
200 updateOptions( getOptions() );
201 _main_panel.getControlPanel().showWhole();
203 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
204 updateOptions( getOptions() );
205 _main_panel.getControlPanel().showWhole();
207 else if ( o == _search_case_senstive_cbmi ) {
208 updateOptions( getOptions() );
209 getMainPanel().getControlPanel().search();
211 else if ( o == _search_whole_words_only_cbmi ) {
212 updateOptions( getOptions() );
213 getMainPanel().getControlPanel().search();
215 else if ( o == _inverse_search_result_cbmi ) {
216 updateOptions( getOptions() );
217 getMainPanel().getControlPanel().search();
219 else if ( o == _show_scale_cbmi ) {
220 updateOptions( getOptions() );
222 else if ( o == _show_branch_length_values_cbmi ) {
223 updateOptions( getOptions() );
225 else if ( o == _label_direction_cbmi ) {
226 updateOptions( getOptions() );
228 else if ( o == _show_overview_cbmi ) {
229 updateOptions( getOptions() );
230 if ( getCurrentTreePanel() != null ) {
231 getCurrentTreePanel().updateOvSizes();
234 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
235 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
236 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
239 else if ( o == _screen_antialias_cbmi ) {
240 updateOptions( getOptions() );
241 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
243 else if ( o == _background_gradient_cbmi ) {
244 updateOptions( getOptions() );
246 else if ( o == _show_domain_labels ) {
247 updateOptions( getOptions() );
249 else if ( o == _color_labels_same_as_parent_branch ) {
250 updateOptions( getOptions() );
252 else if ( o == _about_item ) {
255 else if ( o == _help_item ) {
256 MainFrame.help( getConfiguration().getWebLinks() );
258 else if ( o == _website_item ) {
260 Util.openWebsite( Constants.APTX_WEB_SITE, true, this );
262 catch ( final IOException e1 ) {
263 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
266 else if ( o == _phyloxml_website_item ) {
268 Util.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
270 catch ( final IOException e1 ) {
271 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
274 else if ( o == _aptx_ref_item ) {
276 Util.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
278 catch ( final IOException e1 ) {
279 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
282 else if ( o == _phyloxml_ref_item ) {
284 Util.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
286 catch ( final IOException e1 ) {
287 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
293 void buildFontSizeMenu() {
294 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
295 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
296 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
297 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
298 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
299 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
300 customizeJMenuItem( _super_tiny_fonts_mi );
301 customizeJMenuItem( _tiny_fonts_mi );
302 customizeJMenuItem( _small_fonts_mi );
303 customizeJMenuItem( _medium_fonts_mi );
304 customizeJMenuItem( _large_fonts_mi );
305 _jmenubar.add( _font_size_menu );
308 void buildHelpMenu() {
309 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
310 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
311 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
312 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
313 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
314 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
315 _help_jmenu.addSeparator();
316 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
317 customizeJMenuItem( _help_item );
318 customizeJMenuItem( _website_item );
319 customizeJMenuItem( _phyloxml_website_item );
320 customizeJMenuItem( _aptx_ref_item );
321 customizeJMenuItem( _phyloxml_ref_item );
322 customizeJMenuItem( _about_item );
323 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
324 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
325 _jmenubar.add( _help_jmenu );
328 void buildOptionsMenu() {
329 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
330 _options_jmenu.addChangeListener( new ChangeListener() {
333 public void stateChanged( final ChangeEvent e ) {
334 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getCurrentTreePanel() );
335 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
337 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
338 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
339 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
340 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
342 _show_branch_length_values_cbmi,
343 _non_lined_up_cladograms_rbmi,
344 _uniform_cladograms_rbmi,
345 _ext_node_dependent_cladogram_rbmi,
346 _label_direction_cbmi );
349 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
350 getConfiguration() ) );
352 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
353 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
355 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
356 _radio_group_1 = new ButtonGroup();
357 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
358 _radio_group_1.add( _uniform_cladograms_rbmi );
359 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
360 _options_jmenu.add( _show_node_boxes_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL ) );
361 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
363 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
364 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
365 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
367 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
368 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
369 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
370 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
371 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
372 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
373 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
374 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
376 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
377 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
378 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
379 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
380 _options_jmenu.addSeparator();
381 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
382 getConfiguration() ) );
384 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
385 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
387 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
388 customizeJMenuItem( _choose_font_mi );
389 customizeJMenuItem( _choose_minimal_confidence_mi );
390 customizeJMenuItem( _switch_colors_mi );
391 customizeJMenuItem( _overview_placment_mi );
392 customizeCheckBoxMenuItem( _show_node_boxes_cbmi, getOptions().getDefaultNodeShape() );
393 customizeCheckBoxMenuItem( _label_direction_cbmi,
394 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
395 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
396 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
397 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
398 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
399 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
400 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
401 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
402 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
403 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
404 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
405 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
406 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
407 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
408 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
409 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
410 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
411 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
412 _jmenubar.add( _options_jmenu );
415 void buildToolsMenu() {
416 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
417 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
418 customizeJMenuItem( _confcolor_item );
419 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
420 customizeJMenuItem( _taxcolor_item );
421 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
422 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
423 customizeJMenuItem( _remove_branch_color_item );
424 _tools_menu.addSeparator();
425 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
426 customizeJMenuItem( _midpoint_root_item );
427 _tools_menu.addSeparator();
429 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
430 customizeJMenuItem( _infer_common_sn_names_item );
431 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
432 customizeJMenuItem( _collapse_species_specific_subtrees );
433 _jmenubar.add( _tools_menu );
436 void buildTypeMenu() {
437 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
438 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
439 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
440 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
441 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
442 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
443 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
444 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
445 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
446 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
447 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
448 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
449 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
450 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
451 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
452 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
453 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
454 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
455 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
456 initializeTypeMenu( getOptions() );
457 _jmenubar.add( _type_menu );
460 void buildViewMenu() {
461 _view_jmenu = MainFrame.createMenu( "View as Text", getConfiguration() );
462 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
463 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
464 _view_jmenu.add( _view_as_NHX_item = new JMenuItem( "View as NHX" ) );
465 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
466 customizeJMenuItem( _view_as_NH_item );
467 customizeJMenuItem( _view_as_NHX_item );
468 customizeJMenuItem( _view_as_XML_item );
469 customizeJMenuItem( _view_as_nexus_item );
470 _jmenubar.add( _view_jmenu );
473 private void chooseFont() {
474 final FontChooser fc = new FontChooser();
475 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
476 fc.showDialog( this, "Select the Base Font" );
477 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
480 private void chooseMinimalConfidence() {
481 final String s = ( String ) JOptionPane
482 .showInputDialog( this,
483 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
484 + getOptions().getMinConfidenceValue() + "]\n",
485 "Minimal Confidence Value",
486 JOptionPane.QUESTION_MESSAGE,
489 getOptions().getMinConfidenceValue() );
490 if ( !ForesterUtil.isEmpty( s ) ) {
491 boolean success = true;
493 final String m_str = s.trim();
494 if ( !ForesterUtil.isEmpty( m_str ) ) {
496 m = Double.parseDouble( m_str );
498 catch ( final Exception ex ) {
505 if ( success && ( m >= 0.0 ) ) {
506 getOptions().setMinConfidenceValue( m );
511 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
512 if ( item != null ) {
513 item.setFont( MainFrame.menu_font );
514 if ( !getConfiguration().isUseNativeUI() ) {
515 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
516 item.setForeground( getConfiguration().getGuiMenuTextColor() );
518 item.setSelected( is_selected );
519 item.addActionListener( this );
523 void customizeJMenuItem( final JMenuItem jmi ) {
524 jmi.setFont( MainFrame.menu_font );
525 if ( !getConfiguration().isUseNativeUI() ) {
526 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
527 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
529 jmi.addActionListener( this );
532 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
533 if ( item != null ) {
534 item.setFont( MainFrame.menu_font );
535 if ( !getConfiguration().isUseNativeUI() ) {
536 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
537 item.setForeground( getConfiguration().getGuiMenuTextColor() );
539 item.setSelected( is_selected );
540 item.addActionListener( this );
545 public void destroy() {
546 Util.printAppletMessage( NAME, "going to be destroyed " );
548 if ( getMainPanel() != null ) {
549 getMainPanel().terminate();
553 Configuration getConfiguration() {
554 return _configuration;
557 TreePanel getCurrentTreePanel() {
558 return getMainPanel().getCurrentTreePanel();
561 JCheckBoxMenuItem getlabelDirectionCbmi() {
562 return _label_direction_cbmi;
565 private MainPanel getMainPanel() {
569 public Options getOptions() {
573 Options getOtions() {
579 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
580 Util.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
581 final Configuration configuration = new Configuration( config_filename, true, true );
582 setConfiguration( configuration );
583 setOptions( Options.createInstance( configuration ) );
586 Phylogeny[] phys = null;
587 final String phys_url_string = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
588 Util.printAppletMessage( NAME, "URL for phylogenies is " + phys_url_string );
589 // Get URL to tree file
590 if ( phys_url_string != null ) {
592 phys_url = new URL( phys_url_string );
594 catch ( final Exception e ) {
595 ForesterUtil.printErrorMessage( NAME, "error: " + e );
597 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + phys_url_string
598 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
601 // Load the tree from URL
602 if ( phys_url != null ) {
604 phys = Util.readPhylogeniesFromUrl( phys_url, getConfiguration().isValidatePhyloXmlAgainstSchema() );
606 catch ( final Exception e ) {
607 ForesterUtil.printErrorMessage( NAME, e.toString() );
609 JOptionPane.showMessageDialog( this,
610 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
611 "Failed to read phylogenies",
612 JOptionPane.ERROR_MESSAGE );
615 if ( ( phys == null ) || ( phys.length < 1 ) ) {
616 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
617 JOptionPane.showMessageDialog( this,
618 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
619 "Failed to read phylogenies",
620 JOptionPane.ERROR_MESSAGE );
624 Util.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
627 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
628 _jmenubar = new JMenuBar();
629 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
630 if ( !getConfiguration().isUseNativeUI() ) {
631 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
639 setJMenuBar( _jmenubar );
641 final Container contentpane = getContentPane();
642 contentpane.setLayout( new BorderLayout() );
643 contentpane.add( getMainPanel(), BorderLayout.CENTER );
644 addComponentListener( new ComponentAdapter() {
647 public void componentResized( final ComponentEvent e ) {
648 if ( getMainPanel().getCurrentTreePanel() != null ) {
649 getMainPanel().getCurrentTreePanel().setParametersForPainting( getMainPanel().getCurrentTreePanel()
651 getMainPanel().getCurrentTreePanel()
657 if ( getConfiguration().isUseTabbedDisplay() ) {
658 Util.printAppletMessage( NAME, "using tabbed display" );
659 Util.addPhylogeniesToTabs( phys,
660 new File( phys_url.getFile() ).getName(),
666 Util.printAppletMessage( NAME, "not using tabbed display" );
667 Util.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
671 getMainPanel().getControlPanel().showWholeAll();
672 getMainPanel().getControlPanel().showWhole();
674 Util.printAppletMessage( NAME, "successfully initialized" );
676 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
677 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
678 .getRelevantSequenceRelationTypes() ) {
679 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
681 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
682 if ( default_relation != null ) {
683 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
685 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
686 if ( default_sequence != null ) {
687 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
693 void initializeTypeMenu( final Options options ) {
694 setTypeMenuToAllUnselected();
696 switch ( options.getPhylogenyGraphicsType() ) {
698 _convex_type_cbmi.setSelected( true );
701 _curved_type_cbmi.setSelected( true );
704 _euro_type_cbmi.setSelected( true );
707 _rounded_type_cbmi.setSelected( true );
710 _triangular_type_cbmi.setSelected( true );
713 _unrooted_type_cbmi.setSelected( true );
716 _circular_type_cbmi.setSelected( true );
719 _rectangular_type_cbmi.setSelected( true );
723 catch ( final NullPointerException np ) {
724 // In all likelihood, this is caused by menu-less display.
728 private boolean isScreenAntialias() {
732 private void removeBranchColors() {
733 if ( getMainPanel().getCurrentPhylogeny() != null ) {
734 Util.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
738 void removeTextFrame() {
739 if ( _textframe != null ) {
745 void setConfiguration( final Configuration configuration ) {
746 _configuration = configuration;
749 private void setMainPanel( final MainPanelApplets main_panel ) {
750 _main_panel = main_panel;
753 void setOptions( final Options options ) {
757 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
758 setTypeMenuToAllUnselected();
762 _circular_type_cbmi.setSelected( true );
765 _convex_type_cbmi.setSelected( true );
768 _curved_type_cbmi.setSelected( true );
771 _euro_type_cbmi.setSelected( true );
774 _rounded_type_cbmi.setSelected( true );
777 _rectangular_type_cbmi.setSelected( true );
780 _triangular_type_cbmi.setSelected( true );
783 _unrooted_type_cbmi.setSelected( true );
786 throw new IllegalArgumentException( "unknown type: " + type );
789 catch ( final NullPointerException np ) {
790 // In all likelihood, this is caused by menu-less display.
794 void setTypeMenuToAllUnselected() {
795 if ( _convex_type_cbmi != null ) {
796 _convex_type_cbmi.setSelected( false );
798 if ( _curved_type_cbmi != null ) {
799 _curved_type_cbmi.setSelected( false );
801 if ( _euro_type_cbmi != null ) {
802 _euro_type_cbmi.setSelected( false );
804 if ( _rounded_type_cbmi != null ) {
805 _rounded_type_cbmi.setSelected( false );
807 if ( _triangular_type_cbmi != null ) {
808 _triangular_type_cbmi.setSelected( false );
810 if ( _rectangular_type_cbmi != null ) {
811 _rectangular_type_cbmi.setSelected( false );
813 if ( _unrooted_type_cbmi != null ) {
814 _unrooted_type_cbmi.setSelected( false );
816 if ( _circular_type_cbmi != null ) {
817 _circular_type_cbmi.setSelected( false );
821 private void setupUI() {
823 if ( getConfiguration().isUseNativeUI() ) {
824 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
827 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
830 catch ( final UnsupportedLookAndFeelException e ) {
831 Util.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
833 catch ( final ClassNotFoundException e ) {
834 Util.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
836 catch ( final InstantiationException e ) {
837 Util.dieWithSystemError( "InstantiationException: " + e.toString() );
839 catch ( final IllegalAccessException e ) {
840 Util.dieWithSystemError( "IllegalAccessException: " + e.toString() );
842 catch ( final Exception e ) {
843 Util.dieWithSystemError( e.toString() );
848 public void start() {
849 if ( getMainPanel() != null ) {
850 getMainPanel().validate();
853 requestFocusInWindow();
855 Util.printAppletMessage( NAME, "started" );
858 void switchColors() {
859 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
860 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
861 csc.setVisible( true );
862 getMainPanel().setTreeColorSet( colorset );
865 void typeChanged( final Object o ) {
866 updateTypeCheckboxes( getOptions(), o );
867 updateOptions( getOptions() );
868 if ( getCurrentTreePanel() != null ) {
869 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
870 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
871 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
872 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
873 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
874 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
875 getCurrentTreePanel().getControlPanel().showWhole();
877 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
878 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
881 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
883 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
884 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
888 void updateOptions( final Options options ) {
889 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
890 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
891 && _background_gradient_cbmi.isSelected() );
892 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
893 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
894 && _abbreviate_scientific_names.isSelected() );
895 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
896 && _color_labels_same_as_parent_branch.isSelected() );
897 options.setShowNodeBoxes( ( _show_node_boxes_cbmi != null ) && _show_node_boxes_cbmi.isSelected() );
898 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
899 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
901 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
902 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
904 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
905 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
907 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
908 && _search_case_senstive_cbmi.isSelected() );
909 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
910 options.setShowScale( _show_scale_cbmi.isSelected() );
912 if ( _label_direction_cbmi != null ) {
913 if ( _label_direction_cbmi.isSelected() ) {
914 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
917 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
920 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
921 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
922 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
924 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
925 && _search_whole_words_only_cbmi.isSelected() );
926 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
927 && _inverse_search_result_cbmi.isSelected() );
928 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
929 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
931 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
932 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
934 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
935 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
937 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
938 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
940 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
941 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
943 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
944 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
946 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
947 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
949 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
950 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
954 void updateTypeCheckboxes( final Options options, final Object o ) {
955 setTypeMenuToAllUnselected();
956 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
961 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
962 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
965 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNexus() );
970 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
971 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
974 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshire( false ) );
979 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
980 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
983 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshireX() );
988 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
989 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
992 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ) );
995 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
996 for( final TreePanel tree_panel : treepanels ) {
997 tree_panel.setTextAntialias();