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 JMenuItem _remove_visual_styles_item;
100 private JCheckBoxMenuItem _show_domain_labels;
101 private JCheckBoxMenuItem _show_annotation_ref_source;
102 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
103 private JCheckBoxMenuItem _abbreviate_scientific_names;
104 private JCheckBoxMenuItem _screen_antialias_cbmi;
105 private JCheckBoxMenuItem _background_gradient_cbmi;
106 private JCheckBoxMenuItem _color_by_taxonomic_group_cbmi;
107 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
108 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
109 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
110 private Options _options;
111 private JMenuItem _choose_font_mi;
112 private JMenuItem _switch_colors_mi;
113 JCheckBoxMenuItem _label_direction_cbmi;
114 private JCheckBoxMenuItem _show_scale_cbmi;
115 private JCheckBoxMenuItem _search_case_senstive_cbmi;
116 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
117 private JCheckBoxMenuItem _inverse_search_result_cbmi;
118 private JCheckBoxMenuItem _show_overview_cbmi;
119 private JMenuItem _choose_minimal_confidence_mi;
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;
134 private JCheckBoxMenuItem _right_line_up_domains_cbmi;
135 private JCheckBoxMenuItem _line_up_renderable_data_cbmi;
138 public void actionPerformed( final ActionEvent e ) {
139 final Object o = e.getSource();
140 if ( o == _midpoint_root_item ) {
141 getMainPanel().getCurrentTreePanel().midpointRoot();
143 else if ( o == _gsdi_item ) {
144 if ( isSubtreeDisplayed() ) {
149 else if ( o == _gsdir_item ) {
150 if ( isSubtreeDisplayed() ) {
155 else if ( o == _taxcolor_item ) {
156 getMainPanel().getCurrentTreePanel().taxColor();
158 else if ( o == _confcolor_item ) {
159 getMainPanel().getCurrentTreePanel().confColor();
161 else if ( o == _collapse_species_specific_subtrees ) {
162 if ( getCurrentTreePanel() != null ) {
163 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
166 else if ( o == _remove_branch_color_item ) {
167 removeBranchColors();
169 else if ( o == _remove_visual_styles_item ) {
170 removeVisualStyles();
172 else if ( o == _switch_colors_mi ) {
175 else if ( o == _display_basic_information_item ) {
176 displayBasicInformation();
178 else if ( o == _view_as_NH_item ) {
181 else if ( o == _view_as_XML_item ) {
184 else if ( o == _view_as_nexus_item ) {
187 else if ( o == _super_tiny_fonts_mi ) {
188 if ( getCurrentTreePanel() != null ) {
189 getCurrentTreePanel().setSuperTinyFonts();
190 getCurrentTreePanel().repaint();
193 else if ( o == _tiny_fonts_mi ) {
194 if ( getCurrentTreePanel() != null ) {
195 getCurrentTreePanel().setTinyFonts();
196 getCurrentTreePanel().repaint();
199 else if ( o == _small_fonts_mi ) {
200 if ( getCurrentTreePanel() != null ) {
201 getCurrentTreePanel().setSmallFonts();
202 getCurrentTreePanel().repaint();
205 else if ( o == _medium_fonts_mi ) {
206 if ( getCurrentTreePanel() != null ) {
207 getCurrentTreePanel().setMediumFonts();
208 getCurrentTreePanel().repaint();
211 else if ( o == _large_fonts_mi ) {
212 if ( getCurrentTreePanel() != null ) {
213 getCurrentTreePanel().setLargeFonts();
214 getCurrentTreePanel().repaint();
217 else if ( o == _choose_font_mi ) {
220 else if ( o == _choose_minimal_confidence_mi ) {
221 chooseMinimalConfidence();
223 else if ( o == _choose_node_size_mi ) {
224 MainFrame.chooseNodeSize( getOptions(), this );
226 else if ( o == _overview_placment_mi ) {
227 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
229 else if ( o == _cycle_node_fill_mi ) {
230 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
232 else if ( o == _cycle_node_shape_mi ) {
233 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
235 else if ( o == _non_lined_up_cladograms_rbmi ) {
236 updateOptions( getOptions() );
237 _mainpanel.getControlPanel().showWhole();
239 else if ( o == _uniform_cladograms_rbmi ) {
240 updateOptions( getOptions() );
241 _mainpanel.getControlPanel().showWhole();
243 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
244 updateOptions( getOptions() );
245 _mainpanel.getControlPanel().showWhole();
247 else if ( o == _search_case_senstive_cbmi ) {
248 updateOptions( getOptions() );
249 getMainPanel().getControlPanel().search0();
250 getMainPanel().getControlPanel().search1();
252 else if ( o == _search_whole_words_only_cbmi ) {
253 updateOptions( getOptions() );
254 getMainPanel().getControlPanel().search0();
255 getMainPanel().getControlPanel().search1();
257 else if ( o == _inverse_search_result_cbmi ) {
258 updateOptions( getOptions() );
259 getMainPanel().getControlPanel().search0();
260 getMainPanel().getControlPanel().search1();
262 else if ( o == _show_scale_cbmi ) {
263 updateOptions( getOptions() );
265 else if ( o == _show_confidence_stddev_cbmi ) {
266 updateOptions( getOptions() );
268 else if ( o == _label_direction_cbmi ) {
269 updateOptions( getOptions() );
271 else if ( o == _abbreviate_scientific_names ) {
272 updateOptions( getOptions() );
274 else if ( o == _show_overview_cbmi ) {
275 updateOptions( getOptions() );
276 if ( getCurrentTreePanel() != null ) {
277 getCurrentTreePanel().updateOvSizes();
280 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
281 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
282 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
285 else if ( o == _screen_antialias_cbmi ) {
286 updateOptions( getOptions() );
287 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
289 else if ( o == _background_gradient_cbmi ) {
290 updateOptions( getOptions() );
292 else if ( o == _show_domain_labels ) {
293 updateOptions( getOptions() );
295 else if ( o == _color_labels_same_as_parent_branch ) {
296 updateOptions( getOptions() );
298 else if ( o == _show_default_node_shapes_internal_cbmi ) {
299 updateOptions( getOptions() );
301 else if ( o == _show_default_node_shapes_external_cbmi ) {
302 updateOptions( getOptions() );
304 else if ( o == _about_item ) {
307 else if ( o == _help_item ) {
309 AptxUtil.openWebsite( Constants.APTX_DOC_SITE, true, this );
311 catch ( final IOException e1 ) {
312 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
315 else if ( o == _website_item ) {
317 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
319 catch ( final IOException e1 ) {
320 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
323 else if ( o == _phyloxml_website_item ) {
325 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
327 catch ( final IOException e1 ) {
328 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
331 else if ( o == _aptx_ref_item ) {
333 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
335 catch ( final IOException e1 ) {
336 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
339 else if ( o == _phyloxml_ref_item ) {
341 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
343 catch ( final IOException e1 ) {
344 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
347 else if ( o == _color_by_taxonomic_group_cbmi ) {
348 updateOptions( getOptions() );
350 else if ( o == _line_up_renderable_data_cbmi ) {
351 if ( !_line_up_renderable_data_cbmi.isSelected() ) {
352 _right_line_up_domains_cbmi.setSelected( false );
354 updateOptions( getOptions() );
356 else if ( o == _right_line_up_domains_cbmi ) {
357 if ( _right_line_up_domains_cbmi.isSelected() ) {
358 _line_up_renderable_data_cbmi.setSelected( true );
360 updateOptions( getOptions() );
366 public void destroy() {
367 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
368 removeAllTextFrames();
369 if ( getMainPanel() != null ) {
370 getMainPanel().terminate();
375 * This method returns the current external node data which
376 * has been selected by the user by clicking the "Return ..."
377 * menu item. This method is expected to be called from Javascript or
380 * @return current external node data as String
382 public String getCurrentExternalNodesDataBuffer() {
383 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
386 public int getCurrentExternalNodesDataBufferChangeCounter() {
387 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
390 public int getCurrentExternalNodesDataBufferLength() {
391 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
395 * This method returns the current phylogeny as a string in the chosen format
397 * @param format must be NH, NHX, NEXUS or PHYLOXML
398 * @return the phylogeny string
399 * @author Herve Menager
401 public String getCurrentPhylogeny( final String format ) {
402 removeAllTextFrames();
403 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
404 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
407 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
409 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
411 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
413 return getMainPanel().getCurrentPhylogeny().toNexus();
415 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
423 * This method returns a view of the current phylogeny in a chosen
424 * graphics format, base64-encoded in a string so that in can be used
427 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
428 * @return the phylogeny string
429 * @author Herve Menager
431 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
432 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
434 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
435 _mainpanel.getWidth(),
436 _mainpanel.getHeight(),
437 getCurrentTreePanel(),
438 getCurrentTreePanel().getControlPanel(),
439 GraphicsExportType.valueOf( format ),
442 catch ( final IOException ioe ) {
443 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
444 ioe.printStackTrace();
445 JOptionPane.showMessageDialog( this,
446 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
447 "Failed to generate graphics",
448 JOptionPane.ERROR_MESSAGE );
451 final byte[] bytes = baos.toByteArray();
452 final String dataImg = Base64.encodeBase64String( bytes );
456 public Options getOptions() {
462 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
463 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
464 final Configuration configuration = new Configuration( config_filename, true, true, true );
465 setConfiguration( configuration );
466 setOptions( Options.createInstance( configuration ) );
468 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
469 if ( ForesterUtil.isEmpty( tree_url_str ) ) {
470 ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
471 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
472 JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
473 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
476 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
477 // Get URL to tree file
480 phys_url = new URL( tree_url_str );
482 catch ( final Exception e ) {
483 ForesterUtil.printErrorMessage( NAME, "error: " + e );
485 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
486 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
488 if ( phys_url == null ) {
489 ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
490 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
491 JOptionPane.showMessageDialog( this,
492 NAME + ": Could not create URL from: \"" + tree_url_str,
493 "Failed to create URL",
494 JOptionPane.ERROR_MESSAGE );
497 // Load the tree from URL
498 Phylogeny[] phys = null;
500 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
501 getConfiguration().isValidatePhyloXmlAgainstSchema(),
502 getConfiguration().isReplaceUnderscoresInNhParsing(),
503 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
504 getConfiguration().getTaxonomyExtraction(),
505 getConfiguration().isMidpointReroot() );
507 catch ( final Exception e ) {
508 ForesterUtil.printErrorMessage( NAME, e.toString() );
510 JOptionPane.showMessageDialog( this,
511 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
512 "Failed to read phylogenies",
513 JOptionPane.ERROR_MESSAGE );
515 if ( phys == null ) {
516 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
517 JOptionPane.showMessageDialog( this,
518 NAME + ": phylogenies from [" + phys_url + "] are null",
519 "Failed to read phylogenies",
520 JOptionPane.ERROR_MESSAGE );
523 else if ( phys.length < 1 ) {
524 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
525 JOptionPane.showMessageDialog( this,
526 NAME + ": phylogenies from [" + phys_url + "] are empty",
527 "Failed to read phylogenies",
528 JOptionPane.ERROR_MESSAGE );
532 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
535 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
536 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
537 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
538 Phylogeny[] species_trees = null;
540 final URL species_tree_url = new URL( species_tree_url_str );
541 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
542 configuration.isValidatePhyloXmlAgainstSchema(),
543 configuration.isReplaceUnderscoresInNhParsing(),
545 TAXONOMY_EXTRACTION.NO,
548 catch ( final IOException e ) {
549 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
551 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
552 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
554 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
555 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
556 if ( species_trees[ 0 ].isEmpty() ) {
557 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
559 else if ( !species_trees[ 0 ].isRooted() ) {
560 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
563 setSpeciesTree( species_trees[ 0 ] );
564 AptxUtil.printAppletMessage( NAME, "species tree OK" );
571 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
572 _jmenubar = new JMenuBar();
573 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
574 if ( !getConfiguration().isUseNativeUI() ) {
575 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
577 if ( getSpeciesTree() != null ) {
586 setJMenuBar( _jmenubar );
588 final Container contentpane = getContentPane();
589 contentpane.setLayout( new BorderLayout() );
590 contentpane.add( getMainPanel(), BorderLayout.CENTER );
591 addComponentListener( new ComponentAdapter() {
594 public void componentResized( final ComponentEvent e ) {
595 if ( getMainPanel().getCurrentTreePanel() != null ) {
596 getMainPanel().getCurrentTreePanel()
597 .calcParametersForPainting( getMainPanel().getCurrentTreePanel().getWidth(),
598 getMainPanel().getCurrentTreePanel().getHeight(),
599 getOptions().isAllowFontSizeChange() );
603 if ( getConfiguration().isUseTabbedDisplay() ) {
605 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
606 AptxUtil.addPhylogeniesToTabs( phys,
607 new File( phys_url.getFile() ).getName(),
612 catch ( final Exception e ) {
613 ForesterUtil.printErrorMessage( NAME, e.toString() );
618 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
619 if ( getSpeciesTree() != null ) {
620 AptxUtil.printAppletMessage( NAME,
621 "Warning: gsdi (gene duplication inference) only available tabbed display" );
623 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
627 getMainPanel().getControlPanel().showWholeAll();
628 getMainPanel().getControlPanel().showWhole();
630 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
631 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
632 .getRelevantSequenceRelationTypes() ) {
633 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
635 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
636 if ( default_relation != null ) {
637 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
639 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
640 if ( default_sequence != null ) {
641 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
645 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
648 catch ( final Exception e ) {
649 ForesterUtil.printErrorMessage( NAME, e.toString() );
654 public void showTextFrame( final String s, final String title ) {
656 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
660 public void start() {
661 if ( getMainPanel() != null ) {
662 getMainPanel().validate();
665 requestFocusInWindow();
667 AptxUtil.printAppletMessage( NAME, "started" );
670 void buildAnalysisMenu() {
671 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
672 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
673 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
674 customizeJMenuItem( _gsdi_item );
675 customizeJMenuItem( _gsdir_item );
676 // _analysis_menu.addSeparator();
677 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
678 // customizeJMenuItem( _lineage_inference );
679 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
680 _jmenubar.add( _analysis_menu );
683 void buildFontSizeMenu() {
684 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
685 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
686 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
687 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
688 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
689 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
690 customizeJMenuItem( _super_tiny_fonts_mi );
691 customizeJMenuItem( _tiny_fonts_mi );
692 customizeJMenuItem( _small_fonts_mi );
693 customizeJMenuItem( _medium_fonts_mi );
694 customizeJMenuItem( _large_fonts_mi );
695 _jmenubar.add( _font_size_menu );
698 void buildHelpMenu() {
699 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
700 _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
701 _help_jmenu.addSeparator();
702 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
703 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
704 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
705 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
706 _help_jmenu.addSeparator();
707 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
708 customizeJMenuItem( _help_item );
709 customizeJMenuItem( _website_item );
710 customizeJMenuItem( _phyloxml_website_item );
711 customizeJMenuItem( _aptx_ref_item );
712 customizeJMenuItem( _phyloxml_ref_item );
713 customizeJMenuItem( _about_item );
714 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
715 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
716 _jmenubar.add( _help_jmenu );
719 void buildOptionsMenu() {
720 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
721 _options_jmenu.addChangeListener( new ChangeListener() {
724 public void stateChanged( final ChangeEvent e ) {
725 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
726 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
728 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
729 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
730 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
731 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
732 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
733 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
735 getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB();
736 getMainPanel().getControlPanel().setVisibilityOfX();
738 catch ( final Exception ignore ) {
739 // do nothing, not important.
743 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
744 getConfiguration() ) );
746 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
747 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
749 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
750 _radio_group_1 = new ButtonGroup();
751 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
752 _radio_group_1.add( _uniform_cladograms_rbmi );
753 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
755 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
756 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
758 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
760 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
761 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
762 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
763 _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
765 _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
766 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
767 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
769 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
771 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
772 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
773 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
774 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
775 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
776 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
777 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
778 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
779 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
780 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
781 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
782 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
783 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
784 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
786 _options_jmenu.addSeparator();
787 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
788 getConfiguration() ) );
790 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
791 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
793 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
794 customizeJMenuItem( _choose_font_mi );
795 customizeJMenuItem( _choose_minimal_confidence_mi );
796 customizeJMenuItem( _switch_colors_mi );
797 customizeJMenuItem( _overview_placment_mi );
798 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
799 customizeCheckBoxMenuItem( _label_direction_cbmi,
800 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
801 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
802 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
803 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
804 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
805 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
806 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
807 .isShowDefaultNodeShapesExternal() );
808 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
809 .isShowDefaultNodeShapesInternal() );
810 customizeJMenuItem( _cycle_node_shape_mi );
811 customizeJMenuItem( _cycle_node_fill_mi );
812 customizeJMenuItem( _choose_node_size_mi );
813 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
814 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
815 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
816 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
817 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
818 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
819 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
820 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
821 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
822 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
823 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
824 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
825 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
826 customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
827 customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
828 _jmenubar.add( _options_jmenu );
831 void buildToolsMenu() {
832 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
833 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
834 customizeJMenuItem( _confcolor_item );
835 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
836 customizeJMenuItem( _taxcolor_item );
837 _tools_menu.addSeparator();
838 _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
839 _remove_visual_styles_item
840 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
841 customizeJMenuItem( _remove_visual_styles_item );
842 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
843 _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
844 customizeJMenuItem( _remove_branch_color_item );
845 _tools_menu.addSeparator();
846 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
847 customizeJMenuItem( _midpoint_root_item );
848 _tools_menu.addSeparator();
849 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
850 customizeJMenuItem( _collapse_species_specific_subtrees );
851 _jmenubar.add( _tools_menu );
854 void buildTypeMenu() {
855 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
856 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
857 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
858 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
859 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
860 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
861 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
862 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
863 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
864 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
865 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
866 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
867 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
868 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
869 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
870 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
871 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
872 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
873 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
874 initializeTypeMenu( getOptions() );
875 _jmenubar.add( _type_menu );
878 void buildViewMenu() {
879 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
881 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
882 _view_jmenu.addSeparator();
883 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
884 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
885 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
886 customizeJMenuItem( _display_basic_information_item );
887 customizeJMenuItem( _view_as_NH_item );
888 customizeJMenuItem( _view_as_XML_item );
889 customizeJMenuItem( _view_as_nexus_item );
890 _jmenubar.add( _view_jmenu );
893 void checkTextFrames() {
894 if ( _textframes.size() > 5 ) {
896 if ( _textframes.getFirst() != null ) {
897 _textframes.getFirst().removeMe();
900 _textframes.removeFirst();
903 catch ( final NoSuchElementException e ) {
909 void clearCurrentExternalNodesDataBuffer() {
910 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
913 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
914 if ( item != null ) {
915 item.setFont( MainFrame.menu_font );
916 if ( !getConfiguration().isUseNativeUI() ) {
917 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
918 item.setForeground( getConfiguration().getGuiMenuTextColor() );
920 item.setSelected( is_selected );
921 item.addActionListener( this );
925 void customizeJMenuItem( final JMenuItem jmi ) {
926 jmi.setFont( MainFrame.menu_font );
927 if ( !getConfiguration().isUseNativeUI() ) {
928 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
929 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
931 jmi.addActionListener( this );
934 void displayBasicInformation() {
935 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
936 String title = "Basic Information";
937 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
938 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
940 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
945 if ( !isOKforSDI( false, true ) ) {
948 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
949 JOptionPane.showMessageDialog( this,
950 "Gene tree is not rooted.",
951 "Cannot execute GSDI",
952 JOptionPane.ERROR_MESSAGE );
955 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
956 gene_tree.setAllNodesToNotCollapse();
957 gene_tree.recalculateNumberOfExternalDescendants( false );
959 final Phylogeny species_tree = _species_tree.copy();
961 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
963 catch ( final SDIException e ) {
964 JOptionPane.showMessageDialog( this,
965 e.getLocalizedMessage(),
967 JOptionPane.ERROR_MESSAGE );
970 catch ( final Exception e ) {
971 AptxUtil.unexpectedException( e );
974 gene_tree.setRerootable( false );
975 gene_tree.clearHashIdToNodeMap();
976 gene_tree.recalculateNumberOfExternalDescendants( true );
977 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
978 getMainPanel().getControlPanel().setShowEvents( true );
980 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
981 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
983 _mainpanel.getTabbedPane().setSelectedIndex( selected );
985 _mainpanel.getCurrentTreePanel().setEdited( true );
986 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
987 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
988 JOptionPane.showMessageDialog( this,
989 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
990 + "Potential duplications: "
991 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
992 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
993 + "Stripped gene tree nodes: "
994 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
995 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
996 + "Number of polytomies in species tree used: " + poly + "\n",
997 "GSDI successfully completed",
998 JOptionPane.WARNING_MESSAGE );
1001 JOptionPane.showMessageDialog( this,
1002 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1003 + "Potential duplications: "
1004 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1005 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1006 + "Stripped gene tree nodes: "
1007 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1008 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1009 + "Number of polytomies in species tree used: " + poly + "\n",
1010 "GSDI successfully completed",
1011 JOptionPane.INFORMATION_MESSAGE );
1015 void executeGSDIR() {
1016 if ( !isOKforSDI( false, false ) ) {
1019 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1021 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1022 JOptionPane.showMessageDialog( this,
1023 "Gene tree is not completely binary",
1024 "Cannot execute GSDI",
1025 JOptionPane.ERROR_MESSAGE );
1028 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1029 gene_tree.setAllNodesToNotCollapse();
1030 gene_tree.recalculateNumberOfExternalDescendants( false );
1032 final Phylogeny species_tree = _species_tree.copy();
1034 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1036 catch ( final SDIException e ) {
1037 JOptionPane.showMessageDialog( this,
1038 e.getLocalizedMessage(),
1039 "Error during GSDIR",
1040 JOptionPane.ERROR_MESSAGE );
1043 catch ( final Exception e ) {
1044 AptxUtil.unexpectedException( e );
1047 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1048 result_gene_tree.setRerootable( false );
1049 result_gene_tree.clearHashIdToNodeMap();
1050 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1051 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1052 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1053 getMainPanel().getControlPanel().setShowEvents( true );
1055 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1056 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1058 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1060 _mainpanel.getCurrentTreePanel().setEdited( true );
1061 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1062 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1063 JOptionPane.showMessageDialog( this,
1064 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1065 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1066 + "Stripped gene tree nodes: "
1067 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1068 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1069 + "Number of polytomies in species tree used: " + poly + "\n",
1070 "GSDIR successfully completed",
1071 JOptionPane.WARNING_MESSAGE );
1074 JOptionPane.showMessageDialog( this,
1075 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1076 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1077 + "Stripped gene tree nodes: "
1078 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1079 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1080 + "Number of polytomies in species tree used: " + poly + "\n",
1081 "GSDIR successfully completed",
1082 JOptionPane.INFORMATION_MESSAGE );
1086 Configuration getConfiguration() {
1087 return _configuration;
1090 TreePanel getCurrentTreePanel() {
1091 return getMainPanel().getCurrentTreePanel();
1094 JCheckBoxMenuItem getlabelDirectionCbmi() {
1095 return _label_direction_cbmi;
1098 Options getOtions() {
1102 void initializeTypeMenu( final Options options ) {
1103 setTypeMenuToAllUnselected();
1105 switch ( options.getPhylogenyGraphicsType() ) {
1107 _convex_type_cbmi.setSelected( true );
1110 _curved_type_cbmi.setSelected( true );
1113 _euro_type_cbmi.setSelected( true );
1116 _rounded_type_cbmi.setSelected( true );
1119 _triangular_type_cbmi.setSelected( true );
1122 _unrooted_type_cbmi.setSelected( true );
1125 _circular_type_cbmi.setSelected( true );
1128 _rectangular_type_cbmi.setSelected( true );
1132 catch ( final NullPointerException np ) {
1133 // In all likelihood, this is caused by menu-less display.
1137 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1138 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1141 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1142 JOptionPane.showMessageDialog( this,
1143 "No species tree loaded",
1144 "Cannot execute GSDI",
1145 JOptionPane.ERROR_MESSAGE );
1148 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1149 JOptionPane.showMessageDialog( this,
1150 "Species tree is not completely binary",
1151 "Cannot execute GSDI",
1152 JOptionPane.ERROR_MESSAGE );
1155 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1156 JOptionPane.showMessageDialog( this,
1157 "Gene tree is not completely binary",
1158 "Cannot execute GSDI",
1159 JOptionPane.ERROR_MESSAGE );
1167 boolean isSubtreeDisplayed() {
1168 if ( getCurrentTreePanel() != null ) {
1169 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1171 .showMessageDialog( this,
1172 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1173 "Operation can not be exectuted on a sub-tree",
1174 JOptionPane.WARNING_MESSAGE );
1181 void removeAllTextFrames() {
1182 for( final TextFrame tf : _textframes ) {
1187 _textframes.clear();
1190 void setConfiguration( final Configuration configuration ) {
1191 _configuration = configuration;
1194 void setOptions( final Options options ) {
1198 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1199 setTypeMenuToAllUnselected();
1203 _circular_type_cbmi.setSelected( true );
1206 _convex_type_cbmi.setSelected( true );
1209 _curved_type_cbmi.setSelected( true );
1212 _euro_type_cbmi.setSelected( true );
1215 _rounded_type_cbmi.setSelected( true );
1218 _rectangular_type_cbmi.setSelected( true );
1221 _triangular_type_cbmi.setSelected( true );
1224 _unrooted_type_cbmi.setSelected( true );
1227 throw new IllegalArgumentException( "unknown type: " + type );
1230 catch ( final NullPointerException np ) {
1231 // In all likelihood, this is caused by menu-less display.
1235 void setTypeMenuToAllUnselected() {
1236 if ( _convex_type_cbmi != null ) {
1237 _convex_type_cbmi.setSelected( false );
1239 if ( _curved_type_cbmi != null ) {
1240 _curved_type_cbmi.setSelected( false );
1242 if ( _euro_type_cbmi != null ) {
1243 _euro_type_cbmi.setSelected( false );
1245 if ( _rounded_type_cbmi != null ) {
1246 _rounded_type_cbmi.setSelected( false );
1248 if ( _triangular_type_cbmi != null ) {
1249 _triangular_type_cbmi.setSelected( false );
1251 if ( _rectangular_type_cbmi != null ) {
1252 _rectangular_type_cbmi.setSelected( false );
1254 if ( _unrooted_type_cbmi != null ) {
1255 _unrooted_type_cbmi.setSelected( false );
1257 if ( _circular_type_cbmi != null ) {
1258 _circular_type_cbmi.setSelected( false );
1263 _mainpanel.getControlPanel().showWhole();
1266 void switchColors() {
1267 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1268 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1269 csc.setVisible( true );
1270 getMainPanel().setTreeColorSet( colorset );
1273 void typeChanged( final Object o ) {
1274 updateTypeCheckboxes( getOptions(), o );
1275 updateOptions( getOptions() );
1276 if ( getCurrentTreePanel() != null ) {
1277 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1278 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1279 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1280 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1281 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1282 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1283 getCurrentTreePanel().getControlPanel().showWhole();
1285 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1286 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1289 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1291 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1292 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1296 void updateOptions( final Options options ) {
1297 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1298 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1299 && _background_gradient_cbmi.isSelected() );
1300 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1301 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1302 && _show_annotation_ref_source.isSelected() );
1303 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1304 && _abbreviate_scientific_names.isSelected() );
1305 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1306 && _color_labels_same_as_parent_branch.isSelected() );
1307 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1308 && _show_default_node_shapes_internal_cbmi.isSelected() );
1309 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1310 && _show_default_node_shapes_external_cbmi.isSelected() );
1311 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1312 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1314 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1315 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1317 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1318 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1320 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1321 && _search_case_senstive_cbmi.isSelected() );
1322 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1323 options.setShowScale( _show_scale_cbmi.isSelected() );
1325 if ( _label_direction_cbmi != null ) {
1326 if ( _label_direction_cbmi.isSelected() ) {
1327 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1330 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1333 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1334 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1335 && _show_confidence_stddev_cbmi.isSelected() );
1336 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1337 && _search_whole_words_only_cbmi.isSelected() );
1338 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1339 && _inverse_search_result_cbmi.isSelected() );
1340 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1341 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1343 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1344 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1346 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1347 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1349 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1350 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1352 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1353 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1355 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1356 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1358 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1359 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1361 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1362 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1364 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1365 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1367 if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1368 options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1370 if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1371 options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1375 void updateTypeCheckboxes( final Options options, final Object o ) {
1376 setTypeMenuToAllUnselected();
1377 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1380 void viewAsNexus() {
1381 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1382 String title = "Nexus";
1383 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1384 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1386 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1387 .getNhConversionSupportValueStyle() ),
1393 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1394 String title = "New Hampshire";
1395 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1396 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1398 showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1399 .getNhConversionSupportValueStyle() ),
1405 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1406 String title = "phyloXML";
1407 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1408 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1410 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1414 private void chooseFont() {
1415 final FontChooser fc = new FontChooser();
1416 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1417 fc.showDialog( this, "Select the Base Font" );
1418 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1421 private void chooseMinimalConfidence() {
1422 final String s = ( String ) JOptionPane
1423 .showInputDialog( this,
1424 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1425 + getOptions().getMinConfidenceValue() + "]\n",
1426 "Minimal Confidence Value",
1427 JOptionPane.QUESTION_MESSAGE,
1430 getOptions().getMinConfidenceValue() );
1431 if ( !ForesterUtil.isEmpty( s ) ) {
1432 boolean success = true;
1434 final String m_str = s.trim();
1435 if ( !ForesterUtil.isEmpty( m_str ) ) {
1437 m = Double.parseDouble( m_str );
1439 catch ( final Exception ex ) {
1446 if ( success && ( m >= 0.0 ) ) {
1447 getOptions().setMinConfidenceValue( m );
1452 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1453 if ( item != null ) {
1454 item.setFont( MainFrame.menu_font );
1455 if ( !getConfiguration().isUseNativeUI() ) {
1456 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1457 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1459 item.setSelected( is_selected );
1460 item.addActionListener( this );
1464 MainPanel getMainPanel() {
1468 private Phylogeny getSpeciesTree() {
1469 return _species_tree;
1472 private boolean isScreenAntialias() {
1476 private void removeBranchColors() {
1477 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1478 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1482 private void removeVisualStyles() {
1483 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1484 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1488 private void setMainPanel( final MainPanelApplets main_panel ) {
1489 _mainpanel = main_panel;
1492 private void setSpeciesTree( final Phylogeny species_tree ) {
1493 _species_tree = species_tree;
1496 private void setupUI() {
1498 if ( getConfiguration().isUseNativeUI() ) {
1499 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1502 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1505 catch ( final UnsupportedLookAndFeelException e ) {
1506 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1508 catch ( final ClassNotFoundException e ) {
1509 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1511 catch ( final InstantiationException e ) {
1512 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1514 catch ( final IllegalAccessException e ) {
1515 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1517 catch ( final Exception e ) {
1518 AptxUtil.dieWithSystemError( e.toString() );
1522 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1523 for( final TreePanel tree_panel : treepanels ) {
1524 tree_panel.setTextAntialias();