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" );
570 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
571 _jmenubar = new JMenuBar();
572 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
573 if ( !getConfiguration().isUseNativeUI() ) {
574 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
576 if ( getSpeciesTree() != null ) {
585 setJMenuBar( _jmenubar );
587 final Container contentpane = getContentPane();
588 contentpane.setLayout( new BorderLayout() );
589 contentpane.add( getMainPanel(), BorderLayout.CENTER );
590 addComponentListener( new ComponentAdapter() {
593 public void componentResized( final ComponentEvent e ) {
594 if ( getMainPanel().getCurrentTreePanel() != null ) {
595 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
596 .getCurrentTreePanel()
599 .getCurrentTreePanel()
602 .isAllowFontSizeChange() );
606 if ( getConfiguration().isUseTabbedDisplay() ) {
608 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
609 AptxUtil.addPhylogeniesToTabs( phys,
610 new File( phys_url.getFile() ).getName(),
615 catch ( final Exception e ) {
616 ForesterUtil.printErrorMessage( NAME, e.toString() );
621 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
622 if ( getSpeciesTree() != null ) {
623 AptxUtil.printAppletMessage( NAME,
624 "Warning: gsdi (gene duplication inference) only available tabbed display" );
626 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
631 getMainPanel().getControlPanel().showWholeAll();
632 getMainPanel().getControlPanel().showWhole();
634 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
635 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
636 .getRelevantSequenceRelationTypes() ) {
637 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
639 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
640 if ( default_relation != null ) {
641 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
643 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
644 if ( default_sequence != null ) {
645 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
649 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
652 catch ( final Exception e ) {
653 ForesterUtil.printErrorMessage( NAME, e.toString() );
658 public void showTextFrame( final String s, final String title ) {
660 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
664 public void start() {
665 if ( getMainPanel() != null ) {
666 getMainPanel().validate();
669 requestFocusInWindow();
671 AptxUtil.printAppletMessage( NAME, "started" );
674 void buildAnalysisMenu() {
675 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
676 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
677 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
678 customizeJMenuItem( _gsdi_item );
679 customizeJMenuItem( _gsdir_item );
680 // _analysis_menu.addSeparator();
681 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
682 // customizeJMenuItem( _lineage_inference );
683 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
684 _jmenubar.add( _analysis_menu );
687 void buildFontSizeMenu() {
688 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
689 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
690 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
691 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
692 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
693 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
694 customizeJMenuItem( _super_tiny_fonts_mi );
695 customizeJMenuItem( _tiny_fonts_mi );
696 customizeJMenuItem( _small_fonts_mi );
697 customizeJMenuItem( _medium_fonts_mi );
698 customizeJMenuItem( _large_fonts_mi );
699 _jmenubar.add( _font_size_menu );
702 void buildHelpMenu() {
703 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
704 _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
705 _help_jmenu.addSeparator();
706 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
707 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
708 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
709 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
710 _help_jmenu.addSeparator();
711 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
712 customizeJMenuItem( _help_item );
713 customizeJMenuItem( _website_item );
714 customizeJMenuItem( _phyloxml_website_item );
715 customizeJMenuItem( _aptx_ref_item );
716 customizeJMenuItem( _phyloxml_ref_item );
717 customizeJMenuItem( _about_item );
718 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
719 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
720 _jmenubar.add( _help_jmenu );
723 void buildOptionsMenu() {
724 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
725 _options_jmenu.addChangeListener( new ChangeListener() {
728 public void stateChanged( final ChangeEvent e ) {
729 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
730 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
732 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
733 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
734 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
735 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
736 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
737 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
739 getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB();
740 getMainPanel().getControlPanel().setVisibilityOfX();
742 catch ( final Exception ignore ) {
743 // do nothing, not important.
747 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
748 getConfiguration() ) );
750 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
751 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
753 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
754 _radio_group_1 = new ButtonGroup();
755 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
756 _radio_group_1.add( _uniform_cladograms_rbmi );
757 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
759 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
760 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
762 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
764 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
765 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
766 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
767 _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
769 _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
770 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
771 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
773 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
775 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
776 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
777 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
778 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
779 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
780 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
781 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
782 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
783 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
784 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
785 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
786 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
787 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
788 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
790 _options_jmenu.addSeparator();
791 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
792 getConfiguration() ) );
794 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
795 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
797 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
798 customizeJMenuItem( _choose_font_mi );
799 customizeJMenuItem( _choose_minimal_confidence_mi );
800 customizeJMenuItem( _switch_colors_mi );
801 customizeJMenuItem( _overview_placment_mi );
802 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
803 customizeCheckBoxMenuItem( _label_direction_cbmi,
804 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
805 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
806 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
807 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
808 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
809 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
810 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
811 .isShowDefaultNodeShapesExternal() );
812 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
813 .isShowDefaultNodeShapesInternal() );
814 customizeJMenuItem( _cycle_node_shape_mi );
815 customizeJMenuItem( _cycle_node_fill_mi );
816 customizeJMenuItem( _choose_node_size_mi );
817 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
818 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
819 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
820 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
821 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
822 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
823 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
824 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
825 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
826 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
827 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
828 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
829 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
830 customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
831 customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
832 _jmenubar.add( _options_jmenu );
835 void buildToolsMenu() {
836 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
837 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
838 customizeJMenuItem( _confcolor_item );
839 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
840 customizeJMenuItem( _taxcolor_item );
841 _tools_menu.addSeparator();
842 _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
843 _remove_visual_styles_item
844 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
845 customizeJMenuItem( _remove_visual_styles_item );
846 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
847 _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
848 customizeJMenuItem( _remove_branch_color_item );
849 _tools_menu.addSeparator();
850 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
851 customizeJMenuItem( _midpoint_root_item );
852 _tools_menu.addSeparator();
853 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
854 customizeJMenuItem( _collapse_species_specific_subtrees );
855 _jmenubar.add( _tools_menu );
858 void buildTypeMenu() {
859 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
860 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
861 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
862 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
863 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
864 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
865 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
866 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
867 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
868 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
869 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
870 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
871 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
872 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
873 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
874 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
875 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
876 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
877 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
878 initializeTypeMenu( getOptions() );
879 _jmenubar.add( _type_menu );
882 void buildViewMenu() {
883 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
885 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
886 _view_jmenu.addSeparator();
887 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
888 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
889 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
890 customizeJMenuItem( _display_basic_information_item );
891 customizeJMenuItem( _view_as_NH_item );
892 customizeJMenuItem( _view_as_XML_item );
893 customizeJMenuItem( _view_as_nexus_item );
894 _jmenubar.add( _view_jmenu );
897 void checkTextFrames() {
898 if ( _textframes.size() > 5 ) {
900 if ( _textframes.getFirst() != null ) {
901 _textframes.getFirst().removeMe();
904 _textframes.removeFirst();
907 catch ( final NoSuchElementException e ) {
913 void clearCurrentExternalNodesDataBuffer() {
914 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
917 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
918 if ( item != null ) {
919 item.setFont( MainFrame.menu_font );
920 if ( !getConfiguration().isUseNativeUI() ) {
921 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
922 item.setForeground( getConfiguration().getGuiMenuTextColor() );
924 item.setSelected( is_selected );
925 item.addActionListener( this );
929 void customizeJMenuItem( final JMenuItem jmi ) {
930 jmi.setFont( MainFrame.menu_font );
931 if ( !getConfiguration().isUseNativeUI() ) {
932 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
933 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
935 jmi.addActionListener( this );
938 void displayBasicInformation() {
939 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
940 String title = "Basic Information";
941 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
942 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
944 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
949 if ( !isOKforSDI( false, true ) ) {
952 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
953 JOptionPane.showMessageDialog( this,
954 "Gene tree is not rooted.",
955 "Cannot execute GSDI",
956 JOptionPane.ERROR_MESSAGE );
959 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
960 gene_tree.setAllNodesToNotCollapse();
961 gene_tree.recalculateNumberOfExternalDescendants( false );
963 final Phylogeny species_tree = _species_tree.copy();
965 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
967 catch ( final SDIException e ) {
968 JOptionPane.showMessageDialog( this,
969 e.getLocalizedMessage(),
971 JOptionPane.ERROR_MESSAGE );
974 catch ( final Exception e ) {
975 AptxUtil.unexpectedException( e );
978 gene_tree.setRerootable( false );
979 gene_tree.clearHashIdToNodeMap();
980 gene_tree.recalculateNumberOfExternalDescendants( true );
981 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
982 getMainPanel().getControlPanel().setShowEvents( true );
984 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
985 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
987 _mainpanel.getTabbedPane().setSelectedIndex( selected );
989 _mainpanel.getCurrentTreePanel().setEdited( true );
990 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
991 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
992 JOptionPane.showMessageDialog( this,
993 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
994 + "Potential duplications: "
995 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
996 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
997 + "Stripped gene tree nodes: "
998 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
999 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1000 + "Number of polytomies in species tree used: " + poly + "\n",
1001 "GSDI successfully completed",
1002 JOptionPane.WARNING_MESSAGE );
1005 JOptionPane.showMessageDialog( this,
1006 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1007 + "Potential duplications: "
1008 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1009 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1010 + "Stripped gene tree nodes: "
1011 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1012 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1013 + "Number of polytomies in species tree used: " + poly + "\n",
1014 "GSDI successfully completed",
1015 JOptionPane.INFORMATION_MESSAGE );
1019 void executeGSDIR() {
1020 if ( !isOKforSDI( false, false ) ) {
1023 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1025 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1026 JOptionPane.showMessageDialog( this,
1027 "Gene tree is not completely binary",
1028 "Cannot execute GSDI",
1029 JOptionPane.ERROR_MESSAGE );
1032 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1033 gene_tree.setAllNodesToNotCollapse();
1034 gene_tree.recalculateNumberOfExternalDescendants( false );
1036 final Phylogeny species_tree = _species_tree.copy();
1038 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1040 catch ( final SDIException e ) {
1041 JOptionPane.showMessageDialog( this,
1042 e.getLocalizedMessage(),
1043 "Error during GSDIR",
1044 JOptionPane.ERROR_MESSAGE );
1047 catch ( final Exception e ) {
1048 AptxUtil.unexpectedException( e );
1051 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1052 result_gene_tree.setRerootable( false );
1053 result_gene_tree.clearHashIdToNodeMap();
1054 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1055 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1056 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1057 getMainPanel().getControlPanel().setShowEvents( true );
1059 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1060 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1062 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1064 _mainpanel.getCurrentTreePanel().setEdited( true );
1065 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1066 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1067 JOptionPane.showMessageDialog( this,
1068 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1069 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1070 + "Stripped gene tree nodes: "
1071 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1072 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1073 + "Number of polytomies in species tree used: " + poly + "\n",
1074 "GSDIR successfully completed",
1075 JOptionPane.WARNING_MESSAGE );
1078 JOptionPane.showMessageDialog( this,
1079 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1080 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1081 + "Stripped gene tree nodes: "
1082 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1083 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1084 + "Number of polytomies in species tree used: " + poly + "\n",
1085 "GSDIR successfully completed",
1086 JOptionPane.INFORMATION_MESSAGE );
1090 Configuration getConfiguration() {
1091 return _configuration;
1094 TreePanel getCurrentTreePanel() {
1095 return getMainPanel().getCurrentTreePanel();
1098 JCheckBoxMenuItem getlabelDirectionCbmi() {
1099 return _label_direction_cbmi;
1102 Options getOtions() {
1106 void initializeTypeMenu( final Options options ) {
1107 setTypeMenuToAllUnselected();
1109 switch ( options.getPhylogenyGraphicsType() ) {
1111 _convex_type_cbmi.setSelected( true );
1114 _curved_type_cbmi.setSelected( true );
1117 _euro_type_cbmi.setSelected( true );
1120 _rounded_type_cbmi.setSelected( true );
1123 _triangular_type_cbmi.setSelected( true );
1126 _unrooted_type_cbmi.setSelected( true );
1129 _circular_type_cbmi.setSelected( true );
1132 _rectangular_type_cbmi.setSelected( true );
1136 catch ( final NullPointerException np ) {
1137 // In all likelihood, this is caused by menu-less display.
1141 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1142 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1145 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1146 JOptionPane.showMessageDialog( this,
1147 "No species tree loaded",
1148 "Cannot execute GSDI",
1149 JOptionPane.ERROR_MESSAGE );
1152 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1153 JOptionPane.showMessageDialog( this,
1154 "Species tree is not completely binary",
1155 "Cannot execute GSDI",
1156 JOptionPane.ERROR_MESSAGE );
1159 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1160 JOptionPane.showMessageDialog( this,
1161 "Gene tree is not completely binary",
1162 "Cannot execute GSDI",
1163 JOptionPane.ERROR_MESSAGE );
1171 boolean isSubtreeDisplayed() {
1172 if ( getCurrentTreePanel() != null ) {
1173 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1175 .showMessageDialog( this,
1176 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1177 "Operation can not be exectuted on a sub-tree",
1178 JOptionPane.WARNING_MESSAGE );
1185 void removeAllTextFrames() {
1186 for( final TextFrame tf : _textframes ) {
1191 _textframes.clear();
1194 void setConfiguration( final Configuration configuration ) {
1195 _configuration = configuration;
1198 void setOptions( final Options options ) {
1202 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1203 setTypeMenuToAllUnselected();
1207 _circular_type_cbmi.setSelected( true );
1210 _convex_type_cbmi.setSelected( true );
1213 _curved_type_cbmi.setSelected( true );
1216 _euro_type_cbmi.setSelected( true );
1219 _rounded_type_cbmi.setSelected( true );
1222 _rectangular_type_cbmi.setSelected( true );
1225 _triangular_type_cbmi.setSelected( true );
1228 _unrooted_type_cbmi.setSelected( true );
1231 throw new IllegalArgumentException( "unknown type: " + type );
1234 catch ( final NullPointerException np ) {
1235 // In all likelihood, this is caused by menu-less display.
1239 void setTypeMenuToAllUnselected() {
1240 if ( _convex_type_cbmi != null ) {
1241 _convex_type_cbmi.setSelected( false );
1243 if ( _curved_type_cbmi != null ) {
1244 _curved_type_cbmi.setSelected( false );
1246 if ( _euro_type_cbmi != null ) {
1247 _euro_type_cbmi.setSelected( false );
1249 if ( _rounded_type_cbmi != null ) {
1250 _rounded_type_cbmi.setSelected( false );
1252 if ( _triangular_type_cbmi != null ) {
1253 _triangular_type_cbmi.setSelected( false );
1255 if ( _rectangular_type_cbmi != null ) {
1256 _rectangular_type_cbmi.setSelected( false );
1258 if ( _unrooted_type_cbmi != null ) {
1259 _unrooted_type_cbmi.setSelected( false );
1261 if ( _circular_type_cbmi != null ) {
1262 _circular_type_cbmi.setSelected( false );
1267 _mainpanel.getControlPanel().showWhole();
1270 void switchColors() {
1271 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1272 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1273 csc.setVisible( true );
1274 getMainPanel().setTreeColorSet( colorset );
1277 void typeChanged( final Object o ) {
1278 updateTypeCheckboxes( getOptions(), o );
1279 updateOptions( getOptions() );
1280 if ( getCurrentTreePanel() != null ) {
1281 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1282 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1283 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1284 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1285 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1286 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1287 getCurrentTreePanel().getControlPanel().showWhole();
1289 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1290 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1293 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1295 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1296 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1300 void updateOptions( final Options options ) {
1301 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1302 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1303 && _background_gradient_cbmi.isSelected() );
1304 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1305 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1306 && _show_annotation_ref_source.isSelected() );
1307 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1308 && _abbreviate_scientific_names.isSelected() );
1309 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1310 && _color_labels_same_as_parent_branch.isSelected() );
1311 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1312 && _show_default_node_shapes_internal_cbmi.isSelected() );
1313 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1314 && _show_default_node_shapes_external_cbmi.isSelected() );
1315 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1316 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1318 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1319 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1321 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1322 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1324 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1325 && _search_case_senstive_cbmi.isSelected() );
1326 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1327 options.setShowScale( _show_scale_cbmi.isSelected() );
1329 if ( _label_direction_cbmi != null ) {
1330 if ( _label_direction_cbmi.isSelected() ) {
1331 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1334 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1337 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1338 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1339 && _show_confidence_stddev_cbmi.isSelected() );
1340 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1341 && _search_whole_words_only_cbmi.isSelected() );
1342 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1343 && _inverse_search_result_cbmi.isSelected() );
1344 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1345 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1347 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1348 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1350 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1351 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1353 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1354 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1356 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1357 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1359 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1360 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1362 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1363 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1365 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1366 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1368 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1369 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1371 if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1372 options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1374 if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1375 options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1379 void updateTypeCheckboxes( final Options options, final Object o ) {
1380 setTypeMenuToAllUnselected();
1381 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1384 void viewAsNexus() {
1385 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1386 String title = "Nexus";
1387 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1388 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1390 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1391 .getNhConversionSupportValueStyle() ),
1397 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1398 String title = "New Hampshire";
1399 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1400 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1402 showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1403 .getNhConversionSupportValueStyle() ),
1409 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1410 String title = "phyloXML";
1411 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1412 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1414 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1418 private void chooseFont() {
1419 final FontChooser fc = new FontChooser();
1420 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1421 fc.showDialog( this, "Select the Base Font" );
1422 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1425 private void chooseMinimalConfidence() {
1426 final String s = ( String ) JOptionPane
1427 .showInputDialog( this,
1428 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1429 + getOptions().getMinConfidenceValue() + "]\n",
1430 "Minimal Confidence Value",
1431 JOptionPane.QUESTION_MESSAGE,
1434 getOptions().getMinConfidenceValue() );
1435 if ( !ForesterUtil.isEmpty( s ) ) {
1436 boolean success = true;
1438 final String m_str = s.trim();
1439 if ( !ForesterUtil.isEmpty( m_str ) ) {
1441 m = Double.parseDouble( m_str );
1443 catch ( final Exception ex ) {
1450 if ( success && ( m >= 0.0 ) ) {
1451 getOptions().setMinConfidenceValue( m );
1456 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1457 if ( item != null ) {
1458 item.setFont( MainFrame.menu_font );
1459 if ( !getConfiguration().isUseNativeUI() ) {
1460 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1461 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1463 item.setSelected( is_selected );
1464 item.addActionListener( this );
1468 private MainPanel getMainPanel() {
1472 private Phylogeny getSpeciesTree() {
1473 return _species_tree;
1476 private boolean isScreenAntialias() {
1480 private void removeBranchColors() {
1481 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1482 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1486 private void removeVisualStyles() {
1487 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1488 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1492 private void setMainPanel( final MainPanelApplets main_panel ) {
1493 _mainpanel = main_panel;
1496 private void setSpeciesTree( final Phylogeny species_tree ) {
1497 _species_tree = species_tree;
1500 private void setupUI() {
1502 if ( getConfiguration().isUseNativeUI() ) {
1503 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1506 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1509 catch ( final UnsupportedLookAndFeelException e ) {
1510 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1512 catch ( final ClassNotFoundException e ) {
1513 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1515 catch ( final InstantiationException e ) {
1516 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1518 catch ( final IllegalAccessException e ) {
1519 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1521 catch ( final Exception e ) {
1522 AptxUtil.dieWithSystemError( e.toString() );
1526 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1527 for( final TreePanel tree_panel : treepanels ) {
1528 tree_panel.setTextAntialias();