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;
10 import java.io.ByteArrayOutputStream;
12 import java.io.IOException;
14 import java.util.LinkedList;
15 import java.util.List;
16 import java.util.NoSuchElementException;
18 import javax.swing.ButtonGroup;
19 import javax.swing.JApplet;
20 import javax.swing.JCheckBoxMenuItem;
21 import javax.swing.JMenu;
22 import javax.swing.JMenuBar;
23 import javax.swing.JMenuItem;
24 import javax.swing.JOptionPane;
25 import javax.swing.JRadioButtonMenuItem;
26 import javax.swing.UIManager;
27 import javax.swing.UnsupportedLookAndFeelException;
28 import javax.swing.event.ChangeEvent;
29 import javax.swing.event.ChangeListener;
31 import org.apache.commons.codec.binary.Base64;
32 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
33 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
34 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
35 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
36 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
37 import org.forester.phylogeny.Phylogeny;
38 import org.forester.phylogeny.PhylogenyMethods;
39 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
40 import org.forester.phylogeny.data.SequenceRelation;
41 import org.forester.sdi.GSDI;
42 import org.forester.sdi.GSDIR;
43 import org.forester.sdi.SDIException;
44 import org.forester.util.ForesterConstants;
45 import org.forester.util.ForesterUtil;
48 // <applet archive="forester.jar"
49 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
50 // codebase="http://www.myserver.org/path/to/forester"
53 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
54 // <param name="url_of_tree_to_load"
55 // value="http://www.myserver.org/examples/data/apaf.xml">
56 // <param name="config_file"
57 // value="http://www.myserver.org/examples/config/config_file.txt">
59 public class ArchaeopteryxE extends JApplet implements ActionListener {
61 private final static String NAME = "ArchaeopteryxE";
62 private static final long serialVersionUID = -1220055577935759443L;
63 private Configuration _configuration;
64 private MainPanelApplets _mainpanel;
65 private JMenuBar _jmenubar;
66 private JMenu _options_jmenu;
67 private JMenu _font_size_menu;
68 private JMenuItem _super_tiny_fonts_mi;
69 private JMenuItem _tiny_fonts_mi;
70 private JMenuItem _small_fonts_mi;
71 private JMenuItem _medium_fonts_mi;
72 private JMenuItem _large_fonts_mi;
73 private JMenu _tools_menu;
74 private JMenuItem _taxcolor_item;
75 private JMenuItem _confcolor_item;
76 private JMenuItem _midpoint_root_item;
77 private JMenu _view_jmenu;
78 private JMenuItem _view_as_XML_item;
79 private JMenuItem _view_as_NH_item;
80 private JMenuItem _view_as_nexus_item;
81 private JMenuItem _display_basic_information_item;
82 private JMenu _type_menu;
83 private JCheckBoxMenuItem _rectangular_type_cbmi;
84 private JCheckBoxMenuItem _triangular_type_cbmi;
85 private JCheckBoxMenuItem _curved_type_cbmi;
86 private JCheckBoxMenuItem _convex_type_cbmi;
87 private JCheckBoxMenuItem _euro_type_cbmi;
88 private JCheckBoxMenuItem _rounded_type_cbmi;
89 private JCheckBoxMenuItem _unrooted_type_cbmi;
90 private JCheckBoxMenuItem _circular_type_cbmi;
91 private JMenuItem _help_item;
92 private JMenuItem _about_item;
93 private JMenu _help_jmenu;
94 private JMenuItem _website_item;
95 private JMenuItem _phyloxml_website_item;
96 private JMenuItem _phyloxml_ref_item;
97 private JMenuItem _aptx_ref_item;
98 private JMenuItem _remove_branch_color_item;
99 private JCheckBoxMenuItem _show_domain_labels;
100 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
101 private JCheckBoxMenuItem _abbreviate_scientific_names;
102 private JCheckBoxMenuItem _screen_antialias_cbmi;
103 private JCheckBoxMenuItem _background_gradient_cbmi;
104 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
105 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
106 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
107 private Options _options;
108 private JMenuItem _choose_font_mi;
109 private JMenuItem _switch_colors_mi;
110 JCheckBoxMenuItem _label_direction_cbmi;
111 private JCheckBoxMenuItem _show_scale_cbmi;
112 private JCheckBoxMenuItem _search_case_senstive_cbmi;
113 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
114 private JCheckBoxMenuItem _inverse_search_result_cbmi;
115 private JCheckBoxMenuItem _show_overview_cbmi;
116 private JMenuItem _choose_minimal_confidence_mi;
117 private JCheckBoxMenuItem _show_branch_length_values_cbmi;
118 private JMenuItem _collapse_species_specific_subtrees;
119 private JMenuItem _overview_placment_mi;
120 private ButtonGroup _radio_group_1;
121 private JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
122 private JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
123 private JMenuItem _cycle_node_shape_mi;
124 private JMenuItem _cycle_node_fill_mi;
125 private JMenuItem _choose_node_size_mi;
126 private JCheckBoxMenuItem _taxonomy_colorize_node_shapes_cbmi;
127 private JCheckBoxMenuItem _show_confidence_stddev_cbmi;
128 private final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>();
129 private JMenu _analysis_menu;
130 private JMenuItem _gsdi_item;
131 private JMenuItem _gsdir_item;
132 private Phylogeny _species_tree;
135 public void actionPerformed( final ActionEvent e ) {
136 final Object o = e.getSource();
137 if ( o == _midpoint_root_item ) {
138 getMainPanel().getCurrentTreePanel().midpointRoot();
140 else if ( o == _gsdi_item ) {
141 if ( isSubtreeDisplayed() ) {
146 else if ( o == _gsdir_item ) {
147 if ( isSubtreeDisplayed() ) {
152 else if ( o == _taxcolor_item ) {
153 getMainPanel().getCurrentTreePanel().taxColor();
155 else if ( o == _confcolor_item ) {
156 getMainPanel().getCurrentTreePanel().confColor();
158 else if ( o == _collapse_species_specific_subtrees ) {
159 if ( getCurrentTreePanel() != null ) {
160 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
163 else if ( o == _remove_branch_color_item ) {
164 removeBranchColors();
166 else if ( o == _switch_colors_mi ) {
169 else if ( o == _display_basic_information_item ) {
170 displayBasicInformation();
172 else if ( o == _view_as_NH_item ) {
175 else if ( o == _view_as_XML_item ) {
178 else if ( o == _view_as_nexus_item ) {
181 else if ( o == _super_tiny_fonts_mi ) {
182 if ( getCurrentTreePanel() != null ) {
183 getCurrentTreePanel().setSuperTinyFonts();
184 getCurrentTreePanel().repaint();
187 else if ( o == _tiny_fonts_mi ) {
188 if ( getCurrentTreePanel() != null ) {
189 getCurrentTreePanel().setTinyFonts();
190 getCurrentTreePanel().repaint();
193 else if ( o == _small_fonts_mi ) {
194 if ( getCurrentTreePanel() != null ) {
195 getCurrentTreePanel().setSmallFonts();
196 getCurrentTreePanel().repaint();
199 else if ( o == _medium_fonts_mi ) {
200 if ( getCurrentTreePanel() != null ) {
201 getCurrentTreePanel().setMediumFonts();
202 getCurrentTreePanel().repaint();
205 else if ( o == _large_fonts_mi ) {
206 if ( getCurrentTreePanel() != null ) {
207 getCurrentTreePanel().setLargeFonts();
208 getCurrentTreePanel().repaint();
211 else if ( o == _choose_font_mi ) {
214 else if ( o == _choose_minimal_confidence_mi ) {
215 chooseMinimalConfidence();
217 else if ( o == _choose_node_size_mi ) {
218 MainFrame.chooseNodeSize( getOptions(), this );
220 else if ( o == _overview_placment_mi ) {
221 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
223 else if ( o == _cycle_node_fill_mi ) {
224 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
226 else if ( o == _cycle_node_shape_mi ) {
227 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
229 else if ( o == _non_lined_up_cladograms_rbmi ) {
230 updateOptions( getOptions() );
231 _mainpanel.getControlPanel().showWhole();
233 else if ( o == _uniform_cladograms_rbmi ) {
234 updateOptions( getOptions() );
235 _mainpanel.getControlPanel().showWhole();
237 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
238 updateOptions( getOptions() );
239 _mainpanel.getControlPanel().showWhole();
241 else if ( o == _search_case_senstive_cbmi ) {
242 updateOptions( getOptions() );
243 getMainPanel().getControlPanel().search();
245 else if ( o == _search_whole_words_only_cbmi ) {
246 updateOptions( getOptions() );
247 getMainPanel().getControlPanel().search();
249 else if ( o == _inverse_search_result_cbmi ) {
250 updateOptions( getOptions() );
251 getMainPanel().getControlPanel().search();
253 else if ( o == _show_scale_cbmi ) {
254 updateOptions( getOptions() );
256 else if ( o == _show_branch_length_values_cbmi ) {
257 updateOptions( getOptions() );
259 else if ( o == _show_confidence_stddev_cbmi ) {
260 updateOptions( getOptions() );
262 else if ( o == _label_direction_cbmi ) {
263 updateOptions( getOptions() );
265 else if ( o == _show_overview_cbmi ) {
266 updateOptions( getOptions() );
267 if ( getCurrentTreePanel() != null ) {
268 getCurrentTreePanel().updateOvSizes();
271 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
272 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
273 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
276 else if ( o == _screen_antialias_cbmi ) {
277 updateOptions( getOptions() );
278 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
280 else if ( o == _background_gradient_cbmi ) {
281 updateOptions( getOptions() );
283 else if ( o == _show_domain_labels ) {
284 updateOptions( getOptions() );
286 else if ( o == _color_labels_same_as_parent_branch ) {
287 updateOptions( getOptions() );
289 else if ( o == _show_default_node_shapes_internal_cbmi ) {
290 updateOptions( getOptions() );
292 else if ( o == _show_default_node_shapes_external_cbmi ) {
293 updateOptions( getOptions() );
295 else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
296 updateOptions( getOptions() );
298 else if ( o == _about_item ) {
301 else if ( o == _help_item ) {
304 else if ( o == _website_item ) {
306 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
308 catch ( final IOException e1 ) {
309 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
312 else if ( o == _phyloxml_website_item ) {
314 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
316 catch ( final IOException e1 ) {
317 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
320 else if ( o == _aptx_ref_item ) {
322 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
324 catch ( final IOException e1 ) {
325 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
328 else if ( o == _phyloxml_ref_item ) {
330 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
332 catch ( final IOException e1 ) {
333 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
340 public void destroy() {
341 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
342 removeAllTextFrames();
343 if ( getMainPanel() != null ) {
344 getMainPanel().terminate();
349 * This method returns the current external node data which
350 * has been selected by the user by clicking the "Return ..."
351 * menu item. This method is expected to be called from Javascript or
354 * @return current external node data as String
356 public String getCurrentExternalNodesDataBuffer() {
357 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
360 public int getCurrentExternalNodesDataBufferChangeCounter() {
361 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
364 public int getCurrentExternalNodesDataBufferLength() {
365 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
369 * This method returns the current phylogeny as a string in the chosen format
371 * @param format must be NH, NHX, NEXUS or PHYLOXML
372 * @return the phylogeny string
373 * @author Herve Menager
375 public String getCurrentPhylogeny( final String format ) {
376 removeAllTextFrames();
377 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
378 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
381 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
383 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
385 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
387 return getMainPanel().getCurrentPhylogeny().toNexus();
389 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
397 * This method returns a view of the current phylogeny in a chosen
398 * graphics format, base64-encoded in a string so that in can be used
401 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
402 * @return the phylogeny string
403 * @author Herve Menager
405 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
406 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
408 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
409 _mainpanel.getWidth(),
410 _mainpanel.getHeight(),
411 getCurrentTreePanel(),
412 getCurrentTreePanel().getControlPanel(),
413 GraphicsExportType.valueOf( format ),
416 catch ( final IOException ioe ) {
417 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
418 ioe.printStackTrace();
419 JOptionPane.showMessageDialog( this,
420 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
421 "Failed to generate graphics",
422 JOptionPane.ERROR_MESSAGE );
425 final byte[] bytes = baos.toByteArray();
426 final String dataImg = Base64.encodeBase64String( bytes );
430 public Options getOptions() {
436 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
437 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
438 final Configuration configuration = new Configuration( config_filename, true, true, true );
439 setConfiguration( configuration );
440 setOptions( Options.createInstance( configuration ) );
443 Phylogeny[] phys = null;
444 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
445 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
446 // Get URL to tree file
447 if ( tree_url_str != null ) {
449 phys_url = new URL( tree_url_str );
451 catch ( final Exception e ) {
452 ForesterUtil.printErrorMessage( NAME, "error: " + e );
454 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
455 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
458 // Load the tree from URL
459 if ( phys_url != null ) {
461 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
462 getConfiguration().isValidatePhyloXmlAgainstSchema(),
463 getConfiguration().isReplaceUnderscoresInNhParsing(),
464 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
465 getConfiguration().getTaxonomyExtraction(),
466 getConfiguration().isMidpointReroot() );
468 catch ( final Exception e ) {
469 ForesterUtil.printErrorMessage( NAME, e.toString() );
471 JOptionPane.showMessageDialog( this,
472 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
473 "Failed to read phylogenies",
474 JOptionPane.ERROR_MESSAGE );
477 if ( ( phys == null ) || ( phys.length < 1 ) ) {
478 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
479 JOptionPane.showMessageDialog( this,
480 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
481 "Failed to read phylogenies",
482 JOptionPane.ERROR_MESSAGE );
486 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
489 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
490 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
491 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
492 Phylogeny[] species_trees = null;
494 final URL species_tree_url = new URL( species_tree_url_str );
495 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
496 configuration.isValidatePhyloXmlAgainstSchema(),
497 configuration.isReplaceUnderscoresInNhParsing(),
499 TAXONOMY_EXTRACTION.NO,
502 catch ( final IOException e ) {
503 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
505 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
506 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
508 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
509 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
510 if ( species_trees[ 0 ].isEmpty() ) {
511 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
513 else if ( !species_trees[ 0 ].isRooted() ) {
514 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
517 setSpeciesTree( species_trees[ 0 ] );
518 AptxUtil.printAppletMessage( NAME, "species tree OK" );
524 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
525 _jmenubar = new JMenuBar();
526 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
527 if ( !getConfiguration().isUseNativeUI() ) {
528 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
530 if ( getSpeciesTree() != null ) {
539 setJMenuBar( _jmenubar );
541 final Container contentpane = getContentPane();
542 contentpane.setLayout( new BorderLayout() );
543 contentpane.add( getMainPanel(), BorderLayout.CENTER );
544 addComponentListener( new ComponentAdapter() {
547 public void componentResized( final ComponentEvent e ) {
548 if ( getMainPanel().getCurrentTreePanel() != null ) {
549 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
550 .getCurrentTreePanel()
553 .getCurrentTreePanel()
556 .isAllowFontSizeChange() );
560 if ( getConfiguration().isUseTabbedDisplay() ) {
561 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
562 AptxUtil.addPhylogeniesToTabs( phys,
563 new File( phys_url.getFile() ).getName(),
569 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
570 if ( getSpeciesTree() != null ) {
571 AptxUtil.printAppletMessage( NAME,
572 "Warning: gsdi (gene duplication inference) only available tabbed display" );
574 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
578 getMainPanel().getControlPanel().showWholeAll();
579 getMainPanel().getControlPanel().showWhole();
581 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
583 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
584 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
585 .getRelevantSequenceRelationTypes() ) {
586 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
588 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
589 if ( default_relation != null ) {
590 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
592 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
593 if ( default_sequence != null ) {
594 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
600 public void showTextFrame( final String s, final String title ) {
602 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
606 public void start() {
607 if ( getMainPanel() != null ) {
608 getMainPanel().validate();
611 requestFocusInWindow();
613 AptxUtil.printAppletMessage( NAME, "started" );
616 void buildAnalysisMenu() {
617 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
618 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
619 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
620 customizeJMenuItem( _gsdi_item );
621 customizeJMenuItem( _gsdir_item );
622 // _analysis_menu.addSeparator();
623 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
624 // customizeJMenuItem( _lineage_inference );
625 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
626 _jmenubar.add( _analysis_menu );
629 void buildFontSizeMenu() {
630 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
631 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
632 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
633 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
634 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
635 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
636 customizeJMenuItem( _super_tiny_fonts_mi );
637 customizeJMenuItem( _tiny_fonts_mi );
638 customizeJMenuItem( _small_fonts_mi );
639 customizeJMenuItem( _medium_fonts_mi );
640 customizeJMenuItem( _large_fonts_mi );
641 _jmenubar.add( _font_size_menu );
644 void buildHelpMenu() {
645 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
646 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
647 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
648 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
649 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
650 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
651 _help_jmenu.addSeparator();
652 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
653 customizeJMenuItem( _help_item );
654 customizeJMenuItem( _website_item );
655 customizeJMenuItem( _phyloxml_website_item );
656 customizeJMenuItem( _aptx_ref_item );
657 customizeJMenuItem( _phyloxml_ref_item );
658 customizeJMenuItem( _about_item );
659 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
660 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
661 _jmenubar.add( _help_jmenu );
664 void buildOptionsMenu() {
665 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
666 _options_jmenu.addChangeListener( new ChangeListener() {
669 public void stateChanged( final ChangeEvent e ) {
670 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
671 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
673 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
674 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
675 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
676 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
678 _show_branch_length_values_cbmi,
679 _non_lined_up_cladograms_rbmi,
680 _uniform_cladograms_rbmi,
681 _ext_node_dependent_cladogram_rbmi,
682 _label_direction_cbmi );
683 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
684 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
685 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
688 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
689 getConfiguration() ) );
691 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
692 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
694 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
695 _radio_group_1 = new ButtonGroup();
696 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
697 _radio_group_1.add( _uniform_cladograms_rbmi );
698 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
699 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
700 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
702 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
703 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
705 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
707 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
709 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
710 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
711 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
712 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
713 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
715 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
716 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
717 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
718 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
719 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
720 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
721 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
722 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
724 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
725 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
726 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
727 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
728 _options_jmenu.addSeparator();
729 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
730 getConfiguration() ) );
732 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
733 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
735 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
736 customizeJMenuItem( _choose_font_mi );
737 customizeJMenuItem( _choose_minimal_confidence_mi );
738 customizeJMenuItem( _switch_colors_mi );
739 customizeJMenuItem( _overview_placment_mi );
740 customizeCheckBoxMenuItem( _label_direction_cbmi,
741 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
742 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
743 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
744 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
745 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
746 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
747 .isShowDefaultNodeShapesExternal() );
748 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
749 .isShowDefaultNodeShapesInternal() );
750 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
751 customizeJMenuItem( _cycle_node_shape_mi );
752 customizeJMenuItem( _cycle_node_fill_mi );
753 customizeJMenuItem( _choose_node_size_mi );
754 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
755 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
756 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
757 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
758 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
759 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
760 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
761 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
762 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
763 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
764 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
765 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
766 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
767 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
768 _jmenubar.add( _options_jmenu );
771 void buildToolsMenu() {
772 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
773 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
774 customizeJMenuItem( _confcolor_item );
775 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
776 customizeJMenuItem( _taxcolor_item );
777 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
778 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
779 customizeJMenuItem( _remove_branch_color_item );
780 _tools_menu.addSeparator();
781 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
782 customizeJMenuItem( _midpoint_root_item );
783 _tools_menu.addSeparator();
784 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
785 customizeJMenuItem( _collapse_species_specific_subtrees );
786 _jmenubar.add( _tools_menu );
789 void buildTypeMenu() {
790 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
791 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
792 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
793 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
794 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
795 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
796 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
797 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
798 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
799 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
800 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
801 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
802 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
803 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
804 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
805 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
806 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
807 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
808 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
809 initializeTypeMenu( getOptions() );
810 _jmenubar.add( _type_menu );
813 void buildViewMenu() {
814 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
815 _view_jmenu.add( _display_basic_information_item = new JMenuItem( "Display Basic Information" ) );
816 _view_jmenu.addSeparator();
817 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
818 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
819 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
820 customizeJMenuItem( _display_basic_information_item );
821 customizeJMenuItem( _view_as_NH_item );
822 customizeJMenuItem( _view_as_XML_item );
823 customizeJMenuItem( _view_as_nexus_item );
824 _jmenubar.add( _view_jmenu );
827 void checkTextFrames() {
828 if ( _textframes.size() > 5 ) {
830 if ( _textframes.getFirst() != null ) {
831 _textframes.getFirst().removeMe();
834 _textframes.removeFirst();
837 catch ( final NoSuchElementException e ) {
843 void clearCurrentExternalNodesDataBuffer() {
844 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
847 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
848 if ( item != null ) {
849 item.setFont( MainFrame.menu_font );
850 if ( !getConfiguration().isUseNativeUI() ) {
851 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
852 item.setForeground( getConfiguration().getGuiMenuTextColor() );
854 item.setSelected( is_selected );
855 item.addActionListener( this );
859 void customizeJMenuItem( final JMenuItem jmi ) {
860 jmi.setFont( MainFrame.menu_font );
861 if ( !getConfiguration().isUseNativeUI() ) {
862 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
863 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
865 jmi.addActionListener( this );
868 void displayBasicInformation() {
869 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
870 String title = "Basic Information";
871 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
872 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
874 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny() ), title );
879 if ( !isOKforSDI( false, true ) ) {
882 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
883 JOptionPane.showMessageDialog( this,
884 "Gene tree is not rooted.",
885 "Cannot execute GSDI",
886 JOptionPane.ERROR_MESSAGE );
889 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
890 gene_tree.setAllNodesToNotCollapse();
891 gene_tree.recalculateNumberOfExternalDescendants( false );
893 final Phylogeny species_tree = _species_tree.copy();
895 gsdi = new GSDI( gene_tree, species_tree, false, true, true );
897 catch ( final SDIException e ) {
898 JOptionPane.showMessageDialog( this,
899 e.getLocalizedMessage(),
901 JOptionPane.ERROR_MESSAGE );
904 catch ( final Exception e ) {
905 AptxUtil.unexpectedException( e );
908 gene_tree.setRerootable( false );
909 gene_tree.clearHashIdToNodeMap();
910 gene_tree.recalculateNumberOfExternalDescendants( true );
911 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
912 getMainPanel().getControlPanel().setShowEvents( true );
914 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
915 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
917 _mainpanel.getTabbedPane().setSelectedIndex( selected );
919 _mainpanel.getCurrentTreePanel().setEdited( true );
920 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
921 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
922 JOptionPane.showMessageDialog( this,
923 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
924 + "Potential duplications: "
925 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
926 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
927 + "Stripped gene tree nodes: "
928 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
929 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
930 + "Number of polytomies in species tree used: " + poly + "\n",
931 "GSDI successfully completed",
932 JOptionPane.WARNING_MESSAGE );
935 JOptionPane.showMessageDialog( this,
936 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
937 + "Potential duplications: "
938 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
939 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
940 + "Stripped gene tree nodes: "
941 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
942 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
943 + "Number of polytomies in species tree used: " + poly + "\n",
944 "GSDI successfully completed",
945 JOptionPane.INFORMATION_MESSAGE );
949 void executeGSDIR() {
950 if ( !isOKforSDI( false, false ) ) {
953 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
955 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
956 JOptionPane.showMessageDialog( this,
957 "Gene tree is not completely binary",
958 "Cannot execute GSDI",
959 JOptionPane.ERROR_MESSAGE );
962 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
963 gene_tree.setAllNodesToNotCollapse();
964 gene_tree.recalculateNumberOfExternalDescendants( false );
966 final Phylogeny species_tree = _species_tree.copy();
968 gsdir = new GSDIR( gene_tree, species_tree, true, true );
970 catch ( final SDIException e ) {
971 JOptionPane.showMessageDialog( this,
972 e.getLocalizedMessage(),
973 "Error during GSDIR",
974 JOptionPane.ERROR_MESSAGE );
977 catch ( final Exception e ) {
978 AptxUtil.unexpectedException( e );
981 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
982 result_gene_tree.setRerootable( false );
983 result_gene_tree.clearHashIdToNodeMap();
984 result_gene_tree.recalculateNumberOfExternalDescendants( true );
985 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
986 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
987 getMainPanel().getControlPanel().setShowEvents( true );
989 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
990 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
992 _mainpanel.getTabbedPane().setSelectedIndex( selected );
994 _mainpanel.getCurrentTreePanel().setEdited( true );
995 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
996 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
997 JOptionPane.showMessageDialog( this,
998 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
999 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1000 + "Stripped gene tree nodes: "
1001 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1002 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1003 + "Number of polytomies in species tree used: " + poly + "\n",
1004 "GSDIR successfully completed",
1005 JOptionPane.WARNING_MESSAGE );
1008 JOptionPane.showMessageDialog( this,
1009 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1010 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1011 + "Stripped gene tree nodes: "
1012 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1013 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1014 + "Number of polytomies in species tree used: " + poly + "\n",
1015 "GSDIR successfully completed",
1016 JOptionPane.INFORMATION_MESSAGE );
1020 Configuration getConfiguration() {
1021 return _configuration;
1024 TreePanel getCurrentTreePanel() {
1025 return getMainPanel().getCurrentTreePanel();
1028 JCheckBoxMenuItem getlabelDirectionCbmi() {
1029 return _label_direction_cbmi;
1032 Options getOtions() {
1037 final StringBuilder sb = new StringBuilder();
1038 sb.append( "Display options\n" );
1039 sb.append( "-------------------\n" );
1040 sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
1041 sb.append( "Clickable tree nodes\n" );
1042 sb.append( "--------------------\n" );
1043 sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
1044 sb.append( "or by right clicking:\n" );
1045 sb.append( "o Display Node Data -- display information for a node\n" );
1046 sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
1047 sb.append( "o Root/Reroot -- change tree root to clicked node\n" );
1048 sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
1049 sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" );
1050 sb.append( "o Colorize Subtree -- color a subtree\n" );
1051 sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" );
1052 sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
1053 sb.append( "- there may be additional choices depending on this particular setup\n\n" );
1054 sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
1055 sb.append( "Zooming\n" );
1056 sb.append( "---------\n" );
1057 sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
1058 sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
1059 sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
1060 sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
1061 sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
1062 sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
1063 sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
1064 sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
1065 sb.append( "Quick tree manipulation:\n" );
1066 sb.append( "------------------------\n" );
1067 sb.append( "Order Subtrees -- order the tree by branch length\n" );
1068 sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
1069 sb.append( "phyloXML\n" );
1070 sb.append( "-------------------\n" );
1071 sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
1072 sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
1073 sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1075 sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
1076 sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
1077 TextFrame.instantiate( sb.toString(), "Help", _textframes );
1080 void initializeTypeMenu( final Options options ) {
1081 setTypeMenuToAllUnselected();
1083 switch ( options.getPhylogenyGraphicsType() ) {
1085 _convex_type_cbmi.setSelected( true );
1088 _curved_type_cbmi.setSelected( true );
1091 _euro_type_cbmi.setSelected( true );
1094 _rounded_type_cbmi.setSelected( true );
1097 _triangular_type_cbmi.setSelected( true );
1100 _unrooted_type_cbmi.setSelected( true );
1103 _circular_type_cbmi.setSelected( true );
1106 _rectangular_type_cbmi.setSelected( true );
1110 catch ( final NullPointerException np ) {
1111 // In all likelihood, this is caused by menu-less display.
1115 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1116 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1119 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1120 JOptionPane.showMessageDialog( this,
1121 "No species tree loaded",
1122 "Cannot execute GSDI",
1123 JOptionPane.ERROR_MESSAGE );
1126 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1127 JOptionPane.showMessageDialog( this,
1128 "Species tree is not completely binary",
1129 "Cannot execute GSDI",
1130 JOptionPane.ERROR_MESSAGE );
1133 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1134 JOptionPane.showMessageDialog( this,
1135 "Gene tree is not completely binary",
1136 "Cannot execute GSDI",
1137 JOptionPane.ERROR_MESSAGE );
1145 boolean isSubtreeDisplayed() {
1146 if ( getCurrentTreePanel() != null ) {
1147 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1149 .showMessageDialog( this,
1150 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1151 "Operation can not be exectuted on a sub-tree",
1152 JOptionPane.WARNING_MESSAGE );
1159 void removeAllTextFrames() {
1160 for( final TextFrame tf : _textframes ) {
1165 _textframes.clear();
1168 void setConfiguration( final Configuration configuration ) {
1169 _configuration = configuration;
1172 void setOptions( final Options options ) {
1176 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1177 setTypeMenuToAllUnselected();
1181 _circular_type_cbmi.setSelected( true );
1184 _convex_type_cbmi.setSelected( true );
1187 _curved_type_cbmi.setSelected( true );
1190 _euro_type_cbmi.setSelected( true );
1193 _rounded_type_cbmi.setSelected( true );
1196 _rectangular_type_cbmi.setSelected( true );
1199 _triangular_type_cbmi.setSelected( true );
1202 _unrooted_type_cbmi.setSelected( true );
1205 throw new IllegalArgumentException( "unknown type: " + type );
1208 catch ( final NullPointerException np ) {
1209 // In all likelihood, this is caused by menu-less display.
1213 void setTypeMenuToAllUnselected() {
1214 if ( _convex_type_cbmi != null ) {
1215 _convex_type_cbmi.setSelected( false );
1217 if ( _curved_type_cbmi != null ) {
1218 _curved_type_cbmi.setSelected( false );
1220 if ( _euro_type_cbmi != null ) {
1221 _euro_type_cbmi.setSelected( false );
1223 if ( _rounded_type_cbmi != null ) {
1224 _rounded_type_cbmi.setSelected( false );
1226 if ( _triangular_type_cbmi != null ) {
1227 _triangular_type_cbmi.setSelected( false );
1229 if ( _rectangular_type_cbmi != null ) {
1230 _rectangular_type_cbmi.setSelected( false );
1232 if ( _unrooted_type_cbmi != null ) {
1233 _unrooted_type_cbmi.setSelected( false );
1235 if ( _circular_type_cbmi != null ) {
1236 _circular_type_cbmi.setSelected( false );
1241 _mainpanel.getControlPanel().showWhole();
1244 void switchColors() {
1245 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1246 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1247 csc.setVisible( true );
1248 getMainPanel().setTreeColorSet( colorset );
1251 void typeChanged( final Object o ) {
1252 updateTypeCheckboxes( getOptions(), o );
1253 updateOptions( getOptions() );
1254 if ( getCurrentTreePanel() != null ) {
1255 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1256 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1257 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1258 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1259 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1260 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1261 getCurrentTreePanel().getControlPanel().showWhole();
1263 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1264 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1267 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1269 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1270 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1274 void updateOptions( final Options options ) {
1275 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1276 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1277 && _background_gradient_cbmi.isSelected() );
1278 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1279 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1280 && _abbreviate_scientific_names.isSelected() );
1281 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1282 && _color_labels_same_as_parent_branch.isSelected() );
1283 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1284 && _show_default_node_shapes_internal_cbmi.isSelected() );
1285 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1286 && _show_default_node_shapes_external_cbmi.isSelected() );
1287 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1288 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1289 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1290 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1292 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1293 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1295 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1296 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1298 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1299 && _search_case_senstive_cbmi.isSelected() );
1300 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1301 options.setShowScale( _show_scale_cbmi.isSelected() );
1303 if ( _label_direction_cbmi != null ) {
1304 if ( _label_direction_cbmi.isSelected() ) {
1305 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1308 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1311 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1312 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1313 && _show_confidence_stddev_cbmi.isSelected() );
1314 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1315 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1317 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1318 && _search_whole_words_only_cbmi.isSelected() );
1319 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1320 && _inverse_search_result_cbmi.isSelected() );
1321 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1322 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1324 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1325 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1327 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1328 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1330 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1331 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1333 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1334 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1336 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1337 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1339 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1340 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1342 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1343 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1347 void updateTypeCheckboxes( final Options options, final Object o ) {
1348 setTypeMenuToAllUnselected();
1349 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1352 void viewAsNexus() {
1353 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1354 String title = "Nexus";
1355 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1356 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1358 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1359 .getNhConversionSupportValueStyle() ),
1365 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1366 String title = "New Hampshire";
1367 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1368 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1370 showTextFrame( getMainPanel().getCurrentPhylogeny()
1371 .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1377 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1378 String title = "phyloXML";
1379 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1380 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1382 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1386 private void chooseFont() {
1387 final FontChooser fc = new FontChooser();
1388 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1389 fc.showDialog( this, "Select the Base Font" );
1390 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1393 private void chooseMinimalConfidence() {
1394 final String s = ( String ) JOptionPane
1395 .showInputDialog( this,
1396 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1397 + getOptions().getMinConfidenceValue() + "]\n",
1398 "Minimal Confidence Value",
1399 JOptionPane.QUESTION_MESSAGE,
1402 getOptions().getMinConfidenceValue() );
1403 if ( !ForesterUtil.isEmpty( s ) ) {
1404 boolean success = true;
1406 final String m_str = s.trim();
1407 if ( !ForesterUtil.isEmpty( m_str ) ) {
1409 m = Double.parseDouble( m_str );
1411 catch ( final Exception ex ) {
1418 if ( success && ( m >= 0.0 ) ) {
1419 getOptions().setMinConfidenceValue( m );
1424 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1425 if ( item != null ) {
1426 item.setFont( MainFrame.menu_font );
1427 if ( !getConfiguration().isUseNativeUI() ) {
1428 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1429 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1431 item.setSelected( is_selected );
1432 item.addActionListener( this );
1436 private MainPanel getMainPanel() {
1440 private Phylogeny getSpeciesTree() {
1441 return _species_tree;
1444 private boolean isScreenAntialias() {
1448 private void removeBranchColors() {
1449 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1450 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1454 private void setMainPanel( final MainPanelApplets main_panel ) {
1455 _mainpanel = main_panel;
1458 private void setSpeciesTree( final Phylogeny species_tree ) {
1459 _species_tree = species_tree;
1462 private void setupUI() {
1464 if ( getConfiguration().isUseNativeUI() ) {
1465 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1468 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1471 catch ( final UnsupportedLookAndFeelException e ) {
1472 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1474 catch ( final ClassNotFoundException e ) {
1475 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1477 catch ( final InstantiationException e ) {
1478 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1480 catch ( final IllegalAccessException e ) {
1481 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1483 catch ( final Exception e ) {
1484 AptxUtil.dieWithSystemError( e.toString() );
1488 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1489 for( final TreePanel tree_panel : treepanels ) {
1490 tree_panel.setTextAntialias();