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 JCheckBoxMenuItem _show_branch_length_values_cbmi;
121 private JMenuItem _collapse_species_specific_subtrees;
122 private JMenuItem _overview_placment_mi;
123 private ButtonGroup _radio_group_1;
124 private JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
125 private JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
126 private JMenuItem _cycle_node_shape_mi;
127 private JMenuItem _cycle_node_fill_mi;
128 private JMenuItem _choose_node_size_mi;
129 private JCheckBoxMenuItem _show_confidence_stddev_cbmi;
130 private final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>();
131 private JMenu _analysis_menu;
132 private JMenuItem _gsdi_item;
133 private JMenuItem _gsdir_item;
134 private Phylogeny _species_tree;
135 private JCheckBoxMenuItem _right_line_up_domains_cbmi;
136 private JCheckBoxMenuItem _line_up_renderable_data_cbmi;
139 public void actionPerformed( final ActionEvent e ) {
140 final Object o = e.getSource();
141 if ( o == _midpoint_root_item ) {
142 getMainPanel().getCurrentTreePanel().midpointRoot();
144 else if ( o == _gsdi_item ) {
145 if ( isSubtreeDisplayed() ) {
150 else if ( o == _gsdir_item ) {
151 if ( isSubtreeDisplayed() ) {
156 else if ( o == _taxcolor_item ) {
157 getMainPanel().getCurrentTreePanel().taxColor();
159 else if ( o == _confcolor_item ) {
160 getMainPanel().getCurrentTreePanel().confColor();
162 else if ( o == _collapse_species_specific_subtrees ) {
163 if ( getCurrentTreePanel() != null ) {
164 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
167 else if ( o == _remove_branch_color_item ) {
168 removeBranchColors();
170 else if ( o == _remove_visual_styles_item ) {
171 removeVisualStyles();
173 else if ( o == _switch_colors_mi ) {
176 else if ( o == _display_basic_information_item ) {
177 displayBasicInformation();
179 else if ( o == _view_as_NH_item ) {
182 else if ( o == _view_as_XML_item ) {
185 else if ( o == _view_as_nexus_item ) {
188 else if ( o == _super_tiny_fonts_mi ) {
189 if ( getCurrentTreePanel() != null ) {
190 getCurrentTreePanel().setSuperTinyFonts();
191 getCurrentTreePanel().repaint();
194 else if ( o == _tiny_fonts_mi ) {
195 if ( getCurrentTreePanel() != null ) {
196 getCurrentTreePanel().setTinyFonts();
197 getCurrentTreePanel().repaint();
200 else if ( o == _small_fonts_mi ) {
201 if ( getCurrentTreePanel() != null ) {
202 getCurrentTreePanel().setSmallFonts();
203 getCurrentTreePanel().repaint();
206 else if ( o == _medium_fonts_mi ) {
207 if ( getCurrentTreePanel() != null ) {
208 getCurrentTreePanel().setMediumFonts();
209 getCurrentTreePanel().repaint();
212 else if ( o == _large_fonts_mi ) {
213 if ( getCurrentTreePanel() != null ) {
214 getCurrentTreePanel().setLargeFonts();
215 getCurrentTreePanel().repaint();
218 else if ( o == _choose_font_mi ) {
221 else if ( o == _choose_minimal_confidence_mi ) {
222 chooseMinimalConfidence();
224 else if ( o == _choose_node_size_mi ) {
225 MainFrame.chooseNodeSize( getOptions(), this );
227 else if ( o == _overview_placment_mi ) {
228 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
230 else if ( o == _cycle_node_fill_mi ) {
231 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
233 else if ( o == _cycle_node_shape_mi ) {
234 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
236 else if ( o == _non_lined_up_cladograms_rbmi ) {
237 updateOptions( getOptions() );
238 _mainpanel.getControlPanel().showWhole();
240 else if ( o == _uniform_cladograms_rbmi ) {
241 updateOptions( getOptions() );
242 _mainpanel.getControlPanel().showWhole();
244 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
245 updateOptions( getOptions() );
246 _mainpanel.getControlPanel().showWhole();
248 else if ( o == _search_case_senstive_cbmi ) {
249 updateOptions( getOptions() );
250 getMainPanel().getControlPanel().search0();
251 getMainPanel().getControlPanel().search1();
253 else if ( o == _search_whole_words_only_cbmi ) {
254 updateOptions( getOptions() );
255 getMainPanel().getControlPanel().search0();
256 getMainPanel().getControlPanel().search1();
258 else if ( o == _inverse_search_result_cbmi ) {
259 updateOptions( getOptions() );
260 getMainPanel().getControlPanel().search0();
261 getMainPanel().getControlPanel().search1();
263 else if ( o == _show_scale_cbmi ) {
264 updateOptions( getOptions() );
266 else if ( o == _show_branch_length_values_cbmi ) {
267 updateOptions( getOptions() );
269 else if ( o == _show_confidence_stddev_cbmi ) {
270 updateOptions( getOptions() );
272 else if ( o == _label_direction_cbmi ) {
273 updateOptions( getOptions() );
275 else if ( o == _abbreviate_scientific_names ) {
276 updateOptions( getOptions() );
278 else if ( o == _show_overview_cbmi ) {
279 updateOptions( getOptions() );
280 if ( getCurrentTreePanel() != null ) {
281 getCurrentTreePanel().updateOvSizes();
284 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
285 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
286 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
289 else if ( o == _screen_antialias_cbmi ) {
290 updateOptions( getOptions() );
291 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
293 else if ( o == _background_gradient_cbmi ) {
294 updateOptions( getOptions() );
296 else if ( o == _show_domain_labels ) {
297 updateOptions( getOptions() );
299 else if ( o == _color_labels_same_as_parent_branch ) {
300 updateOptions( getOptions() );
302 else if ( o == _show_default_node_shapes_internal_cbmi ) {
303 updateOptions( getOptions() );
305 else if ( o == _show_default_node_shapes_external_cbmi ) {
306 updateOptions( getOptions() );
308 else if ( o == _about_item ) {
311 else if ( o == _help_item ) {
313 AptxUtil.openWebsite( Constants.APTX_DOC_SITE, true, this );
315 catch ( final IOException e1 ) {
316 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
319 else if ( o == _website_item ) {
321 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
323 catch ( final IOException e1 ) {
324 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
327 else if ( o == _phyloxml_website_item ) {
329 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
331 catch ( final IOException e1 ) {
332 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
335 else if ( o == _aptx_ref_item ) {
337 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
339 catch ( final IOException e1 ) {
340 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
343 else if ( o == _phyloxml_ref_item ) {
345 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
347 catch ( final IOException e1 ) {
348 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
351 else if ( o == _color_by_taxonomic_group_cbmi ) {
352 updateOptions( getOptions() );
354 else if ( o == _line_up_renderable_data_cbmi ) {
355 if ( !_line_up_renderable_data_cbmi.isSelected() ) {
356 _right_line_up_domains_cbmi.setSelected( false );
358 updateOptions( getOptions() );
360 else if ( o == _right_line_up_domains_cbmi ) {
361 if ( _right_line_up_domains_cbmi.isSelected() ) {
362 _line_up_renderable_data_cbmi.setSelected( true );
364 updateOptions( getOptions() );
370 public void destroy() {
371 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
372 removeAllTextFrames();
373 if ( getMainPanel() != null ) {
374 getMainPanel().terminate();
379 * This method returns the current external node data which
380 * has been selected by the user by clicking the "Return ..."
381 * menu item. This method is expected to be called from Javascript or
384 * @return current external node data as String
386 public String getCurrentExternalNodesDataBuffer() {
387 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
390 public int getCurrentExternalNodesDataBufferChangeCounter() {
391 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
394 public int getCurrentExternalNodesDataBufferLength() {
395 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
399 * This method returns the current phylogeny as a string in the chosen format
401 * @param format must be NH, NHX, NEXUS or PHYLOXML
402 * @return the phylogeny string
403 * @author Herve Menager
405 public String getCurrentPhylogeny( final String format ) {
406 removeAllTextFrames();
407 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
408 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
411 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
413 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
415 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
417 return getMainPanel().getCurrentPhylogeny().toNexus();
419 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
427 * This method returns a view of the current phylogeny in a chosen
428 * graphics format, base64-encoded in a string so that in can be used
431 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
432 * @return the phylogeny string
433 * @author Herve Menager
435 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
436 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
438 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
439 _mainpanel.getWidth(),
440 _mainpanel.getHeight(),
441 getCurrentTreePanel(),
442 getCurrentTreePanel().getControlPanel(),
443 GraphicsExportType.valueOf( format ),
446 catch ( final IOException ioe ) {
447 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
448 ioe.printStackTrace();
449 JOptionPane.showMessageDialog( this,
450 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
451 "Failed to generate graphics",
452 JOptionPane.ERROR_MESSAGE );
455 final byte[] bytes = baos.toByteArray();
456 final String dataImg = Base64.encodeBase64String( bytes );
460 public Options getOptions() {
466 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
467 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
468 final Configuration configuration = new Configuration( config_filename, true, true, true );
469 setConfiguration( configuration );
470 setOptions( Options.createInstance( configuration ) );
472 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
473 if ( ForesterUtil.isEmpty( tree_url_str ) ) {
474 ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
475 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
476 JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
477 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
480 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
481 // Get URL to tree file
484 phys_url = new URL( tree_url_str );
486 catch ( final Exception e ) {
487 ForesterUtil.printErrorMessage( NAME, "error: " + e );
489 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
490 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
492 if ( phys_url == null ) {
493 ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
494 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
495 JOptionPane.showMessageDialog( this,
496 NAME + ": Could not create URL from: \"" + tree_url_str,
497 "Failed to create URL",
498 JOptionPane.ERROR_MESSAGE );
501 // Load the tree from URL
502 Phylogeny[] phys = null;
504 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
505 getConfiguration().isValidatePhyloXmlAgainstSchema(),
506 getConfiguration().isReplaceUnderscoresInNhParsing(),
507 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
508 getConfiguration().getTaxonomyExtraction(),
509 getConfiguration().isMidpointReroot() );
511 catch ( final Exception e ) {
512 ForesterUtil.printErrorMessage( NAME, e.toString() );
514 JOptionPane.showMessageDialog( this,
515 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
516 "Failed to read phylogenies",
517 JOptionPane.ERROR_MESSAGE );
519 if ( phys == null ) {
520 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
521 JOptionPane.showMessageDialog( this,
522 NAME + ": phylogenies from [" + phys_url + "] are null",
523 "Failed to read phylogenies",
524 JOptionPane.ERROR_MESSAGE );
527 else if ( phys.length < 1 ) {
528 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
529 JOptionPane.showMessageDialog( this,
530 NAME + ": phylogenies from [" + phys_url + "] are empty",
531 "Failed to read phylogenies",
532 JOptionPane.ERROR_MESSAGE );
536 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
539 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
540 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
541 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
542 Phylogeny[] species_trees = null;
544 final URL species_tree_url = new URL( species_tree_url_str );
545 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
546 configuration.isValidatePhyloXmlAgainstSchema(),
547 configuration.isReplaceUnderscoresInNhParsing(),
549 TAXONOMY_EXTRACTION.NO,
552 catch ( final IOException e ) {
553 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
555 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
556 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
558 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
559 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
560 if ( species_trees[ 0 ].isEmpty() ) {
561 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
563 else if ( !species_trees[ 0 ].isRooted() ) {
564 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
567 setSpeciesTree( species_trees[ 0 ] );
568 AptxUtil.printAppletMessage( NAME, "species tree OK" );
574 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
575 _jmenubar = new JMenuBar();
576 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
577 if ( !getConfiguration().isUseNativeUI() ) {
578 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
580 if ( getSpeciesTree() != null ) {
589 setJMenuBar( _jmenubar );
591 final Container contentpane = getContentPane();
592 contentpane.setLayout( new BorderLayout() );
593 contentpane.add( getMainPanel(), BorderLayout.CENTER );
594 addComponentListener( new ComponentAdapter() {
597 public void componentResized( final ComponentEvent e ) {
598 if ( getMainPanel().getCurrentTreePanel() != null ) {
599 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
600 .getCurrentTreePanel()
603 .getCurrentTreePanel()
606 .isAllowFontSizeChange() );
610 if ( getConfiguration().isUseTabbedDisplay() ) {
611 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
612 AptxUtil.addPhylogeniesToTabs( phys,
613 new File( phys_url.getFile() ).getName(),
619 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
620 if ( getSpeciesTree() != null ) {
621 AptxUtil.printAppletMessage( NAME,
622 "Warning: gsdi (gene duplication inference) only available tabbed display" );
624 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
628 getMainPanel().getControlPanel().showWholeAll();
629 getMainPanel().getControlPanel().showWhole();
631 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
632 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
633 .getRelevantSequenceRelationTypes() ) {
634 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
636 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
637 if ( default_relation != null ) {
638 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
640 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
641 if ( default_sequence != null ) {
642 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
646 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
650 public void showTextFrame( final String s, final String title ) {
652 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
656 public void start() {
657 if ( getMainPanel() != null ) {
658 getMainPanel().validate();
661 requestFocusInWindow();
663 AptxUtil.printAppletMessage( NAME, "started" );
666 void buildAnalysisMenu() {
667 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
668 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
669 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
670 customizeJMenuItem( _gsdi_item );
671 customizeJMenuItem( _gsdir_item );
672 // _analysis_menu.addSeparator();
673 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
674 // customizeJMenuItem( _lineage_inference );
675 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
676 _jmenubar.add( _analysis_menu );
679 void buildFontSizeMenu() {
680 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
681 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
682 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
683 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
684 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
685 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
686 customizeJMenuItem( _super_tiny_fonts_mi );
687 customizeJMenuItem( _tiny_fonts_mi );
688 customizeJMenuItem( _small_fonts_mi );
689 customizeJMenuItem( _medium_fonts_mi );
690 customizeJMenuItem( _large_fonts_mi );
691 _jmenubar.add( _font_size_menu );
694 void buildHelpMenu() {
695 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
696 _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
697 _help_jmenu.addSeparator();
698 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
699 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
700 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
701 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
702 _help_jmenu.addSeparator();
703 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
704 customizeJMenuItem( _help_item );
705 customizeJMenuItem( _website_item );
706 customizeJMenuItem( _phyloxml_website_item );
707 customizeJMenuItem( _aptx_ref_item );
708 customizeJMenuItem( _phyloxml_ref_item );
709 customizeJMenuItem( _about_item );
710 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
711 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
712 _jmenubar.add( _help_jmenu );
715 void buildOptionsMenu() {
716 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
717 _options_jmenu.addChangeListener( new ChangeListener() {
720 public void stateChanged( final ChangeEvent e ) {
721 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
722 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
724 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
725 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
726 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
727 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
729 _show_branch_length_values_cbmi,
730 _non_lined_up_cladograms_rbmi,
731 _uniform_cladograms_rbmi,
732 _ext_node_dependent_cladogram_rbmi,
733 _label_direction_cbmi );
734 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
735 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
736 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
739 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
740 getConfiguration() ) );
742 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
743 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
745 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
746 _radio_group_1 = new ButtonGroup();
747 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
748 _radio_group_1.add( _uniform_cladograms_rbmi );
749 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
751 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
752 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
754 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
756 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
758 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
759 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
760 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
761 _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
763 _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
764 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
765 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
767 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
769 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
770 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
771 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
772 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
773 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
774 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
775 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
776 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
777 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
778 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
779 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
780 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
781 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
782 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
784 _options_jmenu.addSeparator();
785 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
786 getConfiguration() ) );
788 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
789 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
791 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
792 customizeJMenuItem( _choose_font_mi );
793 customizeJMenuItem( _choose_minimal_confidence_mi );
794 customizeJMenuItem( _switch_colors_mi );
795 customizeJMenuItem( _overview_placment_mi );
796 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
797 customizeCheckBoxMenuItem( _label_direction_cbmi,
798 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
799 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
800 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
801 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
802 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
803 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
804 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
805 .isShowDefaultNodeShapesExternal() );
806 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
807 .isShowDefaultNodeShapesInternal() );
808 customizeJMenuItem( _cycle_node_shape_mi );
809 customizeJMenuItem( _cycle_node_fill_mi );
810 customizeJMenuItem( _choose_node_size_mi );
811 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
812 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
813 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
814 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
815 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
816 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
817 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
818 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
819 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
820 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
821 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
822 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
823 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
824 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
825 customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
826 customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
827 _jmenubar.add( _options_jmenu );
830 void buildToolsMenu() {
831 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
832 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
833 customizeJMenuItem( _confcolor_item );
834 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
835 customizeJMenuItem( _taxcolor_item );
836 _tools_menu.addSeparator();
837 _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
838 _remove_visual_styles_item
839 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
840 customizeJMenuItem( _remove_visual_styles_item );
841 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
842 _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
843 customizeJMenuItem( _remove_branch_color_item );
844 _tools_menu.addSeparator();
845 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
846 customizeJMenuItem( _midpoint_root_item );
847 _tools_menu.addSeparator();
848 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
849 customizeJMenuItem( _collapse_species_specific_subtrees );
850 _jmenubar.add( _tools_menu );
853 void buildTypeMenu() {
854 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
855 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
856 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
857 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
858 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
859 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
860 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
861 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
862 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
863 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
864 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
865 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
866 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
867 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
868 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
869 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
870 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
871 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
872 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
873 initializeTypeMenu( getOptions() );
874 _jmenubar.add( _type_menu );
877 void buildViewMenu() {
878 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
880 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
881 _view_jmenu.addSeparator();
882 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
883 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
884 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
885 customizeJMenuItem( _display_basic_information_item );
886 customizeJMenuItem( _view_as_NH_item );
887 customizeJMenuItem( _view_as_XML_item );
888 customizeJMenuItem( _view_as_nexus_item );
889 _jmenubar.add( _view_jmenu );
892 void checkTextFrames() {
893 if ( _textframes.size() > 5 ) {
895 if ( _textframes.getFirst() != null ) {
896 _textframes.getFirst().removeMe();
899 _textframes.removeFirst();
902 catch ( final NoSuchElementException e ) {
908 void clearCurrentExternalNodesDataBuffer() {
909 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
912 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
913 if ( item != null ) {
914 item.setFont( MainFrame.menu_font );
915 if ( !getConfiguration().isUseNativeUI() ) {
916 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
917 item.setForeground( getConfiguration().getGuiMenuTextColor() );
919 item.setSelected( is_selected );
920 item.addActionListener( this );
924 void customizeJMenuItem( final JMenuItem jmi ) {
925 jmi.setFont( MainFrame.menu_font );
926 if ( !getConfiguration().isUseNativeUI() ) {
927 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
928 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
930 jmi.addActionListener( this );
933 void displayBasicInformation() {
934 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
935 String title = "Basic Information";
936 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
937 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
939 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
944 if ( !isOKforSDI( false, true ) ) {
947 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
948 JOptionPane.showMessageDialog( this,
949 "Gene tree is not rooted.",
950 "Cannot execute GSDI",
951 JOptionPane.ERROR_MESSAGE );
954 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
955 gene_tree.setAllNodesToNotCollapse();
956 gene_tree.recalculateNumberOfExternalDescendants( false );
958 final Phylogeny species_tree = _species_tree.copy();
960 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
962 catch ( final SDIException e ) {
963 JOptionPane.showMessageDialog( this,
964 e.getLocalizedMessage(),
966 JOptionPane.ERROR_MESSAGE );
969 catch ( final Exception e ) {
970 AptxUtil.unexpectedException( e );
973 gene_tree.setRerootable( false );
974 gene_tree.clearHashIdToNodeMap();
975 gene_tree.recalculateNumberOfExternalDescendants( true );
976 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
977 getMainPanel().getControlPanel().setShowEvents( true );
979 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
980 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
982 _mainpanel.getTabbedPane().setSelectedIndex( selected );
984 _mainpanel.getCurrentTreePanel().setEdited( true );
985 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
986 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
987 JOptionPane.showMessageDialog( this,
988 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
989 + "Potential duplications: "
990 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
991 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
992 + "Stripped gene tree nodes: "
993 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
994 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
995 + "Number of polytomies in species tree used: " + poly + "\n",
996 "GSDI successfully completed",
997 JOptionPane.WARNING_MESSAGE );
1000 JOptionPane.showMessageDialog( this,
1001 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1002 + "Potential duplications: "
1003 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1004 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1005 + "Stripped gene tree nodes: "
1006 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1007 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1008 + "Number of polytomies in species tree used: " + poly + "\n",
1009 "GSDI successfully completed",
1010 JOptionPane.INFORMATION_MESSAGE );
1014 void executeGSDIR() {
1015 if ( !isOKforSDI( false, false ) ) {
1018 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1020 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1021 JOptionPane.showMessageDialog( this,
1022 "Gene tree is not completely binary",
1023 "Cannot execute GSDI",
1024 JOptionPane.ERROR_MESSAGE );
1027 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1028 gene_tree.setAllNodesToNotCollapse();
1029 gene_tree.recalculateNumberOfExternalDescendants( false );
1031 final Phylogeny species_tree = _species_tree.copy();
1033 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1035 catch ( final SDIException e ) {
1036 JOptionPane.showMessageDialog( this,
1037 e.getLocalizedMessage(),
1038 "Error during GSDIR",
1039 JOptionPane.ERROR_MESSAGE );
1042 catch ( final Exception e ) {
1043 AptxUtil.unexpectedException( e );
1046 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1047 result_gene_tree.setRerootable( false );
1048 result_gene_tree.clearHashIdToNodeMap();
1049 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1050 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1051 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1052 getMainPanel().getControlPanel().setShowEvents( true );
1054 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1055 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1057 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1059 _mainpanel.getCurrentTreePanel().setEdited( true );
1060 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1061 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1062 JOptionPane.showMessageDialog( this,
1063 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1064 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1065 + "Stripped gene tree nodes: "
1066 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1067 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1068 + "Number of polytomies in species tree used: " + poly + "\n",
1069 "GSDIR successfully completed",
1070 JOptionPane.WARNING_MESSAGE );
1073 JOptionPane.showMessageDialog( this,
1074 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1075 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1076 + "Stripped gene tree nodes: "
1077 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1078 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1079 + "Number of polytomies in species tree used: " + poly + "\n",
1080 "GSDIR successfully completed",
1081 JOptionPane.INFORMATION_MESSAGE );
1085 Configuration getConfiguration() {
1086 return _configuration;
1089 TreePanel getCurrentTreePanel() {
1090 return getMainPanel().getCurrentTreePanel();
1093 JCheckBoxMenuItem getlabelDirectionCbmi() {
1094 return _label_direction_cbmi;
1097 Options getOtions() {
1101 void initializeTypeMenu( final Options options ) {
1102 setTypeMenuToAllUnselected();
1104 switch ( options.getPhylogenyGraphicsType() ) {
1106 _convex_type_cbmi.setSelected( true );
1109 _curved_type_cbmi.setSelected( true );
1112 _euro_type_cbmi.setSelected( true );
1115 _rounded_type_cbmi.setSelected( true );
1118 _triangular_type_cbmi.setSelected( true );
1121 _unrooted_type_cbmi.setSelected( true );
1124 _circular_type_cbmi.setSelected( true );
1127 _rectangular_type_cbmi.setSelected( true );
1131 catch ( final NullPointerException np ) {
1132 // In all likelihood, this is caused by menu-less display.
1136 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1137 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1140 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1141 JOptionPane.showMessageDialog( this,
1142 "No species tree loaded",
1143 "Cannot execute GSDI",
1144 JOptionPane.ERROR_MESSAGE );
1147 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1148 JOptionPane.showMessageDialog( this,
1149 "Species tree is not completely binary",
1150 "Cannot execute GSDI",
1151 JOptionPane.ERROR_MESSAGE );
1154 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1155 JOptionPane.showMessageDialog( this,
1156 "Gene tree is not completely binary",
1157 "Cannot execute GSDI",
1158 JOptionPane.ERROR_MESSAGE );
1166 boolean isSubtreeDisplayed() {
1167 if ( getCurrentTreePanel() != null ) {
1168 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1170 .showMessageDialog( this,
1171 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1172 "Operation can not be exectuted on a sub-tree",
1173 JOptionPane.WARNING_MESSAGE );
1180 void removeAllTextFrames() {
1181 for( final TextFrame tf : _textframes ) {
1186 _textframes.clear();
1189 void setConfiguration( final Configuration configuration ) {
1190 _configuration = configuration;
1193 void setOptions( final Options options ) {
1197 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1198 setTypeMenuToAllUnselected();
1202 _circular_type_cbmi.setSelected( true );
1205 _convex_type_cbmi.setSelected( true );
1208 _curved_type_cbmi.setSelected( true );
1211 _euro_type_cbmi.setSelected( true );
1214 _rounded_type_cbmi.setSelected( true );
1217 _rectangular_type_cbmi.setSelected( true );
1220 _triangular_type_cbmi.setSelected( true );
1223 _unrooted_type_cbmi.setSelected( true );
1226 throw new IllegalArgumentException( "unknown type: " + type );
1229 catch ( final NullPointerException np ) {
1230 // In all likelihood, this is caused by menu-less display.
1234 void setTypeMenuToAllUnselected() {
1235 if ( _convex_type_cbmi != null ) {
1236 _convex_type_cbmi.setSelected( false );
1238 if ( _curved_type_cbmi != null ) {
1239 _curved_type_cbmi.setSelected( false );
1241 if ( _euro_type_cbmi != null ) {
1242 _euro_type_cbmi.setSelected( false );
1244 if ( _rounded_type_cbmi != null ) {
1245 _rounded_type_cbmi.setSelected( false );
1247 if ( _triangular_type_cbmi != null ) {
1248 _triangular_type_cbmi.setSelected( false );
1250 if ( _rectangular_type_cbmi != null ) {
1251 _rectangular_type_cbmi.setSelected( false );
1253 if ( _unrooted_type_cbmi != null ) {
1254 _unrooted_type_cbmi.setSelected( false );
1256 if ( _circular_type_cbmi != null ) {
1257 _circular_type_cbmi.setSelected( false );
1262 _mainpanel.getControlPanel().showWhole();
1265 void switchColors() {
1266 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1267 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1268 csc.setVisible( true );
1269 getMainPanel().setTreeColorSet( colorset );
1272 void typeChanged( final Object o ) {
1273 updateTypeCheckboxes( getOptions(), o );
1274 updateOptions( getOptions() );
1275 if ( getCurrentTreePanel() != null ) {
1276 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1277 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1278 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1279 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1280 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1281 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1282 getCurrentTreePanel().getControlPanel().showWhole();
1284 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1285 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1288 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1290 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1291 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1295 void updateOptions( final Options options ) {
1296 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1297 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1298 && _background_gradient_cbmi.isSelected() );
1299 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1300 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1301 && _show_annotation_ref_source.isSelected() );
1302 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1303 && _abbreviate_scientific_names.isSelected() );
1304 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1305 && _color_labels_same_as_parent_branch.isSelected() );
1306 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1307 && _show_default_node_shapes_internal_cbmi.isSelected() );
1308 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1309 && _show_default_node_shapes_external_cbmi.isSelected() );
1310 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1311 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1313 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1314 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1316 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1317 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1319 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1320 && _search_case_senstive_cbmi.isSelected() );
1321 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1322 options.setShowScale( _show_scale_cbmi.isSelected() );
1324 if ( _label_direction_cbmi != null ) {
1325 if ( _label_direction_cbmi.isSelected() ) {
1326 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1329 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1332 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1333 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1334 && _show_confidence_stddev_cbmi.isSelected() );
1335 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1336 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1338 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1339 && _search_whole_words_only_cbmi.isSelected() );
1340 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1341 && _inverse_search_result_cbmi.isSelected() );
1342 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1343 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1345 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1346 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1348 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1349 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1351 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1352 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1354 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1355 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1357 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1358 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1360 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1361 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1363 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1364 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1366 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1367 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1369 if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1370 options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1372 if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1373 options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1377 void updateTypeCheckboxes( final Options options, final Object o ) {
1378 setTypeMenuToAllUnselected();
1379 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1382 void viewAsNexus() {
1383 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1384 String title = "Nexus";
1385 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1386 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1388 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1389 .getNhConversionSupportValueStyle() ),
1395 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1396 String title = "New Hampshire";
1397 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1398 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1400 showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1401 .getNhConversionSupportValueStyle() ),
1407 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1408 String title = "phyloXML";
1409 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1410 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1412 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1416 private void chooseFont() {
1417 final FontChooser fc = new FontChooser();
1418 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1419 fc.showDialog( this, "Select the Base Font" );
1420 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1423 private void chooseMinimalConfidence() {
1424 final String s = ( String ) JOptionPane
1425 .showInputDialog( this,
1426 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1427 + getOptions().getMinConfidenceValue() + "]\n",
1428 "Minimal Confidence Value",
1429 JOptionPane.QUESTION_MESSAGE,
1432 getOptions().getMinConfidenceValue() );
1433 if ( !ForesterUtil.isEmpty( s ) ) {
1434 boolean success = true;
1436 final String m_str = s.trim();
1437 if ( !ForesterUtil.isEmpty( m_str ) ) {
1439 m = Double.parseDouble( m_str );
1441 catch ( final Exception ex ) {
1448 if ( success && ( m >= 0.0 ) ) {
1449 getOptions().setMinConfidenceValue( m );
1454 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1455 if ( item != null ) {
1456 item.setFont( MainFrame.menu_font );
1457 if ( !getConfiguration().isUseNativeUI() ) {
1458 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1459 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1461 item.setSelected( is_selected );
1462 item.addActionListener( this );
1466 private MainPanel getMainPanel() {
1470 private Phylogeny getSpeciesTree() {
1471 return _species_tree;
1474 private boolean isScreenAntialias() {
1478 private void removeBranchColors() {
1479 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1480 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1484 private void removeVisualStyles() {
1485 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1486 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1490 private void setMainPanel( final MainPanelApplets main_panel ) {
1491 _mainpanel = main_panel;
1494 private void setSpeciesTree( final Phylogeny species_tree ) {
1495 _species_tree = species_tree;
1498 private void setupUI() {
1500 if ( getConfiguration().isUseNativeUI() ) {
1501 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1504 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1507 catch ( final UnsupportedLookAndFeelException e ) {
1508 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1510 catch ( final ClassNotFoundException e ) {
1511 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1513 catch ( final InstantiationException e ) {
1514 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1516 catch ( final IllegalAccessException e ) {
1517 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1519 catch ( final Exception e ) {
1520 AptxUtil.dieWithSystemError( e.toString() );
1524 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1525 for( final TreePanel tree_panel : treepanels ) {
1526 tree_panel.setTextAntialias();