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;
113 public void actionPerformed( final ActionEvent e ) {
114 final Object o = e.getSource();
115 if ( o == _midpoint_root_item ) {
116 getMainPanel().getCurrentTreePanel().midpointRoot();
118 else if ( o == _taxcolor_item ) {
119 getMainPanel().getCurrentTreePanel().taxColor();
121 else if ( o == _confcolor_item ) {
122 getMainPanel().getCurrentTreePanel().confColor();
124 else if ( o == _infer_common_sn_names_item ) {
125 if ( getCurrentTreePanel() != null ) {
126 getCurrentTreePanel().inferCommonPartOfScientificNames();
129 else if ( o == _collapse_species_specific_subtrees ) {
130 if ( getCurrentTreePanel() != null ) {
131 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
134 else if ( o == _remove_branch_color_item ) {
135 removeBranchColors();
137 else if ( o == _switch_colors_mi ) {
140 else if ( o == _view_as_NH_item ) {
143 else if ( o == _view_as_NHX_item ) {
146 else if ( o == _view_as_XML_item ) {
149 else if ( o == _view_as_nexus_item ) {
152 else if ( o == _super_tiny_fonts_mi ) {
153 if ( getCurrentTreePanel() != null ) {
154 getCurrentTreePanel().setSuperTinyFonts();
155 getCurrentTreePanel().repaint();
158 else if ( o == _tiny_fonts_mi ) {
159 if ( getCurrentTreePanel() != null ) {
160 getCurrentTreePanel().setTinyFonts();
161 getCurrentTreePanel().repaint();
164 else if ( o == _small_fonts_mi ) {
165 if ( getCurrentTreePanel() != null ) {
166 getCurrentTreePanel().setSmallFonts();
167 getCurrentTreePanel().repaint();
170 else if ( o == _medium_fonts_mi ) {
171 if ( getCurrentTreePanel() != null ) {
172 getCurrentTreePanel().setMediumFonts();
173 getCurrentTreePanel().repaint();
176 else if ( o == _large_fonts_mi ) {
177 if ( getCurrentTreePanel() != null ) {
178 getCurrentTreePanel().setLargeFonts();
179 getCurrentTreePanel().repaint();
182 else if ( o == _choose_font_mi ) {
185 else if ( o == _choose_minimal_confidence_mi ) {
186 chooseMinimalConfidence();
188 else if ( o == _overview_placment_mi ) {
189 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
191 else if ( o == _show_node_boxes_cbmi ) {
192 updateOptions( getOptions() );
194 else if ( o == _non_lined_up_cladograms_rbmi ) {
195 updateOptions( getOptions() );
196 _main_panel.getControlPanel().showWhole();
198 else if ( o == _uniform_cladograms_rbmi ) {
199 updateOptions( getOptions() );
200 _main_panel.getControlPanel().showWhole();
202 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
203 updateOptions( getOptions() );
204 _main_panel.getControlPanel().showWhole();
206 else if ( o == _search_case_senstive_cbmi ) {
207 updateOptions( getOptions() );
208 getMainPanel().getControlPanel().search();
210 else if ( o == _search_whole_words_only_cbmi ) {
211 updateOptions( getOptions() );
212 getMainPanel().getControlPanel().search();
214 else if ( o == _inverse_search_result_cbmi ) {
215 updateOptions( getOptions() );
216 getMainPanel().getControlPanel().search();
218 else if ( o == _show_scale_cbmi ) {
219 updateOptions( getOptions() );
221 else if ( o == _show_branch_length_values_cbmi ) {
222 updateOptions( getOptions() );
224 else if ( o == _label_direction_cbmi ) {
225 updateOptions( getOptions() );
227 else if ( o == _show_overview_cbmi ) {
228 updateOptions( getOptions() );
229 if ( getCurrentTreePanel() != null ) {
230 getCurrentTreePanel().updateOvSizes();
233 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
234 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
235 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
238 else if ( o == _screen_antialias_cbmi ) {
239 updateOptions( getOptions() );
240 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
242 else if ( o == _background_gradient_cbmi ) {
243 updateOptions( getOptions() );
245 else if ( o == _show_domain_labels ) {
246 updateOptions( getOptions() );
248 else if ( o == _color_labels_same_as_parent_branch ) {
249 updateOptions( getOptions() );
251 else if ( o == _about_item ) {
254 else if ( o == _help_item ) {
255 MainFrame.help( getConfiguration().getWebLinks() );
257 else if ( o == _website_item ) {
259 Util.openWebsite( Constants.APTX_WEB_SITE, true, this );
261 catch ( final IOException e1 ) {
262 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
265 else if ( o == _phyloxml_website_item ) {
267 Util.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
269 catch ( final IOException e1 ) {
270 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
273 else if ( o == _aptx_ref_item ) {
275 Util.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
277 catch ( final IOException e1 ) {
278 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
281 else if ( o == _phyloxml_ref_item ) {
283 Util.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
285 catch ( final IOException e1 ) {
286 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
292 void buildFontSizeMenu() {
293 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
294 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
295 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
296 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
297 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
298 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
299 customizeJMenuItem( _super_tiny_fonts_mi );
300 customizeJMenuItem( _tiny_fonts_mi );
301 customizeJMenuItem( _small_fonts_mi );
302 customizeJMenuItem( _medium_fonts_mi );
303 customizeJMenuItem( _large_fonts_mi );
304 _jmenubar.add( _font_size_menu );
307 void buildHelpMenu() {
308 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
309 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
310 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
311 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
312 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
313 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
314 _help_jmenu.addSeparator();
315 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
316 customizeJMenuItem( _help_item );
317 customizeJMenuItem( _website_item );
318 customizeJMenuItem( _phyloxml_website_item );
319 customizeJMenuItem( _aptx_ref_item );
320 customizeJMenuItem( _phyloxml_ref_item );
321 customizeJMenuItem( _about_item );
322 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
323 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
324 _jmenubar.add( _help_jmenu );
327 void buildOptionsMenu() {
328 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
329 _options_jmenu.addChangeListener( new ChangeListener() {
331 public void stateChanged( final ChangeEvent e ) {
332 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getCurrentTreePanel() );
333 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
335 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
336 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
337 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
338 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
340 _show_branch_length_values_cbmi,
341 _non_lined_up_cladograms_rbmi,
342 _uniform_cladograms_rbmi,
343 _ext_node_dependent_cladogram_rbmi,
344 _label_direction_cbmi );
347 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
348 getConfiguration() ) );
350 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
351 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
353 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
354 _radio_group_1 = new ButtonGroup();
355 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
356 _radio_group_1.add( _uniform_cladograms_rbmi );
357 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
358 _options_jmenu.add( _show_node_boxes_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL ) );
359 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
361 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
362 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
363 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
365 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
366 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
367 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
368 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
369 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
370 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
371 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
372 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
374 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
375 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
376 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
377 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
378 _options_jmenu.addSeparator();
379 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
380 getConfiguration() ) );
382 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
383 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
385 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
386 customizeJMenuItem( _choose_font_mi );
387 customizeJMenuItem( _choose_minimal_confidence_mi );
388 customizeJMenuItem( _switch_colors_mi );
389 customizeJMenuItem( _overview_placment_mi );
390 customizeCheckBoxMenuItem( _show_node_boxes_cbmi, getOptions().isShowNodeBoxes() );
391 customizeCheckBoxMenuItem( _label_direction_cbmi,
392 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
393 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
394 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
395 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
396 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
397 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
398 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
399 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
400 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
401 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
402 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
403 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
404 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
405 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
406 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
407 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
408 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
409 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
410 _jmenubar.add( _options_jmenu );
413 void buildToolsMenu() {
414 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
415 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
416 customizeJMenuItem( _confcolor_item );
417 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
418 customizeJMenuItem( _taxcolor_item );
419 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
420 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
421 customizeJMenuItem( _remove_branch_color_item );
422 _tools_menu.addSeparator();
423 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
424 customizeJMenuItem( _midpoint_root_item );
425 _tools_menu.addSeparator();
427 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
428 customizeJMenuItem( _infer_common_sn_names_item );
429 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
430 customizeJMenuItem( _collapse_species_specific_subtrees );
431 _jmenubar.add( _tools_menu );
434 void buildTypeMenu() {
435 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
436 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
437 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
438 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
439 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
440 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
441 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
442 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
443 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
444 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
445 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
446 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
447 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
448 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
449 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
450 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
451 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
452 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
453 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
454 initializeTypeMenu( getOptions() );
455 _jmenubar.add( _type_menu );
458 void buildViewMenu() {
459 _view_jmenu = MainFrame.createMenu( "View as Text", getConfiguration() );
460 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
461 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
462 _view_jmenu.add( _view_as_NHX_item = new JMenuItem( "View as NHX" ) );
463 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
464 customizeJMenuItem( _view_as_NH_item );
465 customizeJMenuItem( _view_as_NHX_item );
466 customizeJMenuItem( _view_as_XML_item );
467 customizeJMenuItem( _view_as_nexus_item );
468 _jmenubar.add( _view_jmenu );
471 private void chooseFont() {
472 final FontChooser fc = new FontChooser();
473 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
474 fc.showDialog( this, "Select the Base Font" );
475 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
478 private void chooseMinimalConfidence() {
479 final String s = ( String ) JOptionPane
480 .showInputDialog( this,
481 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
482 + getOptions().getMinConfidenceValue() + "]\n",
483 "Minimal Confidence Value",
484 JOptionPane.QUESTION_MESSAGE,
487 getOptions().getMinConfidenceValue() );
488 if ( !ForesterUtil.isEmpty( s ) ) {
489 boolean success = true;
491 final String m_str = s.trim();
492 if ( !ForesterUtil.isEmpty( m_str ) ) {
494 m = Double.parseDouble( m_str );
496 catch ( final Exception ex ) {
503 if ( success && ( m >= 0.0 ) ) {
504 getOptions().setMinConfidenceValue( m );
509 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
510 if ( item != null ) {
511 item.setFont( MainFrame.menu_font );
512 if ( !getConfiguration().isUseNativeUI() ) {
513 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
514 item.setForeground( getConfiguration().getGuiMenuTextColor() );
516 item.setSelected( is_selected );
517 item.addActionListener( this );
521 void customizeJMenuItem( final JMenuItem jmi ) {
522 jmi.setFont( MainFrame.menu_font );
523 if ( !getConfiguration().isUseNativeUI() ) {
524 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
525 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
527 jmi.addActionListener( this );
530 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
531 if ( item != null ) {
532 item.setFont( MainFrame.menu_font );
533 if ( !getConfiguration().isUseNativeUI() ) {
534 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
535 item.setForeground( getConfiguration().getGuiMenuTextColor() );
537 item.setSelected( is_selected );
538 item.addActionListener( this );
543 public void destroy() {
544 Util.printAppletMessage( NAME, "going to be destroyed " );
546 if ( getMainPanel() != null ) {
547 getMainPanel().terminate();
551 Configuration getConfiguration() {
552 return _configuration;
555 TreePanel getCurrentTreePanel() {
556 return getMainPanel().getCurrentTreePanel();
559 JCheckBoxMenuItem getlabelDirectionCbmi() {
560 return _label_direction_cbmi;
563 private MainPanel getMainPanel() {
567 public Options getOptions() {
571 Options getOtions() {
577 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
578 Util.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
579 final Configuration configuration = new Configuration( config_filename, true, true );
580 setConfiguration( configuration );
581 setOptions( Options.createInstance( configuration ) );
584 Phylogeny[] phys = null;
585 final String phys_url_string = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
586 Util.printAppletMessage( NAME, "URL for phylogenies is " + phys_url_string );
587 // Get URL to tree file
588 if ( phys_url_string != null ) {
590 phys_url = new URL( phys_url_string );
592 catch ( final Exception e ) {
593 ForesterUtil.printErrorMessage( NAME, "error: " + e );
595 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + phys_url_string
596 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
599 // Load the tree from URL
600 if ( phys_url != null ) {
602 phys = Util.readPhylogeniesFromUrl( phys_url, getConfiguration().isValidatePhyloXmlAgainstSchema() );
604 catch ( final Exception e ) {
605 ForesterUtil.printErrorMessage( NAME, e.toString() );
607 JOptionPane.showMessageDialog( this,
608 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
609 "Failed to read phylogenies",
610 JOptionPane.ERROR_MESSAGE );
613 if ( ( phys == null ) || ( phys.length < 1 ) ) {
614 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
615 JOptionPane.showMessageDialog( this,
616 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
617 "Failed to read phylogenies",
618 JOptionPane.ERROR_MESSAGE );
622 Util.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
625 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
626 _jmenubar = new JMenuBar();
627 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
628 if ( !getConfiguration().isUseNativeUI() ) {
629 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
637 setJMenuBar( _jmenubar );
639 final Container contentpane = getContentPane();
640 contentpane.setLayout( new BorderLayout() );
641 contentpane.add( getMainPanel(), BorderLayout.CENTER );
642 addComponentListener( new ComponentAdapter() {
645 public void componentResized( final ComponentEvent e ) {
646 if ( getMainPanel().getCurrentTreePanel() != null ) {
647 getMainPanel().getCurrentTreePanel().setParametersForPainting( getMainPanel().getCurrentTreePanel()
649 getMainPanel().getCurrentTreePanel()
655 if ( getConfiguration().isUseTabbedDisplay() ) {
656 Util.printAppletMessage( NAME, "using tabbed display" );
657 Util.addPhylogeniesToTabs( phys,
658 new File( phys_url.getFile() ).getName(),
664 Util.printAppletMessage( NAME, "not using tabbed display" );
665 Util.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
669 getMainPanel().getControlPanel().showWholeAll();
670 getMainPanel().getControlPanel().showWhole();
672 Util.printAppletMessage( NAME, "successfully initialized" );
674 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
675 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
676 .getRelevantSequenceRelationTypes() ) {
677 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
679 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
680 if ( default_relation != null ) {
681 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
683 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
684 if ( default_sequence != null ) {
685 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
691 void initializeTypeMenu( final Options options ) {
692 setTypeMenuToAllUnselected();
694 switch ( options.getPhylogenyGraphicsType() ) {
696 _convex_type_cbmi.setSelected( true );
699 _curved_type_cbmi.setSelected( true );
702 _euro_type_cbmi.setSelected( true );
705 _rounded_type_cbmi.setSelected( true );
708 _triangular_type_cbmi.setSelected( true );
711 _unrooted_type_cbmi.setSelected( true );
714 _circular_type_cbmi.setSelected( true );
717 _rectangular_type_cbmi.setSelected( true );
721 catch ( final NullPointerException np ) {
722 // In all likelihood, this is caused by menu-less display.
726 private boolean isScreenAntialias() {
730 private void removeBranchColors() {
731 if ( getMainPanel().getCurrentPhylogeny() != null ) {
732 Util.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
736 void removeTextFrame() {
737 if ( _textframe != null ) {
743 void setConfiguration( final Configuration configuration ) {
744 _configuration = configuration;
747 private void setMainPanel( final MainPanelApplets main_panel ) {
748 _main_panel = main_panel;
751 void setOptions( final Options options ) {
755 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
756 setTypeMenuToAllUnselected();
760 _circular_type_cbmi.setSelected( true );
763 _convex_type_cbmi.setSelected( true );
766 _curved_type_cbmi.setSelected( true );
769 _euro_type_cbmi.setSelected( true );
772 _rounded_type_cbmi.setSelected( true );
775 _rectangular_type_cbmi.setSelected( true );
778 _triangular_type_cbmi.setSelected( true );
781 _unrooted_type_cbmi.setSelected( true );
784 throw new IllegalArgumentException( "unknown type: " + type );
787 catch ( final NullPointerException np ) {
788 // In all likelihood, this is caused by menu-less display.
792 void setTypeMenuToAllUnselected() {
793 if ( _convex_type_cbmi != null ) {
794 _convex_type_cbmi.setSelected( false );
796 if ( _curved_type_cbmi != null ) {
797 _curved_type_cbmi.setSelected( false );
799 if ( _euro_type_cbmi != null ) {
800 _euro_type_cbmi.setSelected( false );
802 if ( _rounded_type_cbmi != null ) {
803 _rounded_type_cbmi.setSelected( false );
805 if ( _triangular_type_cbmi != null ) {
806 _triangular_type_cbmi.setSelected( false );
808 if ( _rectangular_type_cbmi != null ) {
809 _rectangular_type_cbmi.setSelected( false );
811 if ( _unrooted_type_cbmi != null ) {
812 _unrooted_type_cbmi.setSelected( false );
814 if ( _circular_type_cbmi != null ) {
815 _circular_type_cbmi.setSelected( false );
819 private void setupUI() {
821 if ( getConfiguration().isUseNativeUI() ) {
822 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
825 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
828 catch ( final UnsupportedLookAndFeelException e ) {
829 Util.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
831 catch ( final ClassNotFoundException e ) {
832 Util.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
834 catch ( final InstantiationException e ) {
835 Util.dieWithSystemError( "InstantiationException: " + e.toString() );
837 catch ( final IllegalAccessException e ) {
838 Util.dieWithSystemError( "IllegalAccessException: " + e.toString() );
840 catch ( final Exception e ) {
841 Util.dieWithSystemError( e.toString() );
846 public void start() {
847 if ( getMainPanel() != null ) {
848 getMainPanel().validate();
851 requestFocusInWindow();
853 Util.printAppletMessage( NAME, "started" );
856 void switchColors() {
857 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
858 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
859 csc.setVisible( true );
860 getMainPanel().setTreeColorSet( colorset );
863 void typeChanged( final Object o ) {
864 updateTypeCheckboxes( getOptions(), o );
865 updateOptions( getOptions() );
866 if ( getCurrentTreePanel() != null ) {
867 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
868 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
869 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
870 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
871 || ( ( 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 getCurrentTreePanel().getControlPanel().showWhole();
875 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
876 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
879 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
881 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
882 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
886 void updateOptions( final Options options ) {
887 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
888 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
889 && _background_gradient_cbmi.isSelected() );
890 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
891 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
892 && _abbreviate_scientific_names.isSelected() );
893 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
894 && _color_labels_same_as_parent_branch.isSelected() );
895 options.setShowNodeBoxes( ( _show_node_boxes_cbmi != null ) && _show_node_boxes_cbmi.isSelected() );
896 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
897 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
899 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
900 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
902 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
903 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
905 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
906 && _search_case_senstive_cbmi.isSelected() );
907 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
908 options.setShowScale( _show_scale_cbmi.isSelected() );
910 if ( _label_direction_cbmi != null ) {
911 if ( _label_direction_cbmi.isSelected() ) {
912 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
915 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
918 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
919 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
920 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
922 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
923 && _search_whole_words_only_cbmi.isSelected() );
924 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
925 && _inverse_search_result_cbmi.isSelected() );
926 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
927 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
929 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
930 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
932 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
933 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
935 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
936 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
938 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
939 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
941 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
942 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
944 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
945 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
947 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
948 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
952 void updateTypeCheckboxes( final Options options, final Object o ) {
953 setTypeMenuToAllUnselected();
954 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
959 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
960 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
963 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNexus() );
968 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
969 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
972 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshire( false ) );
977 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
978 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
981 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toNewHampshireX() );
986 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
987 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
990 _textframe = TextFrame.instantiate( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ) );
993 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
994 for( final TreePanel tree_panel : treepanels ) {
995 tree_panel.setTextAntialias();