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 _show_annotation_ref_source;
101 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
102 private JCheckBoxMenuItem _abbreviate_scientific_names;
103 private JCheckBoxMenuItem _screen_antialias_cbmi;
104 private JCheckBoxMenuItem _background_gradient_cbmi;
105 private JCheckBoxMenuItem _color_by_taxonomic_group_cbmi;
106 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
107 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
108 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
109 private Options _options;
110 private JMenuItem _choose_font_mi;
111 private JMenuItem _switch_colors_mi;
112 JCheckBoxMenuItem _label_direction_cbmi;
113 private JCheckBoxMenuItem _show_scale_cbmi;
114 private JCheckBoxMenuItem _search_case_senstive_cbmi;
115 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
116 private JCheckBoxMenuItem _inverse_search_result_cbmi;
117 private JCheckBoxMenuItem _show_overview_cbmi;
118 private JMenuItem _choose_minimal_confidence_mi;
119 private JCheckBoxMenuItem _show_branch_length_values_cbmi;
120 private JMenuItem _collapse_species_specific_subtrees;
121 private JMenuItem _overview_placment_mi;
122 private ButtonGroup _radio_group_1;
123 private JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
124 private JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
125 private JMenuItem _cycle_node_shape_mi;
126 private JMenuItem _cycle_node_fill_mi;
127 private JMenuItem _choose_node_size_mi;
128 private JCheckBoxMenuItem _show_confidence_stddev_cbmi;
129 private final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>();
130 private JMenu _analysis_menu;
131 private JMenuItem _gsdi_item;
132 private JMenuItem _gsdir_item;
133 private Phylogeny _species_tree;
136 public void actionPerformed( final ActionEvent e ) {
137 final Object o = e.getSource();
138 if ( o == _midpoint_root_item ) {
139 getMainPanel().getCurrentTreePanel().midpointRoot();
141 else if ( o == _gsdi_item ) {
142 if ( isSubtreeDisplayed() ) {
147 else if ( o == _gsdir_item ) {
148 if ( isSubtreeDisplayed() ) {
153 else if ( o == _taxcolor_item ) {
154 getMainPanel().getCurrentTreePanel().taxColor();
156 else if ( o == _confcolor_item ) {
157 getMainPanel().getCurrentTreePanel().confColor();
159 else if ( o == _collapse_species_specific_subtrees ) {
160 if ( getCurrentTreePanel() != null ) {
161 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
164 else if ( o == _remove_branch_color_item ) {
165 removeBranchColors();
167 else if ( o == _switch_colors_mi ) {
170 else if ( o == _display_basic_information_item ) {
171 displayBasicInformation();
173 else if ( o == _view_as_NH_item ) {
176 else if ( o == _view_as_XML_item ) {
179 else if ( o == _view_as_nexus_item ) {
182 else if ( o == _super_tiny_fonts_mi ) {
183 if ( getCurrentTreePanel() != null ) {
184 getCurrentTreePanel().setSuperTinyFonts();
185 getCurrentTreePanel().repaint();
188 else if ( o == _tiny_fonts_mi ) {
189 if ( getCurrentTreePanel() != null ) {
190 getCurrentTreePanel().setTinyFonts();
191 getCurrentTreePanel().repaint();
194 else if ( o == _small_fonts_mi ) {
195 if ( getCurrentTreePanel() != null ) {
196 getCurrentTreePanel().setSmallFonts();
197 getCurrentTreePanel().repaint();
200 else if ( o == _medium_fonts_mi ) {
201 if ( getCurrentTreePanel() != null ) {
202 getCurrentTreePanel().setMediumFonts();
203 getCurrentTreePanel().repaint();
206 else if ( o == _large_fonts_mi ) {
207 if ( getCurrentTreePanel() != null ) {
208 getCurrentTreePanel().setLargeFonts();
209 getCurrentTreePanel().repaint();
212 else if ( o == _choose_font_mi ) {
215 else if ( o == _choose_minimal_confidence_mi ) {
216 chooseMinimalConfidence();
218 else if ( o == _choose_node_size_mi ) {
219 MainFrame.chooseNodeSize( getOptions(), this );
221 else if ( o == _overview_placment_mi ) {
222 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
224 else if ( o == _cycle_node_fill_mi ) {
225 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
227 else if ( o == _cycle_node_shape_mi ) {
228 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
230 else if ( o == _non_lined_up_cladograms_rbmi ) {
231 updateOptions( getOptions() );
232 _mainpanel.getControlPanel().showWhole();
234 else if ( o == _uniform_cladograms_rbmi ) {
235 updateOptions( getOptions() );
236 _mainpanel.getControlPanel().showWhole();
238 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
239 updateOptions( getOptions() );
240 _mainpanel.getControlPanel().showWhole();
242 else if ( o == _search_case_senstive_cbmi ) {
243 updateOptions( getOptions() );
244 getMainPanel().getControlPanel().search0();
245 getMainPanel().getControlPanel().search1();
247 else if ( o == _search_whole_words_only_cbmi ) {
248 updateOptions( getOptions() );
249 getMainPanel().getControlPanel().search0();
250 getMainPanel().getControlPanel().search1();
252 else if ( o == _inverse_search_result_cbmi ) {
253 updateOptions( getOptions() );
254 getMainPanel().getControlPanel().search0();
255 getMainPanel().getControlPanel().search1();
257 else if ( o == _show_scale_cbmi ) {
258 updateOptions( getOptions() );
260 else if ( o == _show_branch_length_values_cbmi ) {
261 updateOptions( getOptions() );
263 else if ( o == _show_confidence_stddev_cbmi ) {
264 updateOptions( getOptions() );
266 else if ( o == _label_direction_cbmi ) {
267 updateOptions( getOptions() );
269 else if ( o == _abbreviate_scientific_names ) {
270 updateOptions( getOptions() );
272 else if ( o == _show_overview_cbmi ) {
273 updateOptions( getOptions() );
274 if ( getCurrentTreePanel() != null ) {
275 getCurrentTreePanel().updateOvSizes();
278 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
279 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
280 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
283 else if ( o == _screen_antialias_cbmi ) {
284 updateOptions( getOptions() );
285 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
287 else if ( o == _background_gradient_cbmi ) {
288 updateOptions( getOptions() );
290 else if ( o == _show_domain_labels ) {
291 updateOptions( getOptions() );
293 else if ( o == _color_labels_same_as_parent_branch ) {
294 updateOptions( getOptions() );
296 else if ( o == _show_default_node_shapes_internal_cbmi ) {
297 updateOptions( getOptions() );
299 else if ( o == _show_default_node_shapes_external_cbmi ) {
300 updateOptions( getOptions() );
302 else if ( o == _about_item ) {
305 else if ( o == _help_item ) {
308 else if ( o == _website_item ) {
310 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
312 catch ( final IOException e1 ) {
313 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
316 else if ( o == _phyloxml_website_item ) {
318 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
320 catch ( final IOException e1 ) {
321 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
324 else if ( o == _aptx_ref_item ) {
326 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
328 catch ( final IOException e1 ) {
329 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
332 else if ( o == _phyloxml_ref_item ) {
334 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
336 catch ( final IOException e1 ) {
337 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
340 else if ( o == _color_by_taxonomic_group_cbmi ) {
341 updateOptions( getOptions() );
347 public void destroy() {
348 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
349 removeAllTextFrames();
350 if ( getMainPanel() != null ) {
351 getMainPanel().terminate();
356 * This method returns the current external node data which
357 * has been selected by the user by clicking the "Return ..."
358 * menu item. This method is expected to be called from Javascript or
361 * @return current external node data as String
363 public String getCurrentExternalNodesDataBuffer() {
364 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
367 public int getCurrentExternalNodesDataBufferChangeCounter() {
368 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
371 public int getCurrentExternalNodesDataBufferLength() {
372 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
376 * This method returns the current phylogeny as a string in the chosen format
378 * @param format must be NH, NHX, NEXUS or PHYLOXML
379 * @return the phylogeny string
380 * @author Herve Menager
382 public String getCurrentPhylogeny( final String format ) {
383 removeAllTextFrames();
384 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
385 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
388 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
390 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
392 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
394 return getMainPanel().getCurrentPhylogeny().toNexus();
396 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
404 * This method returns a view of the current phylogeny in a chosen
405 * graphics format, base64-encoded in a string so that in can be used
408 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
409 * @return the phylogeny string
410 * @author Herve Menager
412 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
413 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
415 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
416 _mainpanel.getWidth(),
417 _mainpanel.getHeight(),
418 getCurrentTreePanel(),
419 getCurrentTreePanel().getControlPanel(),
420 GraphicsExportType.valueOf( format ),
423 catch ( final IOException ioe ) {
424 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
425 ioe.printStackTrace();
426 JOptionPane.showMessageDialog( this,
427 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
428 "Failed to generate graphics",
429 JOptionPane.ERROR_MESSAGE );
432 final byte[] bytes = baos.toByteArray();
433 final String dataImg = Base64.encodeBase64String( bytes );
437 public Options getOptions() {
443 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
444 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
445 final Configuration configuration = new Configuration( config_filename, true, true, true );
446 setConfiguration( configuration );
447 setOptions( Options.createInstance( configuration ) );
450 Phylogeny[] phys = null;
451 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
452 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
453 // Get URL to tree file
454 if ( tree_url_str != null ) {
456 phys_url = new URL( tree_url_str );
458 catch ( final Exception e ) {
459 ForesterUtil.printErrorMessage( NAME, "error: " + e );
461 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
462 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
465 // Load the tree from URL
466 if ( phys_url != null ) {
468 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
469 getConfiguration().isValidatePhyloXmlAgainstSchema(),
470 getConfiguration().isReplaceUnderscoresInNhParsing(),
471 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
472 getConfiguration().getTaxonomyExtraction(),
473 getConfiguration().isMidpointReroot() );
475 catch ( final Exception e ) {
476 ForesterUtil.printErrorMessage( NAME, e.toString() );
478 JOptionPane.showMessageDialog( this,
479 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
480 "Failed to read phylogenies",
481 JOptionPane.ERROR_MESSAGE );
484 if ( ( phys == null ) || ( phys.length < 1 ) ) {
485 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
486 JOptionPane.showMessageDialog( this,
487 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
488 "Failed to read phylogenies",
489 JOptionPane.ERROR_MESSAGE );
493 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
496 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
497 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
498 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
499 Phylogeny[] species_trees = null;
501 final URL species_tree_url = new URL( species_tree_url_str );
502 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
503 configuration.isValidatePhyloXmlAgainstSchema(),
504 configuration.isReplaceUnderscoresInNhParsing(),
506 TAXONOMY_EXTRACTION.NO,
509 catch ( final IOException e ) {
510 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
512 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
513 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
515 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
516 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
517 if ( species_trees[ 0 ].isEmpty() ) {
518 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
520 else if ( !species_trees[ 0 ].isRooted() ) {
521 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
524 setSpeciesTree( species_trees[ 0 ] );
525 AptxUtil.printAppletMessage( NAME, "species tree OK" );
531 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
532 _jmenubar = new JMenuBar();
533 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
534 if ( !getConfiguration().isUseNativeUI() ) {
535 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
537 if ( getSpeciesTree() != null ) {
546 setJMenuBar( _jmenubar );
548 final Container contentpane = getContentPane();
549 contentpane.setLayout( new BorderLayout() );
550 contentpane.add( getMainPanel(), BorderLayout.CENTER );
551 addComponentListener( new ComponentAdapter() {
554 public void componentResized( final ComponentEvent e ) {
555 if ( getMainPanel().getCurrentTreePanel() != null ) {
556 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
557 .getCurrentTreePanel()
560 .getCurrentTreePanel()
563 .isAllowFontSizeChange() );
567 if ( getConfiguration().isUseTabbedDisplay() ) {
568 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
569 AptxUtil.addPhylogeniesToTabs( phys,
570 new File( phys_url.getFile() ).getName(),
576 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
577 if ( getSpeciesTree() != null ) {
578 AptxUtil.printAppletMessage( NAME,
579 "Warning: gsdi (gene duplication inference) only available tabbed display" );
581 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
585 getMainPanel().getControlPanel().showWholeAll();
586 getMainPanel().getControlPanel().showWhole();
588 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
590 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
591 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
592 .getRelevantSequenceRelationTypes() ) {
593 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
595 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
596 if ( default_relation != null ) {
597 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
599 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
600 if ( default_sequence != null ) {
601 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
607 public void showTextFrame( final String s, final String title ) {
609 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
613 public void start() {
614 if ( getMainPanel() != null ) {
615 getMainPanel().validate();
618 requestFocusInWindow();
620 AptxUtil.printAppletMessage( NAME, "started" );
623 void buildAnalysisMenu() {
624 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
625 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
626 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
627 customizeJMenuItem( _gsdi_item );
628 customizeJMenuItem( _gsdir_item );
629 // _analysis_menu.addSeparator();
630 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
631 // customizeJMenuItem( _lineage_inference );
632 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
633 _jmenubar.add( _analysis_menu );
636 void buildFontSizeMenu() {
637 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
638 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
639 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
640 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
641 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
642 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
643 customizeJMenuItem( _super_tiny_fonts_mi );
644 customizeJMenuItem( _tiny_fonts_mi );
645 customizeJMenuItem( _small_fonts_mi );
646 customizeJMenuItem( _medium_fonts_mi );
647 customizeJMenuItem( _large_fonts_mi );
648 _jmenubar.add( _font_size_menu );
651 void buildHelpMenu() {
652 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
653 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
654 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
655 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
656 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
657 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
658 _help_jmenu.addSeparator();
659 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
660 customizeJMenuItem( _help_item );
661 customizeJMenuItem( _website_item );
662 customizeJMenuItem( _phyloxml_website_item );
663 customizeJMenuItem( _aptx_ref_item );
664 customizeJMenuItem( _phyloxml_ref_item );
665 customizeJMenuItem( _about_item );
666 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
667 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
668 _jmenubar.add( _help_jmenu );
671 void buildOptionsMenu() {
672 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
673 _options_jmenu.addChangeListener( new ChangeListener() {
676 public void stateChanged( final ChangeEvent e ) {
677 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
678 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
680 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
681 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
682 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
683 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
685 _show_branch_length_values_cbmi,
686 _non_lined_up_cladograms_rbmi,
687 _uniform_cladograms_rbmi,
688 _ext_node_dependent_cladogram_rbmi,
689 _label_direction_cbmi );
690 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
691 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
692 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
695 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
696 getConfiguration() ) );
698 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
699 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
701 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
702 _radio_group_1 = new ButtonGroup();
703 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
704 _radio_group_1.add( _uniform_cladograms_rbmi );
705 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
707 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
708 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
710 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
712 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
714 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
715 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
716 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
718 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
719 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
721 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
723 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
724 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
725 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
726 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
727 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
728 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
729 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
730 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
731 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
732 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
733 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
734 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
735 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
736 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
738 _options_jmenu.addSeparator();
739 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
740 getConfiguration() ) );
742 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
743 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
745 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
746 customizeJMenuItem( _choose_font_mi );
747 customizeJMenuItem( _choose_minimal_confidence_mi );
748 customizeJMenuItem( _switch_colors_mi );
749 customizeJMenuItem( _overview_placment_mi );
750 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
751 customizeCheckBoxMenuItem( _label_direction_cbmi,
752 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
753 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
754 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
755 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
756 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
757 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
758 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
759 .isShowDefaultNodeShapesExternal() );
760 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
761 .isShowDefaultNodeShapesInternal() );
762 customizeJMenuItem( _cycle_node_shape_mi );
763 customizeJMenuItem( _cycle_node_fill_mi );
764 customizeJMenuItem( _choose_node_size_mi );
765 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
766 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
767 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
768 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
769 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
770 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
771 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
772 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
773 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
774 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
775 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
776 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
777 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
778 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
779 _jmenubar.add( _options_jmenu );
782 void buildToolsMenu() {
783 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
784 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
785 customizeJMenuItem( _confcolor_item );
786 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
787 customizeJMenuItem( _taxcolor_item );
788 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
789 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
790 customizeJMenuItem( _remove_branch_color_item );
791 _tools_menu.addSeparator();
792 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
793 customizeJMenuItem( _midpoint_root_item );
794 _tools_menu.addSeparator();
795 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
796 customizeJMenuItem( _collapse_species_specific_subtrees );
797 _jmenubar.add( _tools_menu );
800 void buildTypeMenu() {
801 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
802 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
803 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
804 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
805 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
806 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
807 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
808 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
809 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
810 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
811 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
812 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
813 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
814 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
815 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
816 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
817 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
818 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
819 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
820 initializeTypeMenu( getOptions() );
821 _jmenubar.add( _type_menu );
824 void buildViewMenu() {
825 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
827 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
828 _view_jmenu.addSeparator();
829 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
830 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
831 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
832 customizeJMenuItem( _display_basic_information_item );
833 customizeJMenuItem( _view_as_NH_item );
834 customizeJMenuItem( _view_as_XML_item );
835 customizeJMenuItem( _view_as_nexus_item );
836 _jmenubar.add( _view_jmenu );
839 void checkTextFrames() {
840 if ( _textframes.size() > 5 ) {
842 if ( _textframes.getFirst() != null ) {
843 _textframes.getFirst().removeMe();
846 _textframes.removeFirst();
849 catch ( final NoSuchElementException e ) {
855 void clearCurrentExternalNodesDataBuffer() {
856 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
859 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
860 if ( item != null ) {
861 item.setFont( MainFrame.menu_font );
862 if ( !getConfiguration().isUseNativeUI() ) {
863 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
864 item.setForeground( getConfiguration().getGuiMenuTextColor() );
866 item.setSelected( is_selected );
867 item.addActionListener( this );
871 void customizeJMenuItem( final JMenuItem jmi ) {
872 jmi.setFont( MainFrame.menu_font );
873 if ( !getConfiguration().isUseNativeUI() ) {
874 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
875 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
877 jmi.addActionListener( this );
880 void displayBasicInformation() {
881 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
882 String title = "Basic Information";
883 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
884 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
886 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
891 if ( !isOKforSDI( false, true ) ) {
894 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
895 JOptionPane.showMessageDialog( this,
896 "Gene tree is not rooted.",
897 "Cannot execute GSDI",
898 JOptionPane.ERROR_MESSAGE );
901 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
902 gene_tree.setAllNodesToNotCollapse();
903 gene_tree.recalculateNumberOfExternalDescendants( false );
905 final Phylogeny species_tree = _species_tree.copy();
907 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
909 catch ( final SDIException e ) {
910 JOptionPane.showMessageDialog( this,
911 e.getLocalizedMessage(),
913 JOptionPane.ERROR_MESSAGE );
916 catch ( final Exception e ) {
917 AptxUtil.unexpectedException( e );
920 gene_tree.setRerootable( false );
921 gene_tree.clearHashIdToNodeMap();
922 gene_tree.recalculateNumberOfExternalDescendants( true );
923 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
924 getMainPanel().getControlPanel().setShowEvents( true );
926 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
927 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
929 _mainpanel.getTabbedPane().setSelectedIndex( selected );
931 _mainpanel.getCurrentTreePanel().setEdited( true );
932 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
933 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
934 JOptionPane.showMessageDialog( this,
935 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
936 + "Potential duplications: "
937 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
938 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
939 + "Stripped gene tree nodes: "
940 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
941 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
942 + "Number of polytomies in species tree used: " + poly + "\n",
943 "GSDI successfully completed",
944 JOptionPane.WARNING_MESSAGE );
947 JOptionPane.showMessageDialog( this,
948 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
949 + "Potential duplications: "
950 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
951 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
952 + "Stripped gene tree nodes: "
953 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
954 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
955 + "Number of polytomies in species tree used: " + poly + "\n",
956 "GSDI successfully completed",
957 JOptionPane.INFORMATION_MESSAGE );
961 void executeGSDIR() {
962 if ( !isOKforSDI( false, false ) ) {
965 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
967 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
968 JOptionPane.showMessageDialog( this,
969 "Gene tree is not completely binary",
970 "Cannot execute GSDI",
971 JOptionPane.ERROR_MESSAGE );
974 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
975 gene_tree.setAllNodesToNotCollapse();
976 gene_tree.recalculateNumberOfExternalDescendants( false );
978 final Phylogeny species_tree = _species_tree.copy();
980 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
982 catch ( final SDIException e ) {
983 JOptionPane.showMessageDialog( this,
984 e.getLocalizedMessage(),
985 "Error during GSDIR",
986 JOptionPane.ERROR_MESSAGE );
989 catch ( final Exception e ) {
990 AptxUtil.unexpectedException( e );
993 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
994 result_gene_tree.setRerootable( false );
995 result_gene_tree.clearHashIdToNodeMap();
996 result_gene_tree.recalculateNumberOfExternalDescendants( true );
997 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
998 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
999 getMainPanel().getControlPanel().setShowEvents( true );
1001 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1002 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1004 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1006 _mainpanel.getCurrentTreePanel().setEdited( true );
1007 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1008 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1009 JOptionPane.showMessageDialog( this,
1010 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1011 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1012 + "Stripped gene tree nodes: "
1013 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1014 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1015 + "Number of polytomies in species tree used: " + poly + "\n",
1016 "GSDIR successfully completed",
1017 JOptionPane.WARNING_MESSAGE );
1020 JOptionPane.showMessageDialog( this,
1021 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1022 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1023 + "Stripped gene tree nodes: "
1024 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1025 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1026 + "Number of polytomies in species tree used: " + poly + "\n",
1027 "GSDIR successfully completed",
1028 JOptionPane.INFORMATION_MESSAGE );
1032 Configuration getConfiguration() {
1033 return _configuration;
1036 TreePanel getCurrentTreePanel() {
1037 return getMainPanel().getCurrentTreePanel();
1040 JCheckBoxMenuItem getlabelDirectionCbmi() {
1041 return _label_direction_cbmi;
1044 Options getOtions() {
1049 final StringBuilder sb = new StringBuilder();
1050 sb.append( "Display options\n" );
1051 sb.append( "-------------------\n" );
1052 sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
1053 sb.append( "Clickable tree nodes\n" );
1054 sb.append( "--------------------\n" );
1055 sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
1056 sb.append( "or by right clicking:\n" );
1057 sb.append( "o Display Node Data -- display information for a node\n" );
1058 sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
1059 sb.append( "o Root/Reroot -- change tree root to clicked node\n" );
1060 sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
1061 sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" );
1062 sb.append( "o Colorize Subtree -- color a subtree\n" );
1063 sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" );
1064 sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
1065 sb.append( "- there may be additional choices depending on this particular setup\n\n" );
1066 sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
1067 sb.append( "Zooming\n" );
1068 sb.append( "---------\n" );
1069 sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
1070 sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
1071 sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
1072 sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
1073 sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
1074 sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
1075 sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
1076 sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
1077 sb.append( "Quick tree manipulation:\n" );
1078 sb.append( "------------------------\n" );
1079 sb.append( "Order Subtrees -- order the tree by branch length\n" );
1080 sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
1081 sb.append( "phyloXML\n" );
1082 sb.append( "-------------------\n" );
1083 sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
1084 sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
1085 sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1087 sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
1088 sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
1089 TextFrame.instantiate( sb.toString(), "Help", _textframes );
1092 void initializeTypeMenu( final Options options ) {
1093 setTypeMenuToAllUnselected();
1095 switch ( options.getPhylogenyGraphicsType() ) {
1097 _convex_type_cbmi.setSelected( true );
1100 _curved_type_cbmi.setSelected( true );
1103 _euro_type_cbmi.setSelected( true );
1106 _rounded_type_cbmi.setSelected( true );
1109 _triangular_type_cbmi.setSelected( true );
1112 _unrooted_type_cbmi.setSelected( true );
1115 _circular_type_cbmi.setSelected( true );
1118 _rectangular_type_cbmi.setSelected( true );
1122 catch ( final NullPointerException np ) {
1123 // In all likelihood, this is caused by menu-less display.
1127 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1128 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1131 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1132 JOptionPane.showMessageDialog( this,
1133 "No species tree loaded",
1134 "Cannot execute GSDI",
1135 JOptionPane.ERROR_MESSAGE );
1138 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1139 JOptionPane.showMessageDialog( this,
1140 "Species tree is not completely binary",
1141 "Cannot execute GSDI",
1142 JOptionPane.ERROR_MESSAGE );
1145 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1146 JOptionPane.showMessageDialog( this,
1147 "Gene tree is not completely binary",
1148 "Cannot execute GSDI",
1149 JOptionPane.ERROR_MESSAGE );
1157 boolean isSubtreeDisplayed() {
1158 if ( getCurrentTreePanel() != null ) {
1159 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1161 .showMessageDialog( this,
1162 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1163 "Operation can not be exectuted on a sub-tree",
1164 JOptionPane.WARNING_MESSAGE );
1171 void removeAllTextFrames() {
1172 for( final TextFrame tf : _textframes ) {
1177 _textframes.clear();
1180 void setConfiguration( final Configuration configuration ) {
1181 _configuration = configuration;
1184 void setOptions( final Options options ) {
1188 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1189 setTypeMenuToAllUnselected();
1193 _circular_type_cbmi.setSelected( true );
1196 _convex_type_cbmi.setSelected( true );
1199 _curved_type_cbmi.setSelected( true );
1202 _euro_type_cbmi.setSelected( true );
1205 _rounded_type_cbmi.setSelected( true );
1208 _rectangular_type_cbmi.setSelected( true );
1211 _triangular_type_cbmi.setSelected( true );
1214 _unrooted_type_cbmi.setSelected( true );
1217 throw new IllegalArgumentException( "unknown type: " + type );
1220 catch ( final NullPointerException np ) {
1221 // In all likelihood, this is caused by menu-less display.
1225 void setTypeMenuToAllUnselected() {
1226 if ( _convex_type_cbmi != null ) {
1227 _convex_type_cbmi.setSelected( false );
1229 if ( _curved_type_cbmi != null ) {
1230 _curved_type_cbmi.setSelected( false );
1232 if ( _euro_type_cbmi != null ) {
1233 _euro_type_cbmi.setSelected( false );
1235 if ( _rounded_type_cbmi != null ) {
1236 _rounded_type_cbmi.setSelected( false );
1238 if ( _triangular_type_cbmi != null ) {
1239 _triangular_type_cbmi.setSelected( false );
1241 if ( _rectangular_type_cbmi != null ) {
1242 _rectangular_type_cbmi.setSelected( false );
1244 if ( _unrooted_type_cbmi != null ) {
1245 _unrooted_type_cbmi.setSelected( false );
1247 if ( _circular_type_cbmi != null ) {
1248 _circular_type_cbmi.setSelected( false );
1253 _mainpanel.getControlPanel().showWhole();
1256 void switchColors() {
1257 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1258 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1259 csc.setVisible( true );
1260 getMainPanel().setTreeColorSet( colorset );
1263 void typeChanged( final Object o ) {
1264 updateTypeCheckboxes( getOptions(), o );
1265 updateOptions( getOptions() );
1266 if ( getCurrentTreePanel() != null ) {
1267 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1268 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1269 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1270 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1271 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1272 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1273 getCurrentTreePanel().getControlPanel().showWhole();
1275 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1276 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1279 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1281 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1282 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1286 void updateOptions( final Options options ) {
1287 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1288 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1289 && _background_gradient_cbmi.isSelected() );
1290 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1291 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1292 && _show_annotation_ref_source.isSelected() );
1293 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1294 && _abbreviate_scientific_names.isSelected() );
1295 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1296 && _color_labels_same_as_parent_branch.isSelected() );
1297 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1298 && _show_default_node_shapes_internal_cbmi.isSelected() );
1299 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1300 && _show_default_node_shapes_external_cbmi.isSelected() );
1301 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1302 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1304 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1305 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1307 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1308 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1310 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1311 && _search_case_senstive_cbmi.isSelected() );
1312 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1313 options.setShowScale( _show_scale_cbmi.isSelected() );
1315 if ( _label_direction_cbmi != null ) {
1316 if ( _label_direction_cbmi.isSelected() ) {
1317 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1320 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1323 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1324 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1325 && _show_confidence_stddev_cbmi.isSelected() );
1326 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1327 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1329 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1330 && _search_whole_words_only_cbmi.isSelected() );
1331 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1332 && _inverse_search_result_cbmi.isSelected() );
1333 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1334 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1336 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1337 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1339 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1340 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1342 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1343 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1345 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1346 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1348 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1349 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1351 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1352 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1354 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1355 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1357 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1358 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1362 void updateTypeCheckboxes( final Options options, final Object o ) {
1363 setTypeMenuToAllUnselected();
1364 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1367 void viewAsNexus() {
1368 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1369 String title = "Nexus";
1370 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1371 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1373 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1374 .getNhConversionSupportValueStyle() ),
1380 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1381 String title = "New Hampshire";
1382 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1383 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1385 showTextFrame( getMainPanel().getCurrentPhylogeny()
1386 .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1392 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1393 String title = "phyloXML";
1394 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1395 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1397 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1401 private void chooseFont() {
1402 final FontChooser fc = new FontChooser();
1403 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1404 fc.showDialog( this, "Select the Base Font" );
1405 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1408 private void chooseMinimalConfidence() {
1409 final String s = ( String ) JOptionPane
1410 .showInputDialog( this,
1411 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1412 + getOptions().getMinConfidenceValue() + "]\n",
1413 "Minimal Confidence Value",
1414 JOptionPane.QUESTION_MESSAGE,
1417 getOptions().getMinConfidenceValue() );
1418 if ( !ForesterUtil.isEmpty( s ) ) {
1419 boolean success = true;
1421 final String m_str = s.trim();
1422 if ( !ForesterUtil.isEmpty( m_str ) ) {
1424 m = Double.parseDouble( m_str );
1426 catch ( final Exception ex ) {
1433 if ( success && ( m >= 0.0 ) ) {
1434 getOptions().setMinConfidenceValue( m );
1439 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1440 if ( item != null ) {
1441 item.setFont( MainFrame.menu_font );
1442 if ( !getConfiguration().isUseNativeUI() ) {
1443 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1444 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1446 item.setSelected( is_selected );
1447 item.addActionListener( this );
1451 private MainPanel getMainPanel() {
1455 private Phylogeny getSpeciesTree() {
1456 return _species_tree;
1459 private boolean isScreenAntialias() {
1463 private void removeBranchColors() {
1464 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1465 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1469 private void setMainPanel( final MainPanelApplets main_panel ) {
1470 _mainpanel = main_panel;
1473 private void setSpeciesTree( final Phylogeny species_tree ) {
1474 _species_tree = species_tree;
1477 private void setupUI() {
1479 if ( getConfiguration().isUseNativeUI() ) {
1480 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1483 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1486 catch ( final UnsupportedLookAndFeelException e ) {
1487 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1489 catch ( final ClassNotFoundException e ) {
1490 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1492 catch ( final InstantiationException e ) {
1493 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1495 catch ( final IllegalAccessException e ) {
1496 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1498 catch ( final Exception e ) {
1499 AptxUtil.dieWithSystemError( e.toString() );
1503 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1504 for( final TreePanel tree_panel : treepanels ) {
1505 tree_panel.setTextAntialias();